Exemple #1
0
        /// <summary>
        /// Split lines into better strings to use and adds them to the currDay
        /// </summary>
        /// <param name="line"></param>
        private void SplitAndAddLoadedEntry(string line)
        {
            if (line != null)
            {
                string[] splittedLine = line.Split(';');

                foreach (Product p in Products)
                {
                    if (Convert.ToString(p.Id) == splittedLine[0])
                    {
                        Entry e = new Entry(p, Convert.ToInt32(splittedLine[1]), Convert.ToInt32(splittedLine[2]),
                                            Convert.ToInt32(splittedLine[1]) * p.Price);
                        CurrWeek.GetCurrentDayAndAddEntry(e);
                        break;
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Loads the entrys of the database
        /// </summary>
        /// <param name="weekName">Week name</param>
        /// <param name="dayId">Id of the day</param>
        public void LoadEntry(string weekName, string dayId)
        {
            try
            {
                string query = "SELECT * FROM entry WHERE 'WeekId' LIKE " + weekName + " AND 'DayId' LIKE " + dayId;
                CreateConnection();

                MySqlCommand commandDatabase = new MySqlCommand(query, _connection)
                {
                    CommandTimeout = 60
                };
                _connection.Open();

                MySqlDataReader reader = commandDatabase.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string id     = reader.GetString(0);
                        string weekId = reader.GetString(1);
                        //string dayId = reader.GetString(2); //todo check if works with given dayId
                        string productForEntryId = reader.GetString(3);
                        string amount            = reader.GetString(4);
                        string amountOnTheHouse  = reader.GetString(5);
                        string price             = reader.GetString(6);

                        CurrWeek.GetCurrentDayAndAddEntry(new Entry(Convert.ToInt32(id), Convert.ToInt32(weekId), Convert.ToInt32(dayId), Convert.ToInt32(productForEntryId), Convert.ToInt32(amount), Convert.ToInt32(amountOnTheHouse), Convert.ToDouble(price)));
                    }
                }

                CloseConnection();
            }
            catch (Exception ex)
            {
                SaveErrorMsg(ex);
                Log(ex.Message);
            }
        }