public static ShopCar getShopCarByShopCarId(int shopcarid) { ShopCar shopcar = new ShopCar(); string sql = "select * from shopcar where id=?shopcarid"; MySqlConnection con = new MySqlConnection(Config_MySql.sqlUrl); con.Open(); MySqlCommand comm = new MySqlCommand(sql, con); comm.Parameters.Add(new MySqlParameter("?shopcarid", shopcarid)); MySqlDataReader rdr = comm.ExecuteReader(); while (rdr.Read()) { shopcar.UserId = rdr.GetInt32("userid"); shopcar.GoodId = rdr.GetInt32("goodid"); shopcar.BuyTime = rdr.GetInt32("buytime"); shopcar.good = GoodService.GetGoodMsg(shopcar.GoodId); } comm.Clone(); con.Close(); return(shopcar); }
static void Main(string[] args) { List <Product> products = Resources.GetProducts(); #region 第一種狀況測試 ShopCar shopCars1 = Resources.GetShopCarsBySituation(1); double resultShopCar1FromOriginalProject = Resources.CalculatePrice(ref shopCars1, ref products); double resultShopCar1 = 3023.6; bool result1 = (resultShopCar1 == Math.Round(resultShopCar1FromOriginalProject, 2, MidpointRounding.AwayFromZero)); Console.WriteLine(string.Format("第一種狀況測試結果: {0}", result1)); #endregion #region 第二種狀況測試 ShopCar shopCars2 = Resources.GetShopCarsBySituation(2); double resultShopCar2FromOriginalProject = Resources.CalculatePrice(ref shopCars2, ref products); double resultShopCar2 = 43.54; bool result2 = (resultShopCar2 == Math.Round(resultShopCar2FromOriginalProject, 2, MidpointRounding.AwayFromZero)); Console.WriteLine(string.Format("第二種狀況測試結果: {0}", result2)); #endregion //console 視窗不會關閉 Console.ReadLine(); }
public ShopCar whereShopcarById(int uid, int gid) { ShopCar shopcar = db.ShopCar.Where(c => c.Users_id == uid) .Where(c => c.Goods_id == gid).FirstOrDefault(); return(shopcar); }
private void btnResetCar_Click(object sender, EventArgs e) { if (ShopCar.ShopCarProductsList.Count > 0) { ShopCar.RemoveAllItemsFromShopCar(); UpdateDataGridViewCarAddress(); UpdateTotalPriceLabel(); } }
public ActionResult AddCar(int GoodId) { ShopCar shopCar = new ShopCar() { GoodID = GoodId }; db.ShopCar.Add(shopCar); db.SaveChanges(); return(View()); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 //регистрация различных модулей, плагинов public void ConfigureServices(IServiceCollection services) { //получение подключения из файла services.AddDbContext <AppDbContent>(options => options.UseSqlServer(_confstring.GetConnectionString("DefaultConnection"))); //обьеденить интерфейс и класс который реализует интерфейс services.AddTransient <IAllCars, CarsRepository>(); services.AddTransient <ICarsCategory, CategoryRepository>(); services.AddTransient <IAllAlders, OrdersRepository>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //работа с сессиями services.AddScoped(sp => ShopCar.GetCar(sp)); //для каждого разная корзина services.AddMvc(options => options.EnableEndpointRouting = false); //регистрация основного плагина services.AddMemoryCache(); services.AddSession(); }
public static void deleteShopCar(int shopcarid) { ShopCar shopcar = new ShopCar(); MySqlConnection con = new MySqlConnection(Config_MySql.sqlUrl); con.Open(); string sql = "delete from shopcar where id=?shopcarid"; MySqlCommand comm = new MySqlCommand(sql, con); comm.Parameters.Add(new MySqlParameter("?shopcarid", shopcarid)); comm.ExecuteNonQuery(); comm.Clone(); con.Close(); }
public static void updateShopCar(int shopcarid, int userid, int buytime) { ShopCar shopcar = null; MySqlConnection con = new MySqlConnection(Config_MySql.sqlUrl); con.Open(); string sql = "update shopcar set buytime=?buytime where id=?shopcarid and userid=?userid"; MySqlCommand comm = new MySqlCommand(sql, con); comm.Parameters.Add(new MySqlParameter("?userid", userid)); comm.Parameters.Add(new MySqlParameter("?shopcarid", shopcarid)); comm.Parameters.Add(new MySqlParameter("?buytime", buytime)); comm.ExecuteNonQuery(); comm.Clone(); con.Close(); }
public static void addShopCar(int userid, int goodid, int buytime) { ShopCar shopcar = new ShopCar(); MySqlConnection con = new MySqlConnection(Config_MySql.sqlUrl); con.Open(); string sql = "insert into shopcar(userid,goodid,buytime)values(@userid,@goodid,@buytime)"; MySqlCommand comm = new MySqlCommand(sql, con); comm.Parameters.Add(new MySqlParameter("@userid", userid)); comm.Parameters.Add(new MySqlParameter("@goodid", goodid)); comm.Parameters.Add(new MySqlParameter("@buytime", buytime)); comm.ExecuteNonQuery(); comm.Clone(); con.Close(); }
public ShopCar updateShopCar() { int shopid_temp = int.Parse(Request.QueryString["shopid"].ToString()); int buytime_temp = int.Parse(Request.Params["time"]); //获取用户id int userid; userid = UserService.getUserIdByPhone(getUserName()); if (userid == 0) { userid = UserService.getUserIdByEmail(getUserName()); } ShopCarService.updateShopCar(shopid_temp, userid, buytime_temp); shopcar = ShopCarService.getShopCarByShopCarId(shopid_temp); return(shopcar); }
public ActionResult AddShop(int?id, int?count) { if (id.HasValue) { if (Request.Cookies["CustomerID"] != null) { //先把数据加载到购物车中,再从购物车数据表中显示数据 ShopCar shop = new ShopCar(); shop.CustomerID = int.Parse(Request.Cookies["CustomerID"].Value); shop.ProperID = id; shop.Quantity = count; shop.CreateTime = DateTime.Now; db.ShopCars.Add(shop); db.SaveChanges(); } } return(RedirectToAction("ShopCar")); }
private void ProccessOrderHandler() { try { if (ShopCar.ShopCarProductsList.Count > 0) { CreateOrder(); ShopCar.RemoveAllItemsFromShopCar(); } else { MessageBox.Show("Tu carrito esta vacío!", "Carrito vacío", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public ActionResult upshop(ShopCar info) { var shop = new ShopCarManager().GetEntitysWhereAsNoTracking(x => x.Id == info.Id).FirstOrDefault(); shop.CarNum = info.CarNum; if (new ShopCarManager().Update(shop)) { var info1 = new { msg = "1000" }; return(Json(info1, JsonRequestBehavior.AllowGet)); } else { var info1 = new { msg = "1001" }; return(Json(info1, JsonRequestBehavior.AllowGet)); } }
//我的订单页面 //信息填写页面 public ActionResult WriteInfo() { //拿到传过来的购物车ID得到购买了哪些商品 string ids = Request.Cookies["ids"].Value; if (ids != null) { string[] id = ids.Split('|'); ViewBag.count = id.Length - 1; //总共有多少件 List <OrderCC> myList = new List <OrderCC>(); foreach (string item in id) { if (item != "") { int carid = int.Parse(item); ShopCar cc = db.ShopCars.Where(x => x.Id == carid).First(); ProductProperty pp = db.ProductProperties.Where(x => x.ProperID == cc.ProperID).First(); ProductType pt = db.ProductTypes.Where(x => x.TypeID == pp.TypeID).First(); Product pd = db.Products.Where(x => x.ProductID == pt.ProductID).First(); //需要做显示的字段存起来 OrderCC oc = new OrderCC() { IMG = pp.IMG, TypeName = pt.TypeName, ProName = pp.ProperName, Price = pp.Price.ToString(), Count = cc.Quantity.ToString(), Postage = pd.Postage.ToString() }; myList.Add(oc); } } ViewBag.orderShop = myList.AsEnumerable(); } return(View()); }
public ShopCar whereShopcarById(string uid, int gid) { ShopCar shopcar = ishopcar.whereShopcarById(uid, gid); return(shopcar); }
public OrdersRepository(AppDbContent appDbContent, ShopCar shopCar) { this.appDbContent = appDbContent; this.shopCar = shopCar; }
public OrderController(IAllAlders allorder, ShopCar shopCar) { this.allorder = allorder; this.shopCar = shopCar; }
public void UpdateShopcarCount(ShopCar shopCar) { db.Entry(shopCar).State = EntityState.Modified; db.SaveChanges(); }
public void TestTimeDelay() { ShopCar.GetTotalPrice(); }
public void AddShopCar(ShopCar shopcar) { db.ShopCar.Add(shopcar); db.SaveChanges(); }
public ActionResult jrgwc([Bind(Include = "Goods_id,Count,Price,Users_id,note,Time,flag")] ShopCar shopCar) { string name = Request.Form["ljgm"]; shopCar.Users_id = (int)Session["Users_id"];/*int.Parse(Session["Users_id"].ToString())*/ var nowcount = shopCar.Count; var nowgoodsid = (int)shopCar.Goods_id; var a = shopcarmanager.CountShopcarById(shopCar.Users_id, shopCar.Goods_id); var b = shopcarmanager.CountShopcarCountById(shopCar.Users_id, shopCar.Goods_id); var beforecount = shopcarmanager.beforeCount(shopCar.Users_id, shopCar.Goods_id); if (a == 1) { //先查询出拿一条数据,再赋值 var beforeshopcar = shopcarmanager.whereShopcarById(shopCar.Users_id, nowgoodsid); beforeshopcar.Goods_id = nowgoodsid; beforeshopcar.Users_id = (int)Session["Users_id"]; /*Session["Users_id"].ToString();*/ beforeshopcar.Count = nowcount + beforecount; beforeshopcar.note = ""; beforeshopcar.Time = System.DateTime.Now; beforeshopcar.flag = 0; shopcarmanager.UpdateShopcarCount(beforeshopcar); if (name == "1") { return(RedirectToAction("Shopcar", "Mall")); } else { if (b == 1) { return(Content("<script>;alert('添加成功!');history.go(-1)</script>")); } else { return(Content("<script>;alert('添加失败!');history.go(-1)</script>")); } } } else { shopCar.Users_id = (int)Session["Users_id"]; shopCar.note = ""; shopCar.Time = System.DateTime.Now; shopCar.flag = 0; shopcarmanager.AddShopCar(shopCar); if (name == "1") { return(RedirectToAction("Shopcar", "Mall")); } else { var c = shopcarmanager.CountShopcarById(shopCar.Users_id, shopCar.Goods_id); if (c == 1) { return(Content("<script>;alert('加入购物车成功!');history.go(-1)</script>")); } else { return(Content("<script>;alert('加入购物车失败!');history.go(-1)</script>")); } } } }
public ActionResult insert(int num, int comid) { var us = Session["USER"] as User; if (us == null) { var info = new { bm = "1005", url = "/LoginReg/LoginReg/LoginIndex" }; return(Json(info, JsonRequestBehavior.AllowGet)); } var list = new ShopCarManager().GetEntitysWhereAsNoTracking(x => x.ComId == comid & x.UserId == us.Id); ShopCar sc = list.FirstOrDefault(); if (list.Count == 0) { sc = new ShopCar() { UserId = us.Id, CarNum = num, ComId = comid }; /*var kc = new ComManager().GetEntitysWhereAsNoTracking(x => x.Id == comid).FirstOrDefault(); * if (num > kc.ComInventNum) * { * var info1 = new * { * bm = "1002",//库存不足 * msg = "库存不够" * }; * return Json(info1, JsonRequestBehavior.AllowGet); * }*/ var result = new ShopCarManager().Insert(sc); if (result) { var info = new { bm = "1001", msg = "加入成功" }; return(Json(info, JsonRequestBehavior.AllowGet)); } else { var info = new { bm = "1000", msg = "加入失败" }; return(Json(info, JsonRequestBehavior.AllowGet)); } } else { sc.CarNum += num; /*var kc = new ComManager().GetEntitysWhereAsNoTracking(x => x.Id == comid).FirstOrDefault(); * if (sc.CarNum > kc.ComInventNum) * { * var info1 = new * { * bm = "1002",//库存不足 * msg = "库存不够" * }; * return Json(info1, JsonRequestBehavior.AllowGet); * }*/ var res = new ShopCarManager().Update(sc); if (res) { var info = new { bm = "1001", msg = "加入成功" }; return(Json(info, JsonRequestBehavior.AllowGet)); } else { var info = new { bm = "1000", msg = "加入失败" }; return(Json(info, JsonRequestBehavior.AllowGet)); } } }
private void UpdateTotalPriceLabel() { totalPrice = ShopCar.GetTotalPrice(); this.lblTotalPriceOrder.Text = totalPrice.ToString(); }
public void UpdateShopcarCount(ShopCar shopCar) { ishopcar.UpdateShopcarCount(shopCar); }
public void AddShopCar(ShopCar shopcar) { ishopcar.AddShopCar(shopcar); }
public ShopCarController(IAllCars Carrep, ShopCar shopCar) { _Carrep = Carrep; _shopCar = shopCar; }