protected void btnConfirmOrder_Click(object sender, EventArgs e) { orderManager objorder = new orderManager(); //if (Session["OrderId"] != null) //{ if (Request.QueryString["orderid"] != null) { objorder.orderid = Convert.ToInt32(Request.QueryString["orderid"]); int Ammount = objorder.getTotalAmountFromOrderId(); if (Ammount != 0) { objorder.orderid = Convert.ToInt32(Request.QueryString["orderid"]); objorder.orderstatus = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["OrderRecieved"]); if (rbtCOD.Checked == true) { objorder.payType = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PayTypeCase"]); } if (rbtCredit.Checked == true) { objorder.payType = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PayTypeCredit"]); } objorder.UpdateOrderStatusByOrderId(); string strCustomerName = txtCustomer.Text.Trim(); int customer_id; string creditLimits = ""; string reducePercent = ""; string GlobleDiscount = ""; customerManager objcustomer = new customerManager(); DataTable dtcustomer = new DataTable(); objcustomer.contactName = Convert.ToString(strCustomerName); objcustomer.companyName = Convert.ToString(strCustomerName); try { customer_id = objcustomer.GetCustomerId(); if (rbtCredit.Checked == true) { dtcustomer = objcustomer.GetCustomerIdAndDiscountCredit(); if (dtcustomer.Rows.Count > 0) { customer_id = Convert.ToInt32(dtcustomer.Rows[0]["customerid"]); GlobleDiscount = dtcustomer.Rows[0]["globleDiscountRate"].ToString(); creditLimits = dtcustomer.Rows[0]["creditLimit"].ToString(); reducePercent = dtcustomer.Rows[0]["reducePercent"].ToString(); } decimal TotalAmmount = objorder.GetSumOfItemPriceUsingOrderId(); string credits = creditLimits.ToString().Replace("SAR", "").Replace(".00", ""); objcustomer.creditLimit = Convert.ToString(Convert.ToInt32(credits) - Convert.ToInt32(TotalAmmount)); objcustomer.customerId = Convert.ToInt32(customer_id); if (GlobleDiscount.Replace("%", "") == "0") { objcustomer.globleDiscountRate = "0"; } else { objcustomer.globleDiscountRate = Convert.ToString(Convert.ToInt32(GlobleDiscount.Replace("%", "")) - Convert.ToInt32(5)) + "%"; } objcustomer.UpdateCustomerCreditLimits(); } } catch (Exception c) { throw c; } finally { objcustomer = null; } SendMail(Convert.ToInt32(Request.QueryString["orderid"]), customer_id, Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["EmailNotificationsOrderReceivedId"])); Session["cust_name"] = ""; //Response.Redirect("vieworder.aspx?orderid=" + Request.QueryString["orderid"]); Response.Redirect("vieworder.aspx"); } else { //Response.Write("<script>alert('There are no items avaliable in order');</script>"); lblerrMsg.Text = "There are no items avaliable in order."; } } }
protected void btnAddProOrder_Click(object sender, EventArgs e) { Session["msg"] = ""; string strCustomerName = txtCustomer.Text.Trim(); int customer_id = 0; string creditLimits = ""; string reducePercent = ""; string GlobleDiscount = ""; int order_id = 0; bool ordFlag = false; //decimal discount = Convert.ToDecimal(0.0); decimal netPayment = Convert.ToDecimal(0.0); customerManager objcustomer = new customerManager(); DataTable dtcustomer = new DataTable(); objcustomer.contactName = Convert.ToString(strCustomerName); objcustomer.companyName = Convert.ToString(strCustomerName); try { //customer_id = objcustomer.GetCustomerId(); dtcustomer = objcustomer.GetCustomerIdAndDiscountCredit(); if (dtcustomer.Rows.Count > 0) { customer_id = Convert.ToInt32(dtcustomer.Rows[0]["customerid"]); GlobleDiscount = dtcustomer.Rows[0]["globleDiscountRate"].ToString(); creditLimits = dtcustomer.Rows[0]["creditLimit"].ToString(); reducePercent = dtcustomer.Rows[0]["reducePercent"].ToString(); } } catch (Exception c) { throw c; } finally { objcustomer = null; } foreach (GridViewRow row in GVOrder.Rows) { if (row.RowType == DataControlRowType.DataRow) { bool isChecked = row.Cells[0].Controls.OfType <CheckBox>().FirstOrDefault().Checked; if (isChecked) { string lblProdutId = row.Cells[0].Controls.OfType <Label>().FirstOrDefault().Text; string lblPrice = row.Cells[4].Controls.OfType <Label>().FirstOrDefault().Text; string TxtQty = row.Cells[6].Controls.OfType <TextBox>().FirstOrDefault().Text; string lblproName = row.Cells[3].Controls.OfType <Label>().FirstOrDefault().Text; string lblCost = row.Cells[2].Controls.OfType <Label>().FirstOrDefault().Text; orderManager objorder = new orderManager(); try { objorder.productid = Convert.ToInt32(lblProdutId); int Inventory = objorder.GetInventoryByProductid(); if (Inventory >= Convert.ToInt32(TxtQty)) { objorder.customerid = Convert.ToInt32(customer_id); //objorder.orderstatus = Convert.ToInt32(1); if (ordFlag == false && Request.QueryString["orderid"] == null && Convert.ToInt32(Request.QueryString["orderid"]) == 0) { if (rbtCOD.Checked == true) { objorder.payType = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PayTypeCase"]); } if (rbtCredit.Checked == true) { objorder.payType = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PayTypeCredit"]); } objorder.contactName = Convert.ToString(strCustomerName); order_id = objorder.InsertOrder(); // insert into order table ordFlag = true; } else { if (Request.QueryString["orderid"] != null && Convert.ToInt32(Request.QueryString["orderid"]) != 0) { order_id = Convert.ToInt32(Request.QueryString["orderid"]); ordFlag = true; } } objorder.productid = Convert.ToInt32(lblProdutId); objorder.productName = Server.HtmlEncode(Convert.ToString(lblproName)); objorder.globleDiscountRate = Convert.ToInt32(GlobleDiscount.Replace("%", "")); objorder.costPrice = Convert.ToDecimal(lblCost); objorder.price = Convert.ToDecimal(lblPrice); objorder.qty = Convert.ToInt32(TxtQty); objorder.orderid = Convert.ToInt32(order_id); if (Convert.ToInt32(GlobleDiscount.Replace("%", "")) > 0) { objorder.finalPrice = Convert.ToDecimal(Convert.ToDecimal(lblPrice) - ((Convert.ToDecimal(lblPrice) * Convert.ToInt32(GlobleDiscount.Replace("%", "")) / 100))); objorder.netprice = Convert.ToDecimal((Convert.ToDecimal(lblPrice) * Convert.ToInt32(TxtQty)) - ((Convert.ToDecimal(lblPrice) * Convert.ToInt32(TxtQty)) * Convert.ToInt32(GlobleDiscount.Replace("%", "")) / 100)); } else { objorder.finalPrice = Convert.ToDecimal(lblPrice); objorder.netprice = Convert.ToDecimal(Convert.ToDecimal(lblPrice) * Convert.ToInt32(TxtQty)); } DataTable dtord = new DataTable(); dtord = objorder.GetOrderDetailByproIdordId(); if (dtord.Rows.Count > 0) { objorder.UpdateOrderDetail(); } else { objorder.InsertOrderDetail(); } if (Convert.ToInt32(GlobleDiscount.Replace("%", "")) > 0) { netPayment = Convert.ToDecimal(Convert.ToDecimal(netPayment) + (Convert.ToDecimal(objorder.netprice) - (Convert.ToDecimal(objorder.netprice) * Convert.ToInt32(GlobleDiscount.Replace("%", "")) / 100))); } else { netPayment = Convert.ToDecimal(Convert.ToDecimal(netPayment) + Convert.ToDecimal(objorder.netprice)); } } else { Session["msg"] = "Please enter quentity less than " + Inventory + " for this product : " + lblproName; lblerror.Visible = true; lblerrors.Text = "Please enter quentity less than " + Inventory + " for this product : " + lblproName; } } catch (Exception ex) { throw ex; } finally { objorder = null; } } } } // add into order if (ordFlag == true) { orderManager objordertotal = new orderManager(); customerManager objcust = new customerManager(); try { objordertotal.orderid = order_id; decimal TotalAmmount = objordertotal.GetSumOfItemPriceUsingOrderId(); if (TotalAmmount != 0) { netPayment = TotalAmmount; } objordertotal.totalammount = Convert.ToDecimal(netPayment); if (rbtCOD.Checked == true) { objordertotal.payType = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PayTypeCase"]); } if (rbtCredit.Checked == true) { objordertotal.payType = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PayTypeCredit"]); } objordertotal.contactName = Convert.ToString(strCustomerName); objordertotal.UpdateOrder(); hidorderid.Value = Convert.ToString(order_id); Session["OrderId"] = Convert.ToString(order_id); Session["cust_name"] = Convert.ToString(txtCustomer.Text.Trim()); GetOrderDetails(); rbtCOD.Enabled = true; rbtCredit.Enabled = true; Response.Redirect("add_order.aspx?orderid=" + order_id + "&chkid=" + objordertotal.payType + "&customer=" + customer_id); } catch (Exception o) { throw o; } finally { objordertotal = null; objcust = null; } } }