Example #1
0
 ///<summary>Will throw an exception if already clocked in.</summary>
 public static void ClockIn(long employeeNum)
 {
     //we'll get this again, because it may have been a while and may be out of date
     ClockEvent clockEvent=ClockEvents.GetLastEvent(employeeNum);
     if(clockEvent==null) {//new employee clocking in
         clockEvent=new ClockEvent();
         clockEvent.EmployeeNum=employeeNum;
         clockEvent.ClockStatus=TimeClockStatus.Home;
         ClockEvents.Insert(clockEvent);//times handled
     }
     else if(clockEvent.ClockStatus==TimeClockStatus.Break) {//only incomplete breaks will have been returned.
         //clocking back in from break
         clockEvent.TimeEntered2=MiscData.GetNowDateTime();
         clockEvent.TimeDisplayed2=clockEvent.TimeEntered2;
         ClockEvents.Update(clockEvent);
     }
     else {//normal clock in/out
         if(clockEvent.TimeDisplayed2.Year<1880) {//already clocked in
             throw new Exception(Lans.g("ClockEvents","Error.  Already clocked in."));
         }
         else {//clocked out for home or lunch.  Need to clock back in by starting a new row.
             TimeClockStatus tcs=clockEvent.ClockStatus;
             clockEvent=new ClockEvent();
             clockEvent.EmployeeNum=employeeNum;
             clockEvent.ClockStatus=tcs;
             ClockEvents.Insert(clockEvent);//times handled
         }
     }
 }
Example #2
0
 ///<summary>Will throw an exception if already clocked out.</summary>
 public static void ClockOut(long employeeNum,TimeClockStatus clockStatus)
 {
     ClockEvent clockEvent=ClockEvents.GetLastEvent(employeeNum);
     if(clockEvent==null) {//new employee never clocked in
         throw new Exception(Lans.g("ClockEvents","Error.  New employee never clocked in."));
     }
     else if(clockEvent.ClockStatus==TimeClockStatus.Break) {//only incomplete breaks will have been returned.
         throw new Exception(Lans.g("ClockEvents","Error.  Already clocked out for break."));;
     }
     else {//normal clock in/out
         if(clockEvent.TimeDisplayed2.Year<1880) {//clocked in.
             if(clockStatus==TimeClockStatus.Break) {//clocking out on break
                 //leave the half-finished event alone and start a new one
                 clockEvent=new ClockEvent();
                 clockEvent.EmployeeNum=employeeNum;
                 clockEvent.ClockStatus=TimeClockStatus.Break;
                 ClockEvents.Insert(clockEvent);//times handled
             }
             else {//finish the existing event
                 clockEvent.TimeEntered2=MiscData.GetNowDateTime();
                 clockEvent.TimeDisplayed2=clockEvent.TimeEntered2;
                 clockEvent.ClockStatus=clockStatus;//whatever the user selected
                 ClockEvents.Update(clockEvent);
             }
         }
         else {//clocked out for home or lunch.
             throw new Exception(Lans.g("ClockEvents","Error.  Already clocked out."));
         }
     }
 }
Example #3
0
        ///<summary>Will throw an exception if already clocked in.</summary>
        public static void ClockIn(long employeeNum)
        {
            //we'll get this again, because it may have been a while and may be out of date
            ClockEvent clockEvent = ClockEvents.GetLastEvent(employeeNum);

            if (clockEvent == null)           //new employee clocking in
            {
                clockEvent             = new ClockEvent();
                clockEvent.EmployeeNum = employeeNum;
                clockEvent.ClockStatus = TimeClockStatus.Home;
                ClockEvents.Insert(clockEvent);                       //times handled
            }
            else if (clockEvent.ClockStatus == TimeClockStatus.Break) //only incomplete breaks will have been returned.
            //clocking back in from break
            {
                clockEvent.TimeEntered2   = MiscData.GetNowDateTime();
                clockEvent.TimeDisplayed2 = clockEvent.TimeEntered2;
                ClockEvents.Update(clockEvent);
            }
            else                                           //normal clock in/out
            {
                if (clockEvent.TimeDisplayed2.Year < 1880) //already clocked in
                {
                    throw new Exception(Lans.g("ClockEvents", "Error.  Already clocked in."));
                }
                else                  //clocked out for home or lunch.  Need to clock back in by starting a new row.
                {
                    TimeClockStatus tcs = clockEvent.ClockStatus;
                    clockEvent             = new ClockEvent();
                    clockEvent.EmployeeNum = employeeNum;
                    clockEvent.ClockStatus = tcs;
                    ClockEvents.Insert(clockEvent);                    //times handled
                }
            }
        }
Example #4
0
        ///<summary>Gets directly from the database.  If the last event is a completed break, then it instead grabs the half-finished clock in.  Other possibilities include half-finished clock in which truly was the last event, a finished clock in/out, a half-finished clock out for break, or null for a new employee.</summary>
        public static ClockEvent GetLastEvent(long employeeNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <ClockEvent>(MethodBase.GetCurrentMethod(), employeeNum));
            }
            string command = "SELECT * FROM clockevent WHERE EmployeeNum=" + POut.Long(employeeNum)
                             + " ORDER BY TimeDisplayed1 DESC";

            command = DbHelper.LimitOrderBy(command, 1);
            ClockEvent ce = Crud.ClockEventCrud.SelectOne(command);

            if (ce != null && ce.ClockStatus == TimeClockStatus.Break && ce.TimeDisplayed2.Year > 1880)
            {
                command = "SELECT * FROM clockevent WHERE EmployeeNum=" + POut.Long(employeeNum) + " "
                          + "AND ClockStatus != 2 "             //not a break
                          + "ORDER BY TimeDisplayed1 DESC";
                command = DbHelper.LimitOrderBy(command, 1);
                ce      = Crud.ClockEventCrud.SelectOne(command);
                return(ce);
            }
            else
            {
                return(ce);
            }
        }
Example #5
0
        ///<summary></summary>
        public static bool IsClockedIn(long employeeNum)
        {
            ClockEvent clockEvent = ClockEvents.GetLastEvent(employeeNum);

            if (clockEvent == null)           //new employee
            {
                return(false);
            }
            else if (clockEvent.ClockStatus == TimeClockStatus.Break)           //only incomplete breaks will have been returned.
            //so currently on break
            {
                return(false);
            }
            else                                           //normal clock in/out row found
            {
                if (clockEvent.TimeDisplayed2.Year < 1880) //already clocked in
                {
                    return(true);
                }
                else                  //clocked out for home or lunch.
                {
                    return(false);
                }
            }
        }
Example #6
0
 ///<summary></summary>
 public FormClockEventEdit(ClockEvent clockEventCur)
 {
     //
     // Required for Windows Form Designer support
     //
     InitializeComponent();
     Lan.F(this);
     ClockEventCur=clockEventCur.Copy();
 }
Example #7
0
 ///<summary></summary>
 public static void Update(ClockEvent clockEvent)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         Meth.GetVoid(MethodBase.GetCurrentMethod(), clockEvent);
         return;
     }
     Crud.ClockEventCrud.Update(clockEvent);
 }
Example #8
0
 ///<summary></summary>
 public static long Insert(ClockEvent clockEvent)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         clockEvent.ClockEventNum = Meth.GetLong(MethodBase.GetCurrentMethod(), clockEvent);
         return(clockEvent.ClockEventNum);
     }
     return(Crud.ClockEventCrud.Insert(clockEvent));
 }
Example #9
0
		public static long InsertWorkPeriod(long emp,DateTime start,DateTime stop) {
			ClockEvent ce=new ClockEvent();
			ce.ClockStatus=TimeClockStatus.Home;
			ce.EmployeeNum=emp;
			ce.TimeDisplayed1=start;
			ce.TimeEntered1=start;
			ce.TimeDisplayed2=stop;
			ce.TimeEntered2=stop;
			ce.ClockEventNum = ClockEvents.Insert(ce);
			ClockEvents.Update(ce);//Updates TimeDisplayed1 because it defaults to now().
			return ce.ClockEventNum;
		}
Example #10
0
		public static long InsertBreak(long emp,DateTime start,int minutes) {
			ClockEvent ce=new ClockEvent();
			ce.ClockStatus=TimeClockStatus.Break;
			ce.EmployeeNum=emp;
			ce.TimeDisplayed1=start;
			ce.TimeEntered1=start;
			ce.TimeDisplayed2=start.AddMinutes(minutes);
			ce.TimeEntered2=start.AddMinutes(minutes);
			ce.ClockEventNum = ClockEvents.Insert(ce);
			ClockEvents.Update(ce);//Updates TimeDisplayed1 because it defaults to now().
			return ce.ClockEventNum;
		}
Example #11
0
        //<summary></summary>
        //public DateTime TimeEnteredTwo;
        //<summary></summary>
        //public DateTime TimeDisplayedTwo;

        ///<summary></summary>
        public ClockEvent Copy()
        {
            ClockEvent c = new ClockEvent();

            c.ClockEventNum = ClockEventNum;
            c.EmployeeNum   = EmployeeNum;
            c.TimeEntered   = TimeEntered;
            c.TimeDisplayed = TimeDisplayed;
            c.ClockIn       = ClockIn;
            c.ClockStatus   = ClockStatus;
            c.Note          = Note;
            return(c);
        }
Example #12
0
        ///<summary>Updates the employee's ClockStatus if necessary based on their clock events. This method handles future clock events as having
        ///already occurred. Ex: If I clock out for home at 6:00 but edit my time card to say 7:00, at 6:30 my status will say Home.</summary>
        public static void UpdateClockStatus(long employeeNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), employeeNum);
                return;
            }
            //Get the last clockevent for the employee. Will include clockevent with "in" before NOW, and "out" anytime before 23:59:59 of TODAY.
            string command = @"SELECT * FROM clockevent 
				WHERE TimeDisplayed2<="                 + DbHelper.DateAddSecond(DbHelper.DateAddDay(DbHelper.Curdate(), "1"), "-1") + " AND TimeDisplayed1<=" + DbHelper.Now() + @"
				AND EmployeeNum="                 + POut.Long(employeeNum) + @"
				ORDER BY IF(YEAR(TimeDisplayed2) < 1880,TimeDisplayed1,TimeDisplayed2) DESC"                ;

            command = DbHelper.LimitOrderBy(command, 1);
            ClockEvent clockEvent  = Crud.ClockEventCrud.SelectOne(command);
            Employee   employee    = GetEmp(employeeNum);
            Employee   employeeOld = employee.Copy();

            if (clockEvent != null && clockEvent.TimeDisplayed2 > DateTime.Now)         //Future time manual clock out.
            {
                employee.ClockStatus = Lans.g("ContrStaff", "Manual Entry");
            }
            else if (clockEvent == null ||       //Employee has never clocked in
                     (clockEvent.TimeDisplayed2.Year > 1880 && clockEvent.ClockStatus == TimeClockStatus.Home))            //Clocked out for home
            {
                employee.ClockStatus = Lans.g("enumTimeClockStatus", TimeClockStatus.Home.ToString());
            }
            else if (clockEvent.TimeDisplayed2.Year > 1880 && clockEvent.ClockStatus == TimeClockStatus.Lunch)           //Clocked out for lunch
            {
                employee.ClockStatus = Lans.g("enumTimeClockStatus", TimeClockStatus.Lunch.ToString());
            }
            else if (clockEvent.TimeDisplayed1.Year > 1880 && clockEvent.TimeDisplayed2.Year < 1880 && clockEvent.ClockStatus == TimeClockStatus.Break)
            {
                employee.ClockStatus = Lans.g("enumTimeClockStatus", TimeClockStatus.Break.ToString());
            }
            else if (clockEvent.TimeDisplayed2.Year > 1880 && clockEvent.ClockStatus == TimeClockStatus.Break)           //Clocked back in from break
            {
                employee.ClockStatus = Lans.g("ContrStaff", "Working");
            }
            else              //The employee has not clocked out yet.
            {
                employee.ClockStatus = Lans.g("ContrStaff", "Working");
            }
            Crud.EmployeeCrud.Update(employee, employeeOld);
        }
Example #13
0
        ///<summary>Will throw an exception if already clocked out.</summary>
        public static void ClockOut(long employeeNum, TimeClockStatus clockStatus)
        {
            ClockEvent clockEvent = ClockEvents.GetLastEvent(employeeNum);

            if (clockEvent == null)           //new employee never clocked in
            {
                throw new Exception(Lans.g("ClockEvents", "Error.  New employee never clocked in."));
            }
            else if (clockEvent.ClockStatus == TimeClockStatus.Break)           //only incomplete breaks will have been returned.
            {
                throw new Exception(Lans.g("ClockEvents", "Error.  Already clocked out for break."));;
            }
            else                                              //normal clock in/out
            {
                if (clockEvent.TimeDisplayed2.Year < 1880)    //clocked in.
                {
                    if (clockStatus == TimeClockStatus.Break) //clocking out on break
                    //leave the half-finished event alone and start a new one
                    {
                        clockEvent             = new ClockEvent();
                        clockEvent.EmployeeNum = employeeNum;
                        clockEvent.ClockStatus = TimeClockStatus.Break;
                        ClockEvents.Insert(clockEvent); //times handled
                    }
                    else                                //finish the existing event
                    {
                        clockEvent.TimeEntered2   = MiscData.GetNowDateTime();
                        clockEvent.TimeDisplayed2 = clockEvent.TimeEntered2;
                        clockEvent.ClockStatus    = clockStatus;                   //whatever the user selected
                        ClockEvents.Update(clockEvent);
                    }
                }
                else                  //clocked out for home or lunch.
                {
                    throw new Exception(Lans.g("ClockEvents", "Error.  Already clocked out."));
                }
            }
        }
Example #14
0
		///<summary>Returns true if two clock events overlap. Useful for determining if a break applies to a given clock event.  
		///Does not matter which order clock events are provided.</summary>
		private static bool timeClockEventsOverlapHelper(ClockEvent clockEvent1,ClockEvent clockEvent2) {
			//Visual representation
			//ClockEvent1:            o----------------o
			//ClockEvent2:o---------------o   or  o-------------------o
			if(clockEvent2.TimeDisplayed2>clockEvent1.TimeDisplayed1 
				&& clockEvent2.TimeDisplayed1<clockEvent1.TimeDisplayed2) {
					return true;
			}
			return false;
		}
Example #15
0
		///<summary></summary>
		public static void Update(ClockEvent clockEvent){
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){
				Meth.GetVoid(MethodBase.GetCurrentMethod(),clockEvent);
				return;
			}
			Crud.ClockEventCrud.Update(clockEvent);
		}
Example #16
0
		///<summary></summary>
		public static long Insert(ClockEvent clockEvent){
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){
				clockEvent.ClockEventNum=Meth.GetLong(MethodBase.GetCurrentMethod(),clockEvent);
				return clockEvent.ClockEventNum;
			}
			return Crud.ClockEventCrud.Insert(clockEvent);
		}