Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                //Set the cursor to appear as busy
                Cursor.Current = Cursors.WaitCursor;

                Choice               choice;
                LocalCentral         localCentral;
                CustomerLedgerMaster customerLedgerMaster = new CustomerLedgerMaster();

                if (String.IsNullOrWhiteSpace(txtCustSupplierName.Text))
                {
                    MessageBox.Show("Customer Name " + Constants.Messages.RequiredField);
                    return;
                }

                customerLedgerMaster.CustomerLedgerId = this.customerLedgerID;

                //values from User Control
                customerLedgerMaster.CustomerLedgerName      = txtCustSupplierName.Text;
                customerLedgerMaster.CustomerLedgerShortName = txtShortName.Text;
                customerLedgerMaster.Address       = txtAddress.Text;
                customerLedgerMaster.ContactPerson = txtContactPerson.Text;
                customerLedgerMaster.Telephone     = txtTelephone.Text;
                customerLedgerMaster.Mobile        = txtMobile.Text;
                customerLedgerMaster.OfficePhone   = txtPhoneO.Text;
                customerLedgerMaster.ResidentPhone = txtPhoneR.Text;
                customerLedgerMaster.EmailAddress  = txtEmailAddress.Text;
                customerLedgerMaster.OpeningBal    = ExtensionMethods.SafeConversionDecimal(txtOpeningBal.Text);
                customerLedgerMaster.CreditDebit   = Convert.ToString(cbxCreditDebit.SelectedItem);
                customerLedgerMaster.TaxRetail     = Convert.ToString(cbxTaxRetail.SelectedItem);
                customerLedgerMaster.Status        = Convert.ToBoolean(cbxStatus.SelectedItem);

                //values from User this form
                customerLedgerMaster.ZSMId      = String.IsNullOrWhiteSpace(tbxZSM.Text) ? null : (int?)tbxZSM.Tag;
                customerLedgerMaster.RSMId      = String.IsNullOrWhiteSpace(tbxRSM.Text) ? null : (int?)tbxRSM.Tag;
                customerLedgerMaster.ASMId      = String.IsNullOrWhiteSpace(tbxASM.Text) ? null : (int?)tbxASM.Tag;
                customerLedgerMaster.AreaId     = String.IsNullOrWhiteSpace(tbxSalesman.Text) ? null : (int?)tbxSalesman.Tag;
                customerLedgerMaster.SalesManId = String.IsNullOrWhiteSpace(tbxArea.Text) ? null : (int?)tbxArea.Tag;
                customerLedgerMaster.RouteId    = String.IsNullOrWhiteSpace(tbxRoute.Text) ? null : (int?)tbxRoute.Tag;

                customerLedgerMaster.DLNo           = tbxDL.Text;
                customerLedgerMaster.GSTNo          = tbxGST.Text;
                customerLedgerMaster.CINNo          = tbxCIN.Text;
                customerLedgerMaster.LINNo          = tbxLIN.Text;
                customerLedgerMaster.ServiceTaxNo   = tbxServiceTax.Text;
                customerLedgerMaster.PANNo          = tbxPAN.Text;
                customerLedgerMaster.CreditLimit    = ExtensionMethods.SafeConversionInt(tbxCredtLimit.Text) ?? default(int);
                customerLedgerMaster.CustomerTypeID = (cbxCustomerType.SelectedItem as CustomerType).CustomerTypeId;

                Enum.TryParse <Choice>(cbxLessExcise.SelectedValue.ToString(), out choice);
                customerLedgerMaster.IsLessExcise = choice == Choice.Yes;

                customerLedgerMaster.InterestTypeID = (cbxRateType.SelectedItem as RateType).RateTypeId;

                customerLedgerMaster.SaleBillFormat = tbxSaleBillFormat.Text;

                customerLedgerMaster.MaxOSAmount    = ExtensionMethods.SafeConversionDecimal(tbxMaxOSAmount.Text);
                customerLedgerMaster.MaxBillAmount  = ExtensionMethods.SafeConversionDecimal(tbxMaxBillAmmount.Text);
                customerLedgerMaster.MaxNumOfOSBill = ExtensionMethods.SafeConversionInt(tbxMaxNumberOfOSBill.Text);
                customerLedgerMaster.MaxGracePeriod = ExtensionMethods.SafeConversionInt(tbxMaxGracePeriod.Text);

                Enum.TryParse <Choice>(cbxFollowConditionStrictly.SelectedValue.ToString(), out choice);
                customerLedgerMaster.IsFollowConditionStrictly = choice == Choice.Yes;

                customerLedgerMaster.Discount = ExtensionMethods.SafeConversionDecimal(tbxDiscount.Text);

                Enum.TryParse <LocalCentral>(cbxLocaLCentral.SelectedValue.ToString(), out localCentral);
                customerLedgerMaster.CentralLocal = localCentral == LocalCentral.L ? "L" : "C";

                ///Get All the mapping for Company discount
                ///
                customerLedgerMaster.CustomerCopanyDiscountList = dgvCompanyDiscount.Rows
                                                                  .Cast <DataGridViewRow>()
                                                                  .Where(r => !String.IsNullOrWhiteSpace(Convert.ToString(r.Cells["Normal"].Value)) ||
                                                                         !String.IsNullOrWhiteSpace(Convert.ToString(r.Cells["Breakage"].Value)) ||
                                                                         !String.IsNullOrWhiteSpace(Convert.ToString(r.Cells["Expired"].Value))
                                                                         ).Select(x => new CustomerCopanyDiscount()
                {
                    CompanyID = (x.DataBoundItem as CustomerCopanyDiscount).CompanyID,
                    Normal    = (x.DataBoundItem as CustomerCopanyDiscount).Normal,
                    Breakage  = (x.DataBoundItem as CustomerCopanyDiscount).Breakage,
                    Expired   = (x.DataBoundItem as CustomerCopanyDiscount).Expired,
                    CustomerItemDiscountMapping = (x.DataBoundItem as CustomerCopanyDiscount).CustomerItemDiscountMapping
                }).ToList();


                int _result = 0;

                if (isInEditMode)
                {
                    _result = applicationFacade.UpdateCustomerLedger(customerLedgerMaster);
                }
                else
                {
                    _result = applicationFacade.AddCustomerLedger(customerLedgerMaster);
                }

                //Make the Cursor to default
                Cursor.Current = Cursors.Default;

                if (_result > 0)
                {
                    this.Close();
                }
                else
                {
                    MessageBox.Show(Constants.Messages.ErrorOccured);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }