コード例 #1
0
        [HttpPost] // 動作選取器
        public ActionResult AddToCart()
        {
            string id = Request.Form["txtFid"];

            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("List"));
            }

            int            fId     = Convert.ToInt32(id);
            dbDemoEntities db      = new dbDemoEntities();
            tProduct       product = db.tProduct.FirstOrDefault(p => p.fId == fId);

            if (product == null)
            {
                return(RedirectToAction("List"));
            }
            tShoppingCart item = new tShoppingCart();

            item.fDate       = DateTime.Now.ToString("yyyyMMddHHmmss");
            item.fCustomerId = 1;
            item.fProductId  = product.fId;
            item.fPrice      = product.fPrice;
            item.fCount      = Convert.ToInt32(Request.Form["txtCount"]);

            db.tShoppingCart.Add(item);
            db.SaveChanges();
            return(RedirectToAction("List"));
        }
コード例 #2
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("首頁"));
            }
        }
コード例 #3
0
        public ProductViewModel GetProductById(int ProductId)
        {
            List <tWarehouse> warehouse = dbContext.tWarehouses.Where(p => p.wProductId == ProductId).ToList();
            tProduct          product   = dbContext.tProducts.FirstOrDefault(p => p.ProductId == ProductId);
            ProductViewModel  Prod      = new ProductViewModel();

            Prod.ProductId     = product.ProductId;
            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;
            if (warehouse != null)
            {
                int warehouseQty = 0;
                foreach (var wareQty in warehouse)
                {
                    warehouseQty += wareQty.wPQty;
                }
                Prod.pQty = warehouseQty;
            }
            else
            {
                Prod.pQty = 0;
            }

            Prod.psImage = GetProductShowImages(product);
            return(Prod);
        }
コード例 #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 }));
        }
コード例 #5
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("首頁"));
            }
        }
コード例 #6
0
        public IHttpActionResult PuttProduct(int id, tProduct tProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tProduct.ID)
            {
                return(BadRequest());
            }

            db.Entry(tProduct).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #7
0
        public ActionResult Create(string fId, string fName, decimal fPrice, HttpPostedFileBase fImg)
        {
            //處理圖檔上傳
            string fileName = "";

            if (fImg != null)
            {
                if (fImg.ContentLength > 0)
                {
                    fileName = System.IO.Path.GetFileName(fImg.FileName);
                    fImg.SaveAs(Server.MapPath("~/images/" + fileName));//MapPath:把邏輯路徑,轉成實體路徑。//將檔案存到Images資料夾下
                }
            }

            //新增至db
            //步驟1,先將東西丟至module
            tProduct product = new tProduct();

            product.fId    = fId;
            product.fName  = fName;
            product.fPrice = fPrice;
            product.fImg   = fileName;
            db.tProduct.Add(product);
            //步驟2,存至db
            //多出來的做新增
            //不一樣的做修改
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        using (eShopperDBEntities products = new eShopperDBEntities())
        {
            var query = from p in products.tProducts

                        select p;


            tProduct product = (query.FirstOrDefault <tProduct>());
            GridView1.DataSource = query.ToList();
            GridView1.DataBind();
        }
        using (eShopperDBEntities categpry = new eShopperDBEntities())
        {
            var query = (from c in categpry.tCategories

                         select c);


            //   tCategory categpryies = (query.FirstOrDefault<tCategory>());
            //    GridView1.DataSource = query.ToList();
            //    GridView1.DataBind();


            DropDownList2.DataSource     = query.ToList();
            DropDownList2.DataTextField  = "CategoryName";
            DropDownList2.DataValueField = "CategoryID";
            DropDownList2.DataBind();
        }
    }
コード例 #9
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));
        }
コード例 #10
0
        [HttpPost]                                  //將表單資料丟到伺服器端

        //取得資料,當資料有檔案時,要使用HttpPostedFileBase
        public ActionResult Create(string fId, string fName, decimal fPrice, HttpPostedFileBase fImg)
        {
            string imgname = "";

            if (fImg != null)
            {                                               //處理表單上傳的圖片
                if (fImg.ContentLength > 0)
                {
                    imgname = System.IO.Path.GetFileName(fImg.FileName);       //system.io為namespace;取得檔案檔名(副檔名也會取得)
                    fImg.SaveAs(Server.MapPath("~/images/" + imgname));        //由於不知道伺服器實體路徑,使用server.mappath,程式會將邏輯路徑轉為伺服器端的實體路徑
                    Console.WriteLine(Server.MapPath("~/images/" + imgname));
                }
            }
            //處理圖檔上傳(先丟到model,再丟到DB)

            tProduct product = new tProduct();      //將資料表鑄造為一個物件,欄位視為資料表的屬性

            product.fId    = fId;
            product.fName  = fName;
            product.fPrice = fPrice;
            product.fImg   = imgname;

            db.tProduct.Add(product);                           //將資料寫到model
            db.SaveChanges();                                   //將資料寫入資料庫

            return(RedirectToAction("Index"));                  //新增完重新導向到首頁
        }
コード例 #11
0
ファイル: HomeController.cs プロジェクト: qo45p/slnMVC-ch10
 public ActionResult Create(string fId, string fName, decimal fPrice, HttpPostedFileBase fImg)
 {
     try
     {
         //上傳圖檔
         string fileName = "";
         //檔案上傳
         if (fImg != null)
         {
             if (fImg.ContentLength > 0)
             {
                 //取得圖檔名稱
                 fileName =
                     System.IO.Path.GetFileName(fImg.FileName);
                 var path = System.IO.Path.Combine(Server.MapPath("~/Images"), fileName);
                 fImg.SaveAs(path); //檔案儲存到Images資料夾下
             }
         }
         //新增記錄
         tProduct product = new tProduct();
         product.fId    = fId;
         product.fName  = fName;
         product.fPrice = fPrice;
         product.fImg   = fileName;
         db.tProduct.Add(product);
         db.SaveChanges();
         return(RedirectToAction("Index")); //導向Index的Action方法
     }
     catch (Exception ex)
     {
         ViewBag.Error = ex.Message;
     }
     return(View());
 }
コード例 #12
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));
        }
コード例 #13
0
ファイル: payMethod.cs プロジェクト: CGW1996/91App_git
        public void pm(tProduct x)
        {
            if (x.fPayBy != null)
            {
                foreach (var i in x.fPayBy)
                {
                    switch (i)
                    {
                    case 1:
                        x.fPayByArrive = 1;
                        break;

                    case 2:
                        x.fPayByLinePay = 1;
                        break;

                    case 3:
                        x.fPayByJKO = 1;
                        break;

                    case 4:
                        x.fPayByCard = 1;
                        break;
                    }
                }
            }
        }
コード例 #14
0
        protected void Btn_Create_Click(object sender, EventArgs e)
        {
            try
            {
                // 圖檔儲存
                string fileName = "";
                if (FileUpload1.HasFile)
                {
                    FileUpload1.SaveAs(Server.MapPath("Images") + "/" + FileUpload1.FileName);
                    fileName = FileUpload1.FileName;
                }

                // 新增紀錄
                dbProductEntities db      = new dbProductEntities();
                tProduct          product = new tProduct();
                product.fId    = txtId.Text;
                product.fName  = txtName.Text;
                product.fPrice = decimal.Parse(txtPrice.Text);
                product.fImg   = fileName;
                db.tProduct.Add(product);
                db.SaveChanges();

                // 轉向 Index.aspx
                Response.Redirect("Index.aspx");
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
コード例 #15
0
ファイル: HomeController.cs プロジェクト: bowbow19/ASPnet1
        public ActionResult Create(string fId, string fName, decimal fPrice, HttpPostedFileBase fImg)
        {
            //處理圖檔上傳
            string fileName = "";

            if (fImg != null)
            {
                if (fImg.ContentLength > 0)
                {
                    fileName = System.IO.Path.GetFileName(fImg.FileName); //取得檔案的檔名

                    fImg.SaveAs(Server.MapPath("~/images/" + fileName));  //將檔案存到Images資料夾下
                }
            }
            //處理圖檔上傳end
            tProduct product = new tProduct();

            product.fId    = fId;
            product.fName  = fName;
            product.fPrice = fPrice;
            product.fImg   = fileName;

            db.tProduct.Add(product);
            db.SaveChanges();

            return(RedirectToAction("Index"));  //導向Index的Action方法
        }
コード例 #16
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 }));
        }
コード例 #17
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") }));
     }
 }
コード例 #18
0
        public JsonResult autoProductNumPrice(int ProductId)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tProduct          product   = dbContext.tProducts.Where(p => p.ProductId == ProductId).FirstOrDefault();
            string            Number    = product.pNumber;
            string            Price     = product.pPrice.ToString("#0.######");

            return(Json(new { num = Number, price = Price }));
        }
コード例 #19
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 == 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;
             tEmployee employee = db.tEmployees.Where(e => e.EmployeeId == items.oEmployeeId).FirstOrDefault();
             if (employee != null)
             {
                 order.EmployeeName = employee.eName;
             }
             order.cNote = items.cNote;
             List <tOrderDetail> orderdetails = db.tOrderDetails.Where(od => od.oOrderId == items.OrderId).ToList();
             List <CustomerOrderDetailViewModel> OrderDetailList = new List <CustomerOrderDetailViewModel>();
             int originPrice = 0;
             foreach (var itemDetail in orderdetails)
             {
                 CustomerOrderDetailViewModel orderdetail = new CustomerOrderDetailViewModel();
                 tProduct product = db.tProducts.Where(p => p.ProductId == itemDetail.oProductId).FirstOrDefault();
                 orderdetail.ProductNum   = product.pNumber;
                 orderdetail.ProductName  = product.pName;
                 orderdetail.ProductPrice = product.pPrice;
                 orderdetail.oProductQty  = itemDetail.oProductQty;
                 orderdetail.oNote        = itemDetail.oNote;
                 OrderDetailList.Add(orderdetail);
                 originPrice += Convert.ToInt32(product.pPrice) * itemDetail.oProductQty;
             }
             if (items.oPromotionId != null)
             {
                 tPromotion promotion = db.tPromotions.Where(p => p.PromotionId == items.oPromotionId).FirstOrDefault();
                 order.TotalAmount = originPrice - Convert.ToInt32(promotion.pDiscount);
             }
             else
             {
                 order.TotalAmount = originPrice;
             }
             List <tOrderPay> paylists = db.tOrderPays.Where(op => op.oOrderId == items.OrderId).ToList();
             foreach (var itemPay in paylists)
             {
                 order.AlreadyPay += Convert.ToInt32(itemPay.oPayment);
             }
             order.Unpaid = order.TotalAmount - order.AlreadyPay;
             order.CustomerOrderDetails = OrderDetailList;
             OrderList.Add(order);
         }
         return(View(OrderList));
     }
     return(RedirectToAction("首頁"));
 }
コード例 #20
0
        public ActionResult ProductEdit(tProduct prod)
        {
            ViewBag.PartDropDownList = DropDownList.GetPartDropDownList();
            ViewBag.NoteDropList     = DropDownList.GetNoteDropList();
            ViewBag.CategoryDropList = DropDownList.GetCategoryDropList();
            ViewBag.EfficacyDropLise = DropDownList.GetEfficacyDropLise();
            ViewBag.featureDropList  = DropDownList.GetfeatureDropList();

            db.SaveChanges();
            return(RedirectToAction("ProductPage"));
        }
コード例 #21
0
        public List <string> GetProductShowImages(tProduct product)
        {
            List <string>        psImage = new List <string>();
            List <tProductImage> images  = dbContext.tProductImages.Where(i => i.ProductId.Equals(product.ProductId)).ToList();

            foreach (var imageitem in images)
            {
                psImage.Add(imageitem.pImage);
            }
            return(psImage);
        }
コード例 #22
0
        public IHttpActionResult PosttProduct(tProduct tProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tProducts.Add(tProduct);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = tProduct.ID }, tProduct));
        }
コード例 #23
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("List"));
            }

            dbDemoEntities db = new dbDemoEntities();
            tProduct       x  = db.tProduct.FirstOrDefault(m => m.fId == id);

            return(View(x));
        }
コード例 #24
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (cl.checkRole(Session["userid_hcc"].ToString(), codeModule, 1))
        {
            if (txtName.Text.Trim().Equals(""))
            {
                Mess("Nhập tên sản phẩm", "");
            }
            else
            {
                try
                {
                    string filename = DateTime.Now.ToString("ddMMyyyyhhmmss"), file_ex = "";

                    HttpFileCollection hfc = Request.Files;
                    for (int i = 0; i < hfc.Count; i++)
                    {
                        HttpPostedFile hpf = hfc[i];
                        if (hpf.ContentLength > 0)
                        {
                            tProduct p = new tProduct();
                            p.Name       = txtName.Text.Trim();
                            p.CategoryId = int.Parse(dlCategory.SelectedValue.Trim());

                            p.IsActive = ckActive.Checked;
                            p.CreateAt = DateTime.Now;

                            file_ex = hpf.FileName.Trim();
                            file_ex = file_ex.Substring(file_ex.LastIndexOf('.'));
                            p.Image = "/wp-content/uploads/gallery/" + filename + "_" + i.ToString() + file_ex;
                            db.tProducts.InsertOnSubmit(p);
                            hpf.SaveAs(Server.MapPath("/wp-content/uploads/gallery/" + filename + "_" + i.ToString() + file_ex));
                        }
                    }

                    db.SubmitChanges();

                    ResetControl();
                    LoadGrid();
                    Mess("Lưu thành công", "");
                }
                catch (Exception ax)
                {
                    Mess(ax.Message, "");
                }
            }
        }
        else
        {
            Mess("Bạn không có quyền sử dụng chức năng này", "/adhome");
        }
    }
コード例 #25
0
        public IHttpActionResult DeletetProduct(int id)
        {
            tProduct tProduct = db.tProducts.Find(id);

            if (tProduct == null)
            {
                return(NotFound());
            }

            db.tProducts.Remove(tProduct);
            db.SaveChanges();

            return(Ok(tProduct));
        }
コード例 #26
0
        public ActionResult EditProduct(tProduct modify, HttpPostedFileBase fImgFile)
        {
            var prod = db.tProduct
                .Where(p => p.fId == modify.fId)
                .FirstOrDefault();

            if (fImgFile != null) 
            {
                string deleteresult = prod.fImg;

                if (System.IO.File.Exists(Server.MapPath(prod.fImg)))
                {
                    try
                    {
                        System.IO.File.Delete(Server.MapPath(prod.fImg));
                    }
                    catch
                    {
                        deleteresult = "修改失敗";
                    }
                }

                if (deleteresult != "修改失敗") 
                {
                    int point = fImgFile.FileName.IndexOf(".");
                    string extention = fImgFile.FileName.Substring(point, fImgFile.FileName.Length - point);
                    string photoName = modify.fPId + extention;
                    fImgFile.SaveAs(Server.MapPath("../Content/" + photoName));
                    modify.fImg = "../Content/" + photoName;
                }
            }
            else
            {
                ViewBag.ImgFile = "請上傳產品圖片";
                return View("EditProduct", "_LayoutAdmin", prod);
            }

            if (prod != null)
            {
                prod.fPId = modify.fPId;
                prod.fName = modify.fName;
                prod.fPrice = modify.fPrice;
                prod.fImg = modify.fImg;
                prod.fIsApproved = modify.fIsApproved;
                db.SaveChanges();                
            }
            
            return RedirectToAction("Index");
        }
コード例 #27
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("List"));
            }
            dbDemoEntities db = new dbDemoEntities();
            tProduct       p  = db.tProduct.FirstOrDefault(m => m.fId == id);

            if (p != null)
            {
                db.tProduct.Remove(p);
                db.SaveChanges();
            }
            return(RedirectToAction("List"));
        }
コード例 #28
0
        //public HttpPostedFileBase fImage { get; set; }
        public ActionResult Create(tProduct x)
        {
            payMethod pm = new payMethod();

            pm.pm(x);
            if (x.fImage != null)
            {
                string name = Guid.NewGuid().ToString() + Path.GetExtension(x.fImage.FileName);
                var    path = Path.Combine(Server.MapPath("~/Content"), name);
                x.fImage.SaveAs(path);
                x.fProductImage = "/Content/" + name;
            }
            db.tProduct.Add(x);
            db.SaveChanges();
            return(RedirectToAction("productList"));
        }
コード例 #29
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("productList"));
            }
            ;
            tProduct t = db.tProduct.FirstOrDefault(z => z.fProductId == id);

            if (t != null)
            {
                db.tProduct.Remove(t);
                db.SaveChanges();
            }
            return(RedirectToAction("productList"));
        }
コード例 #30
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("倉儲看產品頁面"));
        }