private void dgvProduct_CellLeave(object sender, DataGridViewCellEventArgs e) { try { if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQty") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuotationDetailsId"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuotationDetailsId"].Value.ToString() != string.Empty && Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuotationDetailsId"].Value.ToString()) != 0) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString() != string.Empty) { SalesQuotationBll spSalesQuation = new SalesQuotationBll(); decimal decReferencedQty = Math.Round(spSalesQuation.SalesQuatationReferenceCheck(Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuotationDetailsId"].Value.ToString())), PublicVariables._inNoOfDecimalPlaces); decimal decQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()); if (decQty < decReferencedQty) { Messages.InformationMessage("Quantity in row " + (e.RowIndex + 1) + " should be greater than " + decReferencedQty); IsCellValue = false; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = Math.Round(decReferencedQty,PublicVariables._inNoOfDecimalPlaces); IsCellValue = true; } } } AmountCalculation("dgvtxtQty", e.RowIndex); TotalAmountCalculation(); } else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() != string.Empty) { UnitConvertionBll bllUnitConvertion = new UnitConvertionBll(); List< DataTable >listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString()); if (listUnitByProduct[0].Rows.Count > 0) { foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString()) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString()); if (IsDoAfterFill) { decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, Convert.ToInt32(PublicVariables._inNoOfDecimalPlaces)); } } } AmountCalculation("dgvtxtQty", e.RowIndex); TotalAmountCalculation(); } } } else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbBatch") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty) { string strProductCode = string.Empty; ProductInfo infoproduct = new ProductInfo(); ProductCreationBll BllProductCreation = new ProductCreationBll(); decimal decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = BllProductCreation.BarcodeViewByBatchId(decBatchId); strProductCode = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString(); infoproduct = BllProductCreation.ProductViewByCode(strProductCode); DateTime dtcurrentDate = PublicVariables._dtCurrentDate; decimal decNodecplaces = PublicVariables._inNoOfDecimalPlaces; decimal decStandardRate = BllProductCreation.SalesInvoiceProductRateForSales(infoproduct.ProductId, dtcurrentDate, decBatchId, Convert.ToDecimal(cmbPricinglevel.SelectedValue), decNodecplaces); if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty) { if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value) != 0) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces); } AmountCalculation("dgvtxtQty", e.RowIndex); TotalAmountCalculation(); } } } else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtExchangeRate" && isAmountcalc) { AmountCalculation("dgvtxtExchangeRate", e.RowIndex); TotalAmountCalculation(); } //---------------while changing Rate,corresponding change in amount---- else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtRate" && isAmountcalc) { AmountCalculation("dgvtxtRate", e.RowIndex); TotalAmountCalculation(); } //----while changing amount ,corresponding chnage in total amount------- CheckInvalidEntriesInDataGridProduct(e); } catch (Exception ex) { MessageBox.Show("SQ:76" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to call frmProductSearchPopup form to select and view product /// </summary> /// <param name="frmProductSearchPopup"></param> /// <param name="decproductId"></param> /// <param name="decCurrentRowIndex"></param> public void CallFromProductSearchPopup(frmProductSearchPopup frmProductSearchPopup, decimal decproductId, decimal decCurrentRowIndex) { ProductCreationBll BllProductCreation = new ProductCreationBll(); ProductInfo infoProduct = new ProductInfo(); try { this.Enabled = true; this.BringToFront(); this.frmProductSearchPopupObj = frmProductSearchPopup; int inCurrentRowIndex = dgvProduct.CurrentRow.Index; dgvProduct.Rows.Add(); if (decproductId != 0) { List<DataTable> ListObj = new List<DataTable>(); List<DataTable> ListObjUnitViewAll = new List<DataTable>(); infoProduct = BllProductCreation.ProductView(decproductId); TransactionsGeneralFillBll transactionGeneralFillObj = new TransactionsGeneralFillBll(); SalesQuotationBll bllSalesQuotation = new SalesQuotationBll(); dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtProductName"].Value = infoProduct.ProductName; dgvProduct.Rows[inCurrentRowIndex].Cells["ProductId"].Value = infoProduct.ProductId; dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode; dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.SalesRate, PublicVariables._inNoOfDecimalPlaces); DefaultRate = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces); ListObjUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, infoProduct.ProductId.ToString(), inCurrentRowIndex); ListObj= bllSalesQuotation.SalesQuotationMasterBatchFill(dgvProduct, infoProduct.ProductId, inCurrentRowIndex); BatchBll BllBatch = new BatchBll(); decimal decBatchId = BllBatch.BatchIdViewByProductId(infoProduct.ProductId); dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbBatch"].Value = decBatchId; dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbUnit"].Value = infoProduct.UnitId; if (infoProduct.PartNo != string.Empty) { dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtBarcode"].Value = infoProduct.PartNo; } else { if (dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty) { decBatchId = Convert.ToDecimal(dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbBatch"].Value); dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtBarcode"].Value = BllProductCreation.BarcodeViewByBatchId(decBatchId); } } IsDoAfterFill = true; UnitConvertionBll bllUnitConvertion = new UnitConvertionBll(); List<DataTable> listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[inCurrentRowIndex].Cells["ProductId"].Value.ToString()); if (listUnitByProduct[0].Rows.Count > 0) { foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows) { if (dgvProduct.Rows[inCurrentRowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString()) { dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString()); dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString()); if (IsDoAfterFill) { decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate; dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, PublicVariables._inNoOfDecimalPlaces); } } } } decimal decStandardRate = BllProductCreation.SalesInvoiceProductRateForSales(infoProduct.ProductId, PublicVariables._dtCurrentDate, decBatchId, Convert.ToDecimal(cmbPricinglevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces); if (dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty) { if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value) != 0) { dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[inCurrentRowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces); } } dgvProduct.Rows[inCurrentRowIndex].HeaderCell.Value = "X"; dgvProduct.Rows[inCurrentRowIndex].HeaderCell.Style.ForeColor = Color.Red; } frmProductSearchPopupObj.Close(); frmProductSearchPopupObj = null; } catch (Exception ex) { MessageBox.Show("SQ:42" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// On cellendedit of dgvProduct /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProduct_CellEndEdit(object sender, DataGridViewCellEventArgs e) { ProductCreationBll BllProductCreation = new ProductCreationBll(); try { if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtProductName") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString().Trim() != string.Empty) { string strProductName = Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value); ProductInfo infoProduct = BllProductCreation.ProductViewByName(strProductName); if (infoProduct.ProductCode != null && infoProduct.ProductCode != string.Empty) { TransactionsGeneralFillBll transactionGeneralFillObj = new TransactionsGeneralFillBll(); SalesQuotationBll bllSalesQuotation = new SalesQuotationBll(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode; dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = infoProduct.ProductId; List<DataTable> ListObj = new List<DataTable>(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.SalesRate); DefaultRate = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces); ListObjUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, infoProduct.ProductId.ToString(), e.RowIndex); ListObj = bllSalesQuotation.SalesQuotationMasterBatchFill(dgvProduct, infoProduct.ProductId, e.RowIndex); BatchBll BllBatch = new BatchBll(); decimal decBatchId = BllBatch.BatchIdViewByProductId(infoProduct.ProductId); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = decBatchId; dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = infoProduct.UnitId; if (infoProduct.PartNo != string.Empty) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = infoProduct.PartNo; } else { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty) { decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = BllProductCreation.BarcodeViewByBatchId(decBatchId); } } IsDoAfterFill = true; UnitConvertionBll bllUnitConvertion = new UnitConvertionBll(); List<DataTable> listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString()); if (listUnitByProduct[0].Rows.Count > 0) { foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString()) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString()); if (IsDoAfterFill) { decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate,PublicVariables._inNoOfDecimalPlaces); } } } } decimal decStandardRate = BllProductCreation.SalesInvoiceProductRateForSales(infoProduct.ProductId, PublicVariables._dtCurrentDate, decBatchId, Convert.ToDecimal(cmbPricinglevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces); if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty) { if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value) != 0) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces); } } } else { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = string.Empty; } AmountCalculation("dgvtxtQty", e.RowIndex); TotalAmountCalculation(); } else { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty; } } if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtBarcode") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString().Trim() != string.Empty) { List<DataTable> listObjProductdDetails = new List<DataTable>(); string strBarcode = (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString()); listObjProductdDetails = BllProductCreation.ProductDetailsCoreespondingToBarcode(strBarcode); if (listObjProductdDetails[0].Rows.Count > 0) { TransactionsGeneralFillBll transactionGeneralFillObj = new TransactionsGeneralFillBll(); SalesQuotationBll bllSalesQuotation = new SalesQuotationBll(); List<DataTable> ListObj = new List<DataTable>(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = listObjProductdDetails[0].Rows[0]["productCode"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = listObjProductdDetails[0].Rows[0]["productId"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = listObjProductdDetails[0].Rows[0]["productName"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["SalesRate"].ToString())); DefaultRate = Math.Round(Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["purchaseRate"].ToString()), PublicVariables._inNoOfDecimalPlaces); ListObjUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, listObjProductdDetails[0].Rows[0]["productId"].ToString(), e.RowIndex); ListObj = bllSalesQuotation.SalesQuotationMasterBatchFill(dgvProduct, Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["productId"].ToString()), e.RowIndex); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["batchId"].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["unitId"].ToString()); IsDoAfterFill = true; UnitConvertionBll bllUnitConvertion = new UnitConvertionBll(); List<DataTable> listUnitByProduct = bllUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString()); if (listUnitByProduct[0].Rows.Count > 0) { foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString()) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString()); if (IsDoAfterFill) { decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, PublicVariables._inNoOfDecimalPlaces); } } } } decimal decStandardRate = BllProductCreation.SalesInvoiceProductRateForSales(Convert.ToDecimal(listObjProductdDetails[0].Rows[0]["productId"].ToString()), PublicVariables._dtCurrentDate, decBatchId, Convert.ToDecimal(cmbPricinglevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces); if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty) { if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value) != 0) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces); } } } else { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = string.Empty; } AmountCalculation("dgvtxtQty", e.RowIndex); TotalAmountCalculation(); } else { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty; } } else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtProductCode") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString().Trim() != string.Empty) { ProductInfo infoProduct = new ProductInfo(); string strProductCode = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString(); infoProduct = BllProductCreation.ProductViewByCode(strProductCode); if (infoProduct.ProductId != 0) { TransactionsGeneralFillBll transactionGeneralFillObj = new TransactionsGeneralFillBll(); SalesQuotationBll bllSalesQuotation = new SalesQuotationBll(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = infoProduct.ProductName; dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = infoProduct.ProductId; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.SalesRate, PublicVariables._inNoOfDecimalPlaces); DefaultRate = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces); List<DataTable> LiostObj = new List<DataTable>(); ListObjUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, infoProduct.ProductId.ToString(), e.RowIndex); LiostObj = bllSalesQuotation.SalesQuotationMasterBatchFill(dgvProduct, infoProduct.ProductId, e.RowIndex); BatchBll BllBatch = new BatchBll(); decimal decBatchId = BllBatch.BatchIdViewByProductId(infoProduct.ProductId); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = decBatchId; dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = infoProduct.UnitId; if (infoProduct.PartNo != string.Empty) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = infoProduct.PartNo; } else { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty) { decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = BllProductCreation.BarcodeViewByBatchId(decBatchId); } } IsDoAfterFill = true; UnitConvertionBll bllUnitByProduct = new UnitConvertionBll(); List<DataTable> listUnitByProduct = bllUnitByProduct.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString()); if (listUnitByProduct[0].Rows.Count > 0) { foreach (DataRow drUnitByProduct in listUnitByProduct[0].Rows) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString()) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString()); if (IsDoAfterFill) { decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, PublicVariables._inNoOfDecimalPlaces); } } } } decimal decStandardRate = BllProductCreation.SalesInvoiceProductRateForSales(infoProduct.ProductId, PublicVariables._dtCurrentDate, decBatchId, Convert.ToDecimal(cmbPricinglevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces); if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty) { if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value) != 0) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces); } } } else { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = string.Empty; } AmountCalculation("dgvtxtQty", e.RowIndex); TotalAmountCalculation(); } } else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtRate") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString() != string.Empty) { DefaultRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value); } } CheckInvalidEntriesInDataGridProduct(e); } catch (Exception ex) { MessageBox.Show("SQ:56" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to Fill Product Details in grid /// </summary> /// <param name="strProductCode"></param> /// <param name="rowIndex"></param> private void FillProductDetails(string strProductCode, int rowIndex) { try { ProductInfo infoProductFill = new ProductInfo(); infoProductFill = new ProductCreationBll().ProductViewByCode(strProductCode); UnitConvertionBll bllUnitConvertion = new UnitConvertionBll(); BatchBll BllBatch = new BatchBll(); ProductCreationBll BllProductCreation = new ProductCreationBll(); StockPostingBll BllStockPosting = new StockPostingBll(); List<DataTable> list = new List<DataTable>(); decimal decCurrentConversionRate = 0; if (infoProductFill.ProductId != 0) { dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtproductId"].Value = infoProductFill.ProductId; dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtproductCode"].Value = infoProductFill.ProductCode; dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtproductName"].Value = infoProductFill.ProductName; dgvPurchaseReturn.Rows[rowIndex].Cells["dgvcmbGodown"].Value = infoProductFill.GodownId; dgvPurchaseReturn.Rows[rowIndex].Cells["dgvcmbRack"].Value = infoProductFill.RackId; UnitComboFill(infoProductFill.ProductId, rowIndex, dgvPurchaseReturn.CurrentRow.Cells["dgvcmbUnit"].ColumnIndex); dgvPurchaseReturn.Rows[rowIndex].Cells["dgvcmbUnit"].Value = infoProductFill.UnitId; dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtrate"].Value = Math.Round(infoProductFill.PurchaseRate, PublicVariables._inNoOfDecimalPlaces); dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(new UnitConvertionBll().UnitconversionIdViewByUnitIdAndProductId(infoProductFill.UnitId, infoProductFill.ProductId)); dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtConversionRate"].Value = bllUnitConvertion.UnitConversionRateByUnitConversionId(Convert.ToDecimal(dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtUnitConversionId"].Value.ToString())); BatchComboFill(infoProductFill.ProductId, rowIndex, dgvPurchaseReturn.CurrentRow.Cells["dgvcmbBatch"].ColumnIndex); dgvPurchaseReturn.Rows[rowIndex].Cells["dgvcmbBatch"].Value = BllStockPosting.BatchViewByProductId(Convert.ToDecimal(dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtproductId"].Value)); list = bllUnitConvertion.DGVUnitConvertionRateByUnitId(infoProductFill.UnitId, infoProductFill.ProductName); dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtUnitConversionId"].Value = list[0].Rows[0]["unitconversionId"].ToString(); dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtConversionRate"].Value = list[0].Rows[0]["conversionRate"].ToString(); decCurrentConversionRate = Convert.ToDecimal(dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); //dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtqty"].Value = 0; dgvPurchaseReturn.Rows[rowIndex].Cells["dgvcmbTax"].Value = infoProductFill.TaxId; AmountCalculation("dgvtxtqty", rowIndex); decimal decProdtId = infoProductFill.ProductId; decBatchId = BllStockPosting.BatchViewByProductId(decProdtId); dgvPurchaseReturn.Rows[rowIndex].Cells["dgvcmbBatch"].Value = decBatchId; string strBarcode = Convert.ToString(BllProductCreation.BarcodeViewByBatchId(decBatchId)); dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtbarcode"].Value = strBarcode; if (dgvPurchaseReturn.Rows[rowIndex + 1].Cells["dgvtxtproductCode"].Selected == true) { dgvPurchaseReturn.Rows[rowIndex].Cells["dgvtxtqty"].Selected = true; dgvPurchaseReturn.Rows[rowIndex + 1].Selected = false; dgvPurchaseReturn.Rows[rowIndex].HeaderCell.Value = "X"; dgvPurchaseReturn.Rows[rowIndex].HeaderCell.Style.ForeColor = Color.Red; } } } catch (Exception ex) { MessageBox.Show("PR:22" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }