public AddCategoryForm()
        {
            db = new PrjDAO();
            InitializeComponent();
            dataGridView1.DataSource          = db.getCategory();
            dataGridView1.AutoGenerateColumns = false;
            DataTable tb = db.getCategory();

            t = new List <int>();
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                t.Add(Convert.ToInt32(tb.Rows[i][0]));
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim().Equals(""))
            {
                MessageBox.Show("Category name can't be blank");
            }
            else
            {
                int parsedValue;
                if (txtID.Text.Trim().Equals(""))
                {
                    MessageBox.Show("ID can not be blank");
                    return;
                }

                else if (!int.TryParse(txtID.Text, out parsedValue))
                {
                    MessageBox.Show("This is a number only field");
                    return;
                }
                else
                {
                    int r = Convert.ToInt32(txtID.Text);
                    foreach (int i in t)
                    {
                        if (r == i)
                        {
                            MessageBox.Show("ID can not duplicate");
                            return;
                        }
                    }
                    db.addCategory(Convert.ToInt32(txtID.Text), txtName.Text);
                    MessageBox.Show("Add successfully");
                    dataGridView1.DataSource = db.getCategory();
                    dataGridView1.Refresh();
                }
            }
        }
Beispiel #3
0
        public AddProduct()
        {
            InitializeComponent();
            db = new PrjDAO();
            dataGridView1.DataSource          = db.getProductsandCategory();
            cbxCate.DataSource                = db.getCategory();
            cbxCate.DisplayMember             = "name";
            cbxCate.ValueMember               = "id";
            dataGridView1.AutoGenerateColumns = false;
            DataTable tb = db.getProductsandCategory();

            t = new List <int>();
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                t.Add(Convert.ToInt32(tb.Rows[i][0]));
            }
        }