void dataItemskryptonDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (m_editMode == EditMode.View) { return; } itemsDataGrid.Rows[e.RowIndex].ErrorText = ""; if (!itemsDataGrid[e.ColumnIndex, e.RowIndex].IsInEditMode) { return; } if (e.ColumnIndex == scanColumn.Index) { if (e.FormattedValue.ToString() == "") { return; } IList addedPI = new ArrayList(); for (int i = 0; i < itemsDataGrid.Rows.Count; i++) { if (i == e.RowIndex) { continue; } DeliveryOrderItem pi = (DeliveryOrderItem)itemsDataGrid[scanColumn.Index, i].Tag; if (pi == null) { continue; } addedPI.Add(pi.ID); } IList res = r_grn.FindSObyPartAndDONo(e.FormattedValue.ToString(), addedPI, ((Customer)supplierkryptonComboBox.SelectedItem).ID, dateKryptonDateTimePicker.Value); if (res.Count == 0) { using (SearchDOForSRForm fr = new SearchDOForSRForm(e.FormattedValue.ToString(), (Customer)supplierkryptonComboBox.SelectedItem, addedPI, m_mainForm.CurrentUser, dateKryptonDateTimePicker.Value)) { fr.ShowDialog(); IList result = fr.RESULT; m_poItems = result; } } else { m_poItems = res; } } if (QtyColumn.Index == e.ColumnIndex) { DeliveryOrderItem pi = (DeliveryOrderItem)itemsDataGrid[scanColumn.Index, e.RowIndex].Tag; if (pi == null) { return; } Part p = (Part)itemsDataGrid[codeColumn.Index, e.RowIndex].Tag; if (p == null) { return; } Unit u = (Unit)Utils.FindEntityInList(itemsDataGrid[unitColumn.Index, e.RowIndex].Value.ToString(), m_units); if (u == null) { return; } p.UNIT_CONVERSION_LIST = r_part.GetUnitConversions(p.ID); SalesReturnItem sample = new SalesReturnItem(); sample.PART = p; sample.UNIT = u; sample.QYTAMOUNT = Convert.ToDouble(e.FormattedValue); double qty = sample.GetAmountInSmallestUnit(); double rest = r_grn.GetOutstandingReturned(pi.ID) - qty; if (rest < 0) { e.Cancel = true; itemsDataGrid.Rows[e.RowIndex].ErrorText = "Quantity exceed outstanding quantity"; } // itemsDataGrid[OutstandingPOColumn.Index, e.RowIndex].Value = r_grn.GetOutstandingReturned(pi.ID); } if (unitColumn.Index == e.ColumnIndex) { DeliveryOrderItem pi = (DeliveryOrderItem)itemsDataGrid[scanColumn.Index, e.RowIndex].Tag; if (pi == null) { return; } Part p = (Part)itemsDataGrid[codeColumn.Index, e.RowIndex].Tag; if (p == null) { return; } Unit u = (Unit)Utils.FindEntityInList(e.FormattedValue.ToString(), m_units); if (u == null) { return; } p.UNIT_CONVERSION_LIST = r_part.GetUnitConversions(p.ID); DeliveryOrderItem sample = new DeliveryOrderItem(); sample.PART = p; sample.UNIT = u; sample.QYTAMOUNT = Convert.ToDouble(itemsDataGrid[QtyColumn.Index, e.RowIndex].Value); double qty = sample.GetAmountInSmallestUnit(); double rest = r_grn.GetOutstandingReturned(pi.ID) - qty; if (rest < 0) { e.Cancel = true; itemsDataGrid.Rows[e.RowIndex].ErrorText = "Quantity exceed outstanding quantity"; } //itemsDataGrid[OutstandingPOColumn.Index, e.RowIndex].Value = rest; } }