Пример #1
0
        public void LoadEntries()
        {
            DisplayEntries.Clear();
            string queryString = $"SELECT * FROM history WHERE begin BETWEEN datetime('{SelectedDate:s}','start of month') AND datetime('{SelectedDate:s}','start of month','+1 month','-1 day')";

            dbConnection.Open();
            using (var comm = new SQLiteCommand(queryString, dbConnection))
            {
                using (var read = comm.ExecuteReader())
                {
                    while (read.Read())
                    {
                        WorkEntry _ = new WorkEntry();
                        _.Begin = read.GetDateTime(0);
                        _.End   = read.GetDateTime(1);
                        string breakTime = read.GetString(2);
                        _.Break   = new TimeSpan(int.Parse(breakTime.Split(":")[0]), int.Parse(breakTime.Split(":")[1]), int.Parse(breakTime.Split(":")[2]));
                        _.Comment = read.GetString(3);
                        DisplayEntries.Add(_);
                    }
                }
            }
            dbConnection.Close();


            //(dbConnection?.Query<WorkEntry>(queryString) ?? new List<WorkEntry>()).ToList().ForEach(x => DisplayEntries.Add(x));
        }
Пример #2
0
        /// <summary>
        /// Clears all properties and resets them to their default value.
        /// </summary>
        public void Clear()
        {
            //loops over all properties within this class and sets them to their default value.
            var props = GetType().GetProperties();

            foreach (var prop in props)
            {
                //set value types to their default.
                if (prop.PropertyType.IsValueType)
                {
                    prop.SetValue(this, Activator.CreateInstance(prop.PropertyType));
                }
                //set strings to empty (not null)
                else if (prop.PropertyType.Equals(typeof(string)))
                {
                    prop.SetValue(this, "");
                }
            }

            CollectionEntries.Clear();
            DisplayEntries.Clear();
            CustomMap16Data = new byte[0];
        }