/// <summary>
 /// Grid fill function Againest SalseOrderDetails
 /// </summary>
 public void gridFillAgainestSalseOrderDetails()
 {
     BrandBll BllBrand = new BrandBll();
     //SalesOrderBll bllSalesOrder = new SalesOrderBll();
     SalesOrderBll bllSalesOrder = new SalesOrderBll();
     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> ListObj= bllSalesOrder.SalesInvoiceGridfillAgainestSalesOrder(Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString()));
             cmbPricingLevel.SelectedValue = Convert.ToDecimal(ListObj[0].Rows[0]["pricingLevelId"].ToString());
             cmbCurrency.SelectedValue = Convert.ToDecimal(ListObj[0].Rows[0]["exchangeRateId"].ToString());
             if (ListObj[0].Rows[0]["employeeId"].ToString() != string.Empty)
             {
                 strSalesManId = ListObj[0].Rows[0]["employeeId"].ToString();
                 cmbSalesMan.SelectedValue = strSalesManId;
                 if (cmbSalesMan.SelectedValue == null)
                 {
                     salesManComboFill();
                     cmbSalesMan.SelectedValue = ListObj[0].Rows[0]["employeeId"].ToString();
                 }
             }
             cmbPricingLevel.Enabled = false;
             btnNewPricingLevel.Enabled = false;
             cmbCurrency.Enabled = false;
              ListObj = bllSalesOrder.SalesInvoiceGridfillAgainestSalesOrderUsingSalesDetails(Convert.ToDecimal(cmbSalesModeOrderNo.SelectedValue.ToString()), Convert.ToDecimal(decSalesInvoiceIdToEdit), DecSalesInvoiceVoucherTypeId);
             int inRowIndex = 0;
             foreach (DataRow drowDetails in ListObj[0].Rows)
             {
                 dgvSalesInvoice.Rows.Add();
                 isValueChange = false;
                 IsSetGridValueChange = false;
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSISalesOrderDetailsId"].Value = drowDetails["salesOrderDetailsId"].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["salesOrderDetailsId"].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceProductId"].Value = drowDetails.ItemArray[2].ToString();
                 dgvSalesInvoice.Rows[dgvSalesInvoice.Rows.Count - 2].Cells["dgvtxtSalesInvoiceUnitConversionId"].Value = drowDetails["unitConversionId"].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;
                 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["salesOrderDetailsId"].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: 51" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }