Example #1
0
 private void btnSearch_Click(object sender, EventArgs e)
 {
     _brandCollection = new Brand.ParameteredCollection(txtBrandCode.Text == string.Empty ? SqlString.Null : txtBrandCode.Text,
                                                        txtBrandDescription.Text == string.Empty ? SqlString.Null : txtBrandDescription.Text);
     _brandCollection.Load();
     bindingSourceBrand.DataSource = _brandCollection;
 }
Example #2
0
        public List <DropDownItem> GetBrandDropDownCollection()
        {
            var brandCollection = new Brand.ParameteredCollection(SqlString.Null, SqlString.Null);

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

            list.AddRange(brandCollection.Select(brand => new DropDownItem(brand.BrandCode.Value, brand.BrandDescription.IsNull ? string.Empty : brand.BrandDescription.Value)));
            return(list);
        }
Example #3
0
 private void dgvBrand_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     try
     {
         if (!dgvBrand.IsCurrentCellDirty)
         {
             return;
         }
         if (e.FormattedValue == null)
         {
             dgvBrand.Rows[e.RowIndex].ErrorText = "Entry is required";
             e.Cancel = true;
         }
         else
         {
             if (dgvBrand.Columns[e.ColumnIndex].Name == "BrandCode")
             {
                 var rx             = new System.Text.RegularExpressions.Regex(@"^\d{2}$");
                 var formattedValue = e.FormattedValue.ToString();
                 if (!rx.IsMatch(formattedValue))
                 {
                     dgvBrand.Rows[e.RowIndex].ErrorText = "Please enter Brand Code in ##";
                     e.Cancel = true;
                 }
                 else
                 {
                     var checkBrandCollection = new Brand.ParameteredCollection(formattedValue, SqlString.Null);
                     checkBrandCollection.Load();
                     if (checkBrandCollection.Count > 0)
                     {
                         dgvBrand.Rows[e.RowIndex].ErrorText = "Brand already exists";
                         e.Cancel = true;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Utility.GetInstance().HandleException(this, ex, e);
     }
 }
Example #4
0
 private void frmBrand_Load(object sender, EventArgs e)
 {
     _brandCollection = new Brand.ParameteredCollection();
     bindingSourceBrand.DataSource = _brandCollection;
 }
Example #5
0
        private void dgvBrand_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            try
            {
                if (!dgvBrand.IsCurrentRowDirty)
                {
                    return;
                }

                if (dgvBrand.CurrentRow.Cells["BrandCode"].Value == null)
                {
                    return;
                }

                var brandCode = (SqlString)dgvBrand.CurrentRow.Cells["BrandCode"].Value;
                if (brandCode.IsNull)
                {
                    dgvBrand.Rows[e.RowIndex].ErrorText = "Brand Code is required";
                    e.Cancel = true;
                    return;
                }
                var rx = new System.Text.RegularExpressions.Regex(@"^\d{2}$");
                if (!rx.IsMatch(brandCode.Value))
                {
                    dgvBrand.Rows[e.RowIndex].ErrorText = "Please enter Brand Code in ##";
                    e.Cancel = true;
                    return;
                }
                Brand brand;
                // new record
                if (e.RowIndex >= _brandCollection.Count)
                {
                    var checkBrandCollection = new Brand.ParameteredCollection(brandCode, SqlString.Null);
                    checkBrandCollection.Load();
                    if (checkBrandCollection.Count > 0)
                    {
                        dgvBrand.Rows[e.RowIndex].ErrorText = "Brand already exists";
                        e.Cancel = true;
                    }
                    else
                    {
                        brand = _brandCollection.Create(new BrandKey(brandCode));
                        if (dgvBrand.CurrentRow.Cells["BrandDescription"].Value != null)
                        {
                            brand.BrandDescription =
                                (SqlString)(dgvBrand.CurrentRow.Cells["BrandDescription"].Value);
                        }
                        _brandCollection.Save(brand);
                        // when the initial collection is empty
                        // 1. brand 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 (bindingSourceBrand.Count == 1)
                        {
                            bindingSourceBrand.DataSource = null;
                            bindingSourceBrand.DataSource = _brandCollection;
                        }
                        else
                        {
                            bindingSourceBrand.List[bindingSourceBrand.Count - 1] = brand;
                        }
                    }
                }
                // existing record
                else
                {
                    //brand = _brandCollection[new BrandKey(brandCode)];
                    //brand.Save();
                    brand = (Brand)dgvBrand.CurrentRow.DataBoundItem;
                    _brandCollection.Save(brand);
                    _brandCollection[new BrandKey(brandCode)] = brand;
                }
            }
            catch (Exception ex)
            {
                Utility.GetInstance().HandleException(this, ex, e);
            }
        }