private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtCustSupplierName.Text))
                {
                    throw new Exception("Supplier Name can not be blank");
                }

                //Set the cursor to appear as busy
                Cursor.Current = Cursors.WaitCursor;

                Status status;
                //  int areaId = 0;
                decimal openingBal = 0.00M;

                SupplierLedgerMaster supplier = new SupplierLedgerMaster();
                supplier.SupplierLedgerCode      = txtCode.Text;
                supplier.SupplierLedgerName      = txtCustSupplierName.Text;
                supplier.SupplierLedgerShortName = txtShortName.Text;
                supplier.Address       = txtAddress.Text;
                supplier.ContactPerson = txtContactPerson.Text;
                Enum.TryParse <Status>(cbxStatus.SelectedItem.ToString(), out status);
                supplier.Status      = status == Status.Active;
                supplier.CreditDebit = (Enums.TransType)cbxCreditDebit.SelectedItem == Enums.TransType.C ? "C" : "D";

                supplier.AreaId       = Convert.ToInt32(tbxArea.Tag);
                supplier.EmailAddress = txtEmailAddress.Text;
                supplier.Mobile       = txtMobile.Text;
                supplier.OfficePhone  = txtPhoneO.Text;

                int purchaseTypeId = 0;
                Int32.TryParse(Convert.ToString(cbxPurchaseType.SelectedValue), out purchaseTypeId);
                supplier.PurchaseTypeId = purchaseTypeId;

                decimal.TryParse(txtOpeningBal.Text, out openingBal);
                supplier.OpeningBal       = openingBal;
                supplier.ResidentPhone    = txtPhoneR.Text;
                supplier.TaxRetail        = (Enums.TaxRetail)cbxTaxRetail.SelectedItem == TaxRetail.R ? "R" : "T";
                supplier.SupplierLedgerId = SupplierId;

                supplier.DLNo         = tbxDL.Text;
                supplier.GSTNo        = tbxGST.Text;
                supplier.CINNo        = tbxCIN.Text;
                supplier.LINNo        = tbxLIN.Text;
                supplier.ServiceTaxNo = tbxServiceTax.Text;
                supplier.PANNo        = tbxPAN.Text;

                ///Get All the mapping for Company discount
                ///
                supplier.SupplierCompanyDiscountList = 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 SupplierCompanyDiscount()
                {
                    CompanyID = (x.DataBoundItem as SupplierCompanyDiscount).CompanyID,
                    Normal    = (x.DataBoundItem as SupplierCompanyDiscount).Normal,
                    Breakage  = (x.DataBoundItem as SupplierCompanyDiscount).Breakage,
                    Expired   = (x.DataBoundItem as SupplierCompanyDiscount).Expired,
                    SupplierItemDiscountMapping = (x.DataBoundItem as SupplierCompanyDiscount).SupplierItemDiscountMapping
                }).ToList();


                int result = SupplierId > 0 ? applicationFacade.UpdateSupplierLedger(supplier) : applicationFacade.AddSupplierLedger(supplier);

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

                //Close this form if operation is successful
                if (result > 0)
                {
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }