コード例 #1
0
        public void timdonhang(string id)
        {
            donhang dh = new donhang();

            try
            {
                dh                  = donhangtheoid(id);
                txtmsdh.Text        = dh.masodh + "";
                txttkkh.Text        = dh.tkkh + "";
                txtngaydathang.Text = dh.ngaydathang + "";
                txttinhtrang.Text   = dh.tinhtrang + "";
                txttknv1.Text       = dh.tknv1 + "";
                txttknv2.Text       = dh.tknv2 + "";
                txtdcnhanhang.Text  = dh.diachinhanhang + "";
                txtghichu.Text      = dh.ghichu + "";
            }
            catch
            {
                if (dh == null)
                {
                    MessageBox.Show("không tìm thấy");
                }
                txtmsdh.Text        = "";
                txttkkh.Text        = "";
                txtngaydathang.Text = "";
                txttinhtrang.Text   = "";
                txttknv1.Text       = "";
                txttknv2.Text       = "";
                txtdcnhanhang.Text  = "";
                txtghichu.Text      = "";
            };
        }
コード例 #2
0
        public donhang thongtindonhang(int id)
        {
            banhangDataContext context = new banhangDataContext();
            donhang            dh      = context.donhangs.FirstOrDefault(x => x.masodh == id);

            return(dh);
        }
コード例 #3
0
        public JsonResult handle(int id, int status)
        {
            donhang dh = db.donhangs.SingleOrDefault(n => n.id_hd == id);

            if (dh == null)
            {
                return(Json(false));
            }
            else
            {
                if (status == 1)
                {
                    dh.trangthai = status;
                    DateTime date = DateTime.Now;
                    dh.update_time     = date;
                    db.Entry(dh).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    db.donhangs.Remove(dh);
                    db.SaveChanges();
                }
                return(Json(true));
            }
        }
コード例 #4
0
ファイル: MyOrderController.cs プロジェクト: dutv/TTNQLBH
        public ActionResult Index()
        {
            string         namecus = Request.Form["txtHoTen"];
            string         phone   = Request.Form["txtSoDienThoai"];
            DateTime       date    = DateTime.Now;
            string         addcus  = Request.Form["txtDiaChi"];
            string         note    = Request.Form["txtGhiChu"];
            string         email   = Request.Form["txtEmail"];
            int            status  = 0;
            List <GioHang> listgh  = Session["cart"] as List <GioHang>;
            donhang        order   = new donhang();

            foreach (var item in listgh)
            {
                order.masp        = item.masp;
                order.tenkh       = namecus;
                order.sdt         = phone;
                order.thanhtien   = item.thanhtien;
                order.diachi      = addcus;
                order.ghichu      = note;
                order.soluong     = item.slmuasp;
                order.create_time = date;
                order.trangthai   = status;
                order.email       = email;
                db.donhangs.Add(order);
                db.SaveChanges();
            }
            return(View());
        }
コード例 #5
0
        // GET: Admin/Donhang/Details/5
        public ActionResult Chitietdonhang(int id)
        {
            var     ct      = (from i in db.GioHangs where i.id_donhang == id select i).ToList();
            donhang donhang = db.donhangs.Find(id);

            ViewBag.gh = ct;
            return(View(donhang));
        }
コード例 #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            donhang donhang = db.donhang.Find(id);

            db.donhang.Remove(donhang);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #7
0
        public ActionResult StepEnd()
        {
            //Nhận reqest từ trang index
            string phone    = Request.Form["phone"];
            string fullname = Request.Form["fullname"];
            string email    = Request.Form["email"];
            string address  = Request.Form["address"];
            string note     = Request.Form["note"];
            //kiểm tra xem có customer chưa và cập nhật lại
            khachhang newCus = new khachhang();
            var       cus    = db.khachhang.FirstOrDefault(p => p.sdtkh.Equals(phone));

            if (cus != null)
            {
                //nếu có số điện thoại trong db rồi
                //cập nhật thông tin và lưu
                cus.hovaten         = fullname;
                cus.email           = email;
                cus.diachi          = address;
                db.Entry(cus).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                //nếu chưa có sđt trong db
                //thêm thông tin và lưu
                return(RedirectToAction("Register", "User"));
            }
            //Thêm thông tin vào order và orderdetail
            List <CartItem> giohang = Session["giohang"] as List <CartItem>;
            //thêm order mới
            donhang newOrder   = new donhang();
            int     newIDOrder = db.donhang.OrderByDescending(p => p.ngaydat).FirstOrDefault().iddh;

            newOrder.iddh      = newIDOrder;
            newOrder.sdtkh     = phone;
            newOrder.ghichu    = note;
            newOrder.ngaydat   = DateTime.Now.ToString();
            newOrder.trangthai = "0";
            db.donhang.Add(newOrder);
            db.SaveChanges();
            //thêm details
            for (int i = 0; i < giohang.Count; i++)
            {
                chitietdonhang newOrdts = new chitietdonhang();
                newOrdts.iddh    = newOrder.iddh;
                newOrdts.idta    = giohang.ElementAtOrDefault(i).thucanID;
                newOrdts.soluong = giohang.ElementAtOrDefault(i).SoLuong;
                newOrdts.dongia  = giohang.ElementAtOrDefault(i).ThanhTien.ToString();
                db.chitietdonhang.Add(newOrdts);
                db.SaveChanges();
            }
            Session["MDH"]   = newOrder.iddh;
            Session["Phone"] = phone;
            //xoá sạch giỏ hàng
            giohang.Clear();
            return(RedirectToAction("HoaDon", "ThanhToan"));
        }
コード例 #8
0
        public ActionResult DatHang(FormCollection frmCollection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (Session["Taikhoan"] == null || Session["TaiKhoan"].ToString() == "")
                    {
                        return(RedirectToAction("chon", "NguoiDung", new { thongbao = "Chua-Dang-Nhap" }));
                    }
                    else
                    {
                        //Thêm đơn hàng
                        var hoTenNguoiNhan  = frmCollection["HoTenNguoiNgan"];
                        var diaChiNguoiNhan = frmCollection["DiaChiNguoiNhan"];
                        var sdtNguoiNhan    = frmCollection["SDTNguoiNhan"];
                        var ngayGiao        = String.Format("{0:MM/dd/yyyy}", frmCollection["NgayGiao"]);

                        donhang        dondathang = new donhang();
                        khachhang      khachhang  = (khachhang)Session["TaiKhoan"];
                        List <GioHang> lstGioHang = layGioHang();
                        //thông tin khách hàng đặt hàng
                        dondathang.idkh               = khachhang.idkh;
                        dondathang.ngaylap            = DateTime.Now;
                        dondathang.ngaygiaohang       = DateTime.Parse(ngayGiao);
                        dondathang.tinhtranggiao      = false;
                        dondathang.tinhtrangthanhtoan = false;
                        dondathang.hinhthucthanhtoan  = false;
                        //Người nhận
                        dondathang.hotennguoinhan       = hoTenNguoiNhan;
                        dondathang.diachinguoinhan      = diaChiNguoiNhan;
                        dondathang.sodienthoainguoinhan = sdtNguoiNhan;
                        data.donhangs.InsertOnSubmit(dondathang);
                        data.SubmitChanges();
                        //Chi chi tiết đơn hàng
                        foreach (var hang in lstGioHang)
                        {
                            chitietdh chitietdonhang = new chitietdh();
                            chitietdonhang.iddh    = dondathang.iddh;
                            chitietdonhang.idsach  = hang.sidsach;
                            chitietdonhang.soluong = hang.iSoLuong;
                            chitietdonhang.dongia  = (decimal)hang.dDonGia;
                            data.chitietdhs.InsertOnSubmit(chitietdonhang);
                        }
                        data.SubmitChanges();
                        Session["GioHang"] = null;
                    }
                }
                return(RedirectToAction("XacNhanDonHang", "GioHang"));
            }
            catch (Exception error)
            {
                return(RedirectToAction("XacNhanDonHang", "GioHang"));
            }
        }
コード例 #9
0
 public ActionResult Edit([Bind(Include = "iddh,sdtkh,ngaydat,ghichu,trangthai")] donhang donhang)
 {
     if (ModelState.IsValid)
     {
         db.Entry(donhang).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.sdtkh = new SelectList(db.khachhang, "sdtkh", "matkhau", donhang.sdtkh);
     return(View(donhang));
 }
コード例 #10
0
        public donhang donhangtheoid(string id)
        {
            string                     link           = tt.link + "donhang/" + id;
            HttpWebRequest             request        = WebRequest.CreateHttp(link);
            HttpWebResponse            response       = request.GetResponse() as HttpWebResponse;
            DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(donhang));
            object                     responsedata   = jsonSerializer.ReadObject(response.GetResponseStream());
            donhang                    dh             = responsedata as donhang;

            return(dh);
        }
コード例 #11
0
 public ActionResult Edit([Bind(Include = "madonhang,maphuongthucthanhtoan,tenkhachhang,ngaydathang,diachi,email,tinhtrang,ghichu,tongtienthanhtoan")] donhang donhang)
 {
     if (ModelState.IsValid)
     {
         db.Entry(donhang).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.maphuongthucthanhtoan = new SelectList(db.thanhtoan, "maphuongthucthanhtoan", "tenphuongthucthanhtoan", donhang.maphuongthucthanhtoan);
     return(View(donhang));
 }
コード例 #12
0
 public bool create(donhang dh)
 {
     try
     {
         _context.donhangs.Add(dh);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #13
0
        public ActionResult Edit(int id)
        {
            donhang dh = db.donhangs.SingleOrDefault(n => n.id_hd == id);

            if (dh == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            else
            {
                return(View(dh));
            }
        }
コード例 #14
0
 public RedirectToRouteResult Delete(int?id)
 {
     if (id == null)
     {
         return(RedirectToAction("Index"));
     }
     else
     {
         donhang donhang = db.donhangs.Find(id);
         db.donhangs.Remove(donhang);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
コード例 #15
0
        // GET: Areas/Donhang/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            donhang donhang = db.donhang.Find(id);

            if (donhang == null)
            {
                return(HttpNotFound());
            }
            return(View(donhang));
        }
コード例 #16
0
        // GET: Areas/Donhang/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            donhang donhang = db.donhang.Find(id);

            if (donhang == null)
            {
                return(HttpNotFound());
            }
            ViewBag.maphuongthucthanhtoan = new SelectList(db.thanhtoan, "maphuongthucthanhtoan", "tenphuongthucthanhtoan", donhang.maphuongthucthanhtoan);
            return(View(donhang));
        }
コード例 #17
0
        // GET: admin/donhangs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            donhang donhang = db.donhang.Find(id);

            if (donhang == null)
            {
                return(HttpNotFound());
            }
            ViewBag.sdtkh = new SelectList(db.khachhang, "sdtkh", "matkhau", donhang.sdtkh);
            return(View(donhang));
        }
コード例 #18
0
        public ActionResult DeleteOrder(int id_dh, string url)
        {
            donhang dhg = db.donhangs.Where(n => n.id == id_dh).Single();

            if (dhg == null)
            {
                Response.StatusCode = 404;
            }
            else
            {
                dhg.stat = -1;
                db.Entry(dhg);
                db.SaveChanges();
            }
            return(Redirect(url));
        }
コード例 #19
0
 public bool huydonhang(int masodh)
 {
     try
     {
         banhangDataContext context = new banhangDataContext();
         donhang            dh      = context.donhangs.FirstOrDefault(x => x.masodh == masodh);
         if (dh != null)
         {
             dh.tinhtrang = "huy";
             context.SubmitChanges();
             return(true);
         }
     }
     catch { };
     return(false);
 }
コード例 #20
0
 public bool hoanthanhdonhang(int masodh, string tknv2)
 {
     try
     {
         banhangDataContext context = new banhangDataContext();
         donhang            dh      = context.donhangs.FirstOrDefault(x => x.masodh == masodh);
         if (dh != null)
         {
             dh.tinhtrang = "hoantat";
             dh.tknv2     = tknv2;
             context.SubmitChanges();
             return(true);
         }
     }
     catch { };
     return(false);
 }
コード例 #21
0
        public void ThanhToanKoCoSan(List <cartModel> li, CheckOutInfoModel info)
        {
            try
            {
                khachhang kh = new khachhang();
                kh.diachi   = info.diaChi;
                kh.email    = info.gmail;
                kh.ghichu   = null;
                kh.gioitinh = info.gioitinh;
                kh.hoten    = info.tenKH;
                kh.sodt     = info.sdt;
                kh.matk     = null;
                context.khachhangs.Add(kh);
                context.SaveChanges();
                khachhang temp = context.khachhangs.Find(kh.makh);

                donhang dh = new donhang();
                dh.makh     = temp.makh;
                dh.ngaydat  = DateTime.Today;
                dh.tongtien = cartModel.tongTien;
                dh.ghichu   = null;
                dh.httt     = info.httt;
                context.donhangs.Add(dh);
                context.SaveChanges();
                donhang dhtemp = context.donhangs.Find(dh.madh);
                foreach (var sp in li)
                {
                    ctdh ct = new ctdh();
                    ct.madh    = dhtemp.madh;
                    ct.masp    = sp.maSP;
                    ct.soluong = sp.soLuong;
                    ct.gia     = sp.donGia;
                    context.ctdhs.Add(ct);
                }
                context.SaveChanges();
                cartModel.tongSoHang = 0;
                cartModel.tongTien   = 0;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #22
0
        public ActionResult Datmua()
        {
            List <CartItem> giohang        = Session["giohang"] as List <CartItem>;
            List <sanpham>  lisp           = db.sanpham.ToList();
            var             donhang        = db.donhang.ToList();
            var             chitietdonhang = db.chitietdonhang.ToList();
            donhang         dh             = new donhang();

            dh.email                 = Request.Form["email"];
            dh.diachi                = Request.Form["diachi"];
            dh.ghichu                = Request.Form["ghichu"];
            dh.ngaydathang           = DateTime.Now;
            dh.maphuongthucthanhtoan = int.Parse(Request.Form["phuongthuc"].ToString());
            dh.tenkhachhang          = Request.Form["hoten"];
            dh.tinhtrang             = "Đang chờ";
            dh.tongtienthanhtoan     = Convert.ToDecimal(Request.Form["tongtienthanhtoan"]);
            db.donhang.Add(dh);
            db.SaveChanges();
            for (int i = 0; i < giohang.Count; i++)
            {
                chitietdonhang ctdh = new chitietdonhang();
                ctdh.madonhang  = dh.madonhang;
                ctdh.masanpham  = giohang[i].masanpham;
                ctdh.soluongmua = giohang[i].soluong;
                ctdh.tensanpham = giohang[i].tensanpham;
                ctdh.dongia     = (decimal)giohang[i].dongia;
                ctdh.tongtien   = (decimal)giohang[i].thanhtien;
                db.chitietdonhang.Add(ctdh);
                // sửa lại số lượng sản phẩm trong csdl sau khi đặt mua
                sanpham sp = db.sanpham.Find(giohang[i].masanpham);
                sp.soluong = sp.soluong - giohang[i].soluong;
                db.SaveChanges();
            }
            for (int i = 0; i < giohang.Count; i++)
            {
                giohang.RemoveAt(i);
                i--;
            }



            return(RedirectToAction("Datmuathanhcong", "Home"));
        }
コード例 #23
0
        public int themdonhang(string tkkh, DateTime ngaydathang, string diachi, string ghichu)
        {
            int id = 0;

            try
            {
                banhangDataContext context = new banhangDataContext();
                donhang            dhmoi   = new donhang();
                dhmoi.tkkh           = tkkh;
                dhmoi.ngaydathang    = ngaydathang;
                dhmoi.diachinhanhang = diachi;
                dhmoi.tinhtrang      = "chuaxacnhan";
                dhmoi.ghichu         = ghichu;
                context.donhangs.InsertOnSubmit(dhmoi);
                context.SubmitChanges();
                id = dhmoi.masodh;
            }
            catch { };
            return(id);
        }
コード例 #24
0
        public List <donhang> getDonhangmoi()
        {
            DateTime ngaydat = DateTime.Now.Date;

            ngaydat.ToString("yyyy-MM-dd");
            var donhangmoi = (from dh in db.donhangs
                              join kh in db.khachhangs on(int) dh.makh equals(int) kh.makh
                              where dh.ngaydat == ngaydat
                              select new
            {
                dh.madh,
                kh.hoten,
                dh.ngaydat,
                dh.tongtien,
                dh.httt,
                dh.tttt,
                dh.ghichu
            });
            List <donhang> donhangmois = new List <donhang>();

            foreach (var dhm in donhangmoi)
            {
                donhang dh = new donhang();
                dh.madh     = (int)dhm.madh;
                dh.hoten    = dhm.hoten;
                dh.ngaydat  = dhm.ngaydat.ToString();
                dh.tongtien = (double)dhm.tongtien;
                dh.httt     = dhm.httt;
                dh.tttt     = dhm.tttt;
                if (dhm.ghichu == null)
                {
                    dh.ghichu = "Không có";
                }
                else
                {
                    dh.ghichu = dhm.ghichu;
                }
                donhangmois.Add(dh);
            }
            return(donhangmois);
        }
コード例 #25
0
        public int themdonhangtaicuahang(string tknv, DateTime ngaydathang)
        {
            int id = 0;

            try
            {
                banhangDataContext context = new banhangDataContext();
                donhang            dhmoi   = new donhang();
                dhmoi.tkkh           = "muataicuahang";
                dhmoi.tknv1          = tknv;
                dhmoi.tknv2          = tknv;
                dhmoi.ngaydathang    = ngaydathang;
                dhmoi.tinhtrang      = "muataicuahang";
                dhmoi.diachinhanhang = "tai cua hang";
                context.donhangs.InsertOnSubmit(dhmoi);
                context.SubmitChanges();
                id = dhmoi.masodh;
            }
            catch { };
            return(id);
        }
コード例 #26
0
 public RedirectToRouteResult CapnhatTT(int?id, int tt)
 {
     if (id == null)
     {
         return(RedirectToAction("Index"));
     }
     else
     {
         donhang donhang = db.donhangs.Find(id);
         if (donhang.trangthai == tt && tt != 3)
         {
             donhang.trangthai++;
         }
         else
         {
             donhang.ngayxn = DateTime.Now;
         }
         db.Entry(donhang).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
コード例 #27
0
        public ActionResult TaoDonHang(donhang dh)
        {
            try
            {
                user user = Session["TaiKhoan"] as user;
                // int x = user.id;
                //them don hang
                List <GioHang> giohang = Session["giohang"] as List <GioHang>;
                Session["giohang"] = null;
                //donhang a = new donhang();
                dh.user_id   = user.id;
                dh.trangthai = 1;

                db.donhangs.Add(dh);
                db.SaveChanges();
                dh.thanhtien = giohang.Sum(m => m.tongsotien);
                foreach (GioHang i in giohang)
                {
                    i.id_donhang = dh.id;
                    //                  i.tongsotien = i.soluong * i.dongia;
                    db.GioHangs.Add(i);
                    //tt =dh.thanhtien+ i.tongsotien;
                }
                if (ModelState.IsValid)
                {
                    dh.ngaytao         = DateTime.Now;
                    db.Entry(dh).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(dh));
            }
            catch
            {
                return(RedirectToAction("dangnhap", "dangnhap"));
            }

            //ViewBag.user_id = new SelectList(db.users, "id", "Ten", donhang.user_id);
        }
コード例 #28
0
        public RedirectToRouteResult huydon(int id_donhang)
        {
            List <GioHang> gh      = (from i in db.GioHangs where i.id_donhang == id_donhang select i).ToList();
            GioHang        itemXoa = null;

            foreach (GioHang i in gh)
            {
                itemXoa = db.GioHangs.Find(i.id);
                db.GioHangs.Remove(itemXoa);
                db.SaveChanges();
            }
            if (ModelState.IsValid)
            {
                List <donhang> x  = (from i in db.donhangs where i.id == id_donhang select i).ToList();
                donhang        dh = x[0];
                dh.trangthai       = 0;
                db.Entry(dh).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
コード例 #29
0
        public ActionResult chiTietHoaDon(int Mahoadon)
        {
            khachhang kh = (from khachhangmoi in data.khachhangs
                            join donhangmoi in data.donhangs on khachhangmoi.idkh equals donhangmoi.idkh
                            where (donhangmoi.iddh == Mahoadon)
                            select khachhangmoi).FirstOrDefault();

            ViewBag.khGuiHoTen  = kh.hotenkh;
            ViewBag.khGuiDiachi = kh.diachi;
            ViewBag.khGuiSDT    = kh.dienthoaikh;
            ViewBag.khGuiEmail  = kh.email;

            donhang dh = data.donhangs.Where(m => m.iddh == Mahoadon).FirstOrDefault();

            ViewBag.khNhanHoTen  = dh.hotennguoinhan;
            ViewBag.khNhanDiachi = dh.diachinguoinhan;
            ViewBag.khNhanSDT    = dh.sodienthoainguoinhan;

            var chiTietHD = data.ChiTietHoaDonKH(Mahoadon);

            return(View(chiTietHD));
        }
コード例 #30
0
        public ActionResult Ord_detail(int id_dh)
        {
            List <Ord_detail> ctdh = null;
            donhang           dhg  = db.donhangs.Where(n => n.id == id_dh).Single();

            if (dhg == null)
            {
                Response.StatusCode = 404;
            }
            else
            {
                ctdh = (from ct in db.chitietdonhangs join w in db.donghoes on ct.masp equals w.masp
                        select new Ord_detail
                {
                    w_id = ct.masp,
                    w_name = w.tensp,
                    w_brand = w.thuonghieu,
                    w_count = ct.soluong,
                    w_price = w.dongia
                }).ToList();
            }
            return(View(ctdh));
        }