public bool InsertCategory(Category category)
 {
     try
     {
         contextDB.Categories.Add(category);
         contextDB.SaveChanges();
         return true;
     }
     catch { return false; }
 }
 public bool UpdateCategory(Category category)
 {
     try
     {
         Category existing = contextDB.Categories.Find(category.CategoryId);
         ((IObjectContextAdapter)contextDB).ObjectContext.Detach(existing);
         contextDB.Entry(category).State = EntityState.Modified;
         contextDB.SaveChanges();
         return true;
     }
     catch { return false; }
 }
 private void gvCategory_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     int rowindex = gvCategory.CurrentCell.RowIndex;
         var senderGrid = (DataGridView)sender;
         if (senderGrid.Columns[e.ColumnIndex] is DataGridViewImageColumn && e.RowIndex >= 0)
         {
              DialogResult result = MessageBox.Show("Do you want to delete ?", "Warning", MessageBoxButtons.YesNo);
              if (result == DialogResult.Yes)
              {
                  try
                  {
                      Category category = new Category
                      {
                          CategoryId = categoryId,
                          CategoryName = txtCategoryname.Text,
                          CategoryDescription = txtDescription.Text,
                          ProductFromId = int.Parse(cboCategoryFrom.SelectedValue.ToString())
                      };
                      CategoyBLL.DeleteCategory(category);
                      MessageBox.Show("Delete Successful", "Warning");
                      txtCategoryname.Text = "";
                      txtCategoryname.Focus();
                  }
                  catch { MessageBox.Show("Delete fail", "Warning"); }
              }
              LoadCategory();
              txtCategoryname.Text = string.Empty;
              txtDescription.Text = string.Empty;
         }
 }
 private void pictureBox2_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtCategoryname.Text) || string.IsNullOrEmpty(cboCategoryFrom.Text))
     {
         MessageBox.Show("Information is required", "Warning");
         txtCategoryname.Focus();
     }
     else
     {
             try
             {
                 Category category = new Category
                 {
                     CategoryId = categoryId,
                     CategoryName = txtCategoryname.Text,
                     CategoryDescription = txtDescription.Text,
                     ProductFromId = int.Parse(cboCategoryFrom.SelectedValue.ToString())
                 };
                 CategoyBLL.UpdateCategory(category);
                 MessageBox.Show("Update Successful", "Warning");
                 txtCategoryname.Text = "";
                 txtCategoryname.Focus();
                 pictureBox1.Enabled = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Update Fail", "Warning");
             }
         LoadCategory();
         txtCategoryname.Text = string.Empty;
         txtDescription.Text = string.Empty;
     }
 }
 public bool UpdateCategory(Category category)
 {
     DALCategory categoryDAL = new DALCategory();
     return categoryDAL.UpdateCategory(category);
 }
 public bool InsertCategory(Category category)
 {
     DALCategory categoryDAL = new DALCategory();
     return categoryDAL.InsertCategory(category);
 }
 public bool DeleteCategory(Category category)
 {
     DALCategory categoryDAL = new DALCategory();
     return categoryDAL.DeleteCategory(category);
 }