Esempio n. 1
0
 public ActionResult CreateProduct(HANG hang)
 {
     try
     {
         if (hang.UploadImage != null)
         {
             string filename = Path.GetFileNameWithoutExtension(hang.UploadImage.FileName);
             string extent   = Path.GetExtension(hang.UploadImage.FileName);
             filename  = filename + extent;
             hang.Hinh = "~/Images/" + filename;
             hang.UploadImage.SaveAs(Path.Combine(Server.MapPath("~/Images/"), filename));
         }
         var check_ID = database.HANGs.Where(s => s.MaHH == hang.MaHH).FirstOrDefault();
         if (check_ID == null)
         {
             var types = database.LOAIs.ToList();
             ViewBag.Types = new SelectList(types, "MaLoai", "TenLoai");
             var coupon = database.DIEMTHUONGs.ToList();
             ViewBag.Coupons = new SelectList(coupon, "MaDT", "SoDT");
             var size = database.SIZEs.ToList();
             ViewBag.Sizes = new SelectList(size, "MaSize", "Size1");
             database.HANGs.Add(hang);
             database.SaveChanges();
             return(RedirectToAction("ProductsManagement"));
         }
         else
         {
             return(View("CreateProduct", hang));
         }
     }
     catch
     {
         return(View("CreateProduct", hang));
     }
 }
Esempio n. 2
0
        public ActionResult Xnxoahang(int id)
        {
            HANG loai = db.HANGs.SingleOrDefault(n => n.MaH == id);

            try
            {
                if (loai == null)
                {
                    Response.StatusCode = 404;
                    return(null);
                }
                else
                {
                    db.HANGs.DeleteOnSubmit(loai);
                    db.SubmitChanges();
                    ViewBag.Thongbao1 = "Đã Xóa Thành Công";
                }
            }
            catch
            {
                ViewBag.Thongbao1 = "Đã có nước hoa của hãng này trong danh sách";
            }

            return(RedirectToAction("HangSX"));
        }
Esempio n. 3
0
 public ActionResult themDienThoai(HANG dt, HttpPostedFileBase fileUp)
 {
     ViewBag.MANSX = new SelectList(data.NHASXes.ToList().OrderBy(n => n.TENNHASX), "MANSX", "TENNHASX");
     if (fileUp == null)
     {
         ViewBag.ThongBao = "Hãy chọn ảnh bìa";
         return(View());
     }
     else
     {
         if (ModelState.IsValid)
         {
             var fileName = Path.GetFileName(fileUp.FileName);
             var path     = Path.Combine(Server.MapPath("~/Content/images/sanpham"), fileName);
             if (System.IO.File.Exists(path))
             {
                 ViewBag.ThongBao = "Hình ảnh đã tồn tại";
             }
             else
             {
                 fileUp.SaveAs(path);
             }
             dt.HINHANH = fileName;
             data.HANGs.InsertOnSubmit(dt);
             data.SubmitChanges();
         }
     }
     return(RedirectToAction("Dienthoai", "Admin"));
 }
Esempio n. 4
0
 public ActionResult EditProduct(HANG hang)
 {
     try
     {
         if (hang.UploadImage != null)
         {
             string filename = Path.GetFileNameWithoutExtension(hang.UploadImage.FileName);
             string extent   = Path.GetExtension(hang.UploadImage.FileName);
             filename = filename + extent;
             var path = "~/Images/" + filename;
             if (path != "~/Images/product.png")
             {
                 hang.Hinh = path;
                 hang.UploadImage.SaveAs(Path.Combine(Server.MapPath("~/Images/"), filename));
             }
         }
         hang.SoLuongMua = 0;
         var types = database.LOAIs.ToList();
         ViewBag.Types = new SelectList(types, "MaLoai", "TenLoai");
         var coupon = database.DIEMTHUONGs.ToList();
         ViewBag.Coupons = new SelectList(coupon, "MaDT", "SoDT");
         var size = database.SIZEs.ToList();
         ViewBag.Sizes = new SelectList(size, "MaSize", "Size1");
         database.Entry(hang).State = System.Data.Entity.EntityState.Modified;
         database.SaveChanges();
         return(RedirectToAction("ProductsManagement"));
     }
     catch
     {
         return(View("EditProduct", hang));
     }
 }
Esempio n. 5
0
 public ActionResult themhang(HANG hang)
 {
     if (ModelState.IsValid)
     {
         db.HANGs.InsertOnSubmit(hang);
         db.SubmitChanges();
     }
     return(RedirectToAction("HangSX"));
 }
Esempio n. 6
0
 public ActionResult suahang(HANG hang)
 {
     if (ModelState.IsValid)
     {
         UpdateModel(hang);
         db.SubmitChanges();
     }
     return(RedirectToAction("HangSX"));
 }
Esempio n. 7
0
        public ActionResult suahang(int id)
        {
            HANG hang = db.HANGs.SingleOrDefault(n => n.MaH == id);

            if (hang == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            return(View(hang));
        }
Esempio n. 8
0
        public ActionResult xoaDT(int id)
        {
            HANG dt = data.HANGs.SingleOrDefault(n => n.MADT == id);

            ViewBag.MADT = dt.MADT;
            if (dt == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            return(View(dt));
        }
Esempio n. 9
0
        public ActionResult suaDT(int id)
        {
            HANG dt = data.HANGs.SingleOrDefault(n => n.MADT == id);

            if (dt == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            ViewBag.MANSX = new SelectList(data.NHASXes.ToList().OrderBy(n => n.TENNHASX), "MANSX", "TENNHASX", dt.MANSX);
            return(View(dt));
        }
Esempio n. 10
0
        public ActionResult XacNhanXoa(int id)
        {
            HANG dt = data.HANGs.SingleOrDefault(n => n.MADT == id);

            ViewBag.MADT = dt.MADT;
            if (dt == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            data.HANGs.DeleteOnSubmit(dt);
            data.SubmitChanges();
            return(RedirectToAction("chiTietDT", "Admin"));
        }
Esempio n. 11
0
        public bool Inseart()
        {
            var phong = new HANG()
            {
                Ten        = view.Ten,
                DonGiaBan  = view.DonGiaBan,
                DonGiaNhap = view.DonGiaNhap,
                SLTon      = view.SLTon,
                DonVi      = view.DonVi,
                Requested  = view.Requested
            };

            return(model.Insert(phong));
        }
Esempio n. 12
0
        public ActionResult Banmuonxoa(int id)
        {
            HANG hang = db.HANGs.SingleOrDefault(n => n.MaHang == id);

            ViewBag.MaHang = hang.MaHang;
            if (hang == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            db.HANGs.DeleteOnSubmit(hang);
            db.SubmitChanges();
            return(RedirectToAction("hangsanxuat"));
        }
Esempio n. 13
0
        public ActionResult CreateProduct()
        {
            var types = database.LOAIs.ToList();

            ViewBag.Types = new SelectList(types, "MaLoai", "TenLoai");
            var coupon = database.DIEMTHUONGs.ToList();

            ViewBag.Coupons = new SelectList(coupon, "MaDT", "SoDT");
            var size = database.SIZEs.ToList();

            ViewBag.Sizes = new SelectList(size, "MaSize", "Size1");
            HANG hang = new HANG();

            return(View(hang));
        }
Esempio n. 14
0
        public bool Update()
        {
            var ct = new HANG()
            {
                ID         = view.ID,
                Ten        = view.Ten,
                DonGiaNhap = view.DonGiaNhap,
                DonGiaBan  = view.DonGiaBan,
                SLTon      = view.SLTon,
                DonVi      = view.DonVi,
                //   Requested = view.Requested
            };

            return(model.Update(ct));
        }
Esempio n. 15
0
        public bool Inseart()
        {
            var hang = new HANG()
            {
                ID         = 0,
                Ten        = view.Ten,
                DonGiaNhap = view.DonGiaNhap,
                DonGiaBan  = view.DonGiaBan,
                SLTon      = view.SLTon,
                DonVi      = view.DonVi,
                //  Requested = view.Requested
            };

            return(model.Insert(hang));
        }
Esempio n. 16
0
        public ActionResult Themmoihang(HANG hang, HttpPostedFileBase fileUpload)
        {
            //Dua du lieu vao dropdownload

            //Kiem tra duong dan file

            //Them vao CSDL

            if (ModelState.IsValid)
            {
                //Luu vao CSDL
                db.HANGs.InsertOnSubmit(hang);
                db.SubmitChanges();
            }
            return(RedirectToAction("hangsanxuat"));
        }
Esempio n. 17
0
 public JsonResult Save(int id, string flag, string value)
 {
     if (flag == "mau")
     {
         MAU mau = _connect.MAUs.SingleOrDefault(p => p.ID == id);
         mau.MAUSP = value;
     }
     if (flag == "hang")
     {
         HANG hang = _connect.HANGs.SingleOrDefault(p => p.ID == id);
         hang.HANGSX = value;
     }
     if (flag == "loai")
     {
         LOAI loai = _connect.LOAIs.SingleOrDefault(p => p.ID == id);
         loai.LOAISP = value;
     }
     _connect.SaveChanges();
     return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
 }
Esempio n. 18
0
        public ActionResult Suahang(HANG hang, HttpPostedFileBase fileUpload)
        {
            //Dua du lieu vao dropdownload

            //Kiem tra duong dan file

            //Them vao CSDL

            if (ModelState.IsValid)
            {
                HANG h = db.HANGs.SingleOrDefault(n => n.MaHang == hang.MaHang);
                h.MaHang  = hang.MaHang;
                h.TenHang = hang.TenHang;

                //Luu vao CSDL
                UpdateModel(hang);
                db.SubmitChanges();
            }
            return(RedirectToAction("hangsanxuat"));
        }
Esempio n. 19
0
        public JsonResult Delete(int id, string flag)
        {
            if (flag == "mau")
            {
                MAU mau = _connect.MAUs.SingleOrDefault(p => p.ID == id);

                _connect.MAUs.Remove(mau);
            }
            if (flag == "hang")
            {
                HANG hang = _connect.HANGs.SingleOrDefault(p => p.ID == id);

                _connect.HANGs.Remove(hang);
            }
            if (flag == "loai")
            {
                LOAI loai = _connect.LOAIs.SingleOrDefault(p => p.ID == id);
                _connect.LOAIs.Remove(loai);
            }
            _connect.SaveChanges();
            return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 20
0
        public JsonResult Add(string flag, string value)
        {
            if (flag == "mau")
            {
                MAU mau = new MAU();
                mau.MAUSP = value;
                _connect.MAUs.Add(mau);
            }
            if (flag == "hang")
            {
                HANG hang = new HANG();
                hang.HANGSX = value;
                _connect.HANGs.Add(hang);
            }
            if (flag == "loai")
            {
                LOAI loai = new LOAI();
                loai.LOAISP = value;
                _connect.LOAIs.Add(loai);
            }

            _connect.SaveChanges();
            return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 21
0
        //Lưu đơn hàng
        private void btLuuDonHang_Click(object sender, EventArgs e)
        {
            if (CheckNull() == false)
            {
                //CẬP NHẬT NGƯỜI GỬI
                try
                {
                    NGUOIGUI checkNG = (from a in db.NGUOIGUIs where NGCMT.Text == a.CMND select a).SingleOrDefault();
                    if (checkNG == null)
                    {
                        NGUOIGUI NG = new NGUOIGUI();
                        NG.CMND   = NGCMT.Text;
                        NG.DIACHI = NGDiaChi.Text;
                        NG.HOTEN  = NGTen.Text;
                        NG.SDT    = NGSDT.Text;

                        db.NGUOIGUIs.InsertOnSubmit(NG);
                        db.SubmitChanges();
                    }
                    else
                    {
                        NGUOIGUI NG = (from a in db.NGUOIGUIs where NGCMT.Text == a.CMND select a).SingleOrDefault();
                        NG.DIACHI = NGDiaChi.Text;
                        NG.HOTEN  = NGTen.Text;
                        NG.SDT    = NGSDT.Text;
                        db.SubmitChanges();
                    }



                    //CẬP NHẬT NGƯỜI NHẬN
                    NGUOINHAN checkNN = (from a in db.NGUOINHANs where NNCMT.Text == a.CMND select a).SingleOrDefault();
                    if (checkNN == null)
                    {
                        NGUOINHAN NN = new NGUOINHAN();
                        NN.CMND   = NNCMT.Text;
                        NN.DIACHI = NNDiaChi.Text;
                        NN.HOTEN  = NNTen.Text;
                        NN.SDT    = NNSDT.Text;

                        db.NGUOINHANs.InsertOnSubmit(NN);
                        db.SubmitChanges();
                    }
                    else
                    {
                        NGUOINHAN NN = (from a in db.NGUOINHANs where NNCMT.Text == a.CMND select a).SingleOrDefault();
                        NN.DIACHI = NNDiaChi.Text;
                        NN.HOTEN  = NNTen.Text;
                        NN.SDT    = NNSDT.Text;
                        db.SubmitChanges();
                    }



                    //THÊM MẶT HÀNG

                    HANG mathang = new HANG();
                    mathang.MAHANG     = T2MaDonHang.Text;
                    mathang.TRONGLUONG = Convert.ToDouble(T2TrongLuong.Text);
                    mathang.DAI        = Convert.ToDouble(T2Dai.Text);
                    mathang.RONG       = Convert.ToDouble(T2Rong.Text);
                    mathang.CAO        = Convert.ToDouble(T2Cao.Text);
                    mathang.NOIDUNG    = T2Noidung.Text;
                    mathang.GHICHU     = T2Ghichu.Text;

                    db.HANGs.InsertOnSubmit(mathang);
                    db.SubmitChanges();



                    //THÊM PHÍ ĐƠN HÀNG


                    PHIGH phi = new PHIGH();
                    phi.MAPHI = T2MaDonHang.Text;
                    phi.MAPT  = (from a in db.PHUONGTIENs where a.TENPT == T2CbLoaiHinhVanTai.Text select a.MAPT).Single();
                    if (T2PhuPhi.Text != "")
                    {
                        phi.PHUPHI = double.Parse(T2PhuPhi.Text);
                    }
                    else
                    {
                        phi.PHUPHI = 0;
                    }
                    phi.TONGPHI = TinhPhi();
                    if (T2raNG.Checked)
                    {
                        phi.TTPHI = "Đã thanh toán";
                    }
                    else
                    {
                        phi.TTPHI = "Chưa thanh toán";
                    }

                    db.PHIGHs.InsertOnSubmit(phi);
                    db.SubmitChanges();



                    //THÊM HÓA ĐƠN

                    DONHANG newDonHang = new DONHANG();
                    newDonHang.MADH    = T2MaDonHang.Text;
                    newDonHang.MANV    = nv.MANV;
                    newDonHang.CMNDNG  = NGCMT.Text;
                    newDonHang.CMNDNN  = NNCMT.Text;
                    newDonHang.NGAYGUI = DateTime.Today;
                    newDonHang.MAHANG  = T2MaDonHang.Text;
                    newDonHang.MAPHI   = T2MaDonHang.Text;
                    newDonHang.TTHD    = "Chờ vận chuyển";



                    db.DONHANGs.InsertOnSubmit(newDonHang);
                    db.SubmitChanges();


                    DEM dem = (from a in db.DEMs where a.ID == "DH" select a).Single();
                    dem.COUNT++;
                    db.SubmitChanges();

                    XtraMessageBox.Show("Đã thêm đơn hàng " + newDonHang.MADH + " !", "Thêm thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    XemDonHang(true);
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show("Có lỗi trong quá trình thực hiện!", "btLuuDonHang_Click", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    log.Error(ex);
                }
            }
        }
Esempio n. 22
0
        public void Command()
        {
            ExitCommand = new RelayCommand <object>((p) => true, (p) =>
            {
                (p as Window).Close();
            });
            AddCommand = new RelayCommand <Grid>((p) => true, (p) =>
            {
                try
                {
                    string mahang  = "";
                    string tenhang = "";
                    decimal dongia = 0;

                    foreach (var item in p.Children)
                    {
                        if (item is TextBox)
                        {
                            TextBox tb = item as TextBox;
                            if (!string.IsNullOrEmpty(tb.Text))
                            {
                                switch (tb.Name)
                                {
                                case "txbMaHang":
                                    {
                                        mahang = tb.Text;
                                    }
                                    break;

                                case "txbTenHang":
                                    {
                                        tenhang = tb.Text;
                                    }
                                    break;

                                case "txbDonGia":
                                    {
                                        dongia = decimal.Parse(tb.Text.ToString());
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    if (string.IsNullOrEmpty(mahang) || string.IsNullOrEmpty(dongia.ToString()) || string.IsNullOrEmpty(tenhang))
                    {
                        MessageBox.Show("Vui lòng nhập đầy đủ thông tin");
                        return;
                    }
                    if (ListHang.Where((a) => a.MAHANG == mahang).ToList().Count > 0)
                    {
                        MessageBox.Show("Sản phẩm đã tồn tại");
                        return;
                    }
                    if (dongia == 0)
                    {
                        {
                            MessageBox.Show("Đon giá phải lớn hơn 0");
                            return;
                        }
                    }
                    HANG hang = new HANG()
                    {
                        MAHANG     = mahang,
                        TENHANG    = tenhang,
                        DONGIA     = dongia,
                        SOLUONGTON = 0
                    };
                    ListHang.Add(hang);
                    Insert.Instance.ThemThongTinSanPham(hang);
                }
                catch (Exception e) { }
            });
            DeleteCommand = new RelayCommand <ListView>((p) => true, (p) =>
            {
                try
                {
                    int selectedindex = (p as ListView).SelectedIndex;
                    if (selectedindex >= 0)
                    {
                        Delete.Instance.XoaThongTinSanPham(ListHang[selectedindex]);
                        ListHang.RemoveAt(selectedindex);
                    }
                    else
                    {
                        MessageBox.Show("vui lòng chọn sản phẩm cần xóa");
                    }
                }
                catch (Exception e) { }
            });
            UpdateCommand = new RelayCommand <Grid>((p) => true, (p) =>
            {
                try
                {
                    string mahang  = "";
                    string tenhang = "";
                    decimal dongia = 0;
                    foreach (var item in p.Children)
                    {
                        if (item is TextBox)
                        {
                            TextBox tb = item as TextBox;
                            if (!string.IsNullOrEmpty(tb.Text))
                            {
                                switch (tb.Name)
                                {
                                case "txbMaHang":
                                    {
                                        mahang = tb.Text;
                                    }
                                    break;

                                case "txbTenHang":
                                    {
                                        tenhang = tb.Text;
                                    }
                                    break;

                                case "txbDonGia":
                                    {
                                        dongia = decimal.Parse(tb.Text.ToString());
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    if (string.IsNullOrEmpty(mahang) || string.IsNullOrEmpty(dongia.ToString()) || string.IsNullOrEmpty(tenhang))
                    {
                        MessageBox.Show("Vui lòng nhập đầy đủ thông tin");
                        return;
                    }

                    if (DataProvider.Instance.DB.HANGs.Where(h => h.MAHANG == mahang).ToList().Count == 0)
                    {
                        return;
                    }
                    if (dongia == 0)
                    {
                        {
                            MessageBox.Show("Đon giá phải lớn hơn 0");
                            return;
                        }
                    }
                    var update     = ListHang.FirstOrDefault(x => x.MAHANG == mahang);
                    update.TENHANG = tenhang;
                    update.DONGIA  = dongia;

                    ListHang.Remove(ListHang.Where(a => a.MAHANG == update.MAHANG).Single());
                    ListHang.Add(update);
                    Update.Instance.Update_ThongTinSanPham(update);
                }
                catch (Exception e) { }
            });
        }
Esempio n. 23
0
        public ActionResult xoahang(int id)
        {
            HANG loai = db.HANGs.SingleOrDefault(n => n.MaH == id);

            return(View(loai));
        }
Esempio n. 24
0
 public ActionResult ThemmoiHang(HANG sp)
 {
     db.HANGs.InsertOnSubmit(sp);
     db.SubmitChanges();
     return(RedirectToAction("Hang"));
 }