/// <summary>
 /// Function to fill the details against purchase order
 /// </summary>
 public void FillOrderDetails()
 {
     BatchBll BllBatch = new BatchBll();
     PurchaseOrderBll BllPurchaseOrder = new PurchaseOrderBll();
     //StockPostingSP spStockPosting = new StockPostingSP();
     StockPostingBll BllStockPosting = new StockPostingBll();
     ProductCreationBll BllProductCreation = new ProductCreationBll();
     try
     {
         if (!isEditFill)
         {
             isValueChange = false;
             if (dgvProduct.RowCount > 1)
             {
                 for (int i = 0; i < dgvProduct.RowCount - 1; i++)
                 {
                     if (dgvProduct.Rows[i].Cells["dgvtxtMaterialReceiptdetailsId"].Value != null && dgvProduct.Rows[i].Cells["dgvtxtMaterialReceiptdetailsId"].Value.ToString() != string.Empty)
                     {
                         lstArrOfRemove.Add(dgvProduct.Rows[i].Cells["dgvtxtMaterialReceiptdetailsId"].Value.ToString());
                     }
                 }
             }
             dgvProduct.Rows.Clear();
             isValueChange = true;
             isDoAfterGridFill = false;
             List<DataTable> ListObjDetails = new List<DataTable>();
             if (Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()) == decOrderNoWhileEditMode && btnSave.Text == "Update")
             {
                 ListObjDetails = BllPurchaseOrder.PurchaseOrderDetailsViewByOrderMasterIdWithRemainingForEdit(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decMaterialReceiptId);
             }
             else
             {
                 ListObjDetails = BllPurchaseOrder.PurchaseOrderDetailsViewByOrderMasterIdWithRemaining(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decMaterialReceiptId);
             }
             int inRowIndex = 0;
             foreach (DataRow drowDetails in ListObjDetails[0].Rows)
             {
                 dgvProduct.Rows.Add();
                 isValueChange = false;
                 isDoAfterGridFill = false;
                 dgvProduct.CurrentCell = dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"];
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtPurchaseOrderDetailsId"].Value = Convert.ToString(drowDetails.ItemArray[0]);
                 strproductId = drowDetails.ItemArray[2].ToString();
                 ProductInfo infoproduct = new ProductInfo();
                 infoproduct = BllProductCreation.ProductView(Convert.ToDecimal(strproductId));
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["productId"].Value = Convert.ToDecimal(strproductId);
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductCode"].Value = infoproduct.ProductCode;
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"].Value = infoproduct.ProductName;
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtvouchertypeId"].Value = Convert.ToString(drowDetails.ItemArray[11]);
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtvoucherNo"].Value = Convert.ToString(drowDetails.ItemArray[12]);
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtinvoiceNo"].Value = Convert.ToString(drowDetails.ItemArray[13]);
                 UnitComboFill(Convert.ToDecimal(strproductId), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ColumnIndex);
                 isValueChange = true;
                 isDoAfterGridFill = true;
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                 UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                List< DataTable >listUnitByProduct = new List<DataTable>();
                listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(strproductId);
                foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows)
                 {
                     if (dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                     {
                         dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                         dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                     }
                 }
                 isValueChange = false;
                 isDoAfterGridFill = false;
                 BatchComboFill(Convert.ToDecimal(strproductId), dgvProduct.Rows.Count - 2, Convert.ToInt32(dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].ColumnIndex));
                 decimal decBatch = BllStockPosting.BatchViewByProductId(Convert.ToDecimal(strproductId));
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].Value = decBatch;
                 string strBarcode = BllBatch.ProductBatchBarcodeViewByBatchId(decBatch);
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].Value = strBarcode;
                 DGVGodownComboFill();
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(1);
                 RackComboFill(1, dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvCmbRack"].ColumnIndex);
                 List<DataTable> listObj = new List<DataTable>();
                 RackBll BllRack = new RackBll();
                 listObj = BllRack.RackNamesCorrespondingToGodownId(1);
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvCmbRack"].Value = Convert.ToDecimal(listObj[0].Rows[0]["rackId"].ToString());
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtQty"].Value = Convert.ToString(drowDetails.ItemArray[3]);
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtRate"].Value = Convert.ToString(drowDetails.ItemArray[4]);
                 decCurrentRate = Convert.ToDecimal(drowDetails.ItemArray[4].ToString());
                 decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value.ToString());
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtAmount"].Value = Convert.ToString(drowDetails.ItemArray[6]);
                 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["dgvtxtBarcode"].ReadOnly = true;
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtAmount"].ReadOnly = true;
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["inRowIndex"].Value = Convert.ToString(drowDetails["extra1"]);
                 if (cmbVoucherType.Text != "NA")
                 {
                     dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true;
                 }
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].HeaderCell.Value = string.Empty;
                 int intIndex = 0;
                 int.TryParse(Convert.ToString(drowDetails["extra1"]), out intIndex);
                 if (inMaxCount < intIndex)
                     inMaxCount = intIndex;
                 inRowIndex++;
                 NewAmountCalculation(string.Empty, dgvProduct.Rows.Count - 2);
                 isValueChange = true;
                 isDoAfterGridFill = true;
                 dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true;
             }
             for (int i = inRowIndex; i < dgvProduct.Rows.Count; ++i)
                 dgvProduct["inRowIndex", i].Value = Convert.ToString(GetNextinRowIndex());
             SerialNo();
             CalculateTotalAmount();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MR39:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }