private void ThemSach() { if (tblId.Text == "" || tblTenSach.Text == "" || cbTacgia.Text == "" || cbTheloai.Text == "") { MessageBox.Show("Chưa nhập đủ thông tin"); return; } List <sach> data = db.saches.Where(t => t.MaSach == tblId.Text).ToList(); if (data.Count > 0) { MessageBox.Show("mã sách đã tồn tại"); return; } else { sach sa = new sach(); sa.MaSach = tblId.Text; sa.TenSach = tblTenSach.Text; sa.IDTacGia = int.Parse(cbTacgia.SelectedValue.ToString()); sa.IDTheLoai = int.Parse(cbTheloai.SelectedValue.ToString()); db.saches.InsertOnSubmit(sa); db.SubmitChanges(); MessageBox.Show("Thêm thành công"); } }
public bool Edit(sach entity) { var obj = db.saches.First(m => m.masach == entity.masach); if (obj != null) { try { obj.tensach = entity.tensach; obj.tentacgia = entity.tentacgia; obj.manxb = entity.manxb; obj.namxb = entity.namxb; obj.sotrang = entity.sotrang; obj.giatien = entity.giatien; obj.soluong = entity.soluong; obj.ngonngu = entity.ngonngu; obj.theloai = entity.theloai; db.SubmitChanges(); } catch (Exception) { return(false); throw; } } return(true); }
public ActionResult Create([Bind(Include = "idsach,tensach,tacgia,idnxb,idlv,giaxuat,gianhap")] sach sach) { if (ModelState.IsValid) { foreach (sach s in db.saches) { if (sach.tensach == s.tensach) { ModelState.AddModelError("", "Trùng tên sách hoặc sách đã tồn tại"); ViewBag.idlv = new SelectList(db.linhvucs, "idlv", "tenlv", sach.idlv); ViewBag.idnxb = new SelectList(db.nxbs, "idnxb", "tennxb", sach.idnxb); return(View()); } } tonkho tk = new tonkho(); tk.idsach = sach.idsach; tk.thoidiem = DateTime.Now; tk.soluongton = 0; db.tonkhoes.Add(tk); db.saches.Add(sach); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idlv = new SelectList(db.linhvucs, "idlv", "tenlv", sach.idlv); ViewBag.idnxb = new SelectList(db.nxbs, "idnxb", "tennxb", sach.idnxb); return(View(sach)); }
public ActionResult Edit([Bind(Prefix = "phieunhap")] phieunhap phieunhap, [Bind(Prefix = "ct")] ctpn[] ctpn) { if (ModelState.IsValid) { int idpn = phieunhap.idpn; int idct = 1; //thêm chi tiết sửa vào database foreach (ctpn ct in ctpn) { ct.idpn = idpn; ct.idctpn = idct; idct++; sach s = db.sach.Find(ct.idsach); if (s.soluongton != null) { s.soluongton = s.soluongton + ct.soluong; } else { s.soluongton = ct.soluong; } } //xóa chi tiết cũ trong database var ctpncu = db.ctpn.Where(ct => ct.idpn == phieunhap.idpn).ToList(); foreach (var ct in ctpncu) { sach s = db.sach.Find(ct.idsach); int soluonghientai = (int)(s.soluongton - ct.soluong); if (soluonghientai < 0) { ViewBag.idsach = new SelectList(db.sach, "idsach", "tensach"); ViewBag.idnxb = new SelectList(db.nxb, "idnxb", "tennxb", phieunhap.idnxb); phieunhapviewmodel pnvm = new phieunhapviewmodel(); phieunhap.ctpn = ctpn; pnvm.phieunhap = phieunhap; return(View(pnvm)); } s.soluongton = soluonghientai; db.ctpn.Remove(ct); } foreach (ctpn ct in ctpn) { db.ctpn.Add(ct); } db.Entry(phieunhap).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idsach = new SelectList(db.sach, "idsach", "tensach"); ViewBag.idnxb = new SelectList(db.nxb, "idnxb", "tennxb", phieunhap.idnxb); phieunhapviewmodel pnvm1 = new phieunhapviewmodel(); phieunhap.ctpn = ctpn; pnvm1.phieunhap = phieunhap; return(View(pnvm1)); }
public ActionResult DeleteConfirmed(int id) { sach sach = db.sach.Find(id); db.sach.Remove(sach); db.SaveChanges(); return(RedirectToAction("Index")); }
public bool sua(sach s) { if (string.IsNullOrEmpty(s.maSach)) { return(false); } sach.update(s); return(true); }
public ActionResult Create([Bind(Prefix = "danhmucsachdaban")] danhmucsachdaban danhmucsachdaban, [Bind(Prefix = "ct")] ctdmsdb[] ctdmsdb) { danhmucsachdabanviewmodel dmvm = new danhmucsachdabanviewmodel(); if (ModelState.IsValid) { danhmucsachdaban.tinhtrang = "Waiting"; danhmucsachdaban.sotiendathanhtoan = 0; int iddmsdb = 1; if (db.danhmucsachdaban.Any()) { iddmsdb = db.danhmucsachdaban.Max(o => o.iddmsdb) + 1; } int idct = 1; decimal tongtien = 0; foreach (ctdmsdb ct in ctdmsdb) { ct.iddmsdb = iddmsdb; ct.idctdmsdb = idct; idct++; hangtoncuadaily htdl = db.hangtoncuadaily.FirstOrDefault(o => o.iddl == danhmucsachdaban.iddl && o.idsach == ct.idsach); //kiem tra xem so luong sach đã bán có lớn hơn số lượng sách xuất cho dai ly do if (htdl != null && htdl.soluongchuaban >= ct.soluong) { htdl.soluongchuaban = htdl.soluongchuaban - ct.soluong; db.Entry(htdl).State = EntityState.Modified; } else { ModelState.AddModelError("", "số sách đã bán lớn hơn số sách xuất cho đại lý"); ViewBag.idsach = new SelectList(db.sach, "idsach", "tensach"); ViewBag.iddl = new SelectList(db.daily, "iddl", "tendl", danhmucsachdaban.iddl); dmvm.danhmucsachdaban = danhmucsachdaban; return(View(dmvm)); } tongtien += (decimal)(ct.soluong * htdl.sach.giaxuat); //tim nxb cua cuon sach da duoc ban nay sach s = db.sach.Find(ct.idsach); nxb n = db.nxb.Find(s.idnxb); n.sotienphaitra += ct.soluong * s.gianhap; } danhmucsachdaban.sotienconno = tongtien; danhmucsachdaban.ctdmsdb = ctdmsdb; db.danhmucsachdaban.Add(danhmucsachdaban); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idsach = new SelectList(db.sach, "idsach", "tensach"); ViewBag.iddl = new SelectList(db.daily, "iddl", "tendl", danhmucsachdaban.iddl); dmvm.danhmucsachdaban = danhmucsachdaban; return(View(dmvm)); }
public bool insert(sach s) { if (dataTable("select * from SACH where MaSach ='" + s.maSach + "'").Rows.Count > 0) { return(false); } string sqlCommand = string.Format("insert into SACH values ('{0}',N'{1}','{2}','{3}','{4}','{5}','{6}',N'{7}','{8}')", s.maSach, s.tenSach, s.namXB, s.maXB, s.maTG, s.maTL, s.maVT, s.tinhTrang, s.ngonNgu); Excute(sqlCommand); return(true); }
public ActionResult Edit([Bind(Include = "idsach,tensach,tacgia,idnxb,idlv,giaxuat,gianhap")] sach sach) { if (ModelState.IsValid) { db.Entry(sach).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idlv = new SelectList(db.linhvucs, "idlv", "tenlv", sach.idlv); ViewBag.idnxb = new SelectList(db.nxbs, "idnxb", "tennxb", sach.idnxb); return(View(sach)); }
public ActionResult Create([Bind(Prefix = "phieunhap")] phieunhap phieunhap, [Bind(Prefix = "ct")] ctpn[] ctpn) { if (ModelState.IsValid) { int idpn = 1; if (db.phieunhap.Any()) { idpn = db.phieunhap.Max(o => o.idpn) + 1; } int idct = 1; foreach (ctpn ct in ctpn) { ct.idpn = idpn; ct.idctpn = idct; idct++; sach s = db.sach.Find(ct.idsach); if (s.idnxb != phieunhap.idnxb) { ModelState.AddModelError("", "nxb nay khong co ban cuon sach nay"); ViewBag.idnxb = new SelectList(db.nxb, "idnxb", "tennxb", phieunhap.idnxb); ViewBag.idsach = new SelectList(db.sach, "idsach", "tensach"); phieunhap.ctpn = ctpn; phieunhapviewmodel pnvm = new phieunhapviewmodel(); pnvm.phieunhap = phieunhap; return(View(pnvm)); } if (s.soluongton != null) { s.soluongton = s.soluongton + ct.soluong; } else { s.soluongton = ct.soluong; } } phieunhap.ctpn = ctpn; TimeSpan time = DateTime.Now.TimeOfDay; phieunhap.ngaynhap = phieunhap.ngaynhap + time; db.phieunhap.Add(phieunhap); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idnxb = new SelectList(db.nxb, "idnxb", "tennxb", phieunhap.idnxb); ViewBag.idsach = new SelectList(db.sach, "idsach", "tensach"); phieunhap.ctpn = ctpn; phieunhapviewmodel pnvm = new phieunhapviewmodel(); pnvm.phieunhap = phieunhap; return(View(pnvm)); }
public ActionResult Xoasach(int id) { //lay ra doi tuong theo ma sach sach = db.saches.SingleOrDefault(n => n.idsach == id); ViewBag.idsach = sach.idsach; if (sach == null) { Response.StatusCode = 404; return(null); } return(View(sach)); }
public ActionResult Create([Bind(Include = "idsach,tensach,tacgia,idnxb,idlv,soluong,giaxuat,gianhap")] sach sach) { if (ModelState.IsValid) { db.sach.Add(sach); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idlv = new SelectList(db.linhvuc, "idlv", "tenlv", sach.idlv); ViewBag.idnxb = new SelectList(db.nxb, "idnxb", "tennxb", sach.idnxb); return(View(sach)); }
public ActionResult Suasach(sach s, HttpPostedFileBase fileupload, FormCollection f) { ViewBag.idnxb = new SelectList(db.nxbs.ToList().OrderBy(n => n.tennxb), "idnxb", "tennxb"); ViewBag.idchude = new SelectList(db.chudes.ToList().OrderBy(n => n.tenchude), "idchude", "tenchude"); sach smoi = db.saches.First(n => n.idsach == s.idsach); int nxb = int.Parse(f["idnxb"]); int cd = int.Parse(f["idchude"]); string mota = f["mota"]; string anhbia = f["anhbia"]; decimal gia = decimal.Parse(f["gia"]); string noidung = f["noidung"]; string linktai = f["linktai"]; if (fileupload == null) { ViewBag.Thongbao = "Vui lòng chọn ảnh bìa"; return(View()); } //them vao csdl else { if (ModelState.IsValid) { //luu ten file, them thu vien system.io var fileName = Path.GetFileName(fileupload.FileName); //luu duong dan var path = Path.Combine(Server.MapPath("~/Anhbia"), fileName); //kiem tra anh da ton tai chua if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { //luu hinh anh vao duong dan fileupload.SaveAs(path); } smoi.anhbia = fileName; smoi.tensach = s.tensach; smoi.idchude = cd; smoi.idnxb = nxb; smoi.mota = mota; smoi.gia = gia; smoi.noidung = noidung; smoi.linktai = linktai; UpdateModel(smoi); db.SubmitChanges(); } return(RedirectToAction("sach")); } }
// GET: saches/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } sach sach = db.saches.Find(id); if (sach == null) { return(HttpNotFound()); } return(View(sach)); }
public GioHang(int idsach) { sidsach = idsach; sach hang = data.saches.Single(n => n.idsach == sidsach); sTenHangHoa = hang.tensach; sAnhBia = hang.anhbia; sMoTa = hang.mota; sLinkThanhToan = hang.LinkThanhToan; slinkTaiSach = hang.linktai; dDonGia = double.Parse(hang.gia.ToString()); dGiaMoi = double.Parse(hang.GiaMoi.ToString()); iSoLuong = 1; }
private void XoaSach() { if (tblId.Text == "" || tblTenSach.Text == "" || cbTacgia.Text == "" || cbTheloai.Text == "") { MessageBox.Show("Chọn một dòng cần xóa"); return; } sach sa = db.saches.Single(item => item.MaSach == tblId.Text); db.saches.DeleteOnSubmit(sa); db.SubmitChanges(); MessageBox.Show("Xóa thành công"); }
private void SuaSach() { if (tblId.Text == "" || tblTenSach.Text == "" || cbTacgia.Text == "" || cbTheloai.Text == "") { MessageBox.Show("Chọn một dòng cần sửa"); return; } sach sa = db.saches.Single(item => item.MaSach == tblId.Text); sa.TenSach = tblTenSach.Text; sa.IDTacGia = int.Parse(cbTacgia.SelectedValue.ToString()); sa.IDTheLoai = int.Parse(cbTheloai.SelectedValue.ToString()); db.SubmitChanges(); MessageBox.Show("Sửa thành công"); }
public ActionResult Xacnhanxoasach(int id) { //lay ra doi tuong theo ma sach sach = db.saches.SingleOrDefault(n => n.idsach == id); ViewBag.idsach = sach.idsach; if (sach == null) { Response.StatusCode = 404; return(null); } db.saches.DeleteOnSubmit(sach); db.SubmitChanges(); return(RedirectToAction("sach")); }
public ActionResult Suasach(int id) { //lay ra doi tuong theo ma sach sach = db.saches.SingleOrDefault(n => n.idsach == id); ViewBag.idsach = sach.idsach; if (sach == null) { Response.StatusCode = 404; return(null); } ViewBag.idnxb = new SelectList(db.nxbs.ToList().OrderBy(n => n.tennxb), "idnxb", "tennxb"); ViewBag.idchude = new SelectList(db.chudes.ToList().OrderBy(n => n.tenchude), "idchude", "tenchude"); return(View(sach)); }
public int Add(sach entity) { try { db.saches.InsertOnSubmit(entity); db.SubmitChanges(); return(entity.masach); } catch (Exception) { return(0); throw; } }
// GET: saches/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } sach sach = db.saches.Find(id); if (sach == null) { return(HttpNotFound()); } ViewBag.idlv = new SelectList(db.linhvucs, "idlv", "tenlv", sach.idlv); ViewBag.idnxb = new SelectList(db.nxbs, "idnxb", "tennxb", sach.idnxb); return(View(sach)); }
private void Insert(object sender, EventArgs e) { try { sach s = new sach(); s.maSach = BookID.Text; s.tenSach = BookTitle.Text; s.namXB = DatePublic.Value.ToString(); s.maXB = PubID.SelectedValue.ToString(); s.maTG = AuthorID.SelectedValue.ToString(); s.maTL = BCategoryID.SelectedValue.ToString(); s.maVT = LocationID.SelectedValue.ToString(); s.tinhTrang = State.SelectedItem.ToString(); s.ngonNgu = LanguageID.SelectedValue.ToString(); if (s.isNull()) { toolTip1.ToolTipTitle = "Warning"; toolTip1.Show("Please enter full information", windowsUIButtonPanel1, windowsUIButtonPanel1.Location, 5000); return; } else { if (sach.them(s)) { BookForm_Load(sender, e); resetText(); } else { if (sach.sua(s)) { BookForm_Load(sender, e); resetText(); } else { return; } } } } catch (Exception exc) { MessageBox.Show(exc.Message, "Oops", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void ViewListsach(listsach a) { if (a.dssach.Length > 0) { for (int i = 0; i < a.dssach.Length; i = i + 1) { sach sach = a.dssach[i]; Console.WriteLine("Ten sach: ", sach.Tensach); Console.WriteLine("Ma sach IBNS: ", sach.Masach_ISBN); Console.WriteLine(); } } else { Console.WriteLine("Khong co sach trong thu vien"); } }
private void datagrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { int rowindex = datagrid.SelectedIndex; if (rowindex == -1) { return; } else { var nhacungcapTable1 = from item in db.GetTable <nhaCungCap>() select item; var nhacungcapTable2 = from item in db.GetTable <theLoai>() select item; var nhacungcapTable3 = from item in db.GetTable <tacGia>() select item; sach sa = (sach)datagrid.SelectedItem; tblId.Text = sa.MaSach; tblTenSach.Text = sa.TenSach; cbTacgia.SelectedValue = sa.IDTacGia; cbTheloai.Text = sa.theLoai.TheLoai; } }
public Boolean Them(string maSach, string tenSach, string tacGia, long soLuong, long gia, string soTap, DateTime ngayNhap, string maLoai) { if (ktMa(maSach) == false) { return(false); } sach s = new sach(); s.masach = maSach; s.tensach = tenSach; s.tacgia = tacGia; s.soluong = soLuong; s.gia = gia; s.sotap = soTap; s.NgayNhap = ngayNhap; s.maloai = maLoai; db.saches.InsertOnSubmit(s); db.SubmitChanges(); return(true); }
public ActionResult Taomoisach(sach sach, HttpPostedFileBase fileupload) { ViewBag.maloai = new SelectList(db.nxbs.ToList().OrderBy(n => n.tennxb), "idnxb", "tennxb"); ViewBag.macd = new SelectList(db.chudes.ToList().OrderBy(n => n.tenchude), "idchude", "tenchude"); //kiem tra duong dan if (fileupload == null) { ViewBag.Thongbao = "Vui lòng chọn ảnh bìa"; return(View()); } //them vao csdl else { if (ModelState.IsValid) { //luu ten file, them thu vien system.io var fileName = Path.GetFileName(fileupload.FileName); //luu duong dan var path = Path.Combine(Server.MapPath("~/Anhbia"), fileName); //kiem tra anh da ton tai chua if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { //luu hinh anh vao duong dan fileupload.SaveAs(path); } sach.anhbia = fileName; //luu vao csdl db.saches.InsertOnSubmit(sach); db.SubmitChanges(); } return(RedirectToAction("Sach")); } }
public ActionResult DeleteConfirmed(int id) { sach sach = db.saches.Find(id); foreach (tonkho tk in db.tonkhoes) { if (tk.idsach == sach.idsach) { db.tonkhoes.Remove(tk); } } foreach (ctpn ct in db.ctpns) { if (ct.idsach == sach.idsach) { db.ctpns.Remove(ct); phieunhap pn = db.phieunhaps.Find(ct.idpn); db.phieunhaps.Remove(pn); } } db.saches.Remove(sach); db.SaveChanges(); return(RedirectToAction("Index")); }
public void update(sach s) { string sqlCommand = string.Format("update SACH set Ten = N'{0}', NamXB = '{1}', MaXB = '{2}',MaTG = '{3}', MaTL ='{4}',MaVT = '{5}',TinhTrang = N'{6}', MaNN = '{7}' where MaSach = '{8}' ", s.tenSach, s.namXB, s.maXB, s.maTG, s.maTL, s.maVT, s.tinhTrang, s.ngonNgu, s.maSach); Excute(sqlCommand); }
public ActionResult Edit([Bind(Prefix = "danhmucsachdaban")] danhmucsachdaban danhmucsachdaban, [Bind(Prefix = "ct")] ctdmsdb[] ctdmsdb) { ViewBag.iddl = new SelectList(db.daily, "iddl", "tendl", danhmucsachdaban.iddl); ViewBag.idsach = new SelectList(db.sach, "idsach", "tensach"); danhmucsachdabanviewmodel dmvm = new danhmucsachdabanviewmodel(); if (ModelState.IsValid) { int iddmsdb = danhmucsachdaban.iddmsdb; int idct = 1; //xoa chi tiet cu trong database table hangtoncuadaily var ctcudmsdb = db.ctdmsdb.Where(o => o.iddmsdb == danhmucsachdaban.iddmsdb); foreach (ctdmsdb ct in ctcudmsdb) { hangtoncuadaily ht = db.hangtoncuadaily.FirstOrDefault(o => o.iddl == danhmucsachdaban.iddl && o.idsach == ct.idsach); int hangtondaily = (int)(ht.soluongchuaban + ct.soluong); } decimal tongtien = 0; //thêm chi tiết sửa vào database table hangtoncuadaily foreach (ctdmsdb ct in ctdmsdb) { ct.iddmsdb = iddmsdb; ct.idctdmsdb = idct; idct++; hangtoncuadaily ht = db.hangtoncuadaily.FirstOrDefault(o => o.iddl == danhmucsachdaban.iddl && o.idsach == ct.idsach); ht.soluongchuaban = (int)(ht.soluongchuaban - ct.soluong); if (ht.soluongchuaban < 0) { danhmucsachdaban.ctdmsdb = ctdmsdb; dmvm.danhmucsachdaban = danhmucsachdaban; return(View(dmvm)); } sach s = db.sach.Find(ct.idsach); nxb n = db.nxb.Find(s.idnxb); n.sotienphaitra += ct.soluong * s.gianhap; tongtien += (decimal)(ct.soluong * s.giaxuat); } foreach (ctdmsdb ct in ctcudmsdb) { nxb n = db.nxb.Find(ct.sach.idnxb); n.sotienphaitra -= ct.soluong * ct.sach.gianhap; if (n.sotienphaitra < 0) { danhmucsachdaban.ctdmsdb = ctdmsdb; dmvm.danhmucsachdaban = danhmucsachdaban; return(View(dmvm)); } db.ctdmsdb.Remove(ct); } foreach (ctdmsdb ct in ctdmsdb) { db.ctdmsdb.Add(ct); } danhmucsachdaban.sotienconno = tongtien; danhmucsachdaban.sotiendathanhtoan = 0; danhmucsachdaban.tinhtrang = "Waiting"; db.Entry(danhmucsachdaban).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } danhmucsachdaban.ctdmsdb = ctdmsdb; dmvm.danhmucsachdaban = danhmucsachdaban; return(View(dmvm)); }
private void btnLuuSach_Click(object sender, EventArgs e) { if (Them_bool == true && Sua_bool == false) { sach entity = new sach(); //txtMaSach.Text = ""; if (txtTenSach.Text.Length > 0) { entity.tensach = txtTenSach.Text; } else { MessageBox.Show("Chưa nhập đủ thông tin"); return; } if (txtTacGia.Text.Length > 0) { entity.tentacgia = txtTacGia.Text; } else { MessageBox.Show("Chưa nhập đủ thông tin"); return; } entity.manxb = Convert.ToInt32(cbbNXB.SelectedValue.ToString()); if (txtNamXB.Text.Length > 0) { entity.namxb = Convert.ToInt32(txtNamXB.Text); } else { MessageBox.Show("Chưa nhập đủ thông tin"); return; } if (txtSoTrang.Text.Length > 0) { entity.sotrang = Convert.ToInt32(txtSoTrang.Text); } else { MessageBox.Show("Chưa nhập đủ thông tin"); return; } if (txtGiaTien.Text.Length > 0) { entity.giatien = Convert.ToDecimal(txtGiaTien.Text); } else { MessageBox.Show("Chưa nhập đủ thông tin"); return; } if (txtSoLuong.Text.Length > 0) { entity.soluong = Convert.ToInt32(txtSoLuong.Text); } else { MessageBox.Show("Chưa nhập đủ thông tin"); return; } entity.ngonngu = txtNgonNgu.Text; entity.theloai = txtTheLoai.Text; var s = new SachController(); int t = s.Add(entity); if (t > 0) { HienThiSach(); } } if (Them_bool == false && Sua_bool == true) { sach entity = new sach(); entity.masach = Convert.ToInt32(txtMaSach.Text); entity.tensach = txtTenSach.Text; entity.tentacgia = txtTacGia.Text; entity.manxb = Convert.ToInt32(cbbNXB.SelectedValue.ToString()); if (txtNamXB.Text.Length > 0) { entity.namxb = Convert.ToInt32(txtNamXB.Text); } if (txtSoTrang.Text.Length > 0) { entity.sotrang = Convert.ToInt32(txtSoTrang.Text); } if (txtGiaTien.Text.Length > 0) { entity.giatien = Convert.ToDecimal(txtGiaTien.Text); } if (txtSoLuong.Text.Length > 0) { entity.soluong = Convert.ToInt32(txtSoLuong.Text); } entity.ngonngu = txtNgonNgu.Text; entity.theloai = txtTheLoai.Text; var s = new SachController(); if (s.Edit(entity)) { HienThiSach(); } else { MessageBox.Show("khong sua duoc!"); } } btn_edit(false); }