Esempio n. 1
0
        public bool Authenticate(string username, string password)
        {
            //find user in database
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

            var findUser = (from u in dbcontext.Users
                            where u.Username == username
                            select u).ToArray();

            dbcontext.Dispose();

            if (findUser.Length > 0)
            {
                TimePunchDatabase.User foundUser = findUser[0];
                PasswordHash           ph        = new PasswordHash(Convert.FromBase64String(foundUser.Password));
                if (ph.verify(password))
                {
                    this.User       = foundUser;
                    this.isLoggedIn = true;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        static void Main()
        {
            //Temp for testing purpose
            try
            {
                TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

                var users = (from user in dbcontext.Users
                             select user).ToArray();
                if (users.Length == 0)
                {
                    InsertTestData(dbcontext);
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                if (ex.InnerException != null)
                {
                    MessageBox.Show(ex.InnerException.Message);
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
Esempio n. 3
0
        private void ViewHours_Load(object sender, EventArgs e)
        {
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

            var settings = (from setting in dbcontext.Settings
                            where setting.ID == 1
                            select setting).First();

            DateTime currentDate    = DateTime.Today;
            DateTime payPeriodStart = Convert.ToDateTime(settings.payPeriodStartDate).Date;

            double daysPassed = currentDate.Subtract(payPeriodStart).TotalDays;

            int daysIntoPayperiod = (int)Math.Floor(daysPassed % settings.payPeriodDays);

            DateTime firstDay       = DateTime.Today.Subtract(new TimeSpan(daysIntoPayperiod, 0, 0, 0));
            string   firstDayString = firstDay.ToString("o");

            //bypass ADO to compare dates since you can't compare >= with strings and you can't use outside functions with linq. ;-;
            SQLiteConnection conn = new SQLiteConnection("DataSource=./TimePunchV2.db");

            conn.Open();
            string sql = "SELECT * FROM TimePunches " +
                         "WHERE UserID = " + (this.userID == 0 ? auth.User.ID : this.userID) + " AND " +
                         "Date >= \"" + firstDayString + "\"";
            SQLiteCommand    command = new SQLiteCommand(sql, conn);
            SQLiteDataReader reader  = command.ExecuteReader();

            while (reader.Read())
            {
                double hours = 0;

                //half day
                if (reader["LunchStart"] == DBNull.Value && reader["LunchEnd"] == DBNull.Value && reader["PunchOut"] != DBNull.Value)
                {
                    hours = DateTime.Today.Add(Convert.ToDateTime(reader["PunchOut"]).TimeOfDay)
                            .Subtract(DateTime.Today.Add(Convert.ToDateTime(reader["PunchIn"]).TimeOfDay)).TotalHours;
                }//full day
                else if (reader["LunchStart"] != DBNull.Value && reader["LunchEnd"] != DBNull.Value && reader["PunchOut"] != DBNull.Value)
                {
                    hours = DateTime.Today.Add(Convert.ToDateTime(reader["PunchOut"]).TimeOfDay)
                            .Subtract(DateTime.Today.Add(Convert.ToDateTime(reader["LunchEnd"]).TimeOfDay)).TotalHours;
                    hours += DateTime.Today.Add(Convert.ToDateTime(reader["LunchStart"]).TimeOfDay)
                             .Subtract(DateTime.Today.Add(Convert.ToDateTime(reader["PunchIn"]).TimeOfDay)).TotalHours;
                }//on lunch
                else if (reader["LunchStart"] != DBNull.Value && reader["LunchEnd"] == DBNull.Value)
                {
                    hours = DateTime.Today.Add(Convert.ToDateTime(reader["LunchStart"]).TimeOfDay)
                            .Subtract(DateTime.Today.Add(Convert.ToDateTime(reader["PunchIn"]).TimeOfDay)).TotalHours;
                }

                HoursLabel hoursLabel = new HoursLabel(Convert.ToDateTime(reader["Date"]), hours, mainForm, Convert.ToInt32(reader["ID"]));
                hoursFlowLayoutPanel.Controls.Add(hoursLabel);
            }

            conn.Close();
        }
        private void loadUserValues()
        {
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

            var userData = (from user in dbcontext.Users
                            where user.ID == userID
                            select user).First();

            usernameTextBox.Text       = userData.Username;
            firstNameTextBox.Text      = userData.FirstName;
            lastNameTextBox.Text       = userData.LastName;
            roleComboBox.SelectedIndex = (int)userData.Role;

            dbcontext.Dispose();
        }
Esempio n. 5
0
        private void punchInButton_Click(object sender, EventArgs e)
        {
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

            string todaysDate = DateTime.Today.ToString("o");

            //see if the user has an open punch already
            var openPunch = (from punch in dbcontext.TimePunches
                             where punch.UserID == auth.User.ID && punch.isOpen == 1 ||
                             punch.UserID == auth.User.ID && punch.Date == todaysDate && punch.isOpen == 0
                             select punch).ToArray();

            if (openPunch.Length > 0)
            {
                MessageBox.Show("You have already clocked in for the day!", "Punch In", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //Generate SQL for TimePunch Insertion

            string date    = DateTime.Today.Date.ToString("o");
            string punchIn = DateTime.Now.ToString("o");

            SQLiteConnection conn = new SQLiteConnection("DataSource=./TimePunchV2.db");

            conn.Open();

            string sql = string.Format("INSERT INTO TimePunches (UserID, isOpen, Date, PunchIn) VALUES" +
                                       "({0}, {1}, \"{2}\", \"{3}\");", auth.User.ID, 1, date, punchIn);
            SQLiteCommand command = new SQLiteCommand(sql, conn);

            try
            {
                command.ExecuteNonQuery();
                MessageBox.Show("You have clocked in!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show("Could not update punch. Please try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                dbcontext.Dispose();
            }
        }
Esempio n. 6
0
        private void lunchStartButton_Click(object sender, EventArgs e)
        {
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

            //find open punch
            var openPunch = (from punch in dbcontext.TimePunches
                             where punch.UserID == auth.User.ID &&
                             punch.isOpen == 1
                             select punch).ToArray();

            if (openPunch.Length > 0)
            {
                var punch = openPunch[0];

                //check if they have already started lunch
                if (punch.LunchStart == null)
                {
                    //set lunch start in punch and update database
                    punch.LunchStart = DateTime.Now.ToString("o");

                    try
                    {
                        dbcontext.SaveChanges();
                        MessageBox.Show("Your lunch has started!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        MessageBox.Show("Unable to start lunch. Please try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    finally
                    {
                        dbcontext.Dispose();
                    }
                }
                else
                {
                    MessageBox.Show("You have already started a lunch!", "Lunch Start", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("You haven't clocked in yet!", "Lunch Start", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void addButton_Click(object sender, EventArgs e)
        {
            if (!isEdit)
            {
                addUser();
                return;
            }

            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();
            TimePunchDatabase.User user;

            user = (from u in dbcontext.Users
                    where u.ID == this.userID
                    select u).First();

            user.Username = usernameTextBox.Text.Trim();
            if (!isEdit || passwordTextBox.Text.Trim() != "")
            {
                user.Password = Convert.ToBase64String(new PasswordHash(passwordTextBox.Text.Trim()).ToArray());
            }
            user.FirstName = firstNameTextBox.Text;
            user.LastName  = lastNameTextBox.Text;
            user.Role      = roleComboBox.SelectedIndex;

            try
            {
                dbcontext.SaveChanges();
                MessageBox.Show("User has been saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
                MessageBox.Show("User could not be saved. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                dbcontext.Dispose();
            }
        }
Esempio n. 8
0
        private void ViewUsers_Load(object sender, EventArgs e)
        {
            //get list of users
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

            var users = (from user in dbcontext.Users
                         orderby user.LastName, user.FirstName
                         select user).ToArray();

            usersFlowLayout.Controls.Add(new UserLabelTitle());

            foreach (var user in users)
            {
                UserLabel userLabel = new UserLabel(mainForm, user);
                usersFlowLayout.Controls.Add(userLabel);
            }

            dbcontext.Dispose();
        }
Esempio n. 9
0
        private void Settings_Load(object sender, EventArgs e)
        {
            //populate fields with current settings
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

            var settings = (from setting in dbcontext.Settings
                            where setting.ID == 1
                            select setting).ToArray();

            if (settings.Length > 0)
            {
                minLunchInput.Value = settings[0].minimumLunchMins;
                payPeriodStartCalander.SelectionStart = Convert.ToDateTime(settings[0].payPeriodStartDate);
                payPeriodStartCalander.SelectionEnd   = Convert.ToDateTime(settings[0].payPeriodStartDate);
                payPeriodLengthInput.Value            = settings[0].payPeriodDays;
            }

            dbcontext.Dispose();
        }
Esempio n. 10
0
        private void punchOutButton_Click(object sender, EventArgs e)
        {
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

            //find open punch
            var openPunch = (from punch in dbcontext.TimePunches
                             where punch.UserID == auth.User.ID &&
                             punch.isOpen == 1
                             select punch).ToArray();

            if (openPunch.Length > 0)
            {
                var punch = openPunch[0];
                //check if they are still on lunch
                if (!(punch.LunchStart != null && punch.LunchEnd == null))
                {
                    //and a punch out and close the punch
                    punch.PunchOut = DateTime.Now.ToString("o");
                    punch.isOpen   = 0;

                    try
                    {
                        dbcontext.SaveChanges();
                        MessageBox.Show("You have punched out!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                        MessageBox.Show("Could not punch out. Please try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    MessageBox.Show("You are still on lunch!", "Punch Out", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("You have not clocked in!", "Punch Out", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 11
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete this user?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

            if (result == DialogResult.Yes)
            {
                TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();
                var deluser = (from u in dbcontext.Users
                               where u.ID == user.ID
                               select u).First();

                var userPunches = from punch in dbcontext.TimePunches
                                  where punch.UserID == user.ID
                                  select punch;

                //remove all timepunhes from user
                foreach (var punch in userPunches)
                {
                    dbcontext.TimePunches.Remove(punch);
                }
                //remove user
                try
                {
                    dbcontext.Users.Remove(deluser);
                    dbcontext.SaveChanges();
                    MessageBox.Show("User has been deleted", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Dispose();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    MessageBox.Show("User could not be deleted. Try again later", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                finally
                {
                    dbcontext.Dispose();
                }
            }
        }
Esempio n. 12
0
        private void applyButton_Click(object sender, EventArgs e)
        {
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

            var settings = (from setting in dbcontext.Settings
                            where setting.ID == 1
                            select setting).ToArray();

            if (settings.Length > 0)
            {
                settings[0].minimumLunchMins   = (int)minLunchInput.Value;
                settings[0].payPeriodStartDate = payPeriodStartCalander.SelectionStart.ToString("o");
                settings[0].payPeriodDays      = (int)payPeriodLengthInput.Value;
            }
            else
            {
                TimePunchDatabase.Setting newSettings = new TimePunchDatabase.Setting();
                newSettings.minimumLunchMins   = (int)minLunchInput.Value;
                newSettings.payPeriodStartDate = payPeriodStartCalander.SelectionStart.ToString("o");
                newSettings.payPeriodDays      = (int)payPeriodLengthInput.Value;
                dbcontext.Settings.Add(newSettings);
            }

            try
            {
                dbcontext.SaveChanges();
                MessageBox.Show("Settings have been saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                MessageBox.Show("Settings could not be saved. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                dbcontext.Dispose();
            }
        }
        private void ViewUsersHours_Load(object sender, EventArgs e)
        {
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();
            //get settings
            var settings = (from setting in dbcontext.Settings
                            where setting.ID == 1
                            select setting).First();

            //get all users
            var users = (from user in dbcontext.Users
                         orderby user.LastName, user.FirstName
                         select user);

            userHoursFlowLayout.Controls.Add(new UserHoursLabelTitle());

            foreach (var user in users)
            {
                //get all timepunches from pay period for user
                TimeSpan daysPassed        = DateTime.Today.Subtract(Convert.ToDateTime(settings.payPeriodStartDate).Date);
                int      daysIntoPayPeriod = (int)Math.Floor(daysPassed.TotalDays % settings.payPeriodDays);

                DateTime payPeriodStartDate = DateTime.Today.Subtract(new TimeSpan(daysIntoPayPeriod, 0, 0, 0));

                //another bypass because of dates
                SQLiteConnection conn = new SQLiteConnection("DataSource=./TimePunchV2.db");
                conn.Open();
                string sql = String.Format("SELECT * FROM TimePunches " +
                                           "WHERE UserID = " + user.ID + " AND Date >= \"" + payPeriodStartDate.ToString("o") + "\";");
                SQLiteCommand    command = new SQLiteCommand(sql, conn);
                SQLiteDataReader reader  = command.ExecuteReader();

                double totalHours = 0;

                //tally total hours for user in payperiod
                while (reader.Read())
                {
                    if (reader["LunchStart"] != DBNull.Value && reader["LunchEnd"] != DBNull.Value && reader["PunchOut"] != DBNull.Value)
                    {
                        totalHours += DateTime.Today.Add(Convert.ToDateTime(reader["PunchOut"]).TimeOfDay)
                                      .Subtract(DateTime.Today.Add(Convert.ToDateTime(reader["LunchEnd"]).TimeOfDay)).TotalHours;
                        totalHours += DateTime.Today.Add(Convert.ToDateTime(reader["LunchStart"]).TimeOfDay)
                                      .Subtract(DateTime.Today.Add(Convert.ToDateTime(reader["PunchIn"]).TimeOfDay)).TotalHours;
                    }
                    else if (reader["LunchStart"] == DBNull.Value && reader["LunchEnd"] == DBNull.Value && reader["PunchOut"] != DBNull.Value)
                    {
                        totalHours += DateTime.Today.Add(Convert.ToDateTime(reader["PunchOut"]).TimeOfDay)
                                      .Subtract(DateTime.Today.Add(Convert.ToDateTime(reader["PunchIn"]).TimeOfDay)).TotalHours;
                    }
                    else if (reader["LunchStart"] != DBNull.Value && reader["LunchEnd"] == DBNull.Value)
                    {
                        totalHours += DateTime.Today.Add(Convert.ToDateTime(reader["LunchStart"]).TimeOfDay)
                                      .Subtract(DateTime.Today.Add(Convert.ToDateTime(reader["PunchIn"]).TimeOfDay)).TotalHours;
                    }
                }

                conn.Close();

                //Add UserHoursLabel for user
                UserHoursLabel userHoursLabel = new UserHoursLabel(this.mainForm, user, totalHours);
                userHoursFlowLayout.Controls.Add(userHoursLabel);
            }

            dbcontext.Dispose();
        }
Esempio n. 14
0
        public static void InsertTestData(TimePunchDatabase.TimePunchEntities dbcontext)
        {
            TimePunchDatabase.User newUser = new TimePunchDatabase.User();
            PasswordHash           ph      = new PasswordHash("admin");

            //admin
            newUser.Username  = "******";
            newUser.Password  = Convert.ToBase64String(ph.ToArray());
            newUser.Role      = 0;
            newUser.FirstName = "Admin";
            newUser.LastName  = "smith";

            dbcontext.Users.Add(newUser);

            try
            {
                dbcontext.SaveChanges();
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch
            {
                Console.WriteLine("Unable to save new user to database");
            }

            //Bypassing ADO because adding multiple rows results in unique constraint errors from db
            SQLiteConnection conn = new SQLiteConnection("DataSource=./TimePunchV2.db");

            conn.Open();
            string sql = "BEGIN TRANSACTION; ";

            //test users
            string[] firstNames = { "Dakota", "Anna", "Jordan", "John", "Dillon", "Tony", "Shinji", "Asuka" };
            string[] lastNames  = { "Clark", "Mazer", "Packard", "Smith", "Burns", "Stark", "Ikari", "Soryu" };
            TimePunchDatabase.User[] newUsers = new TimePunchDatabase.User[firstNames.Length];

            for (int i = 0; i < firstNames.Length; i++)
            {
                string username = firstNames[i] + lastNames[i];
                string password = Convert.ToBase64String(new PasswordHash(username).ToArray());

                sql += String.Format("INSERT INTO Users (Username, Password, FirstName, LastName, Role) VALUES" +
                                     "(\"{0}\", \"{1}\", \"{2}\", \"{3}\", {4});", username, password, firstNames[i], lastNames[i], 1);
            }

            sql += "COMMIT;";
            SQLiteCommand command = new SQLiteCommand(sql, conn);

            command.ExecuteNonQuery();


            //get all the created users
            var users = from user in dbcontext.Users
                        where user.Username != "admin"
                        select user;

            sql = "BEGIN TRANSACTION;";

            //test TimePunches for test users
            foreach (var user in users)
            {
                for (int i = 8; i > 1; i--)
                {
                    TimePunchDatabase.TimePunch newPunch = new TimePunchDatabase.TimePunch();
                    //get random punch times
                    double[] times = new double[4];
                    times = getRandomTimes();

                    newPunch.UserID     = user.ID;
                    newPunch.Date       = DateTime.Today.Date.Subtract(new TimeSpan(i, 0, 0, 0)).ToString("O");
                    newPunch.PunchIn    = Convert.ToDateTime(newPunch.Date).AddHours(times[0]).ToString("o");
                    newPunch.LunchStart = Convert.ToDateTime(newPunch.Date).AddHours(times[1]).ToString("o");
                    newPunch.LunchEnd   = Convert.ToDateTime(newPunch.Date).AddHours(times[2]).ToString("o");
                    newPunch.PunchOut   = Convert.ToDateTime(newPunch.Date).AddHours(times[3]).ToString("o");
                    newPunch.isOpen     = 0;

                    sql += string.Format("INSERT INTO TimePunches (UserID, Date, PunchIn, LunchStart, LunchEnd, PunchOut, isOpen) VALUES " +
                                         "({0}, \"{1}\", \"{2}\", \"{3}\", \"{4}\", \"{5}\", 0);", newPunch.UserID, newPunch.Date, newPunch.PunchIn, newPunch.LunchStart, newPunch.LunchEnd, newPunch.PunchOut);
                }
            }

            sql += "COMMIT;";
            command.CommandText = sql;
            command.ExecuteNonQuery();


            //change start date in settings for 7 days before today
            string payPeriodStartDate = DateTime.Today.Subtract(new TimeSpan(6, 0, 0, 0)).ToString("o");

            command.CommandText = "UPDATE Settings SET payPeriodStartDate=\"" + payPeriodStartDate + "\" WHERE ID=1;";
            command.ExecuteNonQuery();

            conn.Close();
            dbcontext.Dispose();
        }
Esempio n. 15
0
        private void lunchEndButton_Click(object sender, EventArgs e)
        {
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();

            //find an open punch
            var openPunch = (from punch in dbcontext.TimePunches
                             where punch.UserID == auth.User.ID &&
                             punch.isOpen == 1
                             select punch).ToArray();
            //get settings
            var settings = (from setting in dbcontext.Settings
                            where setting.ID == 1
                            select setting).ToArray();


            if (openPunch.Length > 0)
            {
                var punch = openPunch[0];

                //check if they have already ended thier lunch
                if (punch.LunchEnd == null)
                {
                    //check if they started their lunch
                    if (punch.LunchStart != null)
                    {
                        //check if the minimum amount of minutes has passed
                        long currentUnixTime    = DateTimeOffset.Now.ToUnixTimeSeconds();
                        long lunchStartUnixTime = ((DateTimeOffset)DateTime.Today.Add(Convert.ToDateTime(punch.LunchStart).TimeOfDay).ToUniversalTime()).ToUnixTimeSeconds();
                        long timeDiff           = (currentUnixTime - lunchStartUnixTime) / 60;
                        //add a LunchEnd punch
                        if (timeDiff >= settings[0].minimumLunchMins)
                        {
                            punch.LunchEnd = DateTime.Now.ToString("o");

                            try
                            {
                                dbcontext.SaveChanges();
                                MessageBox.Show("You have clocked in from lunch!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                MessageBox.Show("Could not punch in from lunch. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            finally
                            {
                                dbcontext.Dispose();
                            }
                        }
                        else
                        {
                            MessageBox.Show("You need a minimum of " + settings[0].minimumLunchMins + " mins on your lunch", "End Lunch", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        MessageBox.Show("You have not started your lunch yet", "End Lunch", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("You have already ended your lunch!", "End Lunch", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("You are not clocked in!", "End Lunch", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 16
0
        private void ViewToday_Load(object sender, EventArgs e)
        {
            TimePunchDatabase.TimePunchEntities dbcontext = new TimePunchDatabase.TimePunchEntities();
            TimePunchDatabase.TimePunch[]       openPunch;
            if (this.punchID == 0)
            {
                string todaysDate = DateTime.Today.ToString("o");
                openPunch = (from punch in dbcontext.TimePunches
                             where punch.UserID == auth.User.ID &&
                             punch.Date == todaysDate
                             select punch).ToArray();
            }
            else
            {
                openPunch = (from punch in dbcontext.TimePunches
                             where punch.ID == this.punchID
                             select punch).ToArray();
            }

            if (openPunch.Length > 0)
            {
                var punch = openPunch[0];

                punchBox.Text = Convert.ToDateTime(punch.Date).ToShortDateString();

                //set the outputlabels
                if (punch.PunchIn != null)
                {
                    punchInOutputLabel.Text = DateTime.Today.Add(Convert.ToDateTime(punch.PunchIn).TimeOfDay).ToShortTimeString();
                }
                else
                {
                    punchInOutputLabel.Text = "N/A";
                }

                if (punch.LunchStart != null)
                {
                    lunchStartOutputLabel.Text = DateTime.Today.Add(Convert.ToDateTime(punch.LunchStart).TimeOfDay).ToShortTimeString();
                }
                else
                {
                    lunchStartOutputLabel.Text = "N/A";
                }

                if (punch.LunchEnd != null)
                {
                    lunchEndOutputLabel.Text = DateTime.Today.Add(Convert.ToDateTime(punch.LunchEnd).TimeOfDay).ToShortTimeString();
                }
                else
                {
                    lunchEndOutputLabel.Text = "N/A";
                }

                if (punch.PunchOut != null)
                {
                    punchOutOutputLabel.Text = DateTime.Today.Add(Convert.ToDateTime(punch.PunchOut).TimeOfDay).ToShortTimeString();
                }
                else
                {
                    punchOutOutputLabel.Text = "N/A";
                }

                //set outputlabels visible
                punchInOutputLabel.Visible    = true;
                lunchStartOutputLabel.Visible = true;
                lunchEndOutputLabel.Visible   = true;
                punchOutOutputLabel.Visible   = true;
            }
        }