Beispiel #1
0
        private void HandleTimerTick(object sender, EventArgs e)
        {
            dataFile.load();
            string   username   = System.Environment.UserName.ToLower();
            DateTime today      = DateTime.Now.Date;
            var      tickRecord = dataFile.findUserRecord(username, today);
            var      configUser = configuration.Users[username] as TickUserElement;

            if (configUser != null && tickRecord != null)
            {
                int dayOfWeek = (int)today.DayOfWeek;
                if (dayOfWeek == 0)
                {
                    dayOfWeek = 7;
                }
                allowedMinutes = configUser[dayOfWeek];
                if (configUser.Exceptions != null && configUser.Exceptions[today] != null)
                {
                    allowedMinutes = configUser.Exceptions[today].Minutes;
                }
                passedMinutes = tickRecord.Minutes;

                // Warnings
                int remainingMinutes = allowedMinutes.Value - passedMinutes.Value;
                if (WARNING_MINUTES.Contains(remainingMinutes))
                {
                    MessageBox.Show(String.Format("Es sind nur {0} Minuten geblieben!", remainingMinutes),
                                    "Zeitbegrenzung", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (remainingMinutes == 1)
                {
                    MessageBox.Show(String.Format("Dir bleibt nur eine Minute!", remainingMinutes),
                                    "Zeitbegrenzung", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                passedMinutes  = null;
                allowedMinutes = null;
            }
        }
Beispiel #2
0
        public void tick(object stateObject)
        {
            dataFile.load();
            List <string>     loggedInUsers = GetLoggedInUsers();
            DateTime          today         = DateTime.Now.Date;
            TickConfiguration configuration = TickConfiguration.Instance;

            foreach (var user in loggedInUsers)
            {
                var configUser = configuration.Users[user] as TickUserElement;
                if (configUser != null)
                {
                    int dayOfWeek = (int)today.DayOfWeek;
                    if (dayOfWeek == 0)
                    {
                        dayOfWeek = 7;
                    }
                    int maxMinutes = configUser[dayOfWeek];
                    if (configUser.Exceptions != null)
                    {
                        if (configUser.Exceptions[today] != null)
                        {
                            maxMinutes = configUser.Exceptions[today].Minutes;
                        }
                    }
                    var userRecord = dataFile.findUserRecord(user, today);
                    if (userRecord == null)
                    {
                        userRecord = dataFile.createTickRecord(user, today);
                    }
                    userRecord.Minutes += interval;
                    Console.WriteLine(String.Format("Benutzer {0}: {1} Minuten von {2} sind vorbei", user, userRecord.Minutes, maxMinutes));
                    if (userRecord.Minutes > maxMinutes)
                    {
                        runShutdownCommand();
                    }
                }
            }
            dataFile.save();
        }
Beispiel #3
0
        private void LoadUserData(object sender, EventArgs e)
        {
            dataGrid.Rows.Clear();
            string   selectedUser = userBox.SelectedItem.ToString();
            DateTime date         = dataFile.Records.Count > 0 ? dataFile.Records[0].Date : DateTime.Today;

            while (date <= DateTime.Now)
            {
                TickRecord record      = dataFile.findUserRecord(selectedUser, date);
                int        limit       = getUserLimitForDate(selectedUser, date);
                int        used        = record != null ? record.Minutes : 0;
                int        rest        = limit > used ? limit - used : 0;
                int        restPercent = limit > 0 ?rest * 100 / limit : 0;
                dataGrid.Rows.Insert(0, new object[] { date.ToShortDateString(),
                                                       limit, used, String.Format("{0} Min ({1}%)", rest, restPercent) });
                DataGridViewRow row = dataGrid.Rows[0];
                if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
                {
                    row.DefaultCellStyle.BackColor = Color.LightSalmon;
                }
                date = date.AddDays(1);
            }
        }