Esempio n. 1
0
        // GET: SANPHAMs
        public ActionResult Index(string searchTerm, int page = 1, int pageSize = 11)
        {
            var SanPhams = new SANPHAMsController();
            var mode     = SanPhams.ListAllPaging(searchTerm, page, pageSize);

            ViewBag.SearchTerm = searchTerm;

            return(View(mode));
        }
Esempio n. 2
0
        public ActionResult CreateDH(string id1, string id2, string id3, string id4)
        {
            if (id4.Length <= 9 || string.IsNullOrEmpty(id3))
            {
                ModelState.AddModelError("", "Vui lòng điền đầy đủ thông tin !");
            }
            else
            {
                SANPHAMsController sANPHAM = new SANPHAMsController();

                DONHANG dONHANG = new DONHANG();
                if (ModelState.IsValid)
                {
                    //dONHANG.NV_ID = Session["NV_ID"].ToString();
                    dONHANG.DN_ID   = db.autottang("DonHang", "DN_ID", db.DONHANGs.Count());
                    dONHANG.DN_SDT  = id4;
                    dONHANG.TTDH_ID = 4;
                    if (Session["KH_ID"] != null)
                    {
                        string KH_ID = Session["KH_ID"].ToString();
                        dONHANG.KH_ID = KH_ID;
                    }

                    dONHANG.DN_NGALAPDON = DateTime.Now;
                    dONHANG.DN_GHICHU    = "Khách đặc Online";
                    dONHANG.HTTT_ID      = Convert.ToInt16(id1);
                    //dONHANG.DN_SL = Convert.ToInt32(id2);
                    db.DONHANGs.Add(dONHANG);
                    db.SaveChanges();


                    int            DN_ID          = Convert.ToInt32(dONHANG.DN_ID);
                    CHITIETDONHANG cHITIETDONHANG = new CHITIETDONHANG();
                    var            giohang        = Session["giohang"] as List <CartItem>;
                    foreach (var i in giohang)
                    {
                        string CTDH_ID = db.autottang("CHITIETDONHANG", "CTDH_ID", db.CHITIETDONHANGs.Count()).ToString();

                        string SP_ID = i.SanPhamID;
                        short  TT    = db.Database.SqlQuery <short>("select SP_TRANGTHAI from SanPham where SP_ID ='" + SP_ID + "'").SingleOrDefault();
                        if (TT == 1)
                        {
                            db.Database.ExecuteSqlCommand("Insert into ChiTietDonHang (CTDH_ID,DN_ID,SP_ID,CTDH_DIACHIGIAO) values('" + CTDH_ID + "','" + DN_ID + "','" + SP_ID + "',N'" + id3 + "')");
                            db.Database.ExecuteSqlCommand("update sanpham set SP_TRANGTHAI =0 where SP_ID ='" + SP_ID + "'");

                            ModelState.AddModelError("", "Xạc nhận mua " + i.SanPhamID + " thành công");
                        }
                        CartItem itemXoa = giohang.FirstOrDefault(m => m.SanPhamID == i.SanPhamID);
                        giohang.Remove(itemXoa);
                    }
                    ModelState.AddModelError("", "Đã thêm chờ hàng vui lòng chờ duyệt đơn !");
                }
            }
            return(View());
        }
Esempio n. 3
0
        public ActionResult Index(string HTTT_ID, string TXTSL, string DN_DIACHI, string DN_EMAIL, string DN_SDT, string DN_MATHE, string DN_CHUTHE, string DN_NGAYCAP)
        {
            ViewBag.sdt    = DN_SDT;
            ViewBag.diachi = DN_DIACHI;
            ViewBag.email  = DN_EMAIL;

            ViewBag.HTTT_ID = new SelectList(db.HINHTHUCTHANHTOANs, "HTTT_ID", "HTTT_TEN");
            List <CartItem> giohang = Session["giohang"] as List <CartItem>;

            ViewBag.diachi = db.Database.SqlQuery <string>("select dn.DN_DIACHI from CHITIETDONHANG ctdn inner join DONHANG dn on ctdn.DN_ID = dn.DN_ID and dn.KH_ID ='" + Session["KH_ID"] + "' group by dn.DN_DIACHI").LastOrDefault();


            if (ModelState.IsValid)
            {
                if (DN_SDT.Length <= 9 || !DN_SDT.StartsWith("09") && !DN_SDT.StartsWith("08") && !DN_SDT.StartsWith("03") && !DN_SDT.StartsWith("05") && !DN_SDT.StartsWith("07"))
                {
                    ModelState.AddModelError("", "Vui lòng điền nhập đúng SĐT !");
                }
                else if (string.IsNullOrEmpty(DN_DIACHI))
                {
                    ModelState.AddModelError("", "Vui lòng điền nhập địa chỉ !");
                }
                else if (string.IsNullOrEmpty(DN_EMAIL))
                {
                    ModelState.AddModelError("", "Vui lòng điền nhập email !");
                }
                else
                {
                    SANPHAMsController sANPHAM = new SANPHAMsController();

                    DONHANG dONHANG = new DONHANG();


                    //Session["DN_ID"] = db.autottang("DonHang", "DN_ID", db.DONHANGs.Count());
                    //dONHANG.NV_ID = Session["NV_ID"].ToString();
                    int DN_ID = db.autottang("DonHang", "DN_ID", db.DONHANGs.Count());
                    dONHANG.DN_ID   = DN_ID;
                    dONHANG.DN_SDT  = DN_SDT;
                    dONHANG.TTDH_ID = 4;
                    if (Session["KH_ID"] != null)
                    {
                        string KH_ID = Session["KH_ID"].ToString();
                        dONHANG.KH_ID = KH_ID;
                    }
                    dONHANG.DN_NGALAPDON = DateTime.Now;
                    dONHANG.DN_GHICHU    = "Khách đặc Online";
                    dONHANG.HTTT_ID      = Convert.ToInt16(HTTT_ID);
                    //dONHANG.DN_SL = Convert.ToInt32(TXTSL);
                    dONHANG.DN_DIACHI  = DN_DIACHI;
                    dONHANG.DN_MATHE   = DN_MATHE;
                    dONHANG.DN_CHUTHE  = DN_CHUTHE;
                    dONHANG.DN_NGAYCAP = DN_NGAYCAP;
                    dONHANG.DN_EMAIL   = DN_EMAIL;
                    db.DONHANGs.Add(dONHANG);
                    db.SaveChanges();

                    //string DN_ID = Session["DN_ID"].ToString();
                    CHITIETDONHANG cHITIETDONHANG = new CHITIETDONHANG();
                    List <string>  XoaItem        = new List <string>();
                    foreach (var i in giohang)
                    {
                        XoaItem.Add(i.SanPhamID);
                        string SP_ID = i.SanPhamID;
                        for (int y = 1; y <= i.SoLuong; y++)
                        {
                            string CTDH_ID = db.autottang("CHITIETDONHANG", "CTDH_ID", db.CHITIETDONHANGs.Count()).ToString();
                            string TT      = db.Database.SqlQuery <string>("select CTSP_ID from ChiTietSanPham where SP_ID ='" + i.SP_ID + "' and CTSP_TRANGTHAI =1").FirstOrDefault();
                            if (!string.IsNullOrEmpty(TT))
                            {
                                if (HTTT_ID == "1")
                                {
                                    db.Database.ExecuteSqlCommand("Insert into ChiTietDonHang (CTDH_ID,DN_ID,CTSP_ID) values('" + CTDH_ID + "','" + DN_ID + "','" + TT + "')");
                                }
                                else
                                {
                                    db.Database.ExecuteSqlCommand("Insert into ChiTietDonHang (CTDH_ID,DN_ID,CTSP_ID) values('" + CTDH_ID + "','" + DN_ID + "','" + TT + "')");
                                }

                                db.Database.ExecuteSqlCommand("update ChiTietSanPham set CTSP_TRANGTHAI = 0 where CTSP_ID ='" + TT + "'");

                                ModelState.AddModelError("", "Xạc nhận mua " + i.TenSanPham + " thành công");
                            }
                        }
                        //CartItem itemXoa = giohang.FirstOrDefault(m => m.SanPhamID == i.SanPhamID);
                        //giohang.Remove(itemXoa);
                    }
                    ModelState.AddModelError("", "Đã thêm chờ hàng vui lòng chờ duyệt đơn !");
                    Session["muathanhcong"] = 1;
                    foreach (var i in XoaItem)
                    {
                        CartItem itemXoa = giohang.FirstOrDefault(m => m.SanPhamID == i);
                        giohang.Remove(itemXoa);
                    }
                }
            }
            return(View(giohang));
        }