예제 #1
0
 public bool InsertCategory(Category category)
 {
     try
     {
         contextDB.Categories.Add(category);
         contextDB.SaveChanges();
         return true;
     }
     catch { return false; }
 }
예제 #2
0
 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; }
 }
예제 #3
0
 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;
         }
 }
예제 #4
0
 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;
     }
 }
예제 #5
0
 public bool UpdateCategory(Category category)
 {
     DALCategory categoryDAL = new DALCategory();
     return categoryDAL.UpdateCategory(category);
 }
예제 #6
0
 public bool InsertCategory(Category category)
 {
     DALCategory categoryDAL = new DALCategory();
     return categoryDAL.InsertCategory(category);
 }
예제 #7
0
 public bool DeleteCategory(Category category)
 {
     DALCategory categoryDAL = new DALCategory();
     return categoryDAL.DeleteCategory(category);
 }