public ActionResult Create(LoaiSach collection) { try { if (ModelState.IsValid) { // TODO: Add insert logic here var dao = new LoaiSachDao(); long id = dao.Insert(collection); if (id > 0) { SetAlert("Thêm thành công", "success"); return(RedirectToAction("Index", "LoaiSach")); } else { ModelState.AddModelError("", "Thêm sản phẩm không thành công"); } } return(View(collection)); } catch { return(View("Index")); } }
private void btnThem_Click(object sender, EventArgs e) { LoaiSach data = new LoaiSach(); data.MaLoaiSach = txtMaLoaiSach.Text; if (data.MaLoaiSach.Equals("")) { MessageBox.Show("Mã loại sách không được trống!"); return; } data.TenLoaiSach = txtTenLoaiSach.Text; if (data.TenLoaiSach.Equals("")) { MessageBox.Show("Tên loại sách không được trống!"); return; } data.MoTa = txtMota.Text; if (objls.insertData(data)) { binData("", "", ""); MessageBox.Show("Thêm mới thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Thêm mới không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public List <LoaiSach> getAll(string Top, string Where, string Order) { List <LoaiSach> lst = new List <LoaiSach>(); string selectQuery = "select "; if (Top.Length != 0) { selectQuery += "Top " + Top; } selectQuery += "* "; selectQuery += "from tb_LoaiSach "; if (Where.Length != 0) { selectQuery += "Where " + Where; } if (Order.Length != 0) { selectQuery += "Order by " + Order; } using (SqlCommand cmd = new SqlCommand(selectQuery, openConnection())) { SqlDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { LoaiSach obj = new LoaiSach(); obj.LoaiSachIDataReader(dr); lst.Add(obj); } dr.Close(); } return(lst); }
public ActionResult Edit(LoaiSach collection) { try { if (ModelState.IsValid) { // TODO: Add insert logic here var dao = new LoaiSachDao(); var result = dao.Update(collection); if (result) { SetAlert("Sửa thành công", "success"); return(RedirectToAction("Index", "LoaiSach")); } else { ModelState.AddModelError("", "Cập nhật sản phẩm không thành công"); } } return(View(collection)); } catch { return(View("Index")); } }
private void btnSua_Click(object sender, EventArgs e) { int r = dgvLoaiSach.CurrentCell.RowIndex; if (r < 0) { MessageBox.Show("Chọn một bản ghi trước!"); return; } String id = dgvLoaiSach.CurrentRow.Cells[0].Value.ToString(); LoaiSach data = new LoaiSach(); data.TenLoaiSach = txtTenLoaiSach.Text; data.MaLoaiSach = id; if (data.TenLoaiSach.Equals("")) { MessageBox.Show("Tên loại sách không được trống!"); return; } data.MoTa = txtMota.Text; if (MessageBox.Show("Bạn muốn sửa bản ghi?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (objls.updateData(data)) { binData("", "", ""); MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Sửa không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void FrmSuaLoaiSach_Load(object sender, EventArgs e) { LoaiSach lschon = (LoaiSach)this.Tag; txtMa.Text = lschon.MaLoai.ToString(); txtLoaiSach.Text = lschon.TenLoai; }
private void btnLuu_Click(object sender, EventArgs e) { lsBUS lsB = new lsBUS(); LoaiSach ls = new LoaiSach(txtMaLS.Text, txtTenLS.Text, txtMoTa.Text); if (check == true) { if (lsB.CheckID(txtMaLS.Text)) { MessageBox.Show(txtMaLS.Text + " đã tồn tại!!!"); } else { if (check == true) { lsB.addLS(ls); } } } else { lsB.edit(ls); } grvLoaiSach.DataSource = lsB.getData(); }
public async Task <IActionResult> PutLoaiSach(int id, LoaiSach loaiSach) { if (id != loaiSach.Id) { return(BadRequest()); } _context.Entry(loaiSach).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoaiSachExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <LoaiSach> > PostLoaiSach(LoaiSach loaiSach) { _context.LoaiSach.Add(loaiSach); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLoaiSach", new { id = loaiSach.Id }, loaiSach)); }
public ActionResult DeleteConfirmed(string id) { LoaiSach loaiSach = db.LoaiSachs.Find(id); db.LoaiSachs.Remove(loaiSach); db.SaveChanges(); return(RedirectToAction("Index")); }
public string Insert(LoaiSach cate) { { db.LoaiSaches.Add(cate); db.SaveChanges(); return(cate.MaLoaiSach); } }
public int edit(LoaiSach r) { if (ls.edit(r) == 1) { return(1); } return(0); }
public async Task <ActionResult> DeleteConfirmed(int id) { LoaiSach loaiSach = await db.DanhSachLoaiSach.FindAsync(id); db.DanhSachLoaiSach.Remove(loaiSach); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public void SuaLoaiSach(LoaiSach loaiSach) { using (QLThuVienDataContext db = new QLThuVienDataContext()) { LoaiSach lsMoi = db.LoaiSaches.Single(ls => ls.pid == loaiSach.pid); lsMoi.Ten = loaiSach.Ten; db.SubmitChanges(); } }
public void XoaLoaiSach(string pid) { using (QLThuVienDataContext db = new QLThuVienDataContext()) { LoaiSach lsXoa = db.LoaiSaches.Single(ls => ls.pid == pid); lsXoa.Disable = true; db.SubmitChanges(); } }
public ActionResult Edit([Bind(Include = "MaLoaiSach,TenLoaiSach")] LoaiSach loaiSach) { if (ModelState.IsValid) { db.Entry(loaiSach).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(loaiSach)); }
public int edit(LoaiSach ls) { string sql = "update LoaiSach set Name=N'" + ls.Name + "',Description=N'" + ls.Description + "' where ID='" + ls.Id + "'"; if (data.Edit(sql) > 0) { return(1); } return(0); }
public IActionResult Create(LoaiSach loaiSach) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } context.LoaiSaches.Add(loaiSach); context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult ThemLoaiSach(string MaLoaiSach, string TenLoaiSach) { var theloaiDao = new TheLoaiDao(); var l = new LoaiSach(); l.MaLoaiSach = MaLoaiSach; l.TenLoaiSach = TenLoaiSach; var result = theloaiDao.insert(l); return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult> Edit([Bind(Include = "MaLoaiSach,TenLoaiSach,BiDanh,MoTa,HinhAnh,HienMenu,HienFooter,ThoiGianTao,TaoBoi,ThoiGianCapNhap,CapNhapBoi,MetaKeyword,MetaDescription,TrangThai")] LoaiSach loaiSach) { if (ModelState.IsValid) { db.Entry(loaiSach).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(loaiSach)); }
public ActionResult Create([Bind(Include = "MaLoaiSach,TenLoaiSach")] LoaiSach loaiSach) { if (ModelState.IsValid) { db.LoaiSachs.Add(loaiSach); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(loaiSach)); }
private void dataGridLoaiSach_SelectionChanged(object sender, SelectionChangedEventArgs e) { LoaiSach loaiSachDangChon = dataGridLoaiSach.SelectedItem as LoaiSach; if (loaiSachDangChon == null) { return; } this.lb_MaLoaiSachChon.Content = loaiSachDangChon.pid; this.lb_TenLoaiSachChon.Content = loaiSachDangChon.Ten; }
public ActionResult ThemLoai(LoaiSach ls) { if (ModelState.IsValid) { LoaiSach ls1 = new LoaiSach(); ls1.TenLoai = ls.TenLoai; cn.LoaiSaches.Add(ls1); cn.SaveChanges(); SetAlert("Thêm thành công!", "success"); } return(RedirectToAction("LoaiSach")); }
void binCmbLoaiSach() { LoaiSach item = new LoaiSach(); lst = obj.getAll("", "", ""); item.MaLoaiSach = ""; item.TenLoaiSach = "<All>"; lst.Insert(0, item); cmbLoaiSach.DataSource = lst; cmbLoaiSach.ValueMember = "maLoaiSach"; cmbLoaiSach.DisplayMember = "tenLoaiSach"; }
public List <LoaiSach> getLS() { List <LoaiSach> list = new List <LoaiSach>(); DataTable data = ls.getData(); foreach (DataRow item in data.Rows) { LoaiSach ls1 = new LoaiSach(item); list.Add(ls1); } return(list); }
public void ThemNganhKhoa(string ten) { using (QLThuVienDataContext db = new QLThuVienDataContext()) { LoaiSach loaiSachMoi = new LoaiSach { Ten = ten }; db.LoaiSaches.InsertOnSubmit(loaiSachMoi); db.SubmitChanges(); } }
public void ToExcel() { var listloai = new List <LoaiSach>(); var list = data.LoaiSaches.ToList(); foreach (var item in list) { var model = new LoaiSach(); model.Maloai = item.Maloai; model.Tenloai = item.Tenloai; listloai.Add(model); } ExcelPackage pck = new ExcelPackage(); ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Report"); ws.Cells["A1"].Value = "Communication"; ws.Cells["B1"].Value = "Com2"; ws.Cells["A2"].Value = "Report"; ws.Cells["B2"].Value = "Report2"; ws.Cells["A3"].Value = "Date"; ws.Cells["B3"].Value = string.Format("{0:dd MMMM yyyy} at {0:H: mm tt}", DateTimeOffset.Now); ws.Cells["A6"].Value = "Maloai"; ws.Cells["B6"].Value = "Tenloai"; int rowStart = 7; foreach (var item in list) { if (item.Maloai.Count() < 5) { ws.Row(rowStart).Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Row(rowStart).Style.Fill.BackgroundColor.SetColor(ColorTranslator.FromHtml(string.Format("pink"))); } ws.Cells[string.Format("A{0}", rowStart)].Value = item.Maloai; ws.Cells[string.Format("B{0}", rowStart)].Value = item.Tenloai; rowStart++; } ws.Cells["A:AZ"].AutoFitColumns(); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment: filename=" + "ExcelReport.xlsx"); Response.BinaryWrite(pck.GetAsByteArray()); Response.End(); }
public LoaiSach getLS() { LoaiSach ls = null; string sql = "select * from LoaiSach"; DataTable table = data.getData(sql); foreach (DataRow item in table.Rows) { ls = new LoaiSach(item); return(ls); } return(ls); }
public LoaiSach getLSbyID(string id) { LoaiSach ls1 = null; string sql = "select * from LoaiSach ls where ls.ID = '" + id + "'"; DataTable table = data.getData(sql); foreach (DataRow item in table.Rows) { ls1 = new LoaiSach(item); return(ls1); } return(ls1); }
public LoaiSach getIDbyName(string name) { LoaiSach ls1 = null; string sql = "select * from LoaiSach ls where ls.Name = N'" + name + "'"; DataTable table = data.getData(sql); foreach (DataRow item in table.Rows) { ls1 = new LoaiSach(item); return(ls1); } return(ls1); }