private void btDongy_Click(object sender, EventArgs e) { try { SachDto sach = new SachDto(); sach.TenSach = txtTensach.Text; if (sach.TenSach.Length == 0) { MessageBox.Show("Bạn chưa nhập tên sách !!"); return; } sach.LoaiSach = ((LoaiSachDto)cmbLoaisach.SelectedItem).MLoaiSach; sach.SoTrang = (int)numSotrang.Value; sach.TrangThai = trangThai; sach.NgonNgu = ((NgonNguDto)cmbNgonngu.SelectedItem).MaNgonNgu; sach.TacGia = txtTacgia.Text; sach.MSach = mSach; if (type == 0) { BUS.SachBus.Add(sach); MessageBox.Show("Thêm thành công"); } else { BUS.SachBus.Update(sach); MessageBox.Show("Cập nhật thành công"); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static IList GetList() { ArrayList ds = new ArrayList(); OleDbConnection cn; cn = DataProvider.ConnectionData(); string strSQL; strSQL = "Select * From Sach"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); OleDbDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { SachDto sach = new SachDto(); sach.MSach = (int)dr["MSach"]; sach.TenSach = (String)dr["TenSach"]; sach.LoaiSach = (int)dr["LoaiSach"]; sach.TacGia = (String)dr["TacGia"]; sach.TrangThai = (bool)dr["TrangThai"]; sach.SoTrang = (int)dr["SoTrang"]; sach.NgonNgu = (int)dr["NgonNgu"]; ds.Add(sach); } dr.Close(); cn.Close(); return ds; }
public static int Add(SachDto sach) { OleDbConnection cn; cn = DataProvider.ConnectionData(); string strSQL; strSQL = "Insert into Sach(TenSach,LoaiSach,TacGia,TrangThai,SoTrang,NgonNgu) values (?,?,?,?,?,?)"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@TenSach", OleDbType.WChar); cmd.Parameters.Add("@LoaiSach", OleDbType.Integer); cmd.Parameters.Add("@TacGia", OleDbType.WChar); cmd.Parameters.Add("@TrangThai", OleDbType.Boolean); cmd.Parameters.Add("@SoTrang", OleDbType.Integer); cmd.Parameters.Add("@NgonNgu", OleDbType.Integer); cmd.Parameters["@TenSach"].Value = sach.TenSach; cmd.Parameters["@LoaiSach"].Value = sach.LoaiSach; cmd.Parameters["@TacGia"].Value = sach.TacGia; cmd.Parameters["@TrangThai"].Value = sach.TrangThai; cmd.Parameters["@SoTrang"].Value = sach.SoTrang; cmd.Parameters["@NgonNgu"].Value = sach.NgonNgu; cmd.ExecuteNonQuery(); strSQL = "Select @@IDENTITY"; cmd = new OleDbCommand(strSQL, cn); sach.MSach = (int)cmd.ExecuteScalar(); cn.Close(); return sach.MSach; }
void Find() { try { int pos = cmbTimkiem.SelectedIndex; SachDto sach = new SachDto(); SachDto sach2 = new SachDto(); sach.TenSach = null; sach.LoaiSach = -1; sach.SoTrang = -1; sach.TrangThai = true; sach.NgonNgu = -1; sach.TacGia = null; lbLoaitimkiem.Visible = true; lbThongbao.Text = ""; switch (pos) { case 0: lbLoaitimkiem.Text = ""; sach.TenSach = ""; break; case 1: lbLoaitimkiem.Text = "Tên sách"; sach.TenSach = txtTensachTacgia.Text; if (sach.TenSach.ToString().Length == 0) { lbThongbao.Text = "Bạn chưa nhập tên sách cần tìm !!"; return; } break; case 2: lbLoaitimkiem.Text = "Loại sách"; sach.LoaiSach = ((LoaiSachDto)cmbLoaisachNgonngu.SelectedItem).MLoaiSach; break; case 3: lbLoaitimkiem.Text = "Tác giả"; sach.TacGia = txtTensachTacgia.Text; if (sach.TacGia.ToString().Length == 0) { lbThongbao.Text = "Bạn chưa nhập tác giả cần tìm !!"; return; } break; case 4: lbLoaitimkiem.Text = "Số trang"; sach.SoTrang = (int)numSotrangdau.Value; sach2.SoTrang = (int)numSotrangsau.Value; break; case 5: lbLoaitimkiem.Text = "Ngôn ngữ"; sach.NgonNgu = ((NgonNguDto)cmbLoaisachNgonngu.SelectedItem).MaNgonNgu; break; } DataSet ds = BUS.SachBus.Timsach(sach, sach2); DataTable dt = new DataTable(); dt.Columns.Add("Chọn", System.Type.GetType("System.Boolean")); dt.Columns.Add("Mã sách", System.Type.GetType("System.Int16")); dt.Columns.Add("Tên sách", System.Type.GetType("System.String")); foreach (DataRow row in ds.Tables[0].Rows) { DataRow rows = dt.NewRow(); rows[0] = false; rows[1] = row[0]; rows[2] = row[1]; dt.Rows.Add(rows); } dtgDanhmucsach.Columns.Clear(); dtgDanhmucsach.DataSource = dt; dtgDanhmucsach.Columns[2].Width = 200; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void Update(SachDto sach) { SachDao.Update(sach); }
public static DataSet Timsach(SachDto sach, SachDto sach2) { return SachDao.Timsach(sach, sach2); }
public static DataSet Search(SachDto sach, SachDto sach2) { return SachDao.Search(sach, sach2); }
public static int Add(SachDto sach) { return SachDao.Add(sach); }
public static void Update(SachDto sach) { OleDbConnection cn; cn = DataProvider.ConnectionData(); string strSQL; strSQL = "Update Sach Set TenSach = ? , LoaiSach = ? , TacGia =?, TrangThai=?, SoTrang=?, NgonNgu=? Where MSach = ?"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@TenSach", OleDbType.WChar); cmd.Parameters.Add("@LoaiSach", OleDbType.Integer); cmd.Parameters.Add("@TacGia", OleDbType.WChar); cmd.Parameters.Add("@TrangThai", OleDbType.Boolean); cmd.Parameters.Add("@SoTrang", OleDbType.Integer); cmd.Parameters.Add("@NgonNgu", OleDbType.Integer); cmd.Parameters.Add("@MSach", OleDbType.Integer); cmd.Parameters["@TenSach"].Value = sach.TenSach; cmd.Parameters["@LoaiSach"].Value = sach.LoaiSach; cmd.Parameters["@TacGia"].Value = sach.TacGia; cmd.Parameters["@TrangThai"].Value = sach.TrangThai; cmd.Parameters["@SoTrang"].Value = sach.SoTrang; cmd.Parameters["@NgonNgu"].Value = sach.NgonNgu; cmd.Parameters["@MSach"].Value = sach.MSach; cmd.ExecuteNonQuery(); cn.Close(); }
public static DataSet Timsach(SachDto sach, SachDto sach2) { OleDbConnection cn; cn = DataProvider.ConnectionData(); DataSet ds = new DataSet(); ; string strSQL; strSQL = "Select MSach, TenSach From Sach Where"; if (sach.TenSach != null) { strSQL += " TenSach like '%" + sach.TenSach + "%'"; } else if (sach.LoaiSach != -1) { strSQL += " LoaiSach = " + sach.LoaiSach; } else if (sach.TacGia != null) { strSQL += " TacGia like '%" + sach.TacGia + "%'"; } else if (sach.SoTrang != -1) { strSQL += " SoTrang >= " + sach.SoTrang + " and SoTrang <= " + sach2.SoTrang; } else { strSQL += " NgonNgu = " + sach.NgonNgu; } strSQL += " and TrangThai = true"; OleDbDataAdapter adp = new OleDbDataAdapter(strSQL, cn); adp.Fill(ds); cn.Close(); return ds; }
void Find() { try { int pos = cmbTimkiem.SelectedIndex; SachDto sach = new SachDto(); SachDto sach2 = new SachDto(); sach.TenSach = null; sach.LoaiSach = -1; sach.SoTrang = -1; sach.TrangThai = true; sach.NgonNgu = -1; sach.TacGia = null; lbThongbao.Text = ""; //lbLoaitimkiem.Visible = true; switch (pos) { case 0: sach.TenSach = ""; break; case 1: sach.TenSach = txtTensachTacgia.Text; if (sach.TenSach.ToString().Length == 0) { lbThongbao.Text = "Bạn chưa nhập tên sách cần tìm !!"; return; } break; case 2: lbLoaitimkiem.Text = "Loại sách"; sach.LoaiSach = ((LoaiSachDto)cmbLoaisachNgonngu.SelectedItem).MLoaiSach; break; case 3: lbLoaitimkiem.Text = "Tác giả"; sach.TacGia = txtTensachTacgia.Text; if (sach.TacGia.ToString().Length == 0) { lbThongbao.Text = "Bạn chưa nhập tác giả cần tìm !!"; return; } break; case 4: lbLoaitimkiem.Text = "Số trang"; sach.SoTrang = (int)numSotrangdau.Value; sach2.SoTrang = (int)numSotrangsau.Value; break; case 5: lbLoaitimkiem.Text = "Ngôn ngữ"; sach.NgonNgu = ((NgonNguDto)cmbLoaisachNgonngu.SelectedItem).MaNgonNgu; break; case 6: if (cmbLoaisachNgonngu.SelectedIndex == 0) sach.TrangThai = false; else sach.TrangThai = true; break; } DataSet ds = BUS.SachBus.Search(sach, sach2); dtgDanhmucsach.DataSource = ds.Tables[0]; dtgDanhmucsach.Columns[1].Width += 250; dtgDanhmucsach.Columns[0].HeaderText = "Mã sách"; dtgDanhmucsach.Columns[1].HeaderText = "Tên sách"; } catch (Exception ex) { MessageBox.Show(ex.Message); } }