Beispiel #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 (e.FormattedValue.ToString() == "")
                {
                    return;
                }

                IList addedPI = new ArrayList();
                for (int i = 0; i < itemsDataGrid.Rows.Count; i++)
                {
                    if (i == e.RowIndex)
                    {
                        continue;
                    }
                    SalesOrderItem pi = (SalesOrderItem)itemsDataGrid[scanColumn.Index, i].Tag;
                    if (pi == null)
                    {
                        continue;
                    }
                    addedPI.Add(pi.ID);
                }
                IList res = r_po.FindSObyPartAndSONo(e.FormattedValue.ToString(), addedPI, ((Customer)supplierkryptonComboBox.SelectedItem).ID, dateKryptonDateTimePicker.Value);
                if (res.Count == 0)
                {
                    using (SearchSOForDOForm fr = new SearchSOForDOForm(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)
            {
                SalesOrderItem pi = (SalesOrderItem)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);
                DeliveryOrderItem sample = new DeliveryOrderItem();
                sample.PART      = p;
                sample.UNIT      = u;
                sample.QYTAMOUNT = Convert.ToDouble(e.FormattedValue);
                double qty  = sample.GetAmountInSmallestUnit();
                double rest = r_po.GetOutstandingDelivered(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;
            }
            if (unitColumn.Index == e.ColumnIndex)
            {
                SalesOrderItem pi = (SalesOrderItem)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_po.GetOutstandingDelivered(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;
            }
        }