public static IEnumerable <ShiftTemplate> ShiftTemplates() { var shiftTemplates = new List <ShiftTemplate>(); var st1 = new ShiftTemplate() { Id = 0, DayOfWeek = DayOfWeek.Monday, RestaurantId = 2, Timeslot = new ShiftTimeslot() { Id = 1 } }; var st2 = new ShiftTemplate() { Id = 0, DayOfWeek = DayOfWeek.Monday, RestaurantId = 2, Timeslot = new ShiftTimeslot() { Id = 1 } }; shiftTemplates.Add(st1); shiftTemplates.Add(st2); return(shiftTemplates); }
private static bool IsShiftRequired(ShiftTemplate shiftTemplate, DayOfWeek dayOfWeek) { switch (dayOfWeek) { case DayOfWeek.Monday: return(shiftTemplate.Monday); case DayOfWeek.Tuesday: return(shiftTemplate.Tuesday); case DayOfWeek.Wednesday: return(shiftTemplate.Wednesday); case DayOfWeek.Thursday: return(shiftTemplate.Thursday); case DayOfWeek.Friday: return(shiftTemplate.Friday); case DayOfWeek.Saturday: return(shiftTemplate.Saturday); case DayOfWeek.Sunday: return(shiftTemplate.Sunday); } return(false); }
protected override void ItemShowing() { ShiftTemplate item = UpdatingItem as ShiftTemplate; if (item == null) { return; } txtName.Text = item.Name; chkHolidayShifted.Checked = (item.Options & TemplateOptions.HolidayShifted) == TemplateOptions.HolidayShifted; chkWeekendShifted.Checked = (item.Options & TemplateOptions.WeekendShifted) == TemplateOptions.WeekendShifted; if (item.Items != null && item.Items.Count > 0) { int i = 0; foreach (TemplateItem it in item.Items) { i++; if (i > 6) { break; } (this.Controls["chkShift" + i.ToString()] as CheckBox).Checked = true; (this.Controls["txtShifts" + i.ToString()] as TextBox).Text = GetShiftString(it.Shifts); (this.Controls["txtShifts" + i.ToString()] as TextBox).Tag = it.Shifts; (this.Controls["txtDuration" + i.ToString()] as NumericUpDown).Value = it.Duration; Control panel = this.Controls["panel" + i.ToString()]; (panel.Controls["rdDay" + i.ToString()] as RadioButton).Checked = it.DurationUnit == 0; (panel.Controls["rdTime" + i.ToString()] as RadioButton).Checked = it.DurationUnit == 1; (this.Controls["txtRest" + i.ToString()] as NumericUpDown).Value = it.RestDays; } } txtMemo.Text = item.Memo; }
public static ShiftTemplate Create(T_ShiftArrangeTemplate item) { ShiftTemplate st = new ShiftTemplate(); st.ID = item.ID; st.Name = item.Name; st.Options = item.Options; st.Memo = item.Memo; if (!string.IsNullOrEmpty(item.Value)) { try { using (StringReader reader = new StringReader(item.Value)) { XmlSerializer ser = new XmlSerializer(typeof(List <TemplateItem>)); st.Items = ser.Deserialize(reader) as List <TemplateItem>; } } catch (Exception ex) { LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } } return(st); }
public static T_ShiftArrangeTemplate Create(ShiftTemplate item) { T_ShiftArrangeTemplate tst = new T_ShiftArrangeTemplate(); tst.ID = item.ID; tst.Name = item.Name; tst.Options = item.Options; tst.Memo = item.Memo; if (item.Items != null && item.Items.Count > 0) { try { using (StringWriter writer = new StringWriter()) { XmlSerializer ser = new XmlSerializer(typeof(List <TemplateItem>)); ser.Serialize(writer, item.Items); if (writer.GetStringBuilder() != null) { tst.Value = writer.GetStringBuilder().ToString(); } } } catch (Exception ex) { LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } } return(tst); }
// DELETE api/shifttemplateapi/5 public void Delete(Guid id) { ShiftTemplate shiftTemplate = db.ShiftTemplates.Find(id); if (shiftTemplate != null) { if (ClaimsAuthorization.CheckAccess("Put", "BusinessLocationId", shiftTemplate.BusinessLocation.Id.ToString())) { shiftTemplate.Enabled = false; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, ex)); } } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized)); } } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } }
protected override void ShowItemInGridViewRow(DataGridViewRow row, object item) { ShiftTemplate st = item as ShiftTemplate; row.Tag = st; row.Cells["colName"].Value = st.Name; row.Cells["colMemo"].Value = st.Memo; }
private void AddShiftsFromTemplate(Roster roster, ShiftTemplate shiftTemplate, DayOfWeek dayWeek) { var shift = CreateShiftFromTemplate(roster, shiftTemplate, dayWeek); if (shift != null && shift.StartTime > WebUI.Common.Common.DateTimeNowLocal()) //ensure shift does not occur in the paste { roster.Shifts.Add(shift); } }
private void lnkTemplate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { FrmShiftTemplateMaster frm = new FrmShiftTemplateMaster(); frm.StartPosition = FormStartPosition.CenterParent; frm.ForSelect = true; if (frm.ShowDialog() == DialogResult.OK) { ShiftTemplate template = frm.SelectedItem as ShiftTemplate; txtShiftTemplate.Text = template.Name; txtShiftTemplate.Tag = template; } }
private Shift CreateShiftFromTemplate(Roster roster, ShiftTemplate shiftTemplate, DayOfWeek dayOfWeek) { int dayWeekOffset = 6; //Set default offset for Sunday (6 days from monday which is our week start date) //Adjust offset so that Monday is zero, and sunday is 6 if (dayOfWeek != DayOfWeek.Sunday) { dayWeekOffset = (int)dayOfWeek - 1; } DateTime dtOccurrenceDate = roster.WeekStartDate.AddDays(dayWeekOffset); //Ensure that this shift template does not have a corresponding recurring shift cancellation which is approved var approvedShiftCancelRequests = db.RecurringShiftChangeRequests.Where(sc => sc.ShiftTemplate.Id == shiftTemplate.Id && sc.OccurenceDate == dtOccurrenceDate && sc.Type == ShiftRequestType.Cancel && sc.Status == RequestStatus.Approved); // DbFunctions.CreateDateTime //If the shift template does not have a corresponding cancellation for this occurrence, then proceed and create the shift if (approvedShiftCancelRequests.Count() == 0) { Shift shift = new Shift(); shift.Id = Guid.NewGuid(); shift.InternalLocation = shiftTemplate.InternalLocation; shift.Role = shiftTemplate.Role; shift.Employee = shiftTemplate.Employee; //shift.ExternalShiftBroadcast = new ExternalShiftBroadcast { Id = Guid.NewGuid(), Description = "", Wage = "" }; shift.StartTime = DateTime.Parse(roster.WeekStartDate.AddDays(dayWeekOffset).ToShortDateString() + " " + shiftTemplate.StartTime.ToString()); if (shiftTemplate.FinishNextDay) { shift.FinishTime = DateTime.Parse(roster.WeekStartDate.AddDays(dayWeekOffset + 1).ToShortDateString() + " " + shiftTemplate.FinishTime.ToString()); } else { shift.FinishTime = DateTime.Parse(roster.WeekStartDate.AddDays(dayWeekOffset).ToShortDateString() + " " + shiftTemplate.FinishTime.ToString()); } shift.ShiftTemplate = shiftTemplate; return(shift); } else { return(null); } }
protected override object GetItemFromInput() { ShiftTemplate item = UpdatingItem as ShiftTemplate; if (item == null) { item = new ShiftTemplate(); } item.Name = txtName.Text; item.Options = TemplateOptions.None; if (chkHolidayShifted.Checked) { item.Options |= TemplateOptions.HolidayShifted; } if (chkWeekendShifted.Checked) { item.Options |= TemplateOptions.WeekendShifted; } if (item.Items == null) { item.Items = new List <TemplateItem>(); } item.Items.Clear(); for (int i = 1; i <= 6; i++) { if ((this.Controls["chkShift" + i.ToString()] as CheckBox).Checked) { TemplateItem it = new TemplateItem(); it.Shifts = (this.Controls["txtShifts" + i.ToString()] as TextBox).Tag as List <Shift>; it.Duration = (int)(this.Controls["txtDuration" + i.ToString()] as NumericUpDown).Value; Control panel = this.Controls["panel" + i.ToString()]; it.DurationUnit = (panel.Controls["rdTime" + i.ToString()] as RadioButton).Checked ? 1 : 0; it.RestDays = (int)(this.Controls["txtRest" + i.ToString()] as NumericUpDown).Value; item.Items.Add(it); } } item.Memo = txtMemo.Text; return(item); }
private void btnOk_Click(object sender, EventArgs e) { if (txtShiftTemplate.Tag == null) { MessageBox.Show("没有选择模板"); return; } if (this.ucDateTimeInterval1.StartDateTime > this.ucDateTimeInterval1.EndDateTime) { MessageBox.Show("应用的日期不正确,开始时间大于结束时间"); return; } if (this.departmentTreeview1.SelectedStaff == null || this.departmentTreeview1.SelectedStaff.Count == 0) { MessageBox.Show("没有选择人员"); return; } FrmProcessing frm = new FrmProcessing(); DatetimeRange dr = new DatetimeRange(ucDateTimeInterval1.StartDateTime, ucDateTimeInterval1.EndDateTime); List <Staff> staffs = this.departmentTreeview1.SelectedStaff; ShiftTemplate template = txtShiftTemplate.Tag as ShiftTemplate; Action action = delegate() { decimal count = 0; try { foreach (Staff staff in staffs) { try { frm.ShowProgress(string.Format("正在应用模板 {0}...", staff.Name), count / staffs.Count); count++; List <ShiftArrange> items = template.ApplyTemplateTo(staff, dr); CommandResult ret = (new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri)).ShiftArrange(staff.ID, dr, items); if (ret.Result == ResultCode.Successful) { frm.ShowProgress(string.Format("应用模板成功 {0}", staff.Name), count / staffs.Count); } else { frm.ShowProgress(string.Format("应用模板失败 {0}", staff.Name), count / staffs.Count); } } catch (Exception ex) { LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } } } catch (ThreadAbortException) { } }; Thread t = new Thread(new ThreadStart(action)); t.IsBackground = true; t.Start(); if (frm.ShowDialog() != DialogResult.OK) { t.Abort(); } this.DialogResult = DialogResult.OK; }
public HttpResponseMessage ApproveRecurringShiftChangeRequest(string id, ShiftChangeActionDTO acceptDTO) { try { var requestId = Guid.Parse(id); var email = HttpContext.Current.User.Identity.Name; var scRequest = db.RecurringShiftChangeRequests.FirstOrDefault(er => er.Id == requestId && er.Status == RequestStatus.Pending); if (scRequest == null) { return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "Unable to find pending shift change request.")); } var weekStarting = WebUI.Common.Common.GetStartOfWeek(scRequest.OccurenceDate, DayOfWeek.Monday); //Ensure user has "Put" manager permissions for the business which the request corresponds to if (!ClaimsAuthorization.CheckAccess("Put", "BusinessLocationId", scRequest.ShiftTemplate.BusinessLocation.Id.ToString())) { return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "You do not have permissions.")); } //Ensure week starting date is in the future AND is not already rostered //if (weekStarting < WebUI.Common.Common.DateTimeNowLocal()) // return Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "This shift occurs in a week starting in the past"); //Ensure occurence date is after current time if (new DateTime(scRequest.OccurenceDate.Year, scRequest.OccurenceDate.Month, scRequest.OccurenceDate.Day, scRequest.ShiftTemplate.StartTime.Hours, scRequest.OccurenceDate.Minute, 0) < WebUI.Common.Common.DateTimeNowLocal()) { return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "This shift occurs in the past")); } var roster = db.Rosters.FirstOrDefault(r => r.WeekStartDate == weekStarting && r.BusinessLocation.Id == scRequest.ShiftTemplate.BusinessLocation.Id); if (roster != null) { return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "Roster already created for week starting " + weekStarting.ToShortDateString())); } //Update Request object scRequest.Status = RequestStatus.Approved; scRequest.ActionedDate = WebUI.Common.Common.DateTimeNowLocal(); scRequest.ActionedComment = acceptDTO.Reason; //Attach the Employee record which matches the logged in user profile and business id. scRequest.ActionedBy = db.UserProfiles.FirstOrDefault(usr => usr.Email == email).Employees.FirstOrDefault(emp => emp.BusinessLocation.Id == scRequest.ShiftTemplate.BusinessLocation.Id); if (scRequest.Type == ShiftRequestType.Cancel) { var occurenceDayOfWeek = scRequest.OccurenceDate.DayOfWeek; //Create one off OPEN shift template to fill this shift ShiftTemplate sst = new ShiftTemplate { Id = Guid.NewGuid(), WeekStarting = weekStarting, StartTime = scRequest.ShiftTemplate.StartTime, FinishTime = scRequest.ShiftTemplate.FinishTime, Monday = (occurenceDayOfWeek == DayOfWeek.Monday ? true : false), Tuesday = (occurenceDayOfWeek == DayOfWeek.Tuesday ? true : false), Wednesday = (occurenceDayOfWeek == DayOfWeek.Wednesday ? true : false), Thursday = (occurenceDayOfWeek == DayOfWeek.Thursday ? true : false), Friday = (occurenceDayOfWeek == DayOfWeek.Friday ? true : false), Saturday = (occurenceDayOfWeek == DayOfWeek.Saturday ? true : false), Sunday = (occurenceDayOfWeek == DayOfWeek.Sunday ? true : false), Frequency = ShiftFrequency.OneOff, BusinessLocation = scRequest.ShiftTemplate.BusinessLocation, Employee = null, //set to an OPEN SHIFT InternalLocation = scRequest.ShiftTemplate.InternalLocation, Role = scRequest.ShiftTemplate.Role, Enabled = true }; db.ShiftTemplates.Add(sst); //TODO create an exception to recurring shift template to show that this have been cancelled??? } db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public static void MapDtoToEntityForUpdating(ShiftTemplateDto shiftTemplateDto, ShiftTemplate shiftTemplate) { shiftTemplate.IsActive = shiftTemplateDto.IsActive; shiftTemplate.Name = shiftTemplateDto.Name; shiftTemplate.ShiftRate = shiftTemplateDto.ShiftRate; shiftTemplate.ShiftTypeId = shiftTemplateDto.ShiftTypeId; shiftTemplate.ResourceId = shiftTemplateDto.ResourceId; shiftTemplate.SiteId = shiftTemplateDto.SiteId; shiftTemplate.SubSiteId = shiftTemplateDto.SubSiteId; shiftTemplate.StartTime = shiftTemplateDto.StartTime; shiftTemplate.EndTime = shiftTemplateDto.EndTime; shiftTemplate.Duration = shiftTemplateDto.Duration; shiftTemplate.UnpaidBreakDuration = shiftTemplateDto.UnpaidBreakDuration; shiftTemplate.Mon = shiftTemplateDto.Mon; shiftTemplate.Tue = shiftTemplateDto.Tue; shiftTemplate.Wed = shiftTemplateDto.Wed; shiftTemplate.Thu = shiftTemplateDto.Thu; shiftTemplate.Fri = shiftTemplateDto.Fri; shiftTemplate.Sat = shiftTemplateDto.Sat; shiftTemplate.Sun = shiftTemplateDto.Sun; }