protected void saveButton_Click(object sender, EventArgs e) { string msg = string.Empty; SalesOrderBLL salesOrder = new SalesOrderBLL(); DataTable dtPrdList = new DataTable(); DataRow dr = null; decimal quantity = 0; double rate = 0; double amount = 0; TextBox orderQuantityTextBox; TextBox ratePerUnitTextBox; TextBox amountTextBox; TextBox heighTextBox; TextBox widthTextBox; TextBox UnitTextBox; TextBox totalUnitTextBox; Label vatLabel; int i = 0; dtPrdList.Columns.Add(new DataColumn("ProductId")); dtPrdList.Columns.Add(new DataColumn("Height")); dtPrdList.Columns.Add(new DataColumn("Width")); dtPrdList.Columns.Add(new DataColumn("OrderUnit")); dtPrdList.Columns.Add(new DataColumn("TotalUnit")); dtPrdList.Columns.Add(new DataColumn("OrderQuantity")); dtPrdList.Columns.Add(new DataColumn("Quantity")); dtPrdList.Columns.Add(new DataColumn("RatePerUnit")); dtPrdList.Columns.Add(new DataColumn("VATPercentage")); dtPrdList.Columns.Add(new DataColumn("Amount")); try { for (i = 0; i < selectedProductListGridView.Rows.Count; i++) { //double availAbleQuantity = Convert.ToDouble(selectedProductListGridView.Rows[i].Cells[3].Text.ToString()); heighTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("heightTextBox"); widthTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("WidthTextBox"); UnitTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("UnitTextBox"); totalUnitTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("totalUnitTextBox"); orderQuantityTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("orderQuantityTextBox"); ratePerUnitTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("ratePerUnitTextBox"); amountTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("amountTextBox"); vatLabel = (Label)selectedProductListGridView.Rows[i].FindControl("lblVatparcentage"); if (string.IsNullOrEmpty(orderQuantityTextBox.Text.Trim()) || !decimal.TryParse(orderQuantityTextBox.Text.Trim(), out quantity)) { msg = "Product ID [" + selectedProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid quantity."; msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg; return; } else if (string.IsNullOrEmpty(ratePerUnitTextBox.Text.Trim()) || !double.TryParse(ratePerUnitTextBox.Text.Trim(), out rate)) { msg = "Product ID [" + selectedProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid rate."; msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg; return; } else if (string.IsNullOrEmpty(amountTextBox.Text.Trim()) || !double.TryParse(amountTextBox.Text.Trim(), out amount)) { msg = "Product ID [" + selectedProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid amount."; msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg; return; } //else if (Convert.ToDouble(orderQuantityTextBox.Text) > availAbleQuantity) //{ // msg = "Product ID [" + selectedProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid Availability."; // msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg; // return; //} else { dr = dtPrdList.NewRow(); dr["ProductId"] = selectedProductListGridView.Rows[i].Cells[0].Text.ToString(); // dr["Available"] = selectedProductListGridView.Rows[i].Cells[3].Text.ToString(); dr["Height"] = heighTextBox.Text; dr["Width"] = widthTextBox.Text; dr["OrderUnit"] = UnitTextBox.Text; dr["TotalUnit"] = totalUnitTextBox.Text; dr["Quantity"] = quantity.ToString(); dr["RatePerUnit"] = rate.ToString(); dr["VATPercentage"] = vatLabel.Text; //selectedProductListGridView.Rows[i].Cells[8].Text.ToString(); dr["Amount"] = amount.ToString(); dtPrdList.Rows.Add(dr); } } if (accountHeadDropDownList.SelectedValue == "") { msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Select Any Account Head"; return; } else if (totalAmountTextBox.Text.Trim() == "") { msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Total Amount field is required."; return; } else if (receivedAmountTextBox.Text.Trim() == "" && customerIdDropDownList.SelectedIndex == 1) { msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Received Amount field is required."; return; } else if (changeAmountTextBox.Text.Trim() == "") { msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Change Amount field is required."; return; } else if (customerIdDropDownList.SelectedItem.Text.Trim() == "Retail" && Convert.ToDecimal(receivableAmountTextBox.Text) > Convert.ToDecimal(receivedAmountTextBox.Text) && customerNameTextBox.Text == "" && customerContactNumberTextBox.Text == "") { msgbox.Visible = true; msgTitleLabel.Text = "Warning!!!"; msgDetailLabel.Text = "Can not sale Retail on Due please select Customer."; return; } else if ((paymentModeDropDownList.SelectedValue == "Cheque" && chequeNumberTextBox.Text == "") || (paymentModeDropDownList.SelectedValue == "Cheque" && chequeDateTextBox.Text == "")) { //if (chequeNumberTextBox.Text == "" || chequeDateTextBox.Text == "") //{ msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Cheque Number Or Cheque Date field is Required."; return; // } } //if (string.IsNullOrEmpty(DuesAmoutPayTextBox.Text)) //{ // DuesAmoutPayTextBox.Text = "0"; //} else { if (receivedAmountTextBox.Text == "") { receivedAmountTextBox.Text = "0"; } salesOrder.SalesCenterId = ddlSelectWareHouseOrSalesCenter.SelectedValue.Trim(); salesOrder.CustomerId = customerIdDropDownList.SelectedValue.Trim(); salesOrder.CustomerName = customerNameTextBox.Text.Trim(); salesOrder.CustomerContactNumber = customerContactNumberTextBox.Text.Trim(); salesOrder.CustomerAddress = customerAddressTextBox.Text.Trim(); salesOrder.TotalAmount = totalAmountTextBox.Text.Trim(); salesOrder.DiscountAmount = discountTextBox.Text.Trim(); salesOrder.VAT = vatTextBox.Text.Trim(); salesOrder.TotalReceivable = receivableAmountTextBox.Text.Trim(); salesOrder.Due = "0";//DuesAmoutPayTextBox.Text; salesOrder.SalesOrderId = ""; salesOrder.ReceivedAmount = receivedAmountTextBox.Text.Trim(); salesOrder.ChangeAmount = (Convert.ToDecimal(salesOrder.ReceivedAmount) - Convert.ToDecimal(salesOrder.TotalReceivable)).ToString(); salesOrder.TotalVATAmount = totalVATAmountHiddenField.Value; salesOrder.AccountId = accountHeadDropDownList.SelectedValue; salesOrder.CustomerId = customerIdDropDownList.SelectedValue.Trim(); salesOrder.PaymentMode = paymentModeDropDownList.SelectedValue; // receivePayment.Amount = receivedAmountTextBox.Text.Trim(); salesOrder.Bank = bankDropDownList.Text; salesOrder.BankBranch = bankBranchTextBox.Text; salesOrder.ChequeNumber = chequeNumberTextBox.Text; salesOrder.ChequeDate = LumexLibraryManager.ParseAppDate(chequeDateTextBox.Text); salesOrder.OthersDes = txtbxDescription.Text; salesOrder.OthersAmount = txtbxOthersAmount.Text; salesOrder.Narration = txtbxNarration.Text; if (dtPrdList.Rows.Count == selectedProductListGridView.Rows.Count) { string salesRecordId = salesOrder.SaveRetailSales(dtPrdList); if (salesRecordId != "") { IPOSReportBLL iposReport = new IPOSReportBLL(); iposReport.GetSalesInvoiceBySalesRecord(salesRecordId, salesOrder.SalesCenterId); ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "ViewReportForm();", true); string message = "Product's <span class='actionTopic'>Sales</span> Successfully with Sale ID: <span class='actionTopic'>" + salesRecordId + "</span>."; MyAlertBox("var callbackOk = function () { MyOverlayStart(); window.location = \"/UI/Sales/RetailSales.aspx\"; }; SuccessAlert(\"" + "Process Succeed" + "\", \"" + message + "\", callbackOk);"); } else { string message = "Product's <span class='actionTopic'>Sales</span> Falied" + salesRecordId + "</span>."; MyAlertBox("var callbackOk = function () { MyOverlayStart(); window.location = \"/UI/Sales/RetailSales.aspx\"; }; SuccessAlert(\"" + "Process Succeed" + "\", \"" + message + "\", callbackOk);"); } } } } catch (Exception ex) { string message = ex.Message; if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; } MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");"); } finally { salesOrder = null; dtPrdList = null; } }