public TheLoaiDTO LayTenTheLoai(int maTL) { TheLoaiDTO tl = null; OleDbConnection connection = DataProvider.CreateConnection(); string cmdText = "Select * from THELOAI where MaLoai = ?"; OleDbCommand command = new OleDbCommand(cmdText, connection); command.Parameters.Add("@MaLoai", OleDbType.Integer); command.Parameters["@MaLoai"].Value = maTL; OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { tl = new TheLoaiDTO(); tl.MaLoai = (int)reader["MaLoai"]; tl.TenTheLoai = (string)reader["TenTheLoai"]; } reader.Close(); connection.Close(); return(tl); }
public bool Xoa(TheLoaiDTO del) { string query = string.Empty; query += "DELETE FROM TheLoai WHERE [Matheloai] = @Matheloai"; using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@Matheloai", del.Matheloai); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); return(false); } } } return(true); }
public static List <TheLoaiDTO> loadAll() { string sCommand = "Select MaLoai, TenLoai from TheLoai"; con = DataProvider.openConnection(); DataTable dt = DataProvider.getDataTable(sCommand, con); int n = dt.Rows.Count; if (n <= 0) { DataProvider.closeConnection(con); return(null); } List <TheLoaiDTO> result = new List <TheLoaiDTO>(); for (int i = 0; i < n; i++) { int maLoai = int.Parse(dt.Rows[i]["MaLoai"].ToString()); string tenLoai = dt.Rows[i]["tenLoai"].ToString(); TheLoaiDTO theLoai = new TheLoaiDTO(maLoai, tenLoai); result.Add(theLoai); } DataProvider.closeConnection(con); return(result); }
public bool Sua(TheLoaiDTO edit) { string query = string.Empty; query += "UPDATE TacGia SET [MaTheLoai] = @matheloai, [TenTheLoai] = @Tentheloai WHERE [MaTheLoai] = @MaTheLoai"; using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@MaTheLoai", edit.Matheloai); cmd.Parameters.AddWithValue("@Tentheloai", edit.Tentheloai); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); return(false); } } } return(true); }
private void button_Xoa_Click(object sender, EventArgs e) { //1. Map data from GUI TheLoaiDTO temp = new TheLoaiDTO(); temp.MaTheLoai = this.textBox_Ma.Text; DialogResult dlr = MessageBox.Show("Bạn có muốn xóa thể loại với mã " + temp.MaTheLoai + " khổng?", "Xác nhận!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dlr == DialogResult.Yes) { //2. Kiểm tra data hợp lệ or not //3. Thêm vào DB bool kq = tlBUS.xoa(temp); if (kq == false) { MessageBox.Show("Xóa thể loai thất bại. Vui lòng kiểm tra lại dũ liệu"); } else { MessageBox.Show("Xóa thể loai thành công"); loadData_Vao_GridView(); this.dvg_QuanLyLoaiDocGia.FirstDisplayedScrollingRowIndex = 0; } } else { MessageBox.Show("Không xóa."); } }
public List <TheLoaiDTO> LayDanhSachTheLoai() { List <TheLoaiDTO> dsTheLoai = new List <TheLoaiDTO>(); conn = new SqlConnection(connstring); conn.Open(); SqlCommand command = new SqlCommand(); command.CommandType = System.Data.CommandType.Text; command.CommandText = "select * from TheLoai"; command.Connection = conn; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { TheLoaiDTO aThL = new TheLoaiDTO ( reader["MaTheLoai"].ToString(), reader["TenTheLoai"].ToString(), reader["GhiChu"].ToString() ); dsTheLoai.Add(aThL); } conn.Close(); return(dsTheLoai); }
public int Insert(TheLoaiDTO tl) { int flag = -1; try { string sql = "insert into THELOAI(TenTheLoai) values('" + tl.TenTheLoai + "')"; kn.Connect(); int nRow = kn.ExecuteNonQuery(CommandType.Text, sql, new SqlParameter { ParameterName = "TenTheLoai", Value = tl.TenTheLoai }); if (nRow > 0) { flag = 1; } } catch (Exception ex) { throw ex; } finally { kn.Disconnect(); } return(flag); }
private void button_Sua_Click(object sender, EventArgs e) { //1. Map data from GUI TheLoaiDTO tl = new TheLoaiDTO(); tl.MaTheLoai = this.textBox_Ma.Text; tl.TenTheLoai = this.textBox_TenLoaiDocGia.Text; DialogResult dlr = MessageBox.Show("Bạn có muốn sửa thể loại với mã " + tl.MaTheLoai + " không?", "Xác nhận!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dlr == DialogResult.Yes) { //2. Kiểm tra data hợp lệ or not if (tl.TenTheLoai.Length <= 0) { MessageBox.Show("Sửa thất bại, vui lòng kiểm tra lại thông tin."); return; } //3. Thêm vào DB bool kq = tlBUS.sua(tl); if (kq == false) { MessageBox.Show("Sửa thất bại. Vui lòng kiểm tra lại dũ liệu"); } else { MessageBox.Show("Sửa thành công"); this.loadData_Vao_GridView(); } } }
public List <TheLoaiDTO> FindTaiLieu(string ma) { conn = new SqlConnection(connstring); conn.Open(); SqlCommand command = new SqlCommand(); command.CommandType = System.Data.CommandType.Text; command.CommandText = "select * from TheLoai where MaTheLoai LIKE @ma"; command.Connection = conn; command.Parameters.AddWithValue("ma", "%" + ma + "%"); SqlDataReader reader = command.ExecuteReader(); List <TheLoaiDTO> ds = new List <TheLoaiDTO>(); while (reader.Read()) { TheLoaiDTO aThL = new TheLoaiDTO ( reader["MaTheLoai"].ToString(), reader["TenTheLoai"].ToString(), reader["GhiChu"].ToString() ); ds.Add(aThL); } conn.Close(); return(ds); }
public static List <DauSachDTO> SelecTitleBooks(TheLoaiDTO theLoai) { string sqlstr; if (theLoai != null) { sqlstr = $"EXEC dbo.SelecTitleBooks '{theLoai.Matl}'"; } else { sqlstr = "EXEC dbo.SelecTitleBooks null "; } List <DauSachDTO> dauSaches = new List <DauSachDTO>(); MySQL.Open(); using (SqlDataReader dataReader = MySQL.ExecuteSQL(sqlstr)) { while (dataReader.Read()) { dauSaches.Add( new DauSachDTO( dataReader["mads"].ToString(), dataReader["ten"].ToString(), Int32.Parse(dataReader["soluong"].ToString()), Int32.Parse(dataReader["songaytoida"].ToString()), Int32.Parse(dataReader["sotienphat"].ToString()), Int32.Parse(dataReader["giabia"].ToString()), theLoai ) ); } } MySQL.Close(); return(dauSaches); }
//public string ConnectionString { get => connectionString; set => connectionString = value; } public bool Them(TheLoaiDTO add) { string query = string.Empty; query += "INSERT INTO TheLoai ([Matheloai], [Tentheloai])"; query += "VALUES (@Matheloai,@Tentheloai)"; using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@Matheloai", add.Matheloai); cmd.Parameters.AddWithValue("@Tentheloai", add.Matheloai); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); return(false); } } } return(true); }
private void btnThem_Click(object sender, EventArgs e) { if ("them" != act) { grbInFor.Enabled = true; pnInFor.Visible = true; txtMaTheLoai.Enabled = false; txtMaTheLoai.Text = MaTuTang(); act = "them"; return; } TheLoaiDTO aThL = new TheLoaiDTO ( txtMaTheLoai.Text, txtTenTheLoai.Text, txtGhiChu.Text ); DialogResult result = MessageBox.Show("Bạn chắc chắn muốn thêm ?", " ", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { myTheLoaiBUL.ThemMotTheLoai(aThL); } if (result == DialogResult.No) { return; } viewDaTa(); deleteData(); txtMaTheLoai.Text = MaTuTang(); }
/// <summary> /// Tabpage Đầu sách /// </summary> /* Sự kiện chọn thể loại trong cbb để lấy dữ liệu đầu sách cho vào dgv */ private void cbbBookCate_SelectedValueChanged(object sender, EventArgs e) { if (cbbBookCate.SelectedValue != null) { TheLoaiDTO theLoai = cbbBookCate.SelectedValue as TheLoaiDTO; dgvTitles.DataSource = DauSachBUS.GetTitleBooks(theLoai); dgvTitles.Columns[0].Visible = false; dgvTitles.Columns[1].HeaderText = "Tên"; dgvTitles.Columns[2].HeaderText = "Số lượng"; dgvTitles.Columns[3].HeaderText = "Số ngày"; dgvTitles.Columns[4].HeaderText = "Số tiền phạt"; dgvTitles.Columns[5].HeaderText = "Giá bìa"; dgvTitles.Columns[6].Visible = false; btnAddBook.Enabled = true; btnDelBook.Enabled = true; btnDeleTit.Enabled = true; } if (dgvTitles.Rows.Count == 0) { lbNameTit.Text = String.Empty; lbQuantity.Text = String.Empty; lbDay.Text = String.Empty; lbMulct.Text = String.Empty; lbBookCate.Text = String.Empty; lbPrice.Text = String.Empty; dgvBooks.DataSource = null; btnAddBook.Enabled = false; btnDelBook.Enabled = false; btnDeleTit.Enabled = false; } }
public void Update(TheLoaiDTO theLoaiDTO) { theloai theloai = _mapper.Map <theloai>(theLoaiDTO); _unitOfWork.TheLoaiRepository.Update(theloai); _unitOfWork.CommitAsync(); }
public async Task <TheLoaiDTO> Add(TheLoaiDTO theLoaiDTO) { theloai theloai = _unitOfWork.TheLoaiRepository.Add(_mapper.Map <theloai>(theLoaiDTO)); await _unitOfWork.CommitAsync(); return(_mapper.Map <TheLoaiDTO>(theloai)); }
public bool Sua(TheLoaiDTO tlDTO) { if (tlDTO.Ten == "") { throw new Exception("Chưa nhập tên thể loại!"); } return(tlDAO.Sua(tlDTO)); }
public static TheLoai MappingTheLoai(this TheLoaiDTO theLoaiDto) { return(new TheLoai { MaTL = theLoaiDto.MaTL, TenTL = theLoaiDto.TenTL }); }
public void SuaTheLoai(TheLoaiDTO theLoaiDto) { var theLoai = _theLoaiRepository.GetBy(theLoaiDto.MaTL); theLoaiDto.MappingTheLoai(theLoai); _theLoaiRepository.Update(theLoai); }
private void frmCapNhatTheLoai_Load(object sender, EventArgs e) { TheLoaiDTO tl = tlBUS.LayTheLoaiTheoMa(matheloai); txtMaTheLoai.Text = matheloai.ToString(); txtTen.Text = tl.Ten; txtGhiChu.Text = tl.GhiChu; }
public TheLoaiDTO LayTenTheLoai(int maLoai) { TheLoaiDAO tlDAO = new TheLoaiDAO(); TheLoaiDTO tlDTO = null; tlDTO = tlDAO.LayTenTheLoai(maLoai); return(tlDTO); }
private void btnCapNhat_Click(object sender, EventArgs e) { TheLoaiDTO theLoai = new TheLoaiDTO(); theLoai.MaLoai = ((TheLoaiDTO)cmbLoaiSach.SelectedItem).MaLoai; theLoai.TenTheLoai = txtLoaiSach.Text; TheLoaiBUS.Modify(theLoai); QuanLyLoaiSach_Load(sender, e); }
public static int UpdatBookCategory(TheLoaiDTO theLoai) { string sqlstr = $"EXEC dbo.UpdatBookCategory '{theLoai.Matl}', N'{theLoai.Ten}' "; MySQL.Open(); int numrow = MySQL.ExecuteNonSQL(sqlstr); MySQL.Close(); return(numrow); }
private void btnThem_Click(object sender, EventArgs e) { TheLoaiDTO tl = new TheLoaiDTO(); tl.TenTheLoai = txtTenTheLoai.Text; if (TheLoaiBUS.ThemTheLoai(tl) == false) { MessageBox.Show("Du lieu nhap vao da co trong co so du lieu", "Thong bao"); } HienThiDanhSach(); }
/* Sự kiện sửa tên thể loại */ private void dgvBookCate_CellEndEdit(object sender, DataGridViewCellEventArgs e) { TheLoaiDTO theLoai = (dgvBookCate.DataSource as List <TheLoaiDTO>)[e.RowIndex]; int check = TheLoaiBUS.ChangeBookCategory(theLoai); if (check < 1) { MessageBox.Show("Lưu không thành công.", "Thông báo"); this.OnLoad(new EventArgs()); } }
/** * @param theLoaiDTO */ public void SuaTheLoai(TheLoaiDTO theLoaiDTO) { // TODO implement here try { theLoaiDAO.SuaTaiLieu(theLoaiDTO); } catch (Exception ex) { throw ex; } }
public static bool SuaTheLoai(TheLoaiDTO tl) { if (TheLoaiDAO.GetTheLoaiByMa(tl.MaTheLoai) != null) { TheLoaiDAO.Update(tl); return(true); } else { return(false); } }
public static bool ThemTheLoai(TheLoaiDTO tl) { if (TheLoaiDAO.GetTheLoaiByName(tl.TenTheLoai) == null) { TheLoaiDAO.Insert(tl); return(true); } else { return(false); } }
/** * @param theLoaiDTO */ public void ThemTheLoai(TheLoaiDTO theLoaiDTO) { // TODO implement here try { theLoaiDAO.ThemTheLoai(theLoaiDTO); } catch (Exception ex) { throw ex; } }
public static bool XoaTheLoai(TheLoaiDTO tl) { if (TheLoaiDAO.GetTheLoaiByName(tl.TenTheLoai) != null) { TheLoaiDAO.Delete(tl); return(true); } else { return(false); } }
public TheLoaiDTO timTheLoaitheoten(string TenTheLoai) { TheLoaiDTO theLoaiDTO = new TheLoaiDTO(); TheLoai tl = data.TheLoais.SingleOrDefault(u => u.TenTheLoai == TenTheLoai); theLoaiDTO.MaTheLoai = tl.MaTheLoai; theLoaiDTO.TenTheLoai = tl.TenTheLoai; theLoaiDTO.TrangThai = tl.TrangThai.Value; return(theLoaiDTO); }