public async Task <ActionResult> Dathang(FormCollection collection) { PhieuGiaoHang pgh = new PhieuGiaoHang(); NVPhuTrach nv = (NVPhuTrach)Session["Taikhoan"]; List <Giohang> gh = Laygiohang(); pgh.SOPG = pgh.SOPG; pgh.NgayLapPhieu = DateTime.Now; pgh.TrangThai = pgh.TrangThai; //Thêm chi tiết đơn hàng foreach (var item in gh) { CTPhieuGH ctdh = new CTPhieuGH(); ctdh.SOPG = pgh.SOPG; ctdh.MSMH = item.iMSMH; ctdh.SoLuongGiao = item.iSoLuong; db.PhieuGiaoHangs.Add(pgh); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } await db.SaveChangesAsync(); Session["Giohang"] = null; return(RedirectToAction("Xacnhandonhang", "Giohang")); }
void BindingDataToDataGridViews(List <PhieuGiaoHang> list_phieugiao) { DataTable dt = new DataTable(); dt.Columns.Add("STT"); dt.Columns.Add("ID"); dt.Columns.Add("Tên Sản phẩm"); dt.Columns.Add("Số lượng"); dt.Columns.Add("Đơn giá"); dt.Columns.Add("Ngày giao"); dt.Columns.Add("Ghi chú"); dt.Columns.Add("Mã nhà cung cấp"); dt.Columns.Add("Tên nhà cung cấp"); int stt = 1; for (int i = 0; i < list_phieugiao.Count; i++, stt++) { PhieuGiaoHang s = list_phieugiao[i]; dt.Rows.Add(new String[] { stt.ToString(), s.Id.ToString(), s.TenSanPham, s.SoLuong.ToString(), s.DonGia.ToString(), s.NgayGiao.ToString(), s.GhiChu, s.Supplier.Id.ToString(), s.Supplier.Name }); } dataGridView1.DataSource = dt; }
private void btn_luu_Click(object sender, EventArgs e) { //int cv = Convert.ToInt32(txt_id.Text); PhieuGiaoHang get_phieugiao = model.PhieuGiaoHangs.FirstOrDefault(c => c.Id.ToString() == txt_id.Text); /*nếu sách là*/ if (get_phieugiao == null) // nếu { PhieuGiaoHang s2 = new PhieuGiaoHang(); s2.Id = Int32.Parse(txt_id.Text); s2.TenSanPham = txt_tensp.Text; s2.SoLuong = Int32.Parse(txt_sl.Text); s2.DonGia = Convert.ToDecimal(txt_dongia.Text); s2.NgayGiao = Convert.ToDateTime(dtpNgayGiao.Text); s2.GhiChu = txt_ghichu.Text; s2.maNCC = Int32.Parse(cb_nhacc.SelectedValue.ToString()); model.PhieuGiaoHangs.Add(s2); model.SaveChanges(); btn_them.Visible = true; btn_luu.Visible = false; SetNull(); } else { get_phieugiao.TenSanPham = txt_tensp.Text; get_phieugiao.SoLuong = Int32.Parse(txt_sl.Text); get_phieugiao.DonGia = Convert.ToDecimal(txt_dongia.Text); get_phieugiao.NgayGiao = Convert.ToDateTime(dtpNgayGiao.Text); get_phieugiao.GhiChu = txt_ghichu.Text; get_phieugiao.maNCC = Int32.Parse(cb_nhacc.SelectedValue.ToString()); model.SaveChanges(); /*db.SaveChanges();*/ btn_them.Visible = true; btn_luu.Visible = false; } BindingDataToDataGridViews(model.PhieuGiaoHangs.ToList()); ReadOnlyAll(); //btn_sua.Enabled = true; }
public async Task <ActionResult> PG_Them([Bind(Include = "SOCTPG,SOPG,MSMH,SoLuongGiao,DonGia,ThanhTien")] CTPhieuGH cTPhieuGH, PhieuGiaoHang PhieuGH) { if (ModelState.IsValid) { db.CTPhieuGHs.Add(cTPhieuGH); await db.SaveChangesAsync(); return(RedirectToAction("PhieuGiao")); } ViewBag.MSMH = new SelectList(db.MatHangs, "MSMH", "TenHang", cTPhieuGH.MSMH); ViewBag.SOPG = new SelectList(db.PhieuGiaoHangs, "SOPG", "SOPG", cTPhieuGH.SOPG); ViewBag.MSCH = new SelectList(db.CuaHangs, "MSCH", "TenCH", PhieuGH.MSCH); ViewBag.MSVN = new SelectList(db.NVPhuTraches, "MSNV", "HoTenNV", PhieuGH.MSNV); return(View(cTPhieuGH)); }