コード例 #1
0
        private void BtnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                var data = ((BindingSource)dataGridView1.DataSource).List;

                Category currentCategory = null;

                int id = int.Parse(dataGridView1.Rows[selectedRowIndex].Cells[0].Value.ToString());
                foreach (Category ct in data)
                {
                    if (ct.Id == id)
                    {
                        currentCategory = ct;
                        break;
                    }
                }

                AddNewCategory addNewCategory = new AddNewCategory(null, db, this, currentCategory);
                addNewCategory.Show();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show("Failed to edit category.");
            }
        }
コード例 #2
0
 private void BtnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         AddNewCategory addNewCategory = new AddNewCategory(null, db, this, null);
         addNewCategory.Show();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         MessageBox.Show("Failed to add category");
     }
 }
コード例 #3
0
 private void BtnAddCategory_Click(object sender, EventArgs e)
 {
     try
     {
         AddNewCategory addNewCategory = new AddNewCategory(this, db, null, null);
         addNewCategory.Show();
         // var categories = await categoryModel.GetAllCategoriesByType(type);
         // cbCategory.Items.AddRange(categories);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         MessageBox.Show("Failed to create new category");
     }
 }