コード例 #1
0
        private void AddProduct_Click(object sender, EventArgs e)
        {
            BL.Product prd = new BL.Product();
            if (state == "Add")
            {
                string prod_id, prod_name, price;
                int    qunt, ID_cat;

                prod_id   = textBox_PRD_ID.Text;
                prod_name = textBox_PRD_Name.Text;
                price     = textBox_PRD_Price.Text;
                qunt      = int.Parse(textBox_PRD_Qunt.Text);
                ID_cat    = Convert.ToInt32(comboBox_Categories.SelectedValue);

                MemoryStream ms = new MemoryStream();
                pictureBox_PRD_Img.Image.Save(ms, pictureBox_PRD_Img.Image.RawFormat);

                byte[] img = ms.ToArray();


                prd.Add_products(prod_id, prod_name, qunt, price, ID_cat, img);
                textBox_PRD_ID.Clear();
                textBox_PRD_Name.Clear();
                textBox_PRD_Price.Clear();
                textBox_PRD_Qunt.Clear();



                MessageBox.Show("Product Added Successfully", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                string prod_id, prod_name, price;
                int    qunt, ID_cat;

                prod_id   = textBox_PRD_ID.Text;
                prod_name = textBox_PRD_Name.Text;
                price     = textBox_PRD_Price.Text;
                qunt      = int.Parse(textBox_PRD_Qunt.Text);
                ID_cat    = Convert.ToInt32(comboBox_Categories.SelectedValue);


                MemoryStream ms = new MemoryStream();



                byte[] img = ms.ToArray();

                prd.update_products(prod_id, prod_name, qunt, price, ID_cat, img);
                MessageBox.Show("Product up to date Successfully", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            Prdct_Mngmnt.main_frm.dataGridView1.DataSource = prd.Get_allprdcts();
        }