/// <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 { BatchBll BllBatch = new BatchBll(); 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 { MaterialReceiptBll bllMaterialReceiptDetails = new MaterialReceiptBll(); decimal decMaterialReceiptMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()); List<DataTable> ListObj = new List<DataTable>(); ListObj = bllMaterialReceiptDetails.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 = BllBatch.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> /// Function to fill material receipt details /// </summary> public void MaterialReceiptDetailsFill() { List<DataTable> ListObj = new List<DataTable>(); List<DataTable> ListObjDetals = new List<DataTable>(); MaterialReceiptBll bllMaterialReceiptMaster = new MaterialReceiptBll(); MaterialReceiptBll bllMaterialReceiptDetails = new MaterialReceiptBll(); decimal decMaterialReceiptMasterId = 0; try { if (!isEditFill) { if (cmbCashOrParty.SelectedValue != null) { if (cmbCashOrParty.SelectedValue.ToString() != "System.Data.DataRowView" && cmbCashOrParty.Text != "System.Data.DataRowView") { GridComboFill(); decMaterialReceiptMasterId = Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()); ListObj = bllMaterialReceiptMaster.MaterialReceiptMasterViewByReceiptMasterId(decMaterialReceiptMasterId); if (ListObj[0].Rows.Count > 0) { cmbCurrency.SelectedValue = ListObj[0].Rows[0].ItemArray[7]; } ListObjDetals = bllMaterialReceiptDetails.MaterialReceiptDetailsViewByMaterialReceiptMasterIdWithRemainingByNotInCurrPI (decMaterialReceiptMasterId, decPurchaseMasterId, decPurchaseInvoiceVoucherTypeId); if (ListObjDetals[0].Rows.Count > 0) { if (dgvProductDetails.DataSource == null) { dgvProductDetails.Rows.Clear(); } else { ((DataTable)dgvProductDetails.DataSource).Rows.Clear(); } int i = 0; foreach (DataRow dr in ListObjDetals[0].Rows) { dgvProductDetails.Rows.Add(); dgvProductDetails.Rows[i].Cells["dgvtxtPurchaseDetailsId"].Value = dr["purchaseDetailsId"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtPurchaseOrderDetailsId"].Value = dr["purchaseOrderDetailsId"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtMaterialReceiptDetailsId"].Value = dr["materialReceiptDetailsId"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtProductId"].Value = dr["productId"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtBarcode"].Value = dr["barcode"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtProductCode"].Value = dr["productCode"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtProductName"].Value = dr["productName"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtQuantity"].Value = dr["qty"].ToString(); UnitComboFill(Convert.ToDecimal(dr["productId"].ToString()), i, dgvProductDetails.Rows[i].Cells["dgvcmbUnit"].ColumnIndex); dgvProductDetails.Rows[i].Cells["dgvtxtUnitConversionId"].Value = dr["unitConversionId"].ToString(); dgvProductDetails.Rows[i].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(dr["unitId"].ToString()); dgvProductDetails.Rows[i].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(dr["godownId"].ToString()); ; dgvProductDetails.Rows[i].Cells["dgvcmbRack"].Value = Convert.ToDecimal(dr["rackId"].ToString()); ; BatchComboFill(Convert.ToDecimal(dr["productId"].ToString()), i, dgvProductDetails.Rows[i].Cells["dgvcmbBatch"].ColumnIndex); dgvProductDetails.Rows[i].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(dr["batchId"].ToString()); dgvProductDetails.Rows[i].Cells["dgvtxtRate"].Value = dr["rate"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtGrossValue"].Value = dr["grossValue"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtDiscountPercent"].Value = dr["discountPercent"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtDiscount"].Value = dr["discount"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtNetValue"].Value = dr["netvalue"].ToString(); dgvProductDetails.Rows[i].Cells["dgvcmbTax"].Value = Convert.ToDecimal(dr["taxId"].ToString()); dgvProductDetails.Rows[i].Cells["dgvtxtTaxAmount"].Value = dr["taxAmount"].ToString(); dgvProductDetails.Rows[i].Cells["dgvtxtAmount"].Value = dr["Amount"].ToString(); dgvProductDetails.Rows[i].Cells["dgvcmbUnit"].ReadOnly = true; i++; } dgvProductDetails.AllowUserToAddRows = false; } else { if (dgvProductDetails.DataSource == null) { dgvProductDetails.Rows.Clear(); } else { ((DataTable)dgvProductDetails.DataSource).Rows.Clear(); } } SerialNo(); GridviewReadOnlySettings("Against MaterialReceipt"); } } } } catch (Exception ex) { MessageBox.Show("PI20:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }