private void btnAddNewCategory_Click(object sender, EventArgs e)
        {
            if (txtCategoryName.Text == "")
            {
                MessageBox.Show("Please Enter Category Name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtCategoryName.Focus();
                return;
            }

            CategoryDetails cd = new CategoryDetails();

            cd.CategoryName = txtCategoryName.Text;

            bool isexists = blc.CheckCategory(txtCategoryName.Text);

            if (isexists)
            {
                MessageBox.Show("Category Name Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCategoryName.Text = "";
                txtCategoryName.Focus();
            }
            else
            {
                int i = blc.AddNewCategory(cd);
                if (i > 0)
                {
                    LoadGrid();
                    MessageBox.Show("New Category Added Successfully", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtCategoryName.Text = "";
                    txtCategoryName.Focus();
                }
            }
        }
예제 #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtCategoryName.Text == "")
            {
                MessageBox.Show("Please Enter Category Name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtCategoryName.Focus();
                return;
            }
            CategoryDetails cd = new CategoryDetails();

            cd.Id           = Convert.ToInt32(txtId.Text);
            cd.CategoryName = txtCategoryName.Text;
            cd.AddedDate    = System.DateTime.Now;

            bool isexists = blc.CheckCategory(txtCategoryName.Text);

            if (isexists)
            {
                MessageBox.Show("Category Already Exists in Database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCategoryName.Text = "";
                txtCategoryName.Focus();
            }
            else
            {
                int i = blc.UpdateCategory(cd);
                if (i > 0)
                {
                    MessageBox.Show("Category Updated Successfully", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtCategoryName.Text = "";
                    txtCategoryName.Focus();
                }
            }
        }