Example #1
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (CheckForm())
            {
                Category category = new Category();
                category = FormToCategory();

                CategoryArr oldCategoryArr = new CategoryArr();
                oldCategoryArr.Fill();

                if (!oldCategoryArr.IsContain(category.Name))
                {
                    if (category.Id == 0)
                    {
                        if (category.Insert())
                        {
                            MessageBox.Show("Data saved successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearForm();

                            CategoryArr categoryArr = new CategoryArr();
                            categoryArr.Fill();
                            category = categoryArr.GetCategoryWithMaxId();

                            CategoryArrToForm(category);
                        }
                    }
                    else
                    {
                        if (category.Update())
                        {
                            MessageBox.Show("Data updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearForm();

                            CategoryArr categoryArr = new CategoryArr();
                            categoryArr.Fill();
                            category = categoryArr.GetCategoryWithMaxId();
                            CategoryArrToForm(null);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Category already exsits", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ClearForm();
                }
            }
        }