Example #1
0
 /// <summary>
 /// Gets the hash code for a <see cref="ProductBrand"/>.
 /// </summary>
 /// <param name="obj">The object to calculate hash code for.</param>
 /// <returns>The hash code.</returns>
 private int GetHashCodeInternal(ProductBrand obj)
 {
     if (obj.value == null)
     {
         return(obj.GetType().Name.GetHashCode());
     }
     else
     {
         return(obj.value.ToLower().GetHashCode());
     }
 }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                var confirmResult = MessageBox.Show("Are you sure to Edit this item ??",
                                                    "Confirm Edit!!",
                                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (confirmResult == DialogResult.No)
                {
                    return;
                }

                ProductBrand productBrand = productBrandBindingSource.Current as ProductBrand;
                if (productBrand == null)
                {
                    throw new Exception("Couldn't get the product brand to edit");
                }
                productBrand.Name     = txtName.Text.Trim();
                productBrand.IsActive = checkBoxIsActive.Checked;

                CustomResult customResult = productBrandBUS.EditProductBrand(productBrand);
                if (customResult.Result == CustomResultType.Succeed)
                {
                    RefreshProductBrandGrid();
                    ClearValuesGroupBox();
                    MessageBox.Show("Product Brand Edited",
                                    "Inform", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (customResult.Result == CustomResultType.InvalidModelState)
                {
                    validator.DisplayModelValidationErrorsAndFocus(productBrand.GetType());
                }
                else
                {
                    throw new Exception(customResult.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                var confirmResult = MessageBox.Show("Are you sure to Add this item ??",
                                                    "Confirm Add!!",
                                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (confirmResult == DialogResult.No)
                {
                    return;
                }
                ProductBrand productBrand = new ProductBrand(txtName.Text.Trim(), checkBoxIsActive.Checked);
                CustomResult customResult = productBrandBUS.AddProductBrand(productBrand);
                if (customResult.Result == CustomResultType.Succeed)
                {
                    productBrandDataGridView.Refresh();
                    MessageBox.Show("Product Brand Added",
                                    "Inform", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearValuesGroupBox();
                    RefreshProductBrandGrid();

                    txtName.Focus();
                }
                else if (customResult.Result == CustomResultType.InvalidModelState)
                {
                    validator.DisplayModelValidationErrorsAndFocus(productBrand.GetType());
                }
                else
                {
                    throw new Exception(customResult.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }