/// <summary> /// grid CellValueChanged for do the basic calculation and unit selection /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProductBOM_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { CheckInvalidEntries(e); ProductSP spProduct = new ProductSP(); TransactionsGeneralFill trstGnFill = new TransactionsGeneralFill(); if (e.RowIndex > -1) { if (e.ColumnIndex == dgvProductBOM.Columns["dgvcmbRawMaterial"].Index) { if (dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbRawMaterial"] != null) { dgvProductBOM.Rows[e.RowIndex].Cells["dgvtxtUnit"].Value = spProduct.ProductUnit(Convert.ToDecimal(dgvProductBOM.Rows[e.RowIndex].Cells[1].Value)); DataTable dtblunitconversionViewAll = new DataTable(); decimal decProductId = Convert.ToDecimal(dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbRawMaterial"].Value); dtblunitconversionViewAll = trstGnFill.UnitViewAllByProductId(dgvProductBOM, decProductId.ToString(), e.RowIndex); DataRow drow = dtblunitconversionViewAll.NewRow(); drow["unitName"] = string.Empty; drow["unitId"] = 0; dtblunitconversionViewAll.Rows.InsertAt(drow, 0); DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)(dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbUnit"]); cell.DataSource = dtblunitconversionViewAll; cell.ValueMember = "unitId"; cell.DisplayMember = "unitName"; if (dtblunitconversionViewAll.Rows[0][4] != null && dtblunitconversionViewAll.Rows[0][4] != DBNull.Value) { dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(dtblunitconversionViewAll.Rows[0][4].ToString()); } } } } } catch (Exception ex) { formMDI.infoError.ErrorString = "PB:21" + ex.Message; } }
/// <summary> /// On cellendedit of dgvProduct /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProduct_CellEndEdit(object sender, DataGridViewCellEventArgs e) { ProductSP SpProduct = new ProductSP(); 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 = SpProduct.ProductViewByName(strProductName); if (infoProduct.ProductCode != null && infoProduct.ProductCode != string.Empty) { TransactionsGeneralFill transactionGeneralFillObj = new TransactionsGeneralFill(); SalesQuotationMasterSP SpSalesQuotationMaster = new SalesQuotationMasterSP(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode; dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = infoProduct.ProductId; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.SalesRate); DefaultRate = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces); dtblUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, infoProduct.ProductId.ToString(), e.RowIndex); dtblbatchViewAll = SpSalesQuotationMaster.SalesQuotationMasterBatchFill(dgvProduct, infoProduct.ProductId, e.RowIndex); BatchSP spBatch = new BatchSP(); decimal decBatchId = spBatch.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 = SpProduct.BarcodeViewByBatchId(decBatchId); } } IsDoAfterFill = true; UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString()); if (dtblUnitByProduct.Rows.Count > 0) { foreach (DataRow drUnitByProduct in dtblUnitByProduct.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 = SpProduct.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) { DataTable dtblProductdDetails = new DataTable(); string strBarcode = (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString()); dtblProductdDetails = SpProduct.ProductDetailsCoreespondingToBarcode(strBarcode); if (dtblProductdDetails.Rows.Count > 0) { TransactionsGeneralFill transactionGeneralFillObj = new TransactionsGeneralFill(); SalesQuotationMasterSP SpSalesQuotationMaster = new SalesQuotationMasterSP(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = dtblProductdDetails.Rows[0]["productCode"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value = dtblProductdDetails.Rows[0]["productId"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = dtblProductdDetails.Rows[0]["productName"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(dtblProductdDetails.Rows[0]["SalesRate"].ToString())); DefaultRate = Math.Round(Convert.ToDecimal(dtblProductdDetails.Rows[0]["purchaseRate"].ToString()), PublicVariables._inNoOfDecimalPlaces); dtblUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, dtblProductdDetails.Rows[0]["productId"].ToString(), e.RowIndex); dtblbatchViewAll = SpSalesQuotationMaster.SalesQuotationMasterBatchFill(dgvProduct, Convert.ToDecimal(dtblProductdDetails.Rows[0]["productId"].ToString()), e.RowIndex); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(dtblProductdDetails.Rows[0]["batchId"].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(dtblProductdDetails.Rows[0]["unitId"].ToString()); IsDoAfterFill = true; UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString()); if (dtblUnitByProduct.Rows.Count > 0) { foreach (DataRow drUnitByProduct in dtblUnitByProduct.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 = SpProduct.SalesInvoiceProductRateForSales(Convert.ToDecimal(dtblProductdDetails.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 = SpProduct.ProductViewByCode(strProductCode); if (infoProduct.ProductId != 0) { TransactionsGeneralFill transactionGeneralFillObj = new TransactionsGeneralFill(); SalesQuotationMasterSP SpSalesQuotationMaster = new SalesQuotationMasterSP(); 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); dtblUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, infoProduct.ProductId.ToString(), e.RowIndex); dtblbatchViewAll = SpSalesQuotationMaster.SalesQuotationMasterBatchFill(dgvProduct, infoProduct.ProductId, e.RowIndex); BatchSP spBatch = new BatchSP(); decimal decBatchId = spBatch.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 = SpProduct.BarcodeViewByBatchId(decBatchId); } } IsDoAfterFill = true; UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["ProductId"].Value.ToString()); if (dtblUnitByProduct.Rows.Count > 0) { foreach (DataRow drUnitByProduct in dtblUnitByProduct.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 = SpProduct.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 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) { ProductSP SpProduct = new ProductSP(); ProductInfo infoProduct = new ProductInfo(); try { this.Enabled = true; this.BringToFront(); this.frmProductSearchPopupObj = frmProductSearchPopup; int inCurrentRowIndex = dgvProduct.CurrentRow.Index; dgvProduct.Rows.Add(); if (decproductId != 0) { infoProduct = SpProduct.ProductView(decproductId); TransactionsGeneralFill transactionGeneralFillObj = new TransactionsGeneralFill(); SalesQuotationMasterSP SpSalesQuotationMaster = new SalesQuotationMasterSP(); 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); dtblUnitViewAll = transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, infoProduct.ProductId.ToString(), inCurrentRowIndex); dtblbatchViewAll = SpSalesQuotationMaster.SalesQuotationMasterBatchFill(dgvProduct, infoProduct.ProductId, inCurrentRowIndex); BatchSP spBatch = new BatchSP(); decimal decBatchId = spBatch.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 = SpProduct.BarcodeViewByBatchId(decBatchId); } } IsDoAfterFill = true; UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[inCurrentRowIndex].Cells["ProductId"].Value.ToString()); if (dtblUnitByProduct.Rows.Count > 0) { foreach (DataRow drUnitByProduct in dtblUnitByProduct.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 = SpProduct.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> /// Function to fill the details for edit or delete /// </summary> public void FillRegisterOrReport() { SalesQuotationDetailsSP SpSalesQuotationDetails = new SalesQuotationDetailsSP(); TransactionsGeneralFill transactionGeneralFillObj = new TransactionsGeneralFill(); SalesQuotationMasterInfo infoSalesQuotationMaster = new SalesQuotationMasterInfo(); SalesQuotationMasterSP SpSalesQuotationMaster = new SalesQuotationMasterSP(); ProductSP SpProduct = new ProductSP(); try { VoucherTypeSP spVoucherType = new VoucherTypeSP(); IsDoAfterFill = false; IsCellValue = false; btnSave.Text = "Update"; btnDelete.Enabled = true; infoSalesQuotationMaster = SpSalesQuotationMaster.SalesQuotationMasterView(decSalesquotationMasterId); txtQuotationNo.Text = infoSalesQuotationMaster.InvoiceNo; strVoucherNo = infoSalesQuotationMaster.VoucherNo.ToString(); decSalesQuotationPreffixSuffixId = Convert.ToDecimal(infoSalesQuotationMaster.SuffixPrefixId); decSalesQuotationVoucherId = Convert.ToDecimal(infoSalesQuotationMaster.VoucherTypeId); isAutomatic = spVoucherType.CheckMethodOfVoucherNumbering(decSalesQuotationVoucherId); decsalesQuotationTypeId = decSalesQuotationVoucherId; txtSalesQuotationDate.Text = infoSalesQuotationMaster.Date.ToString("dd-MMM-yyyy"); cmbCashOrParty.SelectedValue = infoSalesQuotationMaster.LedgerId; ComboSalesManFill(); cmbSalesman.SelectedValue = infoSalesQuotationMaster.EmployeeId; txtNarration.Text = infoSalesQuotationMaster.Narration; cmbCurrency.SelectedValue = infoSalesQuotationMaster.ExchangeRateId; decimal decsalesregisterTotal = Convert.ToDecimal(infoSalesQuotationMaster.TotalAmount.ToString()); decsalesregisterTotal = Math.Round(decsalesregisterTotal, PublicVariables._inNoOfDecimalPlaces); txtTotal.Text = Convert.ToString(decsalesregisterTotal); cmbPricinglevel.SelectedValue = infoSalesQuotationMaster.PricinglevelId; DataTable dtbl = new DataTable(); dtbl = SpSalesQuotationDetails.SalesQuotationDetailsViewByMasterId(decSalesquotationMasterId); if (isAutomatic) { txtQuotationNo.ReadOnly = true; txtSalesQuotationDate.Focus(); } else { txtQuotationNo.ReadOnly = false; txtQuotationNo.Focus(); } string strApproved = Convert.ToString(infoSalesQuotationMaster.Approved); if (strApproved == "False") { cbxApproved.Checked = false; } else { cbxApproved.Checked = true; } decimal decCount = SpSalesQuotationMaster.CheckingStastusForSalesQuotation(decSalesquotationMasterId); if (decCount > 0) { cbxApproved.Enabled = false; } else { cbxApproved.Enabled = true; } for (int i = 0; i < dtbl.Rows.Count; i++) { isAmountcalc = false; dgvProduct.Rows.Add(); dgvProduct.Rows[i].HeaderCell.Value = string.Empty; dgvProduct.Rows[i].Cells["dgvtxtQuotationDetailsId"].Value = Convert.ToDecimal(dtbl.Rows[i]["quotationDetailsId"].ToString()); dgvProduct.Rows[i].Cells["ProductId"].Value = dtbl.Rows[i]["productId"].ToString(); dgvProduct.Rows[i].Cells["dgvtxtBarcode"].Value = dtbl.Rows[i]["Barcode"].ToString(); dgvProduct.Rows[i].Cells["dgvtxtProductCode"].Value = dtbl.Rows[i]["productCode"].ToString(); transactionGeneralFillObj.UnitViewAllByProductId(dgvProduct, dtbl.Rows[i]["productId"].ToString(), i); SpSalesQuotationMaster.SalesQuotationMasterBatchFill(dgvProduct, Convert.ToDecimal(dtbl.Rows[i]["productId"].ToString()), i); dgvProduct.Rows[i].Cells["dgvtxtProductName"].Value = dtbl.Rows[i]["productName"].ToString(); dgvProduct.Rows[i].Cells["dgvtxtQty"].Value = dtbl.Rows[i]["qty"].ToString(); IsCellValue = true; dgvProduct.Rows[i].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(dtbl.Rows[i]["unitId"].ToString()); IsCellValue = false; dgvProduct.Rows[i].Cells["dgvtxtRate"].Value = dtbl.Rows[i]["rate"].ToString(); IsCellValue = true; dgvProduct.Rows[i].Cells["dgvtxtAmount"].Value = dtbl.Rows[i]["amount"].ToString(); IsCellValue = false; dgvProduct.Rows[i].Cells["dgvcmbbatch"].Value = Convert.ToDecimal(dtbl.Rows[i]["batchId"].ToString()); UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[i].Cells["ProductId"].Value.ToString()); if (dtblUnitByProduct.Rows.Count > 0) { foreach (DataRow drUnitByProduct in dtblUnitByProduct.Rows) { if (dgvProduct.Rows[i].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString()) { dgvProduct.Rows[i].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString()); dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString()); } } } decimal decStandardRate = SpProduct.SalesInvoiceProductRateForSales(Convert.ToDecimal(dtbl.Rows[i]["productId"].ToString()), PublicVariables._dtCurrentDate, Convert.ToDecimal(dtbl.Rows[i]["batchId"].ToString()), Convert.ToDecimal(cmbPricinglevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces); if (dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty) { if (decStandardRate != 0 && Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value) != 0) { dgvProduct.Rows[i].Cells["dgvtxtRate"].Value = Math.Round(decStandardRate / Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces); } } } isAmountcalc = true; IsCellValue = true; IsDoAfterFill = true; } catch (Exception ex) { MessageBox.Show("SQ:39" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// grid CellValueChanged for do the basic calculation and unit selection /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProductBOM_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { CheckInvalidEntries(e); ProductSP spProduct = new ProductSP(); TransactionsGeneralFill trstGnFill = new TransactionsGeneralFill(); if (e.RowIndex > -1) { if (e.ColumnIndex == dgvProductBOM.Columns["dgvcmbRawMaterial"].Index) { if (dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbRawMaterial"] != null) { dgvProductBOM.Rows[e.RowIndex].Cells["dgvtxtUnit"].Value = spProduct.ProductUnit(Convert.ToDecimal(dgvProductBOM.Rows[e.RowIndex].Cells[1].Value)); DataTable dtblunitconversionViewAll = new DataTable(); decimal decProductId = Convert.ToDecimal(dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbRawMaterial"].Value); dtblunitconversionViewAll = trstGnFill.UnitViewAllByProductId(dgvProductBOM, decProductId.ToString(), e.RowIndex); DataRow drow = dtblunitconversionViewAll.NewRow(); drow["unitName"] = string.Empty; drow["unitId"] = 0; dtblunitconversionViewAll.Rows.InsertAt(drow, 0); DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)(dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbUnit"]); cell.DataSource = dtblunitconversionViewAll; cell.ValueMember = "unitId"; cell.DisplayMember = "unitName"; if (dtblunitconversionViewAll.Rows[0][4] != null && dtblunitconversionViewAll.Rows[0][4] != DBNull.Value) { dgvProductBOM.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(dtblunitconversionViewAll.Rows[0][4].ToString()); } } } } } catch (Exception ex) { MessageBox.Show("PB:21" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// To Get Default Product Values /// </summary> /// <param name="inindex"></param> /// <param name="decproductId"></param> public void ProductDefaultValues(int inindex, decimal decproductId) { try { UnitSP spUnit = new UnitSP(); isValueChange = false; infoProduct = spProduct.ProductView(decproductId); dgvProduct.Rows[inindex].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode; dgvProduct.Rows[inindex].Cells["dgvtxtProductName"].Value = infoProduct.ProductName; TransactionsGeneralFill obj = new TransactionsGeneralFill(); DataTable dtblUnitViewall = new DataTable(); dtblUnitViewall = obj.UnitViewAllByProductId(dgvProduct, decproductId.ToString(), inindex); BatchSP spBatch = new BatchSP(); spBatch.BatchViewbyProductIdForComboFillInGrid(decproductId, dgvProduct, inindex); isValueChange = true; } catch (Exception ex) { MessageBox.Show("RO40:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Fill Details Corresponding Quotation No /// </summary> public void FillQuotationDetails() { SerialNo(); try { SalesOrderDetailsInfo infoSalesOrderDetails = new SalesOrderDetailsInfo(); TransactionsGeneralFill TransactionGeneralFillObj = new TransactionsGeneralFill(); decimal decOrderNo = 0; if (!isEditFill) { inMaxCount = 0; decOrderNo = Convert.ToDecimal(cmbQuotationNo.SelectedValue.ToString()); dgvSalesOrder.Rows.Clear(); DataTable dtblMaster = new SalesQuotationMasterSP().QuotationMasterViewByQuotationMasterId(Convert.ToDecimal(cmbQuotationNo.SelectedValue.ToString())); if (dtblMaster.Rows.Count > 0) { cmbPricingLevel.SelectedValue = dtblMaster.Rows[0]["pricingLevelId"].ToString(); if (dtblMaster.Rows[0]["employeeId"].ToString() != "") { strSalesMan = dtblMaster.Rows[0]["employeeId"].ToString(); cmbSalesMan.SelectedValue = strSalesMan; if (cmbSalesMan.SelectedValue == null) { SalesManComboFill(); cmbSalesMan.SelectedValue = dtblMaster.Rows[0]["employeeId"].ToString(); } } DGVCurrencyComboFill(); cmbCurrency.SelectedValue = dtblMaster.Rows[0]["exchangeRateId"].ToString(); DataTable dtblDetails = new SalesQuotationDetailsSP().SalesQuotationDetailsViewByquotationMasterIdWithRemainingBySO(Convert.ToDecimal(cmbQuotationNo.SelectedValue.ToString()), decSalesOrderMasterId); int inRowIndex = 0; foreach (DataRow drowDetails in dtblDetails.Rows) { dgvSalesOrder.Rows.Add(); isValueChange = false; isDoAfterGridFill = false; dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtSalesOrderDetailsId"].Value = drowDetails.ItemArray[0].ToString(); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtSalesQuotationDetailsId"].Value = drowDetails.ItemArray[0].ToString(); String ProductId = drowDetails.ItemArray[2].ToString(); infoProduct = new ProductSP().ProductView(Convert.ToDecimal(ProductId)); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtBarcode"].Value = drowDetails["barcode"].ToString(); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductId"].Value = drowDetails["productId"]; dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode; dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductName"].Value = drowDetails["productName"].ToString(); AssignProductDefaultValues(dgvSalesOrder.Rows.Count - 2, drowDetails["productId"].ToString()); TransactionGeneralFillObj.UnitViewAllByProductId(dgvSalesOrder, infoProduct.ProductId.ToString(), dgvSalesOrder.Rows.Count - 2); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtQty"].Value = drowDetails["qty"].ToString(); UnitComboFill(Convert.ToDecimal(ProductId), dgvSalesOrder.Rows.Count - 2, dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbUnit"].ColumnIndex); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString()); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtRate"].Value = drowDetails["rate"].ToString(); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtAmount"].Value = drowDetails["amount"].ToString(); BatchComboFill(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvSalesOrder.Rows.Count - 2, dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbBatch"].ColumnIndex); if (Convert.ToDecimal(drowDetails["batchId"].ToString()) != 0) { dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString()); } else { StockPostingSP spStockPosting = new StockPostingSP(); decimal decBatchId = spStockPosting.BatchViewByProductId(Convert.ToDecimal(ProductId)); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbBatch"].Value = decBatchId; } string strBarcode = new BatchSP().ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbBatch"].Value.ToString())); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtBarcode"].Value = strBarcode.ToString(); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductCode"].ReadOnly = true; dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductName"].ReadOnly = true; dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtBarcode"].ReadOnly = true; dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["inRowIndex"].Value = drowDetails["extra1"].ToString(); UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtProductId"].Value.ToString()); foreach (DataRow drUnitByProduct in dtblUnitByProduct.Rows) { if (dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString()) { dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString()); dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString()); } } decCurrentConversionRate = Convert.ToDecimal(dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value.ToString()); decCurrentRate = Convert.ToDecimal(dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvtxtRate"].Value.ToString()); if (cmbQuotationNo.Visible == true) { dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true; } dgvSalesOrder.Rows[dgvSalesOrder.Rows.Count - 2].HeaderCell.Value = ""; int intIndex = 0; int.TryParse(drowDetails["extra1"].ToString(), out intIndex); if (inMaxCount < intIndex) inMaxCount = intIndex; inRowIndex++; isValueChange = true; } for (int i = inRowIndex; i < dgvSalesOrder.Rows.Count; ++i) dgvSalesOrder["inRowIndex", i].Value = GetNextinRowIndex().ToString(); SerialNo(); TotalAmountCalculation(); isDoAfterGridFill = true; } } } catch (Exception ex) { MessageBox.Show("SO38: " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }