public string InsertThietBi(ThietBi ttThietBi) { string Message; SqlConnection con = new SqlConnection(strQuery); con.Open(); SqlCommand cmd = new SqlCommand("insert into ThietBi(TenTB,DonGia,SoLuong,TrangThai,MaLoaiTB) values(@tenTB,@donGia,@soLuong,@trangThai,@maLoaiTB)", con); cmd.Parameters.AddWithValue("@tenTB", ttThietBi.tenTB); cmd.Parameters.AddWithValue("@donGia", ttThietBi.donGia); cmd.Parameters.AddWithValue("@soluong", ttThietBi.soLuong); cmd.Parameters.AddWithValue("@trangThai", ttThietBi.trangThai); cmd.Parameters.AddWithValue("@maLoaiTB", ttThietBi.maLoaiTB); int result = cmd.ExecuteNonQuery(); if (result == 1) { Message = ttThietBi.tenTB + "them thanh cong"; } else { Message = ttThietBi.tenTB + "them khong thanh cong"; } con.Close(); return(Message); }
public bool DeleteThietBi(ThietBi ttThietBi) { SqlConnection con = new SqlConnection(strQuery); con.Open(); SqlCommand cmd = new SqlCommand("delete from ThietBi where MaTB=@idTB", con); cmd.Parameters.AddWithValue("@idTB", ttThietBi.maTB); cmd.ExecuteNonQuery(); con.Close(); return(true); }
public void UpdateThietBi(ThietBi ttThietBi) { SqlConnection con = new SqlConnection(strQuery); con.Open(); SqlCommand cmd = new SqlCommand("update ThietBi set TenTB=@tenTB, DonGia=@donGia, SoLuong=@soLuong, TrangThai=@trangthai, MaLoaiTB=@maLoaiTB where MaTB=@idTB", con); cmd.Parameters.AddWithValue("@idTB", ttThietBi.maTB); cmd.Parameters.AddWithValue("@tenTB", ttThietBi.tenTB); cmd.Parameters.AddWithValue("@donGia", ttThietBi.donGia); cmd.Parameters.AddWithValue("@soluong", ttThietBi.soLuong); cmd.Parameters.AddWithValue("@trangThai", ttThietBi.trangThai); cmd.Parameters.AddWithValue("@maLoaiTB", ttThietBi.maLoaiTB); cmd.ExecuteNonQuery(); con.Close(); }
public DataSet timKiemTB(ThietBi tkTB) { SqlConnection con = new SqlConnection(strQuery); con.Open(); SqlCommand cmd = new SqlCommand("select * from ThietBi where TenTB=@TenTB", con); cmd.Parameters.AddWithValue("@TenTB", tkTB.tenTB); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); cmd.ExecuteNonQuery(); sda.Fill(ds); con.Close(); return(ds); }