示例#1
0
    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);
    }
示例#2
0
        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();
        }
示例#3
0
文件: SqlShopCar.cs 项目: wdy1/XueHai
        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);
        }
示例#4
0
 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());
        }
示例#6
0
        // 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();
        }
示例#7
0
    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();
    }
示例#8
0
    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();
    }
示例#9
0
    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();
    }
示例#10
0
    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);
    }
示例#11
0
 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"));
 }
示例#12
0
 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);
     }
 }
示例#13
0
        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());
        }
示例#15
0
        public ShopCar whereShopcarById(string uid, int gid)
        {
            ShopCar shopcar = ishopcar.whereShopcarById(uid, gid);

            return(shopcar);
        }
示例#16
0
 public OrdersRepository(AppDbContent appDbContent, ShopCar shopCar)
 {
     this.appDbContent = appDbContent;
     this.shopCar      = shopCar;
 }
示例#17
0
 public OrderController(IAllAlders allorder, ShopCar shopCar)
 {
     this.allorder = allorder;
     this.shopCar  = shopCar;
 }
示例#18
0
文件: SqlShopCar.cs 项目: wdy1/XueHai
 public void UpdateShopcarCount(ShopCar shopCar)
 {
     db.Entry(shopCar).State = EntityState.Modified;
     db.SaveChanges();
 }
示例#19
0
 public void TestTimeDelay()
 {
     ShopCar.GetTotalPrice();
 }
示例#20
0
文件: SqlShopCar.cs 项目: wdy1/XueHai
 public void AddShopCar(ShopCar shopcar)
 {
     db.ShopCar.Add(shopcar);
     db.SaveChanges();
 }
示例#21
0
        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>"));
                    }
                }
            }
        }
示例#22
0
        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));
                }
            }
        }
示例#23
0
 private void UpdateTotalPriceLabel()
 {
     totalPrice = ShopCar.GetTotalPrice();
     this.lblTotalPriceOrder.Text = totalPrice.ToString();
 }
示例#24
0
 public void UpdateShopcarCount(ShopCar shopCar)
 {
     ishopcar.UpdateShopcarCount(shopCar);
 }
示例#25
0
 public void AddShopCar(ShopCar shopcar)
 {
     ishopcar.AddShopCar(shopcar);
 }
 public ShopCarController(IAllCars Carrep, ShopCar shopCar)
 {
     _Carrep = Carrep; _shopCar = shopCar;
 }