예제 #1
0
 public Sanpham GetsanphamByMASP(string strSP)
 {
     Sanpham sp = null;
     try
     {
         if (conn.State != ConnectionState.Open) conn.Open();
         OleDbCommand cmd = new OleDbCommand("select * from tbSanPham where masp=@masp order by MaSP ASC", conn);
         cmd.Parameters.Add("@masp", OleDbType.BSTR).Value = strSP;
         OleDbDataReader rd = cmd.ExecuteReader();
         if(rd.Read())
         {
             sp = new Sanpham();
             sp.Masanpham = rd["MaSP"].ToString();
             sp.Tensanpham = rd["TenSP"].ToString();
             sp.Soluong = (int)rd["SoLuong"];
             sp.DonGia = (int)rd["DonGia"];
             sp.XuatXu = rd["XuatXu"].ToString();
             sp.MaDanhMuc = rd["MaDM"].ToString();
             rd.Close();
         }
     }
     catch (Exception e)
     {
         conn.Close();
         Console.WriteLine(e.ToString());
     }
     return sp;
 }
예제 #2
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     int sl = Convert.ToInt32(txtSoluong.Text);
     int dg = Convert.ToInt32(txtDongia.Text);
     Sanpham sp = new Sanpham(txtMasp.Text, txtTensp.Text, sl, dg, txtXuatxu.Text, comboDanhmuc.SelectedValue.ToString());
     if (objSP.XoaSanPham(sp))
     {
         MessageBox.Show("Xóa sản phẩm thành công");
         dataGridView1.DataSource = objSP.GetSanPhamByMADM(SanhForm.strSanh_chon);
     }
     else
     {
         MessageBox.Show("Xóa sản phẩm thất bại");
     }
 }
예제 #3
0
 public bool Addsanpham(Sanpham sp)
 {
     try
     {
         if (conn.State != ConnectionState.Open) conn.Open();
         OleDbCommand cmd = new OleDbCommand("INSERT INTO tbSANPHAM([MASP],[TENSP],[SOLUONG],[DONGIA],[XUATXU],[MADM]) VALUES(@masp, @tensp, @soluong, @dongia, @xuatxu, @madm)", conn);
         cmd.Parameters.Add("@masp", OleDbType.BSTR).Value = sp.Masanpham;
         cmd.Parameters.Add("@tensp", OleDbType.BSTR).Value = sp.Tensanpham;
         cmd.Parameters.Add("@soluong", OleDbType.Numeric).Value = sp.Soluong;
         cmd.Parameters.Add("@dongia", OleDbType.Numeric).Value = sp.DonGia;
         cmd.Parameters.Add("@xuatxu", OleDbType.BSTR).Value = sp.XuatXu;
         cmd.Parameters.Add("@madm", OleDbType.BSTR).Value = sp.MaDanhMuc;
         cmd.ExecuteNonQuery();
         conn.Close();
         return true;
     }
     catch (Exception e)
     {
         conn.Close();
         return false;
     }
 }
예제 #4
0
 public bool Xoasanpham(Sanpham sp)
 {
     try
     {
         if (conn.State != ConnectionState.Open) conn.Open();
         string strcmd = "DELETE FROM tbSANPHAM where MASP='" + sp.Masanpham + "'";
         OleDbCommand cmd = new OleDbCommand(strcmd, conn);
         cmd.ExecuteNonQuery();
         conn.Close();
         return true;
     }
     catch (Exception e)
     {
         conn.Close();
         return false;
     }
 }
예제 #5
0
 public bool Updatesanpham(Sanpham sp)
 {
     try
     {
         if (conn.State != ConnectionState.Open) conn.Open();
         string strcmd = "UPDATE tbSANPHAM SET TENSP='" + sp.Tensanpham + "', SOLUONG='" + sp.Soluong.ToString() + "', DONGIA='" + sp.DonGia.ToString() + "', XUATXU='" + sp.XuatXu + "',MADM='" + sp.MaDanhMuc + "' where MASP='" + sp.Masanpham + "'";
         OleDbCommand cmd = new OleDbCommand(strcmd, conn);
         cmd.ExecuteNonQuery();
         conn.Close();
         return true;
     }
     catch (Exception e)
     {
         conn.Close();
         return false;
     }
 }
예제 #6
0
 public bool XoaSanPham(Sanpham sp)
 {
     return objSP.Xoasanpham(sp);
 }
예제 #7
0
 public bool UpdateSanPham(Sanpham sp)
 {
     return objSP.Updatesanpham(sp);
 }
예제 #8
0
 public bool AddSanPham(Sanpham sp)
 {
     return objSP.Addsanpham(sp);
 }