/// <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; BatchBll BllBatch = new BatchBll(); RackBll BllRack = new RackBll(); PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll(); PurchaseReturnBll BllPurchaseReturn = new PurchaseReturnBll(); ProductCreationBll BllProductCreation = new ProductCreationBll(); 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 = BllProductCreation.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 = BllProductCreation.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 = BllProductCreation.BatchIdByPartNoOrBarcode(strBarcode, strBarcode); if (decBatchId > 0) { List<DataTable> listObjBatchName = new List<DataTable>(); listObjBatchName = BllProductCreation.ProductCodeAndBarcodeByBatchId(decBatchId); dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtproductCode"].Value = listObjBatchName[0].Rows[0]["productCode"].ToString(); if (listObjBatchName[0].Rows[0]["barcode"].ToString() != null && listObjBatchName[0].Rows[0]["barcode"].ToString() != string.Empty) { dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtbarcode"].Value = listObjBatchName[0].Rows[0]["barcode"].ToString(); } decimal batchId = BllBatch.BatchViewByBarcode(strBarcode); dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value = batchId; FillProductDetails(listObjBatchName[0].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 { List<DataTable> ListObj= BllPurchaseInvoice.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(ListObj[0].Rows[e.RowIndex]["qty"].ToString())) { dgvPurchaseReturn.Rows[e.RowIndex].Cells["dgvtxtqty"].Value = Math.Round(Convert.ToDecimal(ListObj[0].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 = BllBatch.ProductBatchBarcodeViewByBatchId(decBatchId2); dgvPurchaseReturn.CurrentRow.Cells["dgvtxtbarcode"].Value = strBarcode2; } } CheckInvalidEntries(e); } catch (Exception ex) { MessageBox.Show("PR:80" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }