示例#1
0
 public void Set()
 {
     try
     {
         var data    = new PriceAll();
         var client  = new WebClient();
         var content = client.DownloadString("https://api.coinmarketcap.com/v1/ticker/raiblocks");
         var jsonXRB = JsonConvert.DeserializeObject <List <PriceXRB> >(content);
         if (jsonXRB != null)
         {
             data.PriceXRB = (float)Math.Round(float.Parse(jsonXRB[0].price_usd) * 20000, 0);
         }
         content = client.DownloadString("https://api.coinmarketcap.com/v1/ticker/bitcoin/");
         var jsonBTC = JsonConvert.DeserializeObject <List <PriceBTC> >(content);
         if (jsonBTC != null)
         {
             data.PriceBTC = (float)Math.Round(float.Parse(jsonBTC[0].price_usd) * 22000, 0);
         }
         data.PriceUSD = 20000;
         //luu gia vao database
         var config = _configServices.GetConfig();
         if (config.GiaXRB != data.PriceXRB || config.GiaBTC != data.PriceBTC)
         {
             config.GiaXRB = data.PriceXRB - 100;
             config.GiaBTC = data.PriceBTC;
             _configServices.UpdateConfig(config);
         }
     }
     catch (Exception)
     {
     }
 }
示例#2
0
        private string AddPriceAll(PriceAll priceAll)
        {
            string stPriceAll = name.PriceAllBeginning + "\n";

            stPriceAll += name.PriceAll + priceAll.Price + "\n";
            stPriceAll += name.Date + priceAll.Date + "\n";
            stPriceAll += name.Comments + priceAll.Comments + "\n";
            stPriceAll += name.PriceAllEnd + "\n";
            return(stPriceAll);
        }
示例#3
0
        private void AddPriceAll(string order, PriceAll priceAll)
        {
            int    idexEnd             = order.IndexOf(name.PriceAllEnd);
            string stPriceAll          = order.Substring(0, idexEnd);
            int    indexComments       = stPriceAll.IndexOf(name.Comments) + name.Comments.Length;
            int    indexCommentsRemove = stPriceAll.IndexOf(name.Comments);
            int    indexData           = stPriceAll.IndexOf(name.Date) + name.Date.Length;
            int    indexDataRemove     = stPriceAll.IndexOf(name.Date);
            int    indexPriceAll       = stPriceAll.IndexOf(name.PriceAll) + name.PriceAll.Length;

            priceAll.Comments = RemoveWhiteChar(stPriceAll.Substring(indexComments));
            stPriceAll        = RemoveWorkAndTextToEnd(stPriceAll, indexCommentsRemove);
            priceAll.Date     = RemoveWhiteChar(stPriceAll.Substring(indexData));
            stPriceAll        = RemoveWorkAndTextToEnd(stPriceAll, indexDataRemove);
            priceAll.Price    = RemoveWhiteChar(stPriceAll.Substring(indexPriceAll));
        }
示例#4
0
        public void TestSaveOrder()
        {
            TCreateTabeles createSql = new TCreateTabeles();

            createSql.CreateSQLiteTables();
            TInsertAndQuestionSQL sql = new TInsertAndQuestionSQL();

            sql.RemoveAllTask();

            ListOfDishes listOfDishes = new ListOfDishes();

            List <Dish> lPizza = listOfDishes.LoadListPizza();
            PriceAll    price  = new PriceAll
            {
                Comments = "hhhhh",
                Date     = "24.03.2020",
                Price    = "120"
            };


            Order order = new Order
            {
                PriceAll   = price,
                ListDishes = lPizza
            };

            TSave save = new TSave();

            save.SaveOrder(TSave.ChoiceSaveOrder.Sql, order);

            TLoadOrder   load   = new TLoadOrder();
            List <Order> lOrder = load.LoadOrderList(TLoadOrder.ChoiceLoadOrder.Sql);

            Assert.AreEqual(order.ListDishes[0].Name, name.Margh);

            Assert.AreEqual(order.PriceAll.Comments, lOrder[0].PriceAll.Comments);
            Assert.AreEqual(order.PriceAll.Date, lOrder[0].PriceAll.Date);
            Assert.AreEqual(order.PriceAll.Price, lOrder[0].PriceAll.Price);

            Assert.AreEqual(order.ListDishes[0].Name, lOrder[0].ListDishes[0].Name);
            Assert.AreEqual(order.ListDishes[0].Price, lOrder[0].ListDishes[0].Price);

            Assert.AreEqual(order.ListDishes[0].SidesDishes, lOrder[0].ListDishes[0].SidesDishes);
        }
示例#5
0
        private void AddNewTaskOrder(Order order)
        {
            PriceAll priceAll = order.PriceAll;

            FindingMaxIdCena(priceAll);
            SQLiteConnection cn = CreateSQLiteConnection();

            using (cn)
            {
                cn.Open();

                string sql = "INSERT INTO " + name.PriceAll + "(" + name.Id + ", " + name.Price + ", " + name.Date + ", " + name.Comments + ") VALUES(@param1, @param2, @param3, @param4)";

                SQLiteParameter param1 = new SQLiteParameter("param1", DbType.Int64);
                SQLiteParameter param2 = new SQLiteParameter("param2", DbType.String);
                SQLiteParameter param3 = new SQLiteParameter("param3", DbType.String);
                SQLiteParameter param4 = new SQLiteParameter("param4", DbType.String);

                SQLiteCommand cmd = new SQLiteCommand(sql, cn);
                cmd.Parameters.Add(param1);
                cmd.Parameters.Add(param2);
                cmd.Parameters.Add(param3);
                cmd.Parameters.Add(param4);


                param1.Value = order.PriceAll.ID;
                param2.Value = order.PriceAll.Price;
                param3.Value = order.PriceAll.Date;
                param4.Value = order.PriceAll.Comments;

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Console.WriteLine("bład przy dodawaniu zamownienia \n" + e);
                }
                cn.Close();
                AddNewTaskDish(order);
            }
        }
示例#6
0
        private void AddNewTaskDish(Order order)
        {
            SQLiteConnection cn = CreateSQLiteConnection();

            using (cn)
            {
                List <Dish> listaDania = order.ListDishes;
                PriceAll    cena       = order.PriceAll;
                cn.Open();
                foreach (var dania in listaDania)
                {
                    string sql = "INSERT INTO " + name.Dishes + "(" + name.IdPrice + ", " + name.Dish + ", " + name.Price + ", " + name.SidesDishes + ") VALUES(@param1, @param2, @param3, @param4)";

                    SQLiteParameter param1 = new SQLiteParameter("param1", DbType.String);
                    SQLiteParameter param2 = new SQLiteParameter("param2", DbType.String);
                    SQLiteParameter param3 = new SQLiteParameter("param3", DbType.String);
                    SQLiteParameter param4 = new SQLiteParameter("param4", DbType.String);


                    SQLiteCommand cmd = new SQLiteCommand(sql, cn);
                    cmd.Parameters.Add(param1);
                    cmd.Parameters.Add(param2);
                    cmd.Parameters.Add(param3);
                    cmd.Parameters.Add(param4);

                    param1.Value = order.PriceAll.ID;
                    param2.Value = dania.Name;
                    param3.Value = dania.Price;
                    param4.Value = dania.SidesDishes;

                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("bład AddNewTaskDania\n" + e);
                    }
                }
                cn.Close();
            }
        }
示例#7
0
        private void FindingMaxIdCena(PriceAll cena)
        {
            SQLiteConnection cn;

            using (cn = new SQLiteConnection(strConnection))
            {
                string findingMaxIdPrice = "SELECT  MAX(id) FROM " + name.PriceAll;

                try
                {
                    using (SQLiteCommand cmd = new SQLiteCommand(findingMaxIdPrice, cn))
                    {
                        cn.Open();
                        SQLiteDataReader dr = cmd.ExecuteReader();
                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                //Did not close the connection, in the case of an epty table
                                try
                                {
                                    cena.ID = Convert.ToInt64(dr[0]);
                                }
                                catch
                                {
                                    dr.Close();
                                }
                            }
                            dr.Close();
                            cena.ID++;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    cena.ID = 1;
                    cn.Close();
                }
                cn.Close();
            }
        }
示例#8
0
 private void AddOrdersToListOrders(SQLiteDataReader dr, List <Order> listorder)
 {
     while (dr.Read())
     {
         try
         {
             Order    order = new Order();
             PriceAll price = new PriceAll
             {
                 ID       = Convert.ToInt64(dr[0]),
                 Price    = Convert.ToString(dr[1]),
                 Date     = Convert.ToString(dr[2]),
                 Comments = Convert.ToString(dr[3])
             };
             order.PriceAll = price;
             order          = LoadDishes(Convert.ToString(price.ID), order);
             listorder.Add(order);
         }
         catch
         {
             dr.Close();
         }
     }
 }
示例#9
0
        public HttpResponseMessage ToReservePayPage(ToReservePayPage req)
        {
            var   userId   = Convert.ToInt32(req.userId);
            var   tokenStr = req.Token;
            Token token    = CacheHelper.GetUserToken(tokenStr);

            if (token == null)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token失效"));
            }
            if (token.Payload.UserID != userId)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token错误"));
            }

            ReserveOrderRes res = new ReserveOrderRes();

            var foodId = Convert.ToInt32(req.foodId);
            var amount = Convert.ToInt32(req.amount);

            //获取最近使用过的地址
            var list_addr = UserAddressOper.Instance.GetRecentlyAddr(userId);

            if (list_addr.Count < 1)
            {
                res.userAddress = null;
            }
            else
            {
                res.userAddress = new UserAddressForOrderRes(list_addr.First());
            }

            var user    = UserInfoOper.Instance.GetById(userId);//获取用户信息
            var balance = (decimal)user.userBalance;
            var coupon  = (decimal)user.coupon;

            var           listFoods = new List <foodId_Amount>();
            foodId_Amount fa1       = new foodId_Amount(foodId, amount);

            listFoods.Add(fa1);

            var listWeekNotMainFoods = FoodInfoOper.Instance.GetReserveNotMainFood();

            if (listWeekNotMainFoods.Count > 0)
            {
                foreach (var item in listWeekNotMainFoods)
                {
                    foodId_Amount fa = new foodId_Amount(item.id, 0);
                    listFoods.Add(fa);
                }
            }
            var fd         = FoodInfoOper.Instance.GetFoodPriceAndDeposit(listFoods);
            var deposit    = fd.deposit;
            var foodsPrice = fd.price;

            //var sumMoney = foodsPrice + deposit;
            var priceRes = ControllerHelper.Instance.GetThreePriceWithDeposit(balance, coupon, foodsPrice, deposit);

            res.balance = balance.ToString();
            res.coupon  = coupon.ToString();
            PriceAll pa = new PriceAll();

            pa.payMoney  = priceRes.payMoney.ToString();
            pa.price     = (priceRes.payMoney + priceRes.useBalance).ToString();
            res.priceAll = pa;

            res.listFoods = FoodInfoOper.Instance.GetFoodINAPI(listFoods);

            res.deposit = deposit.ToString();

            res.isUseBalance = balance <= 0 ? false : true;
            res.isUseCoupon  = coupon <= 0 ? false : true;

            return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(res), ""));
        }
示例#10
0
        public HttpResponseMessage ToPayPage(ToPayPageReq req)
        {
            OrderRes res      = new OrderRes();
            var      userId   = Convert.ToInt32(req.userId);
            var      tokenStr = req.Token;

            Token token = CacheHelper.GetUserToken(tokenStr);

            if (token == null)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token失效"));
            }
            if (token.Payload.UserID != userId)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token错误"));
            }

            var areaId = Convert.ToInt32(req.areaId);
            List <RiderStockJoin> listRs = RiderStockOper.Instance.GetRSJoinByAreaId(areaId);

            var foodIdsInArea = listRs.Select(p => p.foodId).Distinct().ToArray();//区域内存在的菜品的id
            var list_foods    = new List <foodId_Amount>();
            var listafa       = CacheHelper.GetTempFoods2(userId);

            listafa = listafa.Where(p => p.areaId == areaId).ToList();//-txy
            foreach (var item in listafa)
            {
                foodId_Amount fa = new foodId_Amount();
                fa.amount = item.amount;
                fa.foodId = item.foodId;
                list_foods.Add(fa);
            }

            #region 根据库存调整菜品数量
            //点过的菜,不属于区域内的去掉
            list_foods = list_foods.Where(p => foodIdsInArea.Contains(p.foodId)).ToList();

            var listTempFoods = new List <foodId_Amount>();
            foreach (var item in list_foods)
            {
                var rsAmount = listRs.Where(p => p.foodId == item.foodId).ToList().Sum(p => p.amount);
                item.amount = item.amount > rsAmount ? (int)rsAmount : item.amount;
                listTempFoods.Add(item);
            }
            #endregion

            var list_addr = UserAddressOper.Instance.GetRecentlyAddr(userId);
            if (list_addr.Count < 1)
            {
                res.userAddress = null;
            }
            else
            {
                res.userAddress = new UserAddressForOrderRes(list_addr.First());
            }

            var user    = UserInfoOper.Instance.GetById(userId);//获取用户信息
            var balance = (decimal)user.userBalance;
            var coupon  = (decimal)user.coupon;

            var ids = listTempFoods.Select(p => p.foodId).ToArray();

            var tempList = CacheHelper.GetByIds <FoodView>("foodView", ids);

            var f_d        = FoodInfoOper.Instance.GetFoodPriceAndDeposit(listTempFoods);
            var deposit    = f_d.deposit;
            var foodsPrice = f_d.price;
            var priceRes   = ControllerHelper.Instance.GetThreePriceWithDeposit(balance, coupon, foodsPrice, deposit);

            res.balance = balance.ToString();
            res.coupon  = coupon.ToString();
            PriceAll pa = new PriceAll();
            pa.payMoney  = priceRes.payMoney.ToString();
            pa.price     = (priceRes.payMoney + priceRes.useBalance).ToString();
            res.priceAll = pa;

            List <foodId_name_amount_price_isMain> foodListRes = new List <foodId_name_amount_price_isMain>();
            foreach (var item in tempList)
            {
                foodId_name_amount_price_isMain a = new foodId_name_amount_price_isMain(item);
                foodListRes.Add(a);
            }

            foreach (var item in listTempFoods)
            {
                foodListRes.Where(p => p.foodId == item.foodId).FirstOrDefault().amount = item.amount;
            }

            var list = RiderStockOper.Instance.GetStockNotMain(areaId);

            var extraFoodIdList = list.OrderByDescending(p => p.id).GroupBy(p => new { p.foodId, p.foodName, p.foodPrice }).Select(g => new foodId_name_amount_price_isMain
            {
                foodId    = (int)g.Key.foodId,
                foodName  = g.Key.foodName,
                foodPrice = g.Key.foodPrice.ToString(),
                amount    = 0,
                isMain    = false
            }).ToList();
            foreach (var item in extraFoodIdList)
            {
                foodListRes.Add(item);
            }

            res.listFoods = foodListRes.OrderByDescending(p => p.foodId).ToList();

            res.isUseBalance = balance <= 0 ? false : true;
            res.isUseCoupon  = coupon <= 0 ? false : true;
            res.deposit      = deposit.ToString();
            return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(res), ""));
        }
示例#11
0
        public void TestMessagePizzaAll()
        {
            PriceAll priceAll = new PriceAll()
            {
                Price    = "275zł",
                Comments = "",
                Date     = "2020-07-07 21:03:37"
            };


            Pizza.Dish pizza = new Pizza.Dish
            {
                Name  = name.Margh,
                Price = "20zł"
            };

            Pizza.Dish pizzaSide1 = new Pizza.Dish
            {
                Name        = name.VegetPrice,
                SidesDishes = Sides(name.DoubelCheesePrice),
                Price       = "24zł"
            };

            Pizza.Dish pizzaSide2 = new Pizza.Dish
            {
                Name        = name.ToscaPrice,
                SidesDishes = Sides(name.DoubelCheesePrice, name.SalamiPrice),
                Price       = "29zł"
            };

            Pizza.Dish pizzaSide3 = new Pizza.Dish
            {
                Name        = name.VenecPrice,
                SidesDishes = Sides(name.SalamiPrice, name.HamPrice, name.MushroomsPrice),
                Price       = "31zł"
            };

            Dish pizzaSide4 = new Pizza.Dish
            {
                Name        = name.VenecPrice,
                SidesDishes = Sides(name.DoubelCheesePrice, name.SalamiPrice, name.HamPrice, name.MushroomsPrice),
                Price       = "33zł"
            };

            Pizza.Dish dania1 = new Pizza.Dish
            {
                Name        = name.Schnitzel,
                SidesDishes = "",
                Price       = "30zł"
            };

            Pizza.Dish dania2 = new Pizza.Dish
            {
                Name        = name.FishPrice,
                SidesDishes = Sides(name.BarPrice),
                Price       = "33zł"
            };

            Pizza.Dish dania3 = new Pizza.Dish
            {
                Name        = name.PotatoPrice,
                SidesDishes = Sides(name.BarPrice, name.SetOfSaucesPrice),
                Price       = "38zł"
            };

            Pizza.Dish zupa1 = new Pizza.Dish
            {
                Name        = name.Tomato,
                SidesDishes = "",
                Price       = "12zł"
            };

            Pizza.Dish zupa2 = new Pizza.Dish
            {
                Name        = name.ChickenSoup,
                SidesDishes = "",
                Price       = "10zł"
            };


            Pizza.Dish napoje1 = new Pizza.Dish
            {
                Name        = name.Coffee,
                SidesDishes = "",
                Price       = "5zł"
            };

            Pizza.Dish napoje2 = new Pizza.Dish
            {
                Name        = name.Tea,
                SidesDishes = "",
                Price       = "5zł"
            };

            Pizza.Dish napoje3 = new Pizza.Dish
            {
                Name        = name.Cola,
                SidesDishes = "",
                Price       = "5zł"
            };



            Pizza.Order order = new Pizza.Order
            {
                PriceAll = priceAll
            };
            order.AddDishToListDisch(pizza);
            order.AddDishToListDisch(pizzaSide1);
            order.AddDishToListDisch(pizzaSide2);
            order.AddDishToListDisch(pizzaSide3);
            order.AddDishToListDisch(pizzaSide4);

            order.AddDishToListDisch(dania1);
            order.AddDishToListDisch(dania2);
            order.AddDishToListDisch(dania3);

            order.AddDishToListDisch(zupa1);
            order.AddDishToListDisch(zupa2);

            order.AddDishToListDisch(napoje1);
            order.AddDishToListDisch(napoje2);
            order.AddDishToListDisch(napoje3);

            Pizza.EmailMessage message = new Pizza.EmailMessage(order);


            string test = "###################################################\n#\n#               2020-07-07 21:03:37                \n#                     Cena: 275zł                 \n#\n###################################################" +
                          "\n###################################################\n#\n# Margheritta\n# Cenna za danie: 20zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Vegetariana -22zł\n# Podwójny Ser -2zł\n# Cenna za danie: 24zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Tosca -25zł\n# Podwójny Ser -2zł\n# Salami -2zł\n# Cenna za danie: 29zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Venecia -25zł\n# Salami -2zł\n# Szynka -2zł\n# Pieczarki -2zł\n# Cenna za danie: 31zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Venecia -25zł\n# Podwójny Ser -2zł\n# Salami -2zł\n# Szynka -2zł\n# Pieczarki -2zł\n# Cenna za danie: 33zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Schabowy z frytkami/ryżem/ziemniakami\n# Cenna za danie: 30zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Ryba z frytkami -28zł\n# Bar sałatkowy -5zł\n# Cenna za danie: 33zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Placek po węgiersku -27zł\n# Bar sałatkowy -5zł\n# Zestaw sosów -6zł\n# Cenna za danie: 38zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Pomidorowa\n# Cenna za danie: 12zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Rosół\n# Cenna za danie: 10zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Kawa\n# Cenna za danie: 5zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Herbata\n# Cenna za danie: 5zł\n#\n###################################################" +
                          "\n###################################################\n#\n# Cola\n# Cenna za danie: 5zł\n#\n###################################################" +
                          "\nUwagi do zamówienia: \n";

            Assert.AreEqual(test, message.WriteBill());
        }