Ejemplo n.º 1
0
        public int GetIndexDaily(DateTime date)
        {
            TradingDay mod   = DailyHistory.OrderBy(x => Math.Abs(x.TradeDate.Ticks - date.Ticks)).First();
            int        index = DailyHistory.IndexOf(mod);

            return(index);
        }
Ejemplo n.º 2
0
        internal static User LoadUserData(string username)
        {
            List <DailyHistory> result = new List <DailyHistory>();
            User loadedUser            = new User();

            if (dbCon.State == ConnectionState.Closed)
            {
                dbCon.Open();
            }
            SqlCeCommand command = new SqlCeCommand();

            command.Connection  = dbCon;
            command.CommandText = String.Format(@"SELECT * FROM Users WHERE UserName='******'", username);
            SqlCeDataReader reader = command.ExecuteReader();

            reader.Read();
            loadedUser.Nickname = username;
            loadedUser.Password = (string)reader["Password"];
            loadedUser.Type     = (UserType)Enum.Parse(typeof(UserType), (string)reader["Type"]);
            loadedUser.Name     = (string)reader["Name"];
            loadedUser.Email    = (string)reader["Email"];

            string sqlCommand = String.Format(
                @"SELECT History.Data, History.DailyCalories, DailyHistory.ProductName, 
                DailyHistory.Quantity, DailyHistory.Calories, Users.UserName FROM DailyHistory 
                    INNER JOIN History ON DailyHistory.HistoryId = History.Id 
                    INNER JOIN Users ON History.UserName = Users.UserName
                WHERE  (Users.UserName = '******')", username);

            command.CommandText = sqlCommand;
            reader = command.ExecuteReader();
            using (reader)
            {
                while (reader.Read())
                {
                    DailyHistory daily = new DailyHistory()
                    {
                        eatenHistory  = new List <EatenData>(),
                        date          = (string)reader["Data"],
                        dailyCalories = (decimal)reader["DailyCalories"]
                    };
                    bool isDateEqual;
                    bool readMore;
                    do
                    {
                        EatenData eaten = new EatenData()
                        {
                            productName = (string)reader["ProductName"],
                            quantity    = (int)reader["Quantity"],
                            calories    = (decimal)reader["Calories"]
                        };
                        daily.eatenHistory.Add(eaten);
                        readMore = reader.Read();
                        if (readMore)
                        {
                            isDateEqual = (string)reader["Data"] == daily.date;
                            if (isDateEqual == false)
                            {
                                isDateEqual = true;
                                result.Add(daily);
                                daily = new DailyHistory()
                                {
                                    eatenHistory  = new List <EatenData>(),
                                    date          = (string)reader["Data"],
                                    dailyCalories = (decimal)reader["DailyCalories"]
                                };
                            }
                        }
                        else
                        {
                            result.Add(daily);
                            isDateEqual = false;
                        }
                    }while (readMore && isDateEqual);
                }
            }

            dbCon.Close();
            loadedUser.History = result;
            return(loadedUser);
        }
 // удаление элемента из таблицы с историей и обновление статистики
 public void DeleteItem(EatingHistoryItem item)
 {
     _repo.RemoveEatingHistoryItem(item);
     DailyHistory.Remove(item);
     DailyFoodStatistics = _counter.CountFoodStatistics(DailyHistory.ToList());
 }
Ejemplo n.º 4
0
 public void SortDates()
 {
     DailyHistory.Reverse();
 }