Ejemplo n.º 1
0
        //Method for Selecting hours worked between two given DateTimes.
        //Selects TimeWorked from EmpTime table between 2 DateTimes, sets double Total to figure out hours worked in that time frame.
        public void selectOvertime(DateTime i, DateTime o)
        {
            TimeIO tio = new TimeIO();

            for (int x = 0; x < emps.Count(); x++)
            {
                //selectHours for all employees
                tio.selectHours(emps[x].getId(), i, o);
                //if employee's hours are greater than 40 and not equal to zero, populate lists
                if (tio.getTotal() > 40 && tio.getTotal() != 0)
                {
                    //adds employee ids to empIds list
                    getEmpIds().Add(emps[x].getId());
                    //add total from TimeIO BO to hours list
                    getHours().Add(tio.getTotal());
                }
            }

            //Display results
            for (int x = 0; x < empIds.Count(); x++)
            {
                tio.selectHours(empIds[x], i, o);
                Employee e1 = new Employee();
                e1.selectEmp(empIds[x]);


                Console.WriteLine("Hours worked between " + i + " and " + o + " for Employee " + e1.getFName() + " " + e1.getLName());
                Console.WriteLine("Overtime Hours Worked: " + ((int)(hours[x]) - 40) + " Hours and " + ((hours[x] - (int)(hours[x])) * 60) + " minutes.");
                Console.WriteLine(hours[x] - (int)hours[x] + "");
            }
        }
Ejemplo n.º 2
0
        public void timeSheetSelect(string id)
        {
            d1.DBSetup();

            d1.cmd = "Select * from EmpTime where EmpId ='" + id + "'";
            d1.SqlDataAdapter.SelectCommand.CommandText = d1.cmd;
            d1.SqlDataAdapter.SelectCommand.Connection  = d1.SqlDbConection2;
            try
            {
                d1.SqlDbConection2.Open();

                System.Data.SqlClient.SqlDataReader dr;
                dr = d1.SqlDataAdapter.SelectCommand.ExecuteReader();
                Console.WriteLine(d1.cmd);

                while (dr.Read())
                {
                    TimeIO t1 = new TimeIO(((String)dr.GetValue(1)), (DateTime)dr.GetValue(2), (DateTime)dr.GetValue(3), (String)dr.GetValue(4), (int)dr.GetValue(0), (bool)dr.GetValue(5), (bool)dr.GetValue(7));
                    getTS().Add(t1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Something happened: " + e);
            }
            finally
            {
                d1.SqlDbConection2.Close();
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //Set variables equal to the selected index number from the dropdown lists
            hin  = ddlHoursIn.SelectedIndex;
            min  = ddlMinutesIn.SelectedIndex;
            hout = ddlHoursOut.SelectedIndex;
            mout = ddlMinutesOut.SelectedIndex;
            r    = ddlReason.SelectedValue;
            year = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            //Try catch the if statement
            try
            {
                /*
                 * Use the employee id session object we got from the login page to
                 * use for the TimeIO constructor.
                 * We use the index number to tell which item is selected,
                 * and we have a filler item for each dropdown list. This means
                 * we have to subtract the index number by 1 to get the proper number
                 * for the hours and minutes.
                 * Create two date time objects for clock in and clock out and run insertTime().
                 */
                if (hin > 0 && min > 0 && hout > 0 && mout > 0)
                {
                    string id = Session["EmployeeID"].ToString();
                    hoursIn    = hin - 1;
                    minutesIn  = min - 1;
                    hoursOut   = hout - 1;
                    minutesOut = mout - 1;
                    dtIn       = new DateTime(date.Year, date.Month, date.Day, hoursIn, minutesIn, 00);
                    dtOut      = new DateTime(date.Year, date.Month, date.Day, hoursOut, minutesOut, 00);
                    TimeIO t1 = new TimeIO(id, dtIn, dtOut, r, 0, false, false);
                    t1.insertTime();

                    //Change the visibility of the lables depending on if the user is successful in
                    //inserting a time sheet
                    lblError.Visible   = false;
                    lblSuccess.Visible = true;
                }
                else
                {
                    //If the user hasn't selected an item for all dropdown lists
                    //we set the error label visible and success label invisible
                    lblSuccess.Visible = false;
                    lblError.Visible   = true;
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                //Finally we set the dropdown lists to the default index
                ddlHoursIn.SelectedIndex    = 0;
                ddlHoursOut.SelectedIndex   = 0;
                ddlMinutesIn.SelectedIndex  = 0;
                ddlMinutesOut.SelectedIndex = 0;
                ddlReason.SelectedIndex     = 0;
            }
        }
        //Method for Selecting hours worked between two given DateTimes.
        //Selects TimeWorked from EmpTime table between 2 DateTimes, sets double Total to figure out hours worked in that time frame.
        public void selectOvertime(DateTime i, DateTime o)
        {
            TimeIO tio = new TimeIO();

            for (int x = 0; x < emps.Count(); x++)
            {
                tio.selectHours(emps[x].getId(), i, o);
                if (tio.getTotal() > 40 && tio.getTotal() != 0)
                {
                    getEmpIds().Add(emps[x].getId());
                    getHours().Add(tio.getTotal());
                }
            }
        }