private void ResumeAction() { GotoState(InitState.NotRunningLogged); // Save state to database var entities = new DialogTimeEntities(); using (entities) { var q = from x in entities.StartStops where x.TimeIntervall.EndsWith("p") && x.PersId == _user.PersId select x; if (q.Any()) { if (q.Count() > 1) { // TODO: Szenario behandeln // I'm resuming, but there are many pending activities return; } var first = q.First(); first.TimeIntervall = first.TimeIntervall.Substring(0, first.TimeIntervall.Length - 1) + string.Format(",{0:00}:{1:00}-", DateTime.Now.Hour, DateTime.Now.Minute); entities.SaveChanges(); _intervalls = new Helpers.Intervalls(first.TimeIntervall); GotoState(InitState.Running); } } }
private void PauseAction() { GotoState(InitState.Paused); var entities = new DialogTimeEntities(); using (entities) { var q = from x in entities.StartStops where x.TimeIntervall.EndsWith("-") && x.PersId == _user.PersId select x; if (q.Any()) { if (q.Count() > 1) { // TODO: Szenario behandeln // I'm pausing, but there are many pending activities return; } var first = q.First(); first.TimeIntervall += string.Format("{0:00}:{1:00}p", DateTime.Now.Hour, DateTime.Now.Minute); entities.SaveChanges(); _intervalls = new Helpers.Intervalls(first.TimeIntervall); _timer_Elapsed(this, null); GotoState(InitState.Paused); } } }
private void BaseStartAction(DateTime time) { if (!PassValidation()) { FeedbackText = "Bitte, alle nötige Daten eingeben"; return; } var entities = new DialogTimeEntities(); using (entities) { var entry = new StartStop(); entry.PersId = _username; entry.ProjektId = _selectedProjekt.Value; entry.TimeIntervall = string.Format("{0:00}:{1:00}-", time.Hour, time.Minute); entry.LohnkategorieKuerzel = _selectedLohnkategorie; entry.TarifkategorieId = _selectedTarifkategorie; entry.Text = Text; entry.Datum = time; entities.StartStops.Add(entry); entities.SaveChanges(); _intervalls = new Helpers.Intervalls(entry.TimeIntervall); GotoState(InitState.Running); } }
public MainViewModel() { _timer = new Timer(); _timer.Enabled = false; _timer.Elapsed += _timer_Elapsed;; _timer.Interval = 30000; _intervalls = null; // Define command behavior StartCommand = new RelayCommand(() => StartAction()); StartExCommand = new RelayCommand(() => StartExAction()); StopCommand = new RelayCommand(() => StopAction()); StopExCommand = new RelayCommand(() => StopExAction()); PauseCommand = new RelayCommand(() => PauseAction()); ResumeCommand = new RelayCommand(() => ResumeAction()); AbmeldenCommand = new RelayCommand(() => { Username = ""; // Password = ""; _user = null; GotoState(InitState.NotRunningNotLogged); }); AbmeldenCommand.IsEnabled = true; // Init Comboboxes InitComboBoxes(); // Set initial state GotoState(InitState.NotRunningNotLogged); }
private void AfterLoginProcess() { // Validate Username / Password _user = UserValidation(); if (_user == null) { return; } // Now we know the user LoadProjektComboBox(); // Restore last selections SetLastSelections(); // Restore status var db = new DialogTimeEntities(); using (db) { var state = InitAndGetState(db); switch (state) { case InitState.Running: _intervalls = new Intervalls(_current.TimeIntervall); //SelectedProjekt = _current.ProjektId; //SelectedLohnkategorie = _current.LohnkategorieKuerzel; //SelectedTarifkategorie = _current.TarifkategorieId; //Text = _current.Text; GotoState(InitState.Running); break; case InitState.Paused: var str = _current.TimeIntervall.Substring(0, _current.TimeIntervall.Length - 1); _intervalls = new Intervalls(str); //SelectedProjekt = _current.ProjektId; //SelectedLohnkategorie = _current.LohnkategorieKuerzel; //SelectedTarifkategorie = _current.TarifkategorieId; //Text = _current.Text; GotoState(InitState.Paused); break; default: GotoState(state); break; } } }
private StateResponse _putStop(dialogTimeEntities db, string persId, StartStop entry, DateTime datum, bool manuell = false) { if (entry == null) { return(new Models.StateResponse() { Success = false, Error = "Kann man nicht stoppen wenn nicht gestarted. Bitte melden!" }); } var timeIntervall = entry.TimeIntervall; if (timeIntervall.EndsWith("-") || timeIntervall.EndsWith("p")) { if (timeIntervall.EndsWith("-")) { entry.TimeIntervall = timeIntervall + string.Format("{0:00}:{1:00}", datum.Hour, datum.Minute); } else { entry.TimeIntervall = timeIntervall.Substring(0, timeIntervall.Length - 1); } if (manuell) { entry.StartStopManuell = manuell; } var ii = new Intervalls(entry.TimeIntervall); var jj = new Intervalls(); var q2 = from x in db.RapportEintraege where x.PersId == persId && x.Datum == datum.Date select x; foreach (var e in q2) { jj.AddRange(new Intervalls(e.TimeIntervall)); } ii.CutWith(jj); var eintrag = new RapportEintrag() { Id = Guid.NewGuid(), AnsatzExtern = 0, AnsatzIntern = 0, ArbeitsRapportNr = 0, Aufwand = Math.Round(ii.EllapsedAsDouble, 1), Datum = datum.Date, ErfDatum = DateTime.Now, ErfName = persId, LohnkategorieKuerzel = entry.LohnkategorieKuerzel, LohnKatKontierung = "", MandantId = Guid.Parse("331A58AF-C3F6-42BE-BF55-0AE0C5F26C87"), MutDatum = DateTime.Now, MutName = persId, PersId = persId, ProjektId = entry.ProjektId, TarifkategorieId = entry.TarifkategorieId, Text = entry.Text, TimeIntervall = ii.ToString(), Verrechnet = 0, Zuschlag = 0, StartStopManuell = entry.StartStopManuell }; db.RapportEintraege.Add(eintrag); db.SaveChanges(); return(new Models.StateResponse() { Success = true, TimeIntervall = eintrag.TimeIntervall, Error = null }); } else { return(new Models.StateResponse() { Success = false, Error = "Kann man nicht stoppen wenn nicht gestarted. Bitte melden!" }); } }
private void BaseStopAction(DateTime time) { GotoState(InitState.NotRunningLogged); var entities = new DialogTimeEntities(); using (entities) { var q = from x in entities.StartStops where (x.TimeIntervall.EndsWith("-") || x.TimeIntervall.EndsWith("p")) && x.PersId == _user.PersId select x; if (q.Any()) { if (q.Count() > 1) { // TODO: Szenario behandeln // I'm stopping, but there are many pending activities return; } var first = q.First(); if (first.TimeIntervall.EndsWith("p")) { first.TimeIntervall = first.TimeIntervall.Substring(0, first.TimeIntervall.Length - 1); } else { first.TimeIntervall += string.Format("{0:00}:{1:00}", time.Hour, time.Minute); } var ii = new Intervalls(first.TimeIntervall); var jj = new Intervalls(); var q2 = from x in entities.RapportEintraeges where x.PersId == _user.PersId && x.Datum == time select x; foreach (var e in q2) { jj.AddRange(new Intervalls(e.TimeIntervall)); } ii.CutWith(jj); RapportEintraege eintrag = new RapportEintraege() { Id = Guid.NewGuid(), AnsatzExtern = 0, AnsatzIntern = 0, ArbeitsRapportNr = 0, Aufwand = Math.Round(ii.EllapsedAsDouble, 1), Datum = time, ErfDatum = DateTime.Now, ErfName = _user.PersId, LohnkategorieKuerzel = first.LohnkategorieKuerzel, LohnKatKontierung = "", MandantId = Guid.Parse("331A58AF-C3F6-42BE-BF55-0AE0C5F26C87"), MutDatum = DateTime.Now, MutName = _user.PersId, PersId = _user.PersId, ProjektId = first.ProjektId, TarifkategorieId = first.TarifkategorieId, Text = first.Text, TimeIntervall = ii.ToString(), Verrechnet = 0, Zuschlag = 0 }; entities.RapportEintraeges.Add(eintrag); entities.SaveChanges(); _intervalls = new Helpers.Intervalls(first.TimeIntervall); _timer_Elapsed(this, null); GotoState(InitState.NotRunningLogged); } } }