Example #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            string old  = dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim();
            string masp = txtMaSP.Text;

            if (old != masp)
            {
                MessageBox.Show("Không được sửa mã bánh!", "Thông Báo");
                return;
            }
            string        loai;
            string        nhasx;
            SqlConnection cnn = sqlConnectionData.Ketnoi();

            cnn.Open();
            SqlCommand    cmd = new SqlCommand("select * from LOAI where MaLoai='" + cbLoai.SelectedValue.ToString() + "'", cnn);
            SqlDataReader r   = cmd.ExecuteReader();


            r.Read();
            loai = r.GetString(0).ToString();
            r.Close();
            SqlCommand    cmd1 = new SqlCommand("select * from NHASX where MaSX='" + cbSX.SelectedValue.ToString() + "'", cnn);
            SqlDataReader r1   = cmd1.ExecuteReader();

            r1.Read();
            nhasx = r1.GetString(0).ToString();
            r1.Close();

            string      tensp   = txtTenSP.Text;
            int         gia     = int.Parse(txtGia.Text);
            int         soluong = int.Parse(txtsl.Text);
            SanPham_DTO sp      = new SanPham_DTO(masp, tensp, loai, gia, nhasx, soluong);

            SanPham_BUS.SuaSP(sp, txtMaSP.Text);
            dataGridView1.DataSource = SanPham_BUS.hienthi();
            cnn.Close();
        }