Esempio n. 1
0
 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 (!((DataGridViewTextBoxCell)itemsDataGrid[scanColumn.Index, e.RowIndex]).IsInEditMode)
         {
             return;
         }
         if (e.FormattedValue.ToString() == "")
         {
             return;
         }
         IList result = r_part.SearchActivePart(e.FormattedValue.ToString(), true);
         if (result.Count == 1)
         {
             Part p = (Part)result[0];
             for (int i = 0; i < itemsDataGrid.Rows.Count; i++)
             {
                 if (i == e.RowIndex)
                 {
                     continue;
                 }
                 Part pi = (Part)itemsDataGrid[codeColumn.Index, i].Tag;
                 if (pi == null)
                 {
                     continue;
                 }
                 if (pi.ID == p.ID)
                 {
                     itemsDataGrid.Rows[e.RowIndex].ErrorText = "Part : " + p.NAME + " already add.";
                     e.Cancel = true;
                     return;
                 }
             }
             itemsDataGrid[codeColumn.Index, e.RowIndex].Tag   = p;
             itemsDataGrid[scanColumn.Index, e.RowIndex].Value = p.BARCODE;
             itemsDataGrid[codeColumn.Index, e.RowIndex].Value = p.CODE;
             itemsDataGrid[nameColumn.Index, e.RowIndex].Value = p.NAME;
             //dataItemskryptonDataGridView[QtyColumn.Index, e.RowIndex].Value = 0;
             //unitColumn.Items.Clear();
             // IList units = r_part.GetAllUnit(p.ID, p.UNIT.ID);
             //Utils.GetListCode(unitColumn.Items, units);
             p.UNIT = (Unit)r_unit.GetById(p.UNIT);
             itemsDataGrid[unitColumn.Index, e.RowIndex].Value  = p.UNIT.ToString();
             itemsDataGrid[priceColumn.Index, e.RowIndex].Value = r_po.GetTheLatestPOPrice(((Customer)supplierkryptonComboBox.SelectedItem).ID, p.ID, p.UNIT.ID);
             //dataItemskryptonDataGridView[totalAmountColumn.Index, e.RowIndex].Value = 0;
             itemsDataGrid[warehouseColumn.Index, e.RowIndex].Value = m_warehouses[0].ToString();
         }
         if ((result.Count == 0) || (result.Count > 1))
         {
             using (SearchPartForm fr = new SearchPartForm(e.FormattedValue.ToString(), result))
             {
                 fr.ShowDialog();
                 Part p = fr.PART;
                 if (p == null)
                 {
                     p = (Part)itemsDataGrid[codeColumn.Index, e.RowIndex].Tag;
                     if (p == null)
                     {
                         e.Cancel = true;
                         return;
                     }
                 }
                 else
                 {
                     for (int i = 0; i < itemsDataGrid.Rows.Count; i++)
                     {
                         if (i == e.RowIndex)
                         {
                             continue;
                         }
                         Part pi = (Part)itemsDataGrid[codeColumn.Index, i].Tag;
                         if (pi == null)
                         {
                             continue;
                         }
                         if (pi.ID == p.ID)
                         {
                             itemsDataGrid.Rows[e.RowIndex].ErrorText = "Part : " + p.NAME + " already add.";
                             e.Cancel = true;
                             return;
                         }
                     }
                     itemsDataGrid[codeColumn.Index, e.RowIndex].Tag   = p;
                     itemsDataGrid[scanColumn.Index, e.RowIndex].Value = p.BARCODE;
                     itemsDataGrid[codeColumn.Index, e.RowIndex].Value = p.CODE;
                     itemsDataGrid[nameColumn.Index, e.RowIndex].Value = p.NAME;
                     //dataItemskryptonDataGridView[QtyColumn.Index, e.RowIndex].Value = 0;
                     //unitColumn.Items.Clear();
                     //IList units = r_part.GetAllUnit(p.ID, p.UNIT.ID);
                     //Utils.GetListCode(unitColumn.Items, units);
                     p.UNIT = (Unit)r_unit.GetById(p.UNIT);
                     itemsDataGrid[unitColumn.Index, e.RowIndex].Value  = p.UNIT.ToString();
                     itemsDataGrid[priceColumn.Index, e.RowIndex].Value = r_po.GetTheLatestPOPrice(((Customer)supplierkryptonComboBox.SelectedItem).ID, p.ID, p.UNIT.ID);
                     // dataItemskryptonDataGridView[totalAmountColumn.Index, e.RowIndex].Value = 0;
                     itemsDataGrid[warehouseColumn.Index, e.RowIndex].Value = m_warehouses[0].ToString();
                 }
             }
         }
     }
     if (e.ColumnIndex == discabcColumn.Index)
     {
         if (e.FormattedValue.ToString() == "")
         {
             return;
         }
         else
         {
             try
             {
                 splitDiscString(e.FormattedValue.ToString(), 0);
                 splitDiscString(e.FormattedValue.ToString(), 1);
                 splitDiscString(e.FormattedValue.ToString(), 2);
             }
             catch (Exception x)
             {
                 itemsDataGrid.Rows[e.RowIndex].ErrorText = x.Message;
                 e.Cancel = true;
                 return;
             }
         }
     }
 }
Esempio n. 2
0
 void dataItemskryptonDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (m_editMode == EditMode.View)
     {
         return;
     }
     dataItemskryptonDataGridView.Rows[e.RowIndex].ErrorText = "";
     if (!dataItemskryptonDataGridView[e.ColumnIndex, e.RowIndex].IsInEditMode)
     {
         return;
     }
     if (e.ColumnIndex == scanColumn.Index)
     {
         if (!((DataGridViewTextBoxCell)dataItemskryptonDataGridView[scanColumn.Index, e.RowIndex]).IsInEditMode)
         {
             return;
         }
         if (e.FormattedValue.ToString() == "")
         {
             return;
         }
         IList result = r_part.SearchActivePart(e.FormattedValue.ToString(), true);
         if (result.Count == 1)
         {
             Part p = (Part)result[0];
             for (int i = 0; i < dataItemskryptonDataGridView.Rows.Count; i++)
             {
                 if (i == e.RowIndex)
                 {
                     continue;
                 }
                 Part pi = (Part)dataItemskryptonDataGridView[codeColumn.Index, i].Tag;
                 if (pi == null)
                 {
                     continue;
                 }
                 if (pi.ID == p.ID)
                 {
                     dataItemskryptonDataGridView.Rows[e.RowIndex].ErrorText = "Part : " + p.NAME + " already add.";
                     e.Cancel = true;
                     return;
                 }
             }
             dataItemskryptonDataGridView[codeColumn.Index, e.RowIndex].Tag   = p;
             dataItemskryptonDataGridView[codeColumn.Index, e.RowIndex].Value = p.CODE;
             dataItemskryptonDataGridView[nameColumn.Index, e.RowIndex].Value = p.NAME;
             //dataItemskryptonDataGridView[QtyColumn.Index, e.RowIndex].Value = 0;
             unitColumn.Items.Clear();
             IList units = r_part.GetAllUnit(p.ID, p.UNIT.ID);
             Utils.GetListCode(unitColumn.Items, units);
             dataItemskryptonDataGridView[unitColumn.Index, e.RowIndex].Value = units[0].ToString();;
             //dataItemskryptonDataGridView[priceColumn.Index, e.RowIndex].Value = 0;
             //dataItemskryptonDataGridView[totalAmountColumn.Index, e.RowIndex].Value = 0;
         }
         if ((result.Count == 0) || (result.Count > 1))
         {
             using (SearchPartForm fr = new SearchPartForm(e.FormattedValue.ToString(), result))
             {
                 fr.ShowDialog();
                 Part p = fr.PART;
                 if (p == null)
                 {
                     p = (Part)dataItemskryptonDataGridView[codeColumn.Index, e.RowIndex].Tag;
                     if (p == null)
                     {
                         e.Cancel = true;
                         return;
                     }
                 }
                 else
                 {
                     for (int i = 0; i < dataItemskryptonDataGridView.Rows.Count; i++)
                     {
                         if (i == e.RowIndex)
                         {
                             continue;
                         }
                         Part pi = (Part)dataItemskryptonDataGridView[codeColumn.Index, i].Tag;
                         if (pi == null)
                         {
                             continue;
                         }
                         if (pi.ID == p.ID)
                         {
                             dataItemskryptonDataGridView.Rows[e.RowIndex].ErrorText = "Part : " + p.NAME + " already add.";
                             e.Cancel = true;
                             return;
                         }
                     }
                     dataItemskryptonDataGridView[codeColumn.Index, e.RowIndex].Tag   = p;
                     dataItemskryptonDataGridView[codeColumn.Index, e.RowIndex].Value = p.CODE;
                     dataItemskryptonDataGridView[nameColumn.Index, e.RowIndex].Value = p.NAME;
                     //dataItemskryptonDataGridView[QtyColumn.Index, e.RowIndex].Value = 0;
                     unitColumn.Items.Clear();
                     IList units = r_part.GetAllUnit(p.ID, p.UNIT.ID);
                     Utils.GetListCode(unitColumn.Items, units);
                     dataItemskryptonDataGridView[unitColumn.Index, e.RowIndex].Value = units[0].ToString();;
                     //dataItemskryptonDataGridView[priceColumn.Index, e.RowIndex].Value = 0;
                     // dataItemskryptonDataGridView[totalAmountColumn.Index, e.RowIndex].Value = 0;
                 }
             }
         }
     }
 }