Hi please can you help to multiply the quantity by customer by the unit price, example if the quantity customer ordered is 20 and the unit price is 50 dollars how do i insert the total money
protected void btnSave_Click(object sender, EventArgs e)
{
// string name = ddlcustomername.Text.Trim();
// string address = customeraddress.Text.Trim();
string productName = ddlProducts.SelectedItem.Text.Trim();
string name = ddlcustomername.SelectedItem.Text.Trim();
string address = ddlcustomeraddress.SelectedItem.Text.Trim();
decimal unitPrice = Convert.ToDecimal(lblProductPrice.Text.Trim());
int availableQuantity = Convert.ToInt32(lblQuantityAvailable.Text.Trim());
int quantity = Convert.ToInt32(txtQuantity.Text.Trim());
int inserted = 0;
// int availableInventoryQty = AvailableInventoryQty();
if (lblProductPrice.Text.Length > 0 && txtQuantity.Text.Length > 0)
{
double stock = Convert.ToDouble(txtQuantity.Text);
double customerqty = Convert.ToDouble(txtQuantity.Text);
double tqty = stock - customerqty;
double gqty = tqty;
{
if (lblProductPrice.Text.Length > 0 && txtQuantity.Text.Length > 0)
{
double unitprice2 = Convert.ToDouble(lblProductPrice.Text);
double customerqty2 = Convert.ToDouble(txtQuantity.Text);
double grandtotal = unitprice2 * customerqty;
double total = grandtotal;
{
// if (txtunitprice.Text.Length > 0 && txtdiscount.Text.Length > 0)
{
// double unitprice = Convert.ToDouble(txtunitprice.Text);
// double discount = Convert.ToDouble(txtdiscount.Text);
// double sum = grandtotal - discount;
// double sumb = sum;
if ((availableQuantity != 0) && (quantity != 0) && (quantity < availableQuantity))
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = str;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
cmd.CommandText = "INSERT INTO Sells VALUES('" + name + "','" + address + "','" + productName + "'," + unitPrice + "," + quantity + ")";
cmd.Parameters.AddWithValue("@UserName", Session["userName"]);
cmd.Parameters.AddWithValue("@CustomerName", ddlcustomername.Text.Trim());
// cmd.Parameters.AddWithValue("@Location", ddlLocation.Text.Trim());
cmd.Parameters.AddWithValue("@ProductName", ddlProducts.Text.Trim());
// cmd.Parameters.AddWithValue("@Inches", ddlInches.Text.Trim()); //Name of rep
// cmd.Parameters.AddWithValue("@MouldType", ddlmouldcategory.Text.Trim());
// cmd.Parameters.AddWithValue("@Category", ddlProducts.Text.Trim());
// cmd.Parameters.AddWithValue("@StockRemaining", tqty);
// cmd.Parameters.AddWithValue("@PaymentMethod", ddlpaymentmethod.Text.Trim());
// cmd.Parameters.AddWithValue("@OrderStatus", ddlorderstatus.Text.Trim());
//Address
cmd.Parameters.AddWithValue("@Ordered", txtQuantity.Text.Trim());
// cmd.Parameters.AddWithValue("@Discount", txtdiscount.Text.Trim());
cmd.Parameters.AddWithValue("@UnitPrice", lblProductPrice.Text.Trim());
cmd.Parameters.AddWithValue("@TotalAmount", grandtotal);
cmd.Parameters.AddWithValue("@OrderDate", DateTime.Today);
con.Open();
inserted = cmd.ExecuteNonQuery();
con.Close();
}
}
}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('No of Quantity entered is not available in Stock')", true);
}