Exemplo n.º 1
0
 private bool PassValidation()
 {
     if (_selectedProjekt == Guid.Empty ||
         string.IsNullOrEmpty(_selectedLohnkategorie) ||
         string.IsNullOrEmpty(_selectedTarifkategorie) ||
         string.IsNullOrEmpty(_text))
     {
         return(false);
     }
     if (_state == InitState.NotRunningNotLogged)
     {
         if (string.IsNullOrEmpty(_username) || string.IsNullOrEmpty(_password))
         {
             return(false);
         }
         var db = new DialogTimeEntities();
         using (db)
         {
             var md5 = MD5(_password);
             var q   = from x in db.Personals
                       where x.PersId == _username && x.Passwort == md5
                       select x;
             if (q.Any())
             {
                 // TODO: Set standard values for projekt, lohnkategotie and tarifkategorie based on user
                 _user = q.First();
                 SetLastSelections();
                 // Password = _stars;
                 return(true);
             }
         }
     }
     return(true);
 }
Exemplo n.º 2
0
        private void SetLastSelections()
        {
            var db = new DialogTimeEntities();

            using (db)
            {
                var r = from x in db.StartStops
                        where x.PersId == _user.PersId
                        orderby x.Id descending
                        select x;
                if (r.Any())
                {
                    var last = r.First();
                    SelectedProjekt = last.ProjektId;
                    // Now the list of Lohnkategorien should be reloaded
                    // then...
                    SelectedLohnkategorie  = last.LohnkategorieKuerzel;
                    SelectedTarifkategorie = last.TarifkategorieId;
                    Text = last.Text;
                }
                else
                {
                    SelectedProjekt        = _projekteListe.First().Id;
                    SelectedLohnkategorie  = _lohnkategorienListe.First().Kuerzel;
                    SelectedTarifkategorie = _tarifkategorienListe.First().Id;
                    Text = "";
                }
            }
        }
Exemplo n.º 3
0
        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);
                }
            }
        }
Exemplo n.º 4
0
        private InitState InitAndGetState(DialogTimeEntities db)
        {
            // Restore state from database
            if (_user == null)
            {
                return(InitState.NotRunningNotLogged);
            }
            var q = from x in db.StartStops
                    where (x.TimeIntervall.EndsWith("-") || x.TimeIntervall.EndsWith("p")) && x.PersId == _user.PersId
                    select x;

            if (q.Any())
            {
                if (q.Count() > 1)
                {
                    // TODO: Szenarion behandeln
                    // I find more than one pending activity!
                    return(InitState.Running);
                }
                _current = q.First();
                if (_current.TimeIntervall.EndsWith("-"))
                {
                    return(InitState.Running);
                }
                if (_current.TimeIntervall.EndsWith("p"))
                {
                    return(InitState.Paused);
                }
            }
            _current = null;
            return(InitState.NotRunningLogged);
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        private void LoadProjektComboBox()
        {
            var db = new DialogTimeEntities();

            using (db)
            {
                ProjekteListe = new List <Projekte>();
                if (_user != null)
                {
                    db.Personals.Attach(_user);
                    var q1 = _user.MitarbeiterProjektes.OrderBy(pr => pr.Bezeichnung);
                    ProjekteListe = q1.ToList();
                }
            }
        }
Exemplo n.º 8
0
        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;
                }
            }
        }
Exemplo n.º 9
0
        private void InitComboBoxes()
        {
            var db = new DialogTimeEntities();

            using (db)
            {
                ProjekteListe = new List <Projekte>();
                if (_user != null)
                {
                    db.Personals.Attach(_user);
                    var q1 = _user.MitarbeiterProjektes;
                    ProjekteListe = q1.ToList();
                }
                LohnkategorienListe = new List <Lohnkategorien>();
                var q3 = db.Tarifkategoriens;
                TarifkategorienListe = q3.ToList();
            }
        }
Exemplo n.º 10
0
        private Personal UserValidation()
        {
            if (string.IsNullOrEmpty(_username) ||
                string.IsNullOrEmpty(_password))
            {
                return(null);
            }
            var db = new DialogTimeEntities();

            using (db)
            {
                var md5 = MD5(_password);
                var q   = from x in db.Personals
                          where x.PersId == _username && x.Passwort == md5
                          select x;
                if (q.Any())
                {
                    return(q.First());
                }
            }
            return(null);
        }
Exemplo n.º 11
0
        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);
                }
            }
        }