Пример #1
0
        public ActionResult SaveInfo(AdministratorInfo admin)
        {
            AdministratorInfo AdminInfo = shop.AdministratorInfo.Where(a => a.AI_Num == admin.AI_Num).FirstOrDefault();

            //判断用户没有选择性别时默认选中保密
            if (string.IsNullOrEmpty(admin.AI_Sex))
            {
                admin.AI_Sex = "2";
            }

            //判断用户没有选择注册类型时默认选中店主
            if (admin.AI_Type == null)
            {
                admin.AI_Type = 1;
            }
            AdminInfo.AI_Sex    = admin.AI_Sex;
            AdminInfo.AI_IDCard = admin.AI_IDCard;
            AdminInfo.AI_Name   = admin.AI_Name;
            AdminInfo.AI_Type   = admin.AI_Type;
            AdminInfo.AI_Alipay = admin.AI_Alipay;
            AdminInfo.AI_HImage = Session["url"].ToString();

            int count = shop.SaveChanges();

            if (count > 0)
            {
                Session["LoginInfo"] = AdminInfo;
            }
            return(RedirectToAction("Index_Information"));
        }
        public ActionResult Create(actBulletin act, HttpPostedFileBase actImage) 
        {
            string fileName = "";
            string GetActID = db.Database.SqlQuery<string>("Select dbo.GetActID()").FirstOrDefault();
            act.actID = GetActID;
            act.actImage = GetActID + ".jpg";
            
            if (actImage != null)
            {
                if (actImage.ContentLength > 0)
                {
                    fileName = GetActID + ".jpg";
                    actImage.SaveAs(Server.MapPath("~/actImage/" + fileName));
                }
            }

            if (actImage == null)
            {
                act.actImage= "act0000000.jpg";
            }
            //if (ModelState.IsValid)
            //{
            //    db.actBulletin.Add(actBulletin);
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}

            db.actBulletin.Add(act);
            db.SaveChanges();
            ViewBag.admID = new SelectList(db.Adm, "admID", "admName", act.admID);
            return View(act);
        }
        public ActionResult DeleteConfirmed(string id)
        {
            WishList wishList = db.WishList.Find(id);

            db.WishList.Remove(wishList);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
        /// <summary>
        /// 处理页面参数
        /// </summary>
        /// <returns></returns>
        public ActionResult GoodsTypeInsert_2(string CTI_Name, string CTI_ID)
        {
            if (Convert.ToInt32(CTI_ID) == 0)
            {
                CommodityTypeInfo F_Info = new CommodityTypeInfo();
                F_Info.CTI_Name   = CTI_Name;
                F_Info.CTI_CTI_ID = null;
                shop.CommodityTypeInfo.Add(F_Info);

                //shop.Entry(F_Info).State = System.Data.EntityState.Added;
                int count = shop.SaveChanges();

                if (count > 0)
                {
                    return(RedirectToAction("GoodsTypeSelect", "GoodsType"));
                }
                else
                {
                    string ErrorMsg = "抱歉,新增失败,可以继续~~~";

                    if (Session["ErrorMsg"] != null)
                    {
                        Session["ErrorMsg"] = null;
                    }
                    Session["ErrorMsg"] = ErrorMsg;
                    return(RedirectToAction("GoodsTypeError", "GoodsType"));
                }
            }
            else
            {
                CommodityTypeInfo S_Info = new CommodityTypeInfo();

                S_Info.CTI_Name   = CTI_Name;
                S_Info.CTI_CTI_ID = Convert.ToInt32(CTI_ID);
                shop.CommodityTypeInfo.Add(S_Info);

                //shop.Entry(F_Info).State = System.Data.EntityState.Added;
                int count = shop.SaveChanges();

                if (count > 0)
                {
                    return(RedirectToAction("GoodsTypeSelect", "GoodsType"));
                }
                else
                {
                    string ErrorMsg = "抱歉,新增失败,可以继续~~~";

                    if (Session["ErrorMsg"] != null)
                    {
                        Session["ErrorMsg"] = null;
                    }
                    Session["ErrorMsg"] = ErrorMsg;
                    return(RedirectToAction("GoodsTypeError", "GoodsType"));
                }
            }
        }
Пример #5
0
        public ActionResult Edit(Product p)
        {
            var product = db.Product.Where(m => m.pdtID == p.pdtID).FirstOrDefault();

            product.pdtName      = p.pdtName;
            product.pdtDescribe  = p.pdtDescribe;
            product.Discontinued = p.Discontinued;
            db.SaveChanges();
            return(RedirectToAction("myProduct", "SellerHome"));
        }
Пример #6
0
        public ActionResult CreatePdt(Product pdt)
        {
            DateTime dt = DateTime.Now;

            pdt.pdtDate = dt;
            db.Product.Add(pdt);

            db.SaveChanges();


            return(RedirectToAction("Index", "productmanage", new { id = pdt.selID }));
        }
Пример #7
0
        public ActionResult SellerCreate(Seller seller, HttpPostedFileBase photo) //創造賣家
        {
            if (ModelState.IsValid != true)
            {
                return(View());
            }

            string fileName    = "";
            string GetSellerID = db.Database.SqlQuery <string>("Select dbo.GetSellerID()").FirstOrDefault();
            string mbrID       = Session["memberID"].ToString();

            seller.selID    = GetSellerID;
            seller.mbrID    = mbrID;
            seller.selImage = GetSellerID + ".jpg";
            seller.selAut   = "2";


            HttpPostedFileBase f = (HttpPostedFileBase)photo;

            if (f != null)
            {
                if (f.ContentLength > 0)
                {
                    fileName = GetSellerID + ".jpg";
                    f.SaveAs(Server.MapPath("~/sellerImage/" + fileName));
                }
            }

            if (f == null)
            {
                seller.selImage = "sel0000000.jpg";
            }


            if (ModelState.IsValid)
            {
                db.Entry(seller).State = EntityState.Modified;
                if (lastcheck(seller.IDNumber) == true)
                {
                    db.Seller.Add(seller);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Market"));
                }
                else
                {
                    ViewBag.Message = "身份證字號不合法";
                }
            }
            return(View(seller));
        }
Пример #8
0
        public ActionResult Register(Member mbr, MemberAccount memberAccount)
        {
            var a = ModelState.IsValid;

            string GetMemberID = db.Database.SqlQuery <string>("Select dbo.GetMemberID()").FirstOrDefault();

            mbr.mbrID           = GetMemberID;
            memberAccount.mbrID = GetMemberID;

            mbr.nickName      = mbr.mbrName;
            mbr.Points        = 0;
            mbr.mbrAut        = false;
            mbr.signupDate    = DateTime.Now;
            mbr.mbrImage      = "0.jpg";
            mbr.mbrBlock      = false;
            mbr.MemberAccount = memberAccount;


            if (ModelState.IsValid)
            {
                //db.Entry(mbr).State = EntityState.Modified;
                //db.Entry(mbr).State = EntityState.Detached;

                db.Member.Add(mbr);
                db.SaveChanges();
                //db.MemberAccount.Add(memberAccount);
                //db.SaveChanges();



                return(RedirectToAction("Registercheck", "login"));
            }
            ViewBag.RegisterErr = true;
            return(View("Login"));
        }
Пример #9
0
        /// <summary>
        /// index_1的更新数据
        /// </summary>
        /// <returns></returns>
        public ActionResult Index_1_flush(CommodityInfo Cinfo)
        {
            shopDBEntities shop = new shopDBEntities();

            Cinfo.CI_NowPrice = (Convert.ToDouble(Cinfo.CI_Discount) * Convert.ToInt32(Cinfo.CI_Price)).ToString();

            var update = shop.Entry(Cinfo);

            update.State = System.Data.EntityState.Unchanged;

            update.Property("CI_Name").IsModified     = true;
            update.Property("CI_CTI_ID").IsModified   = true;
            update.Property("CI_Num").IsModified      = true;
            update.Property("CI_Discount").IsModified = true;
            update.Property("CI_Price").IsModified    = true;
            update.Property("CI_NowPrice").IsModified = true;
            update.Property("CI_Is").IsModified       = true;
            update.Property("CI_SI_ID").IsModified    = true;

            int count = shop.SaveChanges();

            if (count > 0)
            {
                return(RedirectToAction("Index_1", "Mindex"));
            }
            else
            {
                Response.Write("<script>alert('抱歉更新失败了')</script>");
                return(RedirectToAction("Index_1", "Mindex"));
            }
        }
Пример #10
0
        /// <summary>
        /// 用户添加数据zih(处理注册)
        /// </summary>
        /// <returns></returns>
        public ActionResult Register_2(string phone, string pass)
        {
            shopDBEntities shop = new shopDBEntities();



            AdministratorInfo admin = new AdministratorInfo();

            admin.AI_Num      = phone;
            admin.AI_LoginPwd = pass;
            admin.AI_Date     = DateTime.Now;

            shop.Entry(admin).State = System.Data.EntityState.Added;

            int count = shop.SaveChanges();

            if (count > 0)
            {
                return(RedirectToAction("Login_Index", "Login"));
            }
            else
            {
                return(RedirectToAction("Register", "Login"));
            }
        }
Пример #11
0
        public ActionResult Create(ntfRecord ntfRecord)
        {
            string GetntfID = db.Database.SqlQuery <string>("Select dbo.GetNtfID()").FirstOrDefault();

            ntfRecord.ntfID = GetntfID;



            db.ntfRecord.Add(ntfRecord);
            db.SaveChanges();

            ViewBag.mbrID    = new SelectList(db.Member, "mbrID", "mbrName", ntfRecord.mbrID);
            ViewBag.ntfCtgID = new SelectList(db.ntfCategory, "ntfCtgID", "ntfType", ntfRecord.ntfCtgID);

            return(RedirectToAction("Index"));
        }
Пример #12
0
        /// <summary>
        /// 添加店铺
        /// </summary>
        /// <param name="_id">店主编号</param>
        /// <param name="_tid">店铺类型编号</param>
        /// <param name="_name">店铺名称</param>
        /// <param name="_logo">店铺标志图片</param>
        /// <param name="_intro">店铺描述</param>
        /// <param name="_remark">店铺备注</param>
        /// <returns>true:添加店铺成功,false:添加店铺失败</returns>
        public static bool Add(int _id, int _tid, string _name, string _logo, string _intro, string _remark)
        {
            //创建一个shopDBEntities对象
            shopDBEntities sde = new shopDBEntities();

            //创建一个店铺信息对象
            StoreInfo si = new StoreInfo()
            {
                SI_AI_ID      = _id,
                SI_STI_ID     = _tid,
                SI_CreateDate = DateTime.Now,
                SI_Intro      = _intro,
                SI_Logo       = _logo,
                SI_Name       = _name,
                SI_Remark     = _remark
            };

            //添加
            sde.Entry(si).State = System.Data.EntityState.Added;

            //提交
            int count = sde.SaveChanges();


            return(IsYes(count));
        }
 public ActionResult Edit([Bind(Include = "pdtID,selID,pdtName,pdtDate,pdtDescribe,Discontinued,ctgID")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ctgID = new SelectList(db.ProductCategory, "pdtCtgID", "fstLayerID", product.ctgID);
     ViewBag.selID = new SelectList(db.Seller, "selID", "selCompany", product.selID);
     return(View(product));
 }
        public ActionResult Edit([Bind(Include = "mbrID,mbrName,nickName,mbrPhone,mbrMail,birthDate,Points,mbrAut,signupDate,mbrImage,mbrBlock")] Member member)
        {
            if (ModelState.IsValid)
            {
                db.Entry(member).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.mbrID = new SelectList(db.MemberAccount, "mbrID", "mbrAccount", member.mbrID);
            return(View(member));
        }
Пример #15
0
        /// <summary>
        /// 确认订单
        /// </summary>
        /// <param name="orderid"></param>
        public void Decise_Order(string orderid, int?express_id)
        {
            int count = 0;

            //解析字符串转换成多个int值
            if (orderid.Contains(','))
            {
                string[] order_ID = orderid.Split(',');
                for (int i = 0; i < orderid.Length; i++)
                {
                    int?id = Convert.ToInt32(order_ID[i]);
                    //修改该订单的状态
                    OrderFormInfo order = shop.OrderFormInfo.Where(a => a.OFI_ID == id).FirstOrDefault();

                    order.OFI_States = 2;

                    if (!string.IsNullOrEmpty(express_id.ToString()))
                    {
                        order.Express_ID = express_id;
                    }
                    count = shop.SaveChanges();
                }
            }
            else
            {
                int?idS = Convert.ToInt32(orderid);
                //修改该订单的状态
                OrderFormInfo order = shop.OrderFormInfo.Where(a => a.OFI_ID == idS).FirstOrDefault();

                order.OFI_States = 2;

                if (!string.IsNullOrEmpty(express_id.ToString()))
                {
                    order.Express_ID = express_id;
                }
                count = shop.SaveChanges();
            }
            Response.Write(count);
        }
Пример #16
0
        public ActionResult CreateQA(string question, string pdtID)
        {
            string GetQAID = db.Database.SqlQuery <string>("Select dbo.GetQAID()").FirstOrDefault();
            var    qa      = new QA()
            {
                qaID          = GetQAID,
                mbrID         = (string)Session["memberID"],
                Question      = question,//TODO:限制長度
                pdtID         = pdtID,
                displayStatus = true,
                qaTime        = DateTime.Now,
            };

            //QA 預設值
            //qaID  : 自動產生 TODO : QAID不可為NULL
            //qa未讀 : 預設未讀
            //qa公開 : 預設不公開

            db.QA.Add(qa);
            db.SaveChanges();
            return(RedirectToAction("_GetQASection", new { productID = pdtID }));
        }
Пример #17
0
        public ActionResult Edit([Bind(Include = "odrID,pmtID,odrStatusID,recName,recCity,recDist,recAddress,recPhone,pmtDate,odrDate,shpDate,odrNote,traceNumber,cashFlowID")] Order order)

        {
            if (ModelState.IsValid)
            {
                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.odrStatusID = new SelectList(db.OrderStatus, "odrStatusID", "odrStatus", order.odrStatusID);
            ViewBag.pmtID       = new SelectList(db.PaymentMethod, "pmtID", "pmtMethod", order.pmtID);
            return(View(order));
        }
Пример #18
0
        /// <summary>
        /// 店主添加商品处理
        /// </summary>
        /// <param name="commodity"></param>
        /// <returns></returns>
        public ActionResult Index_2_Insert(CommodityInfo commodity)
        {
            //int number = Request.Files.Count;

            //处理文件

            string name = Request.Files[0].FileName;

            if (string.IsNullOrEmpty(name))
            {
                name = "default.png";
            }

            //截取后缀

            int index = name.LastIndexOf(".");

            string houz = name.Substring(index + 1);

            //判断
            if (houz.ToLower() != "png" && houz.ToLower() != "jpg" && houz.ToLower() != "ico" && houz.ToLower() != "gif")
            {
                Response.Write("<script>alert('文件格式不是图片格式')</script>");
                return(RedirectToAction("Index_2", "Mindex"));
            }
            //让用户在指定的文件夹里面选择图片,不需要再重新分配地址

            commodity.CI_Url = "IMG/" + name;

            commodity.CI_SalesNum = 0;

            commodity.CI_NowPrice = (Convert.ToDouble(commodity.CI_Discount) * Convert.ToInt32(commodity.CI_Price)).ToString();

            shopDBEntities shop = new shopDBEntities();

            var insert = shop.Entry(commodity);

            insert.State = System.Data.EntityState.Added;

            int count = shop.SaveChanges();

            if (count > 0)
            {
                return(RedirectToAction("Index_1", "Mindex"));
            }
            else
            {
                Response.Write("<script>alert('抱歉新添商品失败')</script>");
                return(RedirectToAction("Index_2", "Mindex"));
            }
        }
Пример #19
0
        /// <summary>
        /// 删除店铺
        /// </summary>
        /// <param name="_id">店铺编号</param>
        /// <returns>true:删除成功,false:删除失败</returns>
        public static bool Delete(int _id)
        {
            //创建一个shopDBEntities对象
            shopDBEntities sde = new shopDBEntities();

            //删除
            sde.Entry(new StoreInfo()
            {
                SI_ID = _id
            }).State = System.Data.EntityState.Deleted;

            //提交结果
            return(IsYes(sde.SaveChanges()));
        }
        public ActionResult delivery(string odrID, string traceNumber)
        {
            var editods = db.Order.Where(m => m.odrID == odrID).FirstOrDefault();

            editods.odrStatusID = "ods0000003";
            editods.traceNumber = traceNumber;
            editods.shpDate     = DateTime.Now;

            //if (ModelState.IsValid == true)
            //{
            //    db.SaveChanges();
            //    return RedirectToAction("deliveryIndex");  //導向Index的Action方法
            //}
            db.SaveChanges();
            return(RedirectToAction("deliveryIndex"));  //導向Index的Action方法
        }
Пример #21
0
        /// <summary>
        /// 删除店铺类型
        /// </summary>
        /// <param name="_id">店铺类型编号</param>
        /// <returns>是否删除成功  true:删除成功,false:删除失败</returns>
        public static bool Delete(int _id)
        {
            //创建一个shopDBEntities对象
            shopDBEntities sde = new shopDBEntities();

            //删除
            sde.Entry(new StoreTypeInfo()
            {
                STI_ID = _id
            }).State = System.Data.EntityState.Deleted;

            //提交数据库
            int count = sde.SaveChanges();

            return(IsYes(count));
        }
Пример #22
0
        /// <summary>
        /// 修改商铺类型信息
        /// </summary>
        /// <param name="_id">店铺类型编号</param>
        /// <param name="_name">店铺类型名称</param>
        /// <param name="_remark">是否执行成功 true:成功,false:失败</param>
        public static bool Update(int _id, string _name, string _remark)
        {
            //创建一个shopDBEntities对象
            shopDBEntities sde = new shopDBEntities();

            //修改
            sde.Entry(new StoreTypeInfo()
            {
                STI_ID = _id, STI_Name = _name, STI_Remark = _remark
            }).State = System.Data.EntityState.Modified;

            //提交
            int count = sde.SaveChanges();

            //判断是否成功
            return(IsYes(count));
        }
Пример #23
0
        public ActionResult AddToMyCart(string spcID, int quantity = 1)
        {   //TODO:加入 請訪客登入
            //把memberID加入MBRID

            string mbrID = (string)Session["memberID"]; //利用SESSION存取

            if (mbrID is null)
            {
                string js = "alert('請先登入會員才可加入購物車')";
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(JavaScript(js));
            }


            Cart_OrderDetail cod;
            //檢查是否已經加入購物車
            var getCartItem = db.Cart_OrderDetail.Where(m => m.mbrID == mbrID)
                              .Where(m => m.spcID == spcID)
                              .Where(m => m.odrID == null);
            int inCartCount = getCartItem.Count();

            if (inCartCount > 0)
            {
                cod          = getCartItem.FirstOrDefault();
                cod.Quantity = quantity;
            }
            else
            {
                cod = new Cart_OrderDetail()
                {
                    cartID     = db.Database.SqlQuery <string>("Select dbo.GetCartID()").FirstOrDefault(),
                    mbrID      = mbrID,
                    Quantity   = quantity,
                    spcID      = spcID,
                    usedPoints = 0,
                    Discount   = 0,
                    pdtPrice   = 0,
                    shpID      = "shp0000001" //預設運送方式
                };
                db.Cart_OrderDetail.Add(cod);
            }

            try
            {
                db.SaveChanges();
                return(JavaScript("alert('成功新增至購物車')"));
            }
            catch (Exception e)
            {
                return(JavaScript($"alert('失敗了,請再嘗試一次')"));
            }
        }
Пример #24
0
        /// <summary>
        /// 添加店铺类型
        /// </summary>
        /// <param name="_name">店铺类型名称</param>
        /// <param name="_remark">店铺类型备注</param>
        /// <returns>是否添加成功 true:添加店铺类型成功,false:添加店铺类型失败</returns>
        public static bool Add(string _name, string _remark)
        {
            //创建一个shopDBEntities对象
            shopDBEntities sde = new shopDBEntities();

            //创建一个StoreType对象
            StoreTypeInfo sti = new StoreTypeInfo()
            {
                STI_Name = _name, STI_Remark = _remark
            };

            //添加
            sde.Entry(sti).State = System.Data.EntityState.Added;

            //提交数据库
            int count = sde.SaveChanges();

            //是否添加成功
            return(IsYes(count));
        }
        public ActionResult mbrEdit(Member m, HttpPostedFileBase Image)
        {
            if (Session["memberID"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }


            string fileName = "";

            if (Image != null)
            {
                if (Image.ContentLength > 0)
                {
                    fileName = m.mbrID + ".jpg";
                    Image.SaveAs(Server.MapPath("~/mbrPhoto/" + fileName));
                }
            }
            else
            {
                fileName = m.mbrImage;
            }


            var member = db.Member.Where(a => a.mbrID == m.mbrID).FirstOrDefault();

            member.mbrName   = m.mbrName;
            member.nickName  = m.nickName;
            member.mbrPhone  = m.mbrPhone;
            member.mbrMail   = m.mbrMail;
            member.birthDate = m.birthDate;
            member.mbrImage  = fileName;



            if (ModelState.IsValid)
            {
                db.SaveChanges();
                return(RedirectToAction("mbrIndex"));
            }

            else
            {
                return(View(m));
            }
        }
Пример #26
0
        /// <summary>
        /// 修改店铺信息
        /// </summary>
        /// <param name="_id">店铺编号</param>
        /// <param name="uid">店主编号</param>
        /// <param name="_tid">店铺类型编号</param>
        /// <param name="_name">店铺名称</param>
        /// <param name="_logo">店铺标志图片</param>
        /// <param name="_intro">店铺描述</param>
        /// <param name="remark">店铺备注</param>
        /// <returns>true:修改成功,false:修改失败</returns>
        public static bool Update(int _id, int uid, int _tid, string _name, string _logo, string _intro, string remark)
        {
            //创建一个店铺对象
            StoreInfo si = new StoreInfo()
            {
                SI_ID     = _id,
                SI_AI_ID  = uid,
                SI_STI_ID = _tid,
                SI_Logo   = _logo,
                SI_Name   = _name,
                SI_Intro  = _intro,
                SI_Remark = remark
            };

            //创建一个shopDBEntities对象
            shopDBEntities sde = new shopDBEntities();

            //修改
            sde.Entry(si).State = System.Data.EntityState.Modified;

            //提交
            return(IsYes(sde.SaveChanges()));
        }
Пример #27
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="goodsid">商品编号</param>
        /// <returns>首页路径</returns>
        public ActionResult Index_1_delete(string goodsid)
        {
            CommodityInfo commodity = new CommodityInfo();

            commodity.CI_ID = Convert.ToInt32(goodsid);

            shopDBEntities shop = new shopDBEntities();

            //shop.CommodityInfo.Remove(commodity);

            shop.Entry(commodity).State = System.Data.EntityState.Deleted;

            int count = shop.SaveChanges();

            if (count > 0)
            {
                return(RedirectToAction("Index_1", "Mindex"));
            }
            else
            {
                Response.Write("<script>alert('删除失败,请再次选择!!')</script>");
                return(RedirectToAction("Index_1", "Mindex"));
            }
        }
Пример #28
0
        public ActionResult Create(VM_pdtCreate product, Specification[] specification, HttpPostedFileBase[] photo, ProductImage[] image, ShipperDetail[] shipperDetail, Tag[] tag, string fstID, string sndID, string trdID)
        {
            ViewBag.fst           = new SelectList(db.FirstLayer, "fstLayerID", "fstLayer");
            ViewBag.shipperDetail = db.Shipper.ToList();
            if (photo[0] == null)
            {
                ModelState.AddModelError("Photo", "沒有封面圖片");
            }

            if (ModelState.IsValid != true)
            {
                return(View());
            }


            string id       = Session["memberID"].ToString();
            string getselID = db.Seller.Where(m => m.mbrID == id).FirstOrDefault().selID;

            var getctgID = db.ProductCategory.Where(m => m.fstLayerID == fstID && m.sndLayerID == sndID && m.trdLayerID == trdID).FirstOrDefault().pdtCtgID;



            string GetpdtID = db.Database.SqlQuery <string>("Select dbo.GetProductID()").FirstOrDefault();

            //傳入ProductVM(ViewModel)的products(ViewModel中的Product資料表)
            product.products.pdtID        = GetpdtID;
            product.products.selID        = getselID; //用Session["member"]查
            product.products.pdtDate      = DateTime.Now;
            product.products.Discontinued = false;
            product.products.ctgID        = getctgID; //擱置,資料表設計錯誤
            db.Product.Add(product.products);
            if (ModelState.IsValid == true)
            {
                db.SaveChanges();
            }

            //傳入規格資料表
            for (int i = 0; i < specification.Length; i++)
            {
                Specification spc = new Specification();
                spc.pdtID    = GetpdtID;
                spc.Style    = specification[i].Style;
                spc.Size     = specification[i].Size;
                spc.Stock    = specification[i].Stock;
                spc.Price    = specification[i].Price;
                spc.Discount = 1;
                string GetspcID = db.Database.SqlQuery <string>("Select dbo.GetSpecificationID()").FirstOrDefault();
                spc.spcID = GetspcID;



                db.Specification.Add(spc);
                if (ModelState.IsValid == true)
                {
                    db.SaveChanges();
                }
            }

            //傳入照片


            string fileName = "";

            for (int i = 0; i < photo.Length; i++)
            {
                ProductImage       img = new ProductImage();
                HttpPostedFileBase f   = (HttpPostedFileBase)photo[i];
                if (f != null)
                {
                    if (f.ContentLength > 0)
                    {
                        string GetpImgID = db.Database.SqlQuery <string>("Select dbo.GetpImgID()").FirstOrDefault();

                        fileName = GetpImgID + ".jpg";
                        f.SaveAs(Server.MapPath("~/productImage/" + fileName));
                        img.pImgID   = GetpImgID;
                        img.pdtID    = GetpdtID;
                        img.pdtImage = GetpImgID + ".jpg";

                        db.ProductImage.Add(img);
                        if (ModelState.IsValid == true)
                        {
                            db.SaveChanges();
                        }
                    }
                }
            }
            //選擇運費
            for (int i = 0; i < shipperDetail.Length; i++)
            {
                ShipperDetail shp = new ShipperDetail();
                shp.shpID           = shipperDetail[i].shpID;
                shp.pdtID           = GetpdtID;
                shp.defaultShipping = shipperDetail[i].defaultShipping;
                db.ShipperDetail.Add(shp);
                if (ModelState.IsValid == true)
                {
                    db.SaveChanges();
                }
            }

            //寫入tag
            for (int i = 0; i < tag.Length; i++)
            {
                Tag    tg       = new Tag();
                string GetTagID = db.Database.SqlQuery <string>("Select dbo.GetTagID()").FirstOrDefault();
                tg.tagID   = GetTagID;
                tg.tagName = tag[i].tagName;
                tg.pdtID   = GetpdtID;
                db.Tag.Add(tg);
                if (ModelState.IsValid == true)
                {
                    db.SaveChanges();
                }
            }



            //ViewBag.shp123 = new SelectList(db.Shipper, "shpID", "shpMethod");
            ViewBag.shipperDetail = db.Shipper.ToList();
            if (ModelState.IsValid == true)
            {
                return(RedirectToAction("myProduct", "SellerHome"));
            }

            return(View(product));
        }
Пример #29
0
        /// <summary>
        /// 处理信息录入
        /// </summary>
        /// <returns></returns>
        public ActionResult Register_Information2(AdministratorInfo admin)
        {
            shopDBEntities shop = new shopDBEntities();


            if (Session["Name"] == null || Session["Name"].ToString() == "")
            {
                AdministratorInfo admin2 = shop.AdministratorInfo.Where(a => a.AI_Name == admin.AI_Name).FirstOrDefault();

                if (admin2 != null)
                {
                    Response.Write("<script>alert('该用户名已被他人所用')</script>");
                    return(View("Register_Information"));
                }
            }
            //获取文件的完整路径
            string name = Request.Files[0].FileName;

            if (string.IsNullOrEmpty(name))
            {
                name = "a6.jpg";
            }
            //获取下标(.)
            int index = name.LastIndexOf(".");
            //截取字符串
            string behind = name.Substring(index + 1);

            //判断是否是满足图片格式
            if (behind.ToLower() != "gif" && behind.ToLower() != "png" && behind.ToLower() != "jpg" && behind.ToLower() != "ico")
            {
                Response.Write("<script>alert('文件格式不满足图片格式!!!')</script>");
                return(View("Register_Information"));
            }
            ////随机生成一段字符串
            //string filename = Guid.NewGuid().ToString();
            //生成完整路径(获取项目路经)
            string allname = Server.MapPath("~");

            //用 用户名作为头像的路径

            //图片另存为
            Request.Files[0].SaveAs(allname + "/Needs/head/" + admin.AI_Name + "." + behind);
            //根据用户输入的信息去完善用户数据库
            //(d第一步:先去获取要修改的用户(赋值))



            AdministratorInfo admininfo = shop.AdministratorInfo.Where(a => a.AI_LoginPwd == admin.AI_LoginPwd && a.AI_Num == admin.AI_Num).FirstOrDefault();

            admininfo.AI_Name   = admin.AI_Name;
            admininfo.AI_Sex    = admin.AI_Sex;
            admininfo.AI_Type   = admin.AI_Type;
            admininfo.AI_Date   = DateTime.Now;
            admininfo.AI_IDCard = admin.AI_IDCard;
            admininfo.AI_Alipay = admin.AI_Alipay;
            admininfo.AI_HImage = admin.AI_Name + "." + behind;

            int count = count = shop.SaveChanges();

            //try
            //{
            //    admininfo.AI_Name = admin.AI_Name;
            //    admininfo.AI_Sex = admin.AI_Sex;
            //    admininfo.AI_Type = admin.AI_Type;
            //    admininfo.AI_Date = DateTime.Now;
            //    admininfo.AI_IDCard = admin.AI_IDCard;
            //    admininfo.AI_Alipay = admin.AI_Alipay;
            //    admininfo.AI_HImage = filename + "." + behind;

            //    count = shop.SaveChanges();
            //}
            //catch (System.Data.Entity.Validation.DbEntityValidationException db)
            //{

            //    var msg = string.Empty;
            //    var errors = (from u in db.EntityValidationErrors select u.ValidationErrors).ToList();
            //    foreach (var item in errors)
            //        msg += item.FirstOrDefault().ErrorMessage;

            //}



            if (count > 0)
            {
                return(RedirectToAction("Index_1", "Mindex"));
            }
            else
            {
                Response.Write("对不起,信息录入失败??");

                return(View("Register_Information"));
            }
        }