public ActionResult LuuDonHang(FormCollection c) { string ngaygiao = c["txtDate"]; GioHang gio = Session["gh"] as GioHang; tbl_KhachHang khach = Session["kh"] as tbl_KhachHang; tbl_HoaDon hd = new tbl_HoaDon(); hd.NgayHoaDon = DateTime.Now; hd.MaKH = khach.MaKhachHang; hd.NgayGiao = DateTime.Parse(ngaygiao); data.tbl_HoaDons.InsertOnSubmit(hd); data.SubmitChanges(); //Lưu nhiều dòng vào bảng chi tiết đơn hàng foreach (CartItem item in gio.dsSP) { tbl_ChiTiet ct = new tbl_ChiTiet(); ct.MaHD = hd.MaHoaDon; ct.MaSP = item.iMaSach; ct.SoLuong = item.iSoluong; data.tbl_ChiTiets.InsertOnSubmit(ct); data.SubmitChanges(); } Session["gh"] = null; return(View()); }
public IHttpActionResult Puttbl_HoaDon(long id, tbl_HoaDon tbl_HoaDon) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tbl_HoaDon.ID) { return(BadRequest()); } db.Entry(tbl_HoaDon).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tbl_HoaDonExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
//xu ly thanh toan public ActionResult XLTT() { if (Session["KH"] == null) { return(RedirectToAction("DangNhap", "KhachHang")); } else { tbl_HoaDon hd = new tbl_HoaDon(); hd.NgayTao = DateTime.Now; tbl_KhachHang kh = (tbl_KhachHang)Session["KH"]; hd.MaKH = kh.MaKhachHang; mk.tbl_HoaDons.InsertOnSubmit(hd); mk.SubmitChanges(); tbl_ChiTietHD ct; List <GioHang> GH = LayGioHang(); foreach (var i in GH) { ct = new tbl_ChiTietHD(); ct.MaHD = hd.MaHoaDon; ct.MaSP = i.Masp; ct.SoLuong = i.SL; mk.tbl_ChiTietHDs.InsertOnSubmit(ct); mk.SubmitChanges(); } } return(RedirectToAction("Index", "Home")); }
public IHttpActionResult Gettbl_HoaDon(long id) { tbl_HoaDon tbl_HoaDon = db.tbl_HoaDon.Find(id); if (tbl_HoaDon == null) { return(NotFound()); } return(Ok(tbl_HoaDon)); }
public IHttpActionResult Posttbl_HoaDon(tbl_HoaDon tbl_HoaDon) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.tbl_HoaDon.Add(tbl_HoaDon); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = tbl_HoaDon.ID }, tbl_HoaDon)); }
public IHttpActionResult Deletetbl_HoaDon(long id) { tbl_HoaDon tbl_HoaDon = db.tbl_HoaDon.Find(id); if (tbl_HoaDon == null) { return(NotFound()); } db.tbl_HoaDon.Remove(tbl_HoaDon); db.SaveChanges(); return(Ok(tbl_HoaDon)); }
public ActionResult Edit(tbl_HoaDon model) { if (ModelState.IsValid) { var session = (UserLogin)Session[CommonConstants.USER_SESSION]; model.sNguoiTiepNhan = session.UserName; //var result = dao.Edit(model); new HoaDonDAO().Update(model); SetAlert("Cập nhật thành công", "success"); return(RedirectToAction("Index")); } setViewBag(model.iMaTrangThai); return(View()); }
public bool Update(tbl_HoaDon entity) { try { var hoadon = db.tbl_HoaDon.Find(entity.ID); hoadon.dNgaySua = DateTime.Now; hoadon.iStatus = entity.iStatus; hoadon.iMaTrangThai = entity.iMaTrangThai; db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
private void btnXoa_Click(object sender, EventArgs e) { if (dgvHoaDon.SelectedRows.Count > 0) { if (XtraMessageBox.Show("Bạn có muốn xóa không ? ", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { string mahd = txtMaHDon.Text; tbl_HoaDon hd = db.tbl_HoaDon.Find(mahd); db.tbl_HoaDon.Remove(hd); db.SaveChanges(); HienThiDSHoaDon(); setNull(); } } else { XtraMessageBox.Show("Vui lòng chọn dòng cần xóa"); } }
public ActionResult Success() { var order = new tbl_HoaDon(); String Token = Request["token"]; if (Token != null) { long orderID = long.Parse(Request["Order_code"]); RequestCheckOrder info = new RequestCheckOrder(); info.Merchant_id = MerchantID; info.Merchant_password = MerchantPassword; info.Token = Token; APICheckoutV3 objNLChecout = new APICheckoutV3(); ResponseCheckOrder result = objNLChecout.GetTransactionDetail(info); ViewBag.Message = result.errorCode + result.payerName; order.ID = orderID; order.iStatus = 1; order.iMaTrangThai = 1; new HoaDonDAO().Update(order); } return(View()); }
private void btnLuu_Click(object sender, EventArgs e) { try { string mahd = txtMaHDon.Text; string nhanvien = cboTenNV.SelectedValue.ToString(); string makh = txtMaKH.Text; string tenkh = txtTenKH.Text; string mahdong = txtMaHopDong.Text; DateTime ngaylap = DateTime.Parse(dtpNgayLap.Value.ToString("dd/MM/yyyy")); DateTime ngaytra = DateTime.Parse(dtpNgayTra.Value.ToString("dd/MM/yyyy")); float thanhtien = float.Parse(txtThanhTien.Text); float giaphong = float.Parse(txtGiaPhong.Text); string noidung = txtNoiDung.Text; if (Flag == true) { if (db.tbl_HoaDon.SqlQuery("select * from tbl_HoaDon").Where(m => m.MaHoaDon.Contains(txtMaHDon.Text)).Count() > 0) { XtraMessageBox.Show("Mã hóa đơn nhập sai hoặc bị trùng", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (txtNoiDung.Text == "") { XtraMessageBox.Show("Vui lòng nhập đầy đủ thông tin!"); } else { tbl_HoaDon hd = new tbl_HoaDon(); hd.MaHoaDon = mahd; hd.MaNhanVien = nhanvien; hd.MaKhachHang = makh; hd.HoTenKhach = tenkh; hd.MaHopDong = mahdong; hd.NgayLap = ngaylap; hd.NgayTra = ngaytra; hd.GiaPhong = giaphong; hd.NoiDung = noidung; hd.ThanhTien = thanhtien; db.tbl_HoaDon.Add(hd); db.SaveChanges(); HienThiDSHoaDon(); XtraMessageBox.Show("Thêm hóa đơn thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); setNull(); setButton(true); setKhoa(true); } } } else { tbl_HoaDon hd = db.tbl_HoaDon.Where(m => m.MaHoaDon == mahd).FirstOrDefault(); hd.MaNhanVien = nhanvien; hd.MaKhachHang = makh; hd.HoTenKhach = tenkh; hd.MaHopDong = mahdong; hd.NgayLap = ngaylap; hd.NgayTra = ngaytra; hd.GiaPhong = giaphong; hd.NoiDung = noidung; hd.ThanhTien = thanhtien; if (hd == null) { XtraMessageBox.Show("Hóa đơn không tồn tại!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { db.Entry(hd).State = EntityState.Modified; db.SaveChanges(); HienThiDSHoaDon(); XtraMessageBox.Show("Cập nhật thành công!", "Thông Báo"); setNull(); setButton(true); setKhoa(true); } } } catch { } }
public JsonResult JSPayCheck(FormCollection form) { JsonResult js = new JsonResult(); bool isNumeric = true; string finame = form["finame"]; string miname = form["miname"]; string laname = form["laname"]; string add1 = form["add1"]; string add2 = form["add2"]; string country = form["country"]; string state = form["state"]; string city = form["city"]; string phone = form["phone"]; if (string.IsNullOrEmpty(finame) || string.IsNullOrEmpty(laname) || string.IsNullOrEmpty(add1) || string.IsNullOrEmpty(country) || string.IsNullOrEmpty(state) || string.IsNullOrEmpty(city) || string.IsNullOrEmpty(phone)) { js.Data = new { status = "EMPTY" }; } else { foreach (char c in phone) { if (!Char.IsNumber(c)) { isNumeric = false; break; } } if (isNumeric == false) { js.Data = new { status = "ERRPHONE" }; } else { if (phone.Length != 10) { js.Data = new { status = "ERRPHONE" }; } else { string address = add1 + " " + add2 + " " + state + " " + city + " " + country; string name = finame + " " + miname + " " + laname; if (Session["Cart"] == null) { Response.Redirect("/Product/Product/1"); } Code code = new Code(); List <CartItem> giohang = Session["Cart"] as List <CartItem>; if (giohang.Count() == 0) { Response.Redirect("/Product/Product/1"); } bool status = true; foreach (CartItem item in giohang) { if (item.SoLuong > code.Get_ThietBi().FirstOrDefault(m => m.MaThietBi == item.SanPhamID).SoLuong) { status = false; item.SoLuong = code.Get_ThietBi().FirstOrDefault(m => m.MaThietBi == item.SanPhamID).SoLuong; } } if (status == true) { if (Session["User"] == null) { Response.Redirect("/Login/Login"); } else { tbl_KhachHang u = (tbl_KhachHang)Session["User"]; tbl_HoaDon hd = new tbl_HoaDon(); hd.MaKhachHang = u.MaKhachHang; hd.NgayLap = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year; hd.MaTrangThaiDonHang = 2; hd.DiaChiNhan = address; hd.NguoiNhan = name; hd.SDT = int.Parse(phone); hd.TongTien = giohang.Sum(m => m.ThanhTien); hd.TrangThaiThanhToan = 2; code.AddObject(hd); foreach (CartItem item in giohang) { tbl_ChiTietHoaDon cthd = new tbl_ChiTietHoaDon(); cthd.MaHoaDon = hd.MaHoaDon; cthd.MaThietBi = item.SanPhamID; cthd.SoLuong = item.SoLuong; cthd.ThanhTien = item.ThanhTien; cthd.DonGia = item.DonGia; code.AddObject(cthd); code.Save(); tbl_ThietBi tb = code.Get_ThietBi().FirstOrDefault(m => m.MaThietBi == item.SanPhamID); tb.SoLuong = tb.SoLuong - item.SoLuong; code.Save(); } code.Save(); Session.Remove("Cart"); js.Data = new { status = "OK" }; } } else { js.Data = new { status = "ER" }; } } } } return(Json(js, JsonRequestBehavior.AllowGet)); }
public ActionResult Payment(string sTenNguoiNhan, string sEmail, string sSoDienThoai, string sDiaChi, string FormOfPayment, string sBankCode, FormCollection formcollection) { var order = new tbl_HoaDon(); var userSession = (UserLogin)Session[Common.CommonConstants.USER_SESSION]; var TenTinhThanh = formcollection["hdnTenTinhThanh"]; var TenQuanHuyen = formcollection["hdnTenQuanHuyen"]; string diachi = TenQuanHuyen + ", " + TenTinhThanh; if (userSession != null) { order.IDKhachHang = userSession.UserID; } order.dNgayTao = DateTime.Now; order.sTenNguoiNhan = sTenNguoiNhan; order.sEmailNguoiNhan = sEmail; order.sSDTnguoiNhan = sSoDienThoai; order.sDiaChi = sDiaChi + ", " + TenQuanHuyen + ", " + TenTinhThanh; order.sFormOfPayment = FormOfPayment; order.iMaTrangThai = 1; try { var id = new HoaDonDAO().Insert(order); var cart = (List <GioHangItems>)Session[CartSession]; var detailDao = new Model.DAO.ChiTietHoaDonDAO(); decimal total = 0; foreach (var item in cart) { var divsp = new SanPhamDAO(); var orderDetail = new tbl_ChiTietHoaDon(); orderDetail.IDSanPham = item.SanPham.ID; orderDetail.IDHoaDon = id; orderDetail.sGhiChu = item.sGhiChu; orderDetail.iSoLuong = item.SoLuong; if (item.SanPham.dGiaKhuyenMai != null && item.SanPham.dGiaKhuyenMai != 0) { orderDetail.dDonGia = item.SanPham.dGiaKhuyenMai; } else { orderDetail.dDonGia = item.SanPham.dGiaBan; } detailDao.Insert(orderDetail); if (item.SanPham.dGiaKhuyenMai != null && item.SanPham.dGiaKhuyenMai != 0) { total += (item.SanPham.dGiaKhuyenMai.GetValueOrDefault(0) * item.SoLuong); } else { total += (item.SanPham.dGiaBan.GetValueOrDefault(0) * item.SoLuong); } divsp.divSanPham(item.SanPham.ID, item.SoLuong); //ViewBag.Total = total; } if (!FormOfPayment.Equals("COD")) { RequestInfo info = new RequestInfo(); info.Merchant_id = MerchantID; info.Merchant_password = MerchantPassword; info.Receiver_email = MerchantEmail; info.cur_code = "vnd"; info.bank_code = sBankCode; info.Order_code = id.ToString(); info.Total_amount = total.ToString(); info.fee_shipping = "0"; info.Discount_amount = "0"; info.order_description = "Thanh toán đơn hàng Myhands Store"; info.return_url = currentLink + "/hoan-thanh"; info.cancel_url = currentLink + "/loi-thanh-toan"; info.Buyer_fullname = sTenNguoiNhan; info.Buyer_email = sEmail; info.Buyer_mobile = sSoDienThoai; APICheckoutV3 objNLChecout = new APICheckoutV3(); ResponseInfo result = objNLChecout.GetUrlCheckout(info, FormOfPayment); if (result.Error_code == "00") { Response.Redirect(result.Checkout_url); //return Redirect("/hoan-thanh"); } else { return(Redirect("/loi-thanh-toan")); } } string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/Client/Templates/MailForm.html")); content = content.Replace("{{sTenNguoiNhan}}", sTenNguoiNhan); content = content.Replace("{{sSoDienThoai}}", sSoDienThoai); content = content.Replace("{{sEmail}}", sEmail); content = content.Replace("{{sDiaChi}}", sDiaChi + diachi); content = content.Replace("{{Total}}", total.ToString("N0")); var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString(); new Mail().SendMail(sEmail, "Đơn hàng mới từ MyHandsStore", content); new Mail().SendMail(toEmail, "Đơn hàng mới từ MyHandsStore", content); } catch (Exception ex) { string script = "<script>alert('" + ex.Message + "');</script>"; return(Redirect("/loi-thanh-toan")); } Session[CartSession] = null; return(Redirect("/hoan-thanh")); }
public long Insert(tbl_HoaDon order) { db.tbl_HoaDon.Add(order); db.SaveChanges(); return(order.ID); }