public void AddWorkScheduleShift(WorkScheduleShift workScheduleShift)
 {
     using (SqlConnection con = new SqlConnection(connectionString))
     {
         try
         {
             con.Open();
             SqlCommand Addworkschedule = new SqlCommand("Sp_AddWorkScheduleShift", con);
             Addworkschedule.CommandType = CommandType.StoredProcedure;
             Addworkschedule.Parameters.Add(new SqlParameter("@EmployeeId", workScheduleShift.Employee.EmployeeId));
             Addworkschedule.Parameters.Add(new SqlParameter("@StartTime", workScheduleShift.StartTime));
             Addworkschedule.Parameters.Add(new SqlParameter("@EndTime", workScheduleShift.EndTime));
             SqlDataReader reader = Addworkschedule.ExecuteReader();
             if (reader.HasRows)
             {
                 while (reader.Read())
                 {
                     workScheduleShift.ShiftID = int.Parse(reader["ShiftID"].ToString());
                 }
             }
         }
         catch (SqlException e) { Console.WriteLine("Muuuuligvis en fejl\n" + e.Message); }
     }
     GetAllWorkScheduleShifts();
 }
Example #2
0
        public List <WorkScheduleShift> GetAllWorkScheduleShifts()
        {
            List <WorkScheduleShift> allShifts = new List <WorkScheduleShift>();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                try
                {
                    con.Open();

                    SqlCommand allShiftsFromDB = new SqlCommand("Sp_GetWorkScheduleShifts", con);
                    allShiftsFromDB.CommandType = System.Data.CommandType.StoredProcedure;

                    SqlDataReader reader = allShiftsFromDB.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            int               shiftId         = int.Parse(reader["ShiftID"].ToString());
                            int               employeeId      = int.Parse(reader["EmployeeID"].ToString());
                            DateTime          startTime       = Convert.ToDateTime(reader["StartTime"]);
                            DateTime          endTime         = Convert.ToDateTime(reader["EndTime"]);
                            Employee          employeeToShift = EmployeeRepository.GetInstance().GetEmployeeById(employeeId);
                            WorkScheduleShift newShift        = new WorkScheduleShift(shiftId, employeeToShift, startTime, endTime);
                            allShifts.Add(newShift);
                        }
                    }
                }
                catch (SqlException e) { Console.WriteLine("Muuuuligvis en fejl\n" + e.Message); }
            }
            return(allShifts);
        }
        public void GetAllWorkScheduleShifts()
        {
            List <WorkScheduleShift> listOfAllShifts = new List <WorkScheduleShift>();

            workSchedules.Clear();
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                try
                {
                    con.Open();

                    SqlCommand allShiftsFromDB = new SqlCommand("Sp_GetWorkScheduleShifts", con);
                    allShiftsFromDB.CommandType = System.Data.CommandType.StoredProcedure;

                    SqlDataReader reader = allShiftsFromDB.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            int               shiftId         = int.Parse(reader["ShiftID"].ToString());
                            int               employeeId      = int.Parse(reader["EmployeeID"].ToString());
                            DateTime          startTime       = Convert.ToDateTime(reader["StartTime"]);
                            DateTime          endTime         = Convert.ToDateTime(reader["EndTime"]);
                            Employee          employeeToShift = EmployeeRepository.GetInstance().GetEmployeeById(employeeId);
                            WorkScheduleShift newShift        = new WorkScheduleShift(shiftId, employeeToShift, startTime, endTime);
                            listOfAllShifts.Add(newShift);
                        }
                    }
                }
                catch (SqlException e) { Console.WriteLine("Muuuuligvis en fejl\n" + e.Message); }
            }
            foreach (WorkScheduleShift wss in listOfAllShifts)
            {
                int          shiftYear    = int.Parse(wss.StartTime.ToString("yyyy"));
                int          shiftMonth   = int.Parse(wss.StartTime.ToString("M"));
                WorkSchedule workSchedule = this.GetSchedule(shiftYear, shiftMonth);
                if (workSchedule == null)
                {
                    workSchedule = new WorkSchedule(shiftYear, shiftMonth);
                    AddWorkSchedule(workSchedule);
                }
                workSchedule.AddShiftToSchedule(wss);
            }
        }
Example #4
0
 public void AddShiftToSchedule(WorkScheduleShift shift)
 {
     shifts.Add(shift);
 }
Example #5
0
 public void AddWorkShift(WorkScheduleShift newWorkSchedule)
 {
     workShifts.Add(newWorkSchedule);
 }