Ejemplo n.º 1
0
        public XmlNode ToXMLNode(XmlDocument owner)
        {
            var node          = owner.CreateElement("BarSettings");
            var startTimeAttr = node.Attributes.Append(owner.CreateAttribute("startMinute"));

            startTimeAttr.Value = StartMinute.ToString();

            var intervalsStr = new StringBuilder();
            var first        = true;

            foreach (var inter in intervals)
            {
                if (!first)
                {
                    intervalsStr.Append(" ");
                }
                first = false;
                intervalsStr.Append(inter);
            }
            var intervalsAttr = node.Attributes.Append(owner.CreateAttribute("intervals"));

            intervalsAttr.Value = intervalsStr.ToString();

            return(node);
        }
Ejemplo n.º 2
0
        public byte[] ToPayload(byte scheduleId, byte?scheduleIdBlock = null)
        {
            int numBytes = 12 + Commands.Sum(cmd => cmd.Command.Length + 1);

            var bytes = new byte[numBytes];

            byte durationType, durationByte1, durationByte2;

            if (Duration.HasValue)
            {
                var    duration = Duration.Value;
                ushort durationNumber;
                if (Duration >= TimeSpan.FromHours(60000))
                {
                    durationType   = DurationTypeDays;
                    durationNumber = (ushort)Math.Min(duration.Days, ushort.MaxValue);
                }
                else if (Duration >= TimeSpan.FromMinutes(60000))
                {
                    durationType   = DurationTypeHours;
                    durationNumber = (ushort)(duration.Days * 24 + duration.Hours);
                }
                else
                {
                    durationType   = DurationTypeMinutes;
                    durationNumber = (ushort)((duration.Days * 24 + duration.Hours) * 60 + duration.Minutes);
                }
                durationByte1 = (byte)(durationNumber / 256);
                durationByte2 = (byte)(durationNumber % 256);
            }
            else
            {
                durationType  = DurationTypeOverride;
                durationByte1 = 0;
                durationByte2 = (byte)OverrideType;
            }

            bytes[0]  = scheduleId;
            bytes[1]  = scheduleIdBlock.GetValueOrDefault(1);
            bytes[2]  = (byte)(StartYear.HasValue ? StartYear - YearOffset : StartYearNotSpecified);
            bytes[3]  = (byte)((int)State << 4 | StartMonth.GetValueOrDefault(StartMonthNotSpecified));
            bytes[4]  = (byte)StartDayOfMonth.GetValueOrDefault(StartDayOfMonthNotSpecified);
            bytes[5]  = (byte)(durationType << 5 | (int)StartWeekdays);
            bytes[6]  = (byte)StartHour.GetValueOrDefault(StartHourNotSpecified);
            bytes[7]  = (byte)StartMinute.GetValueOrDefault(StartMinuteNotSpecified);
            bytes[8]  = durationByte1;
            bytes[9]  = durationByte2;
            bytes[10] = 0; // reports to follow
            bytes[11] = (byte)Commands.Length;

            int index = 12;

            foreach (var cmd in Commands)
            {
                bytes[index] = (byte)cmd.Command.Length;
                index++;
                Array.Copy(cmd.Command, 0, bytes, index, cmd.Command.Length);
                index += cmd.Command.Length;
            }

            return(bytes);
        }
Ejemplo n.º 3
0
        private void Save()
        {
            string message = "";

            try
            {
                var validator = NinjectBinder.GetValidator <TimeSegmentViewModelValidator>();
                var results   = validator.Validate(this);
                if (!results.IsValid)
                {
                    message = string.Join("\n", results.Errors);
                    SendMessage(message);
                    return;
                }

                var beginDateTime = new DateTime(2000, 1, 1, StartHour.ToInt32(), StartMinute.ToInt32(), 0);
                var endDateTime   = new DateTime(2000, 1, 1, EndHour.ToInt32(), EndMinute.ToInt32(), 0);
                if (endDateTime.Ticks - beginDateTime.Ticks < 0)
                {
                    message = "开始时间不能大于结束时间";
                    SendMessage(message);
                    return;
                }

                BeginTime = beginDateTime.ToString("HH:mm");
                EndTime   = endDateTime.ToString("HH:mm");
                Status    = GeneralStatus.Enabled;

                var coreModel = Mapper.Map <TimeSegment>(this);

                if (TimeSegmentID == 0)
                {
                    coreModel.CreateUserID = ApplicationManager.GetInstance().CurrentOperatorInfo.OperatorID;
                    coreModel.CreateDate   = DateTime.Now;
                    coreModel = _timeSegmentRepo.Insert(coreModel);
                    message   = "增加时间段成功!";
                }
                else
                {
                    coreModel.UpdateUserID = ApplicationManager.GetInstance().CurrentOperatorInfo.OperatorID;
                    coreModel.UpdateDate   = DateTime.Now;
                    _timeSegmentRepo.Update(coreModel);
                    message = "修改时间段成功!";
                }

                ViewModelAttachment.CoreModel            = coreModel;
                ViewModelAttachment.LastOperationSuccess = true;
            }
            catch (BusinessException ex)
            {
                Log.Error("Update timesegment fails.", ex);
                SendMessage(ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Log.Error("Update timesegment fails.", ex);
                message = "保存时间段失败";
                SendMessage(message);
                return;
            }

            RaisePropertyChanged(null);
            Close(message);
        }