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; int i = 0; dtPrdList.Columns.Add("ProductId"); dtPrdList.Columns.Add("Available"); dtPrdList.Columns.Add("Quantity"); dtPrdList.Columns.Add("RatePerUnit"); dtPrdList.Columns.Add("LastUnitPrice"); dtPrdList.Columns.Add("Amount"); try { for (i = 0; i < selectedProductListGridView.Rows.Count; i++) { orderQuantityTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("orderQuantityTextBox"); ratePerUnitTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("ratePerUnitTextBox"); amountTextBox = (TextBox)selectedProductListGridView.Rows[i].FindControl("amountTextBox"); if (string.IsNullOrEmpty(orderQuantityTextBox.Text.Trim()) || !decimal.TryParse(orderQuantityTextBox.Text.Trim(), out quantity)) { msg = "Product ID [" + selectedProductListGridView.Rows[i].Cells[1].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[1].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[1].Text.ToString() + "] has no valid amount."; msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg; return; } else { dr = dtPrdList.NewRow(); dr["ProductId"] = selectedProductListGridView.Rows[i].Cells[1].Text.ToString(); dr["Available"] = selectedProductListGridView.Rows[i].Cells[3].Text.ToString(); dr["Quantity"] = quantity.ToString(); dr["RatePerUnit"] = rate.ToString(); dr["LastUnitPrice"] = selectedProductListGridView.Rows[i].Cells[7].Text.ToString(); dr["Amount"] = amount.ToString(); dtPrdList.Rows.Add(dr); } } if (totalAmountTextBox.Text.Trim() == "") { msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Total Amount field is required."; return; } salesOrder.SalesCenterId = salesCenterDropDownList.SelectedValue; salesOrder.TotalAmount = totalAmountTextBox.Text.Trim(); if (dtPrdList.Rows.Count == selectedProductListGridView.Rows.Count) { string damageRecordId = ""; //if (chkatDropdownList.SelectedValue == "SC") //{ // damageRecordId= salesOrder.SaveDamageProduct(dtPrdList); // //MyAlertBox("alert(\"Retail Sales Created Successfully with Sales ID: " + damageRecordId.Trim() + " \"); window.location=\"/UI/Sales/RetailSalesList.aspx\""); // //Response.Redirect("/UI/DamageRecord/DamageRecordList.aspx", false); //} //else if (chkatDropdownList.SelectedValue == "WH") //{ damageRecordId = salesOrder.SaveWarehouseDamageProduct(dtPrdList); string message = "Damage Product Record <span class='actionTopic'>Created</span> Successfully with Damage Record ID: <span class='actionTopic'>" + damageRecordId + "</span>."; MyAlertBox("var callbackOk = function () { MyOverlayStart(); window.location = \"/UI/DamageRecord/DamageRecordList.aspx\"; }; SuccessAlert(\"" + "Process Succeed" + "\", \"" + message + "\", callbackOk);"); } } catch (Exception ex) { msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = ex.Message; } finally { salesOrder = null; dtPrdList = null; } }