Esempio n. 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (kiemtratrungdl() == true)
            {
                MessageBox.Show("Mã bánh không được trùng", "Thông Báo");
                return;
            }
            if (txtMaSP.Text == "" || txtGia.Text == "" || txtsl.Text == "" || txtTenSP.Text == "")
            {
                MessageBox.Show("Vui lòng điền đầy đủ thông tin", "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 masp = txtMaSP.Text;
            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.ThemSP(sp);
            dataGridView1.DataSource = SanPham_BUS.hienthi();
            cnn.Close();
        }
Esempio n. 2
0
        public static void ThemSP(SanPham_DTO sp)
        { 
            SqlConnection cnn= sqlConnectionData.Ketnoi();
            string sql = "insert into SANPHAM values(@ma,@ten,@loai,@dongia,@nhasx,@soluong)";
            SqlCommand cmd = new SqlCommand(sql, cnn);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add("@ma",SqlDbType.NVarChar,10);
            cmd.Parameters.Add("@ten",SqlDbType.NVarChar,50);
            cmd.Parameters.Add("@loai",SqlDbType.NVarChar,10);
            cmd.Parameters.Add("@dongia",SqlDbType.Int);
            cmd.Parameters.Add("@nhasx",SqlDbType.NVarChar,10);
            cmd.Parameters.Add("@soluong",SqlDbType.Int);

            cmd.Parameters["@ma"].Value = sp.masp;
            cmd.Parameters["@ten"].Value = sp.tensp;
            cmd.Parameters["@loai"].Value = sp.loaisp;
            cmd.Parameters["@dongia"].Value = sp.dongia;
            cmd.Parameters["@nhasx"].Value = sp.nhasx;
            cmd.Parameters["@soluong"].Value =sp.soluong;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
Esempio n. 3
0
        public static void SuaSP(SanPham_DTO sp,string macu)
        {
            SqlConnection cnn = sqlConnectionData.Ketnoi();
            string sql = "update SANPHAM set MaSP=@ma,TenSP=@ten,LoaiSP=@loai,Dongia=@dongia,NhaSX=nhasx,SoLuong=@soluong where MaSP='"+macu+"'";
            SqlCommand cmd = new SqlCommand(sql, cnn);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add("@ma", SqlDbType.NVarChar, 10);
            cmd.Parameters.Add("@ten", SqlDbType.NVarChar, 50);
            cmd.Parameters.Add("@loai", SqlDbType.NVarChar, 10);
            cmd.Parameters.Add("@dongia", SqlDbType.Int);
            cmd.Parameters.Add("@nhasx", SqlDbType.NVarChar, 10);
            cmd.Parameters.Add("@soluong", SqlDbType.Int);


            cmd.Parameters["@ma"].Value = sp.masp;
            cmd.Parameters["@ten"].Value = sp.tensp;
            cmd.Parameters["@loai"].Value = sp.loaisp;
            cmd.Parameters["@dongia"].Value = sp.dongia;
            cmd.Parameters["@nhasx"].Value = sp.nhasx;
            cmd.Parameters["@soluong"].Value = sp.soluong;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
Esempio n. 4
0
 public static void SuaSP(SanPham_DTO sp, string macu)
 {
     SanPham_DAO.SuaSP(sp,macu);
 }
Esempio n. 5
0
 public static void ThemSP(SanPham_DTO sp)
 {
     SanPham_DAO.ThemSP(sp);
 }
Esempio n. 6
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();
        }