/// <summary>
 /// Doing the grid calculations other functions in grid CellEndEdit event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvPurchaseOrder_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     ProductCreationBll BllProductCreation = new ProductCreationBll();
     ProductInfo infoProduct = new ProductInfo();
     List<DataTable> listObj = new List<DataTable>();
     try
     {
         isValueChange = false;
         isDoAfterGridFill = false;
         if (dgvPurchaseOrder.Columns[e.ColumnIndex].Name == "dgvtxtProductName")
         {
             string strProductName = string.Empty;
             if (dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value != null && dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString().Trim() != string.Empty)
             {
                 strProductName = dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString();
             }
             infoProduct = BllProductCreation.ProductViewByName(strProductName);
             if (infoProduct.ProductCode != null && infoProduct.ProductCode != string.Empty)
             {
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value = infoProduct.ProductId;
                 UnitComboFill(infoProduct.ProductId, e.RowIndex, dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].ColumnIndex);
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = infoProduct.UnitId;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces).ToString();
                 UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                 listunitconversionViewAll = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString());
                 foreach (DataRow drUnitByProduct in listunitconversionViewAll[0].Rows)
                 {
                     if (dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                     {
                         dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = drUnitByProduct.ItemArray[2].ToString();
                         dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value = drUnitByProduct.ItemArray[3].ToString();
                     }
                 }
                 decCurrentConversionRate = Convert.ToDecimal(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value.ToString());
                 decCurrentRate = Convert.ToDecimal(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString());
                 NewAmountCalculation("dgvtxtQty", e.RowIndex);
                 CalculateTotalAmount();
             }
             else
             {
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value = string.Empty;
             }
         }
         else if (dgvPurchaseOrder.Columns[e.ColumnIndex].Name == "dgvtxtProductCode")
         {
             string strPrdCode = string.Empty;
             if (dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty)
             {
                 strPrdCode = dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString();
             }
             infoProduct = BllProductCreation.ProductViewByCode(strPrdCode);
             if (infoProduct.ProductId != 0)
             {
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = infoProduct.ProductName;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value = infoProduct.ProductId;
                 decimal decproductId = infoProduct.ProductId;
                 UnitComboFill(infoProduct.ProductId, e.RowIndex, dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].ColumnIndex);
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = infoProduct.UnitId;
                 UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                 listunitconversionViewAll = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString());
                 foreach (DataRow drUnitByProduct in listunitconversionViewAll[0].Rows)
                 {
                     if (dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                     {
                         dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = drUnitByProduct.ItemArray[2].ToString();
                         dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value = drUnitByProduct.ItemArray[3].ToString();
                     }
                 }
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces);
                 if (infoProduct.PartNo != string.Empty)
                 {
                     dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = infoProduct.PartNo;
                 }
                 decCurrentConversionRate = Convert.ToDecimal(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value.ToString());
                 decCurrentRate = Convert.ToDecimal(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString());
                 NewAmountCalculation("dgvtxtQty", e.RowIndex);
                 CalculateTotalAmount();
             }
             else
             {
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value = string.Empty;
             }
         }
         else if (dgvPurchaseOrder.Columns[e.ColumnIndex].Name == "dgvtxtBarcode")
         {
             string strBCode = string.Empty;
             if (dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value != null && dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString().Trim() != string.Empty)
             {
                 strBCode = dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString();
             }
             listObj = BllProductCreation.ProductDetailsCoreespondingToBarcode(strBCode);
             if (listObj[0].Rows.Count > 0)
             {
                 foreach (DataRow RowDetails in listObj[0].Rows)
                 {
                     dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value = RowDetails["productId"].ToString();
                     dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = RowDetails["productCode"].ToString();
                     dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = RowDetails["productName"].ToString();
                     UnitComboFill(Convert.ToDecimal(RowDetails["productId"].ToString()), e.RowIndex, dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].ColumnIndex);
                     dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(RowDetails["unitId"].ToString());
                     UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                     listunitconversionViewAll = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString());
                     foreach (DataRow drUnitByProduct in listunitconversionViewAll[0].Rows)
                     {
                         if (dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                         {
                             dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = drUnitByProduct.ItemArray[2].ToString();
                             dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value = drUnitByProduct.ItemArray[3].ToString();
                         }
                     }
                     dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(RowDetails["purchaseRate"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                     decCurrentConversionRate = Convert.ToDecimal(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value.ToString());
                     decCurrentRate = Convert.ToDecimal(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString());
                     NewAmountCalculation("dgvtxtQty", e.RowIndex);
                     CalculateTotalAmount();
                 }
             }
             else
             {
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = string.Empty;
                 dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value = string.Empty;
             }
         }
         CheckInvalidEntries(e);
         isAmountcalc = true;
         isValueChange = true;
         isDoAfterGridFill = true;
         if (txtTotalAmount.Text.ToString().Split('.')[0].Length > 13)
         {
             MessageBox.Show("Amount exxed than limit");
             dgvPurchaseOrder.Rows.RemoveAt(dgvPurchaseOrder.Rows.Count - 2);
             CalculateTotalAmount();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PO48:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Grid CellEndEdit for product details fill to curresponding row in grid
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvPurchaseReturn_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         string strBarcode2 = string.Empty;
         decimal decBatchId2 = 0;
         BatchBll BllBatch = new BatchBll();
         RackBll BllRack = new RackBll();
         PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll();
         PurchaseReturnBll BllPurchaseReturn = new PurchaseReturnBll();
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtproductName")
         {
             if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductName"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductName"].Value.ToString().Trim() != string.Empty)
             {
                 ProductInfo infoProduct = BllProductCreation.ProductViewByName(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductName"].Value.ToString());
                 if (infoProduct.ProductCode != null && infoProduct.ProductCode != string.Empty)
                 {
                     FillProductDetails(infoProduct.ProductCode.ToString(), e.RowIndex);
                 }
                 else
                 {
                     StringEmptyDetailsInGrid();
                 }
             }
             else
             {
                 dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductName"].Value = string.Empty;
             }
         }
         else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtproductCode")
         {
             if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value.ToString().Trim() != string.Empty)
             {
                 ProductInfo infoProduct = BllProductCreation.ProductViewByCode(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value.ToString());
                 if (infoProduct.ProductName != null && infoProduct.ProductCode != string.Empty)
                 {
                     FillProductDetails(infoProduct.ProductCode.ToString(), e.RowIndex);
                 }
                 else
                 {
                     StringEmptyDetailsInGrid();
                 }
             }
             else
             {
                 dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value = string.Empty;
             }
         }
         else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtbarcode")
         {
             if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value.ToString().Trim() != string.Empty)
             {
                 string strBarcode = dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value.ToString();
                 decBatchId = BllProductCreation.BatchIdByPartNoOrBarcode(strBarcode, strBarcode);
                 if (decBatchId > 0)
                 {
                     List<DataTable> listObjBatchName = new List<DataTable>();
                     listObjBatchName = BllProductCreation.ProductCodeAndBarcodeByBatchId(decBatchId);
                     dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value = listObjBatchName[0].Rows[0]["productCode"].ToString();
                     if (listObjBatchName[0].Rows[0]["barcode"].ToString() != null && listObjBatchName[0].Rows[0]["barcode"].ToString() != string.Empty)
                     {
                         dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value = listObjBatchName[0].Rows[0]["barcode"].ToString();
                     }
                     decimal batchId = BllBatch.BatchViewByBarcode(strBarcode);
                     dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = batchId;
                     FillProductDetails(listObjBatchName[0].Rows[0]["productCode"].ToString(), e.RowIndex);
                 }
                 else
                 {
                     StringEmptyDetailsInGrid();
                 }
             }
             else
             {
                 dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value = string.Empty;
             }
         }
         if (e.ColumnIndex == dgvPurchaseReturn.Columns["dgvcmbUnit"].Index)
         {
             if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvcmbUnit")
             {
                 if ((dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null) && (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() != string.Empty))
                 {
                     UnitConversionCalc(e.RowIndex);
                     AmountCalculation("dgvtxtqty", e.RowIndex);
                 }
             }
         }
         if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtqty" && isAmountcalc)
         {
             if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value.ToString() != string.Empty && Convert.ToDecimal(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value.ToString()) != 0)
             {
                 if (cmbInvoiceNo.SelectedValue == null || cmbInvoiceNo.SelectedValue.ToString() == string.Empty)
                 {
                     AmountCalculation("dgvtxtqty", e.RowIndex);
                 }
                 else
                 {
                     List<DataTable> ListObj= BllPurchaseInvoice.PurchaseDetailsViewByPurchaseMasterIdWithRemaining(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()), decPurchaseReturnMasterId, decPurchaseReturnVoucherTypeId);
                     if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtPurchaseDetailsId"].Value != null)
                     {
                         if (Convert.ToDecimal(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtPurchaseDetailsId"].Value.ToString()) > 0)
                         {
                             if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value != null)
                             {
                                 if (Convert.ToDecimal(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value.ToString()) > Convert.ToDecimal(ListObj[0].Rows[e.RowIndex]["qty"].ToString()))
                                 {
                                     dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value = Math.Round(Convert.ToDecimal(ListObj[0].Rows[e.RowIndex]["qty"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                                 }
                             }
                         }
                     }
                     AmountCalculation("dgvtxtqty", e.RowIndex);
                 }
             }
         }
         else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtrate" && isAmountcalc)
         {
             if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value.ToString() != string.Empty && Convert.ToDecimal(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value.ToString()) != 0)
             {
                 AmountCalculation("dgvtxtrate", e.RowIndex);
             }
         }
         else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtdiscount")
         {
             if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtdiscount"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtdiscount"].Value.ToString().Trim() != string.Empty && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtDiscount"].Value.ToString().Trim() != "0")
             {
                 AmountCalculation("dgvtxtrate", e.RowIndex);
             }
         }
         else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvcmbTax" && isAmountcalc)
         {
             if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbTax"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbTax"].Value.ToString() != string.Empty)
             {
                 AmountCalculation("dgvtxtrate", e.RowIndex);
             }
         }
         else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvcmbBatch")
         {
             if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
             {
                 decBatchId2 = Convert.ToDecimal(dgvPurchaseReturn.CurrentRow.Cells["dgvcmbBatch"].Value);
                 strBarcode2 = BllBatch.ProductBatchBarcodeViewByBatchId(decBatchId2);
                 dgvPurchaseReturn.CurrentRow.Cells["dgvtxtbarcode"].Value = strBarcode2;
             }
         }
         CheckInvalidEntries(e);
     }
     catch (Exception ex)
     {
         MessageBox.Show("PR:80" + 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>
        /// On cellEndEdit of grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvProduct_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            ProductInfo infoProduct = new ProductInfo();
            BatchBll BllBatch = new BatchBll();
            ProductCreationBll BllProductCreation = new ProductCreationBll();
            StockPostingBll BllStockPosting = new StockPostingBll();
            //StockPostingSP spStockPosting = new StockPostingSP();
            try
            {
                isDoAfterGridFill = false;
                isValueChange = false;
                if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtProductName")
                {
                    string strProductName = string.Empty;
                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString() != string.Empty)
                    {
                        strProductName = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString();
                    }
                    infoProduct = BllProductCreation.ProductViewByName(strProductName);
                    if (infoProduct.ProductCode != null && infoProduct.ProductCode != string.Empty)
                    {
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode;
                        decimal decproductId = infoProduct.ProductId;
                        dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = infoProduct.ProductId;
                        BatchComboFill(decproductId, e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex));
                        decimal decBatchId = BllStockPosting.BatchViewByProductId(decproductId);
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = decBatchId;
                        decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value);
                        string strBarcode = BllBatch.ProductBatchBarcodeViewByBatchId(decBatchId);
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = strBarcode;
                        ListObj = BllProductCreation.ProductDetailsCoreespondingToBarcode(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString());
                        if (ListObj[0].Rows.Count > 0)
                        {
                            foreach (DataRow RowDetails in ListObj[0].Rows)
                            {
                                isValueChange = false;
                                dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = RowDetails["productId"].ToString();
                                decimal decProductId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value);
                                BatchComboFill(decProductId, e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex));
                                dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(RowDetails["batchId"].ToString());
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = RowDetails["productCode"].ToString();
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = RowDetails["productName"].ToString();
                                dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(RowDetails["godownId"].ToString());
                                decGodownId = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value);
                                RackComboFill(decGodownId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].ColumnIndex);

                                dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = Convert.ToDecimal(RowDetails["rackId"].ToString());
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(RowDetails["purchaseRate"].ToString()), PublicVariables._inNoOfDecimalPlaces).ToString();
                                UnitComboFill(decProductId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].ColumnIndex);
                                dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(RowDetails["unitId"].ToString());

                                UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                               List< DataTable> listUnitByProduct = new List<DataTable>();
                               listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value.ToString());
                               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());
                                    }
                                }
                                decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString());
                                decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                NewAmountCalculation("dgvtxtQty", e.RowIndex);
                                CalculateTotalAmount();
                            }
                        }
                    }
                    else
                    {
                        isValueChange = false;
                        dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                        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["dgvtxtQty"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty;
                        isValueChange = true;
                    }
                }
                if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtProductCode")
                {
                    string strPrdCode = string.Empty;
                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty)
                    {
                        strPrdCode = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString();
                    }
                    isDoAfterGridFill = false;
                    infoProduct = BllProductCreation.ProductViewByCode(strPrdCode);
                    if (infoProduct.ProductId != 0)
                    {
                        decimal decproductId = infoProduct.ProductId;
                        dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = infoProduct.ProductId;
                        BatchComboFill(decproductId, e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex));
                        decimal decBatchId = BllStockPosting.BatchViewByProductId(decproductId);
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = decBatchId;
                        decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value);
                        string strBarcode = BllBatch.ProductBatchBarcodeViewByBatchId(decBatchId);
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = strBarcode;
                        ListObj = BllProductCreation.ProductDetailsCoreespondingToBarcode(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString());
                        if (ListObj[0].Rows.Count > 0)
                        {
                            foreach (DataRow RowDetails in ListObj[0].Rows)
                            {
                                isValueChange = false;
                                dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = RowDetails["productId"].ToString();
                                decimal decProductId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value);
                                BatchComboFill(decProductId, e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex));
                                dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(RowDetails["batchId"].ToString());
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = RowDetails["productCode"].ToString();
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = RowDetails["productName"].ToString();
                                dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(RowDetails["godownId"].ToString());
                                decGodownId = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value);
                                RackComboFill(decGodownId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].ColumnIndex);
                                dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = Convert.ToDecimal(RowDetails["rackId"].ToString());
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(RowDetails["purchaseRate"].ToString()), PublicVariables._inNoOfDecimalPlaces).ToString();
                                UnitComboFill(decProductId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].ColumnIndex);
                                dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(RowDetails["unitId"].ToString());
                                UnitConvertionBll bllUnitByProduct = new UnitConvertionBll();
                               List< DataTable >listUnitByProduct = new List<DataTable>();
                               listUnitByProduct = bllUnitByProduct.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value.ToString());
                               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());
                                    }
                                }
                                decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString());
                                decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                NewAmountCalculation("dgvtxtQty", e.RowIndex);
                                CalculateTotalAmount();
                            }
                        }
                    }
                    else
                    {
                        isValueChange = false;
                        dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                        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["dgvtxtQty"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty;
                        isValueChange = true;
                    }
                }
                if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtBarcode")
                {
                    string strBCode = string.Empty;
                   // DataTable dtbl = new DataTable();
                    if (!dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].ReadOnly && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString() != string.Empty)
                    {
                        strBCode = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString();
                    }
                    isDoAfterGridFill = false;
                    ListObj = BllProductCreation.ProductDetailsCoreespondingToBarcode(strBCode);
                    if (ListObj[0].Rows.Count > 0)
                    {
                        foreach (DataRow RowDetails in ListObj[0].Rows)
                        {
                            isValueChange = false;
                            dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = RowDetails["productId"].ToString();
                            decimal decProductId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value);
                            BatchComboFill(decProductId, e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex));
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(RowDetails["batchId"].ToString());
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = RowDetails["productCode"].ToString();
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = RowDetails["productName"].ToString();
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(RowDetails["godownId"].ToString());
                            decGodownId = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value);
                            RackComboFill(decGodownId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].ColumnIndex);
                            dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = Convert.ToDecimal(RowDetails["rackId"].ToString());
                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(RowDetails["purchaseRate"].ToString()), PublicVariables._inNoOfDecimalPlaces).ToString();
                            UnitComboFill(decProductId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].ColumnIndex);
                            dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(RowDetails["unitId"].ToString());
                            UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                            List<DataTable> listUnitByProduct = new List<DataTable>();
                            listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value.ToString());
                            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());
                                }
                            }
                            decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString());
                            decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                            NewAmountCalculation("dgvtxtQty", e.RowIndex);
                            CalculateTotalAmount();
                        }
                    }
                    else
                    {
                        isValueChange = false;
                        dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
                        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["dgvtxtQty"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = string.Empty;
                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty;
                        isValueChange = true;
                    }
                }
                CheckInvalidEntries(e);
                isDoAfterGridFill = true;
                isValueChange = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("MR68:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }