/// <summary> /// New Term /// </summary> /// <param name="startDate">Can't be 00:00</param> /// <param name="termStyle"></param> /// <param name="lenghtOfMinutes"></param> /// <returns></returns> public static Term New(DateTime startDate, TermStyle termStyle, int lenghtOfMinutes) { if (termStyle == null) { throw new ArgumentNullException("termStyle"); } var startTime = startDate; if (termStyle is AssignmentType) { //用途不明却,需注意旧版使用情境 var startValue = startDate.Hour * 60 + startDate.Minute; if (startValue == termStyle.TimeRange.StartValue) { startTime = startDate.Date.AddMinutes(termStyle.TimeRange.StartValue); } } var length = TimeSpan.FromMinutes(lenghtOfMinutes); var ci = termStyle.Type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, CallingConventions.HasThis, new[] { typeof(DateTime), typeof(TimeSpan) }, null); var obj = ci.Invoke(new object[] { startTime, length }); obj.MAssign(new { termStyle.Background, Text = termStyle.Name, termStyle.OnService, termStyle.AsARest, TermStyleId = termStyle.Id }); obj.SaftyInvoke <Term>(t => t.IsNeedSeat = termStyle.Occupied); obj.SaftyInvoke <IAssignment>(t => { t.HrDate = startDate.Date; }); if (termStyle is AssignmentType) { var type = termStyle.As <AssignmentType>(); obj.MAssign(new { type.AsAWork, type.IgnoreAdherence, type.GapGuaranteed }); } return(obj as Term); }
public static Term NewAssignment(DateTime unCheckedstart, DateTime uncheckedEnd, TermStyle termStyle) { var start = unCheckedstart.TurnToMultiplesOf5(); var end = uncheckedEnd.TurnToMultiplesOf5(); if (termStyle.Type.FullName != null) { if (termStyle as BasicAssignmentType == null && termStyle.Type.FullName.Contains("Event")) { throw new ArgumentNullException("termStyle"); } } if (end < start) { end = end.AddDays(1); } var length = end.Subtract(start); var ci = termStyle.Type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, CallingConventions.HasThis, new[] { typeof(DateTime), typeof(TimeSpan) }, null); var obj = ci.Invoke(new object[] { start, length }); var type = termStyle.As <BasicAssignmentType>(); obj.MAssign(new { type.Background, Text = type.Name, type.OnService, IsNeedSeat = type.Occupied, type.AsAWork, type.AsARest, type.IgnoreAdherence, type.GapGuaranteed, TermStyleId = type.Id }); return(obj as Term); }