/// <summary>
 /// Function to fill the voucher details for edit
 /// </summary>
 public void MaterialReceiptDetailsEditFill()
 {
     ProductInfo infoProduct = new ProductInfo();
     MaterialReceiptDetailsInfo infoMaterialReceiptDetails = new MaterialReceiptDetailsInfo();
     StockPostingBll BllStockPosting = new StockPostingBll();
     MaterialReceiptBll bllMaterialReceipt = new MaterialReceiptBll();
     ProductCreationBll BllProductCreation = new ProductCreationBll();
     try
     {
         for (int inI = 0; inI < dgvProduct.Rows.Count - 1; inI++)
         {
             decimal decStatus = bllMaterialReceipt.MaterialReceiptDetailsReferenceCheck(decMaterialReceiptDetailId);
             if (decStatus == 1)
             {
                 dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvtxtProductName"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvcmbUnit"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvtxtBarcode"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvCmbRack"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvcmbGodown"].ReadOnly = true;
                 dgvProduct.Rows[inI].Cells["dgvtxtRate"].ReadOnly = true;
             }
             if (dgvProduct.Rows[inI].Cells["dgvtxtProductName"].Value != null)
             {
                 if (dgvProduct.Rows[inI].Cells["dgvtxtMaterialReceiptdetailsId"].Value == null || dgvProduct.Rows[inI].Cells["dgvtxtMaterialReceiptdetailsId"].Value.ToString() == string.Empty)
                 {
                     infoMaterialReceiptDetails.MaterialReceiptMasterId = decMaterialReceiptMasterId;
                     infoProduct = BllProductCreation.ProductViewByCode(dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                     infoMaterialReceiptDetails.ProductId = infoProduct.ProductId;
                     if (dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value != null)
                     {
                         infoMaterialReceiptDetails.OrderDetailsId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString());
                     }
                     else
                         infoMaterialReceiptDetails.OrderDetailsId = 0;
                     infoMaterialReceiptDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                     infoMaterialReceiptDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                     infoMaterialReceiptDetails.UnitConversionId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value);
                     if (dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.GodownId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.GodownId = 1;
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value != null && dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.RackId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.RackId = 1;
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.BatchId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.BatchId = 1;
                     }
                     infoMaterialReceiptDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                     infoMaterialReceiptDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                     infoMaterialReceiptDetails.Slno = Convert.ToInt32(dgvProduct.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
                     infoMaterialReceiptDetails.Extra1 = string.Empty;
                     infoMaterialReceiptDetails.Exta2 = string.Empty;
                     infoMaterialReceiptDetails.ExtraDate = Convert.ToDateTime(DateTime.Now);
                     bllMaterialReceipt.MaterialReceiptDetailsAdd(infoMaterialReceiptDetails);
                 }
                 else
                 {
                     infoMaterialReceiptDetails.MaterialReceiptMasterId = decMaterialReceiptMasterId;
                     infoMaterialReceiptDetails.MaterialReceiptDetailsId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtMaterialReceiptdetailsId"].Value);
                     infoProduct = BllProductCreation.ProductViewByCode(dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                     infoMaterialReceiptDetails.ProductId = infoProduct.ProductId;
                     if (dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value != null)
                     {
                         infoMaterialReceiptDetails.OrderDetailsId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString());
                     }
                     else
                         infoMaterialReceiptDetails.OrderDetailsId = 0;
                     infoMaterialReceiptDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                     infoMaterialReceiptDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                     infoMaterialReceiptDetails.UnitConversionId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value);
                     infoMaterialReceiptDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                     if (dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.GodownId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.GodownId = 1;
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value != null && dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.RackId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.RackId = 1;
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                     {
                         infoMaterialReceiptDetails.BatchId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString());
                     }
                     else
                     {
                         infoMaterialReceiptDetails.BatchId = 1;
                     }
                     infoMaterialReceiptDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                     infoMaterialReceiptDetails.Slno = Convert.ToInt32(dgvProduct.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
                     infoMaterialReceiptDetails.Extra1 = string.Empty;
                     infoMaterialReceiptDetails.Exta2 = string.Empty;
                     infoMaterialReceiptDetails.ExtraDate = Convert.ToDateTime(DateTime.Now);
                     bllMaterialReceipt.MaterialReceiptDetailsEdit(infoMaterialReceiptDetails);
                 }
                 StockPostingInfo infoStockPosting = new StockPostingInfo();
                 infoStockPosting.Date = Convert.ToDateTime(txtDate.Text);
                 infoStockPosting.ProductId = infoMaterialReceiptDetails.ProductId;
                 infoStockPosting.BatchId = infoMaterialReceiptDetails.BatchId;
                 infoStockPosting.UnitId = infoMaterialReceiptDetails.UnitId;
                 infoStockPosting.GodownId = infoMaterialReceiptDetails.GodownId;
                 infoStockPosting.RackId = infoMaterialReceiptDetails.RackId;
                 if (cmbOrderNo.SelectedValue != null)
                 {
                     if (dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value.ToString() != string.Empty && dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value.ToString() != "NA")
                     {
                         infoStockPosting.VoucherNo = Convert.ToString(dgvProduct.Rows[inI].Cells["dgvtxtvoucherNo"].Value.ToString());
                         infoStockPosting.AgainstVoucherNo = strVoucherNo;
                     }
                     else
                     {
                         infoStockPosting.VoucherNo = strVoucherNo;
                         infoStockPosting.AgainstVoucherNo = "NA";
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value.ToString() != string.Empty && dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value.ToString() != "NA")
                     {
                         infoStockPosting.InvoiceNo = Convert.ToString(dgvProduct.Rows[inI].Cells["dgvtxtinvoiceNo"].Value.ToString());
                         infoStockPosting.AgainstInvoiceNo = txtReceiptNo.Text;
                     }
                     else
                     {
                         infoStockPosting.InvoiceNo = txtReceiptNo.Text;
                         infoStockPosting.AgainstInvoiceNo = "NA";
                     }
                     if (dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value != null && dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value.ToString() != string.Empty && Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value.ToString()) != 0)
                     {
                         infoStockPosting.VoucherTypeId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtvouchertypeId"].Value.ToString());
                         infoStockPosting.AgainstVoucherTypeId = decMaterialReceiptVoucherTypeId;
                     }
                     else
                     {
                         infoStockPosting.VoucherTypeId = decMaterialReceiptVoucherTypeId;
                         infoStockPosting.AgainstVoucherTypeId = 0;
                     }
                 }
                 else
                 {
                     infoStockPosting.InvoiceNo = txtReceiptNo.Text;
                     infoStockPosting.VoucherNo = strVoucherNo;
                     infoStockPosting.VoucherTypeId = decMaterialReceiptVoucherTypeId;
                     infoStockPosting.AgainstVoucherTypeId = 0;
                     infoStockPosting.AgainstVoucherNo = "NA";
                     infoStockPosting.AgainstInvoiceNo = "NA";
                 }
                 BllStockPosting.StockPostingDeleteByVoucherTypeAndVoucherNo(strVoucherNo, decMaterialReceiptVoucherTypeId);
                 infoStockPosting.InwardQty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                 infoStockPosting.OutwardQty = 0;
                 infoStockPosting.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                 infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoStockPosting.Extra1 = string.Empty;
                 infoStockPosting.Extra2 = string.Empty;
                 BllStockPosting.StockPostingAdd(infoStockPosting);
                 isEdit = true;
             }
         }
         if (isEdit)
         {
             cmbCashOrParty.Enabled = true;
             cmbOrderNo.Enabled = true;
             cmbcurrency.Enabled = true;
             txtDate.Enabled = true;
             cmbVoucherType.Enabled = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR37:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }