Exemple #1
0
        public ActionResult Delete(int id, FormCollection collection, int?page)
        {
            MONAN ctv        = data.MONANs.SingleOrDefault(i => i.ID_MonAn == id);
            int   countMonAn = data.DONHANGs.Count(i => i.ID_MonAn == id);
            int   coutKM     = data.KhuyenMais.Count(i => i.ID_MonAn == id);

            if (countMonAn > 0)
            {
                ViewBag.ErrorBody = string.Format("Không thể Xóa  do [{0}] đang có [{1}] đơn hàng.", ctv.TenMonAn, countMonAn);
                CONGTACVIEN tk    = (CONGTACVIEN)Session["TenTK_CTV"];
                var         monan = from m in data.MONANs where m.MaTK_CTV == tk.MaTK_CTV select m;
                return(View("Index", monan));
            }
            if (coutKM > 0)
            {
                ViewBag.ErrorKM = string.Format("Không thể Xóa  do [{0}] đang được Khuyến Mại.", ctv.TenMonAn);
                CONGTACVIEN tk    = (CONGTACVIEN)Session["TenTK_CTV"];
                var         monan = from m in data.MONANs where m.MaTK_CTV == tk.MaTK_CTV select m;
                return(View("Index", monan));
            }
            else
            if (ModelState.IsValid)
            {
                data.MONANs.DeleteOnSubmit(ctv);
                data.SubmitChanges();
            }

            return(RedirectToAction("Index", "CTVMonAn"));
        }
Exemple #2
0
        public ActionResult Edit(FormCollection collection, CONGTACVIEN nd)
        {
            string      matkhaucu  = collection["MatKhauCu"];
            string      matkhaumoi = collection["MatKhauMoi"];
            string      nhaplai    = collection["NhapLaiMatKhauMoi"];
            CONGTACVIEN ctv        = data.CONGTACVIENs.SingleOrDefault(i => i.MaTK_CTV == nd.MaTK_CTV);

            if (matkhaumoi != nhaplai)
            {
                ViewBag.LoiMK = "Mật khẩu không trùng khớp";
            }
            if (ctv.MatKhau_CTV == matkhaucu)
            {
                ctv.TenTK_CTV   = nd.TenTK_CTV;
                ctv.MatKhau_CTV = matkhaumoi;
                UpdateModel(ctv);
                data.SubmitChanges();
                Session["TenTK_CTV"] = null;
                return(RedirectToAction("DangNhap", "CTVTaiKhoan"));
            }
            else
            {
                ViewBag.Loi = "Mật khẩu không hợp lệ";
            }
            return(View());
        }
Exemple #3
0
        public ActionResult Edit(int id)
        {
            if (Session["TenTK_CTV"] == null)
            {
                return(RedirectToAction("DangNhap", "CTVTaiKhoan"));
            }
            CONGTACVIEN ctv = data.CONGTACVIENs.SingleOrDefault(i => i.MaTK_CTV == id);

            return(View(ctv));
        }
Exemple #4
0
        public ActionResult ThongTinTK()
        {
            if (Session["TenTK_CTV"] == null)
            {
                return(RedirectToAction("DangNhap", "CTVTaiKhoan"));
            }
            CONGTACVIEN tk = (CONGTACVIEN)Session["TenTK_CTV"];
            var         tt = from m in data.CONGTACVIENs where m.MaTK_CTV == tk.MaTK_CTV select m;

            return(View(tt));
        }
Exemple #5
0
        public ActionResult PV_ThongKeMonAn()
        {
            if (Session["TenTK_CTV"] == null)
            {
                return(RedirectToAction("DangNhap", "CTVTaiKhoan"));
            }
            CONGTACVIEN tk  = (CONGTACVIEN)Session["TenTK_CTV"];
            var         top = from m in data.V_Top5MonAns where m.MaTK_CTV == tk.MaTK_CTV select m;

            return(PartialView(top));
        }
Exemple #6
0
        public ActionResult MonAnTheoCTV()
        {
            if (Session["TenTK_CTV"] == null)
            {
                return(RedirectToAction("DangNhap", "CTVTaiKhoan"));
            }
            CONGTACVIEN tk    = (CONGTACVIEN)Session["TenTK_CTV"];
            var         monan = from m in data.MONANs where m.MaTK_CTV == tk.MaTK_CTV select m;

            return(View(monan));
        }
Exemple #7
0
        // GET: CTVDonHang
        public ActionResult Index()
        {
            if (Session["TenTK_CTV"] == null)
            {
                return(RedirectToAction("DangNhap", "CTVTaiKhoan"));
            }
            CONGTACVIEN tk    = (CONGTACVIEN)Session["TenTK_CTV"];
            var         monan = from m in data.DONHANGs where m.MONAN.MaTK_CTV == tk.MaTK_CTV where m.DATHANG.TinhTrangGiao == false select m;

            return(View(monan));
        }
Exemple #8
0
        // GET: DoanhThu
        public ActionResult Index()
        {
            if (Session["TenTK_CTV"] == null)
            {
                return(RedirectToAction("DangNhap", "CTVTaiKhoan"));
            }
            CONGTACVIEN tk  = (CONGTACVIEN)Session["TenTK_CTV"];
            var         sum = from m in data.DOANHTHUs where m.MaTK_CTV == tk.MaTK_CTV select m;

            return(View(sum));
        }
Exemple #9
0
        // GET: CTVKhuyenMai
        public ActionResult Index()
        {
            if (Session["TenTK_CTV"] == null)
            {
                return(RedirectToAction("DangNhap", "CTVTaiKhoan"));
            }
            CONGTACVIEN tk    = (CONGTACVIEN)Session["TenTK_CTV"];
            var         monan = from m in data.KhuyenMais where m.MONAN.MaTK_CTV == tk.MaTK_CTV select m;

            // List<KHUYENMAI> monan = data.KHUYENMAIs.ToList();
            return(View(monan));
        }
Exemple #10
0
        // GET: AdminCTV/Delete/5
        public ActionResult Delete(int id)
        {
            if (Session["TenTK_Admin"] == null)
            {
                return(RedirectToAction("DangNhap", "AdminTaiKhoan"));
            }
            CONGTACVIEN ctv = data.CONGTACVIENs.SingleOrDefault(n => n.MaTK_CTV == id);

            ViewBag.Masach = ctv.MaTK_CTV;
            if (ctv == null)
            {
                return(RedirectToAction("Index", "AdminCTV"));
            }
            return(View(ctv));
        }
Exemple #11
0
        public ActionResult PV_Dropdown_MonAn(int?id)
        {
            if (Session["TenTK_CTV"] == null)
            {
                return(RedirectToAction("DangNhap", "CTVTaiKhoan"));
            }
            CONGTACVIEN tk    = (CONGTACVIEN)Session["TenTK_CTV"];
            var         monan = from m in data.MONANs where m.MaTK_CTV == tk.MaTK_CTV select m;

            if (id != null)
            {
                ViewBag.idLoai = id;
            }
            return(PartialView(monan));
        }
Exemple #12
0
        public ActionResult Tinh(FormCollection collection, DOANHTHU dt)
        {
            var gt = collection["ID_ChiecKhau"];

            ViewBag.MessageFail = string.Empty;
            if (!string.IsNullOrEmpty(ViewBag.MessageFail))
            {
                return(View());
            }
            CONGTACVIEN tk  = (CONGTACVIEN)Session["TenTK_CTV"];
            decimal     sum = 0;

            dt.MaTK_CTV     = tk.MaTK_CTV;
            sum             = Convert.ToDecimal(data.f_tongdt(tk.MaTK_CTV));
            dt.TongDoanhThu = sum;
            decimal tck = 0;

            tck = sum * Decimal.Parse(gt);
            dt.TienChiecKhau = tck;


            if (ModelState.IsValid)
            {
                data.DOANHTHUs.InsertOnSubmit(dt);
                try
                {
                    dt.Thang = DateTime.Now;
                    data.SubmitChanges();
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Violation of PRIMARY KEY constraint"))
                    {
                        ViewBag.MessageFail = string.Format("Doanh thu tháng {0} đã tồn tại, nếu muốn thay đổi, Vui lòng CẬP NHẬT.", dt.Thang);
                    }
                    else
                    {
                        ViewBag.ErrorBody = ex.ToString();
                    }
                    return(View());
                }
            }

            ViewBag.MessageSuccess = "Tính doanh thu tháng : [" + dt.Thang + "] thành công";
            return(View());
        }
Exemple #13
0
        public ActionResult DangNhap(FormCollection collection)
        {
            var         tendn   = collection["TenDangNhap"];
            var         matkhau = collection["MatKhau"];
            CONGTACVIEN tk      = this.data.CONGTACVIENs.FirstOrDefault(n => n.TenTK_CTV == tendn && n.MatKhau_CTV == matkhau);

            if (tk != null)
            {
                ViewBag.ThongBao     = "Đăng nhập thành công";
                Session["TenTK_CTV"] = tk;
                return(RedirectToAction("Index", "CTV"));
            }
            else
            {
                ViewBag.Thongbao = "Sai thông tin đăng nhập!";
            }
            return(View());
        }
Exemple #14
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            CONGTACVIEN ctv        = data.CONGTACVIENs.SingleOrDefault(i => i.MaTK_CTV == id);
            int         countMonAn = data.MONANs.Count(i => i.MaTK_CTV == id);

            if (countMonAn > 0)
            {
                ViewBag.ErrorBody = string.Format("Không thể Xóa  do [{0}] đang có [{1}] Món Ăn trên Web.", ctv.HoTen, countMonAn);
                List <CONGTACVIEN> all = data.CONGTACVIENs.ToList();
                return(View("Index", all.ToList()));
            }
            else
            if (ModelState.IsValid)
            {
                data.CONGTACVIENs.DeleteOnSubmit(ctv);
                data.SubmitChanges();
            }
            return(RedirectToAction("Index", "AdminCTV"));
        }
Exemple #15
0
        public ActionResult Edit(CONGTACVIEN congtacvien, FormCollection collection)
        {
            CONGTACVIEN ctv         = data.CONGTACVIENs.SingleOrDefault(i => i.MaTK_CTV == congtacvien.MaTK_CTV);
            var         giaquangcao = Convert.ToInt32(collection["GiaQuangCao"]);

            ctv.MaTK_CTV      = congtacvien.MaTK_CTV;
            ctv.TenTK_CTV     = congtacvien.TenTK_CTV;
            ctv.MatKhau_CTV   = congtacvien.MatKhau_CTV;
            ctv.HoTen         = congtacvien.HoTen;
            ctv.CMND          = congtacvien.CMND;
            ctv.Email         = congtacvien.Email;
            ctv.DiaChi        = congtacvien.DiaChi;
            ctv.DienThoai     = congtacvien.DienThoai;
            ctv.NgaySinh      = congtacvien.NgaySinh;
            ctv.GioiTinh      = congtacvien.GioiTinh;
            ctv.LevelVip      = giaquangcao;
            ctv.NgayHetHanVip = congtacvien.NgayHetHanVip;
            if (ModelState.IsValid)
            {
                UpdateModel(ctv);
                data.SubmitChanges();
            }
            return(RedirectToAction("Index"));
        }
Exemple #16
0
        public ActionResult Create(FormCollection collection, CONGTACVIEN tk)
        {
            var  tendn          = collection["TenDangNhap"];
            var  matkhau        = collection["MatKhau"];
            var  nhaplaimatkhau = collection["NhapLaiMatKhau"];
            var  hoten          = collection["HoTen"];
            var  cmnd           = collection["CMND"];
            var  email          = collection["Email"];
            var  diachi         = collection["DiaChi"];
            var  dienthoai      = collection["DienThoai"];
            var  ngaysinh       = String.Format("{0:MM/dd/yyyy}", collection["NgaySinh"]);
            bool gioitinh       = Convert.ToBoolean(Convert.ToInt16(collection["GioiTinh"]));
            var  giaquangcao    = Convert.ToInt32(collection["GiaQuangCao"]);
            var  ngayhethanvip  = String.Format("{0:MM/dd/yyyy}", collection["NgayHetHan"]);
            //Goi mail
            string user = "******";
            string pass = "******";

            SmtpClient client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential(user, pass),
                EnableSsl   = true
            };

            string      from    = user;
            string      to      = collection["Email"];
            MailMessage message = new MailMessage(from, to);

            message.Subject = "[THÔNG TIN TÀI KHOẢN CỘNG TÁC VIÊN]" + "-" + collection["HoTen"];
            message.Body    = "Tên tài khoản:" + " " + collection["TenDangNhap"] + " " + ", Mật khẩu:" + " " + collection["MatKhau"];

            try
            {
                client.Send(message);
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View("Index"));
            }
            //-----------------------------------
            ViewBag.MessageFail = string.Empty;
            if (nhaplaimatkhau != matkhau)
            {
                ViewBag.MessageFail += "Mật khẩu không trùng khớp";
            }
            if (DateTime.Now.Year - DateTime.Parse(ngaysinh).Year < 18)
            {
                ViewBag.MessageFail += "Cộng tác viên phải đủ 18 tuổi";
            }
            if (!string.IsNullOrEmpty(ViewBag.MessageFail))
            {
                return(View());
            }
            else
            {
                tk.TenTK_CTV     = tendn;
                tk.MatKhau_CTV   = matkhau;
                tk.HoTen         = hoten;
                tk.CMND          = cmnd;
                tk.Email         = email;
                tk.DiaChi        = diachi;
                tk.DienThoai     = dienthoai;
                tk.NgaySinh      = DateTime.Parse(ngaysinh);
                tk.GioiTinh      = gioitinh;
                tk.LevelVip      = giaquangcao;
                tk.NgayHetHanVip = DateTime.Parse(ngayhethanvip);
                data.CONGTACVIENs.InsertOnSubmit(tk);
                data.SubmitChanges();
            }
            ViewBag.MessageSuccess = "Thêm Cộng tác viên: [" + hoten + "] thành công";
            return(View());
        }
Exemple #17
0
        public ActionResult Create(FormCollection form, HttpPostedFileBase HinhAnh)
        {
            string  tenMonAn     = form["TenMonAn"];
            string  gioiThieu    = form["GioiThieu"];
            decimal giaban       = Decimal.Parse(form["GiaBan"]);
            decimal phivanchuyen = Decimal.Parse(form["PhiVanChuyen"]);
            int     soluong      = Int32.Parse(form["SoLuong"]);
            int     idkhuvuc     = Int32.Parse(form["ID_KhuVuc"]);
            int     idLoai       = Int32.Parse(form["ID_Loai"]);

            ViewBag.MessageFail = string.Empty;
            if (string.IsNullOrWhiteSpace(tenMonAn))
            {
                ViewBag.MessageFail += "Tên món ăn không hợp lệ. ";
            }
            if (!string.IsNullOrEmpty(ViewBag.MessageFail))
            {
                return(View());
            }

            string _FileName = "";

            try
            {
                if (HinhAnh.ContentLength > 0)
                {
                    string _folderPath = Path.Combine(Server.MapPath("~/images/MonAn/"));
                    // Determine whether the directory exists.
                    if (!Directory.Exists(_folderPath))
                    {
                        DirectoryInfo di = Directory.CreateDirectory(_folderPath);
                    }

                    _FileName = Path.GetFileName(HinhAnh.FileName);
                    string _path = Path.Combine(Server.MapPath("~/images/MonAn/"), _FileName);
                    if (!System.IO.File.Exists(_path))
                    {
                        HinhAnh.SaveAs(_path);
                    }
                }
            }
            catch
            {
            }

            MONAN       monAn = new MONAN();
            CONGTACVIEN tk    = (CONGTACVIEN)Session["TenTK_CTV"];

            monAn.TenMonAn     = tenMonAn;
            monAn.GiaBan       = giaban;
            monAn.PhiVanChuyen = phivanchuyen;
            monAn.MoTa         = gioiThieu;
            monAn.AnhBia       = _FileName;
            monAn.NgayCapNhap  = DateTime.Now;
            monAn.SoLuong      = soluong;
            monAn.ID_KhuVuc    = idkhuvuc;
            monAn.ID_Loai      = idLoai;
            monAn.MaTK_CTV     = tk.MaTK_CTV;

            if (ModelState.IsValid)
            {
                data.MONANs.InsertOnSubmit(monAn);
                data.SubmitChanges();
            }
            ViewBag.MessageSuccess = "Thêm món ăn: [" + tenMonAn + "] thành công";
            return(View());
        }
Exemple #18
0
        public ActionResult TaiKhoan()
        {
            CONGTACVIEN tk = (CONGTACVIEN)Session["TenTK_CTV"];

            return(PartialView(tk));
        }