public void ProductDetailsFill(int inRowIndex, string strFillMode) { try { ProductInfo infoProduct = new ProductInfo(); BatchSP spBatch = new BatchSP(); 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 ProductSP().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 ProductSP().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 = spStockPosting.BatchViewByProductId(Convert.ToDecimal(dgvProduct.Rows[inRowIndex].Cells["dgvtxtProductId"].Value)); string strBarcode = spBatch.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; UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(strproductId); foreach (DataRow drUnitByProduct in dtblUnitByProduct.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> /// Grid view Cell Enter for set editmode and set basics of unit conversion /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProduct_CellEnter(object sender, DataGridViewCellEventArgs e) { decimal decGodownId = 0; try { if (dgvProduct.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewComboBoxCell) { dgvProduct.EditMode = DataGridViewEditMode.EditOnEnter; } else { dgvProduct.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2; } if (e.RowIndex != -1 && e.ColumnIndex != -1) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString() != string.Empty) { if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString() != string.Empty) { decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString()); } } } } if (dgvProduct.CurrentRow.Cells["dgvtxtProductId"].Value != null) { if (dgvProduct.CurrentRow.Cells["dgvtxtProductId"].Value.ToString() != string.Empty) { BatchSP spBatch = new BatchSP(); decimal decBatchId = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbBatch"].Value); string strBarcode = spBatch.ProductBatchBarcodeViewByBatchId(decBatchId); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = strBarcode; } } if (e.ColumnIndex == dgvProduct.Columns["dgvcmbRack"].Index) { if (dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value != null) { if (dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value.ToString() != string.Empty) { if (dgvProduct.CurrentRow.Cells["dgvcmbRack"].Value == null || dgvProduct.CurrentRow.Cells["dgvcmbRack"].Value.ToString() == string.Empty) { decGodownId = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value); RackComboFill1(decGodownId, e.RowIndex, e.ColumnIndex); } } } } } CheckInvalidEntries(e); } catch (Exception ex) { MessageBox.Show("DN49:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Grid CellEndEdit for product details fill to curresponding row in grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvPurchaseReturn_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { string strBarcode2 = string.Empty; decimal decBatchId2 = 0; BatchSP spBatch = new BatchSP(); ProductSP spProduct = new ProductSP(); PurchaseDetailsSP SPPurchaseDetails = new PurchaseDetailsSP(); PurchaseReturnDetailsSP SPPurchaseReturnDetails = new PurchaseReturnDetailsSP(); if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtproductName") { if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductName"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductName"].Value.ToString().Trim() != string.Empty) { ProductInfo infoProduct = spProduct.ProductViewByName(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductName"].Value.ToString()); if (infoProduct.ProductCode != null && infoProduct.ProductCode != string.Empty) { FillProductDetails(infoProduct.ProductCode.ToString(), e.RowIndex); } else { StringEmptyDetailsInGrid(); } } else { dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductName"].Value = string.Empty; } } else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtproductCode") { if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value.ToString().Trim() != string.Empty) { ProductInfo infoProduct = spProduct.ProductViewByCode(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value.ToString()); if (infoProduct.ProductName != null && infoProduct.ProductCode != string.Empty) { FillProductDetails(infoProduct.ProductCode.ToString(), e.RowIndex); } else { StringEmptyDetailsInGrid(); } } else { dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value = string.Empty; } } else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtbarcode") { if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value.ToString().Trim() != string.Empty) { string strBarcode = dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value.ToString(); decBatchId = spProduct.BatchIdByPartNoOrBarcode(strBarcode, strBarcode); if (decBatchId > 0) { DataTable dtblBatchName = new DataTable(); dtblBatchName = spProduct.ProductCodeAndBarcodeByBatchId(decBatchId); dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value = dtblBatchName.Rows[0]["productCode"].ToString(); if (dtblBatchName.Rows[0]["barcode"].ToString() != null && dtblBatchName.Rows[0]["barcode"].ToString() != string.Empty) { dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value = dtblBatchName.Rows[0]["barcode"].ToString(); } decimal batchId = spBatch.BatchViewByBarcode(strBarcode); dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = batchId; FillProductDetails(dtblBatchName.Rows[0]["productCode"].ToString(), e.RowIndex); } else { StringEmptyDetailsInGrid(); } } else { dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value = string.Empty; } } if (e.ColumnIndex == dgvPurchaseReturn.Columns["dgvcmbUnit"].Index) { if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvcmbUnit") { if ((dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null) && (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() != string.Empty)) { UnitConversionCalc(e.RowIndex); AmountCalculation("dgvtxtqty", e.RowIndex); } } } if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtqty" && isAmountcalc) { if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value.ToString() != string.Empty && Convert.ToDecimal(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value.ToString()) != 0) { if (cmbInvoiceNo.SelectedValue == null || cmbInvoiceNo.SelectedValue.ToString() == string.Empty) { AmountCalculation("dgvtxtqty", e.RowIndex); } else { DataTable dtbl = SPPurchaseDetails.PurchaseDetailsViewByPurchaseMasterIdWithRemaining(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()), decPurchaseReturnMasterId, decPurchaseReturnVoucherTypeId); if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtPurchaseDetailsId"].Value != null) { if (Convert.ToDecimal(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtPurchaseDetailsId"].Value.ToString()) > 0) { if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value != null) { if (Convert.ToDecimal(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value.ToString()) > Convert.ToDecimal(dtbl.Rows[e.RowIndex]["qty"].ToString())) { dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value = Math.Round(Convert.ToDecimal(dtbl.Rows[e.RowIndex]["qty"].ToString()), PublicVariables._inNoOfDecimalPlaces); } } } } AmountCalculation("dgvtxtqty", e.RowIndex); } } } else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtrate" && isAmountcalc) { if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value.ToString() != string.Empty && Convert.ToDecimal(dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value.ToString()) != 0) { AmountCalculation("dgvtxtrate", e.RowIndex); } } else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvtxtdiscount") { if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtdiscount"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtdiscount"].Value.ToString().Trim() != string.Empty && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtDiscount"].Value.ToString().Trim() != "0") { AmountCalculation("dgvtxtrate", e.RowIndex); } } else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvcmbTax" && isAmountcalc) { if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbTax"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbTax"].Value.ToString() != string.Empty) { AmountCalculation("dgvtxtrate", e.RowIndex); } } else if (dgvPurchaseReturn.Columns[e.ColumnIndex].Name == "dgvcmbBatch") { if (dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty) { decBatchId2 = Convert.ToDecimal(dgvPurchaseReturn.CurrentRow.Cells["dgvcmbBatch"].Value); strBarcode2 = spBatch.ProductBatchBarcodeViewByBatchId(decBatchId2); dgvPurchaseReturn.CurrentRow.Cells["dgvtxtbarcode"].Value = strBarcode2; } } CheckInvalidEntries(e); } catch (Exception ex) { MessageBox.Show("PR:80" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to fill the product details in dataGridView from productCreationPopup /// </summary> /// <param name="productcreation"></param> /// <param name="decproductId"></param> /// <param name="decCurrentRowIndex"></param> public void productDetailsFillFromProductCreation(frmProductCreation productcreation, decimal decproductId, decimal decCurrentRowIndex) { try { decimal decCurrentConversionRate = 0; DataTable dtbl = new DataTable(); UnitConvertionSP SPUnitConversion = new UnitConvertionSP(); BatchSP spBatch = new BatchSP(); ProductInfo infoProductFill = new ProductInfo(); ProductSP spproduct = new ProductSP(); ProductInfo infoProduct = new ProductInfo(); int inI = dgvPurchaseReturn.CurrentRow.Index; if (inI == dgvPurchaseReturn.Rows.Count - 1) { dgvPurchaseReturn.Rows.Add(); } if (decproductId != 0) { infoProduct = spproduct.ProductView(decproductId); SerialNo(); dgvPurchaseReturn.Rows[inI].Cells["dgvtxtproductCode"].Value = infoProduct.ProductCode; dgvPurchaseReturn.Rows[inI].Cells["dgvtxtproductId"].Value = decproductId.ToString(); dgvPurchaseReturn.Rows[inI].Cells["dgvtxtproductName"].Value = infoProduct.ProductName; dgvPurchaseReturn.Rows[inI].Cells["dgvcmbGodown"].Value = infoProduct.GodownId; dgvPurchaseReturn.Rows[inI].Cells["dgvcmbRack"].Value = infoProduct.RackId; UnitComboFill(infoProduct.ProductId, dgvPurchaseReturn.CurrentRow.Index, dgvPurchaseReturn.CurrentRow.Cells["dgvcmbUnit"].ColumnIndex); dgvPurchaseReturn.Rows[inI].Cells["dgvcmbUnit"].Value = infoProduct.UnitId; dgvPurchaseReturn.Rows[inI].Cells["dgvtxtrate"].Value = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces); dgvPurchaseReturn.Rows[inI].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(new UnitConvertionSP().UnitconversionIdViewByUnitIdAndProductId(infoProduct.UnitId, infoProduct.ProductId)); dgvPurchaseReturn.CurrentRow.Cells["dgvtxtConversionRate"].Value = SPUnitConversion.UnitConversionRateByUnitConversionId(Convert.ToDecimal(dgvPurchaseReturn.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString())); BatchComboFill(decproductId, inI, dgvPurchaseReturn.Rows[inI].Cells["dgvcmbBatch"].ColumnIndex); dgvPurchaseReturn.Rows[inI].Cells["dgvcmbBatch"].Value = spBatch.BatchIdViewByProductId(decproductId); RackComboFill(infoProduct.GodownId, inI, dgvPurchaseReturn.Rows[inI].Cells["dgvcmbRack"].ColumnIndex); dgvPurchaseReturn.Rows[inI].Cells["dgvtxtqty"].Value = "0"; dgvPurchaseReturn.Rows[inI].Cells["dgvtxtbarcode"].Value = spBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvPurchaseReturn.Rows[inI].Cells["dgvcmbBatch"].Value.ToString())); dtbl = SPUnitConversion.DGVUnitConvertionRateByUnitId(infoProduct.UnitId, infoProduct.ProductName); dgvPurchaseReturn.Rows[inI].Cells["dgvtxtConversionRate"].Value = dtbl.Rows[0]["conversionRate"].ToString(); decCurrentConversionRate = Convert.ToDecimal(dgvPurchaseReturn.CurrentRow.Cells["dgvtxtConversionRate"].Value.ToString()); AmountCalculation("dgvtxtqty", inI); dgvPurchaseReturn.Rows[inI].Cells["dgvtxtqty"].Selected = true; dgvPurchaseReturn.Rows[inI + 1].Selected = false; } dgvPurchaseReturn.Rows[inI].HeaderCell.Value = "X"; dgvPurchaseReturn.Rows[inI].HeaderCell.Style.ForeColor = Color.Red; } catch (Exception ex) { MessageBox.Show("PR:24" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to fill the details against purchase order /// </summary> public void FillOrderDetails() { BatchSP spbatch = new BatchSP(); PurchaseOrderDetailsSP SPPurchaseOrderDetails = new PurchaseOrderDetailsSP(); StockPostingSP spStockPosting = new StockPostingSP(); ProductSP spproduct = new ProductSP(); try { if (!isEditFill) { isValueChange = false; if (dgvProduct.RowCount > 1) { for (int i = 0; i < dgvProduct.RowCount - 1; i++) { if (dgvProduct.Rows[i].Cells["dgvtxtMaterialReceiptdetailsId"].Value != null && dgvProduct.Rows[i].Cells["dgvtxtMaterialReceiptdetailsId"].Value.ToString() != string.Empty) { lstArrOfRemove.Add(dgvProduct.Rows[i].Cells["dgvtxtMaterialReceiptdetailsId"].Value.ToString()); } } } dgvProduct.Rows.Clear(); isValueChange = true; isDoAfterGridFill = false; DataTable dtblDetails = new DataTable(); if (Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()) == decOrderNoWhileEditMode && btnSave.Text == "Update") { dtblDetails = SPPurchaseOrderDetails.PurchaseOrderDetailsViewByOrderMasterIdWithRemainingForEdit(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decMaterialReceiptId); } else { dtblDetails = SPPurchaseOrderDetails.PurchaseOrderDetailsViewByOrderMasterIdWithRemaining(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decMaterialReceiptId); } int inRowIndex = 0; foreach (DataRow drowDetails in dtblDetails.Rows) { dgvProduct.Rows.Add(); isValueChange = false; isDoAfterGridFill = false; dgvProduct.CurrentCell = dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"]; dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtPurchaseOrderDetailsId"].Value = Convert.ToString(drowDetails.ItemArray[0]); strproductId = drowDetails.ItemArray[2].ToString(); ProductInfo infoproduct = new ProductInfo(); infoproduct = spproduct.ProductView(Convert.ToDecimal(strproductId)); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["productId"].Value = Convert.ToDecimal(strproductId); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductCode"].Value = infoproduct.ProductCode; dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"].Value = infoproduct.ProductName; dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtvouchertypeId"].Value = Convert.ToString(drowDetails.ItemArray[11]); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtvoucherNo"].Value = Convert.ToString(drowDetails.ItemArray[12]); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtinvoiceNo"].Value = Convert.ToString(drowDetails.ItemArray[13]); UnitComboFill(Convert.ToDecimal(strproductId), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ColumnIndex); isValueChange = true; isDoAfterGridFill = true; dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString()); UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(strproductId); foreach (DataRow drUnitByProduct in dtblUnitByProduct.Rows) { if (dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString()) { dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString()); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString()); } } isValueChange = false; isDoAfterGridFill = false; BatchComboFill(Convert.ToDecimal(strproductId), dgvProduct.Rows.Count - 2, Convert.ToInt32(dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].ColumnIndex)); decimal decBatch = spStockPosting.BatchViewByProductId(Convert.ToDecimal(strproductId)); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].Value = decBatch; string strBarcode = spbatch.ProductBatchBarcodeViewByBatchId(decBatch); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].Value = strBarcode; DGVGodownComboFill(); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(1); RackComboFill(1, dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvCmbRack"].ColumnIndex); DataTable dtbl = new DataTable(); RackSP spRack = new RackSP(); dtbl = spRack.RackNamesCorrespondingToGodownId(1); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvCmbRack"].Value = Convert.ToDecimal(dtbl.Rows[0]["rackId"].ToString()); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtQty"].Value = Convert.ToString(drowDetails.ItemArray[3]); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtRate"].Value = Convert.ToString(drowDetails.ItemArray[4]); decCurrentRate = Convert.ToDecimal(drowDetails.ItemArray[4].ToString()); decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value.ToString()); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtAmount"].Value = Convert.ToString(drowDetails.ItemArray[6]); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductCode"].ReadOnly = true; dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"].ReadOnly = true; dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].ReadOnly = true; dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtAmount"].ReadOnly = true; dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["inRowIndex"].Value = Convert.ToString(drowDetails["extra1"]); if (cmbVoucherType.Text != "NA") { dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true; } dgvProduct.Rows[dgvProduct.Rows.Count - 2].HeaderCell.Value = string.Empty; int intIndex = 0; int.TryParse(Convert.ToString(drowDetails["extra1"]), out intIndex); if (inMaxCount < intIndex) inMaxCount = intIndex; inRowIndex++; NewAmountCalculation(string.Empty, dgvProduct.Rows.Count - 2); isValueChange = true; isDoAfterGridFill = true; dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true; } for (int i = inRowIndex; i < dgvProduct.Rows.Count; ++i) dgvProduct["inRowIndex", i].Value = Convert.ToString(GetNextinRowIndex()); SerialNo(); CalculateTotalAmount(); } } catch (Exception ex) { MessageBox.Show("MR39:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// enables the enter key navigation for Cell EndEdit /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProduct_CellEndEdit(object sender, DataGridViewCellEventArgs e) { decimal decCurQty = 0; decimal decNewAmount = 0; try { // CheckInvalidEntries(e); UnitConvertionSP spUnitConvertion = new UnitConvertionSP(); if (isValueChange) { if (isDoCellValueChange) { if (dgvProduct.Rows.Count > 0) { if (e.ColumnIndex == dgvProduct.Columns["dgvcmbRack"].Index) { if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbGodown") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value != null) { RackComboFill(Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value.ToString()), dgvProduct, e.RowIndex); } } } if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbBatch") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null) { BatchSP SpBatch = new BatchSP(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = SpBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value)); } } if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtproductId"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtproductId"].Value.ToString() != string.Empty) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString() != string.Empty) { decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString()); } } } } //---------------while changing Qty,corresponding change in amount---- if (dgvProduct.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvtxtQty" && isAmountcalc) { if (cmbMaterialReceiptNo.SelectedValue == null || cmbMaterialReceiptNo.SelectedValue.ToString() == string.Empty) { NewAmountCalculation("dgvtxtQty", e.RowIndex); } else { DataTable dtblReceiptDetails = spMaterialReceiptDetails.ShowMaterialReceiptDetailsViewbyMaterialReceiptDetailsIdWithPending(Convert.ToDecimal(cmbMaterialReceiptNo.SelectedValue.ToString()), decRejectionOutId); if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value != null) { DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = spUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtproductId"].Value.ToString()); foreach (DataRow drdtbl in dtblReceiptDetails.Rows) { foreach (DataRow drUnitviewall in dtblUnitByProduct.Rows) { if (drdtbl.ItemArray[6].ToString() == drUnitviewall.ItemArray[2].ToString())//Checking UnitconversionId { decimal decQty = Convert.ToDecimal(drdtbl.ItemArray[3].ToString()); decimal decConRate = Convert.ToDecimal(drUnitviewall.ItemArray[3].ToString()); decimal decCurConRateInGrid = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtconversionRate"].Value.ToString()); decOldQty = (decQty / decConRate) * decCurConRateInGrid; decOldQty = Math.Round(decOldQty, PublicVariables._inNoOfDecimalPlaces); decCurrQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()); if (decCurrQty > decOldQty) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = decOldQty.ToString(); } } } } // //decCurrQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()); //decOldQty = Convert.ToDecimal(dtblReceiptDetails.Rows[e.RowIndex].ItemArray[3].ToString()); if (decCurrQty > decOldQty) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = decOldQty.ToString(); } } else { dgvProduct.Focus(); } NewAmountCalculation("dgvtxtQty", e.RowIndex); TotalAmount(); } } //if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit") //{ // if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtproductId"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtproductId"].Value.ToString() != string.Empty) // { // if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() != string.Empty) // { // DataTable dtblUnitByProduct = new DataTable(); // dtblUnitByProduct = spUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtproductId"].Value.ToString()); // 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 (isDoAfterGridFill) // { // decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtconversionRate"].Value.ToString()); // decCurQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()); // decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate; // //dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate); // dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, 2); // decNewAmount = (decCurrentRate * decCurQty * decCurrentConversionRate) / decNewConversionRate; // dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = Math.Round(decNewAmount, 2); // TotalAmount(); // txtTotalAmount.Text = Math.Round(decNewRate, 2).ToString(); // } // } // } // if (decCurrQty > decOldQty) // { // dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = decOldQty.ToString(); // } // } // } //} else if (dgvProduct.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvtxtRate" && isAmountcalc) { NewAmountCalculation("dgvtxtRate", e.RowIndex); TotalAmount(); } else if (dgvProduct.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvtxtAmount" && isAmountcalc) { TotalAmount(); } } } } } catch (Exception ex) { MessageBox.Show("RO62:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to fill details while return from Product creation when creating new Product /// </summary> /// <param name="decProductId"></param> public void ReturnFromProductCreation(decimal decProductId) { ProductInfo infoProduct = new ProductInfo(); ProductSP spProduct = new ProductSP(); BatchSP spBatch = new BatchSP(); DataTable dtbl = new DataTable(); UnitConvertionSP spUnitConversion = new UnitConvertionSP(); try { this.Enabled = true; this.BringToFront(); if (decProductId != 0) { infoProduct = spProduct.ProductView(decProductId); dgvSalesOrder.CurrentRow.Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode.ToString(); dgvSalesOrder.CurrentRow.Cells["dgvtxtProductId"].Value = decProductId.ToString(); dgvSalesOrder.CurrentRow.Cells["dgvtxtProductName"].Value = infoProduct.ProductName; dgvSalesOrder.CurrentRow.Cells["dgvtxtRate"].Value = infoProduct.SalesRate.ToString(); UnitComboFill(decProductId, dgvSalesOrder.CurrentRow.Index, dgvSalesOrder.CurrentRow.Cells["dgvcmbUnit"].ColumnIndex); dgvSalesOrder.CurrentRow.Cells["dgvcmbUnit"].Value = infoProduct.UnitId; BatchComboFill(decProductId, dgvSalesOrder.CurrentRow.Index, dgvSalesOrder.CurrentRow.Cells["dgvcmbBatch"].ColumnIndex); dgvSalesOrder.CurrentRow.Cells["dgvcmbBatch"].Value = spBatch.BatchIdViewByProductId(decProductId); dgvSalesOrder.CurrentRow.Cells["dgvtxtBarcode"].Value = spBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvSalesOrder.CurrentRow.Cells["dgvcmbBatch"].Value.ToString())); dtbl = spUnitConversion.DGVUnitConvertionRateByUnitId(infoProduct.UnitId, infoProduct.ProductName); dgvSalesOrder.CurrentRow.Cells["dgvtxtUnitConversionId"].Value = dtbl.Rows[0]["unitconversionId"].ToString(); dgvSalesOrder.CurrentRow.Cells["dgvtxtConversionRate"].Value = dtbl.Rows[0]["conversionRate"].ToString(); decCurrentConversionRate = Convert.ToDecimal(dgvSalesOrder.CurrentRow.Cells["dgvtxtConversionRate"].Value.ToString()); decCurrentRate = Convert.ToDecimal(dgvSalesOrder.CurrentRow.Cells["dgvtxtRate"].Value.ToString()); AmountCalculation("dgvtxtQty", dgvSalesOrder.CurrentRow.Index); TotalAmountCalculation(); } } catch (Exception ex) { MessageBox.Show("SO24:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Sales grid cell leave event to calculate the basic functions and calculation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvSalesInvoice_CellLeave(object sender, DataGridViewCellEventArgs e) { if (IsSetGridValueChange == true) { BatchSP spBatch = new BatchSP(); UnitConvertionSP spUnitConversion = new UnitConvertionSP(); DataTable dtblUnitConversion = new DataTable(); decimal decBatchId = 0; string strBarcode = string.Empty; try { if (e.RowIndex != -1 && e.ColumnIndex != -1) { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceProductName"].Value != null) { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceProductName"].Value.ToString() != string.Empty) { if (dgvSalesInvoice.RowCount > 1) { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value != null) { try { if (decimal.Parse(dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceDeliveryNoteDetailsId"].Value.ToString()) > 0) { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceQty"].Value != null) { if (decimal.Parse(dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceQty"].Value.ToString()) > decimal.Parse(dtblDeliveryNoteDetails.Rows[e.RowIndex]["qty"].ToString())) { dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceQty"].Value = dtblDeliveryNoteDetails.Rows[e.RowIndex]["qty"].ToString(); if (decDeliveryNoteQty < decimal.Parse(dtblDeliveryNoteDetails.Rows[e.RowIndex]["qty"].ToString())) { dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceQty"].Value = decDeliveryNoteQty; decDeliveryNoteQty = 0; } } } } } catch (Exception) { } } if (dgvSalesInvoice.Columns[e.ColumnIndex].Name == "dgvtxtSalesInvoicembUnitName") { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoicembUnitName"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoicembUnitName"].Value.ToString() != string.Empty) { UnitConversionCalc(e.RowIndex); } } if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceDiscountPercentage"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceDiscountPercentage"].Value.ToString() != string.Empty || dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceDiscountAmount"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceDiscountAmount"].Value.ToString() != string.Empty || dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceQty"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceQty"].Value.ToString() != string.Empty || dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceProductName"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceProductName"].Value.ToString() != string.Empty || dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceRate"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceRate"].Value.ToString() != string.Empty || dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceProductName"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceProductName"].Value.ToString() != string.Empty || dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceGrossValue"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceGrossValue"].Value.ToString() != string.Empty || dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceQty"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceQty"].Value.ToString() != string.Empty) { DiscountCalculation(e.RowIndex, e.ColumnIndex); } if (dgvSalesInvoice.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvcmbSalesInvoiceTaxName" || dgvSalesInvoice.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvtxtSalesInvoiceGrossValue" || dgvSalesInvoice.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvtxtSalesInvoiceDiscountPercentage") { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvcmbSalesInvoiceTaxName"].Visible) { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvcmbSalesInvoiceTaxName"].Value != null && (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceNetAmount"].Value != null || dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceGrossValue"].Value != null)) { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvcmbSalesInvoiceTaxName"].Value.ToString() != string.Empty && (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceNetAmount"].Value.ToString() != string.Empty || dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceGrossValue"].Value.ToString() != string.Empty)) { { taxAndGridTotalAmountCalculation(e.RowIndex); } } } } else { taxAndGridTotalAmountCalculation(e.RowIndex); } } if (dgvSalesInvoice.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvtxtSalesInvoiceRate" || dgvSalesInvoice.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvtxtSalesInvoiceQty") { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceQty"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceRate"].Value != null) { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceQty"].Value.ToString() != string.Empty && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceRate"].Value.ToString() != string.Empty) { { GrossValueCalculation(e.RowIndex); } } } } } if (e.ColumnIndex == dgvSalesInvoice.Columns["dgvcmbSalesInvoiceBatch"].Index) { if (dgvSalesInvoice.CurrentRow.Cells["dgvcmbSalesInvoiceBatch"].Value != null) { if (dgvSalesInvoice.CurrentRow.Cells["dgvcmbSalesInvoiceBatch"].Value.ToString() != string.Empty && dgvSalesInvoice.CurrentRow.Cells["dgvcmbSalesInvoiceBatch"].Value.ToString() != "0") { decBatchId = Convert.ToDecimal(dgvSalesInvoice.CurrentRow.Cells["dgvcmbSalesInvoiceBatch"].Value.ToString()); strBarcode = spBatch.ProductBatchBarcodeViewByBatchId(decBatchId); dgvSalesInvoice.CurrentRow.Cells["dgvtxtSalesInvoiceBarcode"].Value = strBarcode; if (dgvSalesInvoice.CurrentRow.Cells["dgvtxtSalesInvoiceProductId"].Value != null) // here get product rate for sales(standard rate) { getProductRate(e.RowIndex, Convert.ToDecimal(dgvSalesInvoice.CurrentRow.Cells["dgvtxtSalesInvoiceProductId"].Value.ToString()), decBatchId); UnitConversionCalc(e.RowIndex); } } } } } } if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceProductId"].Value != null && dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceProductId"].Value.ToString() != string.Empty) { if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceConversionRate"].Value != null) { decCurrentConversionRate = Convert.ToDecimal(dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceConversionRate"].Value.ToString()); } if (dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceRate"].Value != null) { decCurrentRate = Convert.ToDecimal(dgvSalesInvoice.Rows[e.RowIndex].Cells["dgvtxtSalesInvoiceRate"].Value.ToString()); } } CheckInvalidEntries(e); SiGridTotalAmountCalculation(); CalculateAmountFromGrid(e.RowIndex, e, e.ColumnIndex); } } catch (Exception ex) { MessageBox.Show("SI: 105" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// <summary> /// On leave from each cell of dgvProductDetails /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProductDetails_CellLeave(object sender, DataGridViewCellEventArgs e) { string strBarcode = string.Empty; decimal decDiscountPercent = 0; decimal decDiscount = 0; decimal decGrossValue = 0; try { BatchSP spBatch = new BatchSP(); if (e.ColumnIndex > -1 && e.RowIndex > -1) { if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value != null) { if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString() != string.Empty && dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString() != "0") { if (e.ColumnIndex == dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtQuantity"].ColumnIndex) { if (dgvProductDetails.RowCount > 1) { try { MaterialReceiptDetailsSP spMaterialReceiptDetails = new MaterialReceiptDetailsSP(); decimal decMaterialReceiptMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()); dtblMeterialReceiptQty = spMaterialReceiptDetails.MaterialReceiptDetailsViewByMaterialReceiptMasterIdWithRemainingByNotInCurrPI (decMaterialReceiptMasterId, decPurchaseMasterId, decPurchaseInvoiceVoucherTypeId); if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtMaterialReceiptDetailsId"].Value != null) { if (decimal.Parse(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtMaterialReceiptDetailsId"].Value.ToString()) > 0) { if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value != null) { if (decimal.Parse(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value.ToString()) > decimal.Parse(dtblMeterialReceiptQty.Rows[e.RowIndex]["qty"].ToString())) { dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value = dtblMeterialReceiptQty.Rows[e.RowIndex]["qty"].ToString(); if (decMeterialReceiptQty < decimal.Parse(dtblMeterialReceiptQty.Rows[e.RowIndex]["qty"].ToString())) { dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value = decMeterialReceiptQty; decMeterialReceiptQty = 0; } } } } } } catch (Exception) { } } } else if (e.ColumnIndex == dgvProductDetails.Columns["dgvcmbBatch"].Index) { if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvProductDetails.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty) { decimal decBatchId = Convert.ToDecimal(dgvProductDetails.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value); strBarcode = spBatch.ProductBatchBarcodeViewByBatchId(decBatchId); dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = strBarcode; } } else if (e.ColumnIndex == dgvProductDetails.Columns["dgvtxtGrossValue"].Index) { dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscountPercent"].Value = 0; dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscount"].Value = 0; } else if (e.ColumnIndex == dgvProductDetails.Columns["dgvtxtDiscountPercent"].Index) { if (dgvProductDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) { if (dgvProductDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() != string.Empty) { if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value != null) { if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value.ToString() != string.Empty) { decDiscountPercent = Convert.ToDecimal(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscountPercent"].Value.ToString()); decGrossValue = Convert.ToDecimal(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value.ToString()); if (decGrossValue > 0) { decDiscount = decGrossValue * decDiscountPercent / 100; } dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscount"].Value = Math.Round(decDiscount, PublicVariables._inNoOfDecimalPlaces); } } } } } else if (e.ColumnIndex == dgvProductDetails.Columns["dgvtxtDiscount"].Index) { if (dgvProductDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) { if (dgvProductDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() != string.Empty) { if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value != null) { if (dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value.ToString() != string.Empty) { decDiscount = Convert.ToDecimal(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscount"].Value.ToString()); decGrossValue = Convert.ToDecimal(dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtGrossValue"].Value.ToString()); if (decGrossValue > 0) { decDiscountPercent = decDiscount * 100 / decGrossValue; } dgvProductDetails.Rows[e.RowIndex].Cells["dgvtxtDiscountPercent"].Value = Math.Round(decDiscountPercent, PublicVariables._inNoOfDecimalPlaces); } } } } } } } SerialNo(); } CheckInvalidEntries(e); } catch (Exception ex) { MessageBox.Show("PI85:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// doing the unit conversion in cell enter /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvSalesOrder_CellEnter(object sender, DataGridViewCellEventArgs e) { SalesOrderMasterInfo infoSalesOrderMaster = new SalesOrderMasterInfo(); SalesOrderMasterSP spSalesOrderMaster = new SalesOrderMasterSP(); // decimal decQty =0; try { if (dgvSalesOrder.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewComboBoxCell) { dgvSalesOrder.EditMode = DataGridViewEditMode.EditOnEnter; } else { dgvSalesOrder.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2; } if (e.RowIndex != -1 && e.ColumnIndex != -1) { if (dgvSalesOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value != null && dgvSalesOrder.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString() != string.Empty) { if (dgvSalesOrder.Columns[e.ColumnIndex].Name == "dgvcmbUnit") { if (dgvSalesOrder.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvSalesOrder.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty) { if (dgvSalesOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value != null && dgvSalesOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString() != string.Empty) { decCurrentConversionRate = Convert.ToDecimal(dgvSalesOrder.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); decCurrentRate = Convert.ToDecimal(dgvSalesOrder.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString()); } } } } if (dgvSalesOrder.CurrentRow.Cells["dgvtxtProductId"].Value != null) { if (dgvSalesOrder.CurrentRow.Cells["dgvtxtProductId"].Value.ToString() != string.Empty) { BatchSP spBatch = new BatchSP(); decimal decBatchId = Convert.ToDecimal(dgvSalesOrder.CurrentRow.Cells["dgvcmbBatch"].Value); string strBarcode = spBatch.ProductBatchBarcodeViewByBatchId(decBatchId); dgvSalesOrder.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = strBarcode; } } } CheckInvalidEntries(e); } catch (Exception ex) { MessageBox.Show("SO75" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// On cellLeave of dgvProduct /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProduct_CellLeave(object sender, DataGridViewCellEventArgs e) { BatchSP spbatch = new BatchSP(); PurchaseOrderMasterSP SPPurchaseOrderMaster = new PurchaseOrderMasterSP(); StockPostingSP spStockPosting = new StockPostingSP(); try { if (isValueChange) { string strBarcode = string.Empty; string strProductCode = string.Empty; if (e.RowIndex > -1 && e.ColumnIndex > -1) { CheckInvalidEntries(e); if (e.ColumnIndex == dgvProduct.Columns["dgvcmbBatch"].Index) { if (dgvProduct.Rows[e.RowIndex].Cells["productId"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["productId"].Value.ToString() != string.Empty) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value.ToString() != string.Empty) { if (Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value) != string.Empty && Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value) != "0") { decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value); strProductCode = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString(); strBarcode = spbatch.ProductBatchBarcodeViewByBatchId(decBatchId); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = strBarcode; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = strProductCode; } } } } 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) { UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value.ToString()); 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 (isDoAfterGridFill) { 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, 2); NewAmountCalculation("dgvtxtQty", e.RowIndex); CalculateTotalAmount(); } } } CheckInvalidEntries(e); } } else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbGodown") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value.ToString() != string.Empty) { decGodownId = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value); RackComboFill(decGodownId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].ColumnIndex); DataTable dtbl = new DataTable(); RackSP spRack = new RackSP(); dtbl = spRack.RackNamesCorrespondingToGodownId(decGodownId); dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = Convert.ToDecimal(dtbl.Rows[0]["rackId"].ToString()); } CheckInvalidEntries(e); } else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvCmbCurrency" && isAmountcalc) { ExchangeRateSP spExchangeRate = new ExchangeRateSP(); if (dgvProduct.Rows[e.RowIndex].Cells["dgvCmbCurrency"].Value != null && Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvCmbCurrency"].Value) != string.Empty) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtExchangeRate"].Value = spExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvCmbCurrency"].Value))); } else { dgvProduct.Rows[e.RowIndex].Cells["dgvCmbCurrency"].Value = SPPurchaseOrderMaster.ExchangeRateIdByCurrencyId(PublicVariables._decCurrencyId); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtExchangeRate"].Value = spExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(Convert.ToString(dgvProduct.Rows[e.RowIndex].Cells["dgvCmbCurrency"].Value))); } CheckInvalidEntries(e); } //----------while changing Qty,corresponding change in amount-------- else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQty" && isAmountcalc) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value != null) { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString() != string.Empty) { NewAmountCalculation("dgvtxtQty", e.RowIndex); CalculateTotalAmount(); } } CheckInvalidEntries(e); } //---------------while changing Qty,corresponding change in amount---- else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtRate" && isAmountcalc) { NewAmountCalculation("dgvtxtRate", e.RowIndex); CalculateTotalAmount(); CheckInvalidEntries(e); } //----while changing amount ,corresponding chnage in total amount------- else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtAmount" && isAmountcalc) { if (cmbcurrency.Text != string.Empty) { CalculateTotalAmount(); } } //} } } CheckInvalidEntries(e); } catch (Exception ex) { MessageBox.Show("MR72:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to fill the product details in dataGridView from productCreationPopup /// </summary> /// <param name="productcreation"></param> /// <param name="decproductId"></param> /// <param name="decCurrentRowIndex"></param> public void productDetailsFillFromProductCreation(frmProductCreation productcreation, decimal decproductId, decimal decCurrentRowIndex) { try { decimal decCurrentConversionRate = 0; DataTable dtbl = new DataTable(); UnitConvertionSP SPUnitConversion = new UnitConvertionSP(); BatchSP spBatch = new BatchSP(); ProductInfo infoProductFill = new ProductInfo(); ProductSP spproduct = new ProductSP(); ProductInfo infoProduct = new ProductInfo(); int inI = dgvProduct.CurrentRow.Index; if (inI == dgvProduct.Rows.Count - 1) { dgvProduct.Rows.Add(); } if (decproductId != 0) { infoProduct = spproduct.ProductView(decproductId); SerialNo(); dgvProduct.Rows[inI].Cells["dgvtxtproductCode"].Value = infoProduct.ProductCode; dgvProduct.Rows[inI].Cells["productId"].Value = decproductId.ToString(); dgvProduct.Rows[inI].Cells["dgvtxtProductName"].Value = infoProduct.ProductName; dgvProduct.Rows[inI].Cells["dgvcmbGodown"].Value = infoProduct.GodownId; dgvProduct.Rows[inI].Cells["dgvCmbRack"].Value = infoProduct.RackId; UnitComboFill(decproductId, inI, dgvProduct.Rows[inI].Cells["dgvcmbUnit"].ColumnIndex); dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value = infoProduct.UnitId; UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[inI].Cells["productId"].Value.ToString()); //UnitComboFill(infoProduct.ProductId, dgvProduct.CurrentRow.Index, dgvProduct.CurrentRow.Cells["dgvcmbUnit"].ColumnIndex); //dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value = infoProduct.UnitId; dgvProduct.Rows[inI].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces); dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(new UnitConvertionSP().UnitconversionIdViewByUnitIdAndProductId(infoProduct.UnitId, infoProduct.ProductId)); dgvProduct.CurrentRow.Cells["dgvtxtConversionRate"].Value = SPUnitConversion.UnitConversionRateByUnitConversionId(Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString())); BatchComboFill(decproductId, inI, dgvProduct.Rows[inI].Cells["dgvcmbBatch"].ColumnIndex); dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value = spBatch.BatchIdViewByProductId(decproductId); RackComboFill(infoProduct.GodownId, inI, dgvProduct.Rows[inI].Cells["dgvCmbRack"].ColumnIndex); dgvProduct.Rows[inI].Cells["dgvtxtBarcode"].Value = spBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvProduct.Rows[inI].Cells["dgvcmbBatch"].Value.ToString())); dtbl = SPUnitConversion.DGVUnitConvertionRateByUnitId(infoProduct.UnitId, infoProduct.ProductName); dgvProduct.Rows[inI].Cells["dgvtxtConversionRate"].Value = dtbl.Rows[0]["conversionRate"].ToString(); decCurrentConversionRate = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvtxtConversionRate"].Value.ToString()); NewAmountCalculation("dgvtxtQty", inI); CalculateTotalAmount(); } } catch (Exception ex) { MessageBox.Show("MR6:new" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// On cellEndEdit of grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProduct_CellEndEdit(object sender, DataGridViewCellEventArgs e) { ProductInfo infoProduct = new ProductInfo(); BatchSP spbatch = new BatchSP(); ProductSP spproduct = new ProductSP(); StockPostingSP spStockPosting = new StockPostingSP(); try { isDoAfterGridFill = false; isValueChange = false; if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtProductName") { string strProductName = string.Empty; if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString() != string.Empty) { strProductName = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value.ToString(); } infoProduct = spproduct.ProductViewByName(strProductName); if (infoProduct.ProductCode != null && infoProduct.ProductCode != string.Empty) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = infoProduct.ProductCode; decimal decproductId = infoProduct.ProductId; dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = infoProduct.ProductId; BatchComboFill(decproductId, e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex)); decimal decBatchId = spStockPosting.BatchViewByProductId(decproductId); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = decBatchId; decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value); string strBarcode = spbatch.ProductBatchBarcodeViewByBatchId(decBatchId); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = strBarcode; dtbl = spproduct.ProductDetailsCoreespondingToBarcode(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString()); if (dtbl.Rows.Count > 0) { foreach (DataRow RowDetails in dtbl.Rows) { isValueChange = false; dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = RowDetails["productId"].ToString(); decimal decProductId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value); BatchComboFill(decProductId, e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex)); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(RowDetails["batchId"].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = RowDetails["productCode"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = RowDetails["productName"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(RowDetails["godownId"].ToString()); decGodownId = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value); RackComboFill(decGodownId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].ColumnIndex); dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = Convert.ToDecimal(RowDetails["rackId"].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(RowDetails["purchaseRate"].ToString()), PublicVariables._inNoOfDecimalPlaces).ToString(); UnitComboFill(decProductId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].ColumnIndex); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(RowDetails["unitId"].ToString()); UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value.ToString()); 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()); } } decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString()); decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); NewAmountCalculation("dgvtxtQty", e.RowIndex); CalculateTotalAmount(); } } } else { isValueChange = false; dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].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["dgvtxtRate"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].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["dgvcmbGodown"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty; isValueChange = true; } } if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtProductCode") { string strPrdCode = string.Empty; if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty) { strPrdCode = dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString(); } isDoAfterGridFill = false; infoProduct = spproduct.ProductViewByCode(strPrdCode); if (infoProduct.ProductId != 0) { decimal decproductId = infoProduct.ProductId; dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = infoProduct.ProductId; BatchComboFill(decproductId, e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex)); decimal decBatchId = spStockPosting.BatchViewByProductId(decproductId); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = decBatchId; decBatchId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value); string strBarcode = spbatch.ProductBatchBarcodeViewByBatchId(decBatchId); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = strBarcode; dtbl = spproduct.ProductDetailsCoreespondingToBarcode(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value.ToString()); if (dtbl.Rows.Count > 0) { foreach (DataRow RowDetails in dtbl.Rows) { isValueChange = false; dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = RowDetails["productId"].ToString(); decimal decProductId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value); BatchComboFill(decProductId, e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex)); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(RowDetails["batchId"].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = RowDetails["productCode"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = RowDetails["productName"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(RowDetails["godownId"].ToString()); decGodownId = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value); RackComboFill(decGodownId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].ColumnIndex); dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = Convert.ToDecimal(RowDetails["rackId"].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(RowDetails["purchaseRate"].ToString()), PublicVariables._inNoOfDecimalPlaces).ToString(); UnitComboFill(decProductId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].ColumnIndex); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(RowDetails["unitId"].ToString()); UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value.ToString()); 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()); } } decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString()); decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); NewAmountCalculation("dgvtxtQty", e.RowIndex); CalculateTotalAmount(); } } } else { isValueChange = false; dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].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["dgvtxtRate"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].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["dgvcmbGodown"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty; isValueChange = true; } } if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtBarcode") { string strBCode = string.Empty; DataTable dtbl = new DataTable(); 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(); } isDoAfterGridFill = false; dtbl = spproduct.ProductDetailsCoreespondingToBarcode(strBCode); if (dtbl.Rows.Count > 0) { foreach (DataRow RowDetails in dtbl.Rows) { isValueChange = false; dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = RowDetails["productId"].ToString(); decimal decProductId = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value); BatchComboFill(decProductId, e.RowIndex, Convert.ToInt32(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].ColumnIndex)); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(RowDetails["batchId"].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = RowDetails["productCode"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductName"].Value = RowDetails["productName"].ToString(); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(RowDetails["godownId"].ToString()); decGodownId = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvcmbGodown"].Value); RackComboFill(decGodownId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].ColumnIndex); dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = Convert.ToDecimal(RowDetails["rackId"].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(Convert.ToDecimal(RowDetails["purchaseRate"].ToString()), PublicVariables._inNoOfDecimalPlaces).ToString(); UnitComboFill(decProductId, e.RowIndex, dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].ColumnIndex); dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(RowDetails["unitId"].ToString()); UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["productId"].Value.ToString()); 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()); } } decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString()); decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); NewAmountCalculation("dgvtxtQty", e.RowIndex); CalculateTotalAmount(); } } else { isValueChange = false; dgvProduct.Rows[e.RowIndex].Cells["productId"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].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["dgvtxtRate"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].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["dgvcmbGodown"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvCmbRack"].Value = string.Empty; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty; isValueChange = true; } } CheckInvalidEntries(e); isDoAfterGridFill = true; isValueChange = true; } catch (Exception ex) { MessageBox.Show("MR68:" + 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; DataTable dtbl = new DataTable(); UnitConvertionSP spUnitConversion = new UnitConvertionSP(); ProductInfo infoProduct = new ProductInfo(); BatchSP spBatch = new BatchSP(); infoProduct = new ProductSP().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 = spBatch.BatchIdViewByProductId(decproductId); dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtBarcode"].Value = spBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvcmbBatch"].Value.ToString())); dtbl = spUnitConversion.DGVUnitConvertionRateByUnitId(infoProduct.UnitId, infoProduct.ProductName); dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtUnitConversionId"].Value = dtbl.Rows[0]["unitconversionId"].ToString(); dgvProduct.Rows[Convert.ToInt32(decCurrentRowIndex.ToString())].Cells["dgvtxtConversionRate"].Value = dtbl.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); } }
/// <summary> /// Doing the basic calculations in grid cell value change /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProduct_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (isDoCellValueChange) { decimal decOldQty = 0; decimal decCurQty = 0; decimal decNewAmount = 0; if (e.RowIndex != -1 && e.ColumnIndex != -1) { if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbGodown") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value != null) { DGVRackComboFill(Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value.ToString()), dgvProduct, e.RowIndex); } } if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbBatch") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null) { ProductSP SpProduct = new ProductSP(); decimal decRate = SpProduct.SalesInvoiceProductRateForSales(Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value), dtpDate.Value, Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value), Convert.ToDecimal(cmbPricingLevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decRate / Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces); BatchSP SpBatch = new BatchSP(); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = SpBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value)); } } //------------Hided when asked Rejection In not to need unit conversion process ------------------- //if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit") //{ // if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtproductId"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtproductId"].Value.ToString() != string.Empty) // { // if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty) // { // if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString() != string.Empty) // { // decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); // decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString()); // } // } // } //} if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQuantity") { DeliveryNoteDetailsInfo infodeliverynotedetails = new DeliveryNoteDetailsInfo(); DeliveryNoteDetailsSP spdeliverynotedetails = new DeliveryNoteDetailsSP(); DataTable dtbl = spdeliverynotedetails.DeliveryNoteDetailsViewByDeliveryNoteMasterIdWithPending(Convert.ToDecimal(cmbDeliveryNoteNo.SelectedValue.ToString()), decRejectionInIdToEdit); if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value != null) { DataTable dtblUnitByProduct = new DataTable(); UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString()); foreach (DataRow drdtbl in dtbl.Rows) { foreach (DataRow drUnitviewall in dtblUnitByProduct.Rows) { if (drdtbl["unitConversionId"].ToString() == drUnitviewall["unitConversionId"].ToString()) { decimal decCurrentQty = Convert.ToDecimal(drdtbl.ItemArray[3].ToString()); decimal decConRateToDlryNteDtls = Convert.ToDecimal(drUnitviewall.ItemArray[3].ToString()); decimal decCurConRateInGrid = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); decOldQty = (decCurrentQty / decConRateToDlryNteDtls) * decCurConRateInGrid; decOldQty = Math.Round(decOldQty, PublicVariables._inNoOfDecimalPlaces); decCurQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value.ToString()); } } } if (decCurQty > decOldQty) { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value = decOldQty; } else if (decCurQty <= decOldQty) { decimal decrate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = Math.Round(decrate * decCurQty, PublicVariables._inNoOfDecimalPlaces); CalcTotalAmt(); } } } if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null) { DataTable dtblUnitByProduct = new DataTable(); UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString()); 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[2].ToString()); dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString()); if (isDoAfterGridFill) { decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString()); decCurQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value.ToString()); decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate); decNewAmount = (decCurrentRate * decCurQty * decCurrentConversionRate) / decNewConversionRate; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = Math.Round(decNewAmount); txtTotalAmount.Text = Math.Round(decNewRate, 2).ToString(); CalcTotalAmt(); } } } } } } } } catch (Exception ex) { MessageBox.Show("RI:41 " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> ///Function for ReturnFromProductCreationPopup /// </summary> public void ReturnFromProductCreation(decimal decProductId) { ProductInfo infoProduct = new ProductInfo(); ProductSP spProduct = new ProductSP(); BatchSP spBatch = new BatchSP(); DataTable dtbl = new DataTable(); UnitConvertionSP spUnitConversion = new UnitConvertionSP(); try { this.Enabled = true; this.BringToFront(); int inI = dgvProduct.CurrentRow.Index; if (inI == dgvProduct.Rows.Count - 1) { dgvProduct.Rows.Add(); } if (decProductId != 0) { infoProduct = spProduct.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 = spBatch.BatchIdViewByProductId(decProductId); dgvProduct.Rows[inI].Cells["dgvtxtBarcode"].Value = spBatch.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; dtbl = spUnitConversion.DGVUnitConvertionRateByUnitId(infoProduct.UnitId, infoProduct.ProductName); dgvProduct.Rows[inI].Cells["dgvtxtUnitConversionId"].Value = dtbl.Rows[0]["unitconversionId"].ToString(); dgvProduct.Rows[inI].Cells["dgvtxtConversionRate"].Value = dtbl.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); } }
private void dgvPhysicalStock_CellLeave(object sender, DataGridViewCellEventArgs e) { if (!isFromEditMode) { try { string strBarcode = string.Empty; string strProductCode = string.Empty; ProductInfo infoProduct = new ProductInfo(); ProductSP spProduct = new ProductSP(); BatchSP spBatch = new BatchSP(); PhysicalStockMasterSP spPhysicalStockMaster = new PhysicalStockMasterSP(); 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 = spBatch.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> /// dgvProduction grid cell valuechange event to calculate the basic functions and calculation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvProduction_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (IsSetGridValueChange) { if (e.RowIndex != -1 && e.ColumnIndex != -1) { if (dgvProduction.RowCount > 1) { if (dgvProduction.Columns[e.ColumnIndex].Name == "dgvcmbProductionunitId") { if (dgvProduction.Rows[e.RowIndex].Cells["dgvcmbProductionunitId"].Value != null && dgvProduction.Rows[e.RowIndex].Cells["dgvcmbProductionunitId"].Value.ToString() != string.Empty) { UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduction.Rows[e.RowIndex].Cells["dgvtxtProductionProductId"].Value.ToString()); foreach (DataRow drUnitByProduct in dtblUnitByProduct.Rows) { if (dgvProduction.Rows[e.RowIndex].Cells["dgvcmbProductionunitId"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString()) { dgvProduction.Rows[e.RowIndex].Cells["dgvtxtProductionunitConversionId"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[2].ToString()); dgvProduction.Rows[e.RowIndex].Cells["dgvtxtProductionConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString()); decimal decNewConversionRate = Convert.ToDecimal(dgvProduction.Rows[e.RowIndex].Cells["dgvtxtProductionConversionRate"].Value.ToString()); decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate; dgvProduction.Rows[e.RowIndex].Cells["dgvtxtProductionRate"].Value = Math.Round(decNewRate, 2); } } TotalAmountCalculationProduction("", e.RowIndex); } } if (e.ColumnIndex == dgvProduction.Columns["dgvcmbProductionBatch"].Index) { BatchSP spBatch = new BatchSP(); decimal decBatchId = 0; string strBarcode = string.Empty; if (dgvProduction.CurrentRow.Cells["dgvtxtProductionProductId"].Value != null) { if (dgvProduction.CurrentRow.Cells["dgvcmbProductionBatch"].Value != null) { if (dgvProduction.CurrentRow.Cells["dgvcmbProductionBatch"].Value.ToString() != string.Empty && dgvProduction.CurrentRow.Cells["dgvcmbProductionBatch"].Value.ToString() != "0") { decBatchId = Convert.ToDecimal(dgvProduction.CurrentRow.Cells["dgvcmbProductionBatch"].Value); strBarcode = spBatch.ProductBatchBarcodeViewByBatchId(decBatchId); dgvProduction.CurrentRow.Cells["dgvtxtProductionBarcode"].Value = strBarcode; } } } } } } } } catch (Exception ex) { MessageBox.Show("SJ:81" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// To select the product from ProductSearchPopup /// </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(); ProductSP spproduct = new ProductSP(); UnitConvertionSP SPUnitConversion = new UnitConvertionSP(); BatchSP spBatch = new BatchSP(); try { base.Show(); this.frmProductSearchPopupObj = frmProductSearchPopup; infoProduct = spproduct.ProductView(decproductId); int inRowcount = dgvProduct.Rows.Count; for (int i = 0; i < inRowcount; i++) { if (i == inRowcount - 1) { dgvProduct.Rows.Add(); } if (i == decCurrentRowIndex) { SerialNo(); dgvProduct.Rows[i].Cells["dgvtxtproductCode"].Value = infoProduct.ProductCode; dgvProduct.Rows[i].Cells["productId"].Value = decproductId.ToString(); dgvProduct.Rows[i].Cells["dgvtxtProductName"].Value = infoProduct.ProductName; dgvProduct.Rows[i].Cells["dgvcmbGodown"].Value = infoProduct.GodownId; dgvProduct.Rows[i].Cells["dgvCmbRack"].Value = infoProduct.RackId; UnitComboFill(decproductId, i, dgvProduct.Rows[i].Cells["dgvcmbUnit"].ColumnIndex); dgvProduct.Rows[i].Cells["dgvcmbUnit"].Value = infoProduct.UnitId; UnitConvertionSP SpUnitConvertion = new UnitConvertionSP(); DataTable dtblUnitByProduct = new DataTable(); dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[i].Cells["productId"].Value.ToString()); //UnitComboFill(infoProduct.ProductId, dgvProduct.CurrentRow.Index, dgvProduct.CurrentRow.Cells["dgvcmbUnit"].ColumnIndex); //dgvProduct.Rows[inI].Cells["dgvcmbUnit"].Value = infoProduct.UnitId; dgvProduct.Rows[i].Cells["dgvtxtRate"].Value = Math.Round(infoProduct.PurchaseRate, PublicVariables._inNoOfDecimalPlaces); dgvProduct.Rows[i].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(new UnitConvertionSP().UnitconversionIdViewByUnitIdAndProductId(infoProduct.UnitId, infoProduct.ProductId)); dgvProduct.CurrentRow.Cells["dgvtxtConversionRate"].Value = SPUnitConversion.UnitConversionRateByUnitConversionId(Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvtxtUnitConversionId"].Value.ToString())); BatchComboFill(decproductId, i, dgvProduct.Rows[i].Cells["dgvcmbBatch"].ColumnIndex); dgvProduct.Rows[i].Cells["dgvcmbBatch"].Value = spBatch.BatchIdViewByProductId(decproductId); RackComboFill(infoProduct.GodownId, i, dgvProduct.Rows[i].Cells["dgvCmbRack"].ColumnIndex); dgvProduct.Rows[i].Cells["dgvtxtBarcode"].Value = spBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvProduct.Rows[i].Cells["dgvcmbBatch"].Value.ToString())); dtbl = SPUnitConversion.DGVUnitConvertionRateByUnitId(infoProduct.UnitId, infoProduct.ProductName); dgvProduct.Rows[i].Cells["dgvtxtConversionRate"].Value = dtbl.Rows[0]["conversionRate"].ToString(); decCurrentConversionRate = Convert.ToDecimal(dgvProduct.CurrentRow.Cells["dgvtxtConversionRate"].Value.ToString()); NewAmountCalculation("dgvtxtQty", i); CalculateTotalAmount(); } } frmProductSearchPopupObj.Close(); frmProductSearchPopupObj = null; } catch (Exception ex) { MessageBox.Show("MR4:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }