public void Delete_Order(string orderid) { int count = 0; if (orderid.Contains(',')) { string[] str_id = orderid.Split(','); for (int i = 0; i < str_id.Length; i++) { int ids = Convert.ToInt32(str_id[i]); OrderFormInfo order = new OrderFormInfo() { OFI_ID = ids }; shop.Entry(order).State = System.Data.EntityState.Deleted; count = shop.SaveChanges(); } } else { int id = Convert.ToInt32(orderid); OrderFormInfo order = new OrderFormInfo() { OFI_ID = id }; shop.Entry(order).State = System.Data.EntityState.Deleted; count = shop.SaveChanges(); } Response.Write(count); }
public ActionResult Edit([Bind(Include = "actID,pdtID,actStrDate,actEndDate,actImage,actDisplay,admID")] actBulletin actBulletin, HttpPostedFileBase actImage) { string fileName = ""; if (actImage != null) { if (actImage.ContentLength > 0) { fileName = actBulletin.actID + ".jpg"; actImage.SaveAs(Server.MapPath("~/actImage/" + fileName)); actBulletin.actImage = fileName; } } if (actImage == null) { actBulletin.actImage = "act0000000.jpg"; } if (ModelState.IsValid) { db.Entry(actBulletin).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.admID = new SelectList(db.Adm, "admID", "admName", actBulletin.admID); return View(actBulletin); }
/// <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")); } }
/// <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")); } }
/// <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 = "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)); }
public ActionResult Edit([Bind(Include = "ntfContent,ntfCtgID,mbrID,ntfTitle,ntfTime,ntfID")] ntfRecord ntfRecord) { if (ModelState.IsValid) { db.Entry(ntfRecord).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.mbrID = new SelectList(db.Member, "mbrID", "mbrName", ntfRecord.mbrID); ViewBag.ntfCtgID = new SelectList(db.ntfCategory, "ntfCtgID", "ntfType", ntfRecord.ntfCtgID); return(View(ntfRecord)); }
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 = "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)); }
/// <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")); } }
public ActionResult GoodsTypeDelete(string needID) { //获取最后一个下标 int index = needID.LastIndexOf(","); string newID = needID.Substring(0, index); string[] StrID = newID.Split(','); int count = 0; for (int i = 0; i < StrID.Length; i++) { int id = Convert.ToInt32(StrID[i]); List <CommodityInfo> Glist = shop.CommodityInfo.Where(a => a.CI_CTI_ID == id).ToList(); if (Glist.Count > 0) { string ErrorMsg = "该类里面存在商品,所以不能删除"; if (Session["ErrorMsg"] != null) { Session["ErrorMsg"] = null; } Session["ErrorMsg"] = ErrorMsg; return(RedirectToAction("GoodsTypeError", "GoodsType")); } CommodityTypeInfo comm = new CommodityTypeInfo(); comm.CTI_ID = id; shop.Entry(comm).State = System.Data.EntityState.Deleted; } 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")); } }
/// <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 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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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())); }
/// <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")); } }
public ActionResult receiveOrder(string[] cartID, string[] shipSelect, string[] quantity, Order order) //提交訂單 { var cod = db.Cart_OrderDetail; string memberID = Session["memberID"] as string; List <Cart_OrderDetail> m = (from p in cod where p.mbrID == memberID where p.odrID == null orderby p.Specification.Product.selID select p).ToList(); List <string> sellerIDList = m.Where(sItem => cartID.Contains(sItem.cartID)).Select(s => s.Specification.Product.selID).Distinct().ToList(); //if (ModelState.IsValid != true) //{ // return View("myCart"); //} using (var transaction = db.Database.BeginTransaction()) { //初始化訂單 order.traceNumber = ""; //物流單號 為not NULL 欄位 在此隨便填 order.pmtID = "pmt0000001"; //付款方式 order.odrStatusID = "ods0000001"; //訂單狀態 order.odrDate = DateTime.Now; //訂單成立時間 order.shpPrice = 100; order.traceNumber = "123456"; order.recPhone = "0911-111-111"; foreach (var sellerID in sellerIDList) { order.selID = sellerID; order.odrID = db.Database.SqlQuery <string>("Select dbo.GetOrderID()").FirstOrDefault(); try { db.Order.Add(order); db.SaveChanges(); db.Entry(order).State = EntityState.Detached; } catch (Exception d) { transaction.Rollback(); return(JavaScript($"alert('失敗了,請再嘗試一次')")); } } //寫入COD資料 string orderID = ""; for (int i = 0; i < cartID.Length; i++) //依據傳入的cartID[]條件 加入cart { if (cartID[i] != "false") { Cart_OrderDetail currentCart = m[i]; orderID = currentCart.Specification.Product.selID; string selectedShipMethod = shipSelect[i]; string SelID = currentCart.Specification.Product.selID; currentCart.odrID = db.Order.Where(od => od.selID == SelID).ToList().LastOrDefault().odrID; currentCart.shpID = db.Shipper.Where(t => t.shpMethod == selectedShipMethod).FirstOrDefault().shpID; currentCart.pdtPrice = currentCart.Specification.Price; //取得商品時價 currentCart.Discount = currentCart.Specification.Discount; //取得商品當時打折 //庫存減去商品下單數 if ((currentCart.Specification.Stock - currentCart.Quantity) >= 0) { currentCart.Specification.Stock -= currentCart.Quantity; } else { return(JavaScript("alert('下單量大於庫存囉')")); } } } try { db.SaveChanges(); } catch (DbUpdateException e) { transaction.Rollback(); return(JavaScript($"alert({e.Entries})")); } ///更新ORDER 運費 var odr = db.Order.Where(o => o.shpPrice == null).ToList(); string shpID; foreach (var oItem in odr) { shpID = db.Cart_OrderDetail.Where(c => c.odrID == oItem.odrID).FirstOrDefault().shpID; oItem.shpPrice = db.ShipperDetail.Where(p => p.shpID == shpID).FirstOrDefault().defaultShipping; } try { db.SaveChanges(); transaction.Commit(); return(RedirectToAction("MyCart")); } catch (DbUpdateException e) { transaction.Rollback(); return(JavaScript($"alert('失敗了,請再嘗試一次')")); } } }