示例#1
0
 /// <summary>
 /// Function to use the Combo Selection By using InvoiceNo
 /// </summary>
 public void ComboSelectionByInvoiceNo()
 {
     DataTable dtblComboSelection = new DataTable();
     SalesReturnMasterSP spSalesReturnMaster = new SalesReturnMasterSP();
     try
     {
         if (!isEnterIntoComboSelectn == false)
         {
             if (cmbInvoiceNo.SelectedIndex != -1)
             {
                 if (cmbInvoiceNo.SelectedValue.ToString() != "System.Data.DataRowView" && cmbInvoiceNo.Text != "System.Data.DataRowView")
                 {
                     DGVGodownComboFill();
                     DGVUnitComboFill();
                     decTotalAmounForSaveCheck = 0;
                     SalesMasterSP spSaleMaster = new SalesMasterSP();
                     dgvSalesReturn.Rows.Clear();
                     dtblComboSelection = spSaleMaster.SalesMasterViewByInvoiceNoForComboSelection(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()));
                     if (dtblComboSelection != null)
                     {
                         cmbPricingLevel.SelectedValue = dtblComboSelection.Rows[0]["pricingLevelId"];
                         cmbSalesAccount.SelectedValue = dtblComboSelection.Rows[0]["salesAccount"];
                         cmbSalesAccount.Enabled = true;
                         txtTransportationComp.Text = dtblComboSelection.Rows[0]["transportationCompany"].ToString();
                         txtLRNo.Text = dtblComboSelection.Rows[0]["lrNo"].ToString();
                     }
                     DataTable dtblSalesReturnGrideFill = spSalesDetails.SalesDetailsViewForSalesReturnGrideFill(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()), salesReturnMasterId);
                     dtblSalesInvoice = dtblSalesReturnGrideFill;
                     foreach (DataRow drowDetails in dtblSalesReturnGrideFill.Rows)
                     {
                         decimal decproductId = Convert.ToDecimal(drowDetails["productId"].ToString());
                         TaxGridFill();
                         dgvSalesReturn.Rows.Add();
                         if (drowDetails["S.No"].ToString() != string.Empty)
                         {
                             dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvSNo"].Value = drowDetails["S.No"].ToString();
                         }
                         if (drowDetails["salesDetailsId"].ToString() != string.Empty)
                         {
                             dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesDetailsId"].Value = drowDetails["salesDetailsId"].ToString();
                         }
                         else
                         {
                             dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesDetailsId"].Value = 0;
                         }
                         if (drowDetails["productId"].ToString() != string.Empty)
                         {
                             dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value = drowDetails["productId"].ToString();
                             DataTable dtbl = spSalesDetails.SalesDetailsViewForSalesReturnGrideFill1(Convert.ToDecimal(drowDetails["productId"].ToString()));
                             foreach (DataRow drowDetails1 in dtbl.Rows)
                             {
                                 if (dtblComboSelection.Rows[0]["voucherTypeId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["voucherTypeId"].Value = Convert.ToDecimal(dtblComboSelection.Rows[0]["voucherTypeId"].ToString());
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["voucherTypeId"].Value = 0;
                                 }
                                 if (dtblComboSelection.Rows[0]["voucherNo"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["voucherNo"].Value = dtblComboSelection.Rows[0]["voucherNo"].ToString();
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["voucherNo"].Value = 0;
                                 }
                                 if (dtblComboSelection.Rows[0]["invoiceNo"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["invoiceNo"].Value = dtblComboSelection.Rows[0]["invoiceNo"].ToString();
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["invoiceNo"].Value = 0;
                                 }
                                 if (drowDetails1["barcode"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextBarcode"].Value = drowDetails1["barcode"].ToString();
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextBarcode"].ReadOnly = true;
                                 }
                                 if (drowDetails1["productCode"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductCode"].Value = drowDetails1["productCode"].ToString();
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductCode"].ReadOnly = true;
                                 }
                                 if (drowDetails1["productName"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductName"].Value = drowDetails1["productName"].ToString();
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductName"].ReadOnly = true;
                                 }
                                 if (drowDetails["unitId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].ReadOnly = true;
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].Value = 1;
                                 }
                                 if (drowDetails["goDownId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value = Convert.ToDecimal(drowDetails["goDownId"].ToString());
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].ReadOnly = false;
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value = 1;
                                 }
                                 RackComboFill(Convert.ToDecimal(dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value), dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].ColumnIndex);
                                 if (drowDetails["rackId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].Value = Convert.ToDecimal(drowDetails["rackId"].ToString());
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].Value = 1;
                                 }
                                 BatchComboFill(Convert.ToDecimal(dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value), dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].ColumnIndex);
                                 if (drowDetails["batchId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].ReadOnly = true;
                                 }
                                 if (drowDetails["unitConversionId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["unitConversionId"].Value = drowDetails["unitConversionId"].ToString();
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["unitConversionId"].Value = 0;
                                 }
                                 dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["conversionRate"].Value = drowDetails["conversionRate"].ToString();
                                 if (drowDetails["taxId"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTaxId"].Value = 0;
                                     if (Convert.ToDecimal(drowDetails["taxId"].ToString()) != 0)
                                     {
                                         dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTaxId"].Value = Convert.ToDecimal(drowDetails["taxId"].ToString());
                                         dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value = Convert.ToDecimal(drowDetails["taxId"].ToString());
                                         strTaxRate = spSalesReturnMaster.TaxRateFindForTaxAmmountCalByTaxId(Convert.ToDecimal(drowDetails["taxId"].ToString()));
                                     }
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value = 1;
                                 }
                                 if (drowDetails["qty"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextQty"].Value = Math.Round(Convert.ToDecimal(drowDetails["qty"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                     decQty = Math.Round(Convert.ToDecimal(drowDetails["qty"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextQty"].Value = 0;
                                     decQty = 0;
                                 }
                                 if (drowDetails["rate"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextRate"].Value = Convert.ToDecimal(drowDetails["rate"].ToString());
                                     decRate = Convert.ToDecimal(drowDetails["rate"].ToString());
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextRate"].Value = 0.00;
                                     decRate = 0;
                                 }
                                 if (drowDetails["grossAmount"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].Value = Math.Round(Convert.ToDecimal(drowDetails["grossAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = true;
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].Value = 0.00;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = true;
                                 }
                                 if (drowDetails["discount"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountPercentage"].Value = 0.00;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountAmount"].Value = Math.Round(Convert.ToDecimal(drowDetails["discount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountAmount"].Value = 0.00;
                                 }
                                 if (drowDetails["netAmount"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].Value = Math.Round(Convert.ToDecimal(drowDetails["netAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = true;
                                     txtBillDiscount.Text = "0.00";
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].Value = 0.00;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = true;
                                 }
                                 if (drowDetails["taxAmount"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value = Math.Round(Convert.ToDecimal(drowDetails["taxAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = false;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value = 0.00;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = true;
                                 }
                                 if (drowDetails["amount"].ToString() != string.Empty)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].Value = Math.Round(Convert.ToDecimal(drowDetails["amount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].ReadOnly = true;
                                 }
                                 else
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].Value = 0.00;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].ReadOnly = true;
                                 }
                                 if (cmbInvoiceNo.Visible == true)
                                 {
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextBarcode"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextProductCode"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextProductName"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextQty"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbUnit"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbGodown"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbRack"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbBatch"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextRate"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextDiscountPercentage"].ReadOnly = true;
                                     dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbTax"].ReadOnly = true;
                                 }
                                 foreach (DataGridViewRow item1 in dgvSalesReturn2.Rows)
                                 {
                                     if (item1.Cells["dgvTextTaxId"].Value != null)
                                     {
                                         if (dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value != null && dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value.ToString() != string.Empty)
                                         {
                                             if (dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value.ToString() == item1.Cells["dgvTextTaxId"].Value.ToString())
                                             {
                                                 item1.Cells["dgvTextAmount"].Value = dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         else
                         {
                             dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["productId"].Value = 0;
                         }
                     }
                     txtNarration.Text = dtblComboSelection.Rows[0]["narration"].ToString();
                     GrossValueCalculation(dgvSalesReturn.Rows.Count - 2);
                     DiscountCalculationfordiscountpercentage(dgvSalesReturn.Rows.Count - 2, 12);
                     DiscountCalculation(dgvSalesReturn.Rows.Count - 2, 13);
                     TaxAmountCalculation(dgvSalesReturn.Rows.Count - 2);
                     TotalAmtCalculation();
                     TotalBillTaxCalculation();
                     GrandTotalCalculation();
                     taxamountfill();
                     taxAndGridTotalAmountCalculation(dgvSalesReturn.Rows.Count - 2);
                     CessTaxamountCalculation();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SR46:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
示例#2
0
        /// <summary>
        /// FunctionToreturn fromregisterclick
        /// </summary>
        public void FillRegisterOrReport()
        {
            SalesReturnMasterSP spSalesReturnMaster = new SalesReturnMasterSP();
            SalesReturnDetailsSP spSalesReturnDetails = new SalesReturnDetailsSP();
            try
            {
                isFromOther = true;
                btnSave.Text = "Update";
                btnDelete.Enabled = true;
                CashOrPartyUnderSundryDebitorComboFill(cmbCashOrParty);
                DataTable dtblSalesMaster = new DataTable();
                DataTable dtblSalesReturnMaster = new DataTable();
                dtblSalesReturnMaster = spSalesReturnMaster.SalesReturnMasterViewBySalesReturnMasterId(salesReturnMasterId);
                decSalesReturnMasterId = salesReturnMasterId;
                DecSalesReturnVoucherTypeId = Convert.ToDecimal(dtblSalesReturnMaster.Rows[0]["voucherTypeId"].ToString());
                VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
                infoVoucherType = spVoucherType.VoucherTypeView(DecSalesReturnVoucherTypeId);
                this.Text = infoVoucherType.VoucherTypeName;
                if (infoVoucherType.MethodOfVoucherNumbering == "Manual")
                {
                    txtReturnNo.Text = dtblSalesReturnMaster.Rows[0]["invoiceNo"].ToString();
                    ManualReturnNo = dtblSalesReturnMaster.Rows[0]["invoiceNo"].ToString();
                    txtReturnNo.Enabled = true;
                }
                else
                {
                    txtReturnNo.Text = dtblSalesReturnMaster.Rows[0]["invoiceNo"].ToString();
                    txtReturnNo.Enabled = false;
                }
                if (dtblSalesReturnMaster.Rows.Count > 0)
                {
                    txtDate.Text = dtblSalesReturnMaster.Rows[0]["date"].ToString();
                    dtpDate.Value = Convert.ToDateTime(txtDate.Text);
                    if (dtblSalesReturnMaster.Rows[0]["grandTotal"].ToString() != string.Empty)
                    {
                        txtGrandTotal.Text = dtblSalesReturnMaster.Rows[0]["grandTotal"].ToString();
                    }
                    strVoucherNo = dtblSalesReturnMaster.Rows[0]["voucherNo"].ToString();
                    if (dtblSalesReturnMaster.Rows[0]["ledgerId"].ToString() != string.Empty)
                    {
                        cmbCashOrParty.SelectedValue = dtblSalesReturnMaster.Rows[0]["ledgerId"].ToString();
                    }
                    cmbVoucherTypeComboFill();
                    if (dtblSalesReturnMaster.Rows[0]["SMVoucherTypeId"].ToString() != string.Empty)
                    {
                        cmbVoucherType.SelectedValue = dtblSalesReturnMaster.Rows[0]["SMVoucherTypeId"].ToString();
                    }
                    else
                    {
                        cmbVoucherType.SelectedValue = 0;
                    }
                    cmbInvoiceComboFill();
                    if (dtblSalesReturnMaster.Rows[0]["pricingLevelId"].ToString() != string.Empty)
                    {
                        cmbPricingLevel.SelectedValue = dtblSalesReturnMaster.Rows[0]["pricingLevelId"].ToString();
                    }
                    if (dtblSalesReturnMaster.Rows[0]["salesAccount"].ToString() != string.Empty)
                    {
                        cmbSalesAccount.SelectedValue = dtblSalesReturnMaster.Rows[0]["salesAccount"].ToString();
                    }
                    if (dtblSalesReturnMaster.Rows[0]["employeeId"].ToString() != string.Empty)
                    {
                        cmbSalesMan.SelectedValue = dtblSalesReturnMaster.Rows[0]["employeeId"].ToString();
                    }
                    if (dtblSalesReturnMaster.Rows[0]["exchangeRateId"].ToString() != string.Empty)
                    {
                        cmbCurrency.SelectedValue = dtblSalesReturnMaster.Rows[0]["exchangeRateId"].ToString();
                    }
                    txtNarration.Text = dtblSalesReturnMaster.Rows[0]["narration"].ToString();
                    txtLRNo.Text = dtblSalesReturnMaster.Rows[0]["lrNo"].ToString();
                    txtTransportationComp.Text = dtblSalesReturnMaster.Rows[0]["transportationCompany"].ToString();
                    if (dtblSalesReturnMaster.Rows[0]["salesMasterId"].ToString() != string.Empty && Convert.ToDecimal(dtblSalesReturnMaster.Rows[0]["salesMasterId"].ToString()) != 0)
                    {
                        cmbInvoiceNo.SelectedValue = dtblSalesReturnMaster.Rows[0]["salesMasterId"].ToString();
                        decinvoiceno = Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString());
                        dtblSalesReturnMasterViewBySMID = spSalesReturnMaster.SalesReturnMasterViewBySalesMasterId(Convert.ToDecimal(dtblSalesReturnMaster.Rows[0]["salesMasterId"].ToString()));
                    }
                    isInvoiceFill = false;
                    if (dtblSalesReturnMaster.Rows[0]["voucherTypeId"].ToString() != string.Empty)
                    {
                        decSalesReturnVoucherTypeId = Convert.ToDecimal(dtblSalesReturnMaster.Rows[0]["voucherTypeId"].ToString());
                    }
                    TaxGridFill();
                    if (cmbInvoiceNo.SelectedValue != null)
                    {
                        infoSalesMaster = spSalesMaster.SalesMasterViewBySalesMasterId(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()));
                    }
                    DataTable dtblSalesReturnDetails = new DataTable();
                    dtblSalesReturnDetails = spSalesReturnDetails.SalesReturnDetailsViewBySalesReturnMasterId(salesReturnMasterId);
                    dtblSalesInvoice = dtblSalesReturnDetails;
                    foreach (DataRow drowDetails in dtblSalesReturnDetails.Rows)
                    {
                        dgvSalesReturn.Rows.Add();
                        if (drowDetails["salesReturnDetailsId"].ToString() != string.Empty)
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesReturnDetailsId"].Value = Convert.ToDecimal(drowDetails["salesReturnDetailsId"].ToString());
                        }
                        if (drowDetails["salesDetailsId"].ToString() != string.Empty)
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesDetailsId"].Value = drowDetails["salesDetailsId"].ToString();
                        }
                        else
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["salesDetailsId"].Value = 0;
                        }
                        if (drowDetails["productId"].ToString() != string.Empty)
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value = drowDetails["productId"].ToString();
                            DataTable dtbl = spSalesDetails.SalesReturnGrideFillNewByProductId(Convert.ToDecimal(drowDetails["productId"].ToString()));
                            foreach (DataRow drowDetails1 in dtbl.Rows)
                            {
                                if (drowDetails1["barcode"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextBarcode"].Value = drowDetails1["barcode"].ToString();
                                }
                                if (drowDetails1["productCode"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductCode"].Value = drowDetails1["productCode"].ToString();
                                }
                                if (drowDetails1["productName"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextProductName"].Value = drowDetails1["productName"].ToString();
                                }
                                if (cmbInvoiceNo.Visible == true)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].ReadOnly = true;
                                }
                                if (drowDetails["unitId"].ToString() != string.Empty)
                                {
                                    decProductId = decimal.Parse(dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value.ToString());
                                    UnitComboFill(decProductId, dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].ColumnIndex);
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbUnit"].Value = 1;
                                }
                                if (drowDetails["goDownId"].ToString() != string.Empty)
                                {
                                    DGVGodownComboFill();
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value = Convert.ToDecimal(drowDetails["goDownId"].ToString());
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value = 1;
                                }
                                if (drowDetails["rackId"].ToString() != string.Empty)
                                {
                                    RackComboFill(Convert.ToDecimal(dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbGodown"].Value.ToString()), dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].ColumnIndex);
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].Value = Convert.ToDecimal(drowDetails["rackId"].ToString());
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbRack"].Value = 1;
                                }
                                if (drowDetails["batchId"].ToString() != string.Empty)
                                {
                                    BatchComboFill(decProductId, dgvSalesReturn.Rows.Count - 2, dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].ColumnIndex);
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                                }
                                if (drowDetails["unitConversionId"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["unitConversionId"].Value = drowDetails["unitConversionId"].ToString();
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["unitConversionId"].Value = 0;
                                }
                                if (dtblSalesReturnMaster.Rows[0]["SMVoucherTypeId"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbBatch"].ReadOnly = true;
                                }
                                if (drowDetails["taxId"].ToString() != string.Empty)
                                {
                                    if (Convert.ToDecimal(drowDetails["taxId"].ToString()) != 0)
                                    {
                                        dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTaxId"].Value = Convert.ToDecimal(drowDetails["taxId"].ToString());
                                        dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value = Convert.ToDecimal(drowDetails["taxId"].ToString());
                                        strTaxRate = spSalesReturnMaster.TaxRateFindForTaxAmmountCalByTaxId(Convert.ToDecimal(drowDetails["taxId"].ToString()));
                                    }
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value = 1;
                                }
                                if (drowDetails["qty"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextQty"].Value = Math.Round(Convert.ToDecimal(drowDetails["qty"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    decQty = Math.Round(Convert.ToDecimal(drowDetails["qty"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextQty"].Value = 0.00;
                                    decQty = 0;
                                }
                                if (drowDetails["rate"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextRate"].Value = Math.Round(Convert.ToDecimal(drowDetails["rate"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    decRate = Convert.ToDecimal(drowDetails["rate"].ToString());
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextRate"].Value = 0.00;
                                    decRate = 0;
                                }
                                if (drowDetails["grossAmount"].ToString() != string.Empty)
                                {
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = false;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].Value = Math.Round(Convert.ToDecimal(drowDetails["grossAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    // dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = true;
                                }
                                else
                                {
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = false;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].Value = 0.00;
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextGrossValue"].ReadOnly = true;
                                }
                                if (drowDetails["discount"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountPercentage"].Value = 0.00;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountAmount"].Value = Math.Round(Convert.ToDecimal(drowDetails["discount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountAmount"].Value = 0.00;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextDiscountPercentage"].Value = 0.00;
                                }
                                if (drowDetails["netAmount"].ToString() != string.Empty)
                                {
                                    // dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = false;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].Value = Math.Round(Convert.ToDecimal(drowDetails["netAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    //  dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = true;
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = false;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].Value = 0.00;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextNetValue"].ReadOnly = true;
                                }
                                if (drowDetails["taxAmount"].ToString() != string.Empty)
                                {
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = false;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value = Math.Round(Convert.ToDecimal(drowDetails["taxAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    //dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = true;
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value = 0.00;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].ReadOnly = true;
                                }
                                if (drowDetails["amount"].ToString() != string.Empty)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].Value = Math.Round(Convert.ToDecimal(drowDetails["amount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].ReadOnly = true;
                                }
                                else
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].Value = 0.00;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextAmount1"].ReadOnly = true;
                                }
                                if (cmbInvoiceNo.Visible == true)
                                {
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextBarcode"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextProductCode"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextProductName"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextQty"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbUnit"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbGodown"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbRack"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbBatch"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextRate"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvTextDiscountPercentage"].ReadOnly = true;
                                    dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 1].Cells["dgvCmbTax"].ReadOnly = true;
                                }
                                dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["conversionRate"].Value = drowDetails["conversionRate"].ToString();
                                foreach (DataGridViewRow item1 in dgvSalesReturn2.Rows)
                                {
                                    if (item1.Cells["dgvTextTaxId"].Value != null)
                                    {
                                        if (dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvCmbTax"].Value.ToString() == item1.Cells["dgvTextTaxId"].Value.ToString())
                                        {
                                            item1.Cells["dgvTextAmount"].Value = dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["dgvTextTaxAmount"].Value;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            dgvSalesReturn.Rows[dgvSalesReturn.Rows.Count - 2].Cells["productId"].Value = 0;
                        }
                        TotalAmountCalculation();
                    }
                    if (!isSalesReturnFormActive)
                    {
                        dtblTaxGride = spSalesReturnBillTax.TaxDetailsViewBySalesReturnMasterId(salesReturnMasterId);
                        foreach (DataRow item1 in dtblTaxGride.Rows)
                        {
                            dgvSalesReturn2.Rows.Add();
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvTextTaxName"].Value = item1["taxName"].ToString();
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvTextAmount"].Value = Math.Round(Convert.ToDecimal(item1["taxAmount"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvRate"].Value = item1["rate"].ToString();
                            dgvSalesReturn2.Rows[dgvSalesReturn2.Rows.Count - 2].Cells["dgvTextTaxId"].Value = item1["taxId"].ToString();
                        }
                    }
                    txtBillDiscount.Text = Convert.ToString(Math.Round(Convert.ToDecimal(dtblSalesReturnMaster.Rows[0]["discount"].ToString()), PublicVariables._inNoOfDecimalPlaces));
                    SerialNo2();

                    TotalBillTaxCalculation();
                    CessTaxamountCalculation();
                    TotalTaxAmtCalculation();
                    if (txtBillDiscount.Text != string.Empty)
                    {
                        decimal decDiscount = Convert.ToDecimal(txtBillDiscount.Text);
                        decimal decTotalAmt = Convert.ToDecimal(txtTotalAmount.Text);
                        if (decTotalAmt > decDiscount)
                        {
                            decimal decGrandTotal = decTotalAmt + decTotalBillTaxAmount + decTotalCessTaxamount - decDiscount;
                            decGrandTotal = Math.Round(decGrandTotal, PublicVariables._inNoOfDecimalPlaces);
                            txtGrandTotal.Text = decGrandTotal.ToString();
                        }
                    }
                    // SerialNo();
                }
                else
                {
                    MessageBox.Show("No record exists", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("SR28:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }