Exemplo n.º 1
0
        private DateTimeInfo GetNextDateTimeInfo(int nextSelectionStart)
        {
            DateTimeInfo nextDateTimeInfo = this.GetDateTimeInfo(nextSelectionStart);

            if (nextDateTimeInfo == null)
            {
                nextDateTimeInfo = _dateTimeInfoList.First();
            }

            DateTimeInfo initialDateTimeInfo = nextDateTimeInfo;

            while (nextDateTimeInfo.Type == DateTimePart.Other)
            {
                nextDateTimeInfo = this.GetDateTimeInfo(nextDateTimeInfo.StartPosition + nextDateTimeInfo.Length);
                if (nextDateTimeInfo == null)
                {
                    nextDateTimeInfo = _dateTimeInfoList.First();
                }
                if (object.Equals(nextDateTimeInfo, initialDateTimeInfo))
                {
                    throw new InvalidOperationException("Couldn't find a valid DateTimeInfo.");
                }
            }
            return(nextDateTimeInfo);
        }
Exemplo n.º 2
0
        public void LoadData()
        {
            var dc = new TaskDataContext(this.UserCD);
            var l  = dc.Task_CompleteTimeIsNull_Get(this.UserCD, null, DateTimeInfo.GetToday().Date);

            if (l.Count > 0)
            {
                this.Data.HasData = true;
                for (int i = 0; i < l.Count; i++)
                {
                    var r = l[i].Map(new TaskRecord());
                    if (i == 0)
                    {
                        this.Data.Task = r;
                    }
                    else
                    {
                        this.Data.TaskList.Add(r);
                    }
                }
            }
            else
            {
                this.Data.HasData = false;
            }
            this.UpdateCommandData(State.AskComplete);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Now
        /// </summary>
        public override string ToString()
        {
            StringBuilder logBuffer = new StringBuilder();

            logBuffer.Append("[");
            logBuffer.Append(DateTimeInfo.ToString("yyyyMMdd-HH:mm:ss.fffff"));
            logBuffer.Append("] [");
            if (Caller != "UNKNOWN")
            {
                logBuffer.Append(Caller.PadRight(25, ' '));
            }
            logBuffer.Append("]");

            if (Exception == null)
            {
                logBuffer.Append(" [I] ");
                logBuffer.Append(Message);
            }
            else
            {
                logBuffer.Append(" [E] ");
                logBuffer.Append(" Exception Raised   ");
                logBuffer.Append(System.Environment.NewLine);
                logBuffer.Append("                                                    ");
                logBuffer.Append(Exception.Message);
                logBuffer.Append(System.Environment.NewLine);
                logBuffer.Append(Exception != null && Exception.StackTrace != null ? Exception.StackTrace.Replace(" at ", "                                                   at ") : "ERROR");
                logBuffer.Append(Message);
            }

            return(logBuffer.ToString());
        }
Exemplo n.º 4
0
        private DateTimeInfo GetPreviousDateTimeInfo(int previousSelectionStart)
        {
            DateTimeInfo previousDateTimeInfo = this.GetDateTimeInfo(previousSelectionStart);

            if (previousDateTimeInfo == null)
            {
                if (_dateTimeInfoList.Count > 0)
                {
                    previousDateTimeInfo = _dateTimeInfoList.Last();
                }
            }

            DateTimeInfo initialDateTimeInfo = previousDateTimeInfo;

            while ((previousDateTimeInfo != null) && (previousDateTimeInfo.Type == DateTimePart.Other))
            {
                previousDateTimeInfo = this.GetDateTimeInfo(previousDateTimeInfo.StartPosition - 1);
                if (previousDateTimeInfo == null)
                {
                    previousDateTimeInfo = _dateTimeInfoList.Last();
                }
                if (object.Equals(previousDateTimeInfo, initialDateTimeInfo))
                {
                    throw new InvalidOperationException("Couldn't find a valid DateTimeInfo.");
                }
            }
            return(previousDateTimeInfo);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 调整 slave pc 时间
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdjustTime_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("确定调整Slave PC 时间吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    var tasks = new List <Task>();
                    this.dtpAdjustTime.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    DateTimeInfo dtInfo = new DateTimeInfo(this.dtpAdjustTime.Value);
                    foreach (var iixServer in Global.ListIIXSerevr)
                    {
                        if (iixServer.IsEnable == false)
                        {
                            continue;
                        }

                        tasks.Add(Task.Factory.StartNew(() =>
                        {
                            IIXExecute.AdjustPCTime(iixServer, dtInfo);
                        }));
                    }

                    Task.WaitAll(tasks.ToArray());
                }
            }
            catch (Exception ex)
            {
                Log.GetInstance().ErrorWrite("系统错误,请查询日志文件检查。");
                Log.WriterExceptionLog(ex.ToString());
            }
        }
Exemplo n.º 6
0
 private void UpdateCommandData(State nextState)
 {
     this.Data.State     = nextState;
     _Record.RetryTime   = null;
     _Record.ExpireTime  = DateTimeInfo.GetNow().AddMinutes(ExpireMinutes);
     _Record.CommandData = JsonConvert.SerializeObject(this.Data);
     this.UpdateCommandData();
 }
Exemplo n.º 7
0
 internal void Select(DateTimeInfo info)
 {
     if (info != null)
     {
         _fireSelectionChangedEvent = false;
         this.TextBox.Select(info.StartPosition, info.Length);
         _fireSelectionChangedEvent = true;
         _selectedDateTimeInfo      = info;
     }
 }
Exemplo n.º 8
0
        private void StartTaskAddCommand()
        {
            var dc          = new BotDataContext(this.UserCD);
            var data        = new BotCommand_TaskAdd.CommandData();
            var rBotCommand = dc.BotCommand_Add(DatabaseSetting.NewGuid(), this.UserCD, BotCommandName.TaskAdd, null
                                                , DateTimeInfo.GetNow().AddMinutes(BotCommand_TaskAdd.ExpireMinutes), JsonConvert.SerializeObject(data));
            var cm = new BotCommand_TaskAdd(this.RecipientID, this.BotCD, rBotCommand);

            cm.ResponseMessage();
        }
Exemplo n.º 9
0
        internal void Select(DateTimeInfo info)
        {
            if ((info != null) && !info.Equals(_selectedDateTimeInfo) && (this.TextBox != null) && !string.IsNullOrEmpty(this.TextBox.Text))
            {
                _fireSelectionChangedEvent = false;
                this.TextBox.Select(info.StartPosition, info.Length);
                _fireSelectionChangedEvent = true;
                _selectedDateTimeInfo      = info;
#if VS2008
                this.CurrentDateTimePart = info.Type;
#else
                this.SetCurrentValue(DateTimeUpDownBase <T> .CurrentDateTimePartProperty, info.Type);
#endif
            }
        }
Exemplo n.º 10
0
        private void Increment(int step)
        {
            _fireSelectionChangedEvent = false;

            var currentValue = this.ConvertTextToValue(this.TextBox.Text);

            if (currentValue.HasValue)
            {
                var newValue = this.UpdateDateTime(currentValue, step);
                if (newValue == null)
                {
                    return;
                }
                this.TextBox.Text = newValue.Value.ToString(this.GetFormatString(this.Format), this.CultureInfo);
            }
            else
            {
                this.TextBox.Text = (this.DefaultValue != null)
                                    ? this.DefaultValue.Value.ToString(this.GetFormatString(this.Format), this.CultureInfo)
                                    : this.ContextNow.ToString(this.GetFormatString(this.Format), this.CultureInfo);
            }

            if (this.TextBox != null)
            {
                DateTimeInfo info = _selectedDateTimeInfo;
                //this only occurs when the user manually type in a value for the Value Property
                if (info == null)
                {
                    info = (this.CurrentDateTimePart != DateTimePart.Other) ? this.GetDateTimeInfo(this.CurrentDateTimePart) : _dateTimeInfoList[0];
                }
                if (info == null)
                {
                    info = _dateTimeInfoList[0];
                }

                //whenever the value changes we need to parse out the value into out DateTimeInfo segments so we can keep track of the individual pieces
                this.ParseValueIntoDateTimeInfo(this.ConvertTextToValue(this.TextBox.Text));

                //we loose our selection when the Value is set so we need to reselect it without firing the selection changed event
                this.TextBox.Select(info.StartPosition, info.Length);
            }
            _fireSelectionChangedEvent = true;

            this.SyncTextAndValueProperties(true, Text);
        }
Exemplo n.º 11
0
        protected void SendImage(BotActionType actionType)
        {
            var cl = new FacebookBotClient();

            cl.SuppressThrowException = true;

            var l = WebApp.Current.DatabaseCache.BotActionImage
                    .Where(el => el.BotCD == this.BotCD && el.ActionType == actionType).ToList();

            if (l.Count == 0)
            {
                return;
            }
            var index  = _Random.Next(l.Count);
            var rImage = l[index];

            HttpResponse res         = null;
            var          rAttachment = WebApp.Current.DatabaseCache.FacebookAttachment.FirstOrDefault(el => el.Url == rImage.ImageUrl);

            if (rAttachment == null)
            {
                res = cl.SendImage(this.RecipientID, rImage.ImageUrl);
                if (res.StatusCode == HttpStatusCode.OK)
                {
                    try
                    {
                        var o = JsonConvert.DeserializeObject <SendMediaResponse>(res.BodyText);
                        rAttachment = new FacebookAttachmentRecord();
                        rAttachment.AttachmentID = o.Attachment_ID;
                        rAttachment.Url          = rImage.ImageUrl;
                        rAttachment.CreateTime   = DateTimeInfo.GetNow();
                        var dc = new SystemDataContext();
                        dc.FacebookAttachment_Insert(rAttachment);
                    }
                    catch (Exception ex)
                    {
                        HignullLog.Current.Add(ex);
                    }
                }
            }
            else
            {
                res = cl.SendAttachment(this.RecipientID, rAttachment.AttachmentID);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 修改时间
        /// </summary>
        /// <param name="iixServer"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static CmdResultCode AdjustPCTime(IIXServer iixServer, DateTimeInfo dateTime)
        {
            CmdResultCode cmdRes = CmdResultCode.Other;

            cmdRes = iixServer.DmrSvrApi.AdjustPCTime(dateTime);
            iixServer.LatestResult = cmdRes.ToString();

            if (cmdRes == CmdResultCode.Success)
            {
                Log.GetInstance().NormalWrite(string.Format("[{0}]修改时间成功", iixServer.Ip));
            }
            else
            {
                Log.GetInstance().ErrorWrite(string.Format("[{0}]修改时间失败,Error:{1}", iixServer.Ip, cmdRes.ToString()));
            }

            return(cmdRes);
        }
        public void GetCurrentDateTimeInfo_IoT()
        {
            TestHelpers.MockHttpResponder.AddMockResponse(
                DevicePortal.DateTimeInfoApi,
                this.PlatformType,
                this.FriendlyOperatingSystemVersion,
                HttpMethods.Get);

            Task <DateTimeInfo> getTask = TestHelpers.Portal.GetDateTimeInfoAsync();

            getTask.Wait();

            Assert.AreEqual(TaskStatus.RanToCompletion, getTask.Status);
            DateTimeInfo dateTime = getTask.Result;

            // Check some known things about this response.
            Assert.AreEqual(22, dateTime.CurrentDateTime.Day);
        }
Exemplo n.º 14
0
        protected override void OnValueChanged(DateTime?oldValue, DateTime?newValue)
        {
            DateTimeInfo info = _selectedDateTimeInfo;

            //this only occurs when the user manually type in a value for the Value Property
            if (info == null)
            {
                info = (this.CurrentDateTimePart != DateTimePart.Other) ? this.GetDateTimeInfo(this.CurrentDateTimePart) : _dateTimeInfoList[0];
            }
            if (info == null)
            {
                info = _dateTimeInfoList[0];
            }

            //whenever the value changes we need to parse out the value into out DateTimeInfo segments so we can keep track of the individual pieces
            //but only if it is not null
            if (newValue != null)
            {
                ParseValueIntoDateTimeInfo(this.Value);
            }

            base.OnValueChanged(oldValue, newValue);

            if (!_isTextChangedFromUI)
            {
                _lastValidDate = newValue;
            }

            if (TextBox != null)
            {
                //we loose our selection when the Value is set so we need to reselect it without firing the selection changed event
                _fireSelectionChangedEvent = false;
                TextBox.Select(info.StartPosition, info.Length);
                _fireSelectionChangedEvent = true;
            }
        }
Exemplo n.º 15
0
 public Boolean IsExpired()
 {
     return(_Record.ExpireTime.HasValue && _Record.ExpireTime < DateTimeInfo.GetNow());
 }
Exemplo n.º 16
0
        public override HandleMessageResult HandleMessage(UserActionMessage message)
        {
            var cm = message.Command;

            switch (this.Data.State)
            {
            case State.AskStart:
                if (message.ActionType != UserActionType.Postback || cm == null)
                {
                    return(new HandleMessageResult(false));
                }
                if (cm.MethodName == nameof(State.AskStart))
                {
                    if (cm.Value.ToBoolean() == true)
                    {
                        this.LoadData();
                        if (this.Data.Task == null)
                        {
                            this.Complete();
                        }
                        else
                        {
                            this.ResponseAskComplete();
                        }
                    }
                    else
                    {
                        this.Complete();
                    }
                    return(new HandleMessageResult(true));
                }
                break;

            case State.AskComplete:
                if (message.ActionType != UserActionType.Postback || cm == null)
                {
                    return(new HandleMessageResult(false));
                }

                if (cm.MethodName == "TaskSuspend")
                {
                    this.UpdateCommandData(State.AskSuspend);
                    this.ResponseAskSuspend();
                    return(new HandleMessageResult(true));
                }

                if (cm.MethodName == "TaskComplete")
                {
                    var rState = WebApp.Current.DatabaseCache.TaskState.GetDefaultState(this.Data.Task.ProjectCD, "Done");
                    var dc     = new TaskDataContext(this.UserCD);
                    dc.Task_CompleteState_Edit(this.Data.Task.TaskCD, rState.StateCD);
                }
                else if (cm.MethodName == "TaskInCompleted")
                {
                    //Do nothing...
                }
                if (this.Data.TaskList.Count > 0)
                {
                    this.TaskEdit();
                }
                else
                {
                    this.Complete();
                }
                return(new HandleMessageResult(true));

            case State.AskSuspend:
                if (message.ActionType == UserActionType.Postback)
                {
                    if (cm.MethodName == "SuspendDay")
                    {
                        var      dc      = new TaskDataContext(this.UserCD);
                        var      days    = cm.Value.ToInt32();
                        DateTime?dueDate = null;
                        if (days.HasValue)
                        {
                            dueDate = DateTimeInfo.GetToday().Date.AddDays(days.Value);
                        }
                        dc.Task_DueDate_Edit(this.Data.Task.TaskCD, dueDate);
                        this.TaskEdit();
                    }
                }
                else if (message.ActionType == UserActionType.Message)
                {
                    var days = message.Text.ToInt32();
                    if (days > 0)
                    {
                        var dueDate = DateTimeInfo.GetToday().Date.AddDays(days.Value);
                        var dc      = new TaskDataContext(this.UserCD);
                        dc.Task_DueDate_Edit(this.Data.Task.TaskCD, dueDate);
                    }
                    this.TaskEdit();
                }
                return(new HandleMessageResult(true));

            default: throw new InvalidOperationException();
            }
            return(new HandleMessageResult(false));
        }
Exemplo n.º 17
0
        protected override void InitializeDateTimeInfoList(DateTime?value)
        {
            _dateTimeInfoList.Clear();
            _selectedDateTimeInfo = null;

            string format = GetFormatString(Format);

            if (string.IsNullOrEmpty(format))
            {
                return;
            }

            while (format.Length > 0)
            {
                int          elementLength = GetElementLengthByFormat(format);
                DateTimeInfo info          = null;

                switch (format[0])
                {
                case '"':
                case '\'':
                {
                    int closingQuotePosition = format.IndexOf(format[0], 1);
                    info = new DateTimeInfo
                    {
                        IsReadOnly = true,
                        Type       = DateTimePart.Other,
                        Length     = 1,
                        Content    = format.Substring(1, Math.Max(1, closingQuotePosition - 1))
                    };
                    elementLength = Math.Max(1, closingQuotePosition + 1);
                    break;
                }

                case 'D':
                case 'd':
                {
                    string d = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        d = "%" + d;
                    }

                    if (elementLength > 2)
                    {
                        info = new DateTimeInfo
                        {
                            IsReadOnly = true,
                            Type       = DateTimePart.DayName,
                            Length     = elementLength,
                            Format     = d
                        }
                    }
                    ;
                    else
                    {
                        info = new DateTimeInfo
                        {
                            IsReadOnly = false,
                            Type       = DateTimePart.Day,
                            Length     = elementLength,
                            Format     = d
                        }
                    };
                    break;
                }

                case 'F':
                case 'f':
                {
                    string f = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        f = "%" + f;
                    }

                    info = new DateTimeInfo
                    {
                        IsReadOnly = false,
                        Type       = DateTimePart.Millisecond,
                        Length     = elementLength,
                        Format     = f
                    };
                    break;
                }

                case 'h':
                {
                    string h = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        h = "%" + h;
                    }

                    info = new DateTimeInfo
                    {
                        IsReadOnly = false,
                        Type       = DateTimePart.Hour12,
                        Length     = elementLength,
                        Format     = h
                    };
                    break;
                }

                case 'H':
                {
                    string H = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        H = "%" + H;
                    }

                    info = new DateTimeInfo
                    {
                        IsReadOnly = false,
                        Type       = DateTimePart.Hour24,
                        Length     = elementLength,
                        Format     = H
                    };
                    break;
                }

                case 'M':
                {
                    string M = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        M = "%" + M;
                    }

                    if (elementLength >= 3)
                    {
                        info = new DateTimeInfo
                        {
                            IsReadOnly = false,
                            Type       = DateTimePart.MonthName,
                            Length     = elementLength,
                            Format     = M
                        }
                    }
                    ;
                    else
                    {
                        info = new DateTimeInfo
                        {
                            IsReadOnly = false,
                            Type       = DateTimePart.Month,
                            Length     = elementLength,
                            Format     = M
                        }
                    };
                    break;
                }

                case 'S':
                case 's':
                {
                    string s = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        s = "%" + s;
                    }

                    info = new DateTimeInfo
                    {
                        IsReadOnly = false,
                        Type       = DateTimePart.Second,
                        Length     = elementLength,
                        Format     = s
                    };
                    break;
                }

                case 'T':
                case 't':
                {
                    string t = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        t = "%" + t;
                    }

                    info = new DateTimeInfo
                    {
                        IsReadOnly = false,
                        Type       = DateTimePart.AmPmDesignator,
                        Length     = elementLength,
                        Format     = t
                    };
                    break;
                }

                case 'Y':
                case 'y':
                {
                    string y = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        y = "%" + y;
                    }

                    info = new DateTimeInfo
                    {
                        IsReadOnly = false,
                        Type       = DateTimePart.Year,
                        Length     = elementLength,
                        Format     = y
                    };
                    break;
                }

                case '\\':
                {
                    if (format.Length >= 2)
                    {
                        info = new DateTimeInfo
                        {
                            IsReadOnly = true,
                            Content    = format.Substring(1, 1),
                            Length     = 1,
                            Type       = DateTimePart.Other
                        };
                        elementLength = 2;
                    }
                    break;
                }

                case 'g':
                {
                    string g = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        g = "%" + g;
                    }

                    info = new DateTimeInfo
                    {
                        IsReadOnly = true,
                        Type       = DateTimePart.Period,
                        Length     = elementLength,
                        Format     = format.Substring(0, elementLength)
                    };
                    break;
                }

                case 'm':
                {
                    string m = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        m = "%" + m;
                    }

                    info = new DateTimeInfo
                    {
                        IsReadOnly = false,
                        Type       = DateTimePart.Minute,
                        Length     = elementLength,
                        Format     = m
                    };
                    break;
                }

                case 'z':
                {
                    string z = format.Substring(0, elementLength);
                    if (elementLength == 1)
                    {
                        z = "%" + z;
                    }

                    info = new DateTimeInfo
                    {
                        IsReadOnly = true,
                        Type       = DateTimePart.TimeZone,
                        Length     = elementLength,
                        Format     = z
                    };
                    break;
                }

                default:
                {
                    elementLength = 1;
                    info          = new DateTimeInfo
                    {
                        IsReadOnly = true,
                        Length     = 1,
                        Content    = format[0].ToString(),
                        Type       = DateTimePart.Other
                    };
                    break;
                }
                }

                _dateTimeInfoList.Add(info);
                format = format.Substring(elementLength);
            }
        }
Exemplo n.º 18
0
        public override HandleMessageResult HandleMessage(UserActionMessage message)
        {
            var cm = message.Command;

            switch (this.Data.State)
            {
            case State.AskTitle:
                #region
                if (message.ActionType == UserActionType.Message)
                {
                    this.Data.Title = message.Text;
                    this.UpdateCommandData(State.AskProject);
                    this.ResponseAskProject();
                    return(new HandleMessageResult(true));
                }
                break;

                #endregion
            case State.AskProject:
                #region
                if (message.ActionType != UserActionType.Postback || cm == null)
                {
                    return(new HandleMessageResult(false));
                }
                if (cm.MethodName == "SelectProject")
                {
                    this.Data.ProjectCD = Guid.Parse(cm.Value);
                    this.UpdateCommandData(State.AskUser);
                    this.ResponseAskUser();
                    return(new HandleMessageResult(true));
                }
                break;

                #endregion
            case State.AskUser:
                #region
                if (message.ActionType != UserActionType.Postback || cm == null)
                {
                    return(new HandleMessageResult(false));
                }
                if (cm.MethodName == "SelectUser")
                {
                    this.Data.UserCD = cm.Value.ToGuid();
                    this.UpdateCommandData(State.AskAdditional);
                    this.ResponseAskAdditional();
                    return(new HandleMessageResult(true));
                }
                break;

                #endregion
            case State.AskAdditional:
                #region
                if (message.ActionType != UserActionType.Postback || cm == null)
                {
                    return(new HandleMessageResult(false));
                }
                if (cm.MethodName == nameof(BotTextKey.AskTaskAdditionalInfo))
                {
                    if (cm.Value.ToBoolean() == true)
                    {
                        this.UpdateCommandData(State.AskDueDate);
                        this.ResponseAskDueDate();
                    }
                    else
                    {
                        this.AddTask();
                    }
                    return(new HandleMessageResult(true));
                }
                break;

                #endregion
            case State.AskDueDate:
                #region
                if (message.ActionType == UserActionType.Message)
                {
                    var dtime = DateTimeInfo.GetDateTime(message.Text);
                    if (dtime.HasValue)
                    {
                        this.Data.DueDate = dtime.Value.Date;
                    }
                    this.UpdateCommandData(State.AskDescription);
                    this.ResponseAskDescription();
                    return(new HandleMessageResult(true));
                }
                break;

                #endregion
            case State.AskDescription:
                #region
                if (message.ActionType == UserActionType.Message)
                {
                    this.Data.Description = message.Text;
                    this.AddTask();
                    return(new HandleMessageResult(true));
                }
                break;

                #endregion
            default: throw new InvalidOperationException();
            }
            return(new HandleMessageResult(false));
        }
Exemplo n.º 19
0
        private DateTime?UpdateDateTime(DateTime?currentDateTime, int value)
        {
            DateTimeInfo info = _selectedDateTimeInfo;

            //this only occurs when the user manually type in a value for the Value Property
            if (info == null)
            {
                info = (this.CurrentDateTimePart != DateTimePart.Other) ? this.GetDateTimeInfo(this.CurrentDateTimePart) : _dateTimeInfoList[0];
            }
            if (info == null)
            {
                info = _dateTimeInfoList[0];
            }

            DateTime?result = null;

            try
            {
                switch (info.Type)
                {
                case DateTimePart.Year:
                {
                    result = ((DateTime)currentDateTime).AddYears(value);
                    break;
                }

                case DateTimePart.Month:
                case DateTimePart.MonthName:
                {
                    result = ((DateTime)currentDateTime).AddMonths(value);
                    break;
                }

                case DateTimePart.Day:
                case DateTimePart.DayName:
                {
                    result = ((DateTime)currentDateTime).AddDays(value);
                    break;
                }

                case DateTimePart.Hour12:
                case DateTimePart.Hour24:
                {
                    result = ((DateTime)currentDateTime).AddHours(value);
                    break;
                }

                case DateTimePart.Minute:
                {
                    result = ((DateTime)currentDateTime).AddMinutes(value);
                    break;
                }

                case DateTimePart.Second:
                {
                    result = ((DateTime)currentDateTime).AddSeconds(value);
                    break;
                }

                case DateTimePart.Millisecond:
                {
                    result = ((DateTime)currentDateTime).AddMilliseconds(value);
                    break;
                }

                case DateTimePart.AmPmDesignator:
                {
                    result = ((DateTime)currentDateTime).AddHours(value * 12);
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
            catch
            {
                //this can occur if the date/time = 1/1/0001 12:00:00 AM which is the smallest date allowed.
                //I could write code that would validate the date each and everytime but I think that it would be more
                //efficient if I just handle the edge case and allow an exeption to occur and swallow it instead.
            }

            return(this.CoerceValueMinMax(result));
        }
        protected override GetOrderDeliveryDateTimeRangeRD ProcessRequest(
            APIRequest <GetOrderDeliveryDateTimeRangeRP> pRequest)
        {
            var rd = new GetOrderDeliveryDateTimeRangeRD();

            var deliveryid = string.IsNullOrWhiteSpace(pRequest.Parameters.DeliveryId)
                ? "2"
                : pRequest.Parameters.DeliveryId;

            //基础数据初始化
            GetPickingDateRD getPickingDateRD   = new GetPickingDateRD();
            var getOrderDeliveryDateTimeRangeRD = new GetOrderDeliveryDateTimeRangeRD();
            CustomerTakeDeliveryBLL    customerTakeDeliveryBll    = new CustomerTakeDeliveryBLL(CurrentUserInfo);
            CustomerTakeDeliveryEntity customerTakeDeliveryEntity =
                customerTakeDeliveryBll.QueryByEntity(
                    new CustomerTakeDeliveryEntity()
            {
                DeliveryId = deliveryid, CustomerId = CurrentUserInfo.ClientID
            },
                    null).FirstOrDefault();
            SysTimeQuantumBLL sysTimeQuantumBll = new SysTimeQuantumBLL(CurrentUserInfo);
            var sysTimeQuantumEntityList        =
                sysTimeQuantumBll.QueryByEntity(
                    new SysTimeQuantumEntity()
            {
                DeliveryId = deliveryid, CustomerID = CurrentUserInfo.ClientID
            },
                    new OrderBy[] { new OrderBy()
                                    {
                                        FieldName = "Quantum", Direction = OrderByDirections.Asc
                                    } });

            var beginDateTime = DateTime.MinValue;
            var endDateTime   = DateTime.MinValue;

            var now = DateTime.Now;


            List <DateTimeInfo> dateTimeInfos = new List <DateTimeInfo>();

            int?stockUpPeriod = customerTakeDeliveryEntity.StockUpPeriod == null
                ? 0
                : customerTakeDeliveryEntity.StockUpPeriod;
            int?maxDelivery = customerTakeDeliveryEntity.MaxDelivery == null
                ? 0
                : customerTakeDeliveryEntity.MaxDelivery;

            if (deliveryid == "2")
            {
                if (sysTimeQuantumEntityList.Length == 0)
                {
                    beginDateTime = now.AddHours(Convert.ToDouble(stockUpPeriod));
                }
                else
                {
                    string[] timeTemp  = sysTimeQuantumEntityList[0].Quantum.Split('-');
                    string   beginTime = now.AddHours(Convert.ToDouble(stockUpPeriod)).ToString("HH:mm");
                    //如果在备货完的结束日期没有时间段可以选择,则后一天为允许选择的开始时间
                    if (beginTime.CompareTo(timeTemp[0]) < 0)
                    {
                        beginDateTime =
                            now.AddHours(Convert.ToDouble(stockUpPeriod));
                    }
                    else
                    {
                        beginDateTime =
                            now.AddHours(Convert.ToDouble(stockUpPeriod)).AddDays(1);
                    }
                }

                int?addMaxDelivery = maxDelivery == 0 ? 0 : customerTakeDeliveryEntity.MaxDelivery - 1;
                endDateTime = beginDateTime.AddDays(Convert.ToDouble(addMaxDelivery));
            }
            else if (deliveryid == "4")
            {
                if (sysTimeQuantumEntityList.Length == 0)
                {
                    beginDateTime = now.AddDays(Convert.ToDouble(stockUpPeriod));
                }
                else
                {
                    string[] timeTemp  = sysTimeQuantumEntityList[0].Quantum.Split('-');
                    string   beginTime = now.ToString("HH:mm");
                    //如果在备货完的结束日期没有时间段可以选择,则后一天为允许选择的开始时间
                    if (beginTime.CompareTo(timeTemp[1]) > 0)
                    {
                        beginDateTime =
                            now.AddDays(Convert.ToDouble(stockUpPeriod));
                    }
                    else
                    {
                        beginDateTime =
                            now.AddDays(Convert.ToDouble(stockUpPeriod)).AddDays(1);
                    }
                }

                var deliveryServiceConfigDay = "7";//ConfigurationManager.AppSettings["DeliveryServiceConfigDay"]; //服时间为最近的7天

                endDateTime = beginDateTime
                              .AddDays(int.Parse(deliveryServiceConfigDay));
            }

            for (var i = beginDateTime; i <= endDateTime; i = i.AddDays(1))
            {
                List <string> timeRange = new List <string>();

                foreach (var entity in sysTimeQuantumEntityList)
                {
                    string[] timeTemp  = entity.Quantum.Split('-');
                    string   beginTime = string.Empty;
                    if (deliveryid == "2")
                    {
                        beginTime = now.AddHours(Convert.ToDouble(stockUpPeriod)).ToString("HH:mm");
                    }
                    else if (deliveryid == "4")
                    {
                        beginTime = now.AddDays(Convert.ToDouble(stockUpPeriod)).ToString("HH:mm");
                    }

                    if (i == beginDateTime)
                    {
                        //if (beginTime.CompareTo(timeTemp[0]) < 0)
                        //{
                        timeRange.Add(entity.Quantum);
                        //}
                    }
                    else
                    {
                        timeRange.Add(entity.Quantum);
                    }

                    //如果在备货完的结束日期没有时间段可以选择,则后一天为允许选择的开始时间
                    //if (beginTime.CompareTo(timeTemp[0]) < 0)
                    //}
                }



                var dateTimeInfo = new DateTimeInfo
                {
                    dataRange = i.ToString("yyyy-MM-dd"),
                    timeRange = timeRange.ToArray()
                };
                dateTimeInfos.Add(dateTimeInfo);
            }

            rd.DateRange = dateTimeInfos.ToArray();


            return(rd);
        }