/// <summary>
 /// Function to fill AgainstOrder combobox
 /// </summary>
 public void AgainstOrderComboFill()
 {
     try
     {
         bool isEveryComboFill = false;
         SalesOrderBll bllSalesOrder = new SalesOrderBll();
         SalesQuotationBll bllQuotation = new SalesQuotationBll();
         List<DataTable> ListObj = new List<DataTable>();
         if (cmbCashOrParty.SelectedValue.ToString() != null && cmbDeliveryMode.SelectedValue.ToString() != "System.Data.DataRowView")
         {
             cmbOrderNo.Text = string.Empty;
             if (strTypeOfVoucher == "Sales Order")
             {
                 ListObj = bllSalesOrder.GetSalesOrderInvoiceNumberCorrespondingToLedgerId(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()), Convert.ToDecimal(cmbDeliveryMode.SelectedValue.ToString()));
                 DataRow dr = ListObj[0].NewRow();
                 dr[0] = "0";
                 dr[1] = string.Empty;
                 ListObj[0].Rows.InsertAt(dr, 0);
                 cmbOrderNo.DataSource = ListObj[0];
                 if (ListObj[0].Rows.Count > 0)
                 {
                     cmbOrderNo.DisplayMember = "invoiceNo";
                     cmbOrderNo.ValueMember = "salesOrderMasterId";
                     cmbOrderNo.SelectedIndex = 0;
                 }
             }
             else if (strTypeOfVoucher == "Sales Quotation")
             {
                 ListObj = bllQuotation.GetSalesQuotationNumberCorrespondingToLedger(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()), Convert.ToDecimal(cmbDeliveryMode.SelectedValue.ToString()));
                 DataRow dr = ListObj[0].NewRow();
                 dr[0] = "0";
                 dr[1] = string.Empty;
                 ListObj[0].Rows.InsertAt(dr, 0);
                 cmbOrderNo.DataSource = ListObj[0];
                 if (ListObj[0].Rows.Count > 0)
                 {
                     cmbOrderNo.DisplayMember = "invoiceNo";
                     cmbOrderNo.ValueMember = "quotationMasterId";
                 }
             }
             else
             {
                 GridFill();
             }
         }
         isEveryComboFill = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show("DNREP06: " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function to fill the details for edit or delete
        /// </summary>
        public void FillRegisterOrReport()
        {
            SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
            TransactionsGeneralFillBll transactionGeneralFillObj = new TransactionsGeneralFillBll();
            SalesQuotationMasterInfo infoSalesQuotationMaster = new SalesQuotationMasterInfo();
            ProductCreationBll BllProductCreation = new ProductCreationBll();
            try
            {
                VoucherTypeBll BllVoucherType = new VoucherTypeBll();
                IsDoAfterFill = false;
                IsCellValue = false;
                btnSave.Text = "Update";
                btnDelete.Enabled = true;
                infoSalesQuotationMaster =bllSalesQuotation.SalesQuotationMasterView(decSalesquotationMasterId);
                txtQuotationNo.Text = infoSalesQuotationMaster.InvoiceNo;
                strVoucherNo = infoSalesQuotationMaster.VoucherNo.ToString();
                decSalesQuotationPreffixSuffixId = Convert.ToDecimal(infoSalesQuotationMaster.SuffixPrefixId);
                decSalesQuotationVoucherId = Convert.ToDecimal(infoSalesQuotationMaster.VoucherTypeId);
                isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(decSalesQuotationVoucherId);
                decsalesQuotationTypeId = decSalesQuotationVoucherId;
                txtSalesQuotationDate.Text = infoSalesQuotationMaster.Date.ToString("dd-MMM-yyyy");
                cmbCashOrParty.SelectedValue = infoSalesQuotationMaster.LedgerId;
                ComboSalesManFill();
                cmbSalesman.SelectedValue = infoSalesQuotationMaster.EmployeeId;
                txtNarration.Text = infoSalesQuotationMaster.Narration;
                cmbCurrency.SelectedValue = infoSalesQuotationMaster.ExchangeRateId;
                decimal decsalesregisterTotal = Convert.ToDecimal(infoSalesQuotationMaster.TotalAmount.ToString());
                decsalesregisterTotal = Math.Round(decsalesregisterTotal, PublicVariables._inNoOfDecimalPlaces);
                txtTotal.Text = Convert.ToString(decsalesregisterTotal);
                cmbPricinglevel.SelectedValue = infoSalesQuotationMaster.PricinglevelId;
                List<DataTable> ListObj = new List<DataTable>();
                ListObj = bllSalesQuotation.SalesQuotationDetailsViewByMasterId(decSalesquotationMasterId);
                if (isAutomatic)
                {
                    txtQuotationNo.ReadOnly = true;
                    txtSalesQuotationDate.Focus();
                }
                else
                {
                    txtQuotationNo.ReadOnly = false;
                    txtQuotationNo.Focus();
                }
                string strApproved = Convert.ToString(infoSalesQuotationMaster.Approved);
                if (strApproved == "False")
                {
                    cbxApproved.Checked = false;
                }
                else
                {
                    cbxApproved.Checked = true;
                }

                decimal decCount = bllSalesQuotation.CheckingStastusForSalesQuotation(decSalesquotationMasterId);
                if (decCount > 0)
                {
                    cbxApproved.Enabled = false;
                }
                else
                {
                    cbxApproved.Enabled = true;
                }
                for (int i = 0; i < ListObj[0].Rows.Count; i++)
                {
                    isAmountcalc = false;

                    dgvProduct.Rows.Add();

                    dgvProduct.Rows[i].HeaderCell.Value = string.Empty;
                    dgvProduct.Rows[i].Cells["dgvtxtQuotationDetailsId"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["quotationDetailsId"].ToString());
                    dgvProduct.Rows[i].Cells["ProductId"].Value = ListObj[0].Rows[i]["productId"].ToString();
                    dgvProduct.Rows[i].Cells["dgvtxtBarcode"].Value = ListObj[0].Rows[i]["Barcode"].ToString();
                    dgvProduct.Rows[i].Cells["dgvtxtProductCode"].Value = ListObj[0].Rows[i]["productCode"].ToString();
                    transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, ListObj[0].Rows[i]["productId"].ToString(), i);
                    bllSalesQuotation.SalesQuotationMasterBatchFill(dgvProduct, Convert.ToDecimal(ListObj[0].Rows[i]["productId"].ToString()), i);
                    dgvProduct.Rows[i].Cells["dgvtxtProductName"].Value = ListObj[0].Rows[i]["productName"].ToString();
                    dgvProduct.Rows[i].Cells["dgvtxtQty"].Value = ListObj[0].Rows[i]["qty"].ToString();
                    IsCellValue = true;
                    dgvProduct.Rows[i].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["unitId"].ToString());
                    IsCellValue = false;
                    dgvProduct.Rows[i].Cells["dgvtxtRate"].Value = ListObj[0].Rows[i]["rate"].ToString();
                    IsCellValue = true;
                    dgvProduct.Rows[i].Cells["dgvtxtAmount"].Value = ListObj[0].Rows[i]["amount"].ToString();
                    IsCellValue = false;
                    dgvProduct.Rows[i].Cells["dgvcmbbatch"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["batchId"].ToString());

                    UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                    List<DataTable> listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[i].Cells["ProductId"].Value.ToString());
                    if (listUnitByProduct[0].Rows.Count > 0)
                    {
                        foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows)
                        {
                            if (dgvProduct.Rows[i].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                            {
                                dgvProduct.Rows[i].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                                dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());

                            }
                        }
                    }

                    decimal decStandardRate = BllProductCreation.SalesInvoiceProductRateForSales(Convert.ToDecimal(ListObj[0].Rows[i]["productId"].ToString()), PublicVariables._dtCurrentDate, Convert.ToDecimal(ListObj[0].Rows[i]["batchId"].ToString()), Convert.ToDecimal(cmbPricinglevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces);
                    if (dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty)
                    {
                        if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value) != 0)
                        {
                            dgvProduct.Rows[i].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces);
                        }
                    }

                }
                isAmountcalc = true;
                IsCellValue = true;
                IsDoAfterFill = true;

            }
            catch (Exception ex)
            {
                MessageBox.Show("SQ:39" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to edit the SalesQuatation
        /// </summary>
        public void EditFunction()
        {
            SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
            SalesQuotationMasterInfo infoSalesQuotationMaster = new SalesQuotationMasterInfo();
            //SalesQuotationBll bllSalesQuotation = new infoSalesQuotationMaster();
            SettingsBll BllSettings = new SettingsBll();
            try
            {
                for (int inI = 0; inI < dgvProduct.Rows.Count - 1; inI++)
                {
                    if (Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtquotationDetailsId"].Value) != 0)
                    {
                        isEditDetails = Convert.ToString(bllSalesQuotation.SalesQuotationRefererenceCheckForEditDetails(Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtquotationDetailsId"].Value)));
                    }
                }
                isEditMaster = Convert.ToString(bllSalesQuotation.SalesQuotationRefererenceCheckForEditMaster(decSalesquotationMasterId));
                if (isEditMaster == "False" && isEditDetails == "False")
                {
                    infoSalesQuotationMaster.QuotationMasterId = decSalesquotationMasterId;
                    infoSalesQuotationMaster.Date = Convert.ToDateTime(txtSalesQuotationDate.Text);
                    infoSalesQuotationMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
                    infoSalesQuotationMaster.SuffixPrefixId = Convert.ToDecimal(decSalesQuotationPreffixSuffixId);
                    infoSalesQuotationMaster.VoucherNo = strVoucherNo;
                    infoSalesQuotationMaster.VoucherTypeId = decSalesQuotationVoucherId;
                    infoSalesQuotationMaster.InvoiceNo = txtQuotationNo.Text;
                    infoSalesQuotationMaster.userId = PublicVariables._decCurrentUserId;//by default current userid used as current user id
                    infoSalesQuotationMaster.EmployeeId = Convert.ToDecimal(cmbSalesman.SelectedValue.ToString());
                    infoSalesQuotationMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                    infoSalesQuotationMaster.Narration = txtNarration.Text.Trim();
                    infoSalesQuotationMaster.TotalAmount = Convert.ToDecimal(txtTotal.Text);
                    infoSalesQuotationMaster.PricinglevelId = Convert.ToDecimal(cmbPricinglevel.SelectedValue.ToString());
                    infoSalesQuotationMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                    if (cbxApproved.Checked)
                    {
                        infoSalesQuotationMaster.Approved = true;
                    }
                    else
                    {
                        infoSalesQuotationMaster.Approved = false;
                    }
                    infoSalesQuotationMaster.Extra1 = string.Empty;
                    infoSalesQuotationMaster.Extra2 = string.Empty;
                    bllSalesQuotation.SalesQuotationMasterEdit(infoSalesQuotationMaster);
                    RemoveSalesQuotationDetails();
                    NewRowAddedToSalesQuotationDetails();
                    SalesQuotationDetailsEditFill();
                    Messages.UpdatedMessage();
                    if (frmSalesQuotationRegisterObj != null)
                    {
                        if (cbxPrintAfterSave.Checked)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decSalesquotationMasterId);
                            }
                            else
                            {
                                Print(decSalesquotationMasterId);
                            }
                        }
                        this.Close();
                        frmSalesQuotationRegisterObj.GridFill();
                    }
                    if (frmSalesQuotationReportObj != null)
                    {
                        if (cbxPrintAfterSave.Checked)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decSalesquotationMasterId);
                            }
                            else
                            {
                                Print(decSalesquotationMasterId);
                            }
                        }
                        this.Close();
                        frmSalesQuotationReportObj.GridFill();
                    }
                    if (frmDayBookObj != null)
                    {
                        if (cbxPrintAfterSave.Checked)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decSalesquotationMasterId);
                            }
                            else
                            {
                                Print(decSalesquotationMasterId);
                            }
                        }
                        this.Close();
                    }
                    if (objfrmVoucherSearch != null)
                    {
                        if (cbxPrintAfterSave.Checked)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decSalesquotationMasterId);
                            }
                            else
                            {
                                Print(decSalesquotationMasterId);
                            }
                        }
                        this.Close();
                    }
                    if (objVoucherSearch != null)
                    {
                        if (cbxPrintAfterSave.Checked)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decSalesquotationMasterId);
                            }
                            else
                            {
                                Print(decSalesquotationMasterId);
                            }
                        }
                        this.Close();
                    }

                }
                else
                {
                    Messages.ReferenceExistsMessageForUpdate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("SQ:33" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to delete the salesquatation
 /// </summary>
 public void Delete()
 {
     SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
        // SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
     try
     {
         decimal decResult2 = bllSalesQuotation.SalesQuotationMasterDelete(decSalesquotationMasterId);
         decimal decResult1 = 0;
         if (decResult2 == 1)
         {
             for (int inI = 0; inI < dgvProduct.Rows.Count - 1; inI++)
             {
                 if (Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtquotationDetailsId"].Value) != 0)
                 {
                     decResult1 = bllSalesQuotation.SalesQuotationDetailsDelete(Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtquotationDetailsId"].Value));
                 }
             }
         }
         if (decResult1 > 0 && decResult2 > 0)
         {
             Messages.DeletedMessage();
             if (frmSalesQuotationRegisterObj != null)
             {
                 this.Close();
                 frmSalesQuotationRegisterObj.Enabled = true;
             }
             if (frmSalesQuotationReportObj != null)
             {
                 this.Close();
                 frmSalesQuotationReportObj.Enabled = true;
             }
             if (objVoucherSearch != null)
             {
                 this.Close();
                 objVoucherSearch.Enabled = true;
             }
             if (frmDayBookObj != null)
             {
                 this.Close();
                 frmDayBookObj.Enabled = true;
             }
         }
         else
         {
             Messages.ReferenceExistsMessage();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(" SQ:34" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Fill Details Corresponding Quotation No
 /// </summary>
 public void FillQuotationDetails()
 {
     SerialNo();
     try
     {
         BatchBll BllBatch = new BatchBll();
         SalesOrderDetailsInfo infoSalesOrderDetails = new SalesOrderDetailsInfo();
         TransactionsGeneralFillBll TransactionGeneralFillObj = new TransactionsGeneralFillBll();
         decimal decOrderNo = 0;
         if (!isEditFill)
         {
             inMaxCount = 0;
             decOrderNo = Convert.ToDecimal(cmbQuotationNo.SelectedValue.ToString());
             dgvSalesOrder.Rows.Clear();
             List<DataTable> ListObj = new SalesQuotationBll().QuotationMasterViewByQuotationMasterId(Convert.ToDecimal(cmbQuotationNo.SelectedValue.ToString()));
             if (ListObj[0].Rows.Count > 0)
             {
                 cmbPricingLevel.SelectedValue = ListObj[0].Rows[0]["pricingLevelId"].ToString();
                 if (ListObj[0].Rows[0]["employeeId"].ToString() != "")
                 {
                     strSalesMan = ListObj[0].Rows[0]["employeeId"].ToString();
                     cmbSalesMan.SelectedValue = strSalesMan;
                     if (cmbSalesMan.SelectedValue == null)
                     {
                         SalesManComboFill();
                         cmbSalesMan.SelectedValue = ListObj[0].Rows[0]["employeeId"].ToString();
                     }
                 }
                 DGVCurrencyComboFill();
                 cmbCurrency.SelectedValue = ListObj[0].Rows[0]["exchangeRateId"].ToString();
                 List<DataTable> ListObj1 = new SalesQuotationBll().SalesQuotationDetailsViewByquotationMasterIdWithRemainingBySO(Convert.ToDecimal(cmbQuotationNo.SelectedValue.ToString()), decSalesOrderMasterId);
                 int inRowIndex = 0;
                 foreach (DataRow drowDetails in ListObj1[0].Rows)
                 {
                     dgvSalesOrder.Rows.Add();
                     isValueChange = false;
                     isDoAfterGridFill = false;
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtSalesOrderDetailsId"].Value = drowDetails.ItemArray[0].ToString();
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtSalesQuotationDetailsId"].Value = drowDetails.ItemArray[0].ToString();
                     String ProductId = drowDetails.ItemArray[2].ToString();
                     infoProduct = new ProductCreationBll().ProductView(Convert.ToDecimal(ProductId));
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtBarcode"].Value = drowDetails["barcode"].ToString();
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductId"].Value = drowDetails["productId"];
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode;
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductName"].Value = drowDetails["productName"].ToString();
                     AssignProductDefaultValues(dgvSalesOrder.Rows.Count - 2, drowDetails["productId"].ToString());
                     TransactionGeneralFillObj.UnitViewAllByProductId(dgvSalesOrder, infoProduct.ProductId.ToString(), dgvSalesOrder.Rows.Count - 2);
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtQty"].Value = drowDetails["qty"].ToString();
                     UnitComboFill(Convert.ToDecimal(ProductId), dgvSalesOrder.Rows.Count - 2, dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbUnit"].ColumnIndex);
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtRate"].Value = drowDetails["rate"].ToString();
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtAmount"].Value = drowDetails["amount"].ToString();
                     BatchComboFill(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvSalesOrder.Rows.Count - 2, dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbBatch"].ColumnIndex);
                     if (Convert.ToDecimal(drowDetails["batchId"].ToString()) != 0)
                     {
                         dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                     }
                     else
                     {
                         StockPostingBll BllStockPosting = new StockPostingBll();
                         decimal decBatchId = BllStockPosting.BatchViewByProductId(Convert.ToDecimal(ProductId));
                         dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbBatch"].Value = decBatchId;
                     }
                     string strBarcode = BllBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbBatch"].Value.ToString()));
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtBarcode"].Value = strBarcode.ToString();
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductCode"].ReadOnly = true;
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductName"].ReadOnly = true;
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtBarcode"].ReadOnly = true;
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["inRowIndex"].Value = drowDetails["extra1"].ToString();
                     UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                     List<DataTable> list = new List<DataTable>();
                     list = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductId"].Value.ToString());
                     foreach (DataRow drUnitByProduct in list[0].Rows)
                     {
                         if (dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                         {
                             dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                             dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                         }
                     }
                     decCurrentConversionRate = Convert.ToDecimal(dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value.ToString());
                     decCurrentRate = Convert.ToDecimal(dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtRate"].Value.ToString());
                     if (cmbQuotationNo.Visible == true)
                     {
                         dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true;
                     }
                     dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].HeaderCell.Value = "";
                     int intIndex = 0;
                     int.TryParse(drowDetails["extra1"].ToString(), out intIndex);
                     if (inMaxCount < intIndex)
                         inMaxCount = intIndex;
                     inRowIndex++;
                     isValueChange = true;
                 }
                 for (int i = inRowIndex; i < dgvSalesOrder.Rows.Count; ++i)
                     dgvSalesOrder["inRowIndex", i].Value = GetNextinRowIndex().ToString();
                 SerialNo();
                 TotalAmountCalculation();
                 isDoAfterGridFill = true;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SO38: " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 ///to change the corresponding values in grid when cells changed 
 /// </summary>
 private void dgvProduct_CellLeave(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         SalesQuotationBll bllQuotation = new SalesQuotationBll();
         //DeliveryNoteMasterSP spDeliveryNoteMaster = new DeliveryNoteMasterSP();
         DeliveryNoteBll bllDeliveryNote = new DeliveryNoteBll();
         if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQty")
         {
             decimal decCurrentQty = 0;
             decimal decOldQty = 0;
             if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString() != string.Empty)
             {
                 if (decDelivryNoteIdToEdit != 0)
                 {
                     if (cmbOrderNo.SelectedIndex != 0)
                     {
                         if (cmbDeliveryMode.Text == "Against Order")
                         {
                             List<DataTable> ListObj = new SalesOrderBll().SalesOrderDetailsViewBySalesOrderMasterIdWithRemaining(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit);
                             decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[0].Cells["dgvtxtQty"].Value.ToString());
                             decOldQty = Convert.ToDecimal(ListObj[0].Rows[0]["qty"].ToString());
                         }
                         else if (cmbDeliveryMode.Text == "Against Quotation")
                         {
                             List<DataTable> ListQuotationDetails = bllQuotation.SalesQuotationDetailsViewByquotationMasterIdWithRemainingByNotInCurrDN(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit);
                             if (ListQuotationDetails[0].Rows.Count >= 1)
                             {
                                 decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[0].Cells["dgvtxtQty"].Value.ToString());
                                 decOldQty = Convert.ToDecimal(ListQuotationDetails[0].Rows[0]["qty"].ToString());
                             }
                         }
                         if (bllDeliveryNote.DeliveryNoteMasterReferenceCheckRejectionIn(decDelivryNoteIdToEdit))
                         {
                             List<DataTable> listObjRejectionInQty = new List<DataTable>();
                             listObjRejectionInQty = bllDeliveryNote.DeliveryNoteMasterReferenceCheckRejectionInQty(decDelivryNoteIdToEdit);
                             decimal decRejectionInQty = decimal.Parse(listObjRejectionInQty[0].Rows[e.RowIndex]["qty"].ToString());
                             if (decimal.Parse(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()) > decimal.Parse(listObjRejectionInQty[0].Rows[e.RowIndex]["qty"].ToString()))
                             {
                                 decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString());
                             }
                             else
                             {
                                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = Convert.ToDecimal(decRejectionInQty);
                             }
                         }
                         if (bllDeliveryNote.DeliveryNoteCheckReferenceInSalesInvoice(decDelivryNoteIdToEdit))
                         {
                             List<DataTable> listObjSalesInvoiceQty = new List<DataTable>();
                             listObjSalesInvoiceQty = bllDeliveryNote.DeliveryNoteMasterReferenceCheckSalesInvoiceQty(decDelivryNoteIdToEdit);
                             decimal decSalesInvoiceQty = decimal.Parse(listObjSalesInvoiceQty[0].Rows[e.RowIndex]["qty"].ToString());
                             if (decimal.Parse(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()) > decimal.Parse(listObjSalesInvoiceQty[0].Rows[e.RowIndex]["qty"].ToString()))
                             {
                                 decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString());
                             }
                             else
                             {
                                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = Convert.ToDecimal(decSalesInvoiceQty);
                             }
                         }
                     }
                     else
                     {
                         Messages.InformationMessage("Select OrderNo");
                         cmbOrderNo.Focus();
                     }
                 }
                 if (decDelivryNoteIdToEdit == 0)
                 {
                     if (Convert.ToInt32(dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value) != 0)
                     {
                         if (cmbDeliveryMode.Text == "Against Quotation")
                         {
                             List<DataTable> ListObj = bllQuotation.SalesQuotationDetailsViewByquotationMasterIdWithRemainingByNotInCurrDN(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit);
                             decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString());
                             decOldQty = Convert.ToDecimal(ListObj[0].Rows[e.RowIndex]["qty"].ToString());
                         }
                         else if (cmbDeliveryMode.Text == "Against Order")
                         {
                             List<DataTable> ListObj = new SalesOrderBll().SalesOrderDetailsViewBySalesOrderMasterIdWithRemaining(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit);
                             decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString());
                             decOldQty = Convert.ToDecimal(ListObj[0].Rows[e.RowIndex]["qty"].ToString());
                         }
                     }
                 }
             }
         }
         if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit")
         {
             if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty)
             {
                 if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() != string.Empty)
                 {
                     UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                     List<DataTable> ListObj = new List<DataTable>();
                     ListObj = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString());
                     foreach (DataRow drUnitByProduct in ListObj[0].Rows)
                     {
                         if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                         {
                             dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                             dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                             if (isDoAfterGridFill)
                             {
                                 decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                 decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate;
                                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, 2);
                             }
                         }
                     }
                 }
             }
         }
         if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQty")
         {
             AmountCalculation("dgvtxtQty", e.RowIndex);
         }
         if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtRate")
         {
             AmountCalculation("dgvtxtRate", e.RowIndex);
         }
         else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtAmount")
         {
             TotalAmountCalculation();
         }
         CheckInvalidEntries(e);
     }
     catch (Exception ex)
     {
         MessageBox.Show("DN70:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// To fill the Order combo box based on the sales quotation numbers
 /// </summary>
 public void AgainstQuotationComboFill()
 {
     try
     {
         if (cmbType.SelectedValue.ToString() != "System.Data.DataRowView")
         {
             SalesQuotationBll bllQuotation = new SalesQuotationBll();
             List<DataTable> ListObj = new List<DataTable>();
             ListObj = bllQuotation.GetSalesQuotationNumberCorrespondingToLedgerForDN(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()), Convert.ToDecimal(cmbType.SelectedValue.ToString()), decDelivryNoteIdToEdit);
             DataRow dr = ListObj[0].NewRow();
             dr[0] = 0;
             dr[1] = string.Empty;
             ListObj[0].Rows.InsertAt(dr, 0);
             cmbOrderNo.DataSource = ListObj[0];
             if (ListObj[0].Rows.Count > 0)
             {
                 cmbOrderNo.DisplayMember = "invoiceNo";
                 cmbOrderNo.ValueMember = "quotationMasterId";
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("DN13: " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to call the save or edit function and also checking invalid entries 
 /// </summary>
 public void SaveOrEdit()
 {
     SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
     try
     {
         int InRow = dgvProduct.RowCount;
         dgvProduct.ClearSelection();
         if (txtQuotationNo.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Please enter QuotationNo");
             txtQuotationNo.Focus();
         }
         else if (bllSalesQuotation.CheckSalesQuotationNumberExistance(txtQuotationNo.Text.Trim(), decsalesQuotationTypeId) == true && btnSave.Text == "Save")
         {
             Messages.InformationMessage("Quotation number already  exist");
         }
         else if (cmbCashOrParty.SelectedValue == null)
         {
             Messages.InformationMessage(" please select cash Or Party");
             cmbCashOrParty.Focus();
         }
         else if (cmbSalesman.SelectedValue == null)
         {
             Messages.InformationMessage("Please select any salesman ");
             cmbSalesman.Focus();
         }
         else if (txtSalesQuotationDate.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Select date between financial year");
         }
         else if (cmbPricinglevel.SelectedValue == null)
         {
             Messages.InformationMessage("please select pricing level");
         }
         else if (InRow - 1 == 0)
         {
             Messages.InformationMessage("Can't save SalesQuotation without atleast one product with complete details");
         }
         else
         {
             if (RemoveIncompleteRowFromTheGrid())
             {
                 if (dgvProduct.Rows[0].Cells["dgvtxtProductName"].Value == null && dgvProduct.Rows[0].Cells["dgvtxtProductCode"].Value == null && dgvProduct.Rows[0].Cells["dgvcmbBatch"].Value == null)
                 {
                     MessageBox.Show("Can't save salesQuotation  without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     dgvProduct.ClearSelection();
                     dgvProduct.Focus();
                 }
                 else
                 {
                     if (btnSave.Text == "Save")
                     {
                         if (dgvProduct.Rows[0].Cells["dgvtxtProductName"].Value == null)
                         {
                             MessageBox.Show("Can't save salesQuotation without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             dgvProduct.ClearSelection();
                             dgvProduct.Focus();
                         }
                         {
                             if (PublicVariables.isMessageAdd)
                             {
                                 if (Messages.SaveMessage())
                                 {
                                     SaveFunction();
                                 }
                             }
                             else
                             {
                                 SaveFunction();
                             }
                         }
                     }
                     if (btnSave.Text == "Update")
                     {
                         if (dgvProduct.Rows[0].Cells["dgvtxtProductName"].Value == null)
                         {
                             MessageBox.Show("Can't edit salesQuotation without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             dgvProduct.ClearSelection();
                             dgvProduct.Focus();
                         }
                         else
                         {
                             if (PublicVariables.isMessageEdit)
                             {
                                 if (Messages.UpdateMessage())
                                 {
                                     EditFunction();
                                 }
                             }
                             else
                             {
                                 EditFunction();
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SQ:37" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the grid to edit the details
 /// </summary>
 public void SalesQuotationDetailsEditFill()
 {
     SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
     SalesQuotationDetailsInfo infoSalesQuotationDetails = new SalesQuotationDetailsInfo();
     ProductCreationBll BllProductCreation = new ProductCreationBll();
     ProductInfo infoproduct = new ProductInfo();
     try
     {
         for (int inI = 0; inI < dgvProduct.Rows.Count - 1; inI++)
         {
             infoSalesQuotationDetails.QuotationMasterId = decSalesquotationMasterId;
             infoSalesQuotationDetails.QuotationDetailsId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQuotationDetailsId"].Value);
             infoproduct = BllProductCreation.ProductViewByCode(dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
             infoSalesQuotationDetails.ProductId = infoproduct.ProductId;
             infoSalesQuotationDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
             if (Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQuotationDetailsId"].Value) == 0)
             {
                 infoSalesQuotationDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
             }
             else
             {
                 DGVUnitComboFill();
                 infoSalesQuotationDetails.UnitId = Convert.ToDecimal((dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString()));
             }
             decimal unitConversion = bllSalesQuotation.UnitconversionIdViewByUnitIdAndProductId(infoSalesQuotationDetails.UnitId, infoSalesQuotationDetails.ProductId);
             infoSalesQuotationDetails.UnitConversionId = unitConversion;
             infoSalesQuotationDetails.BatchId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value);
             infoSalesQuotationDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value);
             infoSalesQuotationDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value);
             infoSalesQuotationDetails.Slno = Convert.ToInt32(dgvProduct.Rows[inI].Cells["dgvtxtSlNo"].Value);
             infoSalesQuotationDetails.Extra1 = string.Empty;
             infoSalesQuotationDetails.Extra2 = string.Empty;
             bllSalesQuotation.SalesQuotationDetailsEdit(infoSalesQuotationDetails);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SQ:20" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to save the sales quatation
 /// </summary>
 public void SaveFunction()
 {
     SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
     //SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
     SalesQuotationMasterInfo infoSalesQuotationMaster = new SalesQuotationMasterInfo();
     SalesQuotationDetailsInfo infoSalesQuotationDetails = new SalesQuotationDetailsInfo();
     SettingsBll BllSettings = new SettingsBll();
     ProductCreationBll BllProductCreation = new ProductCreationBll();
     ProductInfo infoproduct = new ProductInfo();
     try
     {
         infoSalesQuotationMaster.Date = Convert.ToDateTime(txtSalesQuotationDate.Text);
         infoSalesQuotationMaster.PricinglevelId = Convert.ToDecimal(cmbPricinglevel.SelectedValue.ToString());
         infoSalesQuotationMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         infoSalesQuotationMaster.EmployeeId = Convert.ToDecimal(cmbSalesman.SelectedValue.ToString());
         if (isAutomatic)
         {
             infoSalesQuotationMaster.SuffixPrefixId = decSalesQuotationPreffixSuffixId;
             infoSalesQuotationMaster.VoucherNo = strSalesQuotationNo;
         }
         else
         {
             infoSalesQuotationMaster.SuffixPrefixId = 0;
             infoSalesQuotationMaster.VoucherNo = bllSalesQuotation.VoucherNoMax(decsalesQuotationTypeId);
         }
         infoSalesQuotationMaster.VoucherTypeId = decsalesQuotationTypeId;
         infoSalesQuotationMaster.InvoiceNo = txtQuotationNo.Text;
         infoSalesQuotationMaster.EmployeeId = Convert.ToDecimal(cmbSalesman.SelectedValue.ToString());
         infoSalesQuotationMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         infoSalesQuotationMaster.userId = PublicVariables._decCurrentUserId;
         infoSalesQuotationMaster.TotalAmount = Convert.ToDecimal(txtTotal.Text);
         infoSalesQuotationMaster.Narration = txtNarration.Text.Trim();
         infoSalesQuotationMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         infoSalesQuotationMaster.Extra1 = string.Empty;
         infoSalesQuotationMaster.Extra2 = string.Empty;
         if (cbxApproved.Checked)
         {
             infoSalesQuotationMaster.Approved = true;
         }
         else
         {
             infoSalesQuotationMaster.Approved = false;
         }
         decSalesQuotationmasterIdentity = Convert.ToDecimal(bllSalesQuotation.SalesQuotationMasterAdd(infoSalesQuotationMaster));
         int inRowcount = dgvProduct.Rows.Count;
         for (int inI = 0; inI < inRowcount - 1; inI++)
         {
             infoSalesQuotationDetails.QuotationMasterId = decSalesQuotationmasterIdentity;
             if (dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty)
             {
                 infoproduct = BllProductCreation.ProductViewByCode(dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                 infoSalesQuotationDetails.ProductId = infoproduct.ProductId;
             }
             if (dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString() != string.Empty)
             {
                 infoSalesQuotationDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
             }
             if (dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString() != string.Empty)
             {
                 infoSalesQuotationDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                 decimal unitConversion = bllSalesQuotation.UnitconversionIdViewByUnitIdAndProductId(infoSalesQuotationDetails.UnitId, infoSalesQuotationDetails.ProductId);
                 infoSalesQuotationDetails.UnitConversionId = unitConversion;
             }
             if (dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
             {
                 infoSalesQuotationDetails.BatchId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value);
             }
             else
             {
                 infoSalesQuotationDetails.BatchId = 0;
             }
             infoSalesQuotationDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
             infoSalesQuotationDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
             infoSalesQuotationDetails.Slno = Convert.ToInt32(dgvProduct.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
             infoSalesQuotationDetails.Extra1 = string.Empty;
             infoSalesQuotationDetails.Extra2 = string.Empty;
             bllSalesQuotation.SalesQuotationDetailsAdd(infoSalesQuotationDetails);
         }
         Messages.SavedMessage();
         if (cbxPrintAfterSave.Checked)
         {
             if (dgvProduct.Rows.Count > 0)
             {
                 if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decSalesQuotationmasterIdentity);
                 }
                 else
                 {
                     Print(decSalesQuotationmasterIdentity);
                 }
             }
             else
             {
                 Messages.InformationMessage("No data found");
             }
         }
         Clear();
     }
     catch (Exception ex)
     {
         MessageBox.Show("SQ:32" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to remove SalesQuatation details in edit mode
 /// </summary>
 public void RemoveSalesQuotationDetails()
 {
     SalesQuotationBll bllSalesQuotationDetails = new SalesQuotationBll();
     try
     {
         foreach (var strId in lstArrOfRemove)
         {
             decimal decDeleteId = Convert.ToDecimal(strId);
             bllSalesQuotationDetails.SalesQuotationDetailsDelete(decDeleteId);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SQ:18" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to print the SalesQuatation
 /// </summary>
 /// <param name="decMasterId"></param>
 public void Print(decimal decMasterId)
 {
     SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
     try
     {
         DataSet dsSalesQuotation = bllSalesQuotation.SalesQuotationPrinting(decMasterId);
         frmReport frmReport = new frmReport();
         frmReport.MdiParent = formMDI.MDIObj;
         frmReport.SalesQuotationPrinting(dsSalesQuotation);
     }
     catch (Exception ex)
     {
         MessageBox.Show("SQ:24" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill QuotationNo combobox
 /// </summary>
 public void QuotationNoComboFill()
 {
     try
     {
         List<DataTable> ListObj = new List<DataTable>();
         SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
         ListObj = bllSalesQuotation.GetQuotationNoCorrespondingtoLedgerForSalesOrderRpt(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()));
         if (ListObj != null)
         {
             cmbQuotationNo.DataSource = ListObj[0];
             cmbQuotationNo.DisplayMember = "invoiceNo";
             cmbQuotationNo.ValueMember = "quotationMasterId";
             DataRow dr = ListObj[0].NewRow();
             dr["invoiceNo"] = "All";
             dr["quotationMasterId"] = 0;
             ListObj[0].Rows.InsertAt(dr, 0);
             cmbQuotationNo.SelectedIndex = 0;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SORP8" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Against Sales order combofill function
 /// </summary>
 public void againstOrderComboFill()
 {
     try
     {
         SalesOrderBll bllSalesOrder = new SalesOrderBll();
         //DeliveryNoteMasterSP spDeliveryNoteMasterSp = new DeliveryNoteMasterSP();
         DeliveryNoteBll bllDeliveryNote = new DeliveryNoteBll();
         SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
         List<DataTable> Listobj = new List<DataTable>();
         if (cmbCashOrParty.SelectedValue != null)
         {
             if (cmbSalesMode.Text == "Against SalesOrder")
             {
                 Listobj = bllSalesOrder.GetSalesOrderNoIncludePendingCorrespondingtoLedgerforSI(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()), decSalesInvoiceIdToEdit, Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString()));
                 DataRow dr = Listobj[0].NewRow();
                 dr["invoiceNo"] = "";
                 dr["salesOrderMasterId"] = 0;
                 Listobj[0].Rows.InsertAt(dr, 0);
                 isFromEditMode = true;
                 cmbSalesModeOrderNo.DataSource = Listobj[0];
                 cmbSalesModeOrderNo.ValueMember = "salesOrderMasterId";
                 cmbSalesModeOrderNo.DisplayMember = "invoiceNo";
                 isFromEditMode = false;
             }
             if (cmbSalesMode.Text == "Against Delivery Note")
             {
                 List<DataTable> listObj = new List<DataTable>();
                 listObj = bllDeliveryNote.GetDeleveryNoteNoIncludePendingCorrespondingtoLedgerForSI(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()), decSalesInvoiceIdToEdit, Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString()));
                 DataRow dr = listObj[0].NewRow();
                 dr["invoiceNo"] = "";
                 dr["deliveryNoteMasterId"] = 0;
                 listObj[0].Rows.InsertAt(dr, 0);
                 isFromEditMode = true;
                 cmbSalesModeOrderNo.DataSource = listObj[0];
                 cmbSalesModeOrderNo.ValueMember = "deliveryNoteMasterId";
                 cmbSalesModeOrderNo.DisplayMember = "invoiceNo";
                 isFromEditMode = false;
             }
             if (cmbSalesMode.Text == "Against Quotation")
             {
                 List<DataTable> listObj = new List<DataTable>();
                 listObj = bllSalesQuotation.GetSalesQuotationIncludePendingCorrespondingtoLedgerForSI(Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString()), decSalesInvoiceIdToEdit, Convert.ToDecimal(cmbVoucherType.SelectedValue.ToString()));
                 DataRow dr = listObj[0].NewRow();
                 dr["invoiceNo"] = "";
                 dr["quotationMasterId"] = 0;
                 listObj[0].Rows.InsertAt(dr, 0);
                 isFromEditMode = true;
                 cmbSalesModeOrderNo.DataSource = listObj[0];
                 cmbSalesModeOrderNo.ValueMember = "quotationMasterId";
                 cmbSalesModeOrderNo.DisplayMember = "invoiceNo";
                 isFromEditMode = false;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 13" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function to call frmProductSearchPopup form to select and view product
        /// </summary>
        /// <param name="frmProductSearchPopup"></param>
        /// <param name="decproductId"></param>
        /// <param name="decCurrentRowIndex"></param>
        public void CallFromProductSearchPopup(frmProductSearchPopup frmProductSearchPopup, decimal decproductId, decimal decCurrentRowIndex)
        {
            ProductCreationBll BllProductCreation = new ProductCreationBll();
            ProductInfo infoProduct = new ProductInfo();
            try
            {
                this.Enabled = true;
                this.BringToFront();

                this.frmProductSearchPopupObj = frmProductSearchPopup;
                int inCurrentRowIndex = dgvProduct.CurrentRow.Index;
                dgvProduct.Rows.Add();
                if (decproductId != 0)
                {
                    List<DataTable> ListObj = new List<DataTable>();
                    List<DataTable> ListObjUnitViewAll = new List<DataTable>();
                    infoProduct = BllProductCreation.ProductView(decproductId);
                    TransactionsGeneralFillBll transactionGeneralFillObj = new TransactionsGeneralFillBll();
                    SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
                    dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtProductName"].Value = infoProduct.ProductName;
                    dgvProduct.Rows[inCurrentRowIndex].Cells["ProductId"].Value = infoProduct.ProductId;
                    dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode;
                    dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.SalesRate, PublicVariables._inNoOfDecimalPlaces);
                    DefaultRate = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces);
                    ListObjUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, infoProduct.ProductId.ToString(), inCurrentRowIndex);
                    ListObj= bllSalesQuotation.SalesQuotationMasterBatchFill(dgvProduct, infoProduct.ProductId, inCurrentRowIndex);

                    BatchBll BllBatch = new BatchBll();
                    decimal decBatchId = BllBatch.BatchIdViewByProductId(infoProduct.ProductId);
                    dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbBatch"].Value = decBatchId;
                    dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbUnit"].Value = infoProduct.UnitId;

                    if (infoProduct.PartNo != string.Empty)
                    {
                        dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtBarcode"].Value = infoProduct.PartNo;
                    }
                    else
                    {
                        if (dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                        {
                            decBatchId = Convert.ToDecimal(dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbBatch"].Value);
                            dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtBarcode"].Value = BllProductCreation.BarcodeViewByBatchId(decBatchId);
                        }
                    }
                    IsDoAfterFill = true;
                    UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                    List<DataTable> listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[inCurrentRowIndex].Cells["ProductId"].Value.ToString());
                    if (listUnitByProduct[0].Rows.Count > 0)
                    {
                        foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows)
                        {
                            if (dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                            {
                                dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                                dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                                if (IsDoAfterFill)
                                {
                                    decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                    decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate;
                                    dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, PublicVariables._inNoOfDecimalPlaces);
                                }
                            }
                        }
                    }
                    decimal decStandardRate =  BllProductCreation.SalesInvoiceProductRateForSales(infoProduct.ProductId, PublicVariables._dtCurrentDate, decBatchId, Convert.ToDecimal(cmbPricinglevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces);
                    if (dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty)
                    {
                        if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value) != 0)
                        {
                            dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces);
                        }
                    }
                    dgvProduct.Rows[inCurrentRowIndex].HeaderCell.Value = "X";
                    dgvProduct.Rows[inCurrentRowIndex].HeaderCell.Style.ForeColor = Color.Red;
                }
                frmProductSearchPopupObj.Close();
                frmProductSearchPopupObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show("SQ:42" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 ///  Grid fill function Againest QuotationDetails
 /// </summary>
 public void gridFillAgainestQuotationDetails()
 {
     BrandBll BllBrand = new BrandBll();
     SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
     ProductInfo infoproduct = new ProductInfo();
     //SalesMasterSP spSalesMaster = new SalesMasterSP();
     SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
     BrandInfo InfoBrand = new BrandInfo();
     TaxInfo infoTax = new TaxInfo();
     TaxBll bllTax = new TaxBll();
     try
     {
         if (cmbSalesModeOrderNo.SelectedIndex > 0)
         {
             inMaxCount = 0;
             isValueChange = false;
             for (int i = 0; i < dgvSalesInvoice.RowCount - 1; i++)
             {
                 if (dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value != null && dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString() != string.Empty)
                 {
                     lstArrOfRemove.Add(dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceSalesDetailsId"].Value.ToString());
                 }
             }
             dgvSalesInvoice.Rows.Clear();
             isValueChange = true;
             List<DataTable> ListSalesMaster = bllSalesQuotation.SalesInvoiceGridfillAgainestQuotation(Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString()));
             cmbPricingLevel.SelectedValue = Convert.ToDecimal(ListSalesMaster[0].Rows[0]["pricingLevelId"].ToString());
             cmbCurrency.SelectedValue = Convert.ToDecimal(ListSalesMaster[0].Rows[0]["exchangeRateId"].ToString());
             if (ListSalesMaster[0].Rows[0]["employeeId"].ToString() != string.Empty)
             {
                 strSalesManId = ListSalesMaster[0].Rows[0]["employeeId"].ToString();
                 cmbSalesMan.SelectedValue = strSalesManId;
                 if (cmbSalesMan.SelectedValue == null)
                 {
                     salesManComboFill();
                     cmbSalesMan.SelectedValue = ListSalesMaster[0].Rows[0]["employeeId"].ToString();
                 }
             }
             cmbPricingLevel.Enabled = false;
             btnNewPricingLevel.Enabled = false;
             cmbCurrency.Enabled = false;
             List<DataTable> ListSalesDetals = bllSalesQuotation.SalesInvoiceGridfillAgainestQuotationUsingQuotationDetails(Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString()), decSalesInvoiceIdToEdit, DecSalesInvoiceVoucherTypeId);
             int inRowIndex = 0;
             foreach (DataRow drowDetails in ListSalesDetals[0].Rows)
             {
                 dgvSalesInvoice.Rows.Add();
                 IsSetGridValueChange = false;
                 isValueChange = false;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceQuotationDetailsId"].Value = drowDetails["quotationDetailsId"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductCode"].Value = drowDetails["productCode"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceBarcode"].Value = drowDetails["barcode"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvcmbSalesInvoiceBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceVoucherNo"].Value = drowDetails["voucherNo"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceInvoiceNo"].Value = drowDetails["invoiceNo"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceVoucherTypeId"].Value = drowDetails["voucherTypeId"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceDiscountPercentage"].Value = "0";
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceInRowIndex"].Value = drowDetails["quotationDetailsId"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductId"].Value = drowDetails.ItemArray[2].ToString();
                 infoproduct = BllSalesInvoice.ProductViewByProductIdforSalesInvoice(Convert.ToDecimal(dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductId"].Value).ToString());
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductName"].Value = infoproduct.ProductName;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceMrp"].Value = infoproduct.Mrp;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoicePurchaseRate"].Value = infoproduct.PurchaseRate;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceSalesRate"].Value = infoproduct.SalesRate;
                 InfoBrand = BllBrand.BrandView(infoproduct.BrandId);
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceBrand"].Value = InfoBrand.BrandName;
                 infoTax = bllTax.TaxViewByProductId(Convert.ToDecimal(dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductId"].Value).ToString());
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvcmbSalesInvoiceTaxName"].Value = infoTax.TaxId;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceUnitConversionId"].Value = drowDetails["unitConversionId"].ToString();
                 isValueChange = false;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoicembUnitName"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoicembUnitName"].ReadOnly = true;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceQty"].Value = drowDetails["Qty"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceRate"].Value = drowDetails["rate"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceAmount"].Value = drowDetails["amount"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceConversionRate"].Value = drowDetails["conversionRate"].ToString();
                 isFromAgainest = true;
                 gridColumnMakeEnables();
                 int intIndex = 0;
                 intIndex = Convert.ToInt32(drowDetails["quotationDetailsId"].ToString());
                 if (inMaxCount < intIndex)
                     inMaxCount = intIndex;
                 inRowIndex++;
                 isValueChange = true;
                 isFromAgainest = false;
                 GrossValueCalculation(dgvSalesInvoice.Rows.Count - 2);
                 discountCalculation(dgvSalesInvoice.Rows.Count - 2);
                 taxAndGridTotalAmountCalculation(dgvSalesInvoice.Rows.Count - 2);
             }
             IsSetGridValueChange = true;
             for (int i = inRowIndex; i < dgvSalesInvoice.Rows.Count; ++i)
                 dgvSalesInvoice["dgvtxtSalesInvoiceInRowIndex", i].Value = GetNextinRowIndex().ToString();
             SerialNoforSalesInvoice();
             strVoucherNoTostockPost = dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceVoucherNo"].Value.ToString();
             strInvoiceNoTostockPost = dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceInvoiceNo"].Value.ToString();
             decVouchertypeIdTostockPost = Convert.ToDecimal(dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceVoucherTypeId"].Value);
         }
         else
         {
             SiGridTotalAmountCalculation();
             ClearGridAgainest();
         }
         SiGridTotalAmountCalculation();
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 52" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// On cellendedit of dgvProduct
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvProduct_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            ProductCreationBll BllProductCreation = new ProductCreationBll();
            try
            {
                if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtProductName")
                {
                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString().Trim() != string.Empty)
                    {
                        string strProductName = Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value);
                        ProductInfo infoProduct = BllProductCreation.ProductViewByName(strProductName);
                        if (infoProduct.ProductCode != null && infoProduct.ProductCode != string.Empty)
                        {
                            TransactionsGeneralFillBll transactionGeneralFillObj = new TransactionsGeneralFillBll();
                            SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();

                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode;
                            dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = infoProduct.ProductId;
                            List<DataTable> ListObj = new List<DataTable>();
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.SalesRate);
                            DefaultRate = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces);
                            ListObjUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, infoProduct.ProductId.ToString(), e.RowIndex);
                            ListObj = bllSalesQuotation.SalesQuotationMasterBatchFill(dgvProduct, infoProduct.ProductId, e.RowIndex);
                            BatchBll BllBatch = new BatchBll();
                            decimal decBatchId = BllBatch.BatchIdViewByProductId(infoProduct.ProductId);
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = decBatchId;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = infoProduct.UnitId;
                            if (infoProduct.PartNo != string.Empty)
                            {
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = infoProduct.PartNo;
                            }
                            else
                            {
                                if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                                {
                                    decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value);
                                    dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = BllProductCreation.BarcodeViewByBatchId(decBatchId);
                                }
                            }
                            IsDoAfterFill = true;
                            UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                            List<DataTable> listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString());
                            if (listUnitByProduct[0].Rows.Count > 0)
                            {
                                foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows)
                                {
                                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                                    {
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                                        if (IsDoAfterFill)
                                        {
                                            decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                            decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate;
                                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate,PublicVariables._inNoOfDecimalPlaces);
                                        }
                                    }
                                }
                            }

                            decimal decStandardRate = BllProductCreation.SalesInvoiceProductRateForSales(infoProduct.ProductId, PublicVariables._dtCurrentDate, decBatchId, Convert.ToDecimal(cmbPricinglevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces);
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty)
                            {
                                if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value) != 0)
                                {
                                    dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces);
                                }
                            }

                        }
                        else
                        {
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = string.Empty;
                        }
                            AmountCalculation("dgvtxtQty", e.RowIndex);
                            TotalAmountCalculation();
                    }
                    else
                    {
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                    }
                }
                if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtBarcode")
                {
                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString().Trim() != string.Empty)
                    {
                        List<DataTable> listObjProductdDetails = new List<DataTable>();
                        string strBarcode = (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString());
                        listObjProductdDetails = BllProductCreation.ProductDetailsCoreespondingToBarcode(strBarcode);

                        if (listObjProductdDetails[0].Rows.Count > 0)
                        {
                            TransactionsGeneralFillBll transactionGeneralFillObj = new TransactionsGeneralFillBll();
                            SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
                            List<DataTable> ListObj = new List<DataTable>();
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = listObjProductdDetails[0].Rows[0]["productCode"].ToString();
                            dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = listObjProductdDetails[0].Rows[0]["productId"].ToString();
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = listObjProductdDetails[0].Rows[0]["productName"].ToString();
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["SalesRate"].ToString()));
                            DefaultRate = Math.Round(Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["purchaseRate"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                            ListObjUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, listObjProductdDetails[0].Rows[0]["productId"].ToString(), e.RowIndex);
                            ListObj = bllSalesQuotation.SalesQuotationMasterBatchFill(dgvProduct, Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["productId"].ToString()), e.RowIndex);
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["batchId"].ToString());
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["unitId"].ToString());

                            IsDoAfterFill = true;
                            UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                            List<DataTable> listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString());
                            if (listUnitByProduct[0].Rows.Count > 0)
                            {
                                foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows)
                                {
                                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                                    {
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                                        if (IsDoAfterFill)
                                        {
                                            decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                            decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate;
                                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, PublicVariables._inNoOfDecimalPlaces);
                                        }
                                    }
                                }
                            }
                            decimal decStandardRate = BllProductCreation.SalesInvoiceProductRateForSales(Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["productId"].ToString()), PublicVariables._dtCurrentDate, decBatchId, Convert.ToDecimal(cmbPricinglevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces);
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty)
                            {
                                if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value) != 0)
                                {
                                    dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces);
                                }
                            }

                        }
                        else
                        {
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = string.Empty;
                        }
                        AmountCalculation("dgvtxtQty", e.RowIndex);
                        TotalAmountCalculation();
                    }
                    else
                    {
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                    }
                }
                else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtProductCode")
                {
                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString().Trim() != string.Empty)
                    {
                        ProductInfo infoProduct = new ProductInfo();
                        string strProductCode = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString();
                        infoProduct = BllProductCreation.ProductViewByCode(strProductCode);
                        if (infoProduct.ProductId != 0)
                        {
                            TransactionsGeneralFillBll transactionGeneralFillObj = new TransactionsGeneralFillBll();
                            SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = infoProduct.ProductName;
                            dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = infoProduct.ProductId;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.SalesRate, PublicVariables._inNoOfDecimalPlaces);
                            DefaultRate = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces);
                            List<DataTable> LiostObj = new List<DataTable>();
                            ListObjUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, infoProduct.ProductId.ToString(), e.RowIndex);
                            LiostObj = bllSalesQuotation.SalesQuotationMasterBatchFill(dgvProduct, infoProduct.ProductId, e.RowIndex);

                            BatchBll BllBatch = new BatchBll();
                            decimal decBatchId = BllBatch.BatchIdViewByProductId(infoProduct.ProductId);
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = decBatchId;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = infoProduct.UnitId;

                            if (infoProduct.PartNo != string.Empty)
                            {
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = infoProduct.PartNo;
                            }
                            else
                            {
                                if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                                {
                                    decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value);
                                    dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = BllProductCreation.BarcodeViewByBatchId(decBatchId);
                                }
                            }
                            IsDoAfterFill = true;
                            UnitConvertionBll bllUnitByProduct = new UnitConvertionBll();

                            List<DataTable> listUnitByProduct = bllUnitByProduct.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString());
                            if (listUnitByProduct[0].Rows.Count > 0)
                            {
                                foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows)
                                {
                                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                                    {
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                                        if (IsDoAfterFill)
                                        {
                                            decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                            decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate;
                                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, PublicVariables._inNoOfDecimalPlaces);
                                        }
                                    }
                                }
                            }
                            decimal decStandardRate = BllProductCreation.SalesInvoiceProductRateForSales(infoProduct.ProductId, PublicVariables._dtCurrentDate, decBatchId, Convert.ToDecimal(cmbPricinglevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces);
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty)
                            {
                                if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value) != 0)
                                {
                                    dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces);
                                }
                            }
                        }
                        else
                        {
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = string.Empty;
                            dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = string.Empty;
                        }
                        AmountCalculation("dgvtxtQty", e.RowIndex);
                        TotalAmountCalculation();
                    }
                }
                else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtRate")
                {
                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString() != string.Empty)
                    {
                        DefaultRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value);
                    }
                }
                CheckInvalidEntriesInDataGridProduct(e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("SQ:56" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// To fill the details according to the DeliveryNote master Id from frmDeliveryNoteRegister and frmDeliveryNoteReport
        /// </summary>
        public void FillRegisterOrReport()
        {
            try
            {
                DeliveryNoteMasterInfo infoDeliveryNoteMaster = new DeliveryNoteMasterInfo();
                VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
                VoucherTypeBll BllVoucherType = new VoucherTypeBll();
                //DeliveryNoteMasterSP spDeliveryNoteMaster = new DeliveryNoteMasterSP();
                //DeliveryNoteDetailsSP spDeliveryNoteDetails = new DeliveryNoteDetailsSP();
                DeliveryNoteBll bllDeliveryNote = new DeliveryNoteBll();
                SalesOrderMasterInfo infoSalesOrderMaster = new SalesOrderMasterInfo();
                SalesOrderBll bllSalesOrder = new SalesOrderBll();
                SalesQuotationMasterInfo infoSalesQuotationMaster = new SalesQuotationMasterInfo();
                SalesQuotationBll bllSalesQuotatin = new SalesQuotationBll();
                dgvProduct.Rows.Clear();
                isRegisterReportFill = true;
                btnSave.Text = "Update";
                int inRowIndex = 0;
                btnDelete.Enabled = true;
                txtDeliveryNoteNo.ReadOnly = true;
                if (txtDeliveryNoteNo.ReadOnly == true)
                {
                    txtDate.Focus();
                }
                else
                {
                    txtDeliveryNoteNo.Focus();
                }

                infoDeliveryNoteMaster = bllDeliveryNote.DeliveryNoteMasterViewAllByMasterId(decDelivryNoteIdToEdit);
                txtDeliveryNoteNo.Text = infoDeliveryNoteMaster.InvoiceNo;
                strVoucherNo = infoDeliveryNoteMaster.VoucherNo.ToString();
                decDeliveryNoteSuffixPrefixId = Convert.ToDecimal(infoDeliveryNoteMaster.SuffixPrefixId);
                decDeliveryNoteVoucherTypeId = Convert.ToDecimal(infoDeliveryNoteMaster.VoucherTypeId);
                isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(decDeliveryNoteVoucherTypeId);
                decDeliveryNoteTypeId = decDeliveryNoteVoucherTypeId;
                cmbCashOrParty.SelectedValue = infoDeliveryNoteMaster.LedgerId;
                txtDate.Text = infoDeliveryNoteMaster.Date.ToString("dd-MMM-yyyy");
                cmbPricingLevel.SelectedValue = infoDeliveryNoteMaster.PricinglevelId;
                infoVoucherType = BllVoucherType.VoucherTypeView(decDeliveryNoteVoucherTypeId);
                this.Text = infoVoucherType.VoucherTypeName;
                if (infoDeliveryNoteMaster.OrderMasterId != 0)
                {
                    cmbDeliveryMode.Text = "Against Order";
                    infoSalesOrderMaster = bllSalesOrder.SalesOrderMasterView(infoDeliveryNoteMaster.OrderMasterId);
                    cmbType.SelectedValue = infoSalesOrderMaster.VoucherTypeId;
                    AgainstOrderComboFill();
                    cmbOrderNo.SelectedValue = infoDeliveryNoteMaster.OrderMasterId;
                }
                else if (infoDeliveryNoteMaster.QuotationMasterId != 0)
                {
                    cmbDeliveryMode.Text = "Against Quotation";
                    infoSalesQuotationMaster = bllSalesQuotatin.SalesQuotationMasterView(infoDeliveryNoteMaster.QuotationMasterId);
                    cmbType.SelectedValue = infoSalesQuotationMaster.VoucherTypeId;
                    AgainstQuotationComboFill();
                    cmbOrderNo.SelectedValue = infoDeliveryNoteMaster.QuotationMasterId;
                }
                CurrencyComboFill();
                cmbSalesMan.SelectedValue = infoDeliveryNoteMaster.EmployeeId;
                cmbCurrency.SelectedValue = infoDeliveryNoteMaster.ExchangeRateId;
                txtTraspotationCompany.Text = infoDeliveryNoteMaster.TransportationCompany;
                txtNarration.Text = infoDeliveryNoteMaster.Narration;
                txtLRNo.Text = infoDeliveryNoteMaster.LrNo;
                txtTotalAmnt.Text = infoDeliveryNoteMaster.TotalAmount.ToString("00.00");
                List<DataTable> listObjDetails = bllDeliveryNote.DeliveryNoteDetailsViewByDeliveryNoteMasterId(decDelivryNoteIdToEdit);
                foreach (DataRow drowDetails in listObjDetails[0].Rows)
                {
                    dgvProduct.Rows.Add();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].ReadOnly = true;
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].Value = drowDetails["barcode"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtDetailsId"].Value = drowDetails["deliveryNoteDetailsId"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtVoucherNo"].Value = drowDetails["VoucherNo"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtInvoiceNo"].Value = drowDetails["OrderNoOrQuotationNo"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtVoucherTypeId"].Value = drowDetails["VoucherTypeId"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductId"].Value = drowDetails["productId"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductCode"].Value = drowDetails["productCode"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"].Value = drowDetails["productName"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["Col"].Value = drowDetails["slNo"].ToString();
                    if (Convert.ToDecimal(drowDetails["orderDetails1Id"].ToString()) == 0)
                    {
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value = 0;
                    }
                    else
                    {
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value = Convert.ToDecimal(drowDetails["orderDetails1Id"].ToString());
                    }
                    if (Convert.ToDecimal(drowDetails["quotationDetails1Id"].ToString()) != 0)
                    {
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value = Convert.ToDecimal(drowDetails["quotationDetails1Id"].ToString());
                    }
                    BatchComboFill(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].ColumnIndex);
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                    UnitComboFill1(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ColumnIndex);
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                    GridGodownComboFill(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].ColumnIndex);
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(drowDetails["godownId"].ToString());
                    RackComboFill1(Convert.ToDecimal(drowDetails["godownId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbRack"].ColumnIndex);
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbRack"].Value = Convert.ToDecimal(drowDetails["rackId"].ToString());
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtQty"].Value = drowDetails["qty"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtRate"].Value = drowDetails["rate"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtUnitConversionId"].Value = drowDetails["unitConversionId"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value = drowDetails["conversionRate"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtAmount"].Value = drowDetails["amount"].ToString();
                    if (cmbOrderNo.Visible == true)
                    {
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true;
                    }
                    if (bllDeliveryNote.DeliveryNoteMasterReferenceCheckRejectionIn(decDelivryNoteIdToEdit))
                    {
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductCode"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbRack"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtRate"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true;
                    }
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].HeaderCell.Value = "";
                    AmountCalculation("dgvtxtQty", inRowIndex);
                    TotalAmountCalculation();
                }
                if (!isAutomatic)
                {
                    txtDeliveryNoteNo.ReadOnly = false;
                    txtDeliveryNoteNo.Focus();
                }
                isRegisterReportFill = false;
                isDoAfterGridFill = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("DN19: " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void dgvProduct_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            try
            {

                if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQty")
                {
                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuotationDetailsId"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuotationDetailsId"].Value.ToString() != string.Empty && Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuotationDetailsId"].Value.ToString()) != 0)
                    {
                        if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString() != string.Empty)
                        {
                            SalesQuotationBll spSalesQuation = new SalesQuotationBll();
                            decimal decReferencedQty = Math.Round(spSalesQuation.SalesQuatationReferenceCheck(Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuotationDetailsId"].Value.ToString())), PublicVariables._inNoOfDecimalPlaces);
                            decimal decQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString());
                            if (decQty < decReferencedQty)
                            {
                                Messages.InformationMessage("Quantity in row " + (e.RowIndex + 1) + " should be greater than " + decReferencedQty);
                                IsCellValue = false;
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = Math.Round(decReferencedQty,PublicVariables._inNoOfDecimalPlaces);
                                IsCellValue = true;
                            }
                        }
                    }
                    AmountCalculation("dgvtxtQty", e.RowIndex);
                    TotalAmountCalculation();
                }
                else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit")
                {
                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() != string.Empty)
                    {
                        UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                       List< DataTable >listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString());
                       if (listUnitByProduct[0].Rows.Count > 0)
                        {
                            foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows)
                            {
                                if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                                {
                                    dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                                    dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                                    if (IsDoAfterFill)
                                    {
                                        decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                        decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate;
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, Convert.ToInt32(PublicVariables._inNoOfDecimalPlaces));
                                    }
                                }
                            }
                            AmountCalculation("dgvtxtQty", e.RowIndex);
                            TotalAmountCalculation();
                        }
                    }
                }
                else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbBatch")
                {
                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                    {
                        string strProductCode = string.Empty;
                        ProductInfo infoproduct = new ProductInfo();
                        ProductCreationBll BllProductCreation = new ProductCreationBll();
                        decimal decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value);
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = BllProductCreation.BarcodeViewByBatchId(decBatchId);
                        strProductCode = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString();
                        infoproduct = BllProductCreation.ProductViewByCode(strProductCode);
                        DateTime dtcurrentDate = PublicVariables._dtCurrentDate;
                        decimal decNodecplaces = PublicVariables._inNoOfDecimalPlaces;
                        decimal decStandardRate = BllProductCreation.SalesInvoiceProductRateForSales(infoproduct.ProductId, dtcurrentDate, decBatchId, Convert.ToDecimal(cmbPricinglevel.SelectedValue), decNodecplaces);
                        if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty)
                        {
                            if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value) != 0)
                            {
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces);
                            }
                            AmountCalculation("dgvtxtQty", e.RowIndex);
                            TotalAmountCalculation();
                        }
                    }
                }
                else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtExchangeRate" && isAmountcalc)
                {
                    AmountCalculation("dgvtxtExchangeRate", e.RowIndex);
                    TotalAmountCalculation();
                }
                //---------------while changing Rate,corresponding change in amount----
                else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtRate" && isAmountcalc)
                {
                    AmountCalculation("dgvtxtRate", e.RowIndex);
                    TotalAmountCalculation();
                }
                //----while changing amount ,corresponding chnage in total amount-------

                CheckInvalidEntriesInDataGridProduct(e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("SQ:76" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Save Function
        /// </summary>
        public void SaveFunction()
        {
            try
            {
                DeliveryNoteMasterInfo infoDeliveryNoteMaster = new DeliveryNoteMasterInfo();
                DeliveryNoteDetailsInfo infoDeliveryNoteDetails = new DeliveryNoteDetailsInfo();
                StockPostingInfo infoStockPosting = new StockPostingInfo();
                StockPostingBll BllStockPosting = new StockPostingBll();
                // StockPostingSP spStockPosting = new StockPostingSP();
                //DeliveryNoteMasterSP spDeliveryNoteMaster = new DeliveryNoteMasterSP();
                //DeliveryNoteDetailsSP spDeliveryNoteDetails = new DeliveryNoteDetailsSP();
                DeliveryNoteBll bllDeliveryNote = new DeliveryNoteBll();
                SalesOrderMasterInfo infoSalesOrderMaster = new SalesOrderMasterInfo();
                SalesOrderBll bllSalesOrder = new SalesOrderBll();
                SalesQuotationMasterInfo infoSalesQuotationMaster = new SalesQuotationMasterInfo();
                SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
                infoDeliveryNoteMaster.InvoiceNo = txtDeliveryNoteNo.Text;
                infoDeliveryNoteMaster.VoucherTypeId = decDeliveryNoteVoucherTypeId;
                infoDeliveryNoteMaster.Date = Convert.ToDateTime(txtDate.Text);
                infoDeliveryNoteMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
                infoDeliveryNoteMaster.VoucherNo = strVoucherNo;
                infoDeliveryNoteMaster.SuffixPrefixId = decDeliveryNoteSuffixPrefixId;
                if (btnSave.Text == "Save")
                {
                    if (cmbOrderNo.SelectedValue != null)
                    {
                        if (cmbDeliveryMode.Text == "Against Order")
                        {
                            infoDeliveryNoteMaster.OrderMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
                            infoSalesOrderMaster = bllSalesOrder.SalesOrderMasterView(infoDeliveryNoteMaster.OrderMasterId);
                        }
                        else if (cmbDeliveryMode.Text == "Against Quotation")
                        {
                            infoDeliveryNoteMaster.QuotationMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
                            infoSalesQuotationMaster = bllSalesQuotation.SalesQuotationMasterView(infoDeliveryNoteMaster.QuotationMasterId);
                        }
                        else if (cmbDeliveryMode.Text == "NA")
                        {
                            infoDeliveryNoteMaster.OrderMasterId = 0; infoDeliveryNoteMaster.QuotationMasterId = 0;
                        }
                    }
                    else
                    {
                        infoDeliveryNoteMaster.OrderMasterId = 0;
                        infoDeliveryNoteMaster.QuotationMasterId = 0;
                    }
                    infoDeliveryNoteMaster.PricinglevelId = Convert.ToDecimal(cmbPricingLevel.SelectedValue.ToString());
                    if (cmbSalesMan.SelectedIndex != -1)
                    {
                        infoDeliveryNoteMaster.EmployeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString());
                    }
                    else
                    {
                        infoDeliveryNoteMaster.EmployeeId = 0;
                    }
                    infoDeliveryNoteMaster.Narration = txtNarration.Text;
                    infoDeliveryNoteMaster.TotalAmount = Convert.ToDecimal(txtTotalAmnt.Text);
                    infoDeliveryNoteMaster.UserId = PublicVariables._decCurrentUserId;
                    infoDeliveryNoteMaster.LrNo = txtLRNo.Text;
                    infoDeliveryNoteMaster.TransportationCompany = txtTraspotationCompany.Text;
                    infoDeliveryNoteMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                    infoDeliveryNoteMaster.Extra1 = string.Empty;
                    infoDeliveryNoteMaster.Extra2 = string.Empty;
                    infoDeliveryNoteMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                    if (decDelivryNoteIdToEdit == 0)
                    {
                        decDeliveryNoteMasterId = Convert.ToDecimal(bllDeliveryNote.DeliveryNoteMasterAdd(infoDeliveryNoteMaster));
                    }
                    int inRowcount = dgvProduct.Rows.Count;
                    for (int inI = 0; inI < inRowcount - 1; inI++)
                    {
                        if (dgvProduct.Rows[inI].Cells["dgvtxtDetailsId"].Value == null)
                        {
                            if (cmbDeliveryMode.Text == "Against Order")
                            {
                                if (dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value != null)
                                {
                                    infoDeliveryNoteDetails.OrderDetails1Id = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value == null ? string.Empty : dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value.ToString());
                                }
                                else
                                {
                                    infoDeliveryNoteDetails.OrderDetails1Id = 0;
                                    infoDeliveryNoteDetails.QuotationDetails1Id = 0;
                                }
                            }
                            else if (cmbDeliveryMode.Text == "Against Quotation")
                            {
                                if (dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value != null)
                                {
                                    infoDeliveryNoteDetails.QuotationDetails1Id = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value == null ? string.Empty : dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value.ToString());
                                }
                                else
                                {
                                    infoDeliveryNoteDetails.OrderDetails1Id = 0;
                                    infoDeliveryNoteDetails.QuotationDetails1Id = 0;
                                }
                            }
                            else if (cmbDeliveryMode.Text == "NA")
                            {
                                infoDeliveryNoteDetails.OrderDetails1Id = 0;
                                infoDeliveryNoteDetails.QuotationDetails1Id = 0;
                            }
                        }
                        else
                        {
                            if (cmbOrderNo.SelectedText != string.Empty)
                            {
                                if (cmbDeliveryMode.Text == "Against Order")
                                {
                                    infoDeliveryNoteDetails.OrderDetails1Id = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value.ToString());
                                }
                                else if (cmbDeliveryMode.Text == "Against Quotation")
                                {
                                    infoDeliveryNoteDetails.QuotationDetails1Id = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value.ToString());
                                }
                                else if (cmbDeliveryMode.Text == "NA")
                                {
                                    infoDeliveryNoteDetails.OrderDetails1Id = 0;
                                    infoDeliveryNoteDetails.QuotationDetails1Id = 0;
                                }
                            }
                            else
                            {
                                infoDeliveryNoteDetails.OrderDetails1Id = 0;
                                infoDeliveryNoteDetails.QuotationDetails1Id = 0;
                            }
                        }
                        infoDeliveryNoteDetails.ProductId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtProductId"].Value.ToString());
                        infoDeliveryNoteDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                        infoDeliveryNoteDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                        infoDeliveryNoteDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                        infoDeliveryNoteDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                        infoDeliveryNoteDetails.UnitConversionId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString());
                        infoDeliveryNoteDetails.RackId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbRack"].Value.ToString());
                        infoDeliveryNoteDetails.BatchId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString());
                        infoDeliveryNoteDetails.GodownId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
                        infoDeliveryNoteDetails.SlNo = Convert.ToInt32(dgvProduct.Rows[inI].Cells["Col"].Value.ToString());
                        infoDeliveryNoteDetails.Extra1 = string.Empty;
                        infoDeliveryNoteDetails.Extra2 = string.Empty;
                        if (decDelivryNoteIdToEdit == 0)
                        {
                            infoDeliveryNoteDetails.DeliveryNoteMasterId = decDeliveryNoteMasterId;
                            bllDeliveryNote.DeliveryNoteDetailsAdd(infoDeliveryNoteDetails);
                        }
                        else
                        {
                            infoDeliveryNoteDetails.DeliveryNoteMasterId = decDelivryNoteIdToEdit;
                            bllDeliveryNote.DeliveryNoteDetailsEdit(infoDeliveryNoteDetails);
                        }
                        infoStockPosting.Date = Convert.ToDateTime(txtDate.Text);
                        if (dgvProduct.Rows[inI].Cells["dgvtxtVoucherTypeId"].Value != null)
                        {
                            if (cmbDeliveryMode.SelectedItem.ToString() != "NA")
                            {
                                if (dgvProduct.Rows[inI].Cells["dgvtxtVoucherTypeId"].Value != null)
                                {
                                    infoStockPosting.VoucherTypeId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtVoucherTypeId"].Value);
                                }
                                else
                                {
                                    infoStockPosting.VoucherTypeId = 0;
                                }
                                if (dgvProduct.Rows[inI].Cells["dgvtxtVoucherNo"].Value != null)
                                {
                                    infoStockPosting.VoucherNo = dgvProduct.Rows[inI].Cells["dgvtxtVoucherNo"].Value.ToString();
                                }
                                else
                                {
                                    infoStockPosting.VoucherNo = string.Empty;
                                }
                                if (dgvProduct.Rows[inI].Cells["dgvtxtInvoiceNo"].Value != null)
                                {
                                    infoStockPosting.InvoiceNo = dgvProduct.Rows[inI].Cells["dgvtxtInvoiceNo"].Value.ToString();
                                }
                                else
                                {
                                    infoStockPosting.InvoiceNo = string.Empty;
                                }
                                if (decDeliveryNoteVoucherTypeId != 0)
                                {
                                    infoStockPosting.AgainstVoucherTypeId = decDeliveryNoteVoucherTypeId;
                                }
                                else
                                {
                                    infoStockPosting.AgainstVoucherTypeId = 0;
                                }
                                if (strVoucherNo != string.Empty)
                                {
                                    infoStockPosting.AgainstVoucherNo = strVoucherNo;
                                }
                                else
                                {
                                    infoStockPosting.AgainstVoucherNo = string.Empty;
                                }
                                if (txtDeliveryNoteNo.Text != string.Empty)
                                {
                                    infoStockPosting.AgainstInvoiceNo = txtDeliveryNoteNo.Text;
                                }
                                else
                                {
                                    infoStockPosting.AgainstInvoiceNo = string.Empty;
                                }
                            }
                        }
                        else
                        {
                            infoStockPosting.InvoiceNo = txtDeliveryNoteNo.Text;
                            infoStockPosting.VoucherNo = strVoucherNo;
                            infoStockPosting.VoucherTypeId = decDeliveryNoteVoucherTypeId;
                            infoStockPosting.AgainstVoucherTypeId = 0;
                            infoStockPosting.AgainstVoucherNo = "NA";
                            infoStockPosting.AgainstInvoiceNo = "NA";
                        }
                        infoStockPosting.ProductId = infoDeliveryNoteDetails.ProductId;
                        infoStockPosting.BatchId = infoDeliveryNoteDetails.BatchId;
                        infoStockPosting.UnitId = infoDeliveryNoteDetails.UnitId;
                        infoStockPosting.GodownId = infoDeliveryNoteDetails.GodownId;
                        infoStockPosting.RackId = infoDeliveryNoteDetails.RackId;
                        infoStockPosting.OutwardQty = infoDeliveryNoteDetails.Qty;
                        infoStockPosting.Rate = infoDeliveryNoteDetails.Rate;
                        infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                        infoStockPosting.Extra1 = string.Empty;
                        infoStockPosting.Extra2 = string.Empty;
                        BllStockPosting.StockPostingAdd(infoStockPosting);
                    }
                    Messages.SavedMessage();
                    if (cbxPrint.Checked)
                    {
                        SettingsBll BllSettings = new SettingsBll();
                        if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                        {
                            PrintForDotMatrix(decDeliveryNoteMasterId);
                        }
                        else
                        {
                            Print(decDeliveryNoteMasterId);
                        }
                    }
                }
                if (btnSave.Text == "Update")
                {
                    SettingsBll BllSettings = new SettingsBll();
                    infoDeliveryNoteMaster.DeliveryNoteMasterId = decDelivryNoteIdToEdit;
                    infoDeliveryNoteMaster.SuffixPrefixId = Convert.ToDecimal(decDeliveryNoteSuffixPrefixId);
                    infoDeliveryNoteMaster.VoucherNo = strVoucherNo;
                    infoDeliveryNoteMaster.UserId = PublicVariables._decCurrentUserId;//by default current userid used as current employeeid
                    infoDeliveryNoteMaster.PricinglevelId = Convert.ToDecimal(cmbPricingLevel.SelectedValue.ToString());
                    if (cmbSalesMan.SelectedIndex != -1)
                    {
                        infoDeliveryNoteMaster.EmployeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString());
                    }
                    else
                    {
                        infoDeliveryNoteMaster.EmployeeId = 0;
                    }
                    infoDeliveryNoteMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;

                    if (cmbOrderNo.SelectedValue != null)
                    {
                        if (cmbDeliveryMode.Text == "Against Order")
                        {
                            infoDeliveryNoteMaster.OrderMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
                            infoSalesOrderMaster = bllSalesOrder.SalesOrderMasterView(infoDeliveryNoteMaster.OrderMasterId);
                        }
                        else if (cmbDeliveryMode.Text == "Against Quotation")
                        {
                            infoDeliveryNoteMaster.QuotationMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
                            infoSalesQuotationMaster = bllSalesQuotation.SalesQuotationMasterView(infoDeliveryNoteMaster.QuotationMasterId);
                        }
                        else if (cmbDeliveryMode.Text == "NA")
                        {
                            infoDeliveryNoteMaster.OrderMasterId = 0; infoDeliveryNoteMaster.QuotationMasterId = 0;
                        }
                    }
                    else
                    {
                        infoDeliveryNoteMaster.OrderMasterId = 0;
                        infoDeliveryNoteMaster.QuotationMasterId = 0;
                    }
                    infoDeliveryNoteMaster.Narration = txtNarration.Text.Trim();
                    infoDeliveryNoteMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                    infoDeliveryNoteMaster.TotalAmount = Convert.ToDecimal(txtTotalAmnt.Text);
                    infoDeliveryNoteMaster.TransportationCompany = txtTraspotationCompany.Text;
                    infoDeliveryNoteMaster.LrNo = txtLRNo.Text;
                    infoDeliveryNoteMaster.Extra1 = string.Empty;
                    infoDeliveryNoteMaster.Extra2 = string.Empty;
                    bllDeliveryNote.DeliveryNoteMasterEdit(infoDeliveryNoteMaster);
                    RemoveDeliveryNoteDetails();
                    infoDeliveryNoteMaster.VoucherTypeId = decDeliveryNoteVoucherTypeId;
                    bllDeliveryNote.StockPostDeletingForDeliveryNote(decDeliveryNoteVoucherTypeId, strVoucherNo, txtDeliveryNoteNo.Text);
                    DeliveryNoteDetails();
                    Messages.UpdatedMessage();
                    if (frmDeliveryNoteRegisterObj != null)
                    {
                        if (cbxPrint.Checked)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decDelivryNoteIdToEdit);
                            }
                            else
                            {
                                Print(decDelivryNoteIdToEdit);
                            }
                        }
                        frmDeliveryNoteRegisterObj.GridFill();
                    }
                    if (frmDeliveryNoteReportObj != null)
                    {
                        if (cbxPrint.Checked)
                        {
                            if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                            {
                                PrintForDotMatrix(decDelivryNoteIdToEdit);
                            }
                            else
                            {
                                Print(decDelivryNoteIdToEdit);
                            }
                        }
                        frmDeliveryNoteReportObj.GridFill();
                    }
                    this.Close();
                }
                Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("DN35:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to reset the form to create new sales quatation
        /// </summary>
        public void Clear()
        {
            TransactionsGeneralFillBll transactionGeneralFillObj = new TransactionsGeneralFillBll();
            SalesQuotationBll bllSalesQuotation = new SalesQuotationBll();
            try
            {
                if (isAutomatic)
                {
                    strSalesQuotationNo = bllSalesQuotation.SalesQuotationMasterGetMax(decsalesQuotationTypeId).ToString();
                    if (strSalesQuotationNo == string.Empty)
                    {
                        strSalesQuotationNo = " 0";
                    }
                    strSalesQuotationNo = transactionGeneralFillObj.VoucherNumberAutomaicGeneration(decsalesQuotationTypeId, Convert.ToDecimal(strSalesQuotationNo), dtpSalesQuotationDate.Value, tableName);
                    if (Convert.ToDecimal(strSalesQuotationNo) != bllSalesQuotation.SalesQuotationMaxGetPlusOne(decsalesQuotationTypeId))
                    {
                        strSalesQuotationNo = Convert.ToString(bllSalesQuotation.SalesQuotationMaxGetPlusOne(decsalesQuotationTypeId));
                        strSalesQuotationNo = transactionGeneralFillObj.VoucherNumberAutomaicGeneration(decsalesQuotationTypeId, Convert.ToDecimal(strSalesQuotationNo), dtpSalesQuotationDate.Value, tableName);
                        if (bllSalesQuotation.SalesQuotationMasterGetMax(decsalesQuotationTypeId) == 0)
                        {
                            strSalesQuotationNo = "0";
                            strSalesQuotationNo = transactionGeneralFillObj.VoucherNumberAutomaicGeneration(decsalesQuotationTypeId, Convert.ToDecimal(strSalesQuotationNo), dtpSalesQuotationDate.Value, tableName);
                        }
                    }
                    if (isAutomatic)
                    {
                        SuffixPrefixSettingsBll BllSuffixPrefixSettings = new SuffixPrefixSettingsBll();

                        SuffixPrefixInfo infoSuffixPrefix = new SuffixPrefixInfo();
                        infoSuffixPrefix = BllSuffixPrefixSettings.GetSuffixPrefixDetails(decsalesQuotationTypeId, dtpSalesQuotationDate.Value);
                        strPrefix = infoSuffixPrefix.Prefix;
                        strSuffix = infoSuffixPrefix.Suffix;
                        decSalesQuotationPreffixSuffixId = infoSuffixPrefix.SuffixprefixId;
                        strInvoiceNo = strPrefix + strSalesQuotationNo + strSuffix;
                        txtQuotationNo.Text = strInvoiceNo;
                        txtQuotationNo.ReadOnly = true;
                    }
                }
                else
                {
                    txtQuotationNo.Text = string.Empty;
                }
                salesQuotationDatefill();
                if (!ShowProductCode())
                {
                    this.dgvProduct.Columns["dgvtxtProductCode"].Visible = false;
                }
                if (!ShowBarcode())
                {
                    this.dgvProduct.Columns["dgvtxtBarcode"].Visible = false;
                }
                if (PrintAfetrSave())
                {
                    cbxPrintAfterSave.Checked = true;
                }
                else
                {
                    cbxPrintAfterSave.Checked = false;
                }
                dgvProduct.Rows.Clear();
                txtNarration.Text = string.Empty;
                txtTotal.Text = string.Empty;
                btnSave.Text = "Save";
                btnDelete.Enabled = false;
                cbxApproved.Checked = false;
                ComboCurrencyFill();
                ComboPricingLevelFill();
                ComboSalesManFill();
                CashOrPartyCombofill();
                FillProducts(false, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("SQ:31" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// To fill the grid according to the pending Sales Quotation Invoice number
 /// </summary>
 public void FillQuotationDetails()
 {
     SerialNo();
     try
     {
         SalesQuotationBll bllQuotation = new SalesQuotationBll();
         DeliveryNoteMasterInfo infoDeliveryNoteMaster = new DeliveryNoteMasterInfo();
         //DeliveryNoteMasterSP spDeliveryNoteMaster = new DeliveryNoteMasterSP();
         DeliveryNoteBll bllDeliveryNote = new DeliveryNoteBll();
         decimal decOrderNo = 0;
         decimal DefaultRate = 0;
         string strSalesManId;
         inMaxCount = 0;
         decOrderNo = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString());
         dgvProduct.Rows.Clear();
         List<DataTable> ListObj = bllQuotation.SalesQuotationMasterViewByQuotationMasterId(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()));
         if (ListObj[0].Rows.Count > 0)
         {
             cmbPricingLevel.SelectedValue = ListObj[0].Rows[0]["pricingLevelId"].ToString();
             if (ListObj[0].Rows[0]["employeeId"].ToString() != string.Empty)
             {
                 strSalesManId = ListObj[0].Rows[0]["employeeId"].ToString();
                 cmbSalesMan.SelectedValue = strSalesManId;
                 SalesManComboFill();
                 cmbSalesMan.SelectedValue = ListObj[0].Rows[0]["employeeId"].ToString();
             }
             CurrencyComboFill();
             cmbCurrency.SelectedValue = ListObj[0].Rows[0]["exchangeRateId"].ToString();
             List<DataTable> ListObjDelivery = bllQuotation.SalesQuotationDetailsViewByquotationMasterIdWithRemainingByNotInCurrDN(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDeliveryNoteMasterId);
             int inRowIndex = 0;
             isValueChange = false;
             isDoAfterGridFill = false;
             foreach (DataRow drowDetails in ListObjDelivery[0].Rows)
             {
                 dgvProduct.Rows.Add();
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].Value = drowDetails["barcode"].ToString();
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductId"].Value = drowDetails["productId"].ToString();
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductCode"].Value = drowDetails["productCode"].ToString();
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"].Value = drowDetails["productName"].ToString();
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtQty"].Value = drowDetails["Qty"].ToString();
                 UnitComboFill1(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ColumnIndex);
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                 BatchComboFill(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].ColumnIndex);
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                 GridGodownComboFill(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].ColumnIndex);
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(drowDetails["godownId"].ToString());
                 RackComboFill1(Convert.ToDecimal(drowDetails["godownId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbRack"].ColumnIndex);
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbRack"].Value = Convert.ToDecimal(drowDetails["rackId"].ToString());
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtRate"].Value = drowDetails["Rate"].ToString();
                 DefaultRate = Convert.ToDecimal(dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtRate"].Value.ToString());
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value = drowDetails["quotationDetailsId"].ToString();
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtVoucherTypeId"].Value = drowDetails["voucherTypeId"].ToString();
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtVoucherNo"].Value = drowDetails["voucherNo"].ToString();
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtInvoiceNo"].Value = drowDetails["invoiceNo"].ToString();
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drowDetails["unitConversionId"].ToString());
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value = drowDetails["conversionRate"].ToString();
                 if (cmbOrderNo.Visible == true)
                 {
                     dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true;
                 }
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].HeaderCell.Value = "";
                 AmountCalculation("dgvtxtQty", inRowIndex);
                 int inIndex = 0;
                 int.TryParse(drowDetails["extra1"].ToString(), out inIndex);
                 if (inMaxCount < inIndex)
                     inMaxCount = inIndex;
                 inRowIndex++;
                 isValueChange = true;
             }
             for (int i = inRowIndex; i < dgvProduct.Rows.Count; ++i)
                 dgvProduct["inRowIndex", i].Value = GetNextinRowIndex().ToString();
             SerialNo();
             TotalAmountCalculation();
             isDoAfterGridFill = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("DN28 :" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to use to fill details to updation when comes register or report
 /// </summary>
 public void FillRegisterOrReport()
 {
     try
     {
         SalesQuotationMasterInfo infoSalesQuotationMaster = new SalesQuotationMasterInfo();
         SalesOrderMasterInfo infoSalesOrderMaster = new SalesOrderMasterInfo();
         SalesOrderBll bllSalesOrder = new SalesOrderBll();
         isValueChange = false;
         btnSave.Text = "Update";
         btnDelete.Enabled = true;
         txtOrderNo.ReadOnly = true;
         infoSalesOrderMaster = bllSalesOrder.SalesOrderMasterView(decSalesOrderMasterId);
         txtOrderNo.Text = infoSalesOrderMaster.InvoiceNo;
         strVoucherNo = infoSalesOrderMaster.VoucherNo.ToString();
         decSalesSuffixPrefixId = Convert.ToDecimal(infoSalesOrderMaster.SuffixPrefixId);
         decSalesVoucherId = Convert.ToDecimal(infoSalesOrderMaster.VoucherTypeId);
         isAutomatic = new VoucherTypeBll().CheckMethodOfVoucherNumbering(decSalesVoucherId);
         decSalesOrderTypeId = decSalesVoucherId;
         txtDate.Text = infoSalesOrderMaster.Date.ToString("dd-MMM-yyyy");
         cmbCashOrParty.SelectedValue = infoSalesOrderMaster.LedgerId;
         decSalesOrderVoucherTypeId = infoSalesOrderMaster.VoucherTypeId;
         VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
         VoucherTypeBll BllVoucherType = new VoucherTypeBll();
         infoVoucherType = BllVoucherType.VoucherTypeView(decSalesOrderVoucherTypeId);
         string strVoucherTypeName = infoVoucherType.VoucherTypeName;
         this.Text = strVoucherTypeName;
         if (infoSalesOrderMaster.QuotationMasterId == 0)
         {
             cmbType.SelectedItem = "NA";
         }
         else if (infoSalesOrderMaster.QuotationMasterId != 0)
         {
             infoSalesQuotationMaster = new SalesQuotationBll().SalesQuotationMasterView(infoSalesOrderMaster.QuotationMasterId);
             cmbType.SelectedValue = infoSalesQuotationMaster.VoucherTypeId;
             AgainstQuotationComboFill();
             cmbQuotationNo.SelectedValue = infoSalesOrderMaster.QuotationMasterId;
         }
         txtDueDate.Text = infoSalesOrderMaster.DueDate.ToString("dd-MMM-yyyy");
         TimeSpan objTs = Convert.ToDateTime(txtDueDate.Text).Subtract(Convert.ToDateTime(txtDate.Text));
         txtDueDays.Text = objTs.Days.ToString();
         txtNarration.Text = infoSalesOrderMaster.Narration;
         cmbCurrency.SelectedValue = infoSalesOrderMaster.ExchangeRateId;
         cmbPricingLevel.SelectedValue = infoSalesOrderMaster.PricinglevelId;
         SalesManComboFill();
         cmbSalesMan.SelectedValue = infoSalesOrderMaster.EmployeeId;
         txtTotalAmount.Text = infoSalesOrderMaster.TotalAmount.ToString();
         List<DataTable> ListObj = new List<DataTable>();
         ListObj = bllSalesOrder.SalesOrderDetailsViewByMasterId(decSalesOrderMasterId);
         if (CheckCancelStatus(decSalesOrderMasterId))
         {
             isCheck = true;
             cbxCancelled.Checked = true;
             cbxCancelled.Enabled = false;
             btnSave.Enabled = false;
             isCheck = false;
         }
         else
         {
             isCheck = true;
             cbxCancelled.Enabled = true;
             cbxCancelled.Checked = false;
             isCheck = false;
         }
         if (isAutomatic)
         {
             txtOrderNo.ReadOnly = true;
             txtDate.Focus();
         }
         else
         {
             txtOrderNo.ReadOnly = false;
             txtOrderNo.Focus();
         }
         for (int i = 0; i < ListObj[0].Rows.Count; i++)
         {
             isAmountcalc = false;
             isValueChange = false;
             dgvSalesOrder.Rows.Add();
             dgvSalesOrder.Rows[i].HeaderCell.Value = string.Empty;
             dgvSalesOrder.Rows[i].Cells["dgvtxtSalesOrderDetailsId"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["salesOrderDetailsId"].ToString());
             dgvSalesOrder.Rows[i].Cells["dgvtxtProductId"].Value = ListObj[0].Rows[i]["productId"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtProductCode"].Value = ListObj[0].Rows[i]["productCode"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtProductName"].Value = ListObj[0].Rows[i]["productName"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtQty"].Value = ListObj[0].Rows[i]["qty"].ToString();
             UnitComboFill(Convert.ToDecimal(dgvSalesOrder.Rows[i].Cells["dgvtxtProductId"].Value.ToString()), i, dgvSalesOrder.Rows[i].Cells["dgvcmbUnit"].ColumnIndex);
             dgvSalesOrder.Rows[i].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["unitId"].ToString());
             dgvSalesOrder.Rows[i].Cells["dgvtxtRate"].Value = ListObj[0].Rows[i]["rate"].ToString();
             BatchComboFill(Convert.ToDecimal(dgvSalesOrder.Rows[i].Cells["dgvtxtProductId"].Value.ToString()), i, dgvSalesOrder.Rows[i].Cells["dgvcmbBatch"].ColumnIndex);
             dgvSalesOrder.Rows[i].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["batchId"].ToString());
             dgvSalesOrder.Rows[i].Cells["dgvtxtBarcode"].Value = ListObj[0].Rows[i]["barcode"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtAmount"].Value = ListObj[0].Rows[i]["amount"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtUnitConversionId"].Value = ListObj[0].Rows[i]["unitConversionId"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtConversionRate"].Value = ListObj[0].Rows[i]["conversionRate"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtSalesQuotationDetailsId"].Value = ListObj[0].Rows[i]["quotationDetailsId"].ToString();
             if (Convert.ToDecimal(ListObj[0].Rows[i]["quotationDetailsId"].ToString()) != 0)
             {
                 dgvSalesOrder.Rows[i].Cells["dgvtxtProductCode"].ReadOnly = true;
                 dgvSalesOrder.Rows[i].Cells["dgvtxtProductName"].ReadOnly = true;
                 dgvSalesOrder.Rows[i].Cells["dgvtxtBarcode"].ReadOnly = true;
             }
             if (cmbQuotationNo.Visible == true)
             {
                 dgvSalesOrder.Rows[i].Cells["dgvcmbUnit"].ReadOnly = true;
             }
         }
         isAmountcalc = true;
         isEditFill = false;
         isValueChange = true;
         isDoAfterGridFill = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show("SO30:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }