Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

How to create add price , multiply by quantity and minus discount before submitting to database (ASP.NET C#)

$
0
0

Am trying to create a sales web application that will add sells price and multiply with the quantity and also check their is any discount, if yes the discount will be minused from the total sells and then sumbit the final total, but if their is no discount it will submit the result.

Example:

textbox price

textbox quantity

textbox discount

lable result display

the price of iphone5 is $3,000 and a customer wants 5 of it, the application will multiply the price of the iphone by the quantity the customer is bying and then check if their is discount, if yes it will minus the discount and submit the finall result; but no it will insert zero into discount colum and submit final result.

Please this clear to understand?. Any idea on how to make this work?

my design :

<br /></td></tr><tr><td><asp:Label ID="Label6" runat="server" Text="Select Branches:"></asp:Label><br /><asp:DropDownList ID="ddBranch" runat="server"
                                        DataSourceID="SqlDataSource2" DataTextField="BranchName"
                                        DataValueField="BranchID" AutoPostBack="True"
                                        onselectedindexchanged="ddBranch_SelectedIndexChanged"></asp:DropDownList><asp:SqlDataSource ID="SqlDataSource2" runat="server"
                                        ConnectionString="<%$ ConnectionStrings:MIGOLD1 %>"
                                        SelectCommand="SELECT * FROM [Locations]"></asp:SqlDataSource></td></tr><tr><td><asp:Label ID="Label7" runat="server" Text="Select Category:"></asp:Label><br /><asp:DropDownList ID="ddlCategory" runat="server" DataSourceID="SqlDataSource1"
                                        DataTextField="CategoryName" DataValueField="CategoryID"
                                        onselectedindexchanged="ddlCategory_SelectedIndexChanged"
                                        AutoPostBack="True"><asp:ListItem>------Select Category----</asp:ListItem><asp:ListItem></asp:ListItem></asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server"
                                        ConnectionString="<%$ ConnectionStrings:MIGOLD1 %>"
                                        SelectCommand="SELECT * FROM [Category]"></asp:SqlDataSource></td></tr><tr><td><asp:Label ID="Label3" runat="server">Brands:</asp:Label><br /><asp:DropDownList ID="ddBrands" runat="server" DataSourceID="SqlDataSource3"
                                        DataTextField="BrandName" DataValueField="BrandID" AutoPostBack="True"><asp:ListItem>------Select Category----</asp:ListItem><asp:ListItem></asp:ListItem></asp:DropDownList><asp:SqlDataSource ID="SqlDataSource3" runat="server"
                                        ConnectionString="<%$ ConnectionStrings:MIGOLD1 %>"
                                        SelectCommand="SELECT * FROM [Brands]"></asp:SqlDataSource></td></tr><tr><td><asp:Label ID="Label16" runat="server">Customer Name:</asp:Label><br /><asp:DropDownList ID="ddlCustomer_Name" runat="server" AutoPostBack="True"
                                        DataSourceID="SqlDataSource4" DataTextField="Customer_Name" DataValueField="id"></asp:DropDownList><asp:SqlDataSource ID="SqlDataSource4" runat="server"
                                        ConnectionString="<%$ ConnectionStrings:MIGOLD1 %>"
                                        SelectCommand="SELECT * FROM [CustomerDetails]"></asp:SqlDataSource></td></tr><tr><td class="style19"><asp:Label ID="Label4" runat="server">Selling Price:</asp:Label><br /><asp:TextBox ID="txtSellingPrice" runat="server" Width="294px"></asp:TextBox></td></tr><tr><td><asp:Label ID="Label8" runat="server">Quantity:</asp:Label><br /><asp:TextBox ID="txtQuantity" runat="server" Width="294px"></asp:TextBox></td></tr><tr><td><asp:Label ID="Label5" runat="server">Discount:</asp:Label><asp:Label ID="Label9" runat="server" Font-Bold="True" ForeColor="#009900">(Please Add 0 if no discount)</asp:Label><br /><asp:TextBox ID="txtDiscount" runat="server" Width="294px"></asp:TextBox></td></tr><tr><td><asp:Button ID="BtnInsert" runat="server" onclick="BtnInsert_Click"
                                        Text="Insert" style="height: 26px" /></td>

code behind:

        SqlConnection con = new SqlConnection(str);
        SqlCommand cmd = new SqlCommand("select * from Locations where BranchID = '" +
            DropDownList1.SelectedValue + "'", con);
        SqlDataAdapter Adpt = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();


                                       if (txtDate.Text == "")
                                         {
                                      lblMessage.Text = "Empty Field(Date)";
                                          }
                                          else
                                         {
                                       lblMessage.Text = "";


                                    
                                            if (txtAdminID.Text == "")
                                            {
                                                lblMessage.Text = "Empty Field(Date)";
                                            }
                                            else
                                            {
                                                lblMessage.Text = "";


                                                if (ddBranch.SelectedIndex < 1)
                                                {
                                                    lblBookingMessage2.Text = "Select Status";
                                                }
                                                else
                                                {
                                                    lblBookingMessage2.Text = "";

                                                if (ddlCategory.SelectedIndex < 1)
                                                {
                                                    lblBookingMessage2.Text = "Enter Gender.";
                                                }
                                                else
                                                {
                                                    lblBookingMessage2.Text = "";

                                                    if (ddBrands.SelectedIndex < 1)
                                                    {
                                                        lblBookingMessage2.Text = "Select Status";
                                                    }
                                                    else
                                                    {
                                                        lblBookingMessage2.Text = "";

                                                         if (ddlCustomer_Name.SelectedIndex < 1)
                                                    {
                                                        lblBookingMessage2.Text = "Select Status";
                                                    }
                                                    else
                                                    {
                                                        lblBookingMessage2.Text = "";


                                                        if (txtSellingPrice.Text == "")
                                                        {
                                                            lblBookingMessage2.Text = "Enter Customer Location.";
                                                        }
                                                        else
                                                        {
                                                            lblBookingMessage2.Text = "";

                                                            if (txtQuantity.Text == "")
                                                            {
                                                                lblBookingMessage2.Text = "Enter Customer Phone.";
                                                            }
                                                            else
                                                            {
                                                                lblBookingMessage2.Text = "";


                                                                if (txtDiscount.Text == "")
                                                                {
                                                                    lblBookingMessage2.Text = "Enter Daily Booking Charge.";
                                                                }
                                                                else
                                                                {
                                                                    lblBookingMessage2.Text = "";

                                                                   
                                                                                

                                                                                if (txtAdminID.Text == "")
                                                                                {

                                                                                }
                                                                                else
                                                                                {
                                                                                    int C = 1;
                                                                                    if (C > 0)


                                                                                        if (txtSellingPrice.Text.Length > 0 && txtQuantity.Text.Length > 0)
                                                                                        {
                                                                                            float sellingPrice = Convert.ToInt32(txtSellingPrice.Text);
                                                                                            float quantity = Convert.ToInt32(txtQuantity.Text);

                                                                                            // float total = Convert.ToInt32(txtRoomNo.Text);
                                                                                            float sum = sellingPrice * quantity;
                                                                                            float Total = sum;
                                                                                            {
                                                                                                //lblBookingMessage2.Text = " Room Number " + txtRoomNo.Text + " is now ocupied".ToString();

                                                                                            }
                                                                                           // lblBookingMessage3.Text = " Booking cost is N" + Total.ToString();

                                                                                          //  lblBookingMessage4.Text = " Booked For " + DaysBooked.Text + " Days ".ToString();
                                                                                           // lblBookingMessage5.Text = " " + txtRoomCategory.Text +  " suit room number " + txtRoomNo.Text + " is now occupied by " + Status.Text + "  " + txtCustomerName.Text +".".ToString();

                                                                                            if (txtSellingPrice.Text.Length > 0 && txtQuantity.Text.Length > 0);
                                                                                            float sellgPrice = Convert.ToInt32(txtSellingPrice.Text);
                                                                                            float discount = Convert.ToInt32(txtDiscount.Text);
                                                                                            float Sum = sellingPrice - discount;
                                                                                            float total = Sum;



                                                                                           strCon = ConfigurationManager.ConnectionStrings["XXXX"].ConnectionString;
                                                                                           con = new SqlConnection(strCon);
                                                                                           con.Open();


                                                                                           comm = new SqlCommand();
                                                                                           comm.CommandText = "INSERT INTO Sells VALUES('" + txtAdminID.Text + "', '" + txtDate.Text + "', '" + ddBranch.Text + "', '" + ddlCategory.Text + "', '" + ddBrands.Text + "', '" + txtSellingPrice.Text + "', '" + txtQuantity.Text + "', '" + txtDiscount + "', '" + sum + "', '" + Sum + "')";
                                                                                           comm.Connection = con;
                                                                                           result = comm.ExecuteNonQuery();


                                                                                            {

                                                                                                if (result > 0)
                                                                                                {
                                                                                                    lblBookingMessage2.Text = "Record Has Been Inserted !!.";
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    lblBookingMessage2.Text = "Please check your input.";
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                }




Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>