Пример #1
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            try
            {
                string _name  = "";
                string _color = "";
                _name  = Regex.Replace(txt_name.Text, @"\s+", " ");
                _color = Regex.Replace(txt_productColor.Text, @"\s+", " ");

                int _amount = int.Parse(txt_productAmount.Text);
                int _price  = int.Parse(txt_productPrice.Text);

                if (_amount < 0)
                {
                    _amount = 0;
                }
                if (_price < 0)
                {
                    _price = 0;
                }

                bd.InsertToSQL(ref err, "EXEC [Update Product] " + IDProduct + ", " + "[" + _name + "], " + "[" + _color + "], " + "[" + comboBox1.Text + "], " + " " + _amount + ", " + _price);

                UpImage();

                MessageBox.Show("Successful!");
                stateChange = 1;

                btn_Edit.PerformClick();
            }
            catch
            {
                MessageBox.Show(err);
            }
        }
        private void btn_Save_Click(object sender, EventArgs e)
        {
            err = string.Empty;
            if (txt_productName.TextLength == 0 || txt_productID.TextLength == 0 || txt_productColor.TextLength == 0 || txt_productAmount.TextLength == 0 || txt_productPrice.TextLength == 0 || comboBox1.Text == "" || pictureBox1.Tag.ToString() == "Unchecked")
            {
                MessageBox.Show("Please fill all the fields!");
            }
            else
            {
                string sql = "EXEC [Add Product] " + int.Parse(txt_productID.Text) + ", [" + txt_productName.Text + "], [" + txt_productColor.Text + "], " + comboBox1.Text + ", " + int.Parse(txt_productAmount.Text) + ", " + int.Parse(txt_productPrice.Text);

                bd.InsertToSQL(ref err, sql);

                SqlConnection con = new SqlConnection("server=DESKTOP-64SRSV4; database=QuanLyShopQuanAo; Integrated Security=True");

                if (err != "")
                {
                    MessageBox.Show(err);
                }
                else
                {
                    con.Open();
                    ImageConverter imgcon = new ImageConverter();
                    byte[]         data   = (System.Byte[])imgcon.ConvertTo(pictureBox1.Image, Type.GetType("System.Byte[]"));

                    SqlCommand cmd = new SqlCommand("UPDATE Products SET [Image] = @data WHERE ProductID= " + int.Parse(txt_productID.Text), con);
                    cmd.Parameters.AddWithValue("@data", data);
                    cmd.ExecuteNonQuery();

                    MessageBox.Show(err + "successfully");
                    con.Close();
                }
                stateChange = 1;
            }
        }