Ejemplo n.º 1
0
 public JsonResult ChangePassword(int EmployeeId, string ePassword, string oldpass)
 {//要用到其他地方
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
     {
         tEmployee         emp       = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
         MotaiDataEntities dbContext = new MotaiDataEntities();
         tEmployee         changeemp = new tEmployee();
         changeemp            = emp;
         changeemp.EmployeeId = EmployeeId;
         dbContext.tEmployees.Add(changeemp);
         dbContext.SaveChanges();
         if (emp.ePassword == oldpass)
         {
             emp.ePassword = ePassword;
             Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] = emp;
             tEmployee changePwd = dbContext.tEmployees.Where(e => e.EmployeeId.Equals(emp.EmployeeId)).FirstOrDefault();
             changePwd.ePassword = ePassword;
             dbContext.SaveChanges();
             return(Json(new { result = true, msg = "更新成功" }));
         }
         else
         {
             return(Json(new { result = false, msg = "舊密碼錯誤" }));
         }
     }
     else
     {
         return(Json(new { result = false, msg = "請先登入" }));
     }
 }
Ejemplo n.º 2
0
        public ActionResult 人員檢視()
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();

            if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] == null)
            {
                return(RedirectToAction("員工登入", "Employee"));
            }
            tEmployee empse   = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
            var       empall  = dbContext.tEmployees.OrderBy(c => c.eBranch).ToList();
            var       empall2 = empall.OrderBy(c => c.ePosition).ToList();
            var       empall3 = empall2.OrderBy(c => c.eBranch).ToList();
            List <EmployeeViewModels> employees = new List <EmployeeViewModels>();

            foreach (var item in empall3)
            {
                EmployeeViewModels employeeModel = new EmployeeViewModels();
                employeeModel.EmployeeId = item.EmployeeId;
                employeeModel.eAccount   = item.eAccount;
                employeeModel.eName      = item.eName;
                employeeModel.sPosition  = item.tPosition.pPosition;
                employeeModel.sBranch    = item.tBranch.bBranch;
                employees.Add(employeeModel);
            }
            return(View(employees));
        }
Ejemplo n.º 3
0
        public ActionResult 店鋪報表()
        {
            if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] == null)
            {
                return(RedirectToAction("員工登入", "Employee"));
            }
            MotaiDataEntities dbContext = new MotaiDataEntities();

            List <tOrderDetail> tOrderDetails = dbContext.tOrderDetails.ToList();
            wareData            ware          = new wareData();

            ware.waretem = new Dictionary <int, Dictionary <int, int> >();
            List <int> load = new List <int>();

            foreach (tOrderDetail item in tOrderDetails)
            {
                int wNAME = item.tOrder.tWarehouseName.WarehouseNameId;
                if (!load.Contains(wNAME))//抓店
                {
                    load.Add(wNAME);
                    Dictionary <int, int> temD = new Dictionary <int, int>();
                    for (int i = 1; i < 13; i++)
                    {//抓月份
                        var q = from search in tOrderDetails
                                where search.tOrder.oDate.Month == i && search.tOrder.tWarehouseName.WarehouseNameId == wNAME && search.tOrder.oCheck == "checked" && search.tOrder.oDate.Year == DateTime.Now.Year
                                select(search.oProductQty) * ((int)search.tProduct.pPrice);

                        int V = q.Sum();//合併月份內營收
                        temD.Add(i, V);
                    }
                    ware.waretem.Add(wNAME, temD);
                }
            }
            return(View(ware));
        }
Ejemplo n.º 4
0
        public JsonResult 收藏排名()
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            List <tFavorite>  favordb   = dbContext.tFavorites.ToList();

            string func(int i)
            {
                tProduct      p      = new tProduct();
                List <string> pimage = new List <string>();

                p.ProductId = i;
                pimage      = productRespotiory.GetProductShowImages(p);
                if (pimage.Count > 0)
                {
                    return(Url.Content(pimage[0]));
                }
                else
                {
                    return("");
                }
            }

            var favorOrderby = (from i in favordb
                                group i by i.fProductId into j
                                select new
            {
                Pid = j.Key,
                Pimage = func(j.Key),
                Pcount = j.Count(),
            }).OrderByDescending(j => j.Pcount).Take(10).ToArray();

            return(Json(new { favorOrderby }));
        }
Ejemplo n.º 5
0
        public JsonResult 購買排名()
        {
            MotaiDataEntities   dbContext = new MotaiDataEntities();
            List <tOrderDetail> orderdb   = dbContext.tOrderDetails.ToList();

            //這樣才能在linq內使用函式
            string func(int i)
            {
                tProduct      p      = new tProduct();
                List <string> pimage = new List <string>();

                p.ProductId = i;
                pimage      = productRespotiory.GetProductShowImages(p);
                if (pimage.Count > 0)
                {
                    return(Url.Content(pimage[0]));
                }
                else
                {
                    return("");
                }
            }

            var buyOrderby = (from i in orderdb
                              group i by i.oProductId into j
                              select new
            {
                Pid = j.Key,
                Pimage = func(j.Key),
                Pcount = j.Sum(p => p.oProductQty),
            }).OrderByDescending(j => j.Pcount).Take(10).ToArray();

            return(Json(new { buyOrderby }));
        }
Ejemplo n.º 6
0
        public ActionResult 購物車清單()
        {
            if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
            {
                MotaiDataEntities dbContext = new MotaiDataEntities();
                tCustomer         cust      = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
                int count = dbContext.tStatus.Where(c => c.sCustomerId == cust.CustomerId).ToList().Count;
                ViewBag.Count = count + "項";

                List <tStatu> StateList             = dbContext.tStatus.Where(c => c.sCustomerId == cust.CustomerId).ToList();
                List <StatusCartViewModel> cartList = new List <StatusCartViewModel>();
                StatusCartGoToPayViewModel Cart     = new StatusCartGoToPayViewModel();
                foreach (var items in StateList)
                {
                    tProduct            cartProd = dbContext.tProducts.Where(p => p.ProductId == items.sProductId).FirstOrDefault();
                    StatusCartViewModel cartC    = new StatusCartViewModel();
                    cartC.StatusId    = items.StatusId;
                    cartC.ProductId   = items.sProductId;
                    cartC.pName       = cartProd.pName;
                    cartC.pPrice      = cartProd.pPrice;
                    cartC.sProductQty = items.sProductQty;
                    cartList.Add(cartC);
                }
                Cart.Carts = cartList;
                var warehouseNames = commodityRespoitory.GetWarehouseAll();
                List <SelectListItem> warehouselist = commodityRespoitory.GetSelectList(warehouseNames);
                Cart.warehouses = warehouselist;
                return(View(Cart));
            }
            else
            {
                return(RedirectToAction("首頁"));
            }
        }
Ejemplo n.º 7
0
 public JsonResult 修改會員資料(MemberViewModel oldMember)
 {
     if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
     {
         tCustomer         customer  = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
         MotaiDataEntities dbContext = new MotaiDataEntities();
         tCustomer         cust      = dbContext.tCustomers.Find(customer.CustomerId);
         List <tCustomer>  custList  = dbContext.tCustomers.ToList();
         foreach (var item in custList)
         {
             if (item.cCellPhone == oldMember.cCellPhone)
             {
                 if (cust.cCellPhone != oldMember.cCellPhone)
                 {
                     return(Json(new { result = false, msg = "此手機號碼已被註冊" }));
                 }
             }
             else if (item.cEmail == oldMember.cEmail)
             {
                 if (cust.cEmail != oldMember.cEmail)
                 {
                     return(Json(new { result = false, msg = "此信箱已被註冊" }));
                 }
             }
         }
         cust.cName      = oldMember.cName;
         cust.cTelePhone = oldMember.cTelePhone;
         cust.cGUI       = oldMember.cGUI;
         cust.cEmail     = oldMember.cEmail;
         cust.cAddress   = oldMember.cAddress;
         dbContext.SaveChanges();
         return(Json(new { result = true, msg = "修改成功", url = Url.Action("會員中心", "Customer") }));
     }
     return(Json(new { result = true, msg = "請先登入", url = Url.Action("首頁", "Customer") }));
 }
Ejemplo n.º 8
0
        public ActionResult 修改會員資料(int CustomerId)
        {
            MotaiDataEntities db   = new MotaiDataEntities();
            tCustomer         cust = db.tCustomers.FirstOrDefault(c => c.CustomerId == CustomerId);

            if (cust == null)
            {
                return(RedirectToAction("會員中心"));
            }
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tCustomer         custer    = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
            int count = dbContext.tStatus.Where(c => c.sCustomerId == custer.CustomerId).ToList().Count;

            ViewBag.Count = count;
            MemberViewModel customer = new MemberViewModel();

            customer.cAccount   = cust.cAccount;
            customer.cPassword  = cust.cPassword;
            customer.cName      = cust.cName;
            customer.cTelePhone = cust.cTelePhone;
            customer.cCellPhone = cust.cCellPhone;
            customer.cAddress   = cust.cAddress;
            customer.cGUI       = cust.cGUI;
            customer.cEmail     = cust.cEmail;
            return(View(customer));
        }
Ejemplo n.º 9
0
        public JsonResult 員工登入(EmployeeLoginViewModel e登入資料)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tEmployee         d資料確認     = dbContext.tEmployees.Where(e => e.eAccount == e登入資料.eAccount && e.ePassword.Equals(e登入資料.ePassword)).FirstOrDefault();

            if (d資料確認 != null)
            {
                Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] = d資料確認;
                switch (d資料確認.eBranch)
                {
                case 1:
                    return(Json(new { result = true, msg = "登入成功", url = Url.Action("Boss首頁", "Boss") }));

                case 2:
                    return(Json(new { result = true, msg = "登入成功", url = Url.Action("Business首頁", "Business") }));

                case 3:
                    return(Json(new { result = true, msg = "登入成功", url = Url.Action("Accountant首頁", "Accountant") }));

                case 4:
                    return(Json(new { result = true, msg = "登入成功", url = Url.Action("People首頁", "People") }));

                case 5:
                    return(Json(new { result = true, msg = "登入成功", url = Url.Action("Commodity首頁", "Commodity") }));

                default:
                    return(Json(new { result = true, msg = "帳號或密碼有誤", url = Url.Action("員工首頁", "Employee") }));
                }
            }
            else
            {
                return(Json(new { result = false, msg = "帳號或密碼有誤" }));
            }
        }
Ejemplo n.º 10
0
 //客戶訂單
 public ActionResult 客戶看訂單()
 {
     if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
     {
         tCustomer                     cust      = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
         MotaiDataEntities             db        = new MotaiDataEntities();
         List <tOrder>                 orders    = db.tOrders.Where(o => o.oCustomerId.Equals(cust.CustomerId)).ToList();
         List <CustomerOrderViewModel> OrderList = new List <CustomerOrderViewModel>();
         foreach (var items in orders)
         {
             CustomerOrderViewModel order = new CustomerOrderViewModel();
             order.oDate         = items.oDate;
             order.WarehouseName = db.tWarehouseNames.Where(w => w.WarehouseNameId.Equals(items.oWarehouseName)).FirstOrDefault().WarehouseName;
             order.EmployeeName  = db.tEmployees.Where(e => e.EmployeeId.Equals(items.oEmployeeId)).FirstOrDefault().eName;
             order.cNote         = items.cNote;
             List <tOrderDetail> orderdetails = db.tOrderDetails.Where(od => od.oOrderId.Equals(items.OrderId)).ToList();
             List <CustomerOrderDetailViewModel> OrderDetailList = new List <CustomerOrderDetailViewModel>();
             foreach (var itemDetail in orderdetails)
             {
                 CustomerOrderDetailViewModel orderdetail = new CustomerOrderDetailViewModel();
                 orderdetail.ProductNum  = db.tProducts.Where(p => p.ProductId.Equals(itemDetail.oProductId)).FirstOrDefault().pNumber;
                 orderdetail.ProductName = db.tProducts.Where(p => p.ProductId.Equals(itemDetail.oProductId)).FirstOrDefault().pName;
                 orderdetail.oProductQty = itemDetail.oProductQty;
                 orderdetail.oNote       = itemDetail.oNote;
                 OrderDetailList.Add(orderdetail);
             }
             order.CustomerOrderDetails = OrderDetailList;
             OrderList.Add(order);
         }
         return(View(OrderList));
     }
     return(RedirectToAction("首頁"));
 }
Ejemplo n.º 11
0
 public ActionResult 工作日誌()
 {
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
     {
         MotaiDataEntities dbContext = new MotaiDataEntities();
         tEmployee         emp       = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
         var dlist    = dbContext.tDiaries.Where(c => c.dEmployeeId == emp.EmployeeId).ToList();
         var dlistnew = dlist.OrderByDescending(c => c.dDate).ToList();
         List <DiaryViewModel> DSaw = new List <DiaryViewModel>();
         foreach (var item in dlistnew)
         {
             DiaryViewModel show = new DiaryViewModel();
             show.eName            = item.tEmployee.eName;
             show.dDate            = item.dDate;
             show.dWeather         = item.dWeather;
             show.dDiaryNote       = item.dDiaryNote;
             show.DiaryId          = item.DiaryId;
             show.dWarehouseNameId = item.dWarehouseNameId;
             show.dWarehouseName   = dbContext.tWarehouseNames.Where(w => w.WarehouseNameId == item.dWarehouseNameId).FirstOrDefault().WarehouseName;
             DSaw.Add(show);
         }
         return(View(DSaw));
     }
     return(RedirectToAction("員工登入", "Employee"));
 }
Ejemplo n.º 12
0
        public JsonResult OrderPay(int payType, int OrderId, int payMoney)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tOrderPay         pay       = dbContext.tOrderPays.OrderByDescending(op => op.oOrderInstallment).Where(op => op.oOrderId.Equals(OrderId)).FirstOrDefault();

            if (pay == null)
            {
                tOrderPay orderPay = new tOrderPay();
                orderPay.oOrderId          = OrderId;
                orderPay.oOrderInstallment = 1;
                orderPay.oPayType          = payType;
                orderPay.oPayment          = payMoney;
                orderPay.oPayDate          = DateTime.Now;
                dbContext.tOrderPays.Add(orderPay);
                dbContext.SaveChanges();
            }
            else
            {
                tOrderPay orderPay = new tOrderPay();
                orderPay.oOrderId          = OrderId;
                orderPay.oOrderInstallment = pay.oOrderInstallment++;
                orderPay.oPayType          = payType;
                orderPay.oPayment          = payMoney;
                orderPay.oPayDate          = DateTime.Now;
                dbContext.tOrderPays.Add(orderPay);
                dbContext.SaveChanges();
            }
            return(Json(new { msg = "結帳完成", url = Url.Action("實體店新增訂單", "Order") }));
        }
Ejemplo n.º 13
0
        public ActionResult 會員中心()
        {
            if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
            {
                tCustomer         cust   = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
                MotaiDataEntities db     = new MotaiDataEntities();
                tCustomer         custor = db.tCustomers.Find(cust.CustomerId);
                MemberViewModel   member = new MemberViewModel();


                MotaiDataEntities dbContext = new MotaiDataEntities();
                int count = dbContext.tStatus.Where(c => c.sCustomerId == cust.CustomerId).ToList().Count;
                ViewBag.Count = count + "項";


                member.cName      = custor.cName;
                member.cTelePhone = custor.cTelePhone;
                member.cCellPhone = custor.cCellPhone;
                member.cAddress   = custor.cAddress;
                member.cGUI       = custor.cGUI;
                member.cEmail     = custor.cEmail;
                member.cAccount   = custor.cAccount;
                member.cPassword  = custor.cPassword;

                return(View(member));
            }
            return(RedirectToAction("首頁"));
        }
Ejemplo n.º 14
0
        //搜尋客戶訂單
        public JsonResult SearchCustomerOrder(string CustomerCell)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tCustomer         cust      = dbContext.tCustomers.Where(c => c.cCellPhone.Equals(CustomerCell)).FirstOrDefault();

            if (cust == null)
            {
                return(Json(new { result = false, msg = "查無此人" }));
            }
            else
            {
                int           custId    = cust.CustomerId;
                List <tOrder> orderlist = dbContext.tOrders.Where(o => o.oCustomerId == custId && o.oCheck == null).ToList();
                List <SearchCustomerOrderModel> searchlist = new List <SearchCustomerOrderModel>();
                foreach (var item in orderlist)
                {
                    SearchCustomerOrderModel search = new SearchCustomerOrderModel();
                    search.orderId       = item.OrderId;
                    search.purchaseDate  = item.oDate.ToString("yyyy/MM/dd");
                    search.WarehouseName = dbContext.tWarehouseNames.Where(wn => wn.WarehouseNameId == item.oWarehouseName).FirstOrDefault().WarehouseName;
                    OrderPayStatus payStatus = orderRespoitory.GetPayStatus(item.OrderId);
                    search.TotalAmount = payStatus.TotalAmount;
                    search.AlreadyPay  = payStatus.AlreadyPay;
                    search.Unpaid      = payStatus.Unpaid;
                    searchlist.Add(search);
                }
                return(Json(new { result = true, list = searchlist }));
            }
        }
Ejemplo n.º 15
0
        public JsonResult chooseShipWare(int OrderId)
        {
            MotaiDataEntities              dbContext          = new MotaiDataEntities();
            List <tOrderDetail>            orderDetailSearchs = dbContext.tOrderDetails.Where(od => od.oOrderId.Equals(OrderId)).ToList();
            List <WareShipChooseViewModel> ChooseList         = new List <WareShipChooseViewModel>();

            foreach (var item in orderDetailSearchs)
            {
                List <tWarehouse> wareList = dbContext.tWarehouses.Where(w => w.wProductId.Equals(item.oProductId)).ToList();
                foreach (var itemware in wareList)
                {
                    tProduct product = dbContext.tProducts.Where(p => p.ProductId.Equals(item.oProductId)).FirstOrDefault();
                    WareShipChooseViewModel wareChoose = new WareShipChooseViewModel();
                    wareChoose.WareHouseName = dbContext.tWarehouseNames.Where(wn => wn.WarehouseNameId.Equals(itemware.WarehouseNameId)).FirstOrDefault().WarehouseName;
                    wareChoose.WareHouseId   = itemware.WarehouseNameId;
                    wareChoose.OrderDetailId = item.oOrderDetailId;
                    wareChoose.ProductId     = product.ProductId;
                    wareChoose.ProductNum    = product.pNumber;
                    wareChoose.ProductName   = product.pName;
                    wareChoose.ProductQty    = itemware.wPQty;
                    ChooseList.Add(wareChoose);
                }
            }
            return(Json(ChooseList));
        }
Ejemplo n.º 16
0
        public ActionResult 修改產品(int id)
        {
            MotaiDataEntities db      = new MotaiDataEntities();
            tProduct          product = db.tProducts.FirstOrDefault(p => p.ProductId == id);

            if (product == null)
            {
                return(RedirectToAction("員工看產品頁面"));
            }
            EmpProductViewModel Prod = new EmpProductViewModel();

            Prod.ProductId     = id;
            Prod.pNumber       = product.pNumber;
            Prod.pName         = product.pName;
            Prod.psCategory    = product.tProductCategory.Category;
            Prod.psMaterial    = product.tProductMaterial.Material;
            Prod.psSize        = product.tProductSize.Size;
            Prod.pLxWxH        = product.pLxWxH;
            Prod.pWeight       = product.pWeight;
            Prod.pIntroduction = product.pIntroduction;
            Prod.pPrice        = product.pPrice;
            var categories = new ProductRespoitory().GetCategoryAll();
            List <SelectListItem> Cateitems = new ProductRespoitory().GetSelectList(categories);

            Prod.Categories = Cateitems;
            var materials = new ProductRespoitory().GetMaterialAll();
            List <SelectListItem> Mateitems = new ProductRespoitory().GetSelectList(materials);

            Prod.Materials = Mateitems;
            var sizes = new ProductRespoitory().GetSizeAll();
            List <SelectListItem> Sizeitems = new ProductRespoitory().GetSelectList(sizes);

            Prod.Sizes = Sizeitems;
            return(View(Prod));
        }
Ejemplo n.º 17
0
        public ActionResult 修改消息(int id)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tPromotion        promotion = dbContext.tPromotions.FirstOrDefault(p => p.PromotionId == id);

            if (promotion == null)
            {
                return(RedirectToAction("員工看產品頁面"));
            }
            DetailPromotionViewModel Promo = new DetailPromotionViewModel();

            Promo.pADimage             = promotion.pADimage;
            Promo.pCondition           = promotion.pCondition;
            Promo.pDiscount            = promotion.pDiscount;
            Promo.pPromotionDeadline   = promotion.pPromotionDeadline;
            Promo.pPromotionPostDate   = promotion.pPromotionPostDate;
            Promo.pPromotionStartDate  = promotion.pPromotionStartDate;
            Promo.pPromotionWeb        = promotion.pPromotionWeb;
            Promo.PromotionDescription = promotion.PromotionDescription;
            Promo.sPromotinoCategory   = promotion.tPromotionCategory.PromtionCategory;
            Promo.PromotionName        = promotion.PromotionName;
            Promo.pDiscountCode        = promotion.pDiscountCode;
            Promo.PromotionId          = promotion.PromotionId;


            Promo.sPromotinoCategory = promotion.tPromotionCategory.PromtionCategory;
            Promo.pCategory          = promotion.PromotinoCategory;
            var categories = new PromotionRespoitory().GetPromoCategoryAll();
            List <SelectListItem> Cateitems = commodityRespoitory.GetSelectList(categories);//???? 黑人問號

            Promo.Categories = Cateitems;
            return(View(Promo));
        }
Ejemplo n.º 18
0
        public ActionResult 修改消息(DetailPromotionViewModel promotion)
        {
            if (CSession關鍵字.SK_LOGINED_EMPLOYEE == null)
            {
                return(RedirectToAction("員工登入"));
            }
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tPromotion        Promo     = dbContext.tPromotions.FirstOrDefault(p => p.PromotionId == promotion.PromotionId);

            if (Promo != null)
            {
                Promo.pCondition           = promotion.pCondition;
                Promo.pDiscount            = promotion.pDiscount;
                Promo.pPromotionDeadline   = promotion.pPromotionDeadline;
                Promo.pPromotionPostDate   = promotion.pPromotionPostDate;
                Promo.pPromotionStartDate  = promotion.pPromotionStartDate;
                Promo.pPromotionWeb        = promotion.pPromotionWeb;
                Promo.PromotionDescription = promotion.PromotionDescription;
                Promo.PromotinoCategory    = promotion.pCategory;
                Promo.PromotionName        = promotion.PromotionName;
                Promo.pDiscountCode        = promotion.pDiscountCode;
                Promo.PromotionId          = promotion.PromotionId;
                Promo.pPromotionPostDate   = DateTime.Now;
                var uploagFile = promotion.upLoadimage;
                if (uploagFile != null)
                {
                    FileInfo file      = new FileInfo(uploagFile.FileName);
                    string   photoName = Guid.NewGuid().ToString() + file.Extension;
                    uploagFile.SaveAs(Server.MapPath("~/images/" + photoName));
                    Promo.pADimage = "../../images/" + Url.Content(photoName);
                }
                dbContext.SaveChanges();
            }
            return(RedirectToAction("員工看消息"));
        }
Ejemplo n.º 19
0
 //加入購物車
 public JsonResult AddToCart(int ProductId, int buyQty)
 {
     if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
     {
         tCustomer         cust = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
         MotaiDataEntities db   = new MotaiDataEntities();
         var product            = (new MotaiDataEntities()).tProducts.FirstOrDefault(p => p.ProductId == ProductId);
         if (product != null && product.pQty > buyQty)
         {
             tStatu cart = new tStatu();
             cart.sCustomerId = cust.CustomerId;
             cart.sProductId  = ProductId;
             cart.sProductQty = buyQty;
             db.tStatus.Add(cart);
             db.SaveChanges();
             return(Json(new { result = true, msg = "加入成功" }));
         }
         else
         {
             return(Json(new { result = false, msg = "庫存不足" }));
         }
     }
     else
     {
         return(Json(new { result = false, msg = "請先登入" }));
     }
 }
Ejemplo n.º 20
0
        public ActionResult 消息(int page = 1)
        {
            MotaiDataEntities db = new MotaiDataEntities();

            int cpage = page < 1 ? 1 : page;
            //資料庫讀取 tPromotions 為資料庫名稱
            var promotion = db.tPromotions.OrderByDescending(c => c.PromotionId).ToList();
            //開新List 取值
            List <news> reslsit = new List <news>();

            foreach (var items in promotion)
            {
                //實體化 class
                news res = new news();
                NewPromotionViewModel npv = new NewPromotionViewModel();
                //Prom 讀取入get set
                npv.sPromotinoCategory   = items.tPromotionCategory.PromtionCategory;
                npv.PromotionDescription = items.PromotionDescription;
                npv.pADimage             = items.pADimage;
                npv.pPromotionWeb        = items.pPromotionWeb;
                npv.pPromotionPostDate   = items.pPromotionPostDate;
                res.newPrmotion          = npv;
                reslsit.Add(res);
            }
            var result = reslsit.ToPagedList(cpage, pageSize);

            return(View(result));
        }
Ejemplo n.º 21
0
        public JsonResult 會員註冊(RegisterViewModel newMember)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            List <tCustomer>  custo     = dbContext.tCustomers.ToList();

            foreach (var item in custo)
            {
                if (item.cAccount == newMember.cAccount)
                {
                    return(Json(new { msg = "帳號已被註冊" }));
                }
                else if (item.cEmail == newMember.cEmail)
                {
                    return(Json(new { msg = "信箱已被使用" }));
                }
            }
            if (newMember.cPassword == newMember.cConfirmPassword)
            {
                tCustomer newmember = new tCustomer();
                newmember.cAccount   = newMember.cAccount;
                newmember.cPassword  = newMember.cPassword;
                newmember.cName      = newMember.cName;
                newmember.cTelePhone = newMember.cTelePhone;
                newmember.cCellPhone = newMember.cCellPhone;
                newmember.cAddress   = newMember.cAddress;
                newmember.cGUI       = newMember.cGUI;
                newmember.cEmail     = newMember.cEmail;
                dbContext.tCustomers.Add(newmember);
                dbContext.SaveChanges();
                return(Json(new { msg = "註冊成功" }));
            }
            return(Json(new { msg = "註冊失敗" }));
        }
Ejemplo n.º 22
0
        public ActionResult 購物車清單()
        {
            if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
            {
                MotaiDataEntities          dbContext = new MotaiDataEntities();
                tCustomer                  cust      = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
                List <tStatu>              StateList = dbContext.tStatus.Where(c => c.sCustomerId == cust.CustomerId).ToList();
                List <StatusCartViewModel> cartList  = new List <StatusCartViewModel>();

                foreach (var items in StateList)
                {
                    tPromotion          discount = dbContext.tPromotions.Where(p => p.PromotionId == items.sProductId).FirstOrDefault();
                    tProduct            cartProd = dbContext.tProducts.Where(p => p.ProductId == items.sProductId).FirstOrDefault();
                    StatusCartViewModel cartC    = new StatusCartViewModel();
                    cartC.StatusId      = items.StatusId;
                    cartC.pName         = cartProd.pName;
                    cartC.pPrice        = cartProd.pPrice;
                    cartC.sProductQty   = items.sProductQty;
                    cartC.pDiscountCode = discount.pDiscountCode;
                    cartList.Add(cartC);
                }
                return(View(cartList));
            }
            else
            {
                return(RedirectToAction("首頁"));
            }
        }
Ejemplo n.º 23
0
        public ActionResult 修改消息(DetailPromotionViewModel promotion)
        {
            if (CSession關鍵字.SK_LOGINED_EMPLOYEE == null)
            {
                return(RedirectToAction("員工登入"));
            }
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tPromotion        Promo     = dbContext.tPromotions.FirstOrDefault(p => p.PromotionId == promotion.PromotionId);

            if (Promo != null)
            {
                Promo.pADimage             = promotion.pADimage;
                Promo.pCondition           = promotion.pCondition;
                Promo.pDiscount            = promotion.pDiscount;
                Promo.pPromotionDeadline   = promotion.pPromotionDeadline;
                Promo.pPromotionPostDate   = promotion.pPromotionPostDate;
                Promo.pPromotionStartDate  = promotion.pPromotionStartDate;
                Promo.pPromotionWeb        = promotion.pPromotionWeb;
                Promo.PromotionDescription = promotion.PromotionDescription;
                Promo.PromotinoCategory    = promotion.pCategory;
                Promo.PromotionName        = promotion.PromotionName;
                Promo.pDiscountCode        = promotion.pDiscountCode;
                Promo.PromotionId          = promotion.PromotionId;
                dbContext.SaveChanges();
            }
            return(RedirectToAction("員工看消息"));
        }
Ejemplo n.º 24
0
        public JsonResult CustomerChangePassword(int CustomerId, string cPassword, string oldpass)
        {
            if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
            {
                tCustomer         customer  = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
                MotaiDataEntities dbContext = new MotaiDataEntities();

                if (customer.cPassword == oldpass)
                {
                    customer.cPassword = cPassword;
                    Session[CSession關鍵字.SK_LOGINED_CUSTOMER] = customer;
                    tCustomer changePwd = dbContext.tCustomers.Where(c => c.CustomerId.Equals(customer.CustomerId)).FirstOrDefault();
                    changePwd.cPassword = cPassword;
                    dbContext.SaveChanges();
                    return(Json(new { result = true, msg = "更新成功" }));
                }
                else
                {
                    return(Json(new { result = false, msg = "舊密碼錯誤" }));
                }
            }
            else
            {
                return(Json(new { result = false, msg = "請先登入" }));
            }
        }
Ejemplo n.º 25
0
 //出貨單
 public ActionResult 出貨單建立()
 {
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
     {
         MotaiDataEntities       dbContext = new MotaiDataEntities();
         ShipCreateShowViewModel model     = new ShipCreateShowViewModel();
         DateTime today = DateTime.Now.Date;
         var      count = dbContext.tShipLists.Where(s => s.sShipDate == today).ToList().Count;
         count++;
         model.sShipSerialValue = Convert.ToInt32(DateTime.Now.ToString("yyMMdd") + count.ToString("0000"));
         model.sShipDate        = DateTime.Now;
         List <tOrder> orderSearch = dbContext.tOrders.Where(o => o.oCheck != null && o.oDeliverDate == null).ToList();
         List <OrderShipShowViewModel> orderShips = new List <OrderShipShowViewModel>();
         foreach (var item in orderSearch)
         {
             OrderShipShowViewModel orderShip = new OrderShipShowViewModel();
             orderShip.OrderId    = item.OrderId;
             orderShip.oAddress   = item.oAddress;
             orderShip.oCheck     = item.oCheck;
             orderShip.oCheckDate = item.oCheckDate;
             orderShip.cNote      = item.cNote;
             orderShip.oDate      = item.oDate;
             orderShips.Add(orderShip);
         }
         model.ShipShows = orderShips;
         return(View(model));
     }
     return(RedirectToAction("員工登入", "Employee"));
 }
Ejemplo n.º 26
0
        //進貨單
        public ActionResult 進貨單建立()
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();

            if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
            {
                StockCreateViewModel model  = new StockCreateViewModel();
                StockDetailViewModel detail = new StockDetailViewModel();
                tEmployee            emp    = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
                model.sEmployeeId = emp.EmployeeId;
                var productNames = productRespoitory.GetNameAll();
                List <SelectListItem> productlist = productRespoitory.GetPositionName(productNames);
                var warehouseNames = commodityRespoitory.GetWarehouseAll();
                List <SelectListItem> warehouselist = commodityRespoitory.GetSelectList(warehouseNames);
                detail.WareHouseNames = warehouselist;
                detail.ProductNames   = productlist;
                DateTime today = DateTime.Now.Date;
                var      count = dbContext.tStockLists.Where(s => s.sStockDate == today).ToList().Count;
                count++;
                model.sStockSerialValue = Convert.ToInt32(DateTime.Now.ToString("yyMMdd") + count.ToString("0000"));
                model.StockDetail       = detail;
                model.sStockDate        = DateTime.Now;
                return(View(model));
            }
            else
            {
                return(RedirectToAction("員工登入", "Employee"));
            }
        }
Ejemplo n.º 27
0
 public JsonResult 實體店新增訂單(EmployeeOrderViewModel empOrder)
 {
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
     {
         tEmployee emp = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
         if (Session[CSession關鍵字.SK_ORDERDETAIL] == null)
         {
             return(Json(new { result = false, msg = "訂單尚未完成!", url = Url.Action("實體店新增訂單", "Order") }));
         }
         else
         {
             List <EmployeeOrderDetailViewModel> orders = Session[CSession關鍵字.SK_ORDERDETAIL] as List <EmployeeOrderDetailViewModel>;
             MotaiDataEntities dbContext = new MotaiDataEntities();
             tCustomer         customer  = dbContext.tCustomers.Where(c => c.cCellPhone == empOrder.cCellphone).FirstOrDefault();
             tOrder            list      = new tOrder();
             list.oEmployeeId = emp.EmployeeId;
             list.oCustomerId = customer.CustomerId;
             if (empOrder.oAddress == null)
             {
                 list.oAddress = customer.cAddress;
             }
             else
             {
                 list.oAddress = empOrder.oAddress;
             }
             list.oDate          = empOrder.oDate;
             list.cNote          = empOrder.cNote;
             list.oWarehouseName = empOrder.oWarehouseName;
             dbContext.tOrders.Add(list);
             dbContext.SaveChanges();
             int orderId       = dbContext.tOrders.OrderByDescending(i => i.OrderId).First().OrderId;
             int originalPrice = 0;
             foreach (var items in orders)
             {
                 tOrderDetail detail = new tOrderDetail();
                 detail.oOrderId    = orderId;
                 detail.oProductId  = items.oProductId;
                 detail.oProductQty = items.oProductQty;
                 detail.oNote       = items.oNote;
                 dbContext.tOrderDetails.Add(detail);
                 tProduct product = dbContext.tProducts.Where(p => p.ProductId.Equals(items.oProductId)).FirstOrDefault();
                 originalPrice += items.oProductQty * Convert.ToInt32(product.pPrice);
             }
             tOrder order       = dbContext.tOrders.Where(o => o.OrderId == orderId).FirstOrDefault();
             int    promotionId = orderRespoitory.SelectPromotionId(originalPrice, empOrder.oDate);
             if (promotionId != 0)
             {
                 order.oPromotionId = promotionId;
             }
             dbContext.SaveChanges();
             Session[CSession關鍵字.SK_ORDERDETAIL] = null;
             return(Json(new { result = true, msg = "新增成功", url = Url.Action("realCheckView", "Order"), OrderId = orderId }));
         }
     }
     else
     {
         return(Json(new { result = false, msg = "尚未登入!", url = Url.Action("員工登入", "Employee") }));
     }
 }
Ejemplo n.º 28
0
        public JsonResult WareOutInventory(int WarehouseIdOut, int ProductId)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tWarehouse        warehouse = dbContext.tWarehouses.Where(w => w.wProductId.Equals(ProductId) && w.WarehouseNameId.Equals(WarehouseIdOut)).FirstOrDefault();
            int MaxQty = warehouse.wPQty;

            return(Json(MaxQty));
        }
Ejemplo n.º 29
0
        public ActionResult 新增消息(DetailPromotionViewModel create消息)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tPromotion        n消息       = new tPromotion();

            n消息.PromotionName        = create消息.PromotionName;
            n消息.PromotinoCategory    = create消息.pCategory;
            n消息.PromotionDescription = create消息.PromotionDescription;
            n消息.pPromotionStartDate  = create消息.pPromotionStartDate;
            n消息.pPromotionDeadline   = create消息.pPromotionDeadline;
            //n消息.pADimage = create消息.pADimage;
            n消息.pDiscountCode = create消息.pDiscountCode;
            n消息.pDiscount     = create消息.pDiscount;
            n消息.pCondition    = create消息.pCondition;
            var date = DateTime.Now;

            n消息.pPromotionPostDate = date;

            int PromotionId = dbContext.tPromotions.OrderByDescending(o => o.PromotionId).First().PromotionId;

            PromotionId = PromotionId + 1;

            //if (create消息.upLoadimage.Count() > 0)
            //{
            //    foreach (var uploagFile in create消息.upLoadimage)
            //    {
            //        if (uploagFile.ContentLength > 0)
            //        {
            //            FileInfo file = new FileInfo(uploagFile.FileName);
            //            string photoName = Guid.NewGuid().ToString() + file.Extension;
            //            uploagFile.SaveAs(Server.MapPath("~/images/" + photoName));
            //            n消息.pADimage = "~" + Url.Content("~/images/" + photoName);
            //            dbContext.tPromotions.Add(n消息);
            //            dbContext.SaveChanges();
            //        }
            //    }
            //}
            dbContext.SaveChanges();
            return(RedirectToAction("員工看消息"));


            //if (n新增產品.pImage.Count() > 0)
            //{
            //    foreach (var uploagFile in n新增產品.pImage)
            //    {
            //        if (uploagFile.ContentLength > 0)
            //        {
            //            tProductImage image = new tProductImage();
            //            FileInfo file = new FileInfo(uploagFile.FileName);
            //            string photoName = Guid.NewGuid().ToString() + file.Extension;
            //            uploagFile.SaveAs(Server.MapPath("~/images/" + photoName));
            //            image.ProductId = ProductId;
            //            image.pImage = "~" + Url.Content("~/images/" + photoName);
            //            db.tProductImages.Add(image);
            //        }
            //    }
            //}
        }
Ejemplo n.º 30
0
 public JsonResult 進貨單建立(StockCreateViewModel stockList)
 {
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
     {
         tEmployee emp = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
         if (Session[CSession關鍵字.SK_STOCKDETAIL] == null)
         {
             return(Json(new { result = false, msg = "進貨單尚未完成!", url = "" }));
         }
         else
         {
             List <StockDetailViewModel> stocks    = Session[CSession關鍵字.SK_STOCKDETAIL] as List <StockDetailViewModel>;
             MotaiDataEntities           dbContext = new MotaiDataEntities();
             tStockList list = new tStockList();
             list.sEmployeeId       = emp.EmployeeId;
             list.sStockSerialValue = stockList.sStockSerialValue;
             list.sVendor           = stockList.sVendor;
             list.sVendorTel        = stockList.sVendorTel;
             list.sStockDate        = stockList.sStockDate;
             list.sStockNote        = stockList.sStockNote;
             dbContext.tStockLists.Add(list);
             dbContext.SaveChanges();
             foreach (var items in stocks)
             {
                 tStockDetail detail = new tStockDetail();
                 detail.sStockId         = dbContext.tStockLists.OrderByDescending(i => i.StockId).First().StockId;
                 detail.sProductId       = items.sProductId;
                 detail.sCost            = items.sCost;
                 detail.sQuantity        = items.sQuantity;
                 detail.sWarehouseNameId = items.sWarehouseNameId;
                 detail.sNote            = items.sNote;
                 dbContext.tStockDetails.Add(detail);
                 //倉儲變動
                 tWarehouse Warehouse = dbContext.tWarehouses.Where(w => w.WarehouseNameId.Equals(items.sWarehouseNameId) && w.wProductId.Equals(items.sProductId)).FirstOrDefault();
                 if (Warehouse != null)
                 {
                     Warehouse.wPQty += items.sQuantity;
                 }
                 else
                 {
                     tWarehouse warehouse = new tWarehouse();
                     warehouse.WarehouseNameId = items.sWarehouseNameId;
                     warehouse.wProductId      = items.sProductId;
                     warehouse.wPQty           = items.sQuantity;
                     dbContext.tWarehouses.Add(warehouse);
                 }
             }
             dbContext.SaveChanges();
             Session[CSession關鍵字.SK_STOCKDETAIL] = null;
             return(Json(new { result = true, msg = "新增成功", url = Url.Action("進貨單建立", "Commodity") }));
         }
     }
     else
     {
         return(Json(new { result = false, msg = "尚未登入!", url = Url.Action("員工登入", "Employee") }));
     }
 }