/// <summary> ///to change the corresponding values in grid when cells changed /// </summary> private void dgvProduct_CellLeave(object sender, DataGridViewCellEventArgs e) { try { SalesQuotationDetailsSP spQuotationDetails = new SalesQuotationDetailsSP(); DeliveryNoteMasterSP spDeliveryNoteMaster = new DeliveryNoteMasterSP(); if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQty") { decimal decCurrentQty = 0; decimal decOldQty = 0; if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString() != string.Empty) { if (decDelivryNoteIdToEdit != 0) { if (cmbOrderNo.SelectedIndex != 0) { if (cmbDeliveryMode.Text == "Against Order") { DataTable dtblDetails = new SalesOrderDetailsSP().SalesOrderDetailsViewBySalesOrderMasterIdWithRemaining(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit); decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[0].Cells["dgvtxtQty"].Value.ToString()); decOldQty = Convert.ToDecimal(dtblDetails.Rows[0]["qty"].ToString()); } else if (cmbDeliveryMode.Text == "Against Quotation") { DataTable dtblQuotationDetails = spQuotationDetails.SalesQuotationDetailsViewByquotationMasterIdWithRemainingByNotInCurrDN(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit); if (dtblQuotationDetails.Rows.Count >= 1) { decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[0].Cells["dgvtxtQty"].Value.ToString()); decOldQty = Convert.ToDecimal(dtblQuotationDetails.Rows[0]["qty"].ToString()); } } if (spDeliveryNoteMaster.DeliveryNoteMasterReferenceCheckRejectionIn(decDelivryNoteIdToEdit)) { DataTable dtblRejectionInQty = new DataTable(); dtblRejectionInQty = spDeliveryNoteMaster.DeliveryNoteMasterReferenceCheckRejectionInQty(decDelivryNoteIdToEdit); decimal decRejectionInQty = decimal.Parse(dtblRejectionInQty.Rows[e.RowIndex]["qty"].ToString()); if (decimal.Parse(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()) > decimal.Parse(dtblRejectionInQty.Rows[e.RowIndex]["qty"].ToString())) { decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()); } else { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = Convert.ToDecimal(decRejectionInQty); } } if (spDeliveryNoteMaster.DeliveryNoteCheckReferenceInSalesInvoice(decDelivryNoteIdToEdit)) { DataTable dtblSalesInvoiceQty = new DataTable(); dtblSalesInvoiceQty = spDeliveryNoteMaster.DeliveryNoteMasterReferenceCheckSalesInvoiceQty(decDelivryNoteIdToEdit); decimal decSalesInvoiceQty = decimal.Parse(dtblSalesInvoiceQty.Rows[e.RowIndex]["qty"].ToString()); if (decimal.Parse(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()) > decimal.Parse(dtblSalesInvoiceQty.Rows[e.RowIndex]["qty"].ToString())) { decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()); } else { dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = Convert.ToDecimal(decSalesInvoiceQty); } } } else { Messages.InformationMessage("Select OrderNo"); cmbOrderNo.Focus(); } } if (decDelivryNoteIdToEdit == 0) { if (Convert.ToInt32(dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value) != 0) { if (cmbDeliveryMode.Text == "Against Quotation") { DataTable dtbl1 = spQuotationDetails.SalesQuotationDetailsViewByquotationMasterIdWithRemainingByNotInCurrDN(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit); decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()); decOldQty = Convert.ToDecimal(dtbl1.Rows[e.RowIndex]["qty"].ToString()); } else if (cmbDeliveryMode.Text == "Against Order") { DataTable dtbl2 = new SalesOrderDetailsSP().SalesOrderDetailsViewBySalesOrderMasterIdWithRemaining(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit); decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()); decOldQty = Convert.ToDecimal(dtbl2.Rows[e.RowIndex]["qty"].ToString()); } } } } } if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit") { if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty) { 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["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()); decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate; dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, 2); } } } } } } if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQty") { AmountCalculation("dgvtxtQty", e.RowIndex); } if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtRate") { AmountCalculation("dgvtxtRate", e.RowIndex); } else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtAmount") { TotalAmountCalculation(); } CheckInvalidEntries(e); } catch (Exception ex) { MessageBox.Show("DN70:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// To fill the grid according to the pending Sales Quotation Invoice number /// </summary> public void FillQuotationDetails() { SerialNo(); try { SalesQuotationMasterSP spQuotationMaster = new SalesQuotationMasterSP(); SalesQuotationDetailsSP spQuotationDetails = new SalesQuotationDetailsSP(); DeliveryNoteMasterInfo infoDeliveryNoteMaster = new DeliveryNoteMasterInfo(); DeliveryNoteMasterSP spDeliveryNoteMaster = new DeliveryNoteMasterSP(); decimal decOrderNo = 0; decimal DefaultRate = 0; string strSalesManId; inMaxCount = 0; decOrderNo = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()); dgvProduct.Rows.Clear(); DataTable dtblMaster = spQuotationMaster.SalesQuotationMasterViewByQuotationMasterId(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString())); if (dtblMaster.Rows.Count > 0) { cmbPricingLevel.SelectedValue = dtblMaster.Rows[0]["pricingLevelId"].ToString(); if (dtblMaster.Rows[0]["employeeId"].ToString() != string.Empty) { strSalesManId = dtblMaster.Rows[0]["employeeId"].ToString(); cmbSalesMan.SelectedValue = strSalesManId; SalesManComboFill(); cmbSalesMan.SelectedValue = dtblMaster.Rows[0]["employeeId"].ToString(); } CurrencyComboFill(); cmbCurrency.SelectedValue = dtblMaster.Rows[0]["exchangeRateId"].ToString(); DataTable dtblQuotationDetails = spQuotationDetails.SalesQuotationDetailsViewByquotationMasterIdWithRemainingByNotInCurrDN(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDeliveryNoteMasterId); int inRowIndex = 0; isValueChange = false; isDoAfterGridFill = false; foreach (DataRow drowDetails in dtblQuotationDetails.Rows) { dgvProduct.Rows.Add(); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].Value = drowDetails["barcode"].ToString(); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductId"].Value = drowDetails["productId"].ToString(); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductCode"].Value = drowDetails["productCode"].ToString(); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"].Value = drowDetails["productName"].ToString(); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtQty"].Value = drowDetails["Qty"].ToString(); UnitComboFill1(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ColumnIndex); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString()); BatchComboFill(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].ColumnIndex); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString()); GridGodownComboFill(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].ColumnIndex); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(drowDetails["godownId"].ToString()); RackComboFill1(Convert.ToDecimal(drowDetails["godownId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbRack"].ColumnIndex); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbRack"].Value = Convert.ToDecimal(drowDetails["rackId"].ToString()); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtRate"].Value = drowDetails["Rate"].ToString(); DefaultRate = Convert.ToDecimal(dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtRate"].Value.ToString()); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value = drowDetails["quotationDetailsId"].ToString(); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtVoucherTypeId"].Value = drowDetails["voucherTypeId"].ToString(); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtVoucherNo"].Value = drowDetails["voucherNo"].ToString(); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtInvoiceNo"].Value = drowDetails["invoiceNo"].ToString(); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drowDetails["unitConversionId"].ToString()); dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value = drowDetails["conversionRate"].ToString(); if (cmbOrderNo.Visible == true) { dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true; } dgvProduct.Rows[dgvProduct.Rows.Count - 2].HeaderCell.Value = ""; AmountCalculation("dgvtxtQty", inRowIndex); int inIndex = 0; int.TryParse(drowDetails["extra1"].ToString(), out inIndex); if (inMaxCount < inIndex) inMaxCount = inIndex; inRowIndex++; isValueChange = true; } for (int i = inRowIndex; i < dgvProduct.Rows.Count; ++i) dgvProduct["inRowIndex", i].Value = GetNextinRowIndex().ToString(); SerialNo(); TotalAmountCalculation(); isDoAfterGridFill = true; } } catch (Exception ex) { MessageBox.Show("DN28 :" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }