Esempio n. 1
0
 private void btnSearch_Click(object sender, EventArgs e)
 {
     _itemCollection = new Item.ParameteredCollection(_company.CompanyCode, txtItemNumber.Text == string.Empty ? SqlString.Null : txtItemNumber.Text,
                                                      txtItemDescription.Text == string.Empty ? SqlString.Null : txtItemDescription.Text,
                                                      cboProductGroup.SelectedIndex < 1 ? SqlString.Null : cboProductGroup.SelectedValue.ToString(),
                                                      cboBrand.SelectedIndex < 1 ? SqlString.Null : cboBrand.SelectedValue.ToString(),
                                                      cboProductCategory.SelectedIndex < 1 ? SqlString.Null : cboProductCategory.SelectedValue.ToString());
     _itemCollection.Load();
     bindingSourceItem.DataSource = _itemCollection;
 }
Esempio n. 2
0
 private void dgvItem_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     try
     {
         if (!dgvItem.IsCurrentCellDirty)
         {
             return;
         }
         if (e.FormattedValue == null)
         {
             dgvItem.Rows[e.RowIndex].ErrorText = "Entry is required";
             e.Cancel = true;
         }
         else
         {
             if (dgvItem.Columns[e.ColumnIndex].Name == "ItemNumber")
             {
                 var rx             = new System.Text.RegularExpressions.Regex(@"^\d{2}-\d{5}-[A-Z0-9]{2}\d$");
                 var formattedValue = e.FormattedValue.ToString();
                 if (!rx.IsMatch(formattedValue))
                 {
                     dgvItem.Rows[e.RowIndex].ErrorText = "Please enter Item Number in ##-#####-AAA";
                     e.Cancel = true;
                 }
                 else
                 {
                     var checkItemCollection = new Item.ParameteredCollection(_company.CompanyCode, formattedValue, SqlString.Null, SqlString.Null, SqlString.Null, SqlString.Null);
                     checkItemCollection.Load();
                     if (checkItemCollection.Count > 0)
                     {
                         dgvItem.Rows[e.RowIndex].ErrorText = "Item already exists";
                         e.Cancel = true;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Utility.GetInstance().HandleException(this, ex, e);
     }
 }
Esempio n. 3
0
        private void dgvItem_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            try
            {
                if (!dgvItem.IsCurrentRowDirty)
                {
                    return;
                }

                if (dgvItem.CurrentRow.Cells["ItemNumber"].Value != null)
                {
                    SqlString itemNumber = dgvItem.CurrentRow.Cells["ItemNumber"].Value.ToString();
                    if (itemNumber.IsNull)
                    {
                        dgvItem.Rows[e.RowIndex].ErrorText = "Item Number is required";
                        e.Cancel = true;
                        return;
                    }
                    var rx = new System.Text.RegularExpressions.Regex(@"^\d{2}-\d{5}-[A-Z0-9]{2}\d$");
                    if (!rx.IsMatch(itemNumber.Value))
                    {
                        dgvItem.Rows[e.RowIndex].ErrorText = "Please enter Item Number in ##-#####-AAA";
                        e.Cancel = true;
                        return;
                    }
                    Item item;
                    // new record
                    if (e.RowIndex >= _itemCollection.Count)
                    {
                        var checkItemCollection = new Item.ParameteredCollection(_company.CompanyCode, itemNumber, SqlString.Null, SqlString.Null, SqlString.Null, SqlString.Null);
                        checkItemCollection.Load();
                        if (checkItemCollection.Count > 0)
                        {
                            dgvItem.Rows[e.RowIndex].ErrorText = "Item already exists";
                            e.Cancel = true;
                        }
                        else
                        {
                            item = _itemCollection.Create(new ItemKey(_company.CompanyCode, itemNumber));
                            if (dgvItem.CurrentRow.Cells["ItemDescription"].Value != null)
                            {
                                item.ItemDescription = (SqlString)dgvItem.CurrentRow.Cells["ItemDescription"].Value;
                            }
                            if (dgvItem.CurrentRow.Cells["ProductGroup"].Value != null)
                            {
                                item.ProductGroupCodeBinding = (string)dgvItem.CurrentRow.Cells["ProductGroup"].Value;
                            }
                            _itemCollection.Save(item);
                            // when the initial collection is empty
                            // 1. item in bindingSource is not set to the correct type, so reset the bindingSource.DataSource below
                            // 2. the data moves above need to check for null
                            if (bindingSourceItem.Count == 1)
                            {
                                bindingSourceItem.DataSource = null;
                                bindingSourceItem.DataSource = _itemCollection;
                            }
                            else
                            {
                                bindingSourceItem.List[bindingSourceItem.Count - 1] = item;
                            }
                        }
                    }
                    // existing record
                    else
                    {
                        //item = _itemCollection[new ItemKey(itemNumber)];
                        //item.Save();
                        item = (Item)dgvItem.CurrentRow.DataBoundItem;
                        _itemCollection.Save(item);
                        _itemCollection[new ItemKey(_company.CompanyCode, itemNumber)] = item;
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.GetInstance().HandleException(this, ex, e);
            }
        }