Пример #1
0
 private void btnSearch_Click(object sender, EventArgs e)
 {
     _productCategoryCollection = new ProductCategory.ParameteredCollection(txtProductCategoryCode.Text == string.Empty ? SqlString.Null : txtProductCategoryCode.Text,
                                                                            txtProductCategoryDescription.Text == string.Empty ? SqlString.Null : txtProductCategoryDescription.Text);
     _productCategoryCollection.Load();
     bindingSourceProductCategory.DataSource = _productCategoryCollection;
 }
Пример #2
0
        public List <DropDownItem> GetProductCategoryDropDownCollection()
        {
            var productCategoryCollection = new ProductCategory.ParameteredCollection(SqlString.Null, SqlString.Null);

            productCategoryCollection.Load();
            var list = new List <DropDownItem>(productCategoryCollection.Count + 1)
            {
                new DropDownItem(string.Empty, string.Empty)
            };

            list.AddRange(productCategoryCollection.Select(productCategory => new DropDownItem(productCategory.ProductCategoryCode.Value, productCategory.ProductCategoryDescription.IsNull ? string.Empty : productCategory.ProductCategoryDescription.Value)));
            return(list);
        }
Пример #3
0
 private void dgvProductCategory_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     try
     {
         if (!dgvProductCategory.IsCurrentCellDirty)
         {
             return;
         }
         if (e.FormattedValue == null)
         {
             dgvProductCategory.Rows[e.RowIndex].ErrorText = "Entry is required";
             e.Cancel = true;
             return;
         }
         if (dgvProductCategory.Columns[e.ColumnIndex].Name != "ProductCategoryCode")
         {
             return;
         }
         var rx             = new System.Text.RegularExpressions.Regex(@"^\d{2}$");
         var formattedValue = e.FormattedValue.ToString();
         if (!rx.IsMatch(formattedValue))
         {
             dgvProductCategory.Rows[e.RowIndex].ErrorText = "Please enter Product Category Code in ##";
             e.Cancel = true;
             return;
         }
         var checkProductCategoryCollection = new ProductCategory.ParameteredCollection(formattedValue, SqlString.Null);
         checkProductCategoryCollection.Load();
         if (checkProductCategoryCollection.Count > 0)
         {
             dgvProductCategory.Rows[e.RowIndex].ErrorText = "Product Category already exists";
             e.Cancel = true;
         }
     }
     catch (Exception ex)
     {
         Utility.GetInstance().HandleException(this, ex, e);
     }
 }
Пример #4
0
 private void frmProductCategory_Load(object sender, EventArgs e)
 {
     _productCategoryCollection = new ProductCategory.ParameteredCollection();
     bindingSourceProductCategory.DataSource = _productCategoryCollection;
 }
Пример #5
0
        private void dgvProductCategory_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            try
            {
                if (!dgvProductCategory.IsCurrentRowDirty)
                {
                    return;
                }

                if (dgvProductCategory.CurrentRow.Cells["ProductCategoryCode"].Value != null)
                {
                    SqlString productCategoryCode = dgvProductCategory.CurrentRow.Cells["ProductCategoryCode"].Value.ToString();
                    if (productCategoryCode.IsNull)
                    {
                        dgvProductCategory.Rows[e.RowIndex].ErrorText = "Product Category Code is required";
                        e.Cancel = true;
                        return;
                    }
                    var rx = new System.Text.RegularExpressions.Regex(@"^\d{2}$");
                    if (!rx.IsMatch(productCategoryCode.Value))
                    {
                        dgvProductCategory.Rows[e.RowIndex].ErrorText = "Please enter Product Category Code in ##";
                        e.Cancel = true;
                        return;
                    }
                    ProductCategory productCategory = null;
                    // new record
                    if (e.RowIndex >= _productCategoryCollection.Count)
                    {
                        var checkProductCategoryCollection = new ProductCategory.ParameteredCollection(productCategoryCode, SqlString.Null);
                        checkProductCategoryCollection.Load();
                        if (checkProductCategoryCollection.Count > 0)
                        {
                            dgvProductCategory.Rows[e.RowIndex].ErrorText = "Product Category already exists";
                            e.Cancel = true;
                        }
                        else
                        {
                            productCategory = _productCategoryCollection.Create(new ProductCategoryKey(productCategoryCode));
                            if (dgvProductCategory.CurrentRow.Cells["ProductCategoryDescription"].Value != null)
                            {
                                productCategory.ProductCategoryDescription = (SqlString)(dgvProductCategory.CurrentRow.Cells["ProductCategoryDescription"].Value);
                            }
                            _productCategoryCollection.Save(productCategory);
                            // when the initial collection is empty
                            // 1. productCategory 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 (bindingSourceProductCategory.Count == 1)
                            {
                                bindingSourceProductCategory.DataSource = null;
                                bindingSourceProductCategory.DataSource = _productCategoryCollection;
                            }
                            else
                            {
                                bindingSourceProductCategory.List[bindingSourceProductCategory.Count - 1] = productCategory;
                            }
                        }
                    }
                    // existing record
                    else
                    {
                        //productCategory = _productCategoryCollection[new ProductCategoryKey(productCategoryCode)];
                        //productCategory.Save();
                        productCategory = (ProductCategory)dgvProductCategory.CurrentRow.DataBoundItem;
                        _productCategoryCollection.Save(productCategory);
                        _productCategoryCollection[new ProductCategoryKey(productCategoryCode)] = productCategory;
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.GetInstance().HandleException(this, ex, e);
            }
        }