Ejemplo n.º 1
0
        /// <summary>
        /// add a workers hours to the database
        /// </summary>
        /// <param name="empHours"></param>
        public void AddHours(EmployeeHours empHours)
        {
            // create connection
            SqlConnection dbConnection = new SqlConnection
            {
                ConnectionString = ConnectionHelper.GetConnectionString()
            };

            dbConnection.Open();

            using (dbConnection)
            {
                // implement the stored procedure command
                SqlCommand command = new SqlCommand("sp_EmpHours_InsertEmployeeHours", dbConnection);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                // pass through the parameters
                command.Parameters.Add(new SqlParameter("@empid", empHours.EmpHoursID));
                command.Parameters.Add(new SqlParameter("@workdate", empHours.WorkDate));
                command.Parameters.Add(new SqlParameter("@hours", empHours.Hours));

                // run the command
                command.ExecuteNonQuery();
            }
        }
Ejemplo n.º 2
0
        public async Task AddEmployeeHours_WhenNotEmptyTable_KeepId_ConflictingKeyValues()
        {
            await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 4 });

            await dbContext.EmployeeHoursCollection.AddAsync(
                new EmployeeHours { EmployeeHoursId = 100, Value = 100, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 });

            await dbContext.SaveChangesAsync();

            var emp = new EmployeeHours {
                EmployeeHoursId = 100, Value = 100, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4
            };

            var  dao      = new PostgresDataAccessObjectService(dbContext);
            bool exThrown = false;

            try {
                exThrown = true;
                dao.AddEmployeeHours(emp, true);
            } catch (Exception ex) {
                Assert.Equal(typeof(ArgumentException), ex.GetType());
                Assert.Equal("EmployeeHours with EmployeeHoursId: 100 already exists", ex.Message);
            }
            Assert.True(exThrown);
        }
Ejemplo n.º 3
0
        public async Task AddEmployeeHours_Fails_WhenAddedAlreadyWithTheSameTimePeriodEndEmployeeId()
        {
            await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 4 });

            await dbContext.EmployeeHoursCollection.AddAsync(
                new EmployeeHours { EmployeeHoursId = 100, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 });

            await dbContext.SaveChangesAsync();

            var eh = new EmployeeHours {
                EmployeeHoursId = 101, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4
            };

            var  dao      = new PostgresDataAccessObjectService(dbContext);
            bool exThrown = false;

            try {
                exThrown = true;
                dao.AddEmployeeHours(eh);
            } catch (Exception e) {
                Assert.Equal(typeof(ArgumentException), e.GetType());
                Assert.Equal("EmployeeHours with EmployeeId: 4 and TimePeriod 02.01.2019_08.01.2019 already exists", e.Message);
            }
            var coll = dao.GetEmployeeHoursForAnEmployee(4);

            Assert.Single(coll);
            Assert.True(exThrown);
        }
Ejemplo n.º 4
0
        private void computeAdvanceOT()
        {
            // ********************
            // *** Advance OT *****
            // ********************
            if (arrivedEarlierThanScheduled &&
                isWithinAdvanceOtPeriod)
            {
                var baseTimeIn = scheduledTimeIn;
                //If regular hour is less than an hour, all will be recorded as Advance ot
                if (!clockOutGreaterThanNDEndTime)
                {
                    baseTimeIn = clockOut.Value;
                }

                TimeSpan advancedOTHoursCount = baseTimeIn.ChangeSeconds(0, 0) - clockIn.ChangeSeconds(0, 0);
                var      allowedHours         = ComputeTotalAllowedHours(Math.Round(advancedOTHoursCount.TotalHours, 2));
                if (allowedHours > 0)
                {
                    EmployeeHours advancedOTHours =
                        new EmployeeHours
                    {
                        OriginAttendanceId = attendance.AttendanceId,
                        Date       = day,
                        EmployeeId = attendance.EmployeeId,
                        Hours      = allowedHours,
                        Type       = Entities.Enums.RateType.OverTime
                    };

                    _employeeHoursRepository.Add(advancedOTHours);
                }
            }
        }
        //Search employee by ID
        public List <EmployeeHours> SelectEmpIDHours(int id)
        {
            //1- Connection
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = ConnectionHelper.getConnectionString();
            conn.Open();

            using (conn)
            {
                //2- Command
                SqlCommand command = new SqlCommand("sp_EmpHours_SelectEmployeeWorkDateAndHoursByID", conn);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                //3a - Run command (send)
                command.Parameters.Add(new SqlParameter("@empID", id));

                //3b - run command (read)
                SqlDataReader reader = command.ExecuteReader();

                //4 - Reads rows and into employee objects then add them to the list
                List <EmployeeHours> empHrs = new List <EmployeeHours>();

                //Read method return true or false - moves reader pointer into the next row
                while (reader.Read())
                {
                    EmployeeHours newEmpHrs = new EmployeeHours();
                    newEmpHrs.WorkDate = Convert.ToDateTime(reader["WorkDate"]);
                    newEmpHrs.Hours    = Convert.ToDecimal(reader["Hours"]);
                    empHrs.Add(newEmpHrs);
                }

                return(empHrs);
            }
        }
Ejemplo n.º 6
0
        public async Task AddEmployeeHours_WhenNotEmptyTable()
        {
            await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 4 });

            await dbContext.EmployeeHoursCollection.AddAsync(
                new EmployeeHours { EmployeeHoursId = 100, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 });

            await dbContext.SaveChangesAsync();

            var eh = new EmployeeHours();

            eh.EmployeeId = 4;
            eh.Value      = 90;
            eh.TimePeriod = "02.03.2019_08.03.2019";

            var dao = new PostgresDataAccessObjectService(dbContext);

            dao.AddEmployeeHours(eh);

            var coll = dao.GetEmployeeHoursForAnEmployee(4);

            Assert.Equal(2, coll.Count);
            Assert.Equal(100f, coll[0].Value);
            Assert.Equal(90f, coll[1].Value);
            Assert.Equal(100, coll[0].EmployeeHoursId);
            Assert.Equal(101, coll[1].EmployeeHoursId);
        }
Ejemplo n.º 7
0
 private void OnTextChangeCommand(object obj)
 {
     if (EmployeeHours != null)
     {
         TotalHours = EmployeeHours.Sum(x => x.HoursWorked);
     }
 }
Ejemplo n.º 8
0
        public EmployeeHours EmployeeHoursLastChanged()
        {
            // declare object for data
            EmployeeHours eh = new EmployeeHours();
            //2. Create a connection object
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = @"Data Source=127.0.0.1;Initial Catalog=PE2_Project_Employee_Hours;User ID=sa;Password=vRdoZJPoyev4KAx7vLB";
            conn.Open();

            //3.Create a command object
            SqlCommand cmd = new SqlCommand("sp_EmployeeHours_lastUpdated", conn);

            //4.Execute the command - insert, update, delete
            SqlDataReader reader = cmd.ExecuteReader();

            //5.Handle the results
            if (reader.Read())
            {
                eh = new EmployeeHours();
                eh.EmployeeHoursId = Convert.ToInt32(reader["EmployeeHoursId"]);
                eh.EmployeeId      = Convert.ToInt32(reader["EmployeeId"]);
                eh.FullName        = Convert.ToString(reader["FullName"]);
                eh.WorkDate        = Convert.ToDateTime(reader["WorkDate"]);
                eh.HoursWorked     = Convert.ToDouble(reader["HoursWorked"]);
            }

            conn.Close();
            return(eh);
        }
Ejemplo n.º 9
0
        public List <EmployeeHours> GetAllEmployeeHours()
        {
            List <EmployeeHours> listOfEmps = new List <EmployeeHours>();

            //2. Create a connection object
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = @"Data Source=127.0.0.1;Initial Catalog=PE2_Project_Employee_Hours;User ID=sa;Password=vRdoZJPoyev4KAx7vLB";
            conn.Open();

            //3.Create a command object
            SqlCommand cmd = new SqlCommand("sp_EmployeeHours_SelectAll", conn);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            //4.Execute the command - select
            SqlDataReader reader = cmd.ExecuteReader();

            //5.Handle the results
            while (reader.Read())
            {
                EmployeeHours e = new EmployeeHours();
                e.EmployeeHoursId = Convert.ToInt32(reader["EmployeeHoursId"]);
                e.EmployeeId      = Convert.ToInt32(reader["EmployeeId"]);
                e.FullName        = Convert.ToString(reader["FullName"]);
                e.WorkDate        = Convert.ToDateTime(reader["WorkDate"]);
                e.HoursWorked     = Convert.ToDouble(reader["HoursWorked"]);
                listOfEmps.Add(e);
            }

            conn.Close();

            return(listOfEmps);
        }
Ejemplo n.º 10
0
        public void UpdateEmployeeHours(EmployeeHours emp)
        {
            //2. Create a connection object
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = @"Data Source=127.0.0.1;Initial Catalog=PE2_Project_Employee_Hours;User ID=sa;Password=vRdoZJPoyev4KAx7vLB";
            conn.Open();

            //3.Create a command object
            SqlCommand cmd = new SqlCommand("sp_EmployeeHours_Update", conn);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@EmployeeHoursId", emp.EmployeeHoursId));
            cmd.Parameters.Add(new SqlParameter("@EmployeeHoursEmpId", emp.EmployeeId));
            cmd.Parameters.Add(new SqlParameter("@WorkDate", emp.WorkDate));
            cmd.Parameters.Add(new SqlParameter("@HoursWorked", emp.HoursWorked));


            //4.Execute the command - insert, update, delete
            cmd.ExecuteNonQuery();

            //5.Handle the results

            conn.Close();
        }
Ejemplo n.º 11
0
        public EmployeeHours FindEmployeeHoursByID(int id)
        {
            EmployeeHours eh = null;

            //2. Create a connection object
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = @"Data Source=127.0.0.1;Initial Catalog=PE2_Project_Employee_Hours;User ID=sa;Password=vRdoZJPoyev4KAx7vLB";
            conn.Open();

            //3.Create a command object
            SqlCommand cmd = new SqlCommand("sp_EmployeeHours_FindById", conn);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("@EmployeeHoursId", id));

            //4.Execute the command - select
            SqlDataReader reader = cmd.ExecuteReader();

            //5.Handle the results
            if (reader.Read())
            {
                eh             = new EmployeeHours();
                eh.EmployeeId  = Convert.ToInt32(reader["EmployeeId"]);
                eh.FullName    = Convert.ToString(reader["FullName"]);
                eh.WorkDate    = Convert.ToDateTime(reader["WorkDate"]);
                eh.HoursWorked = Convert.ToDouble(reader["HoursWorked"]);
            }

            conn.Close();

            return(eh);
        }
Ejemplo n.º 12
0
        public void InsertEmployeeHours(EmployeeHours emp)
        {
            //connection object
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = @"Data Source=127.0.0.1;Initial Catalog=PE2_Project_Employee_Hours;User ID=sa;Password=vRdoZJPoyev4KAx7vLB";

            //open connection
            conn.Open();

            //create command object
            SqlCommand cmd = new SqlCommand("sp_EmployeeHours_Insert", conn); //sp_EmployeeHours_Insert

            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("@EmployeeId", emp.EmployeeId)); //@EmployeeId
            cmd.Parameters.Add(new SqlParameter("@WorkDate", emp.WorkDate));     //@WorkDate
            cmd.Parameters.Add(new SqlParameter("@WorkHours", emp.HoursWorked)); //@WorkHours

            //excute command
            cmd.ExecuteNonQuery();

            //close connection
            conn.Close();
        }
Ejemplo n.º 13
0
        public async Task EditEmployeeHours_WhenNotExists()
        {
            await dbContext.EmployeeHoursCollection.AddAsync(
                new EmployeeHours { EmployeeHoursId = 101, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 });

            await dbContext.EmployeeHoursCollection.AddAsync(
                new EmployeeHours { EmployeeHoursId = 102, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 });

            await dbContext.SaveChangesAsync();

            var dao   = new PostgresDataAccessObjectService(dbContext);
            var newEH = new EmployeeHours {
                EmployeeHoursId = 666, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4
            };

            bool exThrown = false;

            try {
                exThrown = true;
                dao.EditEmployeeHours(newEH);
            } catch (Exception e) {
                Assert.Equal(typeof(InvalidOperationException), e.GetType());
                Assert.Equal("EmployeeHours object not found", e.Message);
            }
            Assert.True(exThrown);
        }
Ejemplo n.º 14
0
        public async Task EditEmployeeHours_WhenExists()
        {
            await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 4 });

            await dbContext.EmployeeHoursCollection.AddAsync(
                new EmployeeHours { EmployeeHoursId = 101, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 });

            await dbContext.EmployeeHoursCollection.AddAsync(
                new EmployeeHours { EmployeeHoursId = 102, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 });

            await dbContext.SaveChangesAsync();

            var dao = new PostgresDataAccessObjectService(dbContext);

            var newEH = new EmployeeHours {
                EmployeeHoursId = 101, Value = 777f, TimePeriod = "02.01.2019_08.01.2022", EmployeeId = 4
            };

            dao.EditEmployeeHours(newEH);
            var obj = dao.GetOneEmployeeHours(101);

            Assert.NotNull(obj);
            Assert.Equal(101, obj.EmployeeHoursId);
            Assert.Equal(777f, obj.Value);
            Assert.Equal("02.01.2019_08.01.2022", obj.TimePeriod);
            Assert.Equal(4, obj.EmployeeId);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// returns a string depending on the success or failure of adding the hours
        /// </summary>
        /// <param name="hours"></param>
        /// <returns></returns>
        private string EmployeeHoursAdded(EmployeeHours hours)
        {
            ResultsEnum result = _hoursController.AddHours(hours);

            if (result != ResultsEnum.Success)
            {
                return("Hours not added.. check all the fields and try again");
            }
            _empTracker.LoadEmployeeHours(); // update the new employee hours
            return("Employee hours added");
        }
Ejemplo n.º 16
0
        private void computeNightDifferential(DateTime startTime, DateTime endTime)
        {
            // ************************************
            // *** Night Differential Hours *******
            // ************************************
            if ((clockIn >= startTime && clockIn <= endTime) ||
                (clockOut >= startTime && clockOut <= endTime))
            {
                //If clockin is less than night dif start time
                // Set clockin to ND start time
                if (clockIn < startTime)
                {
                    clockIn = clockIn.ChangeTime(startTime.Hour, startTime.Minute, 0, 0);
                }

                //If clockout is greater than night dif end time
                // Set clockout to ND end time
                if (clockOut.Value > endTime)
                {
                    //This handles if NightDif overlaps schedule
                    // If timeout is later nightDifEnd set out to less than 1 hour than actual
                    if (nightDifEndTime.TimeOfDay > employeeWorkSchedule.WorkSchedule.TimeStart &&
                        clockOut.Value.TimeOfDay >= employeeWorkSchedule.WorkSchedule.TimeStart)
                    {
                        clockOut = clockOut.Value.ChangeTime(endTime.Hour, 0, 0, 0);
                    }
                    else
                    {
                        clockOut = clockOut.Value.ChangeTime(endTime.Hour, endTime.Minute, 0, 0);
                    }
                }

                TimeSpan ndHoursCount = clockOut.Value.ChangeSeconds(0, 0) - clockIn.ChangeSeconds(0, 0);

                //Create entry if have night differential hours to record
                var totalHours = ComputeTotalAllowedHours(Math.Round(ndHoursCount.TotalHours, 2));
                if (totalHours > 0)
                {
                    EmployeeHours nightDifHours =
                        new EmployeeHours
                    {
                        OriginAttendanceId = attendance.AttendanceId,
                        Date       = day,
                        EmployeeId = attendance.EmployeeId,
                        Hours      = totalHours,
                        Type       = Entities.Enums.RateType.NightDifferential
                    };

                    _employeeHoursRepository.Add(nightDifHours);
                }
            }
        }
Ejemplo n.º 17
0
 public ResultsEnum AddHours(EmployeeHours emp)
 {
     try
     {
         HoursDao.AddHours(emp);
         return(ResultsEnum.Success);
     }
     catch (Exception e)
     {
         Console.WriteLine("Error from HoursDAO/AddHours" + e.Message);
         return(ResultsEnum.Fail);
     }
 }
Ejemplo n.º 18
0
        public void Add(EmployeeHours empHours, Employee emp)
        {
            var empobj = _context.Employees.FirstOrDefault(x => x.EmployeeNumber == emp.EmployeeNumber);

            if (empobj != null)
            {
                empobj.EmployeeHours.Add(new EmployeeHours {
                    Description = empHours.Description,
                    HoursWorked = empHours.HoursWorked,
                    WorkDate    = empHours.WorkDate
                });
                _context.SaveChanges();
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Shows the employee's details depending on which Id is selected in the list box
        /// </summary>
        private void HoursIndexChanged()
        {
            // get the employe id of the date selected
            EmployeeHours selectedEmployee = (EmployeeHours)lstbxHoursEmpID.SelectedItem;
            int           empId            = selectedEmployee.EmpID;

            // return those employee details by running the search method
            ResultFind employee = _empController.FindEmployeeById(empId); // uses that Id to search for the employee

            // fills the label boxes with their details
            lblHoursEmail.Text = employee.Employee.Email;
            lblHoursName.Text  = employee.Employee.FullName;
            lblHoursPhone.Text = employee.Employee.Phone;
        }
Ejemplo n.º 20
0
        public ResultEnum UpdateEmployeeHours(EmployeeHours emp)
        {
            ResultEnum result = ResultEnum.Success;

            try
            {
                EmployeeHoursDAO dao = new EmployeeHoursDAO();
                dao.UpdateEmployeeHours(emp);
            }
            catch
            {
                result = ResultEnum.Fail;
            }
            return(result);
        }
Ejemplo n.º 21
0
        public void TransformationTest()
        {
            var eh = new EmployeeHours();

            eh.EmployeeHoursId = 99;
            eh.EmployeeId      = 1;
            eh.Value           = 600;
            eh.TimePeriod      = "20.1.2019-26.01.2019";

            var webEh = new WebEmployeeHours(eh);

            Assert.Equal(99, webEh.Id);
            Assert.Equal(1, webEh.EmployeeId);
            Assert.Equal(600f, webEh.Value);
            Assert.Equal("20.1.2019-26.01.2019", webEh.TimePeriod);
        }
Ejemplo n.º 22
0
        private void computeOT()
        {
            // ********************
            // *** OT Hours *******
            // ********************
            var otTimeStart = scheduledTimeOut;
            var otTimeEnd   = clockOut;

            //If clock in is later than scheduled time out ot time start should be clock in
            // e.g. scheduled time out is 4pm.
            // Last attendance time out is 6pm, 2 hrs of OT is already recorded
            // Another clock in for 11pm, the  otTimeStart should be 11pm not 4pm
            if (isClockInLaterThanScheduledTimeOut)
            {
                otTimeStart = clockIn;
            }

            //Set ot time end to 12 am of next days
            if (otTimeEnd.Value.Date > day.Date)
            {
                otTimeEnd = day.AddDays(1);
            }
            if (clockoutLaterThanScheduled)
            {
                TimeSpan otHoursCount = otTimeEnd.Value.ChangeSeconds(0, 0) - otTimeStart.ChangeSeconds(0, 0);

                var totalHours = ComputeTotalAllowedHours(Math.Round(otHoursCount.TotalHours, 2));
                if (otHoursCount != null && otHoursCount.TotalHours > 0 && totalHours > 0)
                {
                    EmployeeHours otHours =
                        new EmployeeHours
                    {
                        OriginAttendanceId = attendance.AttendanceId,
                        Date       = day,
                        EmployeeId = attendance.EmployeeId,
                        Hours      = totalHours,
                        Type       = Entities.Enums.RateType.OverTime
                    };

                    _employeeHoursRepository.Add(otHours);
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// add an employees hours to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddHours_Click(object sender, EventArgs e)
        {
            // checks to make sure only numbers in the hours fields. All the other
            // fields will already be ok
            if (!int.TryParse(txtAddHours.Text, out _))
            {
                lblAddHoursStatus.Text = @"Numbers only";
                return;
            }

            // create the employeehours object
            var newEmpHours = new EmployeeHours
            {
                EmpHoursID = int.Parse(cmbHoursId.Text),
                WorkDate   = DateTime.Parse(dateTimeAddHours.Text),
                Hours      = int.Parse(txtAddHours.Text)
            };

            // update the status box with success or fail of adding the hours
            lblAddHoursStatus.Text = EmployeeHoursAdded(newEmpHours);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// return a list of hours worked between a certain date range
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public List <EmployeeHours> SelectDateRange(DateTime start, DateTime end)
        {
            // create connection
            SqlConnection DbConnection = new SqlConnection
            {
                ConnectionString = ConnectionHelper.GetConnectionString()
            };

            DbConnection.Open();

            // set up the command
            using (DbConnection)
            {
                SqlCommand command = new SqlCommand("sp_EmpHours_SearchBetweenDates", DbConnection);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                // insert the parameters for the search
                command.Parameters.Add(new SqlParameter("@StartDate", start));
                command.Parameters.Add(new SqlParameter("@EndDate", end));

                // run the command through the reader
                SqlDataReader reader = command.ExecuteReader();

                // map the reader rows into Employee objects
                List <EmployeeHours> daterangeHoursList = new List <EmployeeHours>();

                // set up a while loop that checks for data and stops executing when there is none
                while (reader.Read())
                {
                    var empHours = new EmployeeHours();
                    empHours.EmpHoursID = Convert.ToInt32(reader["EmpHoursID"]);
                    empHours.EmpID      = Convert.ToInt32(reader["EmpID"]);
                    empHours.WorkDate   = Convert.ToDateTime(reader["WorkDate"]);
                    empHours.Hours      = Convert.ToInt32(reader["Hours"]);
                    daterangeHoursList.Add(empHours);
                }

                return(daterangeHoursList);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Loop validation check
            bool check = true;

            for (int i = 0; i < buttonEnablingArr.Length; i++)
            {
                check = buttonEnablingArr[i] && check;
            }

            if (lblIDResult.Text == "")
            {
                MessageBox.Show("No employees");
            }
            else
            {
                if (check)
                {
                    //Read input
                    EmployeeHours newEmpHrs = new EmployeeHours();
                    newEmpHrs.EmpID    = int.Parse(lblIDResult.Text);
                    newEmpHrs.WorkDate = DateTime.Parse(dateTimePicker1.Text);
                    newEmpHrs.Hours    = decimal.Parse(txtHours.Text);

                    //Call controller
                    EmployeeHoursController controller = new EmployeeHoursController();
                    controller.AddHours(newEmpHrs);

                    //Clear textboxes and show output
                    MessageBox.Show("Hours successfully added to: " + lblNameResult.Text);
                    txtHours.Clear();
                    epHours.SetError(txtHours, null);
                }
                else
                {
                    ErrorMessage.InputMessage();
                }
            }
        }
        //Add a employee hours
        public void InsertEmpHours(EmployeeHours empHrs)
        {
            //1 - Connection
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = ConnectionHelper.getConnectionString();
            conn.Open();

            using (conn)
            {
                //2 - Command
                SqlCommand command = new SqlCommand("sp_EmpHours_InsertEmployeeHours", conn);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                //Parameters
                command.Parameters.Add(new SqlParameter("@empID", empHrs.EmpID));
                command.Parameters.Add(new SqlParameter("@workDate", empHrs.WorkDate));
                command.Parameters.Add(new SqlParameter("@hours", empHrs.Hours));

                //3 - Run command
                command.ExecuteNonQuery();
            }
        }
Ejemplo n.º 27
0
        public async Task AddEmployeeHours_WhenEmptyTable()
        {
            await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 4 });

            await dbContext.SaveChangesAsync();

            var eh = new EmployeeHours();

            eh.EmployeeId = 4;
            eh.Value      = 90;
            eh.TimePeriod = "02.03.2019_08.03.2019";

            var dao = new PostgresDataAccessObjectService(dbContext);

            dao.AddEmployeeHours(eh);

            var coll = dao.GetEmployeeHoursForAnEmployee(4);

            Assert.Single(coll);
            Assert.Equal(90f, coll[0].Value);
            // apparently we must start from 1
            Assert.Equal(1, coll[0].EmployeeHoursId);
        }
Ejemplo n.º 28
0
        public async Task AddEmployeeHours_WhenEmployeeIdNotSet()
        {
            await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 9 });

            await dbContext.SaveChangesAsync();

            var eh = new EmployeeHours();

            eh.Value      = 90;
            eh.TimePeriod = "02.03.2019_08.03.2019";

            var  dao      = new PostgresDataAccessObjectService(dbContext);
            bool exThrown = false;

            try {
                exThrown = true;
                dao.AddEmployeeHours(eh);
            } catch (Exception e) {
                Assert.Equal(typeof(ArgumentException), e.GetType());
                Assert.Equal("EmployeeId was not set", e.Message);
            }
            Assert.True(exThrown);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Returns all the dates and hours worked
        /// </summary>
        /// <returns></returns>
        public List <EmployeeHours> SelectAllHours()
        {
            // create connection
            SqlConnection DbConnection = new SqlConnection
            {
                ConnectionString = ConnectionHelper.GetConnectionString()
            };

            DbConnection.Open();

            // set up the command
            using (DbConnection)
            {
                SqlCommand command = new SqlCommand("sp_EmpHours_SelectAllHours", DbConnection);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                // run the command through the reader
                SqlDataReader reader = command.ExecuteReader();

                // map the reader rows into Employee objects
                List <EmployeeHours> employeeHoursList = new List <EmployeeHours>();

                // set up a while loop that checks for data and stops executing when there is none
                while (reader.Read())
                {
                    var empHours = new EmployeeHours();
                    empHours.EmpHoursID = Convert.ToInt32(reader["EmpHoursID"]);
                    empHours.EmpID      = Convert.ToInt32(reader["EmpID"]);
                    empHours.WorkDate   = Convert.ToDateTime(reader["WorkDate"]);
                    empHours.Hours      = Convert.ToInt32(reader["Hours"]);
                    employeeHoursList.Add(empHours);
                }

                return(employeeHoursList);
            }
        }
Ejemplo n.º 30
0
 //Add employee hours
 public void AddHours(EmployeeHours empHrs)
 {
     dao.InsertEmpHours(empHrs);
 }