Ejemplo n.º 1
0
        //Will Copy the method
        protected void btnAccept_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 approveQuantityTextbox;
            TextBox rateTextBox;
            TextBox amountAndVatTextBox;
            int i = 0;

            dtPrdList.Columns.Add("ProductId");
            dtPrdList.Columns.Add("Quantity");
            dtPrdList.Columns.Add("RatePerUnit");
            dtPrdList.Columns.Add("VATPercentage");
            dtPrdList.Columns.Add("Amount");
            dtPrdList.Columns.Add("Height");
            dtPrdList.Columns.Add("Running");
            dtPrdList.Columns.Add("OnSale");

            try
            {
                for (i = 0; i < salesOrderProductListGridView.Rows.Count; i++)
                {
                    approveQuantityTextbox = (TextBox)salesOrderProductListGridView.Rows[i].FindControl("orderQuantityTextBox");
                    rateTextBox = (TextBox)salesOrderProductListGridView.Rows[i].FindControl("ratePerUnitTextBox");
                    amountAndVatTextBox = (TextBox)salesOrderProductListGridView.Rows[i].FindControl("amountTextBox");

                    if (string.IsNullOrEmpty(approveQuantityTextbox.Text.Trim()) || !decimal.TryParse(approveQuantityTextbox.Text.Trim(), out quantity))
                    {
                        msg = "Product ID [" + salesOrderProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid quantity.";
                        msgbox.Visible = true; msgTitleLabel.Text = "Warning!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    else if (string.IsNullOrEmpty(rateTextBox.Text.Trim()) || !double.TryParse(rateTextBox.Text.Trim(), out rate))
                    {
                        msg = "Product ID [" + salesOrderProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid rate.";
                        msgbox.Visible = true; msgTitleLabel.Text = "Warning!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    else if (string.IsNullOrEmpty(amountAndVatTextBox.Text.Trim()) || !double.TryParse(amountAndVatTextBox.Text.Trim(), out amount))
                    {
                        msg = "Product ID [" + salesOrderProductListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid amount.";
                        msgbox.Visible = true; msgTitleLabel.Text = "Warning!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    else
                    {
                        dr = dtPrdList.NewRow();

                        dr["ProductId"] = salesOrderProductListGridView.Rows[i].Cells[0].Text.ToString();
                        //dr["Available"] = salesOrderProductListGridView.Rows[i].Cells[3].Text.ToString();
                        dr["Quantity"] = quantity.ToString();
                        dr["RatePerUnit"] = rate.ToString();
                        dr["VATPercentage"] = salesOrderProductListGridView.Rows[i].Cells[7].Text.ToString();
                        dr["Amount"] = amount.ToString();
                        dr["Height"] = "0.00";
                        dr["Running"] = "0.00";
                        dr["OnSale"] = "0.00";

                        dtPrdList.Rows.Add(dr);
                    }
                }

                if (totalAmountLabel.Text.Trim() == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Warning!!!"; msgDetailLabel.Text = "Total Amount field is required.";
                    return;
                }
                //else if (vatLabel.Text.Trim() == "")
                //{
                //    msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "VAT field is required.";
                //    return;
                //}
                else if (totalReceivableLabel.Text.Trim() == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Warning!!!"; msgDetailLabel.Text = "Total Receivable field is required.";
                    return;
                }
                if (string.IsNullOrEmpty(vatLabel.Text))
                {
                    vatLabel.Text = "0";
                }
                salesOrder.SalesOrderId = orderIdLabel.Text.Trim();
                salesOrder.SalesCenterId = salesCenterIdLabel.Text.Trim();
                salesOrder.TotalAmount = totalAmountLabel.Text.Trim();
                salesOrder.DiscountAmount = discountAmntLabel.Text.Trim();
                salesOrder.VAT = vatLabel.Text.Trim();
                salesOrder.TotalReceivable = totalReceivableLabel.Text.Trim();
                salesOrder.TotalVATAmount = VATamntLabel.Text.Trim();
                salesOrder.PaymentMode = paymentModeLabel.Text;
                salesOrder.ChangeAmount = hdnfildChangeAmount.Value;
                salesOrder.ReceivedAmount = receivedAmountLabel.Text.Trim();
                //salesOrder.height = txtbxHeight.Text.Trim();
                //salesOrder.width=txtbxWidth.Text.Trim();
                //salesOrder.onSale = txtbxOnSale.Text.Trim();

               

                if (dtPrdList.Rows.Count == salesOrderProductListGridView.Rows.Count)
                {
                    //  string salesRecordId = salesOrder.SaveRetailSales(dtPrdList);
                    string salesRecordId = salesOrder.ApproveSalesOrder(dtPrdList);
                    salesOrder.UpdateSalesOrderOnApproved(salesRecordId, salesOrder.SalesOrderId);

                    if (!string.IsNullOrEmpty(salesRecordId))
                    {

                        string message =
                            "Product's <span class='actionTopic'>Sales Recorded</span> Successfully with Sale ID: <span class='actionTopic'>" +
                            salesRecordId + "</span>.";
                        MyAlertBox(
                            "var callbackOk = function () { MyOverlayStart(); window.location = \"/UI/SalesOrder/SalesOrderList.aspx\"; }; SuccessAlert(\"" +
                            "Process Succeed" + "\", \"" + message + "\", callbackOk);");
                        //}
                        //MyAlertBox("alert(\"Retail Sales Created Successfully with Sales ID: " + salesRecordId.Trim() + " \"); window.location=\"/UI/Sales/RetailSalesList.aspx\"");
                        //Response.Redirect("/UI/Sales/RetailSalesList.aspx", false);
                    }
                }
            }

            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;
            }
        }