Esempio n. 1
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") }));
        }
Esempio n. 2
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 = "請先登入" }));
     }
 }
Esempio n. 3
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") }));
     }
 }
 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") }));
     }
 }
Esempio n. 5
0
        //加入購物車
        public JsonResult AddToCart(int ProductId, int buyQty)
        {
            if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
            {
                MotaiDataEntities db = new MotaiDataEntities();

                tCustomer cust  = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
                int       count = db.tStatus.Where(c => c.sCustomerId == cust.CustomerId).ToList().Count;
                ViewBag.Count = count + "項";
                tStatu productStatus = db.tStatus.Where(s => s.sCustomerId == cust.CustomerId && s.sProductId == ProductId).FirstOrDefault();
                if (productStatus != null)
                {
                    int statusQty = 0;
                    statusQty = productStatus.sProductQty;
                    var product    = (new MotaiDataEntities()).tProducts.FirstOrDefault(p => p.ProductId == ProductId);
                    int productQty = productRespotiory.GetProductQtyById(ProductId);
                    if (product != null && productQty - statusQty >= buyQty)
                    {
                        productStatus.sProductQty += buyQty;
                        db.SaveChanges();
                        return(Json(new { result = true, msg = "加入成功" }));
                    }
                    else
                    {
                        return(Json(new { result = false, msg = "庫存不足" }));
                    }
                }
                else
                {
                    var product    = (new MotaiDataEntities()).tProducts.FirstOrDefault(p => p.ProductId == ProductId);
                    int productQty = productRespotiory.GetProductQtyById(ProductId);
                    if (product != null && productQty >= 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 = "請先登入" }));
            }
        }
Esempio n. 6
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") }));
 }
        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("員工看消息"));
        }
Esempio n. 8
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 = "註冊失敗" }));
        }
Esempio n. 9
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 = "請先登入" }));
            }
        }
Esempio n. 10
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 = "請先登入" }));
     }
 }
Esempio n. 11
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("員工看消息"));
        }
Esempio n. 12
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);
            //        }
            //    }
            //}
        }
Esempio n. 13
0
        public ActionResult 購物車內刪除(int fid)
        {
            MotaiDataEntities db    = new MotaiDataEntities();
            tStatu            statu = db.tStatus.Where(s => s.StatusId.Equals(fid)).FirstOrDefault();

            if (statu != null)
            {
                db.tStatus.Remove(statu);
                db.SaveChanges();
            }
            return(RedirectToAction("購物車清單"));
        }
Esempio n. 14
0
        public ActionResult 出貨單建立(ShipCreateModel ShipList)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();

            if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
            {
                tEmployee employee = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
                tShipList Shiplist = new tShipList();
                Shiplist.sEmployeeId      = employee.EmployeeId;
                Shiplist.sShipSerialValue = ShipList.sShipSerialValue;
                Shiplist.sOrderId         = ShipList.SelectOrder;
                Shiplist.sShipDate        = ShipList.sShipDate;
                Shiplist.sShipNote        = ShipList.sShipNote;
                dbContext.tShipLists.Add(Shiplist);
                dbContext.SaveChanges();
                for (int i = 0; i < ShipList.WareHouseId.Count; i++)
                {
                    if (ShipList.ShipProductQty[i] != 0)
                    {
                        tShipDetail tShipdetail = new tShipDetail();
                        tShipdetail.ShipId           = dbContext.tShipLists.OrderByDescending(s => s.ShipId).First().ShipId;
                        tShipdetail.sOrderDetailId   = ShipList.OrderDetailId[i];
                        tShipdetail.sProductId       = ShipList.ProductId[i];
                        tShipdetail.sQuantity        = ShipList.ShipProductQty[i];
                        tShipdetail.sWarehouseNameId = ShipList.WareHouseId[i];
                        dbContext.tShipDetails.Add(tShipdetail);
                        //倉儲變動
                        tWarehouse Warehouse = dbContext.tWarehouses.Where(w => w.WarehouseNameId == tShipdetail.sWarehouseNameId && w.wProductId == tShipdetail.sProductId).FirstOrDefault();
                        if (Warehouse != null)
                        {
                            Warehouse.wPQty -= ShipList.ShipProductQty[i];
                        }
                    }
                }
                tOrder order = dbContext.tOrders.Where(o => o.OrderId == Shiplist.sOrderId).FirstOrDefault();
                order.oDeliverDate = ShipList.sShipDate;
                dbContext.SaveChanges();
            }
            return(RedirectToAction("出貨單查詢"));
        }
Esempio n. 15
0
        public JsonResult 會員註冊(RegisterViewModel newMember)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();

            if (newMember.cAccount != null &&
                newMember.cPassword != null &&
                newMember.cName != null &&
                newMember.cCellPhone != null &&
                newMember.cAddress != null &&
                newMember.cEmail != null
                )
            {
                if (newMember.cPassword.Length < 6 && newMember.cAccount.Length < 6)
                {
                    return(Json(new { result = false, msg = "密碼及帳號長度需介於6~12字元" }));
                }

                if (newMember.cPassword != newMember.cConfirmPassword)
                {
                    return(Json(new { result = false, msg = "密碼及確認密碼必須相同" }));
                }

                List <tCustomer> custo = dbContext.tCustomers.ToList();
                foreach (var item in custo)
                {
                    if (item.cAccount == newMember.cAccount)
                    {
                        return(Json(new { result = false, msg = "此帳號已被註冊" }));
                    }
                    else if (item.cEmail == newMember.cEmail)
                    {
                        return(Json(new { result = false, msg = "此信箱已被使用" }));
                    }
                }
                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 { result = true, msg = "註冊成功", url = Url.Action("首頁", "Customer") }));
            }
            return(Json(new { result = false, msg = "帳號、密碼、姓名、手機、地址及信箱必須填寫" }));
        }
Esempio n. 16
0
        //[HttpPost]
        //public JsonResult beforeSendEmail(ForgotPasswordViewModel c電子郵件)
        //{
        //    MotaiDataEntities dbContext = new MotaiDataEntities();
        //    tCustomer d信箱確認 = dbContext.tCustomers.Where(c => c.cEmail == c電子郵件.Email).FirstOrDefault();
        //    if (d信箱確認 != null)
        //    {
        //        string passwordG = Guid.NewGuid().ToString();
        //        d信箱確認.cPassword = passwordG;
        //        dbContext.SaveChanges();
        //        return Json(new { result = true, msg = "已寄出修改密碼的信件!", url = Url.Action("首頁", "Customer"), password = passwordG, name = d信箱確認.cName,});
        //    }
        //    return Json(new { result = false, msg = "此電子郵件尚未被註冊", url = Url.Action("會員註冊", "Customer") });
        //}

        public ActionResult SendEmail(ForgotPasswordViewModel c電子郵件)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tCustomer         d信箱確認     = dbContext.tCustomers.Where(c => c.cEmail == c電子郵件.Email).FirstOrDefault();

            if (d信箱確認 != null)
            {
                string passwordG = Guid.NewGuid().ToString();
                d信箱確認.cPassword = passwordG;
                dbContext.SaveChanges();

                SmtpClient Client = new SmtpClient()
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential()
                    {
                        UserName = "******",
                        Password = "******"
                    }
                };
                MailMessage Message = new MailMessage();
                Message.To.Add(new MailAddress(c電子郵件.Email, d信箱確認.cName));
                Message.From       = new MailAddress("*****@*****.**", "墨台");
                Message.Subject    = "墨台 忘記密碼認證信";
                Message.IsBodyHtml = true;
                Message.Body       = d信箱確認.cName + "您好非常感謝您到墨台進行選購,我們已收到您重設密碼的申請。\r\n請您回到首頁,以此密碼登入:" + d信箱確認.cPassword + "\r\n登入後,點選右上角第一個Icon進入會員中心,重新設定一組新的密碼。\r\n首頁連結: https://motai.azurewebsites.net/ ";
                Message.Priority   = MailPriority.Low;
                ////MailAddress ToEmail = new MailAddress("*****@*****.**", "HY LIN2");
                //MailAddress FromEmail = new MailAddress("*****@*****.**", "墨台");
                //MailAddress ToEmail = new MailAddress(c電子郵件.Email, d信箱確認.cName);
                //MailMessage Message = new MailMessage()
                //{
                //    From = FromEmail,
                //    Subject = "墨台 忘記密碼認證信",
                //    Body = d信箱確認.cName + "您好非常感謝您到墨台進行選購,我們已收到您重設密碼的申請。\r\n請您回到首頁,以此密碼登入:" + d信箱確認.cPassword + "\r\n登入後,點選右上角第一個Icon進入會員中心,重新設定一組新的密碼。\r\n首頁連結: https://motai.azurewebsites.net/ "
                //    //  IsBodyHtml = true
                //};
                //Message.To.Add(ToEmail);
                Client.Send(Message);
                Client.Dispose();
                Message.Dispose();
                return(Json(new { result = true, msg = "已寄出修改密碼的信件!", url = Url.Action("首頁", "Customer") }));
            }
            return(Json(new { result = false, msg = "此電子郵件尚未被註冊", url = Url.Action("會員註冊", "Customer") }));
        }
Esempio n. 17
0
        public ActionResult 購物車內刪除(int fid)
        {
            MotaiDataEntities db    = new MotaiDataEntities();
            tStatu            statu = db.tStatus.Where(s => s.StatusId.Equals(fid)).FirstOrDefault();

            if (statu != null)
            {
                db.tStatus.Remove(statu);
                db.SaveChanges();
                tCustomer cust  = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
                int       count = db.tStatus.Where(c => c.sCustomerId == cust.CustomerId).ToList().Count;
                ViewBag.Count = count + "項";
            }
            return(RedirectToAction("購物車清單"));
        }
 public JsonResult orderCheck(int Id)
 {
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] == null)
     {
         return(Json(new { result = false, msg = "請先登入" }));
     }
     else
     {
         MotaiDataEntities dbContext = new MotaiDataEntities();
         tOrder            order     = dbContext.tOrders.Where(o => o.OrderId.Equals(Id)).FirstOrDefault();
         order.oCheck     = "checked";
         order.oCheckDate = DateTime.Now;
         dbContext.SaveChanges();
         return(Json(new { msg = "審核成功", url = Url.Action("會計查詢", "Accountant") }));
     }
 }
        public ActionResult 會計審核(OrderViewModel checkOrder)
        {
            if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] == null)
            {
                return(RedirectToAction("員工登入"));
            }
            MotaiDataEntities dbContext   = new MotaiDataEntities();
            tOrder            tcheckOrder = dbContext.tOrders.FirstOrDefault(p => p.OrderId == checkOrder.OrderId);

            tcheckOrder.oCheck = checkOrder.oCheck;
            var date = DateTime.Now.Date;

            checkOrder.oCheckDate = date;
            dbContext.SaveChanges();
            return(RedirectToAction("會計查詢"));
        }
Esempio n. 20
0
 public JsonResult CancelFavorite(int ProductId)
 {
     if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
     {
         tCustomer         cust  = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
         MotaiDataEntities db    = new MotaiDataEntities();
         tFavorite         favor = db.tFavorites.Where(f => f.fProductId.Equals(ProductId) && f.fCustomerId.Equals(cust.CustomerId)).FirstOrDefault();
         db.tFavorites.Remove(favor);
         db.SaveChanges();
         return(Json(new { result = true, msg = "刪除成功" }));
     }
     else
     {
         return(Json(new { result = false, msg = "請先登入" }));
     }
 }
Esempio n. 21
0
        public ActionResult 新增產品(ProductViewModel n新增產品)
        {
            MotaiDataEntities db   = new MotaiDataEntities();
            tProduct          prod = new tProduct();

            prod.pNumber   = n新增產品.pNumber;
            prod.pName     = n新增產品.pName;
            prod.pCategory = n新增產品.pCategory;
            prod.pMaterial = n新增產品.pMaterial;
            prod.pSize     = n新增產品.pSize;
            prod.pLxWxH    = n新增產品.pLxWxH;
            prod.pPrice    = n新增產品.pPrice;
            prod.pWeight   = n新增產品.pWeight;
            db.tProducts.Add(prod);

            tProduct Product = db.tProducts.OrderByDescending(o => o.ProductId).FirstOrDefault();
            int      ProductId;

            if (Product == null)
            {
                ProductId = 1;
            }
            else
            {
                ProductId = Product.ProductId;
                ProductId++;
            }
            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);
                    }
                }
            }
            db.SaveChanges();
            return(RedirectToAction("倉儲看產品頁面"));
        }
Esempio n. 22
0
 public ActionResult 修改員工(EmployeeViewModels employee)
 {
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
     {
         MotaiDataEntities db  = new MotaiDataEntities();
         tEmployee         emp = db.tEmployees.Find(employee.EmployeeId);
         if (emp != null)
         {
             emp.eBranch   = employee.eBranch;
             emp.ePosition = employee.ePosition;
             emp.eName     = employee.eName;
             db.SaveChanges();
         }
         return(RedirectToAction("人員檢視"));
     }
     return(RedirectToAction("員工登入", "Employee"));
 }
Esempio n. 23
0
        public ActionResult 修改日誌(DiaryViewModel m)
        {
            MotaiDataEntities dbcontext = new MotaiDataEntities();
            tDiary            diary     = dbcontext.tDiaries.Find(m.DiaryId);

            if (diary != null)
            {
                diary.DiaryId          = m.DiaryId;
                diary.dEmployeeId      = m.dEmployeeId;
                diary.dDate            = m.dDate;
                diary.dDiaryNote       = m.dDiaryNote;
                diary.dWeather         = m.dWeather;
                diary.dWarehouseNameId = m.dWarehouseNameId;
                dbcontext.SaveChanges();
                return(RedirectToAction("工作日誌"));
            }

            return(View("業務看產品頁面"));
        }
Esempio n. 24
0
 public ActionResult 新增日誌(DiaryViewModel data)
 {
     if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
     {
         MotaiDataEntities     db    = new MotaiDataEntities();
         tDiary                diary = new tDiary();
         List <DiaryViewModel> DShow = new List <DiaryViewModel>();
         diary.dEmployeeId      = data.dEmployeeId;
         diary.DiaryId          = data.DiaryId;
         diary.dDate            = data.dDate;
         diary.dWeather         = data.dWeather;
         diary.dWarehouseNameId = data.dWarehouseNameId;
         diary.dDiaryNote       = data.dDiaryNote;
         db.tDiaries.Add(diary);
         db.SaveChanges();
         return(RedirectToAction("工作日誌"));
     }
     return(RedirectToAction("員工登入", "Employee"));
 }
Esempio n. 25
0
        public ActionResult 新增員工(EmployeeViewModels create員工)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();

            if (dbContext.tEmployees.Count().Equals(0))
            {
                create員工.EmployeeId = 1;
            }
            tEmployee n新員工 = new tEmployee();

            n新員工.eAccount   = create員工.eAccount;
            n新員工.EmployeeId = create員工.EmployeeId;
            n新員工.ePassword  = create員工.ePassword;
            n新員工.eName      = create員工.eName;
            n新員工.ePosition  = create員工.ePosition;
            n新員工.eBranch    = create員工.eBranch;
            dbContext.tEmployees.Add(n新員工);
            dbContext.SaveChanges();
            return(RedirectToAction("員工首頁"));
        }
Esempio n. 26
0
 public ActionResult 修改會員資料(MemberViewModel member)
 {
     if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
     {
         tCustomer         customer = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
         MotaiDataEntities db       = new MotaiDataEntities();
         tCustomer         cust     = db.tCustomers.Find(customer.CustomerId);
         if (cust != null)
         {
             cust.cName      = member.cName;
             cust.cTelePhone = member.cTelePhone;
             cust.cGUI       = member.cGUI;
             cust.cEmail     = member.cEmail;
             cust.cAddress   = member.cAddress;
             db.SaveChanges();
         }
         return(RedirectToAction("會員中心"));
     }
     return(RedirectToAction("首頁"));
 }
Esempio n. 27
0
 //加入收藏
 public JsonResult AddFavorite(int ProductId)
 {
     if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null)
     {
         tCustomer         cust      = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer;
         MotaiDataEntities dbContext = new MotaiDataEntities();
         tFavorite         favor     = new tFavorite();
         //if (dbContext.tFavorites.Count().Equals(0))
         //{
         //    favor.FavoriteId = 1;
         //}
         favor.fCustomerId = cust.CustomerId;
         favor.fProductId  = ProductId;
         dbContext.tFavorites.Add(favor);
         dbContext.SaveChanges();
         return(Json(new { result = true, msg = "加入成功" }));
     }
     else
     {
         return(Json(new { result = false, msg = "請先登入" }));
     }
 }
Esempio n. 28
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消息.pPromotionWeb        = create消息.pPromotionWeb;
            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;
            var uploagFile = create消息.upLoadimage;

            if (uploagFile == null)
            {
            }
            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 = "../../images/" + Url.Content(photoName);
                dbContext.tPromotions.Add(n消息);
            }
            dbContext.SaveChanges();
            return(RedirectToAction("員工看消息"));
        }
Esempio n. 29
0
        public ActionResult 調貨單建立(TransferSaveModel save)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();

            if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] != null)
            {
                tEmployee employee = Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] as tEmployee;
                tTransfer transfer = new tTransfer();
                transfer.tProductId  = save.ProductId;
                transfer.tProductQty = save.ProductQty;
                transfer.tEmployeeId = employee.EmployeeId;
                transfer.tWNIdOut    = save.WarehouseIdOut;
                transfer.tWNIdIn     = save.WarehouseIdIn;
                transfer.tDate       = save.Date;
                transfer.tNote       = save.Note;
                tWarehouse warehouseOut = dbContext.tWarehouses.Where(wo => wo.WarehouseNameId.Equals(save.WarehouseIdOut) && wo.wProductId.Equals(save.ProductId)).FirstOrDefault();
                warehouseOut.wPQty = warehouseOut.wPQty - save.ProductQty;
                tWarehouse warehouseIn = dbContext.tWarehouses.Where(wo => wo.WarehouseNameId.Equals(save.WarehouseIdIn) && wo.wProductId.Equals(save.ProductId)).FirstOrDefault();
                if (warehouseIn == null)
                {
                    tWarehouse newwarehouseIn = new tWarehouse();
                    newwarehouseIn.WarehouseNameId = save.WarehouseIdIn;
                    newwarehouseIn.wProductId      = save.ProductId;
                    newwarehouseIn.wPQty           = save.ProductQty;
                    dbContext.tWarehouses.Add(newwarehouseIn);
                }
                else
                {
                    warehouseIn.wPQty = warehouseIn.wPQty + save.ProductQty;
                }
                dbContext.tTransfers.Add(transfer);
                dbContext.SaveChanges();
                return(RedirectToAction("調貨單查詢", "Commodity"));
            }
            return(RedirectToAction("員工登入", "Employee"));
        }
Esempio n. 30
0
        public ActionResult 修改產品(EmpProductViewModel p)
        {
            if (Session[CSession關鍵字.SK_LOGINED_EMPLOYEE] == null)
            {
                return(RedirectToAction("員工登入", "Employee"));
            }
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tProduct          prod      = dbContext.tProducts.Find(p.ProductId);

            if (prod != null)
            {
                prod.pNumber   = p.pNumber;
                prod.pName     = p.pName;
                prod.pCategory = p.pCategory;
                prod.pMaterial = p.pMaterial;
                prod.pSize     = p.pSize;
                prod.pLxWxH    = p.pLxWxH;
                prod.pWeight   = p.pWeight;
                prod.pPrice    = p.pPrice;
                List <tProductImage> oldImages = dbContext.tProductImages.Where(imgs => imgs.ProductId.Equals(p.ProductId)).ToList();
                if (oldImages.Count > p.pImage.Count)
                {
                    int index = 0;
                    foreach (var oldItem in oldImages)
                    {
                        if (index < p.pImage.Count)
                        {
                            if (p.pImage[index] == null)
                            {
                                break;
                            }
                            if (p.pImage[index].ContentLength > 0)
                            {
                                FileInfo file      = new FileInfo(p.pImage[index].FileName);
                                string   photoName = Guid.NewGuid().ToString() + file.Extension;
                                p.pImage[index].SaveAs(Server.MapPath("~/images/" + photoName));
                                oldItem.pImage = Url.Content("~/images/" + photoName);
                                //Directory.Delete(Url.Content(oldItem.pImage));
                            }
                        }
                        else
                        {
                            dbContext.tProductImages.Remove(oldItem);
                        }
                        index++;
                    }
                }
                else
                {
                    int index = 0;
                    foreach (var item in p.pImage)
                    {
                        if (index < oldImages.Count)
                        {
                            FileInfo file      = new FileInfo(item.FileName);
                            string   photoName = Guid.NewGuid().ToString() + file.Extension;
                            item.SaveAs(Server.MapPath("~/images/" + photoName));
                            oldImages[index].pImage = Url.Content("~/images/" + photoName);
                        }
                        else
                        {
                            tProductImage image     = new tProductImage();
                            FileInfo      file      = new FileInfo(item.FileName);
                            string        photoName = Guid.NewGuid().ToString() + file.Extension;
                            item.SaveAs(Server.MapPath("~/images/" + photoName));
                            image.ProductId = p.ProductId;
                            image.pImage    = "~" + Url.Content("~/images/" + photoName);
                            dbContext.tProductImages.Add(image);
                        }
                        index++;
                    }
                }
                dbContext.SaveChanges();
            }
            return(RedirectToAction("倉儲看產品頁面"));
        }