/// <summary>
 /// Function to view the details of product
 /// </summary>
 /// <param name="decId"></param>
 public void view(decimal decId)
 {
     try
     {
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         List<DataTable> listObj = BllProductCreation.ProductDetailsForProductSearch(decId);
         foreach (DataRow dr in listObj[0].Rows)
         {
             lblProductCode.Text = dr["productCode"].ToString();
             lblProductGroup.Text = dr["groupName"].ToString();
             lblProductName.Text = dr["productName"].ToString();
             lblBrand.Text = dr["brandName"].ToString();
             lblCurrentStock.Text = dr["Currentstock"].ToString();
             lblModelNo.Text = dr["modelNo"].ToString();
             lblSize.Text = dr["size"].ToString();
             lbltax.Text = dr["taxName"].ToString();
             lblUnit.Text = dr["unitName"].ToString();
             lblTaxApplicable.Text = dr["taxapplicableOn"].ToString();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PD :01" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function to fill the grid based on the search keys
        /// </summary>
        public void GridFill()
        {
            try
            {
                string strComboText = string.Empty;
                List<DataTable> listObj = new List<DataTable>();
                ProductCreationBll BllProductCreation = new ProductCreationBll();
                ProductInfo infoProduct = new ProductInfo();
                if (cmbActive.Text == "Yes")
                {
                    strComboText = "True";
                }
                else if (cmbActive.Text == "No")
                {
                    strComboText = "False";
                }
                else
                {
                    cmbActive.SelectedIndex = 0;
                    strComboText = "All";
                }
                if (txtSalesRateFrom.Text == string.Empty && txtSalesRateTo.Text == string.Empty)
                {
                    txtSalesRateFrom.Text = "0";
                    txtSalesRateTo.Text = "0";
                }
                decimal decProductGroup = Convert.ToDecimal(cmbProductGroup.SelectedValue);
                string strProductName = txtProductName.Text.Trim();
                string strProductCode = txtProductCode.Text.Trim();
                decimal decSize = Convert.ToDecimal(cmbSize.SelectedValue);
                decimal decModelNo = Convert.ToDecimal(cmbModelNo.SelectedValue);
                decimal decBrand = Convert.ToDecimal(cmbBrand.SelectedValue);
                decimal decTax = Convert.ToDecimal(cmbTax.SelectedValue);
                string strTaxApplicable = cmbTaxApplicableOn.Text.Trim();
                decimal decSalesRateFrom = Convert.ToDecimal(txtSalesRateFrom.Text);
                decimal decSalesRateTo = Convert.ToDecimal(txtSalesRateTo.Text);

                listObj = BllProductCreation.ProductRegisterSearch(decProductGroup, strProductName, strProductCode, decSize, decModelNo, decBrand, decTax, strTaxApplicable, decSalesRateFrom, decSalesRateTo, strComboText);

                dgvProductRegister.DataSource = listObj[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show("PR7:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to get the Details
        /// </summary>
        public void DeliveryNoteDetails()
        {
            try
            {
                ProductInfo infoProduct = new ProductInfo();
                ProductCreationBll BllProductCreation = new ProductCreationBll();
                DeliveryNoteDetailsInfo infoDeliveryNoteDetails = new DeliveryNoteDetailsInfo();
                StockPostingInfo infoStockPosting = new StockPostingInfo();
                StockPostingBll BllStockPosting = new StockPostingBll();
                // StockPostingSP spStockPosting = new StockPostingSP();
                //DeliveryNoteDetailsSP spDeliveryNoteDetails = new DeliveryNoteDetailsSP();
                DeliveryNoteBll bllDeliveryNote = new DeliveryNoteBll();
                UnitBll bllUnit = new UnitBll();

                for (int inI = 0; inI < dgvProduct.Rows.Count - 1; inI++)
                {
                    if (dgvProduct.Rows[inI].Cells["dgvtxtDetailsId"].Value == null)
                    {
                        if (cmbDeliveryMode.Text == "Against Order")
                        {
                            if (dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value != null)
                            {
                                infoDeliveryNoteDetails.OrderDetails1Id = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value == null ? string.Empty : dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value.ToString());
                            }
                            else
                            {
                                infoDeliveryNoteDetails.OrderDetails1Id = 0;
                                infoDeliveryNoteDetails.QuotationDetails1Id = 0;
                            }
                        }
                        else if (cmbDeliveryMode.Text == "Against Quotation")
                        {
                            if (dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value != null)
                            {
                                infoDeliveryNoteDetails.QuotationDetails1Id = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value == null ? string.Empty : dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value.ToString());
                            }
                            else
                            {
                                infoDeliveryNoteDetails.OrderDetails1Id = 0;
                                infoDeliveryNoteDetails.QuotationDetails1Id = 0;
                            }
                        }
                        else if (cmbDeliveryMode.Text == "NA")
                        {
                            infoDeliveryNoteDetails.OrderDetails1Id = 0;
                            infoDeliveryNoteDetails.QuotationDetails1Id = 0;
                        }
                    }
                    else
                    {
                        if (dgvProduct.Rows[inI].Cells["dgvtxtDetailsId"].Value != null)
                        {
                            if (cmbDeliveryMode.Text == "Against Order")
                            {
                                infoDeliveryNoteDetails.OrderDetails1Id = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value.ToString());
                            }
                            else if (cmbDeliveryMode.Text == "Against Quotation")
                            {
                                infoDeliveryNoteDetails.QuotationDetails1Id = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtOrderDetailsId"].Value.ToString());
                            }
                            else if (cmbDeliveryMode.Text == "NA")
                            {
                                infoDeliveryNoteDetails.OrderDetails1Id = 0;
                                infoDeliveryNoteDetails.QuotationDetails1Id = 0;
                            }
                        }
                        else
                        {
                            infoDeliveryNoteDetails.OrderDetails1Id = 0;
                            infoDeliveryNoteDetails.QuotationDetails1Id = 0;
                        }
                    }
                    if (dgvProduct.Rows[inI].Cells["dgvtxtDetailsId"].Value == null || dgvProduct.Rows[inI].Cells["dgvtxtDetailsId"].Value.ToString() == string.Empty || Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtDetailsId"].Value) == 0)
                    {
                        infoDeliveryNoteDetails.DeliveryNoteMasterId = decDelivryNoteIdToEdit;
                        infoProduct = BllProductCreation.ProductViewByCode(dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                        infoDeliveryNoteDetails.ProductId = infoProduct.ProductId;
                        infoDeliveryNoteDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                        infoDeliveryNoteDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value);
                        infoDeliveryNoteDetails.BatchId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString());
                        infoDeliveryNoteDetails.GodownId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
                        infoDeliveryNoteDetails.RackId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbRack"].Value.ToString());
                        infoDeliveryNoteDetails.UnitConversionId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString());
                        infoDeliveryNoteDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                        infoDeliveryNoteDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                        infoDeliveryNoteDetails.SlNo = Convert.ToInt32(dgvProduct.Rows[inI].Cells["Col"].Value.ToString());
                        infoDeliveryNoteDetails.Extra1 = string.Empty;
                        infoDeliveryNoteDetails.Extra2 = string.Empty;
                        bllDeliveryNote.DeliveryNoteDetailsAdd(infoDeliveryNoteDetails);
                    }
                    else
                    {
                        infoDeliveryNoteDetails.DeliveryNoteMasterId = decDelivryNoteIdToEdit;
                        infoDeliveryNoteDetails.DeliveryNoteDetails1Id = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtDetailsId"].Value);
                        infoProduct = BllProductCreation.ProductViewByCode(dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                        infoDeliveryNoteDetails.ProductId = infoProduct.ProductId;
                        infoDeliveryNoteDetails.Qty = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtQty"].Value.ToString());

                        if (Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtDetailsId"].Value) == 0)
                        {
                            infoDeliveryNoteDetails.UnitId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                        }
                        else
                        {
                            infoDeliveryNoteDetails.UnitId = Convert.ToDecimal(bllUnit.UnitIdByUnitName(dgvProduct.Rows[inI].Cells["dgvcmbUnit"].FormattedValue.ToString()));
                        }
                        infoDeliveryNoteDetails.BatchId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString());
                        infoDeliveryNoteDetails.GodownId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
                        infoDeliveryNoteDetails.RackId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbRack"].Value.ToString());
                        infoDeliveryNoteDetails.UnitConversionId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString());
                        infoDeliveryNoteDetails.Rate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                        infoDeliveryNoteDetails.Amount = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                        infoDeliveryNoteDetails.SlNo = Convert.ToInt32(dgvProduct.Rows[inI].Cells["Col"].Value.ToString());
                        bllDeliveryNote.DeliveryNoteDetailsEdit(infoDeliveryNoteDetails);
                    }
                    infoStockPosting.Date = Convert.ToDateTime(txtDate.Text);
                    if (Convert.ToInt32(dgvProduct.Rows[inI].Cells["dgvtxtVoucherTypeId"].Value) != 0)
                    {
                        if (cmbDeliveryMode.SelectedItem.ToString() != "NA")
                        {
                            if (dgvProduct.Rows[inI].Cells["dgvtxtVoucherTypeId"].Value != null)
                            {
                                infoStockPosting.VoucherTypeId = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtVoucherTypeId"].Value);
                            }
                            else
                            {
                                infoStockPosting.VoucherTypeId = 0;
                            }
                            if (dgvProduct.Rows[inI].Cells["dgvtxtVoucherNo"].Value != null)
                            {
                                infoStockPosting.VoucherNo = dgvProduct.Rows[inI].Cells["dgvtxtVoucherNo"].Value.ToString();
                            }
                            else
                            {
                                infoStockPosting.VoucherNo = string.Empty;
                            }
                            if (dgvProduct.Rows[inI].Cells["dgvtxtInvoiceNo"].Value != null)
                            {
                                infoStockPosting.InvoiceNo = dgvProduct.Rows[inI].Cells["dgvtxtInvoiceNo"].Value.ToString();
                            }
                            else
                            {
                                infoStockPosting.InvoiceNo = string.Empty;
                            }
                            if (decDeliveryNoteVoucherTypeId != 0)
                            {
                                infoStockPosting.AgainstVoucherTypeId = decDeliveryNoteVoucherTypeId;
                            }
                            else
                            {
                                infoStockPosting.AgainstVoucherTypeId = 0;
                            }
                            if (strVoucherNo != string.Empty)
                            {
                                infoStockPosting.AgainstVoucherNo = strVoucherNo;
                            }
                            else
                            {
                                infoStockPosting.AgainstVoucherNo = string.Empty;
                            }
                            if (txtDeliveryNoteNo.Text != string.Empty)
                            {
                                infoStockPosting.AgainstInvoiceNo = txtDeliveryNoteNo.Text;
                            }
                            else
                            {
                                infoStockPosting.AgainstInvoiceNo = string.Empty;
                            }
                        }
                    }
                    else
                    {
                        infoStockPosting.InvoiceNo = txtDeliveryNoteNo.Text;
                        infoStockPosting.VoucherNo = strVoucherNo;
                        infoStockPosting.VoucherTypeId = decDeliveryNoteVoucherTypeId;
                        infoStockPosting.AgainstVoucherTypeId = 0;
                        infoStockPosting.AgainstVoucherNo = "NA";
                        infoStockPosting.AgainstInvoiceNo = "NA";
                    }
                    infoStockPosting.ProductId = infoDeliveryNoteDetails.ProductId;
                    infoStockPosting.BatchId = infoDeliveryNoteDetails.BatchId;
                    infoStockPosting.UnitId = infoDeliveryNoteDetails.UnitId;
                    infoStockPosting.GodownId = infoDeliveryNoteDetails.GodownId;
                    infoStockPosting.RackId = infoDeliveryNoteDetails.RackId;
                    infoStockPosting.OutwardQty = infoDeliveryNoteDetails.Qty;
                    infoStockPosting.Rate = infoDeliveryNoteDetails.Rate;
                    infoStockPosting.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                    infoStockPosting.Extra1 = string.Empty;
                    infoStockPosting.Extra2 = string.Empty;
                    BllStockPosting.StockPostingAdd(infoStockPosting);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("DN36:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to call frmProductSearchPopup form to select and view Product created 
 /// </summary>
 /// <param name="frmProductSearchPopup"></param>
 /// <param name="decproductId"></param>
 /// <param name="decCurrentRowIndex"></param>
 public void CallFromProductSearchPopup(frmProductSearchPopup frmProductSearchPopup, decimal decproductId, decimal decCurrentRowIndex)
 {
     try
     {
         base.Show();
         this.frmProductSearchPopupObj = frmProductSearchPopup;
         List<DataTable> list = new List<DataTable>();
         UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
         ProductInfo infoProduct = new ProductInfo();
         BatchBll BllBatch = new BatchBll();
         infoProduct = new ProductCreationBll().ProductView(decproductId);
         dgvProduct.Rows.Add();
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode;
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtProductId"].Value = decproductId.ToString();
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtProductName"].Value = infoProduct.ProductName;
         UnitComboFill1(decproductId, dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Index, dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvcmbUnit"].ColumnIndex);
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvcmbUnit"].Value = infoProduct.UnitId;
         GridGodownComboFill(decproductId, dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Index, dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvcmbGodown"].ColumnIndex);
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvcmbGodown"].Value = infoProduct.GodownId;
         RackComboFill1(infoProduct.GodownId, dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Index, dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvcmbRack"].ColumnIndex);
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvcmbRack"].Value = infoProduct.RackId;
         BatchComboFill(decproductId, dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Index, dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvcmbBatch"].ColumnIndex);
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvcmbBatch"].Value = BllBatch.BatchIdViewByProductId(decproductId);
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtBarcode"].Value = BllBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvcmbBatch"].Value.ToString()));
         list = bllUnitConvertion.DGVUnitConvertionRateByUnitId(infoProduct.UnitId, infoProduct.ProductName);
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtUnitConversionId"].Value = list[0].Rows[0]["unitconversionId"].ToString();
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtConversionRate"].Value = list[0].Rows[0]["conversionRate"].ToString();
         decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtConversionRate"].Value.ToString());
         AmountCalculation("dgvtxtQty", dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Index);
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtRate"].Value = infoProduct.SalesRate.ToString();
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].HeaderCell.Value = "X";
         dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].HeaderCell.Style.ForeColor = Color.Red;
         TotalAmountCalculation();
         frmProductSearchPopupObj.Close();
         frmProductSearchPopupObj = null;
     }
     catch (Exception ex)
     {
         MessageBox.Show("DN12:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 public void ProductDetailsFill(int inRowIndex, string strFillMode)
 {
     try
     {
         ProductInfo infoProduct = new ProductInfo();
         BatchBll BllBatch = new BatchBll();
         StockPostingBll BllStockPosting = new StockPostingBll();
         //StockPostingSP spStockPosting = new StockPostingSP();
         string strPrdCode = string.Empty;
         string strProductName = string.Empty;
         if (strFillMode == "ProductCode")
         {
             if (dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductCode"].Value as string != string.Empty)
             {
                 strPrdCode = dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductCode"].Value.ToString();
             }
             infoProduct = new ProductCreationBll().ProductViewByCode(strPrdCode);
         }
         if (strFillMode == "ProductName")
         {
             if (dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductName"].Value != null && dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductName"].Value.ToString() != string.Empty)
             {
                 strProductName = dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductName"].Value.ToString();
             }
             infoProduct = new ProductCreationBll().ProductViewByName(strProductName);
         }
         if (infoProduct.ProductId != 0)
         {
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode;
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductName"].Value = infoProduct.ProductName;
             string strproductId = Convert.ToString(infoProduct.ProductId);
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductId"].Value = infoProduct.ProductId;
             UnitComboFill1(Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvtxtProductId"].Value), inRowIndex, dgvProduct.Rows[inRowIndex].Cells["dgvcmbUnit"].ColumnIndex);
             dgvProduct.Rows[inRowIndex].Cells["dgvcmbUnit"].Value = infoProduct.UnitId;
             BatchComboFill(Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvtxtProductId"].Value), inRowIndex, dgvProduct.Rows[inRowIndex].Cells["dgvcmbBatch"].ColumnIndex);
             dgvProduct.Rows[inRowIndex].Cells["dgvcmbBatch"].Value = BllStockPosting.BatchViewByProductId(Convert.ToDecimal(dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductId"].Value));
             string strBarcode = BllBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvProduct.Rows[inRowIndex].Cells["dgvcmbBatch"].Value.ToString()));
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtBarcode"].Value = strBarcode;
             GridGodownComboFill(Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvtxtProductId"].Value), inRowIndex, dgvProduct.Rows[inRowIndex].Cells["dgvcmbGodown"].ColumnIndex);
             dgvProduct.Rows[inRowIndex].Cells["dgvcmbGodown"].Value = infoProduct.GodownId;
             RackComboFill1(Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value), inRowIndex, dgvProduct.Rows[inRowIndex].Cells["dgvcmbRack"].ColumnIndex);
             dgvProduct.Rows[inRowIndex].Cells["dgvcmbRack"].Value = infoProduct.RackId;
             UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
             List<DataTable> ListObj = new List<DataTable>();
             ListObj = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(strproductId);
             foreach (DataRow drUnitByProduct in ListObj[0].Rows)
             {
                 if (dgvProduct.Rows[inRowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                 {
                     dgvProduct.Rows[inRowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                     dgvProduct.Rows[inRowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                 }
             }
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.SalesRate, PublicVariables._inNoOfDecimalPlaces);
             decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[inRowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
             decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[inRowIndex].Cells["dgvtxtRate"].Value.ToString());
             decimal decProductId = Convert.ToDecimal(dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductId"].Value.ToString());
             decimal decBatchId = Convert.ToDecimal(dgvProduct.Rows[inRowIndex].Cells["dgvcmbBatch"].Value.ToString());
             getProductRate(inRowIndex, decProductId, decBatchId);
         }
         else
         {
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductName"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtRate"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvcmbGodown"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvcmbRack"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvcmbBatch"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductId"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtUnitConversionId"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtConversionRate"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtRate"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtAmount"].Value = string.Empty;
             dgvProduct.Rows[inRowIndex].Cells["dgvtxtQty"].Value = string.Empty;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("DN47:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill Product combobox
 /// </summary>
 public void ProductNameComboFill()
 {
     try
     {
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         List<DataTable> listObjProductName = new List<DataTable>();
         listObjProductName = BllProductCreation.ProductViewAllForComboBox();
         DataRow dr = listObjProductName[0].NewRow();
         dr["ProductName"] = "All";
         dr["ProductId"] = 0;
         listObjProductName[0].Rows.InsertAt(dr, 0);
         cmbProduct.DataSource = listObjProductName[0];
         cmbProduct.ValueMember = "productId";
         cmbProduct.DisplayMember = "productName";
     }
     catch (Exception ex)
     {
         MessageBox.Show("ST:7" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// fill Items into the purticular controls for Update or delete
 /// </summary>
 public void FillControls()
 {
     try
     {
         StandardRateInfo infoStandardRate = new StandardRateInfo();
         standardRateBll BllStandaredRate = new standardRateBll();
         infoStandardRate = BllStandaredRate.StandardRateView(decStandardRate);
         dtpFromDate.Value = Convert.ToDateTime(infoStandardRate.ApplicableFrom.ToString());
         dtpToDate.Value = Convert.ToDateTime(infoStandardRate.ApplicableTo.ToString());
         dtpFromDate.Text = infoStandardRate.ApplicableFrom.ToString();
         dtpToDate.Text = infoStandardRate.ApplicableTo.ToString();
         txtRate.Text = infoStandardRate.Rate.ToString();
         decProduct = infoStandardRate.ProductId;
         decUnitId = infoStandardRate.UnitId;
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         ProductInfo infoProduct = new ProductInfo();
         infoProduct = BllProductCreation.ProductViewForStandardRate(decProductId);
         txtProductCode.Text = infoProduct.ProductCode;
         txtProductName.Text = infoProduct.ProductName;
         decStandardRateId = infoStandardRate.StandardRateId;
         UnitInfo infoUnit = new UnitInfo();
         UnitBll bllUnit = new UnitBll();
         infoUnit = bllUnit.UnitView(decUnit);
         txtUnitName.Text = infoUnit.UnitName;
         txtProductName.ReadOnly = true;
         txtProductCode.ReadOnly = true;
         txtUnitName.ReadOnly = true;
         BatchInfo infoBatch = new BatchInfo();
         BatchBll BllBatch = new BatchBll();
         decBatchId = infoStandardRate.BatchId;
         infoBatch = BllBatch.BatchView(decBatchId);
         cmbBatch.SelectedValue = infoBatch.BatchId;
     }
     catch (Exception ex)
     {
         MessageBox.Show("SRP5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// edit function for PurchaseOrderDetails
        /// </summary>
        public void EditPurchaseOrderDetails()
        {
            PurchaseOrderBll BllPurchaseOrder = new PurchaseOrderBll();
            PurchaseOrderDetailsInfo infoPurchaseOrderDetails = new PurchaseOrderDetailsInfo();
            ProductCreationBll BllProductCreation = new ProductCreationBll();
            try
            {
                ProductInfo infoProduct = new ProductInfo();

                for (int inI = 0; inI < dgvPurchaseOrder.Rows.Count - 1; inI++)
                {
                    if (Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value) == 0 || dgvPurchaseOrder.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString() == null || dgvPurchaseOrder.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value.ToString() == string.Empty)
                    {
                        infoPurchaseOrderDetails.PurchaseOrderMasterId = decPurchaseOrderMasterId;
                        infoProduct = BllProductCreation.ProductViewByCode(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                        infoPurchaseOrderDetails.ProductId = infoProduct.ProductId;
                        infoPurchaseOrderDetails.Qty = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                        infoPurchaseOrderDetails.UnitId = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvcmbUnit"].Value);
                        infoPurchaseOrderDetails.UnitConversionId = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtUnitConversionId"].Value);
                        infoPurchaseOrderDetails.Rate = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                        infoPurchaseOrderDetails.Amount = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                        infoPurchaseOrderDetails.SlNo = Convert.ToInt32(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
                        infoPurchaseOrderDetails.Extra1 = string.Empty;
                        infoPurchaseOrderDetails.Extra2 = string.Empty;
                        BllPurchaseOrder.PurchaseOrderDetailsAdd(infoPurchaseOrderDetails);
                    }
                    else
                    {
                        infoPurchaseOrderDetails.PurchaseOrderMasterId = decPurchaseOrderMasterId;
                        infoPurchaseOrderDetails.PurchaseOrderDetailsId = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtPurchaseOrderDetailsId"].Value);
                        infoProduct = BllProductCreation.ProductViewByCode(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                        infoPurchaseOrderDetails.ProductId = infoProduct.ProductId;
                        infoPurchaseOrderDetails.Qty = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                        infoPurchaseOrderDetails.UnitId = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                        infoPurchaseOrderDetails.UnitConversionId = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtUnitConversionId"].Value);
                        infoPurchaseOrderDetails.Rate = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                        infoPurchaseOrderDetails.Amount = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                        infoPurchaseOrderDetails.SlNo = Convert.ToInt32(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
                        infoPurchaseOrderDetails.Extra1 = string.Empty;
                        infoPurchaseOrderDetails.Extra2 = string.Empty;
                        BllPurchaseOrder.PurchaseOrderDetailsEdit(infoPurchaseOrderDetails);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PO33:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to call frmProductSearchPopup form to select and view a product
 /// </summary>
 /// <param name="frmProductSearchPopup"></param>
 /// <param name="decproductId"></param>
 /// <param name="decCurrentRowIndex"></param>
 public void CallFromProductSearchPopup(frmProductSearchPopup frmProductSearchPopup, decimal decproductId, decimal decCurrentRowIndex)
 {
     ProductInfo infoProduct = new ProductInfo();
     ProductCreationBll BllProductCreation= new ProductCreationBll();
     try
     {
         base.Show();
         this.frmProductSearchPopupObj = frmProductSearchPopup;
         infoProduct = BllProductCreation.ProductView(decproductId);
         int inRowcount = dgvSalesInvoice.Rows.Count;
         for (int i = 0; i < inRowcount; i++)
         {
             if (i == decCurrentRowIndex)
             {
                 dgvSalesInvoice.Rows.Add();
                 dgvSalesInvoice.Rows[i].Cells["dgvtxtSalesInvoiceProductCode"].Value = infoProduct.ProductCode;
                 strProductCode = infoProduct.ProductCode;
                 ProductDetailsFill(strProductCode, i, "ProductCode");
             }
         }
         frmProductSearchPopupObj.Close();
         frmProductSearchPopupObj = null;
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 59" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill Sales invoice grid while return from Product creation when creating Product 
 /// </summary>
 /// <param name="decProductId"></param>
 public void ReturnFromProductCreation(decimal decProductId)
 {
     ProductInfo infoProduct = new ProductInfo();
     ProductCreationBll BllProductCreation = new ProductCreationBll();
     try
     {
         this.Enabled = true;
         this.Activate();
         if (decProductId != 0)
         {
             infoProduct = BllProductCreation.ProductView(decProductId);
             strProductCode = infoProduct.ProductCode;
             ProductDetailsFill(strProductCode, dgvSalesInvoice.CurrentRow.Index, "ProductCode");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SI: 88" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 public void productDetailsFill(string strProduct, int inRowIndex, string strFillMode)
 {
     try
     {
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         List<DataTable> listObj = new List<DataTable>();
         if (strFillMode == "Barcode")
         {
             listObj = BllProductCreation.ProductDetailsCoreespondingToBarcode(strProduct);
         }
         else if (strFillMode == "ProductCode")
         {
             listObj = BllProductCreation.ProductDetailsCoreespondingToProductCode(strProduct);
         }
         else if (strFillMode == "ProductName")
         {
             listObj = BllProductCreation.ProductDetailsCoreespondingToProductName(strProduct);
         }
         if (listObj[0].Rows.Count != 0)
         {
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvtxtProductCode"].Value = listObj[0].Rows[0]["productCode"].ToString();
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvtxtProductName"].Value = listObj[0].Rows[0]["productName"].ToString();
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(listObj[0].Rows[0]["unitId"].ToString());
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(listObj[0].Rows[0]["unitId"].ToString());
             decimal decproductId = Convert.ToDecimal(listObj[0].Rows[0]["productId"].ToString());
             BatchComboFill(decproductId, inRowIndex, Convert.ToInt32(dgvPhysicalStock.Rows[inRowIndex].Cells["dgvcmbBatch"].ColumnIndex));
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(listObj[0].Rows[0]["batchId"].ToString());
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvtxtRate"].Value = listObj[0].Rows[0]["purchaseRate"].ToString();
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(listObj[0].Rows[0]["godownId"].ToString());
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvcmbRack"].Value = Convert.ToDecimal(listObj[0].Rows[0]["rackId"].ToString());
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvtxtQty"].Value = string.Empty;
         }
         else
         {
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvtxtProductName"].Value = string.Empty;
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvtxtRate"].Value = string.Empty;
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvtxtProductCode"].Value = string.Empty;
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvcmbUnit"].Value = string.Empty;
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
             dgvPhysicalStock.Rows[inRowIndex].Cells["dgvcmbBatch"].Value = string.Empty;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PS:44" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Adding PhysicalStockDetails when updating
 /// </summary>
 public void EditPhysicalStockDetails()
 {
     try
     {
         ProductInfo infoProduct = new ProductInfo();
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         PhysicalStockDetailsInfo infoPhysicalStockDetails = new PhysicalStockDetailsInfo();
         PhysicalStockBll BllPhysicalStock = new PhysicalStockBll();
         int inRowcount = dgvPhysicalStock.Rows.Count;
         for (int inI = 0; inI < inRowcount - 1; inI++)
         {
             infoPhysicalStockDetails.PhysicalStockMasterId = decMasterId;
             infoPhysicalStockDetails.PhysicalStockDetailsId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtPhysicalStockDetailId"].Value);
             if (dgvPhysicalStock.Rows[inI].Cells["dgvtxtProductCode"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty)
             {
                 infoProduct = BllProductCreation.ProductViewByCode(dgvPhysicalStock.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                 infoPhysicalStockDetails.ProductId = infoProduct.ProductId;
             }
             if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbGodown"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbGodown"].Value.ToString() != string.Empty)
             {
                 infoPhysicalStockDetails.GodownId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
             }
             else
             {
                 infoPhysicalStockDetails.GodownId = 0;
             }
             if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbRack"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbRack"].Value.ToString() != string.Empty)
             {
                 infoPhysicalStockDetails.RackId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvcmbRack"].Value.ToString());
             }
             else
             {
                 infoPhysicalStockDetails.RackId = 0;
             }
             if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
             {
                 infoPhysicalStockDetails.BatchId = Convert.ToDecimal(Convert.ToString(dgvPhysicalStock.Rows[inI].Cells["dgvcmbBatch"].Value));
             }
             else
             {
                 infoPhysicalStockDetails.BatchId = 0;
             }
             if (dgvPhysicalStock.Rows[0].Cells["dgvcmbBatch"].Value == null && dgvPhysicalStock.Rows[0].Cells["dgvcmbBatch"].Value == null)
             {
                 MessageBox.Show("Can't update physical stock without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 dgvPhysicalStock.ClearSelection();
                 dgvPhysicalStock.Focus();
             }
             if (dgvPhysicalStock.Rows[inI].Cells["dgvtxtQty"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvtxtQty"].Value.ToString() != string.Empty)
             {
                 infoPhysicalStockDetails.Qty = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
             }
             if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbUnit"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbUnit"].Value.ToString() != string.Empty)
             {
                 infoPhysicalStockDetails.UnitId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
             }
             infoPhysicalStockDetails.Rate = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
             infoPhysicalStockDetails.Amount = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
             infoPhysicalStockDetails.Slno = Convert.ToInt32(dgvPhysicalStock.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
             infoPhysicalStockDetails.Extra1 = string.Empty;
             infoPhysicalStockDetails.Extra2 = string.Empty;
             BllPhysicalStock.PhysicalStockDetailsAdd(infoPhysicalStockDetails);
             decimal decPId = infoPhysicalStockDetails.ProductId;
             string strVoucher = infoPhysicalStockMaster.VoucherNo;
             AddtoStockPosting(decPId, strVoucher);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PS:23" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 private void dgvPhysicalStock_CellLeave(object sender, DataGridViewCellEventArgs e)
 {
     if (!isFromEditMode)
     {
         try
         {
             string strBarcode = string.Empty;
             string strProductCode = string.Empty;
             ProductInfo infoProduct = new ProductInfo();
             ProductCreationBll BllProductCreation = new ProductCreationBll();
             BatchBll BllBatch = new BatchBll();
             //PhysicalStockMasterSP spPhysicalStockMaster = new PhysicalStockMasterSP();
             PhysicalStockBll BllPhysicalStock = new PhysicalStockBll();
             if (e.RowIndex != -1 && e.ColumnIndex != -1)
             {
                 if (dgvPhysicalStock.Columns[e.ColumnIndex].Name == "dgvcmbBatch")
                 {
                     if (dgvPhysicalStock.CurrentRow.Cells["dgvcmbBatch"].Value != null)
                     {
                         if (Convert.ToString(dgvPhysicalStock.CurrentRow.Cells["dgvcmbBatch"].Value) != string.Empty &&
                            Convert.ToDecimal(dgvPhysicalStock.CurrentRow.Cells["dgvcmbBatch"].Value) != 0)
                         {
                             if (isGridValueChanged)
                             {
                                 decBatchId = Convert.ToDecimal(dgvPhysicalStock.CurrentRow.Cells["dgvcmbBatch"].Value);
                                 strBarcode = BllBatch.ProductBatchBarcodeViewByBatchId(decBatchId);
                                 isGridValueChanged = false;
                                 dgvPhysicalStock.CurrentRow.Cells["dgvtxtBarcode"].Value = strBarcode;
                                 isGridValueChanged = true;
                             }
                         }
                     }
                 }
                 CheckColumnMissing();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("PS:45" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
 /// <summary>
 /// Doing basic calculations in cell value change
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvPhysicalStock_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         ProductInfo infoProduct = new ProductInfo();
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         BatchBll BllBatch = new BatchBll();
         //PhysicalStockMasterSP spPhysicalStockMaster = new PhysicalStockMasterSP();
         PhysicalStockBll BllPhysicalStock = new PhysicalStockBll();
         if (e.RowIndex != -1 && e.ColumnIndex != -1)
         {
             string strBarcode = string.Empty;
             string strProductCode = string.Empty;
             if (dgvPhysicalStock.Columns[e.ColumnIndex].Name == "dgvtxtBarcode")
             {
                 string strBCode = string.Empty;
                 DataTable dtbl = new DataTable();
                 if (dgvPhysicalStock.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value != null && dgvPhysicalStock.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString() != string.Empty)
                 {
                     strBCode = dgvPhysicalStock.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString();
                     productDetailsFill(strBCode, dgvPhysicalStock.CurrentRow.Index, "Barcode");
                     CheckColumnMissing();
                 }
             }
             else if (dgvPhysicalStock.Columns[e.ColumnIndex].Name == "dgvtxtProductCode")
             {
                 UnitInfo infoUnit = new UnitInfo();
                 string strPrdCode = string.Empty;
                 if (dgvPhysicalStock.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvPhysicalStock.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty)
                 {
                     strPrdCode = dgvPhysicalStock.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString();
                     productDetailsFill(strPrdCode, dgvPhysicalStock.CurrentRow.Index, "ProductCode");
                     CheckColumnMissing();
                 }
             }
             else if (dgvPhysicalStock.Columns[e.ColumnIndex].Name == "dgvtxtProductName")
             {
                 string strProductName = string.Empty;
                 DataTable dtbl = new DataTable();
                 if (dgvPhysicalStock.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value != null && dgvPhysicalStock.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString() != string.Empty)
                 {
                     strProductName = dgvPhysicalStock.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString();
                     productDetailsFill(strProductName, dgvPhysicalStock.CurrentRow.Index, "ProductName");
                     CheckColumnMissing();
                 }
             }
             if (dgvPhysicalStock.Columns[e.ColumnIndex].Name == "dgvtxtQty" && isAmountcalc || dgvPhysicalStock.Columns[e.ColumnIndex].Name == "dgvtxtRate" && isAmountcalc)
             {
                 NewAmountCalculation(e.RowIndex);
                 CheckColumnMissing();
             }
             if (dgvPhysicalStock.Columns[e.ColumnIndex].Name == "dgvtxtQty" && isAmountcalc || dgvPhysicalStock.Columns[e.ColumnIndex].Name == "dgvtxtRate" && isAmountcalc)
             {
                 CalculateTotalAmount();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PS:45" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Save Function
 /// </summary>
 public void SaveFunction()
 {
     try
     {
         ProductInfo infoProduct = new ProductInfo();
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         PhysicalStockMasterInfo infoPhysicalStockMaster = new PhysicalStockMasterInfo();
         //PhysicalStockDetailsSP spPhysicalStockDetails = new PhysicalStockDetailsSP();
         PhysicalStockBll BllPhysicalStock = new PhysicalStockBll();
         //PhysicalStockMasterSP spPhysicalStockMaster = new PhysicalStockMasterSP();
         infoPhysicalStockMaster.VoucherNo = txtVoucherNo.Text.Trim();
         infoPhysicalStockMaster.Date = Convert.ToDateTime(txtDate.Text);
         infoPhysicalStockMaster.Narration = txtNarration.Text.Trim();
         string s = txtTotalAmount.Text;
         infoPhysicalStockMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
         if (isAutomatic)
         {
             infoPhysicalStockMaster.SuffixPrefixId = decPhysicalStockSuffixPrefixId;
             infoPhysicalStockMaster.VoucherNo = strVoucherNo;
             infoPhysicalStockMaster.InvoiceNo = txtVoucherNo.Text;
         }
         else
         {
             infoPhysicalStockMaster.SuffixPrefixId = 0;
             infoPhysicalStockMaster.VoucherNo = txtVoucherNo.Text;
             infoPhysicalStockMaster.InvoiceNo = txtVoucherNo.Text;
         }
         infoPhysicalStockMaster.VoucherTypeId = decPhysicalStockVoucherTypeId;
         infoPhysicalStockMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         infoPhysicalStockMaster.Extra1 = string.Empty;
         infoPhysicalStockMaster.Extra2 = string.Empty;
         decPhysicalStockMasterIdentity = Convert.ToDecimal(BllPhysicalStock.PhysicalStockMasterAdd(infoPhysicalStockMaster));
         int inRowcount = dgvPhysicalStock.Rows.Count;
         for (int inI = 0; inI < inRowcount - 1; inI++)
         {
             if (dgvPhysicalStock.Rows[inI].HeaderCell.Value.ToString() != "X")
             {
                 infoPhysicalStockDetails.PhysicalStockMasterId = decPhysicalStockMasterIdentity;
                 if (dgvPhysicalStock.Rows[inI].Cells["dgvtxtProductCode"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty)
                 {
                     infoProduct = BllProductCreation.ProductViewByCode(dgvPhysicalStock.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                     infoPhysicalStockDetails.ProductId = infoProduct.ProductId;
                 }
                 if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbGodown"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbGodown"].Value.ToString() != string.Empty)
                 {
                     infoPhysicalStockDetails.GodownId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
                 }
                 else
                 {
                     infoPhysicalStockDetails.GodownId = 0;
                 }
                 if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbRack"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbRack"].Value.ToString() != string.Empty)
                 {
                     infoPhysicalStockDetails.RackId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvcmbRack"].Value.ToString());
                 }
                 else
                 {
                     infoPhysicalStockDetails.RackId = 0;
                 }
                 if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
                 {
                     infoPhysicalStockDetails.BatchId = Convert.ToDecimal(Convert.ToString(dgvPhysicalStock.Rows[inI].Cells["dgvcmbBatch"].Value));
                 }
                 else
                 {
                     infoPhysicalStockDetails.BatchId = 0;
                 }
                 if (dgvPhysicalStock.Rows[inI].Cells["dgvtxtQty"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvtxtQty"].Value.ToString() != string.Empty)
                 {
                     infoPhysicalStockDetails.Qty = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                 }
                 if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbUnit"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbUnit"].Value.ToString() != string.Empty)
                 {
                     infoPhysicalStockDetails.UnitId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                     infoPhysicalStockDetails.UnitConversionId = decConversionId;
                 }
                 infoPhysicalStockDetails.Rate = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                 infoPhysicalStockDetails.Amount = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                 infoPhysicalStockDetails.Slno = Convert.ToInt32(dgvPhysicalStock.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
                 infoPhysicalStockDetails.Extra1 = string.Empty;
                 infoPhysicalStockDetails.Extra2 = string.Empty;
                 BllPhysicalStock.PhysicalStockDetailsAdd(infoPhysicalStockDetails);
                 decimal decPId = infoPhysicalStockDetails.ProductId;
                 string strVoucher = infoPhysicalStockMaster.VoucherNo;
                 AddtoStockPosting(decPId, strVoucher);
             }
         }
         Messages.SavedMessage();
         if (dgvPhysicalStock.RowCount > 1)
         {
             if (cbxPrint.Checked)
             {
                 if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decPhysicalStockMasterIdentity);
                 }
                 else
                 {
                     Print(decPhysicalStockMasterIdentity);
                 }
             }
         }
         clear();
     }
     catch (Exception ex)
     {
         MessageBox.Show("PS:27" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <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>
 /// To unit conversion and grid calculations
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvPurchaseOrder_CellLeave(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (isValueChange)
         {
             ProductCreationBll BllProductCreation = new ProductCreationBll();
             if (e.RowIndex > -1 && e.ColumnIndex > -1)
             {
                 CheckInvalidEntries(e);
                 if (e.ColumnIndex == dgvPurchaseOrder.Columns["dgvcmbUnit"].Index)
                 {
                     if (dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value != null && dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString() != string.Empty)
                     {
                         UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                         List<DataTable> ListObj = new List<DataTable>();
                         ListObj = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString());
                         foreach (DataRow drUnitByProduct in ListObj[0].Rows)
                         {
                             if (dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null)
                             {
                                 if (dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                                 {
                                     dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                                     dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                                     if (isDoAfterGridFill)
                                     {
                                         decimal decNewConversionRate = Convert.ToDecimal(dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtUnitConversionRate"].Value.ToString());
                                         decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate;
                                         dgvPurchaseOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, PublicVariables._inNoOfDecimalPlaces);
                                         NewAmountCalculation("dgvtxtQty", e.RowIndex);
                                         CalculateTotalAmount();
                                     }
                                 }
                             }
                         }
                     }
                     CheckInvalidEntries(e);
                 }
                 else if (e.ColumnIndex == dgvPurchaseOrder.Columns["dgvtxtQty"].Index && isAmountcalc)
                 {
                     NewAmountCalculation("dgvtxtQty", e.RowIndex);
                     CalculateTotalAmount();
                     CheckInvalidEntries(e);
                 }
                 else if (dgvPurchaseOrder.Columns[e.ColumnIndex].Name == "dgvtxtExchangeRate" && isAmountcalc)
                 {
                     NewAmountCalculation("dgvtxtExchangeRate", e.RowIndex);
                     CheckInvalidEntries(e);
                 }
                 else if (dgvPurchaseOrder.Columns[e.ColumnIndex].Name == "dgvtxtRate" && isAmountcalc)
                 {
                     NewAmountCalculation("dgvtxtRate", e.RowIndex);
                     CalculateTotalAmount();
                     CheckInvalidEntries(e);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PO57:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 18
0
        /// <summary>
        ///  Function to fil Controls based on the ProductName
        /// </summary>
        /// <param name="decProductId"></param>
        public void FillControlsByProductName(decimal decProductId)
        {
            try
            {
                PriceListInfo InfoPriceList = new PriceListInfo();
                ProductInfo infoProduct = new ProductInfo();
                ProductCreationBll BllProductCreation = new ProductCreationBll();
                PriceListBll BllPriceList = new PriceListBll();
                ProductBatchInfo infoProductBatch = new ProductBatchInfo();
                infoProduct = BllProductCreation.ProductView(decProductId);
                txtProductCode.Text = infoProduct.ProductCode;
                infoProductBatch = BllProductCreation.BarcodeViewByProductCode(txtProductCode.Text);
                decProductId = infoProductBatch.ProductId;
                decBatchId = infoProductBatch.BatchId;
                InfoPriceList = BllPriceList.PriceListViewByBatchIdORProduct(decBatchId);
                batchcombofill();
                txtBarcode.Text = infoProductBatch.Barcode;
                cmbItem.Text = infoProduct.ProductName;
                cmbGodown.SelectedValue = infoProduct.GodownId;
                cmbRack.SelectedValue = infoProduct.RackId;
                UnitComboFill();
                UnitInfo infoUnit = new UnitInfo();
                infoUnit = new UnitBll().unitVieWForStandardRate(decProductId);
                cmbUnit.SelectedValue = infoUnit.UnitId;
                if (InfoPriceList.PricinglevelId != 0)
                {
                    cmbPricingLevel.SelectedValue = InfoPriceList.PricinglevelId;
                }
                else
                {
                    cmbPricingLevel.SelectedIndex = 0;
                }
                ComboTaxFill();
                cmbTax.SelectedValue = infoProduct.TaxId;
                if (txtProductCode.Text.Trim() != string.Empty && cmbItem.SelectedIndex != -1)
                {
                    decimal decNodecplaces = PublicVariables._inNoOfDecimalPlaces;
                    decimal dcRate = BllProductCreation.ProductRateForSales(decProductId, Convert.ToDateTime(txtDate.Text), decBatchId, decNodecplaces);
                    txtRate.Text = dcRate.ToString();
                    try
                    {
                        if (decimal.Parse(txtQuantity.Text) == 0)
                            txtQuantity.Text = "1";
                    }
                    catch { txtQuantity.Text = "1"; }
                    txtQuantity.Focus();

                }
                TaxAmountCalculation();
                isAfterFillControls = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("POS:27" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// AutoCompletion of Product,productCode
 /// </summary>
 /// <param name="isProductName"></param>
 /// <param name="editControl"></param>
 public void FillProducts(bool isProductName, DataGridViewTextBoxEditingControl editControl)
 {
     try
     {
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         List<DataTable> listObjProducts = new List<DataTable>();
         ProductNames = BllProductCreation.ProudctNameViewAllForAutoComplete();
         ProductCodes = BllProductCreation.ProudctCodesViewAllForAutoComplete();
     }
     catch (Exception ex)
     {
         MessageBox.Show("PO7:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 20
0
 /// <summary>
 /// Function to use the Items Combo Fill 
 /// </summary>
 public void ItemComboFill()
 {
     try
     {
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         List<DataTable> listObj = new List<DataTable>();
         listObj = BllProductCreation.ProductViewAll();
         cmbItem.DataSource = listObj[0];
         cmbItem.ValueMember = "productId";
         cmbItem.DisplayMember = "productName";
     }
     catch (Exception ex)
     {
         MessageBox.Show("POS:17" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to add new standard rate for the purticular product
 /// </summary>
 /// <param name="decProductId"></param>
 /// <param name="frmStandardRate"></param>
 public void CallFromStandardRate(decimal decProductId, frmStandardRate frmStandardRate)
 {
     try
     {
         base.Show();
         StandardrateObj = frmStandardRate;
         StandardrateObj.Enabled = false;
         ProductInfo infoProduct = new ProductInfo();
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         UnitBll bllUnit = new UnitBll();
         UnitInfo infoUnit = new UnitInfo();
         infoProduct = BllProductCreation.ProductViewForStandardRate(decProductId);
         txtProductCode.Text = infoProduct.ProductCode;
         txtProductName.Text = infoProduct.ProductName;
         decProduct = infoProduct.ProductId;
         infoUnit = bllUnit.unitVieWForStandardRate(decProductId);
         decUnitId = infoUnit.UnitId;
         txtUnitName.Text = infoUnit.UnitName;
         txtProductName.ReadOnly = true;
         txtProductCode.ReadOnly = true;
         txtUnitName.ReadOnly = true;
         BatchUnderProductComboFill(decProductId);
         GridFill(decProductId);
     }
     catch (Exception ex)
     {
         MessageBox.Show("SRP2:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 22
0
 /// <summary>
 /// Function to add the products to grid
 /// </summary>
 public void AddToGrid()
 {
     BatchBll BllBatch = new BatchBll();
     GodownBll BllGodown = new GodownBll();
     try
     {
         SettingsBll BllSettings = new SettingsBll();
         if (txtProductCode.Text.Trim() == null && txtProductCode.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Enter product code");
             txtProductCode.Focus();
         }
         else if (cmbItem.SelectedIndex == -1 && cmbItem.SelectedValue == null)
         {
             Messages.InformationMessage("Select a product");
             cmbItem.Focus();
         }
         else if (Convert.ToDecimal(txtQuantity.Text.Trim()) <= 0 || txtQuantity.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Enter quantity");
             txtQuantity.Focus();
         }
         else if (cmbUnit.SelectedValue == null)
         {
             Messages.InformationMessage("Select a unit");
             cmbUnit.Focus();
         }
         else if (BllSettings.SettingsStatusCheck("AllowZeroValueEntry") == "No" && decimal.Parse(txtRate.Text.Trim()) <= 0 || txtRate.Text.Trim() == string.Empty)
         {
             Messages.InformationMessage("Enter rate");
             txtRate.Focus();
         }
         else
         {
             int inCurrentRowIndex = new int();
             bool isExecutef = false;
             if (rowIdToEdit == 0)
             {
                 dgvPointOfSales.Rows.Add();
                 inCurrentRowIndex = dgvPointOfSales.Rows.Count - 1;
                 isExecutef = true;
             }
             else
             {
                 for (int i = 0; i < dgvPointOfSales.Rows.Count; ++i)
                 {
                     if (dgvPointOfSales.Rows[i].Cells["rowId"].Value.ToString() == rowIdToEdit.ToString())
                     {
                         isExecutef = true;
                         inCurrentRowIndex = i;
                         break;
                     }
                 }
             }
             if (!isExecutef)
             {
                 dgvPointOfSales.Rows.Add();
                 inCurrentRowIndex = dgvPointOfSales.Rows.Count - 1;
             }
             ProductInfo infoProduct = new ProductInfo();
             BatchInfo infoBatch = new BatchInfo();
             RackInfo infoRack = new RackInfo();
             ProductCreationBll BllProductCreation = new ProductCreationBll();
             UnitConvertionInfo InfoUnitConvertion = new UnitConvertionInfo();
             infoProduct = BllProductCreation.ProductView(decProductId);
             decimal dcProductBatch = BllBatch.BatchIdViewByProductId(decProductId);
             InfoUnitConvertion = new UnitConvertionBll().UnitViewAllByProductId(decProductId);
             infoBatch = BllBatch.BatchView(dcProductBatch);
             decimal dcGodownId = infoProduct.GodownId;
             GodownInfo infoGodown = new GodownInfo();
             infoGodown = BllGodown.GodownView(dcGodownId);
             decimal dcRackId = infoProduct.RackId;
             infoRack = new RackBll().RackView(dcRackId);
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtProductCode"].Value = txtProductCode.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtProductName"].Value = cmbItem.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtQuantity"].Value = txtQuantity.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtUnit"].Value = cmbUnit.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtRate"].Value = txtRate.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtGrossValue"].Value = txtGrossValue.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtTaxPercentage"].Value = cmbTax.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtTaxAmount"].Value = txtTaxAmount.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtNetAmount"].Value = txtNetAmount.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtDiscount"].Value = txtDiscountAmount.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtTotalAmount"].Value = txtAmount.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxttaxid"].Value = Convert.ToDecimal(cmbTax.SelectedValue);
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtProductId"].Value = infoProduct.ProductId;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtBatchId"].Value = dcProductBatch;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtRackId"].Value = infoProduct.RackId;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtGodownId"].Value = infoProduct.GodownId;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtUnitId"].Value = Convert.ToDecimal(cmbUnit.SelectedValue);
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtunitconversionId"].Value = InfoUnitConvertion.UnitconvertionId;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtBarcode"].Value = txtBarcode.Text;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtBatchno"].Value = infoBatch.BatchNo;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtGodownName"].Value = infoGodown.GodownName;
             dgvPointOfSales.Rows[inCurrentRowIndex].Cells["dgvtxtRackName"].Value = infoRack.RackName;
             TotalAmountCalculation();
             ClearGroupbox();
             dgvPointOfSales.CurrentCell = dgvPointOfSales[0, dgvPointOfSales.Rows.Count - 1];
             txtBarcode.Focus();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("POS:34" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 public void getProductRate(int index, decimal decProductId, decimal decBatchId)
 {
     ProductCreationBll BllProductCreation = new ProductCreationBll();
     decimal decPricingLevelId = 0;
     try
     {
         DateTime dtcurrentDate = PublicVariables._dtCurrentDate;
         decimal decNodecplaces = PublicVariables._inNoOfDecimalPlaces;
         decPricingLevelId = Convert.ToDecimal(cmbPricingLevel.SelectedValue.ToString());
         decimal decRate = BllProductCreation.SalesInvoiceProductRateForSales(decProductId, dtcurrentDate, decBatchId, decPricingLevelId, decNodecplaces);
         dgvProduct.Rows[index].Cells["dgvtxtRate"].Value = decRate;
     }
     catch (Exception ex)
     {
         MessageBox.Show("DN48: " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 24
0
        /// <summary>
        /// Function to call frmProductSearchPopup form to select and view a product
        /// </summary>
        /// <param name="frmProductSearchPopup"></param>
        /// <param name="decproductId"></param>
        /// <param name="decCurrentRowIndex"></param>
        public void CallFromProductSearchPopup(frmProductSearchPopup frmProductSearchPopup, decimal decproductId, decimal decCurrentRowIndex)
        {
            ProductInfo infoProduct = new ProductInfo();
            ProductCreationBll BllProductCreation = new ProductCreationBll();
            try
            {
                base.Show();
                this.frmProductSearchPopupObj = frmProductSearchPopup;

                cmbItem.SelectedValue = decproductId;

                frmProductSearchPopupObj.Close();
                frmProductSearchPopupObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show("POS: 63" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 ///Function for ReturnFromProductCreationPopup
 /// </summary>
 public void ReturnFromProductCreation(decimal decProductId)
 {
     ProductInfo infoProduct = new ProductInfo();
     ProductCreationBll BllProductCreation = new ProductCreationBll();
     BatchBll BllBatch = new BatchBll();
     List<DataTable> list = new List<DataTable>();
     UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
     try
     {
         this.Enabled = true;
         this.BringToFront();
         int inI = dgvProduct.CurrentRow.Index;
         if (inI == dgvProduct.Rows.Count - 1)
         {
             dgvProduct.Rows.Add();
         }
         if (decProductId != 0)
         {
             infoProduct = BllProductCreation.ProductView(decProductId);
             dgvProduct.Rows[inI].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode.ToString();
             dgvProduct.Rows[inI].Cells["dgvtxtProductId"].Value = decProductId.ToString();
             dgvProduct.Rows[inI].Cells["dgvtxtProductName"].Value = infoProduct.ProductName;
             dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value = infoProduct.SalesRate.ToString();
             UnitComboFill1(decProductId, inI, dgvProduct.Rows[inI].Cells["dgvcmbUnit"].ColumnIndex);
             dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value = infoProduct.UnitId;
             BatchComboFill(decProductId, inI, dgvProduct.Rows[inI].Cells["dgvcmbBatch"].ColumnIndex);
             dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value = BllBatch.BatchIdViewByProductId(decProductId);
             dgvProduct.Rows[inI].Cells["dgvtxtBarcode"].Value = BllBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString()));
             GridGodownComboFill(decProductId, dgvProduct.CurrentRow.Index, dgvProduct.Rows[inI].Cells["dgvcmbGodown"].ColumnIndex);
             dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value = infoProduct.GodownId;
             RackComboFill1(infoProduct.GodownId, inI, dgvProduct.Rows[inI].Cells["dgvcmbRack"].ColumnIndex);
             dgvProduct.Rows[inI].Cells["dgvcmbRack"].Value = infoProduct.RackId;
             list = bllUnitConvertion.DGVUnitConvertionRateByUnitId(infoProduct.UnitId, infoProduct.ProductName);
             dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value = list[0].Rows[0]["unitconversionId"].ToString();
             dgvProduct.Rows[inI].Cells["dgvtxtConversionRate"].Value = list[0].Rows[0]["conversionRate"].ToString();
             decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtConversionRate"].Value.ToString());
             decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
             AmountCalculation("dgvtxtQty", dgvProduct.CurrentRow.Index);
             dgvProduct.Rows[inI].HeaderCell.Value = "X";
             dgvProduct.Rows[inI].HeaderCell.Style.ForeColor = Color.Red;
             TotalAmountCalculation();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("DN25:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill product Details while return from Product creation when creating new Product 
 /// </summary>
 /// <param name="decProductId"></param>
 public void ReturnFromProductCreation(decimal decProductId)
 {
     try
     {
         if (decProductId != 0)
         {
             this.Enabled = true;
             ProductInfo infoProduct = new ProductInfo();
             ProductCreationBll BllProductCreation = new ProductCreationBll();
             infoProduct = BllProductCreation.productViewByProductId(decProductId);
             isValueChange = true;
             dgvPurchaseOrder.CurrentRow.Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode;
             dgvPurchaseOrder.CurrentRow.Cells["dgvtxtProductName"].Value = infoProduct.ProductName;
             dgvPurchaseOrder.CurrentRow.Cells["dgvtxtRate"].Value = infoProduct.PurchaseRate;
             UnitComboFill(decProductId, dgvPurchaseOrder.CurrentRow.Index, dgvPurchaseOrder.CurrentRow.Cells["dgvcmbUnit"].ColumnIndex);
             dgvPurchaseOrder.CurrentRow.Cells["dgvcmbUnit"].Value = infoProduct.UnitId;
             UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
             listunitconversionViewAll = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(infoProduct.ProductCode);
             foreach (DataRow drUnitByProduct in listunitconversionViewAll[0].Rows)
             {
                 if (dgvPurchaseOrder.CurrentRow.Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                 {
                     dgvPurchaseOrder.CurrentRow.Cells["dgvtxtUnitConversionId"].Value = drUnitByProduct.ItemArray[2].ToString();
                     dgvPurchaseOrder.CurrentRow.Cells["dgvtxtUnitConversionRate"].Value = drUnitByProduct.ItemArray[3].ToString();
                 }
             }
             decCurrentConversionRate = Convert.ToDecimal(dgvPurchaseOrder.CurrentRow.Cells["dgvtxtUnitConversionRate"].Value.ToString());
             decCurrentRate = Convert.ToDecimal(dgvPurchaseOrder.CurrentRow.Cells["dgvtxtRate"].Value.ToString());
             NewAmountCalculation("dgvtxtQty", dgvPurchaseOrder.CurrentRow.Index);
             CalculateTotalAmount();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PO59:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Fill Product Details Curresponding Product code or Barcode
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvProduct_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     BatchBll BllBatch = new BatchBll();
     try
     {
         ProductInfo infoProduct = new ProductInfo();
         List<DataTable> listObj = new List<DataTable>();
         isValueChange = false;
         isDoAfterGridFill = false;
         decimal DefaultRate = 0;
         if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtBarcode")
         {
             string strBCode = string.Empty;
             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();
             }
             listObj = new ProductCreationBll().ProductDetailsCoreespondingToBarcode(strBCode);
             if (listObj[0].Rows.Count > 0)
             {
                 foreach (DataRow RowDetails in listObj[0].Rows)
                 {
                     dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value = RowDetails["productId"].ToString();
                     decimal decProductId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString());
                     dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = RowDetails["productCode"].ToString();
                     dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = RowDetails["productName"].ToString();
                     UnitComboFill1(Convert.ToDecimal(RowDetails["productId"].ToString()), e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].ColumnIndex);
                     dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(RowDetails["unitId"].ToString());
                     BatchComboFill(Convert.ToDecimal(RowDetails["productId"].ToString()), e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex));
                     dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(RowDetails["batchId"].ToString());
                     GridGodownComboFill(Convert.ToDecimal(RowDetails["productId"].ToString()), e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].ColumnIndex);
                     dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(RowDetails["godownId"].ToString());
                     RackComboFill1(Convert.ToDecimal(RowDetails["godownId"].ToString()), e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvcmbRack"].ColumnIndex);
                     dgvProduct.Rows[e.RowIndex].Cells["dgvcmbRack"].Value = Convert.ToDecimal(RowDetails["rackId"].ToString());
                     decimal decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString());
                     UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
                     List<DataTable> ListObj = new List<DataTable>();
                     ListObj = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString());
                     foreach (DataRow drUnitByProduct in ListObj[0].Rows)
                     {
                         if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                         {
                             dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString());
                             dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                         }
                     }
                     dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(RowDetails["salesRate"].ToString()), PublicVariables._inNoOfDecimalPlaces);
                     decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                     decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString());
                     getProductRate(e.RowIndex, decProductId, decBatchId);
                 }
             }
             else
             {
                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty;
                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].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["dgvcmbGodown"].Value = string.Empty;
                 dgvProduct.Rows[e.RowIndex].Cells["dgvcmbRack"].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["dgvtxtUnitConversionId"].Value = string.Empty;
                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = string.Empty;
                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = string.Empty;
                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty;
                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = string.Empty;
             }
         }
         else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtProductCode")
         {
             isValueChange = false;
             isDoAfterGridFill = false;
             ProductDetailsFill(dgvProduct.CurrentRow.Index, "ProductCode");
         }
         else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtProductName")
         {
             isValueChange = false;
             isDoAfterGridFill = false;
             ProductDetailsFill(dgvProduct.CurrentRow.Index, "ProductName");
         }
         else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtRate")
         {
             if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value != null)
             {
                 if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString() != string.Empty)
                 {
                     DefaultRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value);
                 }
             }
         }
         AmountCalculation("dgvtxtQty", e.RowIndex);
         TotalAmountCalculation();
         isValueChange = true;
         isDoAfterGridFill = true;
         CheckInvalidEntries(e);
     }
     catch (Exception ex)
     {
         MessageBox.Show("DN68:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Save Function
        /// </summary>
        public void SaveFunction()
        {
            try
            {
                PurchaseOrderMasterInfo infoPurchaseOrderMaster = new PurchaseOrderMasterInfo();
                PurchaseOrderBll BllPurchaseOrder = new  PurchaseOrderBll();
                PurchaseOrderDetailsInfo infoPurchaseOrderDetails = new PurchaseOrderDetailsInfo();

                ProductInfo infoProduct = new ProductInfo();
                ProductCreationBll BllProductCreation = new ProductCreationBll();
                SettingsBll BllSettings = new SettingsBll();
                if (cbxCancel.Checked)
                {
                    infoPurchaseOrderMaster.Cancelled = true;
                }
                else
                {
                    infoPurchaseOrderMaster.Cancelled = false;
                }
                infoPurchaseOrderMaster.Date = Convert.ToDateTime(txtDate.Text);
                infoPurchaseOrderMaster.DueDate = Convert.ToDateTime(txtDueDate.Text);
                infoPurchaseOrderMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
                if (isAutomatic == true)
                {
                    infoPurchaseOrderMaster.SuffixPrefixId = decPurchaseSuffixPrefixId;
                    infoPurchaseOrderMaster.VoucherNo = strVoucherNo;
                }
                else
                {
                    infoPurchaseOrderMaster.SuffixPrefixId = 0;
                    infoPurchaseOrderMaster.VoucherNo = BllPurchaseOrder.VoucherNoMax(decPurchaseOrderTypeId);
                }
                infoPurchaseOrderMaster.VoucherTypeId = decPurchaseOrderTypeId;
                infoPurchaseOrderMaster.InvoiceNo = txtOrderNo.Text;
                infoPurchaseOrderMaster.UserId = PublicVariables._decCurrentUserId;
                infoPurchaseOrderMaster.EmployeeId = PublicVariables._decCurrentUserId;//by default current userid used as current employeeid
                infoPurchaseOrderMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                infoPurchaseOrderMaster.Narration = txtNarration.Text.Trim();
                infoPurchaseOrderMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
                infoPurchaseOrderMaster.exchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                infoPurchaseOrderMaster.Extra1 = string.Empty;
                infoPurchaseOrderMaster.Extra2 = string.Empty;
                decPurchaseOrderMasterIdentity = Convert.ToDecimal(BllPurchaseOrder.PurchaseOrderMasterAdd(infoPurchaseOrderMaster));
                int inRowcount = dgvPurchaseOrder.Rows.Count;
                for (int inI = 0; inI < inRowcount - 1; inI++)
                {
                    infoPurchaseOrderDetails.PurchaseOrderMasterId = decPurchaseOrderMasterIdentity;
                    if (dgvPurchaseOrder.Rows[inI].Cells["dgvtxtProductCode"].Value != null && dgvPurchaseOrder.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString() != "")
                    {
                        infoProduct = BllProductCreation.ProductViewByCode(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                        infoPurchaseOrderDetails.ProductId = infoProduct.ProductId;
                    }
                    if (dgvPurchaseOrder.Rows[inI].Cells["dgvtxtQty"].Value != null && dgvPurchaseOrder.Rows[inI].Cells["dgvtxtQty"].Value.ToString() != "")
                    {
                        infoPurchaseOrderDetails.Qty = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                    }
                    if (dgvPurchaseOrder.Rows[inI].Cells["dgvcmbUnit"].Value != null && dgvPurchaseOrder.Rows[inI].Cells["dgvcmbUnit"].Value.ToString() != "")
                    {
                        infoPurchaseOrderDetails.UnitId = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvcmbUnit"].Value);
                        infoPurchaseOrderDetails.UnitConversionId = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString());
                    }
                    infoPurchaseOrderDetails.Rate = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                    infoPurchaseOrderDetails.Amount = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                    infoPurchaseOrderDetails.SlNo = Convert.ToInt32(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
                    infoPurchaseOrderDetails.Extra1 = string.Empty;
                    infoPurchaseOrderDetails.Extra2 = string.Empty;
                    BllPurchaseOrder.PurchaseOrderDetailsAdd(infoPurchaseOrderDetails);
                }
                Messages.SavedMessage();
                if (cbxPrintAfterSave.Checked)
                {
                    if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                    {
                        PrintForDotMatrix(decPurchaseOrderMasterIdentity);
                    }
                    else
                    {
                        Print(decPurchaseOrderMasterIdentity);
                    }
                }
                Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("PO35:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// AutoCompletion of Product name and Product code
 /// </summary>
 /// <param name="isProductName"></param>
 /// <param name="editControl"></param>
 public void FillProducts(bool isProductName, DataGridViewTextBoxEditingControl editControl)
 {
     try
     {
         List<DataTable> listObjProducts = new List<DataTable>();
         listObjProducts = new ProductCreationBll().ProductViewAll();
         ProductNames = new AutoCompleteStringCollection();
         ProductCodes = new AutoCompleteStringCollection();
         foreach (DataRow dr in listObjProducts[0].Rows)
         {
             ProductNames.Add(dr["productName"].ToString());
             ProductCodes.Add(dr["productCode"].ToString());
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("DN15:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to call frmProductSearchPopup form to select and view Products
 /// </summary>
 /// <param name="frmProductSearchPopup"></param>
 /// <param name="decproductId"></param>
 /// <param name="decCurrentRowIndex"></param>
 public void CallFromProductSearchPopup(frmProductSearchPopup frmProductSearchPopup, decimal decproductId, decimal decCurrentRowIndex)
 {
     try
     {
         ProductInfo infoProduct = new ProductInfo();
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         this.frmProductSearchPopupObj = frmProductSearchPopup;
         infoProduct = BllProductCreation.ProductView(decproductId);
         dgvPurchaseOrder.CurrentRow.Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode;
         dgvPurchaseOrder.CurrentRow.Cells["dgvtxtProductName"].Value = infoProduct.ProductName;
         dgvPurchaseOrder.CurrentRow.Cells["dgvtxtRate"].Value = infoProduct.PurchaseRate;
         UnitComboFill(decproductId, dgvPurchaseOrder.CurrentRow.Index, dgvPurchaseOrder.CurrentRow.Cells["dgvcmbUnit"].ColumnIndex);
         dgvPurchaseOrder.CurrentRow.Cells["dgvcmbUnit"].Value = infoProduct.UnitId;
         UnitConvertionBll bllUnitConvertion = new UnitConvertionBll();
         List<DataTable> list = new List<DataTable>();
         list = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(infoProduct.ProductCode);
         foreach (DataRow drUnitByProduct in list[0].Rows)
         {
             if (dgvPurchaseOrder.CurrentRow.Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
             {
                 dgvPurchaseOrder.CurrentRow.Cells["dgvtxtUnitConversionId"].Value = drUnitByProduct.ItemArray[2].ToString();
                 dgvPurchaseOrder.CurrentRow.Cells["dgvtxtUnitConversionRate"].Value = drUnitByProduct.ItemArray[3].ToString();
             }
         }
         decCurrentConversionRate = Convert.ToDecimal(dgvPurchaseOrder.CurrentRow.Cells["dgvtxtUnitConversionRate"].Value.ToString());
         decCurrentRate = Convert.ToDecimal(dgvPurchaseOrder.CurrentRow.Cells["dgvtxtRate"].Value.ToString());
         NewAmountCalculation("dgvtxtQty", dgvPurchaseOrder.CurrentRow.Index);
         CalculateTotalAmount();
         frmProductSearchPopupObj.Close();
         frmProductSearchPopupObj = null;
         this.Enabled = true;
         this.BringToFront();
     }
     catch (Exception ex)
     {
         MessageBox.Show("PO24:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }