tags:

views:

24

answers:

1

Hi all, I am entering customer details in my web page, in that fields are Customerid, Customername, ProductName, Quantity, Rate, Total, Discount, NetTotal. If i enter quantity and rate in respective field in application. All the field should entered automatically and calculation have been done in BAL layer class. But whenever i am entering any value in quantity and rate field, other respective field always showing 0 values only, which is not expected. Here is my all the code:

Data Entry page:

<table cellspacing="0", cellpadding="0">     
    </tr>    
    <tr >
        <td align="center">
         <h1>Sales Entry Details&nbsp;</h1>
        </td>   
    </tr>
    <tr>
        <td>
            <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>       
        </td>    
    </tr>
    <tr>
        <td>
            CustomerId:        
        </td>  
        <td align="center">        
            <asp:TextBox ID="TxtCustomerId" runat="server"></asp:TextBox>
        </td>  
    <tr>
        <td>
            CustomerName:        
        </td>  
        <td align="center">        
            <asp:TextBox ID="TxtCustName" runat="server"></asp:TextBox>
        </td>  
    </tr>   
     <tr>
        <td>
            ProductName:        
        </td>  
        <td align="center">        
            <asp:TextBox ID="TxtProductName" runat="server"></asp:TextBox>
        </td>  
     </tr> 
      <tr>
        <td>
            Quantity:        
        </td>  
        <td align="center">        
            <asp:TextBox ID="TxtQuantity" runat="server"></asp:TextBox>
        </td>  
    </tr>    
     <tr>
        <td>
            Rate:        
        </td>  
        <td align="center">        
            <asp:TextBox ID="TxtRate" runat="server" ontextchanged="TxtRate_TextChanged" AutoPostBack="true"></asp:TextBox>
        </td>  
    </tr>   
     <tr>
        <td>
            Total:        
        </td>  
        <td align="center">        
            <asp:TextBox ID="TxtTotal" runat="server"></asp:TextBox>
        </td>  
    </tr>    
     <tr>
        <td>
            Discount:        
        </td>  
        <td align="center">        
            <asp:TextBox ID="TxtDiscount" runat="server"></asp:TextBox>
        </td>  
    </tr> 
     <tr>
        <td>
            NetTotal:        
        </td>  
        <td align="center">        
            <asp:TextBox ID="TxtNetTotal" runat="server"></asp:TextBox>
        </td>  
    </tr>
    </tr>
    <tr>
        <td align="center">
        <asp:Button ID="BtnSubmit" runat="server" Text="ADD" onclick="BtnSubmit_Click" />        
        </td>    
    </tr>     
    </table> 

BAL Class:

public class SalesBAL
{

    private string custid;
    private string custname;
    private string productname;
    private int quantity;
    private float rate;
    private float total;
    private float discount;
    private float NetTotal;

    public string CUSTOMERID
    {
        get
        {
            return custid;
        }
        set
        {
            custid = value;
        }

    }
    public string CUSTOMERNAME
    {
        get
        {
            return custname;
        }
        set
        {
            custname = value;
        }

    }
    public string PRODUCTNAME
    {
        get
        {
            return productname;
        }
        set
        {
            productname = value;
        }
    }
    public int QUANTITY
    {
        get
        {
            return quantity;
        }
        set
        {
            quantity = value;
        }

    }
    public float RATE
    {
        get
        {
            return rate;
        }
        set
        {
            rate = value;
        }
    }
    public float TOTAL
    {
        get
        {
            return total;
        }
        set
        {
            total = quantity*rate;

        }
    }
    public float DISCOUNT
    {
        get
        {
            return discount;
        }
        set
        {
            discount = ((15/100)*total);
        }       
    }
    public float NETTOTAL
    {
        get
        {
            return NetTotal; 
        }
        set
        {
            NetTotal =(total-discount);
        }

    }
    public int AddCustomer(SalesBAL obj)
    {

        SalesDAL SDAL = new SalesDAL();
        try
        {
            return SDAL.InsertCustomer(obj);
        }
        catch
        {
            throw;
        }
        finally
        {
            SDAL = null;
        }
    }
}
DAL Class:
public class SalesDAL
{
    string connstr = ConfigurationManager.ConnectionStrings["SalesConnectionString"].ConnectionString;
    public int InsertCustomer(SalesBAL obj)
    {
        using (var con = new SqlConnection(connstr))
        {
            con.Open();
            using (var com = new SqlCommand("AddCustDetail", con))
            {
                com.CommandType = CommandType.StoredProcedure;
                try
                {
                    com.Parameters.AddWithValue("@CustomerId",obj.CUSTOMERID);
                    com.Parameters.AddWithValue("@CustomerName", obj.CUSTOMERNAME);
                    com.Parameters.AddWithValue("@ProductName", obj.PRODUCTNAME);
                    com.Parameters.AddWithValue("@Quantity", obj.QUANTITY);
                    com.Parameters.AddWithValue("@Rate", obj.RATE);
                    com.Parameters.AddWithValue("@Total", obj.TOTAL);
                    com.Parameters.AddWithValue("@Discount", obj.DISCOUNT);
                    com.Parameters.AddWithValue("@NetTotal",obj.NETTOTAL);
                    com.Parameters.AddWithValue("@SalesDate", DateTime.Now);
                    return com.ExecuteNonQuery();                
                 }
                catch
                {
                    throw;

                }
                finally
                {
                    con.Close();
                }
            }
        }
    }
}
A: 

Since your fields aren't actually bound to your BAL class object, you'll need to perform the assignment during each PostBack unless you're using either a ViewState property or Session to hold an existing one that already has all of these values set.

Joel Etherton