public bool suaLoaiSanPham(DTO_LoaiSanPham lsp) { try { //Mở kết nối //_conn.Open(); //Query string SQL = string.Format("UPDATE LOAISANPHAM SET LSP_NAME=N'{0}', LSP_DVT=N'{1}' WHERE LSP_ID={2}", lsp.LSP_NAME, lsp.LSP_DVT, lsp.LSP_ID); //SqlCommand SqlCommand cmd = new SqlCommand(SQL, openConnect()); if (cmd.ExecuteNonQuery() > 0) { return(true); } } catch (Exception e) { Console.Write(e.StackTrace.ToString()); return(false); } finally { closeConnect(); } return(false); }
/// <summary> /// Thêm Loại sản phẩm /// </summary> /// <param name="lsp"></param> /// <returns>true</returns> public bool themLoaiSanPham(DTO_LoaiSanPham lsp) { try { // Mo KetNoi openConnect(); //query string SQL = string.Format("INSERT INTO LOAISANPHAM(LSP_NAME,LSP_DVT) VALUES(N'{0}',N'{1}')", lsp.LSP_NAME, lsp.LSP_DVT); // Mac dinh SqlCommand para la chuoi SqlCommand cmd = new SqlCommand(SQL, openConnect()); if (cmd.ExecuteNonQuery() > 0) { return(true); } } catch (Exception e) { Console.Write(e.StackTrace.ToString()); return(false); } finally { closeConnect(); } return(false); }
public static DTO_LoaiSanPham ConverToDTO(DataRow dr) { DTO_LoaiSanPham lsp = new DTO_LoaiSanPham(); lsp.MaLoaiSP = dr["MaLoaiSP"].ToString(); lsp.TenLoaiSP = dr["TenLoaiSP"].ToString(); lsp.TrangThai = bool.Parse(dr["TrangThai"].ToString()); return(lsp); }
private void btnSaveLSP_Click(object sender, EventArgs e) { if (txtNAMELSP.Text != "" && txtDVTLSP.Text != "") { if (txtIDLSP.Text != "") { int id = Convert.ToInt16(txtIDLSP.Text); DTO_LoaiSanPham dtolsp = new DTO_LoaiSanPham(id, txtNAMELSP.Text, txtDVTLSP.Text); if (busloaisanpham.suaLoaiSanPham(dtolsp)) { MessageBox.Show("Cập nhật hoàn tất"); } else { MessageBox.Show("Cập nhật thất bại"); } } else { // toi tao doi tuong DTO_LoaiSanPham dtolsp = new DTO_LoaiSanPham(0, txtNAMELSP.Text, txtDVTLSP.Text); // dùng buss thêm đối tượng if (busloaisanpham.themLoaiSanPham(dtolsp)) { MessageBox.Show("Thêm thành công"); } else { MessageBox.Show("Không thêm được"); } } clearLoaiSanPham(); } else { MessageBox.Show("Nhập thông tin đầy đủ ở các ô có `*`;"); } }
public bool suaLoaiSanPham(DTO_LoaiSanPham ob) { return(dalLoaiSanPham.suaLoaiSanPham(ob)); }
public bool themLoaiSanPham(DTO_LoaiSanPham ob) { return(dalLoaiSanPham.themLoaiSanPham(ob)); }