我在我的网页中输入客户详细信息,其中包括Customerid,Customername,ProductName,Quantity,Rate,Total,Discount,NetTotal。如果我在申请中的相应字段中输入数量和费率。应自动输入所有字段,并在BAL图层类中完成计算。但每当我输入数量和费率字段中的任何值时,其他相应字段始终仅显示0值,这是不期望的。这是我的所有代码:
数据输入页面:
<table cellspacing="0", cellpadding="0">
</tr>
<tr >
<td align="center">
<h1>Sales Entry Details </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班级:
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();
}
}
}
}
}
答案 0 :(得分:0)
由于您的字段实际上并未绑定到BAL类对象,因此您需要在每个PostBack期间执行赋值,除非您使用ViewState属性或Session来保存已具有所有这些属性的现有属性设定值。