public DataTable ThongKeXuatKho(DateTime begin, DateTime end) { DataTable result = new CrystalReports.THINKPRODataset.ThongKeXKDataTable().Clone(); foreach (DataRow SP in data.Tables["SANPHAM"].Rows) { DataRow XK = result.NewRow(); XK["MASP"] = SP["ID_SP"]; XK["TENSP"] = SP["TENSP"]; XK["SOLUONGXUAT"] = 0; XK["GIABAN"] = SP.Field <int>("GIATIEN"); foreach (DataRow CTHD in _CHITIETHD.Rows) { if (XK["MASP"].ToString() == CTHD["ID_SP"].ToString()) { DataRow HD = _HOADON.AsEnumerable().SingleOrDefault(t => t.Field <string>("ID_HD") == CTHD.Field <string>("ID_HD")); if (HD != null) { if (DateTime.Compare(begin, HD.Field <DateTime>("NGAYLAPHD")) <= 0 && DateTime.Compare(HD.Field <DateTime>("NGAYLAPHD"), end) <= 0) { XK["SOLUONGXUAT"] = XK.Field <int>("SOLUONGXUAT") + CTHD.Field <int>("SOLUONG"); } } } } if (XK.Field <int>("SOLUONGXUAT") > 0) { result.Rows.Add(XK); } } return(result); }
public ActionResult Payment(int mahd, string diachi, string sdt, string nguoidat) { var order = new HoaDon(); order.MaHD = mahd; order.NgayDa = DateTime.Now; order.DiaChi = diachi; order.SDT = sdt; order.NguoiDat = nguoidat; try { var id = new HoaDonDao().Insert(order); var cart = (List <CartItem>)Session[CartSession]; var detailDao = new Model.Dao.CTHDDao(); foreach (var item in cart) { var orderDetail = new CTHD(); orderDetail.MaHD = id; orderDetail.MaSan = item.sans.MaSan; orderDetail.GiaSan = item.sans.DonGia; orderDetail.SoLuong = item.SoLuong; detailDao.Insert(orderDetail); } } catch (Exception) { //ghi log return(Redirect("/loi-thanh-toan")); } return(Redirect("/Cart/Success")); }
public ActionResult DatHangKhiNhan(FormCollection collection) { DONDATHANG ddh = new DONDATHANG(); KHACHHANG kh = (KHACHHANG)Session["Taikhoan"]; List <GioHang> gh = LayGioHang(); ddh.MAKH = kh.MaKH; ddh.NgayDat = DateTime.Now; DateTime ngaygiao = DateTime.Parse(collection["Ngaygiao"].ToString()); ddh.NgayGiao = ngaygiao; ddh.TinhTrangGiaoHang = false; ddh.DaThanhToan = false; data.DONDATHANGs.InsertOnSubmit(ddh); data.SubmitChanges(); foreach (var item in gh) { CTHD cthd = new CTHD(); cthd.MaDH = item.iMaSP; cthd.MaSP = ddh.MADH; cthd.SoLuong = item.iSoLuong; cthd.DonGia = (decimal)item.dDonGia; data.CTHDs.InsertOnSubmit(cthd); } data.SubmitChanges(); Session["GioHang"] = null; return(RedirectToAction("XacNhanDonHang", "GioHang")); }
public async Task <IActionResult> Edit(int id, [Bind("MaCTHD,MaHD,MaSP,SoLuong,ThanhTien")] CTHD cTHD) { if (id != cTHD.MaCTHD) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cTHD); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CTHDExists(cTHD.MaCTHD)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cTHD)); }
public void fHoaDonDichVu_Load(object sender, EventArgs e) { dateTimePicker3.Value = DateTime.Today; AutoCompleteStringCollection acsc = new AutoCompleteStringCollection(); foreach (DataRow item in HOADON.dSMAHD().Rows) { acsc.Add(item["MAHD"].ToString()); } txtTK.AutoCompleteCustomSource = acsc; LoadHD(); if (dataGridView2.Rows.Count > 0) { dateTimePicker1.Value = DateTime.Parse(HOADON.NgayThanhToanMoiNhat()); } dataGridView2.Columns["chon"].Width = 30; dataGridView2.ReadOnly = false; dataGridView2.Columns[1].ReadOnly = true; dataGridView2.Columns[2].ReadOnly = true; dataGridView2.Columns[3].ReadOnly = true; dataGridView2.Columns[4].ReadOnly = true; dataGridView2.Columns[5].ReadOnly = true; dataGridView2.Columns[6].ReadOnly = true; if (CTHD.TimNV().machucvu != "CV0002") { btnXoa.Visible = false; dataGridView2.Columns["chon"].Visible = false; } //vcl cai loi nay ma t tim sang gio 8 tieng hoi , xóa delege xem sao, ben t binh thuong m de yen t doc cai loi // loi lien quan toi truy xuat du lieu txtTK.Text = "nhập mã mã hóa đơn...!"; Changebackgroundcolor_rowodd(); }
private void tbl_CtHd_CellValueChanged(object sender, EventArgs e) { CTHD ct = new CTHD(); DoChoiBus dcBus = new DoChoiBus(); var row = tbl_CtHd.SelectedRows[0]; ct.MAHD = (int)row.Cells[0].Value; ct.MADC = (int)row.Cells[1].Value; ct.SL = (int)row.Cells[2].Value; ct.GIA = dcBus.DochoiById(ct.MADC).GIA *ct.SL; row.Cells[3].Value = ct.GIA; var li = changedItem.Where(i => (i.MAHD == ct.MAHD && i.MADC == ct.MADC)); if (li.Count() > 0) { li.First().GIA = ct.GIA; li.First().SL = ct.SL; } else { changedItem.Add(ct); } data_change = true; }
public bool sp_themcthdban(int idhoadon, int mathucdon, int soluong, int giamgia) { try { var query = db.CTHDs.Where(x => x.IDHOADON == idhoadon && x.MATHUCDON == mathucdon && x.GIAMGIA == giamgia).Select(x => x.MATHUCDON); if (query != null) { var soluongcu = db.CTHDs.Where(x => x.IDHOADON == idhoadon && x.MATHUCDON == mathucdon && x.GIAMGIA == giamgia).Select(x => x.SOLUONG); var tongsoluong = Convert.ToInt32(soluongcu) + soluong; var soluongUp = db.CTHDs.Where(x => x.IDHOADON == idhoadon && x.MATHUCDON == mathucdon && x.GIAMGIA == giamgia).FirstOrDefault(); soluongUp.SOLUONG = tongsoluong; db.SaveChanges(); } else { CTHD cthd = new CTHD(idhoadon, mathucdon, soluong, giamgia); db.CTHDs.Add(cthd); db.SaveChanges(); } } catch (Exception) { return(false); } return(true); }
public ActionResult ThemSP(int IDSP, int soLuong) { int IDBan = int.Parse(Session["IDBAN"].ToString()); ganSession(IDBan); List <banDAO> giohang = Session["banDAO"] as List <banDAO>; // Gán qua biến giohang dễ code int donGia = (int)db.Sphams.Find(IDSP).Gia; if (giohang.FirstOrDefault(t => t.IDSanPham == IDSP) == null) { banDAO ban = new banDAO() { IDBan = IDBan, IDSanPham = IDSP, DonGia = donGia, SoLuong = soLuong, TenSP = db.Sphams.Find(IDSP).TenSanPham }; giohang.Add(ban); if (giohang.Count == 1) { HoaDon additemHD = new HoaDon() { GioVao = DateTime.Now, MaBan = IDBan, TinhTrang = false, TongTien = donGia * soLuong }; db.HoaDons.Add(additemHD); db.SaveChanges(); db.Bans.Find(IDBan).TinhTrang = 0; } else { HoaDon hoaDon = db.HoaDons.FirstOrDefault(t => t.MaBan == IDBan && t.TinhTrang == false); hoaDon.TongTien += donGia * soLuong; } int maHD = (int)db.HoaDons.FirstOrDefault(t => t.MaBan == IDBan && t.TinhTrang == false).MaHD; CTHD additemCTHD = new CTHD() { MaHD = maHD, MaSP = IDSP, SoLuong = soLuong, ThanhTien = soLuong * donGia }; db.CTHDs.Add(additemCTHD); db.SaveChanges(); } else { banDAO ban = giohang.FirstOrDefault(t => t.IDSanPham == IDSP); ban.SoLuong += soLuong; int maHD = (int)db.HoaDons.FirstOrDefault(t => t.MaBan == IDBan && t.TinhTrang == false).MaHD; db.CTHDs.FirstOrDefault(t => t.MaHD == maHD && t.MaSP == IDSP).SoLuong += soLuong; db.CTHDs.FirstOrDefault(t => t.MaHD == maHD && t.MaSP == IDSP).ThanhTien += soLuong * donGia; db.HoaDons.Find(maHD).TongTien += soLuong * donGia; db.SaveChanges(); } return(Redirect(Request.UrlReferrer.ToString())); }
public ActionResult DatHang(FormCollection collection) { string ten = ""; int gia = 0; int sl = 0; DONDATHANG ddh = new DONDATHANG(); KHACHHANG kh = (KHACHHANG)Session["Taikhoan"]; List <GioHang> gh = LayGioHang(); ddh.MAKH = kh.MaKH; ddh.NgayDat = DateTime.Now; DateTime ngaygiao = DateTime.Parse(collection["Ngaygiao"].ToString()); ddh.NgayGiao = ngaygiao; ddh.TinhTrangGiaoHang = false; ddh.DaThanhToan = false; data.DONDATHANGs.InsertOnSubmit(ddh); data.SubmitChanges(); foreach (var item in gh) { CTHD cthd = new CTHD(); cthd.MaDH = item.iMaSP; cthd.MaSP = ddh.MADH; cthd.SoLuong = item.iSoLuong; cthd.DonGia = (decimal)item.dDonGia; ten += item.sTenSP + " "; gia += (int)(cthd.DonGia * item.iSoLuong); data.CTHDs.InsertOnSubmit(cthd); } data.SubmitChanges(); string url = "https://www.baokim.vn/payment/product/[email protected]&id=&order_description=ABC" + "&product_name=" + ten + "&product_price=" + gia + "&product_quantity=" + sl + "&total_amount=" + gia + "&url_cancel=&url_detail=" + "&url_success=" + Url.Action("XacNhanDonHang", "GioHang"); Session["GioHang"] = null; return(Redirect(url)); }
public ActionResult DeleteConfirmed(string id) { CTHD cTHD = db.CTHDs.Find(id); db.CTHDs.Remove(cTHD); db.SaveChanges(); return(RedirectToAction("Index")); }
public static bool insert_bill_detail(CTHD cthd) { if (QLLK_DAO.add_bill_detail(cthd)) { return(true); } return(false); }
public ActionResult Edit([Bind(Include = "MaHoaDon,MaHang,Soluong,DonGia,ThanhTien,GiamGia,NgayLapHoaDon,KhachHang,NhanVien")] CTHD cTHD) { if (ModelState.IsValid) { db.Entry(cTHD).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cTHD)); }
public ActionResult Edit([Bind(Include = "MaHD,MaSP,Soluong,DongiaBan,Giamgia")] CTHD cTHD) { if (ModelState.IsValid) { db.Entry(cTHD).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaHD = new SelectList(db.HoaDons, "MaHD", "MaKH", cTHD.MaHD); return(View(cTHD)); }
public ActionResult Create([Bind(Include = "MaHoaDon,MaHang,Soluong,DonGia,ThanhTien,GiamGia,NgayLapHoaDon,KhachHang,NhanVien")] CTHD cTHD) { if (ModelState.IsValid) { db.CTHDs.Add(cTHD); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cTHD)); }
private void btnThemCTHD_Click(object sender, EventArgs e) { string strCn = @"Data Source=LAPTOP-OCUUTDBF\SQLEXPRESS;Initial Catalog=CuaHangDienTu;Integrated Security=True";// đây là chuổi kết nối SqlConnection Cn = new SqlConnection(strCn); CuaHangDienTuEntities entities = new CuaHangDienTuEntities(); List <SanPham> lstsp = entities.SanPhams.ToList(); foreach (var sp in lstsp) { if (sp.MaSP == long.Parse(cbbMaSP.SelectedValue.ToString())) { if (sp.SoLuongTon >= int.Parse(txtSoLuong.Text)) { long sl = long.Parse(txtSoLuong.Text); long DONGIA = long.Parse(txtDonGia.Text); CTHD cTHD = new CTHD { MaHD = this.MaHD, MaSP = long.Parse(cbbMaSP.SelectedValue.ToString()), DonGia = long.Parse(txtDonGia.Text), SoLuong = int.Parse(txtSoLuong.Text), ThanhTien = sl * DONGIA }; SqlConnection sqlConnection1 = Cn; try { string SQL = string.Format("INSERT INTO CTHD VALUES" + " ('{0}','{1}','{2}','{3}','{4}') ", +cTHD.MaHD, cTHD.MaSP, cTHD.DonGia, cTHD.SoLuong, cTHD.ThanhTien); sqlConnection1.Open(); SqlCommand command = new SqlCommand(SQL, sqlConnection1); command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { sqlConnection1.Close(); LoadData(); } } else { MessageBox.Show("Không đủ số lượng hàng!"); } } } }
public async Task <IActionResult> Create([Bind("MaCTHD,MaHD,MaSP,SoLuong,ThanhTien")] CTHD cTHD) { if (ModelState.IsValid) { _context.Add(cTHD); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cTHD)); }
public int Insert(CTHD obj) { SqlParameter[] para = { new SqlParameter("MaHD", obj.maHD), new SqlParameter("MaMH", obj.maMH), new SqlParameter("SoLuong", obj.soLuong), new SqlParameter("DonGia", obj.donGia) }; return(base.ExcuteSQL("CTHD_Insert", para)); }
public ActionResult Edit([Bind(Include = "ID,SanPhamID,SL,HoaDonID")] CTHD cTHD) { if (ModelState.IsValid) { db.Entry(cTHD).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.HoaDonID = new SelectList(db.HOADON, "ID", "Mota", cTHD.HoaDonID); ViewBag.SanPhamID = new SelectList(db.SANPHAM, "ID", "TenSP", cTHD.SanPhamID); return(View(cTHD)); }
public static CTHDDTO MappingCTHDDTO(this CTHD cthd)//Tên biết viết đầu là chữ thường để phân biệt với kiểu dữ liệu { return(new CTHDDTO { ID = cthd.ID, MaHD = cthd.MaHD, MaMon = cthd.MaMon, SoLuong = cthd.SoLuong, Gia = cthd.Gia, TenMon = cthd.TenMon }); }
public ActionResult Edit([Bind(Include = "MaKH,MaHD,SoDien,SoNuoc,GiaDien,GiaNuoc")] CTHD cTHD) { if (ModelState.IsValid) { db.Entry(cTHD).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaHD = new SelectList(db.HoaDons, "MaHD", "MaKH", cTHD.MaHD); ViewBag.MaKH = new SelectList(db.KhachHangs, "MaKH", "HoTen", cTHD.MaKH); return(View(cTHD)); }
public static bool add_bill_detail(CTHD cthd) { string query = @"insert into CTHD values('" + cthd.Id_hd + "','" + cthd.Id_sp + "','" + cthd.Dongia + "','" + cthd.Soluong + "','" + cthd.Thanhtien + "')"; SqlConnection conn = new SqlConnection(@"Data Source=LAPTOP-A27VSOCJ\SQLEXPRESS;Initial Catalog=QLLK;Integrated Security=True"); SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return(false); }
// Trả về một đối tượng danh mục, khi biết Khóa // Thêm một đối tượng public bool Insert(CTHD model) { CTHD dbEntry = context.CTHDs.Find(model.MaHD, model.MaGT); if (dbEntry != null) { return(false); } context.CTHDs.Add(model); context.SaveChanges(); return(true); }
public bool Insert(CTHD detail) { try { db.CTHDs.Add(detail); db.SaveChanges(); return(true); } catch { return(false); } }
public ActionResult Create([Bind(Include = "MaHD,MaSP,Soluong,DongiaBan,Giamgia")] CTHD cTHD) { if (ModelState.IsValid) { db.CTHDs.Add(cTHD); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaHD = new SelectList(db.HoaDons, "MaHD", "MaKH", cTHD.MaHD); ViewBag.MaSP = new SelectList(db.SanPhams, "MaSP", "TenSP", cTHD.MaSP); return(View(cTHD)); }
// Xóa một đối tượng public bool Delete(int MaDM) { CTHD dbEntry = context.CTHDs.Find(MaDM); if (dbEntry == null) { return(false); } context.CTHDs.Remove(dbEntry); context.SaveChanges(); return(true); }
public ActionResult Create([Bind(Include = "MaHD,MaMH,SoLuong,DonGia,GiamGia")] CTHD cTHD) { if (ModelState.IsValid) { db.CTHDs.Add(cTHD); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaHD = new SelectList(db.HoaDons, "MaHD", "MaKH", cTHD.MaHD); ViewBag.MaMH = new SelectList(db.MatHangs, "MaMH", "TenMH", cTHD.MaMH); return(View(cTHD)); }
public void LuuCTHD(string sohd, string masp, string soluong, string giaban) { CTHD cthd = new CTHD(); cthd.SOHD = sohd; cthd.MASP = masp; cthd.SL = Convert.ToInt32(soluong); cthd.GIABAN = int.Parse(giaban); data.Database().CTHDs.InsertOnSubmit(cthd); data.Database().SubmitChanges(); }
// GET: CTHDs/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CTHD cTHD = db.CTHDs.Find(id); if (cTHD == null) { return(HttpNotFound()); } return(View(cTHD)); }
private void btnThemMon_Click(object sender, EventArgs e) { int maMon = Int32.Parse(cbMonAn.SelectedValue.ToString()); int SLMon = (int)nmSLMonAn.Value; if (maBanHT == 0) { MessageBox.Show("Vui lòng chọn bàn!"); } else if (!LayMonAn(maMon, SLMon)) { MessageBox.Show("Đã hết món!"); } else { HoaDon hoaDon = model.HoaDon.FirstOrDefault(c => c.maBan == maBanHT && c.trangThai == false); if (hoaDon == null) { HoaDon HD = new HoaDon(); HD.maNhanVien = frmMain.maTaiKhoan; HD.ngayVao = DateTime.Now; HD.ngayRa = null; HD.maBan = maBanHT; HD.maKhuyenMai = null; HD.trangThai = false; model.HoaDon.Add(HD); model.SaveChanges(); } hoaDon = model.HoaDon.FirstOrDefault(c => c.maBan == maBanHT && c.trangThai == false); CTHD cTHD = model.CTHD.FirstOrDefault(c => c.maHoaDon == hoaDon.ma && c.maMonAn == maMon); if (cTHD != null) { cTHD.soLuong = cTHD.soLuong + SLMon; model.SaveChanges(); } else { CTHD x = new CTHD(); x.maHoaDon = hoaDon.ma; x.maMonAn = maMon; x.soLuong = SLMon; model.CTHD.Add(x); model.SaveChanges(); } ShowHoaDon(maBanHT); LoadTableBtn(model.Ban.ToList()); } ButtonLock(true); }
// GET: CTHDs/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CTHD cTHD = db.CTHDs.SingleOrDefault(m => m.MaHD == id); if (cTHD == null) { return(HttpNotFound()); } return(View(cTHD)); }
public static CTHD SelectCTHDDAL(string key) { var query = from item in db.CTHDs where item.MACTHD == key select new { item.MACTHD, item.MASACH, item.MAHD, item.SL_BAN }; CTHD cthd = new CTHD(); foreach (var item in query) { cthd.MACTHD = item.MACTHD; cthd.MASACH = item.MASACH; cthd.MAHD = item.MAHD; cthd.SL_BAN = item.SL_BAN; } return cthd; }
public static void UpdateCTHDDAL(CTHD item) { var query = db.CTHDs.Single(i => i.MACTHD == item.MACTHD); query.MASACH = item.MASACH; query.MAHD = item.MAHD; query.SL_BAN = item.SL_BAN; db.SubmitChanges(); }
public static void InsertCTHDDAL(CTHD item) { db.CTHDs.InsertOnSubmit(item); db.SubmitChanges(); }