Пример #1
0
        internal LogViewModel(DateTime logDate, SettingsViewModel settings)
        {
            if (IsInDesignMode)
              {
            this.TimeEntries = new ObservableCollection<TimeEntryViewModel>()
            {
              new TimeEntryViewModel() {Type = TimeEntryTypes.StartOfWorkday, StartTime = new DateTime(), EndTime = this.Settings.WorkdayStart, Label = "Start the day" },
              new TimeEntryViewModel() {Type = TimeEntryTypes.Normal, StartTime = DateTime.Now.AddHours(-10), EndTime = DateTime.Now.AddHours(-9), Label = "Second Entry" },
              new TimeEntryViewModel() {Type = TimeEntryTypes.Normal, StartTime = DateTime.Now.AddHours(-9), EndTime = DateTime.Now.AddHours(-8), Label = "Third Entry" },
              new TimeEntryViewModel() {Type = TimeEntryTypes.Normal, StartTime = DateTime.Now.AddHours(-8), EndTime = DateTime.Now.AddHours(-7), Label = "First Entry" },
              new TimeEntryViewModel() {Type = TimeEntryTypes.Normal, StartTime = DateTime.Now.AddHours(-7), EndTime = DateTime.Now.AddHours(-6), Label = "Second Entry" },
              new TimeEntryViewModel() {Type = TimeEntryTypes.Normal, StartTime = DateTime.Now.AddHours(-6), EndTime = DateTime.Now.AddHours(-5), Label = "Third Entry" },
              new TimeEntryViewModel() {Type = TimeEntryTypes.Normal, StartTime = DateTime.Now.AddHours(-5), EndTime = DateTime.Now.AddHours(-4), Label = "First Entry" },
              new TimeEntryViewModel() {Type = TimeEntryTypes.Normal, StartTime = DateTime.Now.AddHours(-4), EndTime = DateTime.Now.AddHours(-3), Label = "Second Entry" },
              new TimeEntryViewModel() {Type = TimeEntryTypes.Normal, StartTime = DateTime.Now.AddHours(-3), EndTime = DateTime.Now.AddHours(-2), Label = "Third Entry" },
              new TimeEntryViewModel() {Type = TimeEntryTypes.Normal, StartTime = DateTime.Now.AddHours(-2), EndTime = DateTime.Now.AddHours(-1), Label = "Third Entry" },
              new TimeEntryViewModel() {Type = TimeEntryTypes.Normal, StartTime = DateTime.Now.AddHours(-1), EndTime = DateTime.Now.AddHours(-0), Label = "Third Entry" },
            };
              }
              else
              {
            this.TimeEntries = new ObservableCollection<TimeEntryViewModel>();
              }

              this.LogDate = logDate;
              this.Settings = settings;
              this.AddEntryCommand = new RelayCommand(AddEntryCommand_Execute, AddEntryCommand_CanExecute);
              this.MessengerInstance.Register<DeleteTimeEntryMessage>(this, HandleDeleteTimeEntryMessage);
              this.MessengerInstance.Register<TimeEntryEditingCompleteMessage>(this, HandleTimeEntryEditingCompleteMessage);
              this.MessengerInstance.Register<TimeEntryEditingStartedMessage>(this, HandleTimeEntryEditingStartedMessage);

              RefreshCurrentEntry();
        }
Пример #2
0
        public LogListingViewModel(SettingsViewModel settings)
        {
            this.AllLogs = new ObservableCollection<LogStub>();
              this.Settings = settings;

              //this.CSV = new CollectionViewSource();
              //this.CSV.Source = this.AllLogs;

              this.AllLogsView = CollectionViewSource.GetDefaultView(this.AllLogs);
              this.AllLogsView.SortDescriptions.Add(new SortDescription("Date", ListSortDirection.Descending));
              this.AllLogsView.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
              //this.AllLogsView.Refresh

              LoadAllLogs();

              //this.AllLogsView.Refresh();
        }
Пример #3
0
        public static LogViewModel LoadByFileName(string filename, DateTime date, SettingsViewModel settings)
        {
            if (File.Exists(filename))
              {
            var log = new LogViewModel(date, settings);

            using (var reader = new StreamReader(filename))
            {
              string currentLine;
              while ((currentLine = reader.ReadLine()) != null)
              {
            Match m = Regex.Match(currentLine, @"^\[(.*) - (.*) : (.*)\]\w*(.*)");
            if (m.Success)
            {
              try
              {
                var startDate = DateTime.Parse(m.Groups[1].Value);
                var endDate = DateTime.Parse(m.Groups[2].Value);
                var type = (TimeEntryTypes)Enum.Parse(typeof(TimeEntryTypes), m.Groups[3].Value);
                var label = m.Groups[4].Value.Trim();

                log.TimeEntries.Add(new TimeEntryViewModel() { StartTime = startDate, EndTime = endDate, Label = label, Type = type });
              }
              catch
              {

              }
            }
              }

            }

            return log;
              }
              else
              {
            var log = new LogViewModel(date, settings);
            log.TimeEntries.Add(new TimeEntryViewModel() { Type = TimeEntryTypes.StartOfWorkday, StartTime = new DateTime(), EndTime = settings.WorkdayStart, Label = "Start the day" });

            return log;
              }
        }
Пример #4
0
        public static LogViewModel LoadByDate(DateTime date, SettingsViewModel settings)
        {
            var filename = settings.GetFileNameByDate(date);

              return LoadByFileName(filename, date, settings);
        }