public ActionResult Create([Bind(Include = "id,nhapID,vattuID,soluong,dongia,ngaytaophieu")] phieunhap phieunhap) { if (ModelState.IsValid) { var query = from i in db.vattus where i.id == phieunhap.vattuID select i; foreach (vattu i in query) { i.soluong = i.soluong + phieunhap.soluong; } try { db.SaveChanges(); } catch (Exception) { return(HttpNotFound()); } db.phieunhaps.Add(phieunhap); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.nhapID = new SelectList(db.nhaps, "id", "maphieu", phieunhap.nhapID); ViewBag.vattuID = new SelectList(db.vattus, "id", "name", phieunhap.vattuID); return(View(phieunhap)); }
// ---------------------------------------------------------------------------Phiếu nhập------------------------------------------------ public bool themphieunhap(phieunhap pn) { string qry = "insert into PhieuNhap(MNV,MNCC,NgayNhap) values(" + "'" + pn.MNV1 + "','" + pn.MNCC1 + "','" + pn.NgayNhap1 + "')"; return(Insert_Update_Delete(qry)); }
public ContentResult AddStocIn(int id_vl, int id_nhacc, int soluong, int nv_role, int id_nv) { string content = null; phieunhap item = new phieunhap(); item.ID_NhaCC = id_nhacc; item.ID_NV = id_nv; item.ID_VL = id_vl; item.SoLuong = soluong; item.Status = 0; if (nv_role != 2) { item.NgayNhap = DateTime.Now; item.Status = 1; } var result = new PhieuNhapDAO().Insert(item); if (result) { content = "<script type='text/javascript'>alert(' Thêm thành công');window.location.href = '/Storage/StockIn/';</script>"; } else { content = "<script type='text/javascript'>alert(' Thêm thất bại !');script>"; } return(Content(content)); }
protected void btnthem_Click(object sender, EventArgs e) { if (ddlMNV.Text == "" || ddlMNCC.Text == "" || txtNgayNhap.Text == "") { Response.Write("<script>alert('Chưa nhập đủ thông tin');</script>"); } else { phieunhap pn = new phieunhap(); pn.MNV1 = int.Parse(ddlMNV.Text); pn.MNCC1 = int.Parse(ddlMNCC.Text); pn.NgayNhap1 = DateTime.Parse(txtNgayNhap.Text); if (ado.themphieunhap(pn)) { Response.Write("<script>alert('Đã thêm');</script>"); } else { Response.Write("<script>alert('Không thể thêm');</script>"); } Loadphieunhap(); Load_dropnhanvien(); Load_dropnhacungcap(); } }
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 bool suaphieunhap(phieunhap pn) { string qry = "update PhieuNhap set MNV = '" + pn.MNV1 + "' ,MNCC= '" + pn.MNCC1 + "',NgayNhap= '" + pn.NgayNhap1 + "' where MPN='" + pn.MPN1 + "'"; return(Insert_Update_Delete(qry)); }
public ActionResult DeleteConfirmed(int id) { phieunhap phieunhap = db.phieunhaps.Find(id); db.phieunhaps.Remove(phieunhap); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(phieunhap pn) { loadnxb(); if (Request.IsAjaxRequest()) { var res = PhieunhapServeic.Insert(pn); return(Json(res, JsonRequestBehavior.AllowGet)); } return(View()); }
protected void Loadlabel() { string a = Session["MPN"].ToString();; phieunhap pn = new phieunhap(); pn = ado.layphieunhap(int.Parse(a)); lblMPN.Text = pn.MPN1.ToString(); lblMNV.Text = pn.MNV1.ToString(); lblMNCC.Text = pn.MNCC1.ToString(); lblngaynhap.Text = pn.NgayNhap1.ToString(); }
public ActionResult Edit([Bind(Include = "id,nhapID,vattuID,soluong,dongia,ngaytaophieu")] phieunhap phieunhap) { if (ModelState.IsValid) { db.Entry(phieunhap).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.nhapID = new SelectList(db.nhaps, "id", "maphieu", phieunhap.nhapID); ViewBag.vattuID = new SelectList(db.vattus, "id", "name", phieunhap.vattuID); return(View(phieunhap)); }
protected void gvPhieuNhap_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { int mapn = int.Parse(gvPhieuNhap.DataKeys[e.NewSelectedIndex].Value.ToString()); phieunhap pn = new phieunhap(); pn = ado.layphieunhap(mapn); txtMPN.Text = pn.MPN1.ToString(); ddlMNV.SelectedValue = pn.MNV1.ToString(); ddlMNCC.SelectedValue = pn.MNCC1.ToString(); txtNgayNhap.Text = Convert.ToDateTime(pn.NgayNhap1).Date.ToString("yyyy-MM-dd"); }
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 int create(phieunhap pn) { //kiểm tra duplicate var result = db.phieunhaps.Where(x => x.mapn.Equals(pn.mapn)).SingleOrDefault(); if (result == null) { db.phieunhaps.Add(pn); db.SaveChanges(); return(1); } return(0); }
// GET: phieunhaps/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } phieunhap phieunhap = db.phieunhap.Find(id); if (phieunhap == null) { return(HttpNotFound()); } return(View(phieunhap)); }
public bool deletePhieuNhap(string mpn) { try { phieunhap p = db.phieunhaps.Single(m => m.mapn == mpn); db.phieunhaps.DeleteOnSubmit(p); db.SubmitChanges(); return(true); } catch { return(false); } }
public bool deleteActivePhieuNhap(string mpn) { try { phieunhap p = db.phieunhaps.Single(m => m.mapn == mpn && m.trangthai == false); p.Active = false; db.SubmitChanges(); return(true); } catch { return(false); } }
public bool updateTrangThaiPhieuNhap(string mpn) { try { phieunhap p = db.phieunhaps.Single(m => m.mapn == mpn); p.trangthai = true; db.SubmitChanges(); return(true); } catch { return(false); } }
public bool updatePhieuNhap(string mpn, DateTime ngay) { try { phieunhap p = db.phieunhaps.Single(m => m.mapn == mpn); p.ngaynhap = ngay; db.SubmitChanges(); return(true); } catch { return(false); } }
public int Edit(phieunhap pn) { var result = db.phieunhaps.Find(pn.mapn); if (result != null) { //code update db result.mapn = pn.mapn; result.tinhtrang = pn.tinhtrang; db.SaveChanges(); return(1); } return(0); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } phieunhap phieunhap = db.phieunhaps.Find(id); if (phieunhap == null) { return(HttpNotFound()); } ViewBag.nhapID = new SelectList(db.nhaps, "id", "maphieu", phieunhap.nhapID); ViewBag.vattuID = new SelectList(db.vattus, "id", "name", phieunhap.vattuID); return(View(phieunhap)); }
public bool insertPhieuNhap(string mpn, DateTime ngay) { try { phieunhap p = new phieunhap(); p.mapn = mpn; p.ngaynhap = ngay; p.trangthai = false; p.Active = true; db.phieunhaps.InsertOnSubmit(p); db.SubmitChanges(); return(true); } catch { return(false); } }
public bool Insert(phieunhap item) { try { db.phieunhaps.Add(item); if (item.Status == 1) { var dbEntry = db.vatlieux.SingleOrDefault(x => x.ID == item.ID_VL); dbEntry.SoLuong += item.SoLuong; } db.SaveChanges(); return(true); } catch { return(false); } }
public ActionResult Create([Bind(Prefix = "phieunhap")] phieunhap phieunhap, [Bind(Prefix = "ct")] ctpn[] ctpn) { if (ModelState.IsValid) { int idpn = 1; if (db.phieunhaps.Any()) { idpn = db.phieunhaps.Max(o => o.idpn) + 1; } int idct = 1; foreach (ctpn ct in ctpn) { ct.idpn = idpn; ct.idctpn = idct; idct++; tonkho tk = new tonkho(); tk.thoidiem = DateTime.Now; //lấy tồn kho mới nhất của sách này tonkho tkht = db.tonkhoes.OrderByDescending(o => o.idtk).FirstOrDefault(o => o.idsach == (int)ct.idsach); if (tkht != null) { tk.idsach = (int)ct.idsach; tk.soluongton = tkht.soluongton + ct.soluong; } else { tk.idsach = (int)ct.idsach; tk.soluongton = ct.soluong; } db.tonkhoes.Add(tk); } phieunhap.ctpns = ctpn; db.phieunhaps.Add(phieunhap); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idnxb = new SelectList(db.nxbs, "idnxb", "tennxb", phieunhap.idnxb); ViewBag.idsach = new SelectList(db.saches, "idsach", "tensach"); return(View()); }
// GET: phieunhaps/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } phieunhap phieunhap = db.phieunhap.Find(id); if (phieunhap == null) { return(HttpNotFound()); } ViewBag.idsach = new SelectList(db.sach, "idsach", "tensach"); ViewBag.idnxb = new SelectList(db.nxb, "idnxb", "tennxb", phieunhap.idnxb); phieunhapviewmodel pnvm = new phieunhapviewmodel(); pnvm.phieunhap = phieunhap; return(View(pnvm)); }
public phieunhap layphieunhap(int mapn) { using (SqlConnection connect = new SqlConnection(connectionString)) { connect.Open(); string sql = "select * from PhieuNhap where MPN=" + mapn; SqlCommand cmd = new SqlCommand(sql, connect); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); phieunhap a = new phieunhap(); a.MPN1 = reader.GetInt32(0); a.MNV1 = reader.GetInt32(1); a.MNCC1 = reader.GetInt32(2); a.NgayNhap1 = reader.GetDateTime(3); cmd.Dispose(); reader.Dispose(); connect.Close(); return(a); } }
public bool Insert(phieunhap obj) { using (CTyPHSachEntities db = new CTyPHSachEntities()) { try { int id = db.ReceiptNotes.Max(x => x.ReceiptNoteID) + 10; var ob = new ReceiptNotes(); ob.ReceiptNoteID = id; ob.receiptName = obj.nguoigia; ob.senderName = obj.nguoitao; ob.totalPrice = obj.giatri; ob.PublisherID = obj.id_nxb; ob.subid = id; ob.receiptDateCreated = obj.ngayxuat; db.ReceiptNotes.Add(ob); List <ReceiptDetails> rd = new List <ReceiptDetails>(); foreach (var item in obj.chitiet) { var ct = new ReceiptDetails(); var s = db.Books.Find(item.masach); s.amount = s.amount + item.sl; ct.BookID = item.masach; ct.ReceiptNoteID = id; ct.receiptAmount = item.sl; ct.totalPrice = s.receiptPrice; rd.Add(ct); } db.ReceiptDetails.AddRange(rd); db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } } }
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 static bool Delete(phieunhap obj) { return(repository.Delete(obj)); }
public bool Update(phieunhap obj) { throw new NotImplementedException(); }
public static bool Update(phieunhap obj) { return(repository.Update(obj)); }