Пример #1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            using (var ctx = new CADContext())
            {
                Schedules schedules = ctx.Schedules.Find(id);
                schedules.ScheduleVMsList.Clear();
                schedules.Name      = Schedule.Name;
                schedules.StartTime = Schedule.StartTime;
                schedules.StopTime  = Schedule.StopTime;

                var sceduleVMs = ctx.ScheduleVM.Where(s => s.ScheduleId == Schedule.Id).ToList();
                foreach (var res in sceduleVMs)
                {
                    ctx.ScheduleVM.Remove(res);
                }

                foreach (var res in SelectedVmsId)
                {
                    var        vm         = ctx.VMs.Find(res);
                    ScheduleVM scheduleVM = new ScheduleVM();
                    scheduleVM.ScheduleId = 1;
                    scheduleVM.Schedules  = Schedule;
                    scheduleVM.VMId       = vm.Id;
                    scheduleVM.VM         = vm;
                    ctx.ScheduleVM.Add(scheduleVM);
                    Schedule.ScheduleVMsList.Add(scheduleVM);
                }

                ctx.SaveChanges();
            }

            return(RedirectToPage("./Index"));
        }
 /// <summary>
 /// Creator: Jordan Lindo
 /// Created: 4/23/2020
 /// Approver:
 ///
 ///  Confirm schedule constructor.
 /// </summary>
 /// <remarks>
 /// Updater: NA
 /// Updated: NA
 /// Update: NA
 ///
 /// </remarks>
 /// <param name="user"></param>
 /// <param name="schedule"></param>
 public frmConfirmNewSchedule(PetUniverseUser user, ScheduleVM schedule)
 {
     InitializeComponent();
     _user     = user;
     _schedule = schedule;
     setDG();
 }
Пример #3
0
        public void GenerateScheduleTest()
        {
            IScheduleManager scheduleManager = new ScheduleManager(_scheduleAccessor,
                                                                   _shiftTimeAccessor);

            List <BaseScheduleLine> lines = new List <BaseScheduleLine>
            {
                new BaseScheduleLine
                {
                    BaseScheduleID = 1000000,
                    DepartmentID   = "Management",
                    ShiftTimeID    = 100002,
                    ERoleID        = "Manager",
                    Count          = 1
                }
            };

            DateTime date = DateTime.Now;

            ScheduleVM scheduleVM = scheduleManager.GenerateSchedule(date, lines);

            int result = scheduleVM.ScheduleLines.Count;
            int target = 10;

            Assert.AreEqual(target, result);
        }
Пример #4
0
        public JsonResult Schedule(FlightVM flightInfo)
        {
            string   origin      = flightInfo.Origin_1;
            string   destination = flightInfo.Destination_1;
            DateTime departTime  = DateTime.Parse(flightInfo.FromDate_1);

            var scheduleList = db.Schedules
                               .Where(x => x.Origin == origin && x.Destination == destination &&
                                      DbFunctions.TruncateTime(x.DepartTime) == departTime.Date);

            var result = new List <ScheduleVM>();

            foreach (var schedule in scheduleList)
            {
                var seatList = schedule.Flight.Seats;
                foreach (var seat in seatList)
                {
                    var item = new ScheduleVM();
                    item.FlightNo    = schedule.FlightID;
                    item.Origin      = schedule.Origin;
                    item.Destination = schedule.Destination;
                    item.SeatNo      = seat.SeatID;
                    item.ScheduleID  = schedule.ID;
                    item.DepartTime  = schedule.DepartTime.ToString("yyyy-MM-dd HH:mm");
                    if (!IsSeatReserved(item))
                    {
                        result.Add(item);
                    }
                }
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #5
0
        public TeamSchedulePage(int idTeam)
        {
            InitializeComponent();

            ScheduleVM scheduleVM = new ScheduleVM(idTeam);

            BindingContext = scheduleVM;
        }
Пример #6
0
        private Boolean IsSeatReserved(ScheduleVM param)
        {
            var ticketList = db.Tickets
                             .Where(x => x.FlightID == param.FlightNo && x.ScheduleID == param.ScheduleID &&
                                    x.SeatID == param.SeatNo);

            return((ticketList.Count() >= 1) ? true : false);
        }
        // GET: ScheduleOnces
        public ActionResult Index()
        {
            ScheduleVM vmodel = new ScheduleVM();

            vmodel.List   = _repo.GetScheduleByUser(Convert.ToInt32(Session["UserId"]));
            vmodel.User   = Session["userName"] + " - " + Session["Name"] + " - " + Session["businessName"].ToString();
            vmodel.UserId = Convert.ToInt32(Session["UserId"]);
            return(View(vmodel));
        }
Пример #8
0
        public ActionResult UpdateSchedule(ScheduleVM post)
        {
            using (var ctx = new CSEntities())
            {
                ctx.UpdateClassSchedule(post.HelpID, post.STime, post.ETime, post.SelectedValuesCl[0], post.SelectedValuesC[0], post.SelectedValuesT[0]);

                return(RedirectToAction("Schedule", "Home"));
            }
        }
Пример #9
0
        public ActionResult Main()
        {
            ScheduleVM model = new ScheduleVM();

            using (var ctx = new CSEntities())
            {
                model.ScheduleView = (from t in ctx.Schedules select t).ToList();
            }
            return(View(model));
        }
Пример #10
0
        public ActionResult Schedule()
        {
            ScheduleVM model = new ScheduleVM();

            using (var ctx = new CSEntities())
            {
                model.ScheduleList = (from t in ctx.ScheduleLists select t).ToList();

                // model.ScheduleUser = ctx.ScheduleUserFunc(Convert.ToInt32(Session["ID"])).ToList();

                model.ScheduleUser = ctx.ScheduleForAllUser(Convert.ToInt32(Session["ID"])).ToList();

                //model.TeacherList = (from t in ctx.Teachers select t.Person.LName).ToList();

                //model.CourseList = (from t in ctx.Courses where t.Closed == false select t.Name).ToList();

                //TEST PART

                // Drop Down List For Teachers
                model.TeacherList = (from t in ctx.Teachers select t).ToList();
                List <SelectListItem> itemsT = new List <SelectListItem>();
                foreach (var item in model.TeacherList)
                {
                    itemsT.Add(new SelectListItem {
                        Value = item.ID.ToString(), Text = item.Person.FName + " " + item.Person.LName
                    });
                }
                model.ValuesT = itemsT;

                // Drop Down List For Courses
                model.CoursesList = (from c in ctx.CoursesLists select c).ToList();
                List <SelectListItem> itemsC = new List <SelectListItem>();
                foreach (var item in model.CoursesList)
                {
                    itemsC.Add(new SelectListItem {
                        Value = item.ID.ToString(), Text = item.Name
                    });
                }
                model.ValuesC = itemsC;

                // Drop Down List For Classes
                model.ClassList = (from t in ctx.ClassRooms select t).ToList();
                List <SelectListItem> itemsCl = new List <SelectListItem>();
                foreach (var item in model.ClassList)
                {
                    itemsCl.Add(new SelectListItem {
                        Value = item.ID.ToString(), Text = item.ClassNumber
                    });
                }
                model.ValuesCl = itemsCl;

                //END
            }
            return(View(model));
        }
Пример #11
0
        /// <summary>
        /// Creator: Jordan Lindo
        /// Created: 4/8/2020
        /// Approver:  Chase Schulte
        ///
        /// Test for inserting a schedule.
        /// </summary>
        /// <remarks>
        /// Updater: NA
        /// Updated: NA
        /// Update: NA
        ///
        /// </remarks>
        /// <param name="schedule"></param>
        /// <returns></returns>
        public int InsertSchedule(ScheduleVM schedule)
        {
            int rows = 0;

            _schedules.Add(schedule);
            if (_schedules.Contains(schedule))
            {
                rows = 1;
            }
            return(rows);
        }
Пример #12
0
 /// <summary>
 /// Creator: Jordan Lindo
 /// Created: 4/23/2020
 /// Approver: Chase Schulte
 ///
 /// Method for inserting a Schedule
 /// </summary>
 /// <remarks>
 /// Updater: NA
 /// Updated: NA
 /// Update: NA
 ///
 /// </remarks>
 public int AddSchedule(ScheduleVM scheduleVM)
 {
     try
     {
         return(_scheduleAccessor.InsertSchedule(scheduleVM));
     }
     catch (Exception ex)
     {
         throw new ApplicationException("Schedule not added. ", ex);
     }
 }
Пример #13
0
 public static void UpdateSchedule(this Schedule model, ScheduleVM viewModel)
 {
     model.ID          = viewModel.ID;
     model.FinalTestID = viewModel.FinalTestID;
     model.SubjectID   = viewModel.SubjectID;
     model.GroupOf     = viewModel.GroupOf;
     model.MaxSize     = viewModel.MaxSize;
     model.RoomID      = viewModel.RoomID;
     model.TestDate    = viewModel.TestDate;
     model.TestTime    = viewModel.TestTime;
 }
Пример #14
0
        private async void Start()
        {
            await Loading.Show();

            ScheduleVM       = new ScheduleVM(RegistrateEnabled);
            this.DataContext = ScheduleVM;
            InitializeComponent();
            scheduler.OptionsCustomization.AllowInplaceEditor = UsedAppointmentType.None;
            scheduler.Views.DayView.AppointmentDisplayOptions.StatusDisplayType = AppointmentStatusDisplayType.Never;
            scheduler.Views.DayView.WorkTime = TimeOfDayInterval.Day;
            scheduler.Views.WorkWeekView.AppointmentDisplayOptions.StatusDisplayType = AppointmentStatusDisplayType.Never;
            scheduler.Views.WorkWeekView.WorkTime = TimeOfDayInterval.Day;
        }
Пример #15
0
        public ScheduleVM GetSchedulesVM()
        {
            var scheduleVm = new ScheduleVM
            {
                AdultsAdvanced = _ctx.Schedules.Where(s => s.Group == "Erwachsene" && s.Level == "Anfänger" && s.ClassName != "Modern Dance"),
                AdultsBeginner = _ctx.Schedules.Where(s => s.Group == "Erwachsene" && s.Level == "Fortgeschrittene" && s.ClassName != "Modern Dance"),
                AdultModern    = _ctx.Schedules.Where(s => s.Group == "Erwachsene" && s.ClassName == "Modern Dance"),
                Kids34         = _ctx.Schedules.Where(s => s.Group == "Kinder" && s.Level == "Alles34"),
                Kids34Eng      = _ctx.Schedules.Where(s => s.Group == "Kinder" && s.Level == "Alles34Eng"),
                Kids57         = _ctx.Schedules.Where(s => s.Group == "Kinder" && s.Level == "Alles57")
            };

            return(scheduleVm);
        }
Пример #16
0
        public void TestGenerateScheduleCountTooHigh()
        {
            IScheduleManager scheduleManager = new ScheduleManager(_scheduleAccessor, _shiftTimeAccessor);

            // To ensure the list is at capacity.
            List <ScheduleVM> scheduleVMs = new List <ScheduleVM>
            {
                new ScheduleVM()
                {
                    ScheduleID     = 1000003,
                    CreatingUserID = 100000,
                    StartDate      = DateTime.Now.AddDays(15),
                    EndDate        = DateTime.Now.AddDays(29),
                    Active         = true,
                    CreatorName    = "Last, First",
                    ScheduleLines  = new List <ShiftUserVM>()
                },
                new ScheduleVM()
                {
                    ScheduleID     = 1000004,
                    CreatingUserID = 100000,
                    StartDate      = DateTime.Now.AddDays(30),
                    EndDate        = DateTime.Now.AddDays(44),
                    Active         = true,
                    CreatorName    = "Last, First",
                    ScheduleLines  = new List <ShiftUserVM>()
                }
            };

            foreach (var item in scheduleVMs)
            {
                scheduleManager.AddSchedule(item);
            }
            List <BaseScheduleLine> lines = new List <BaseScheduleLine>
            {
                new BaseScheduleLine
                {
                    BaseScheduleID = 1000000,
                    DepartmentID   = "Management",
                    ShiftTimeID    = 100002,
                    ERoleID        = "Manager",
                    Count          = 1
                }
            };

            DateTime date = DateTime.Now;

            ScheduleVM scheduleVM = scheduleManager.GenerateSchedule(date, lines);
        }
Пример #17
0
        public ActionResult PostNewDate(ScheduleVM post)
        {
            if (post.STime != null || post.ETime != null)
            {
                using (var ctx = new CSEntities())
                {
                    // ctx.AddNewDate(post.STime, post.ETime, post.ClassList.FirstOrDefault(), post.CourseList.FirstOrDefault(), post.TeacherList.FirstOrDefault());

                    ctx.AddNewDate(post.STime, post.ETime, post.SelectedValuesCl.FirstOrDefault(), post.SelectedValuesC.FirstOrDefault(), post.SelectedValuesT.FirstOrDefault());

                    return(RedirectToAction("Schedule", "Home"));
                }
            }
            return(RedirectToAction("Schedule", "Home"));
        }
        public ActionResult Schedule(int?trackId = null)
        {
            ScheduleVM model = new ScheduleVM();

            if (null != Session["UserId"])
            {
                Database db = new Database();
                if (null != trackId)
                {
                    model.Selectedtrack = db.GetTrackById((int)trackId);
                }
                model.ScheduleItems = db.GetSessionsByUserId((int)Session["UserId"]);
                model.UserTracks    = db.GetTrackByCreator((int)Session["userId"]);
            }
            return(View(model));
        }
Пример #19
0
        /// <summary>
        /// Thêm lịch thi cho kỳ thi
        /// </summary>
        /// <param name="finalTestID">kỳ thi</param>
        /// <param name="subjectID">môn thi</param>
        /// <returns></returns>
        private Schedule AddSchedule(string finalTestID, string subjectID)
        {
            ScheduleVM scheduleVM = new ScheduleVM()
            {
                ID          = Guid.NewGuid().ToString(),
                FinalTestID = finalTestID,
                SubjectID   = subjectID,
                GroupOf     = 1,
                MaxSize     = 30,
                TestDate    = DateTime.Now.Date,
                //TestTime = "7h30",
                RoomID = 1
            };
            Schedule schedule = new Schedule();

            schedule.UpdateSchedule(scheduleVM);
            return(schedule);
        }
Пример #20
0
        public EstimateEditorVM(TECBid bid, ChangeWatcher watcher, TECEstimator estimate)
        {
            this.bid     = bid;
            this.watcher = watcher;

            ScopeEditorVM     = new ScopeEditorVM(bid, watcher);
            LaborVM           = new LaborVM(bid, estimate);
            ReviewVM          = new ReviewVM(bid, estimate);
            ProposalVM        = new ProposalVM(bid);
            ItemizedSummaryVM = new ItemizedSummaryVM(bid, watcher);
            MaterialSummaryVM = new MaterialSummaryVM(bid, watcher);
            RiserVM           = new RiserVM(bid, watcher);
            ScheduleVM        = new ScheduleVM(bid, watcher);
            BidPropertiesVM   = new BidPropertiesVM(bid);
            InternalNotesVM   = new InternalNotesVM(bid);
            QuotesVM          = new QuotesVM(bid, watcher);

            RefreshMaterialSummaryCommand = new RelayCommand(executeMaterialRefersh);
        }
Пример #21
0
        public static ObservableCollection <ScheduleVM> findEmploeyy()
        {
            var res = new ObservableCollection <ScheduleVM>();

            using (var db = new MeiMeiContext())
            {
                var query = from b in db.EmployeeTables
                            orderby b.FIO
                            select b;

                foreach (var item in query)
                {
                    var name = new ScheduleVM();
                    name.FIO = item.FIO;
                    res.Add(name);
                }
            }
            return(res);
        }
Пример #22
0
        public void AddScheduleTester()
        {
            IScheduleManager scheduleManager = new ScheduleManager(_scheduleAccessor,
                                                                   _shiftTimeAccessor);
            ScheduleVM scheduleVM = new ScheduleVM()
            {
                ScheduleID     = 1000001,
                CreatingUserID = 100000,
                StartDate      = DateTime.Now.AddDays(14),
                EndDate        = DateTime.Now.AddDays(28),
                Active         = false,
                CreatorName    = "Last, First",
                ScheduleLines  = new List <ShiftUserVM>()
                {
                    new ShiftUserVM()
                    {
                        ScheduleID  = 1000000,
                        ShiftID     = 1000000,
                        ShiftTimeID = 1000000,
                        ShiftDate   = DateTime.Now,
                        EmployeeID  = 1000000,
                        RoleID      = "Manager"
                    },
                    new ShiftUserVM()
                    {
                        ScheduleID  = 1000000,
                        ShiftID     = 1000001,
                        ShiftTimeID = 1000000,
                        ShiftDate   = DateTime.Now,
                        EmployeeID  = 1000001,
                        RoleID      = "Supervisor"
                    }
                }
            };

            int result = scheduleManager.AddSchedule(scheduleVM);
            int target = 1;

            Assert.AreEqual(target, result);
        }
        /// <summary>
        /// Creator: Jordan Lindo
        /// Created: 4/9/2020
        /// Approver: Chase Schulte
        ///
        /// Inserts a Schedule including ScheduleLines.
        /// </summary>
        /// <remarks>
        /// Updater: NA
        /// Updated: NA
        /// Update: NA
        ///
        /// </remarks>
        /// <param name="schedule"></param>
        /// <returns></returns>
        public int InsertSchedule(ScheduleVM schedule)
        {
            int scheduleID = 0;
            var conn       = DBConnection.GetConnection();
            var cmd        = new SqlCommand("sp_insert_schedule", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@StartDate", schedule.StartDate);
            cmd.Parameters.AddWithValue("@EndDate", schedule.EndDate);
            cmd.Parameters.AddWithValue("@CreatingUserID", schedule.CreatingUserID);

            try
            {
                conn.Open();
                var result = cmd.ExecuteScalar();
                scheduleID = int.Parse(result.ToString());
                foreach (Shift shift in schedule.ScheduleLines)
                {
                    var cmd2 = new SqlCommand("sp_insert_shift", conn);
                    cmd2.CommandType = CommandType.StoredProcedure;
                    cmd2.Parameters.AddWithValue("@ShiftTimeID", shift.ShiftTimeID);
                    cmd2.Parameters.AddWithValue("@ScheduleID", scheduleID);
                    cmd2.Parameters.Add("@Date", SqlDbType.Date).Value = shift.ShiftDate.ToString("yyyy-MM-dd");
                    cmd2.Parameters.AddWithValue("@UserID", shift.EmployeeID);
                    cmd2.Parameters.AddWithValue("@ERoleID", shift.RoleID);
                    cmd2.ExecuteScalar();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }

            return(scheduleID);
        }
        public ActionResult CreateSchedule(ScheduleVM model)
        {
            double minutes     = model.EndTime.Subtract(model.StartTime).TotalMinutes;
            int    slots       = (int)(minutes / 10);
            var    DoctorEmail = Session["UserEmail"];
            var    data        = db.Doctors.Where(x => x.Email == DoctorEmail).FirstOrDefault();

            if (ModelState.IsValid)
            {
                Schedule s = new Schedule()
                {
                    DoctorID            = data.ID,
                    ChamberID           = model.ChamberID,
                    StartTime           = model.StartTime,
                    EndTime             = model.EndTime,
                    FirstAppointmentFee = model.FirstAppointmentFee,
                    NextMeetingFee      = model.NextMeetingFee,
                    SlotNo          = slots,
                    AppointmentDate = model.AppointmentDate.Date
                };
                db.Schedules.Add(s);
                db.SaveChanges();

                //for(int i=0;i<model.days.Count;i++)
                //{
                //    DAS.Models.ScheduleDayRel sd = new Models.ScheduleDayRel()
                //    {
                //        ScheduleId = s.ID,
                //        DayName = model.days[i]
                //    };
                //    db.ScheduleDayRels.Add(sd);
                //    db.SaveChanges();
                //}
                return(Json(Url.Action("Index", "Schedule")));
            }
            ViewBag.ChamberId = new SelectList(db.Chambers, "Id", "Name");
            return(View(model));
        }
Пример #25
0
 /// <summary>
 /// Creator: Jordan Lindo
 /// Created: 4/8/2020
 /// Approver: Chase Schulte
 ///
 /// Generates a new schedule.
 /// </summary>
 /// <remarks>
 /// Updater: NA
 /// Updated: NA
 /// Update: NA
 ///
 /// </remarks>
 private void btnNewSchedule_Click(object sender, RoutedEventArgs e)
 {
     getBaseSchedule();
     if (_baseScheduleVM != null)
     {
         try
         {
             DateTime              startDate = getStartDate();
             ScheduleVM            vM        = _scheduleManager.GenerateSchedule(startDate, _baseScheduleVM.BaseScheduleLines);
             frmConfirmNewSchedule confirm   = new frmConfirmNewSchedule(_user, vM);
             if ((bool)confirm.ShowDialog())
             {
                 vM.ScheduleID = _scheduleManager.AddSchedule(vM);
                 _scheduleManager.AddScheduledHours(vM.ScheduleID);
                 getSchedules();
                 setCboDateRange();
             }
         }
         catch (Exception ex)
         {
             WPFErrorHandler.ErrorMessage(ex.Message);
         }
     }
 }
Пример #26
0
        public ActionResult ShowSchedule(int?courseId)
        {
            if (courseId == null)
            {
                ApplicationUser currentUser = db.Users
                                              .Where(u => u.UserName == User.Identity.Name)
                                              .FirstOrDefault();

                courseId = currentUser.CourseId;
            }

            ScheduleVM schedule = new ScheduleVM();

            //var courseId = currentUser.CourseId;

            var course = db.Courses.Find(courseId);

            //Activities List for one module
            List <Activity> activities = new List <Activity>();

            //Activities List for all modules
            List <Activity> completeActivitiesList = new List <Activity>();

            //Activities List for all modules sorted on start date
            List <Activity> sortedActivities = new List <Activity>();


            //Read modules from database for this course
            var modules = db.Modules.Where(c => c.CourseId == courseId)
                          .OrderByDescending(s => s.StartDate).ToList();

            schedule.CourseName   = course.Name;
            schedule.ModuleExists = true;

            //Read all activities for all modules from the database if modules were found for the course
            if (modules.Count > 0)
            {
                foreach (var item in modules)
                {
                    //Read activities for one module
                    var moduleId = item.Id;
                    activities = db.Activities.Where(m => m.ModuleId == moduleId)
                                 .ToList();
                    foreach (var activityItem in activities)
                    {
                        completeActivitiesList.Add(activityItem);
                    }
                }

                //Sort all activities according to start date
                sortedActivities = completeActivitiesList.OrderByDescending(s => s.StartDate).ToList();
                string activityType = " ";

                //Calculate number of schedule rows based course start date and end date
                TimeSpan courseSpan;
                courseSpan = course.EndDate - course.StartDate;
                int numberOfDays = int.Parse((courseSpan.Days + 1).ToString());

                List <ScheduleRow> rowList = new List <ScheduleRow>();

                //Populate viewmodel properties by iterating over each row in the schedule
                for (int i = 0; i < numberOfDays; i++)
                {
                    //Instantiate a new scheduleRow in the viewmodel
                    ScheduleRow scheduleRow = new ScheduleRow();

                    //Assign values to the ScheduleRowDate and ScheduleRowWeekDay properties in the viewmodel
                    var dateInSchedule = course.StartDate.AddDays(i);

                    scheduleRow.ScheduleRowDate    = dateInSchedule.ToShortDateString();
                    scheduleRow.ScheduleRowWeekDay = dateInSchedule.DayOfWeek.ToString();

                    //Reset all hours, minutes and seconds to 0 in module DateTime properties. This will
                    //enable a correct comparison when checking for a module for this date.
                    foreach (var item in modules)
                    {
                        item.StartDate = item.StartDate.Date;
                        item.EndDate   = item.EndDate.Date;
                    }

                    //Check if there is a module for this date
                    var module = modules.Where(s => s.StartDate <= dateInSchedule)
                                 .Where(e => e.EndDate >= course.StartDate.AddDays(i - 1))
                                 .FirstOrDefault();

                    //If there is a module for this date, assign it to the viewmodel,
                    //else assign an empty string to the module name in the viewmodel.
                    if (module != null)
                    {
                        //Assign the module name to the viewmodel if it is weekday
                        if (dateInSchedule.DayOfWeek.ToString() != "Saturday" && dateInSchedule.DayOfWeek.ToString() != "Sunday")
                        {
                            scheduleRow.ModuleName = module.Name;

                            //Check if there are any activities for this date
                            var activitiesForThisDate = sortedActivities.Where(s => s.StartDate.Date == course.StartDate.Date.AddDays(i))
                                                        .OrderBy(t => t.StartDate.TimeOfDay)
                                                        .ToList();

                            //Read activity type names into a list
                            if (activitiesForThisDate.Count > 0)
                            {
                                List <AmObject> amActivities = new List <AmObject>();
                                List <PmObject> pmActivities = new List <PmObject>();

                                foreach (var item in activitiesForThisDate)
                                {
                                    //The following is only needed if activities are allowed to span more than one day. Not yet implemented.
                                    //Check if the start date of the activity is less than the current date. If it is the set start time = 8:30.
                                    //Check if the end date of the activity is greater than the current date. If it is the set end time = 17:00.


                                    //Read activity type names into a List of strings
                                    activityType = db.ActivityTypes.Find(item.ActivityTypeId).TypeName;

                                    var amObject = new AmObject();
                                    var pmObject = new PmObject();

                                    //Check if the activity is in the morning
                                    if (item.StartDate.Hour < 12 && item.EndDate.Hour <= 12)
                                    {
                                        if (!item.External)
                                        {
                                            amObject.AmActivityTitle = item.StartDate.ToShortTimeString() + " - " + item.EndDate.ToShortTimeString()
                                                                       + ": " + activityType + ", " + item.Name;
                                            amObject.AmActivityDescription = item.Description;
                                            amActivities.Add(amObject);
                                        }
                                        else
                                        {
                                            amObject.AmActivityTitle = item.StartDate.ToShortTimeString() + " - " + item.EndDate.ToShortTimeString()
                                                                       + ": " + activityType + ", " + item.Name + " (EXT)";
                                            amObject.AmActivityDescription = item.Description;
                                            amActivities.Add(amObject);
                                        }
                                    }
                                    //Check if the activity is in the afternoon
                                    else if (item.StartDate.Hour >= 12)
                                    {
                                        if (!item.External)
                                        {
                                            pmObject.PmActivityTitle = item.StartDate.ToShortTimeString() + " - " + item.EndDate.ToShortTimeString()
                                                                       + ": " + activityType + ", " + item.Name;
                                            pmObject.PmActivityDescription = item.Description;
                                            pmActivities.Add(pmObject);
                                        }
                                        else
                                        {
                                            pmObject.PmActivityTitle = item.StartDate.ToShortTimeString() + " - " + item.EndDate.ToShortTimeString()
                                                                       + ": " + activityType + ", " + item.Name + "(EXT)";
                                            pmObject.PmActivityDescription = item.Description;
                                            pmActivities.Add(pmObject);
                                        }
                                    }
                                    //The activity starts before lunch and finishes after lunch. Split it in one morning activity and one
                                    //afternoon activity.
                                    else
                                    {
                                        if (!item.External)
                                        {
                                            amObject.AmActivityTitle = item.StartDate.ToShortTimeString() + " - " + "12:00"
                                                                       + ": " + activityType + ", " + item.Name;
                                            amObject.AmActivityDescription = item.Description;

                                            pmObject.PmActivityTitle = "13:00" + " - " + item.EndDate.ToShortTimeString()
                                                                       + ": " + activityType + ", " + item.Name;

                                            pmObject.PmActivityDescription = item.Description;
                                            amActivities.Add(amObject);
                                            pmActivities.Add(pmObject);
                                        }
                                        else
                                        {
                                            amObject.AmActivityTitle = item.StartDate.ToShortTimeString() + " - " + "12:00"
                                                                       + ": " + activityType + ", " + item.Name + " (EXT)";
                                            amObject.AmActivityDescription = item.Description;

                                            pmObject.PmActivityTitle = "13:00" + " - " + item.EndDate.ToShortTimeString()
                                                                       + ": " + activityType + ", " + item.Name + " (EXT)";
                                            pmObject.PmActivityDescription = item.Description;
                                            amActivities.Add(amObject);
                                            pmActivities.Add(pmObject);
                                        }
                                    }
                                }
                                scheduleRow.AmActivity = amActivities;
                                scheduleRow.PmActivity = pmActivities;
                            }
                        }
                        else
                        {
                            scheduleRow.ModuleName = "";
                        }
                    }
                    else
                    {
                        scheduleRow.ModuleName = "";
                    }

                    rowList.Add(scheduleRow);
                }
                schedule.ScheduleRowList = rowList;
            }
            else
            {
                schedule.ModuleExists = false;
            }

            schedule.UpdatedDate = course.DateChanged;
            return(View("Schedule", schedule));
        }
Пример #27
0
        /// <summary>
        /// Creator: Jordan Lindo
        /// Created: 4/23/2020
        /// Approver: Chase Schulte
        ///
        /// Method for generating a schedule
        /// </summary>
        /// <remarks>
        /// Updater: Jordan Lindo
        /// Updated: 4/28/2020
        /// Update: Added limit to the number allowed.
        ///
        /// </remarks>
        /// <param name="date"></param>
        /// <param name="lines"></param>
        /// <returns></returns>
        public ScheduleVM GenerateSchedule(DateTime date, List <BaseScheduleLine> lines)
        {
            ScheduleVM schedule = new ScheduleVM();

            schedule.ScheduleLines = new List <ShiftUserVM>();
            int daysInSchedule = 14;

            schedule.StartDate = date;
            schedule.EndDate   = date.AddDays(daysInSchedule);
            _openPositions     = new List <OpenPosition>();

            // List for storing which employee is scheduled by day
            List <List <int> > employeeIDsInSchedule = new List <List <int> >();

            // List for recording the count of hours for each employee;
            _employeeHours = new List <PUUserVMHours>();
            try
            {
                int scheduleCount = _scheduleAccessor.GetCountOfActiveSchedules();

                if (scheduleCount < 4)
                {
                    // A loop for repeating for each day in the schedule.
                    for (int i = 0; i < daysInSchedule; i++)
                    {
                        // The list representing the day of the week
                        employeeIDsInSchedule.Add(new List <int>());

                        // A loop to work through a base schedule
                        foreach (BaseScheduleLine line in lines)
                        {
                            // Skip if none are needed.
                            if (line.Count > 0)
                            {
                                // Get a list of possible choices.
                                List <PUUserVMAvailability> shuffle   = _scheduleAccessor.GetListOfAvailableEmployees(date.AddDays(i), line);
                                List <PUUserVMAvailability> avaliable = listShuffle(shuffle);
                                // Skip if no choices are available.
                                if (avaliable != null && avaliable.Count > 0)
                                {
                                    PetUniverseShiftTime shiftTime   = _shiftTimeAccessor.SelectShiftTimeByID(line.ShiftTimeID);
                                    DateTime             shiftStart  = DateTime.Parse(shiftTime.StartTime);
                                    DateTime             shiftEnd    = DateTime.Parse(shiftTime.EndTime);
                                    TimeSpan             shiftLength = shiftEnd - shiftStart;
                                    double minimumHoursToWork        = 6;

                                    bool end = false;
                                    // A loop for the number of positions to fill.
                                    for (int j = line.Count; j > 0 && !end; j--)
                                    {
                                        bool found = false;
                                        int  index = 0;
                                        PUUserVMAvailability candidate = avaliable[index];
                                        PUUserVMAvailability chosen    = null;
                                        int next = index;
                                        do
                                        {
                                            // Check if the candidate is already scheduled on a day.
                                            if (!employeeIDsInSchedule[i].Contains(candidate.PUUserID))
                                            {
                                                DateTime availabilityStart = DateTime.Parse(candidate.Availability.StartTime);
                                                DateTime availabilityEnd   = DateTime.Parse(candidate.Availability.EndTime);
                                                TimeSpan availableLength   = availabilityEnd.Subtract(availabilityStart);

                                                // Short availabilities will be skipped.
                                                if (availableLength.TotalHours >= minimumHoursToWork)
                                                {
                                                    // If the shift start time is after or equal to the availability start time.
                                                    if (shiftStart.CompareTo(availabilityStart) >= 0)
                                                    {
                                                        // If the shift end time is after or equal with the availability end time.
                                                        if (shiftEnd.CompareTo(availabilityEnd) >= 0)
                                                        {
                                                            // If the diference between availability start and
                                                            if (availabilityEnd.Subtract(shiftStart).TotalHours >= minimumHoursToWork)
                                                            {
                                                                shiftEnd = availabilityEnd;
                                                                found    = true;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            found = true;
                                                        }
                                                    }
                                                    // Checks if the person is available for enough of the shift to be scheduled.
                                                    else if ((shiftEnd.Subtract(availabilityStart)).TotalHours >= minimumHoursToWork)
                                                    {
                                                        shiftStart = availabilityStart;
                                                        found      = true;
                                                    }

                                                    if (found)
                                                    {
                                                        bool allowed = true;
                                                        // A loop to see if a person is already scheduled the current day.
                                                        foreach (PUUserVMHours userVMHours in _employeeHours)
                                                        {
                                                            // If the person is found on the current day
                                                            if (userVMHours.PUUserID.Equals(candidate.PUUserID))
                                                            {
                                                                // If the date is in the first week
                                                                if (i < (daysInSchedule / 2))
                                                                {
                                                                    // Check if the user is already scheduled for 40 hours
                                                                    if (userVMHours.Week1Hours >= 40)
                                                                    {
                                                                        allowed = false;
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (userVMHours.Week2Hours >= 40)
                                                                    {
                                                                        allowed = false;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        // If the user hasn't already been scheduled for 40 hours in a week.
                                                        if (allowed)
                                                        {
                                                            // UserId is added to the list of people scheduled on a day.
                                                            employeeIDsInSchedule[i].Add(candidate.PUUserID);
                                                            chosen = candidate;
                                                            bool inList = false;
                                                            // Loop to see if a corresponding user is in the list of hours.
                                                            foreach (PUUserVMHours userVMHours in _employeeHours)
                                                            {
                                                                // If user matches an member
                                                                if (userVMHours.PUUserID.Equals(chosen.PUUserID))
                                                                {
                                                                    inList = true;
                                                                    // Find which week's total hours to update
                                                                    if (i < (daysInSchedule / 2))
                                                                    {
                                                                        userVMHours.Week1Hours += (decimal)(shiftEnd.Subtract(shiftStart)).TotalHours;
                                                                    }
                                                                    else
                                                                    {
                                                                        userVMHours.Week2Hours += (decimal)(shiftEnd.Subtract(shiftStart)).TotalHours;
                                                                    }
                                                                }
                                                            }
                                                            if (!inList)
                                                            {
                                                                // Build a new userVMHours add the hours to the correct week.
                                                                PUUserVMHours userVMHours = new PUUserVMHours
                                                                {
                                                                    PUUserID  = chosen.PUUserID,
                                                                    Email     = chosen.Email,
                                                                    FirstName = chosen.FirstName,
                                                                    LastName  = chosen.LastName
                                                                };
                                                                if (i < (daysInSchedule / 2))
                                                                {
                                                                    userVMHours.Week1Hours += (decimal)(shiftEnd.Subtract(shiftStart)).TotalHours;
                                                                    userVMHours.Week2Hours  = 0;
                                                                }
                                                                else
                                                                {
                                                                    userVMHours.Week1Hours  = 0;
                                                                    userVMHours.Week2Hours += (decimal)(shiftEnd.Subtract(shiftStart)).TotalHours;
                                                                }
                                                                _employeeHours.Add(userVMHours);
                                                            }
                                                        }
                                                        // If it was found, but failed to meet the alternate requirements set found back to false.
                                                        else
                                                        {
                                                            found = false;
                                                        }
                                                    }
                                                }
                                            }
                                            // Move to the next list item.
                                            next++;
                                            if (next != avaliable.Count)
                                            {
                                                candidate = avaliable[next];
                                            }
                                            // Decide if the loop continues
                                        } while (!found && next < avaliable.Count);

                                        // If an appropriate user was found a shift is added to the schedule.
                                        if (found)
                                        {
                                            schedule.ScheduleLines.Add(new ShiftUserVM
                                            {
                                                ShiftTimeID  = line.ShiftTimeID,
                                                ShiftDate    = date.AddDays(i),
                                                RoleID       = line.ERoleID,
                                                EmployeeID   = chosen.PUUserID,
                                                EmployeeName = chosen.LastName + ", " + chosen.FirstName,
                                                ShiftStart   = shiftStart.ToShortTimeString(),
                                                ShiftEnd     = shiftEnd.ToShortTimeString()
                                            });
                                        }
                                        // If no users were available the openings are recorded in the open positions list.
                                        else
                                        {
                                            _openPositions.Add(new OpenPosition
                                            {
                                                ERoleID = line.ERoleID,
                                                count   = j
                                            });
                                            // To prevent more checks for this baseSchedule line based on the remaining count.
                                            end = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    throw new ApplicationException("That schedule is too far in the future.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(schedule);
        }
        public ActionResult Save(ScheduleVM vm, string[] Destinations)
        {
            if (string.IsNullOrEmpty(vm.ScheduleName))
            {
                vm.SaveResult += "請輸入 Schedule Name!<br />";
            }
            if (string.IsNullOrEmpty(vm.ModeType))
            {
                vm.SaveResult += "請選擇 Mode Type!<br />";
            }
            if (string.IsNullOrEmpty(vm.CustomerName))
            {
                vm.SaveResult += "請輸入 Customer Name!<br />";
            }
            if (string.IsNullOrEmpty(vm.Format))
            {
                vm.SaveResult += "請選擇 Format!<br />";
            }
            if (string.IsNullOrEmpty(vm.SettingName))
            {
                vm.SaveResult += "請選擇 Setting Name!<br />";
            }
            if (string.IsNullOrEmpty(vm.WorkType))
            {
                vm.SaveResult += "請選擇 Work Type!<br />";
            }

            // DATE
            if (vm.WorkType.Equals("1"))
            {
                if (string.IsNullOrEmpty(vm.Date))
                {
                    vm.SaveResult += "請輸入 Date!<br />";
                }
                // check Month
                if (!string.IsNullOrEmpty(vm.Month) && !Func.IsNumeric(vm.Month, ",", 1, 12))
                {
                    vm.SaveResult += "請檢查 Month 是否正確(超出範圍 1-12)!<br />";
                }
                // check Date
                if (!string.IsNullOrEmpty(vm.Date) && !Func.IsNumeric(vm.Date, ",", 1, 31))
                {
                    vm.SaveResult += "請檢查 Date 是否正確(超出範圍 1-31)!<br />";
                }
            }
            // DAY
            else if (vm.WorkType.Equals("2"))
            {
                if (string.IsNullOrEmpty(vm.Min))
                {
                    vm.SaveResult += "請輸入 Min!<br />";
                }
                // check Day
                if (!string.IsNullOrEmpty(vm.Day) && !Func.IsNumeric(vm.Day, ",", 1, 7))
                {
                    vm.SaveResult += "請檢查 Day 是否正確(超出範圍 1-7)!<br />";
                }
                // check Hour
                if (!string.IsNullOrEmpty(vm.Hour) && !Func.IsNumeric(vm.Hour, ",", 0, 23))
                {
                    vm.SaveResult += "請檢查 Hour 是否正確(超出範圍 0-23)!<br />";
                }
                // check Min
                if (!string.IsNullOrEmpty(vm.Min) && !Func.IsNumeric(vm.Min, ",", 0, 59))
                {
                    vm.SaveResult += "請檢查 Min 是否正確(超出範圍 0-59)!<br />";
                }
            }

            if (Destinations == null || Destinations.Length == 0)
            {
                if (vm.ModeType.Equals("EXPORT"))
                {
                    vm.SaveResult += "請至少選擇一項 Destination!<br />";
                }
                else if (vm.ModeType.Equals("IMPORT"))
                {
                    vm.SaveResult += "請選擇 Source!<br />";
                }
            }
            else
            {
                // Path
                if (Destinations.Contains("1") && string.IsNullOrEmpty(vm.Path))
                {
                    vm.SaveResult += "請輸入 Path!<br />";
                }
                // Email
                if (Destinations.Contains("2") && string.IsNullOrEmpty(vm.Email))
                {
                    vm.SaveResult += "請輸入 EMail!<BR />";
                }
                // FTP
                if (Destinations.Contains("3"))
                {
                    if (string.IsNullOrEmpty(vm.FTPServer))
                    {
                        vm.SaveResult += "請輸入 FTP Server!<br />";
                    }
                    if (string.IsNullOrEmpty(vm.FTPAccount))
                    {
                        vm.SaveResult += "請輸入 FTP Account!<br />";
                    }
                    if (string.IsNullOrEmpty(vm.FTPPassword))
                    {
                        vm.SaveResult += "請輸入 FTP Password!<br />";
                    }
                }
            }
            if (!string.IsNullOrEmpty(vm.SaveResult))
            {
                return(View("Edit", vm));
            }

            using (tblScheduleRepository rep = new tblScheduleRepository())
            {
                tblSchedule s = new tblSchedule()
                {
                    ScheduleName = vm.ScheduleName,
                    CustomerName = vm.CustomerName,
                    ModeType     = vm.ModeType,
                    Format       = vm.Format,
                    SettingName  = vm.SettingName,
                    Destination  = string.Join(",", Destinations),
                    WorkType     = vm.WorkType,
                    Active       = vm.Active
                };
                // DATE
                if (vm.WorkType.Equals("1"))
                {
                    s.Month = vm.Month;
                    s.Date  = vm.Date;
                }
                // DAY
                else if (vm.WorkType.Equals("2"))
                {
                    s.Day  = vm.Day;
                    s.Hour = vm.Hour;
                    s.Min  = vm.Min;
                }

                // Destination-PATH
                if (Destinations.Contains("1"))
                {
                    s.Path = vm.Path;
                }
                // Destination-EMAIL
                if (Destinations.Contains("2"))
                {
                    s.Email = vm.Email;
                }
                // Destination-FTP
                if (Destinations.Contains("3"))
                {
                    s.FTPAccount  = vm.FTPAccount;
                    s.FTPPassword = vm.FTPPassword;
                    s.FTPServer   = vm.FTPServer;
                }

                vm.SaveResult = rep.Save(vm.originScheduleName, s, userInfo.Account);
                if (vm.SaveResult.Equals("ok"))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("Edit", vm));
                }
            }
        }
Пример #29
0
        public Schedule()
        {
            InitializeComponent();

            DataContext = new ScheduleVM();
        }
        /// <summary>
        /// Creator: Jordan Lindo
        /// Created: 4/12/2020
        /// Approver: Chase Schulte
        ///
        /// Retrieves a list of schedule vms.
        /// </summary>
        /// <remarks>
        /// Updater: NA
        /// Updated: NA
        /// Update: NA
        ///
        /// </remarks>
        /// <param name="active"></param>
        /// <returns></returns>
        public List <ScheduleVM> SelectAllSchedules(bool active)
        {
            List <ScheduleVM> schedules = new List <ScheduleVM>();
            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_select_all_schedules_by_active", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Active", active);

            try
            {
                conn.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ScheduleVM scheduleVM = new ScheduleVM
                        {
                            ScheduleID     = reader.GetInt32(0),
                            StartDate      = reader.GetDateTime(1),
                            EndDate        = reader.GetDateTime(2),
                            CreatingUserID = reader.GetInt32(3),
                            CreatorName    = reader.GetString(4) + " " + reader.GetString(5),
                            Active         = active,
                            ScheduleLines  = new List <ShiftUserVM>()
                        };

                        schedules.Add(scheduleVM);
                    }
                }
                reader.Close();
                foreach (ScheduleVM schedule in schedules)
                {
                    var cmd2 = new SqlCommand("sp_select_shifts_by_scheduleid", conn);
                    cmd2.CommandType = CommandType.StoredProcedure;
                    cmd2.Parameters.AddWithValue("@ScheduleID", schedule.ScheduleID);
                    var reader2 = cmd2.ExecuteReader();
                    if (reader2.HasRows)
                    {
                        while (reader2.Read())
                        {
                            schedule.ScheduleLines.Add(new ShiftUserVM
                            {
                                ScheduleID   = schedule.ScheduleID,
                                ShiftID      = reader2.GetInt32(0),
                                ShiftTimeID  = reader2.GetInt32(1),
                                ShiftDate    = reader2.GetDateTime(2),
                                EmployeeID   = reader2.GetInt32(3),
                                RoleID       = reader2.GetString(4),
                                EmployeeName = reader2.GetString(5) + ", " + reader2.GetString(6),
                                ShiftStart   = reader2.GetString(7),
                                ShiftEnd     = reader2.GetString(8)
                            });
                        }
                    }
                    reader2.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }

            return(schedules);
        }