Exemplo n.º 1
0
        public void TimeSearch(SearchWindow window)
        {
            int      selectedUserId    = Convert.ToInt32(window.CbSearchTimesUserId.SelectedValue.ToString());
            DateTime?selectedStartDate = window.DpSearchTimesStartDate.SelectedDate;
            DateTime?selectedEndDate   = window.DpSearchTimesEndDate.SelectedDate;

            List <WorkPeriod> periods = new WorkPeriodCRUD().GetWorkPeriods();

            if (selectedUserId > 0)
            {
                periods.RemoveAll(x => x.UserId != selectedUserId);
            }

            if (selectedStartDate != null)
            {
                periods.RemoveAll(x => x.Start >= Convert.ToDateTime(selectedStartDate));
            }

            if (selectedEndDate != null)
            {
                periods.RemoveAll(x => x.End <= Convert.ToDateTime(selectedEndDate));
            }

            if (periods.Count > 0)
            {
                BindDataGrid(periods);
                window.Close();
            }
            else
            {
                MessageBox.Show("There are no results", "Information");
            }
        }
Exemplo n.º 2
0
        public void UpdateScreenUI(bool working)
        {
            List <Job> jobs = new JobCRUD().GetJobs();

            if (working)
            {
                WorkPeriod wp = new WorkPeriodCRUD().GetWorkPeriodByUserIdAndWorkPeriodId(CurrentUser.UserId, CurrentUser.WorkPeriodId);

                this.GbJobComboBox.Visibility = Visibility.Hidden;
                this.GbJobLabel.Visibility    = Visibility.Visible;

                this.LblJobName.Content = jobs.Where(x => x.JobId == wp.JobId).First().Name;

                this.BtnClock.Content = "Clock Out";
            }
            else
            {
                this.GbJobComboBox.Visibility = Visibility.Visible;
                this.GbJobLabel.Visibility    = Visibility.Hidden;

                this.CbJobId.ItemsSource       = jobs;
                this.CbJobId.DisplayMemberPath = "Name";
                this.CbJobId.SelectedValuePath = "JobId";

                this.BtnClock.Content = "Clock In";
            }
        }
Exemplo n.º 3
0
        private void BtnSearch_Click(object sender, RoutedEventArgs e)
        {
            List <WorkPeriod> periods = new List <WorkPeriod>();

            if (LbUsers.SelectedItem != null)
            {
                User user = (User)LbUsers.SelectedItem;

                DateTime startDate = (DateTime)dpStartDate.SelectedDate;
                DateTime endDate   = (DateTime)dpEndDate.SelectedDate;

                periods = new WorkPeriodCRUD().GetWorkPeriodsByUserId(user.UserId, startDate, endDate);

                for (int i = 0; i < periods.Count; i++)
                {
                    if (periods[i].End != null)
                    {
                        DateTime periodStartDate = periods[i].Start;
                        DateTime periodEndDate   = (DateTime)periods[i].End;
                        int      hours           = periods[i].WorkPeriodTime.Value.Hours;
                        int      minutes         = periods[i].WorkPeriodTime.Value.Minutes;

                        // set fields
                        periods[i].WorkPeriodTime     = periodEndDate.Subtract(periods[i].Start);
                        periods[i].WorkPeriodReadable = hours + "Hours and " + minutes + " minutes";
                        periods[i].StartHour          = periods[i].Start.Hour;
                        periods[i].StartMinute        = periods[i].Start.Minute;
                        periods[i].EndHour            = periodEndDate.Hour;
                        periods[i].EndMinute          = periodEndDate.Minute;
                    }
                }
            }

            dgData.ItemsSource = periods;
        }
Exemplo n.º 4
0
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            int startHour   = String.IsNullOrEmpty(TxtStartHour.Text) == true ? 0 : Convert.ToInt32(TxtStartHour.Text);
            int endHour     = String.IsNullOrEmpty(TxtEndHour.Text) == true ? 0 : Convert.ToInt32(TxtEndHour.Text);
            int startMinute = String.IsNullOrEmpty(TxtStartMinute.Text) == true ? 0 : Convert.ToInt32(TxtStartMinute.Text);
            int endMinute   = String.IsNullOrEmpty(TxtEndMinute.Text) == true ? 0 : Convert.ToInt32(TxtEndMinute.Text);

            DateTime startDate = Convert.ToDateTime(TxtStartDate.Text);
            DateTime endDate   = Convert.ToDateTime(TxtEndDate.Text);

            DateTime newStartDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, startHour, startMinute, 0);
            DateTime newEndDate   = new DateTime(endDate.Year, endDate.Month, endDate.Day, endHour, endMinute, 0);

            WorkPeriod updatedPeriod = (WorkPeriod)this.DataContext;

            updatedPeriod.Start = newStartDate;
            updatedPeriod.End   = newEndDate;

            int result = new WorkPeriodCRUD().Update(updatedPeriod);

            if (result > 0)
            {
                MessageBox.Show("Work period updated", "Success");
                this.Close();
            }
            else
            {
                MessageBox.Show("Failed to update work period", "Failure");
            }
        }
Exemplo n.º 5
0
        private void BtnClock_Click(object sender, RoutedEventArgs e)
        {
            int  result      = 0;
            User currentUser = (User)this.DataContext;

            if (currentUser.WorkPeriodId > 0)
            {
                // clock out
                WorkPeriodCRUD crud   = new WorkPeriodCRUD();
                WorkPeriod     period = crud.Read(currentUser.WorkPeriodId);
                period.End = DateTime.Now;
                int clockOutIsComplete = crud.Update(period);

                if (clockOutIsComplete > 0)
                {
                    currentUser.WorkPeriodId = 0;
                    currentUser.Working      = false;
                    new UserCRUD().Update(currentUser);
                }
                UpdateScreenUI(false);
            }
            else
            {
                if (CbJobId.SelectedItem != null)
                {
                    // clock in
                    WorkPeriod period = new WorkPeriod();
                    try
                    {
                        period.UserId = Convert.ToInt32(TxtUserId.Text);
                        period.Start  = DateTime.Now;
                        period.End    = null;
                        period.JobId  = Convert.ToInt32(CbJobId.SelectedValue);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Select a job to work on", "Notice");
                        return;
                    }

                    result = new WorkPeriodCRUD().Create(period);
                    this.TxtWorkPeriodId.Text = result.ToString();

                    currentUser.WorkPeriodId = result;
                    currentUser.Working      = true;
                    new UserCRUD().Update(currentUser);

                    UpdateScreenUI(true);
                }
                else
                {
                    MessageBox.Show("Select a job to work on", "Notice");
                }
            }
        }
Exemplo n.º 6
0
        public string GetWeeklyWorkPeriodReadableForUser(User user)
        {
            DateTime startOfWeek = DateTime.Now;
            DateTime endOfWeek   = DateTime.Now;
            string   readable    = "";

            // get start of week
            while (startOfWeek.DayOfWeek != System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek)
            {
                startOfWeek = startOfWeek.AddDays(-1);
            }

            // get end of week
            while (endOfWeek.DayOfWeek != System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek)
            {
                endOfWeek = endOfWeek.AddDays(1);
            }

            // pull work periods between start and end of week
            List <WorkPeriod> workPeriods = new WorkPeriodCRUD().GetWorkPeriodsByUserId(user.UserId, startOfWeek, endOfWeek);

            if (workPeriods.Count > 0)
            {
                // remove any unfinished work periods
                workPeriods.RemoveAll(x => x.End == null);

                // if any work periods are left...
                if (workPeriods.Count > 0)
                {
                    TimeSpan total = new TimeSpan();

                    // look through the work periods...
                    foreach (WorkPeriod period in workPeriods)
                    {
                        // subtract the end date from the start date to get total hours in the work period
                        TimeSpan span = Convert.ToDateTime(period.End).Subtract(period.Start);
                        // add that result to the total timespan
                        total += span;
                    }

                    readable = total.Hours + " hours and " + total.Minutes + " minutes";
                }
                else
                {
                    readable = "No Hours, Clocked In";
                }
            }
            else
            {
                readable = "No Hours";
            }

            return(readable);
        }
Exemplo n.º 7
0
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            int        result = 0;
            WorkPeriod period = (WorkPeriod)this.DataContext;

            if (period.StartMeridiem == 1)
            {
                period.StartHour += 12;
            }

            if (period.EndMeridiem == 1)
            {
                period.EndHour += 12;
            }

            DateTime start = new DateTime(period.Start.Year, period.Start.Month, period.Start.Day, period.StartHour, period.StartMinute, 0);

            period.Start = new DateTime(start.Year, start.Month, start.Day, period.StartHour, period.StartMinute, 0);

            try
            {
                DateTime end = Convert.ToDateTime(period.End);
                period.End = new DateTime(end.Year, end.Month, end.Day, period.EndHour, period.EndMinute, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
                return;
            }

            result = new WorkPeriodCRUD().Update(period);

            if (result > 0)
            {
                MessageBox.Show("Work period for user was updated", "Success");
                this.Close();
            }
            else
            {
                MessageBox.Show("Unable to update work period for user", "Success");
            }
        }
        private void BtnClock_Click(object sender, RoutedEventArgs e)
        {
            int  result      = 0;
            User currentUser = (User)this.DataContext;

            if (currentUser.WorkPeriodId > 0)
            {
                // clock out
                WorkPeriodCRUD crud   = new WorkPeriodCRUD();
                WorkPeriod     period = crud.Read(currentUser.WorkPeriodId);
                period.End = DateTime.Now;
                int clockOutIsComplete = crud.Update(period);

                if (clockOutIsComplete > 0)
                {
                    currentUser.WorkPeriodId = 0;
                    currentUser.Working      = false;
                    new UserCRUD().Update(currentUser);
                }
                this.BtnClock.Content = "Clock In";
            }
            else
            {
                // clock in
                WorkPeriod period = new WorkPeriod()
                {
                    UserId = Convert.ToInt32(TxtUserId.Text),
                    Start  = DateTime.Now,
                    End    = null,
                };
                result = new WorkPeriodCRUD().Create(period);
                this.TxtWorkPeriodId.Text = result.ToString();

                currentUser.WorkPeriodId = result;
                currentUser.Working      = true;
                new UserCRUD().Update(currentUser);

                this.BtnClock.Content = "Clock Out";
            }
        }
Exemplo n.º 9
0
        public List <WorkPeriod> FormatDataGrid(List <WorkPeriod> periods)
        {
            if (periods == null)
            {
                periods = new WorkPeriodCRUD().GetWorkPeriods();
            }

            for (int i = 0; i < periods.Count; i++)
            {
                periods[i].UserName = new UserCRUD().Read(periods[i].UserId).Name;
                periods[i].JobName  = new JobCRUD().Read(periods[i].JobId).Name;

                DateTime periodStartDate = periods[i].Start;
                if (periods[i].End != null)
                {
                    DateTime periodEndDate = (DateTime)periods[i].End;

                    // set fields
                    periods[i].WorkPeriodTime     = periodEndDate.Subtract(periods[i].Start);
                    periods[i].WorkPeriodReadable = periods[i].WorkPeriodTime.Value.Hours + "Hours and " + periods[i].WorkPeriodTime.Value.Minutes + " minutes";
                    periods[i].StartHour          = periods[i].Start.Hour;
                    periods[i].StartMinute        = periods[i].Start.Minute;
                    periods[i].EndHour            = periodEndDate.Hour;
                    periods[i].EndMinute          = periodEndDate.Minute;
                }
                else
                {
                    // end time is null, they are currently clocked in
                    // set fields
                    periods[i].WorkPeriodTime     = null;
                    periods[i].WorkPeriodReadable = "Clocked In";
                    periods[i].StartHour          = periods[i].Start.Hour;
                    periods[i].StartMinute        = periods[i].Start.Minute;
                    periods[i].EndHour            = 0;
                    periods[i].EndMinute          = 0;
                }
            }
            return(periods);
        }
Exemplo n.º 10
0
        private void BtnDestroy_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to delete this user? This will also delete all of their time entries.", "Warning", MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                // delete user
                int result = new UserCRUD().Destroy(GetSelectedUser().UserId);

                if (result > 0)
                {
                    MessageBox.Show("User was deleted", "Success");
                    // delete user time entires
                    int deleteEntriesResult = new WorkPeriodCRUD().DestroyAllWorkPeriodsByUserId(GetSelectedUser().UserId);

                    BindDataGrid(null);
                }
                else
                {
                    MessageBox.Show("Unable to delete user", "Failure");
                }
            }
        }
Exemplo n.º 11
0
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            int        result = 0;
            WorkPeriod period = (WorkPeriod)this.DataContext;

            if (period.UserId == 0)
            {
                MessageBox.Show("Select a user", "Notice");
                return;
            }

            if (period.Start == null)
            {
                MessageBox.Show("Select a start date", "Notice");
                return;
            }

            period.Start = period.Start.AddHours(period.StartHour).AddMinutes(period.StartMinute);

            if (Convert.ToBoolean(ChkClockedIn.IsChecked))
            {
                period.End = null;
            }
            else
            {
                if (period.End == null)
                {
                    MessageBox.Show("Select an end date", "Notice");
                    return;
                }

                if (period.Start.Date > Convert.ToDateTime(period.End).Date)
                {
                    // start date is later than the end date
                    MessageBox.Show("Start date is set after the end date. Please make sure the start date begins before end date", "Notice");
                    return;
                }

                if (period.Start.Date.Day != Convert.ToDateTime(period.End).Date.Day)
                {
                    MessageBox.Show("Unable to create a work period that exceeds one day. Please change the start and end date", "Notice");
                    return;
                }

                if (period.EndMeridiem == 1)
                {
                    period.EndHour += 12;
                }

                try
                {
                    period.End = Convert.ToDateTime(period.End).AddHours(period.EndHour).AddMinutes(period.EndMinute);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                    return;
                }
            }

            if (period.StartMeridiem == 1)
            {
                period.StartHour += 12;
            }


            // check if selected user is clocked in
            // if clocked in, clock him out of that current period, using the current time
            // then, clock him in to the current period by creating a new period
            // show dialouge saying that youre clocking him out and clocking him in to a new time period

            int  selectedUserId = (int)CbUserId.SelectedValue;
            User currentUser    = new UserCRUD().Read(selectedUserId);

            if (currentUser.Working && currentUser.WorkPeriodId > 0)
            {
                // this current user is working
                // do you want to clock them out and create new work period?
                MessageBoxResult messageBoxResult = MessageBox.Show("This user is currently clocked in. Creating this work period will clock them out of their current work period and create a new work period. Are you sure?", "Notice", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (messageBoxResult == MessageBoxResult.No)
                {
                    return;
                }
                else
                {
                    // current work period end is now
                    WorkPeriod workPeriod = new WorkPeriodCRUD().Read(currentUser.WorkPeriodId);
                    workPeriod.End = DateTime.Now;
                    new WorkPeriodCRUD().Update(workPeriod);

                    // clock the user out
                    currentUser.WorkPeriodId = 0;
                    currentUser.Working      = false;
                    int removeUserCurrentWorkPeriodId = new UserCRUD().Update(currentUser);
                }
            }

            result = new WorkPeriodCRUD().Create(period);

            if (period.End == null)
            {
                // update user to be clocked in to current period

                if (selectedUserId > 0 && result > 0)
                {
                    currentUser.WorkPeriodId = result;
                    currentUser.Working      = true;

                    new UserCRUD().Update(currentUser);
                }
            }

            if (result > 0)
            {
                MessageBox.Show("Work period for user was created", "Success");
                this.Close();
            }
            else
            {
                MessageBox.Show("Unable to create work period for user", "Success");
            }
        }