//-------------------------------------phiếu xuất-------------------------------------- public bool themphieuxuat(phieuxuat px) { string qry = "insert into PhieuXuat(MNV,MKH,NgayXuat) values(" + "'" + px.MNV1 + "','" + px.MKH1 + "','" + px.NgayXuat1 + "')"; return(Insert_Update_Delete(qry)); }
public bool suaphieuxuat(phieuxuat px) { string qry = "update PhieuXuat set MNV = '" + px.MNV1 + "' ,MKH= '" + px.MKH1 + "',NgayXuat= '" + px.NgayXuat1 + "' where MPX='" + px.MPX1 + "'"; return(Insert_Update_Delete(qry)); }
protected void btnthem_Click(object sender, EventArgs e) { if (txtNgayXuat.Text == "") { Response.Write("<script>alert('Chưa nhập đủ thông tin');</script>"); } else { phieuxuat pn = new phieuxuat(); pn.MNV1 = int.Parse(ddlMNV.Text); pn.MKH1 = int.Parse(ddlMKH.Text); pn.NgayXuat1 = DateTime.Parse(txtNgayXuat.Text); if (ado.themphieuxuat(pn)) { Response.Write("<script>alert('Đã thêm');</script>"); } else { Response.Write("<script>alert('Không thể thêm');</script>"); } Loadphieuxuat(); Load_dropnhanvien(); Load_dropmakhachhang(); } }
public ActionResult DeleteConfirmed(int id) { phieuxuat phieuxuat = db.phieuxuats.Find(id); db.phieuxuats.Remove(phieuxuat); db.SaveChanges(); return(RedirectToAction("Index")); }
private ActionResult re(phieuxuat px) { ViewBag.iddl = new SelectList(db.dailies, "iddl", "tendl", px.iddl); ViewBag.idsach = new SelectList(db.saches, "idsach", "tensach"); phieuxuatviewmodel pxvm1 = new phieuxuatviewmodel(); pxvm1.phieuxuat = px; return(View(pxvm1)); }
private ActionResult re(phieuxuat px) { ViewBag.iddl = new SelectList(db.daily, "iddl", "tendl", px.iddl); ViewBag.idsach = new SelectList(db.sach.Where(s => s.soluongton != null), "idsach", "tensach"); phieuxuatviewmodel pxvm1 = new phieuxuatviewmodel(); pxvm1.phieuxuat = px; return(View(pxvm1)); }
protected void Loadlabel() { string a = Session["MPX"].ToString(); phieuxuat pn = new phieuxuat(); pn = ado.layphieuxuat(int.Parse(a)); lblMPX.Text = pn.MPX1.ToString(); lblMNV.Text = pn.MNV1.ToString(); lblMKH.Text = pn.MKH1.ToString(); lblngayxuat.Text = pn.NgayXuat1.ToString(); }
public ActionResult Create(phieuxuat pn) { loadnxb(); if (Request.IsAjaxRequest()) { var res = PhieuxuatService.Insert(pn); //kiem tra return(Json(res, JsonRequestBehavior.AllowGet)); } return(View()); }
protected void gvphieuxuat_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { int mapn = int.Parse(gvphieuxuat.DataKeys[e.NewSelectedIndex].Value.ToString()); phieuxuat pn = new phieuxuat(); pn = ado.layphieuxuat(mapn); txtMPX.Text = pn.MPX1.ToString(); ddlMNV.SelectedValue = pn.MNV1.ToString(); ddlMKH.SelectedValue = pn.MKH1.ToString(); txtNgayXuat.Text = Convert.ToDateTime(pn.NgayXuat1).Date.ToString("yyyy-MM-dd"); }
public ActionResult Edit([Bind(Include = "id,xuatID,vattuID,soluong,dongia,ngaytaophieu")] phieuxuat phieuxuat) { if (ModelState.IsValid) { db.Entry(phieuxuat).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.vattuID = new SelectList(db.vattus, "id", "mavattu", phieuxuat.vattuID); ViewBag.xuatID = new SelectList(db.xuats, "id", "maphieu", phieuxuat.xuatID); return(View(phieuxuat)); }
public bool Insert(phieuxuat obj) { using (CTyPHSachEntities db = new CTyPHSachEntities()) { try { int id = db.DeliveryNotes.Max(x => x.DeliveryNoteID) + 10; var ob = new DeliveryNotes(); ob.DeliveryNoteID = id; ob.deliverName = obj.nguoigia; ob.receiverName = obj.nguoitao; ob.totalPrice = obj.giatri; ob.AgencyID = obj.id_dl; ob.endeliverdate = obj.hanthanhtoan; ob.deliverDateCreated = obj.ngayxuat; db.DeliveryNotes.Add(ob); List <DeliveryDetails> rd = new List <DeliveryDetails>(); foreach (var item in obj.chitiet) { var ct = new DeliveryDetails(); var s = db.Books.Find(item.masach); s.amount = s.amount - item.sl; ct.BookID = item.masach; ct.DeliveryNoteID = id; ct.amount = item.sl; ct.price = s.receiptPrice; rd.Add(ct); } db.DeliveryDetails.AddRange(rd); if (obj.thanhtoan > 0) { var tt = new Debts(); tt.DeliveryNoteID = id; tt.dateCreated = obj.ngayxuat; tt.thanhtoan = obj.thanhtoan; tt.id_dl = obj.id_dl; tt.creatorName = obj.nguoitao; db.Debts.Add(tt); } db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } } }
// GET: phieuxuats/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } phieuxuat phieuxuat = db.phieuxuats.Find(id); if (phieuxuat == null) { return(HttpNotFound()); } return(View(phieuxuat)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } phieuxuat phieuxuat = db.phieuxuats.Find(id); if (phieuxuat == null) { return(HttpNotFound()); } ViewBag.vattuID = new SelectList(db.vattus, "id", "mavattu", phieuxuat.vattuID); ViewBag.xuatID = new SelectList(db.xuats, "id", "maphieu", phieuxuat.xuatID); return(View(phieuxuat)); }
public phieuxuat layphieuxuat(int mapx) { using (SqlConnection connect = new SqlConnection(connectionString)) { connect.Open(); string sql = "select * from PhieuXuat where MPX=" + mapx; SqlCommand cmd = new SqlCommand(sql, connect); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); phieuxuat a = new phieuxuat(); a.MPX1 = reader.GetInt32(0); a.MNV1 = reader.GetInt32(1); a.MKH1 = reader.GetInt32(2); a.NgayXuat1 = reader.GetDateTime(3); cmd.Dispose(); reader.Dispose(); connect.Close(); return(a); } }
public static int Insert(phieuxuat obj) { List <int> idsach = new List <int>(); //kiem tra so luong foreach (var item in obj.chitiet) { var b = SachService.GetBookById(item.masach); if (b.sl < item.sl) { idsach.Add(item.masach); } } if (idsach.Count() > 0) { return(1); } //kiem tra ngay no //kiem tra muc no decimal?mucno = DailyService.GetBookById(obj.id_dl).mucno; decimal tienno = obj.giatri - (obj.thanhtoan.HasValue ? obj.thanhtoan.Value : 0); if (tienno > mucno) { return(2); } var res = repository.Insert(obj); if (res) { return(3); } else { return(4); } }
public ActionResult Create([Bind(Include = "id,xuatID,vattuID,soluong,dongia,ngaytaophieu")] phieuxuat phieuxuat) { if (ModelState.IsValid) { var set = db.vattus.FirstOrDefault(s => s.id == phieuxuat.vattuID); if (set.soluong >= phieuxuat.soluong) { var query = from i in db.vattus where i.id == phieuxuat.vattuID select i; foreach (vattu i in query) { i.soluong = i.soluong - phieuxuat.soluong; } try { db.SaveChanges(); } catch (Exception) { return(HttpNotFound()); } db.phieuxuats.Add(phieuxuat); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.vattuID = new SelectList(db.vattus, "id", "mavattu", phieuxuat.vattuID); ViewBag.xuatID = new SelectList(db.xuats, "id", "maphieu", phieuxuat.xuatID); return(View(phieuxuat)); } return(JavaScript("<script language='text/javascript'>alert('Số lượng yêu cầu ko phù hợp');</script>")); }
protected void btnsua_Click(object sender, EventArgs e) { if (txtNgayXuat.Text == "" || txtMPX.Text == "") { Response.Write("<script>alert('Chưa nhập đủ thông tin');</script>"); } else { phieuxuat pn = new phieuxuat(); pn.MPX1 = int.Parse(txtMPX.Text); pn.MNV1 = int.Parse(ddlMNV.Text); pn.MKH1 = int.Parse(ddlMKH.Text); pn.NgayXuat1 = DateTime.Parse(txtNgayXuat.Text); if (ado.suaphieuxuat(pn)) { Response.Write("<script>alert('Đã sửa');</script>"); } else { Response.Write("<script>alert('Không thể sửa');</script>"); }; Loadphieuxuat(); } }
public bool Update(phieuxuat obj) { throw new NotImplementedException(); }
public ActionResult Create([Bind(Prefix = "phieuxuat")] phieuxuat phieuxuat, [Bind(Prefix = "ct")] ctpx[] ctpx) { if (ModelState.IsValid) { decimal tongtien = 0; int idpx = 1; if (db.phieuxuat.Any()) { idpx = db.phieuxuat.Max(o => o.idpx) + 1; } int idct = 1; foreach (ctpx ct in ctpx) { ct.idpx = idpx; ct.idctpx = idct; idct++; //cap nhat ton kho hien tai sach a = db.sach.Find(ct.idsach); //kiem tra xem cuon sach du so luong de xuat ko if (a.soluongton > ct.soluong) { a.soluongton = a.soluongton - ct.soluong; } else { ModelState.AddModelError("", "Không đủ số lượng hoặc chưa nhập sách về"); phieuxuat.ctpx = ctpx; return(re(phieuxuat)); } //cap nhat so sach da gui cho dai ly hangtoncuadaily htdl = db.hangtoncuadaily.FirstOrDefault(o => o.iddl == phieuxuat.iddl && o.idsach == ct.idsach); if (htdl != null && htdl.soluongchuaban != null) { htdl.soluongchuaban = htdl.soluongchuaban + ct.soluong; } else { htdl = new hangtoncuadaily(); htdl.iddl = phieuxuat.iddl; htdl.idsach = ct.idsach; htdl.soluongchuaban = ct.soluong; db.hangtoncuadaily.Add(htdl); } tongtien += (decimal)(ct.soluong * db.sach.Find(ct.idsach).giaxuat); } //cap nhat cong no daily dl = db.daily.Find(phieuxuat.iddl); if (dl.congno > 0 && tongtien > dl.congno) { ModelState.AddModelError("", "tong tien phieu xuat lon hon cong no hien tai cua dai ly"); phieuxuat.ctpx = ctpx; return(re(phieuxuat)); } if (dl.congno != null) { dl.congno = dl.congno + tongtien; } else { dl.congno = tongtien; } phieuxuat.ctpx = ctpx; db.phieuxuat.Add(phieuxuat); db.SaveChanges(); return(RedirectToAction("Index")); } phieuxuat.ctpx = ctpx; return(re(phieuxuat)); }
public ActionResult Create([Bind(Prefix = "phieuxuat")] phieuxuat phieuxuat, [Bind(Prefix = "ct")] ctpx[] ctpx) { if (ModelState.IsValid) { decimal tongtien = 0; int idpx = 1; if (db.phieuxuats.Any()) { idpx = db.phieuxuats.Max(o => o.idpx) + 1; } int idct = 1; foreach (ctpx ct in ctpx) { ct.idpx = idpx; ct.idctpx = idct; idct++; //cap nhat ton kho hien tai tonkho tk = new tonkho(); tk.thoidiem = DateTime.Now; tonkho tkht = db.tonkhoes.OrderByDescending(o => o.idtk).FirstOrDefault(o => o.idsach == (int)ct.idsach); //kiem tra xem cuon sach du so luong de xuat ko if (tkht != null && tkht.soluongton >= ct.soluong) { tk.idsach = (int)ct.idsach; tk.soluongton = tkht.soluongton - ct.soluong; db.tonkhoes.Add(tk); } else { ModelState.AddModelError("", "Không đủ số lượng hoặc chưa nhập sách về"); ViewBag.iddl = new SelectList(db.dailies, "iddl", "tendl"); ViewBag.idsach = new SelectList(db.saches, "idsach", "tensach"); return(View()); } //cap nhat so sach da gui cho dai ly hangtoncuadaily htdl = db.hangtoncuadailies.FirstOrDefault(o => o.iddl == phieuxuat.iddl && o.idsach == ct.idsach); if (htdl != null) { htdl.soluongchuaban = htdl.soluongchuaban + ct.soluong; db.Entry(htdl).State = EntityState.Modified; } else { htdl = new hangtoncuadaily(); htdl.iddl = phieuxuat.iddl; htdl.idsach = ct.idsach; htdl.soluongchuaban = ct.soluong; db.hangtoncuadailies.Add(htdl); } // tạo mới công nợ tongtien += (decimal)(ct.soluong * db.saches.Find(ct.idsach).giaxuat); } congnotheothoigian cn = new congnotheothoigian(); cn.thoidiem = (DateTime)phieuxuat.ngayxuat; congnotheothoigian cnht = db.congnotheothoigians.OrderByDescending(o => o.id).FirstOrDefault(o => o.iddl == phieuxuat.iddl); if (cnht.congno > 0 && tongtien > cnht.congno) { ModelState.AddModelError("", "Tổng tiền lớn hơn công nợ"); ViewBag.iddl = new SelectList(db.dailies, "iddl", "tendl"); ViewBag.idsach = new SelectList(db.saches, "idsach", "tensach"); return(View()); } if (cnht.congno != null) { cn.iddl = phieuxuat.iddl; System.Diagnostics.Debug.WriteLine("Tổng tiền là : " + tongtien); cn.congno = cnht.congno + tongtien; System.Diagnostics.Debug.WriteLine("Công nợ là : " + cn.congno); db.congnotheothoigians.Add(cn); } else { cn.iddl = phieuxuat.iddl; cn.congno = tongtien; db.congnotheothoigians.Add(cn); } phieuxuat.ctpxes = ctpx; db.phieuxuats.Add(phieuxuat); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.iddl = new SelectList(db.dailies, "iddl", "tendl"); ViewBag.idsach = new SelectList(db.saches, "idsach", "tensach"); return(View()); }
public static bool Update(phieuxuat obj) { return(repository.Update(obj)); }
public static bool Delete(phieuxuat obj) { return(repository.Delete(obj)); }
public ActionResult Edit([Bind(Prefix = "phieuxuat")] phieuxuat phieuxuat, [Bind(Prefix = "ct")] ctpx[] ctpx) { if (ModelState.IsValid) { int idpx = phieuxuat.idpx; int idct = 1; //xóa chi tiết cũ trong database table sach //tinh tong tien cu int tongtiencu = 0; var ctpxcu = db.ctpxes.Where(ct => ct.idpx == phieuxuat.idpx).ToList(); foreach (var ct in ctpxcu) { sach s = db.saches.Find(ct.idsach); tonkho tkht = db.tonkhoes.OrderByDescending(o => o.idtk).FirstOrDefault(o => o.idsach == (int)ct.idsach); int soluonghientai = (int)(tkht.soluongton + ct.soluong); tkht.soluongton = soluonghientai; tongtiencu += (int)(ct.soluong * s.giaxuat); } //thêm chi tiết sửa vào database table hangtoncuadaily foreach (ctpx ct in ctpx) { ct.idpx = idpx; ct.idctpx = idct; idct++; hangtoncuadaily ht = db.hangtoncuadailies.FirstOrDefault(o => o.iddl == phieuxuat.iddl && o.idsach == ct.idsach); ht.soluongchuaban = (int)(ht.soluongchuaban + ct.soluong); } //xoa chi tiet cu trong database table hangtoncuadaily foreach (ctpx ct in ctpxcu) { hangtoncuadaily ht = db.hangtoncuadailies.FirstOrDefault(o => o.iddl == phieuxuat.iddl && o.idsach == ct.idsach); int hangtondaily = (int)(ht.soluongchuaban - ct.soluong); if (hangtondaily < 0) { ModelState.AddModelError("", "so sach nay da duoc ban" + hangtondaily); phieuxuat.ctpxes = ctpx; return(re(phieuxuat)); } db.ctpxes.Remove(ct); } //tinh tong tien moi int tongtien = 0; //thêm chi tiết sửa vào database table sach foreach (ctpx ct in ctpx) { sach s = db.saches.Find(ct.idsach); tonkho tkht = db.tonkhoes.OrderByDescending(o => o.idtk).FirstOrDefault(o => o.idsach == (int)ct.idsach); if (tkht.soluongton != null) { tkht.soluongton = tkht.soluongton - ct.soluong; } if (tkht.soluongton < 0) { ModelState.AddModelError("", "so luong hien tai khong du de xuat " + tkht.soluongton + " vui long kiem tra lai"); phieuxuat.ctpxes = ctpx; return(re(phieuxuat)); } tongtien += (int)(ct.soluong * s.giaxuat); } //cap nhat cong no daily dl = db.dailies.Find(phieuxuat.iddl); congnotheothoigian cnht = db.congnotheothoigians.OrderByDescending(o => o.id).FirstOrDefault(o => o.iddl == phieuxuat.iddl); if (cnht.congno > 0 && tongtien > cnht.congno) { ModelState.AddModelError("", "tong tien phieu xuat lon hon cong no hien tai cua dai ly"); phieuxuat.ctpxes = ctpx; return(re(phieuxuat)); } if (cnht.congno != null) { cnht.congno = cnht.congno + tongtien - tongtiencu; } if (cnht.congno < 0) { ModelState.AddModelError("", "cong no dai ly la so am => co sach da ban trong phieu chua sua"); phieuxuat.ctpxes = ctpx; return(re(phieuxuat)); } foreach (ctpx ct in ctpx) { db.ctpxes.Add(ct); } db.Entry(phieuxuat).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index"));; } phieuxuat.ctpxes = ctpx; return(re(phieuxuat)); }