插入值时需要 GUI 层的帮助

发布于 2024-08-19 14:39:26 字数 6266 浏览 3 评论 0原文

我正在网页中输入客户详细信息,其中字段包括 Customerid、Customername、ProductName、Quantity、Rate、Total、Discount、NetTotal。如果我在应用程序的相应字段中输入数量和费率。所有字段都应自动输入,并且已在 BAL 图层类中完成计算。但每当我在数量和费率字段中输入任何值时,其他相应字段总是仅显示 0 值,这是不期望的。这是我的所有代码:

数据输入页面:

<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 类:

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();
                }
            }
        }
    }
}

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 </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();
                }
            }
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙与沫 2024-08-26 14:39:26

由于您的字段实际上并未绑定到 BAL 类对象,因此您需要在每次回发期间执行分配,除非您使用 ViewState 属性或 Session 来保存已设置所有这些值的现有属性。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文