Beispiel #1
0
        /// <summary>
        /// 客户端返回消息解码
        /// </summary>
        /// <param name="buff"></param>
        /// <returns></returns>
        private DeviceStartEnd DecodeData(byte[] buff)
        {
            DeviceStartEnd info = new DeviceStartEnd();

            byte[] tempData = buff;
            //机器码
            int locIdx = 2;

            info.MachineId = ConvertHelper.BytesToInt16(tempData, 0, true);
            //启停标志
            info.Status = (enumDeviceWorkStatus)tempData[locIdx++];
            //施工单编码
            int tempLen = tempData[locIdx++];

            byte[] scheduleByte = new byte[tempLen];
            Array.Copy(tempData, locIdx, scheduleByte, 0, tempLen);
            info.ScheduleNumber = Encoding.ASCII.GetString(scheduleByte);
            locIdx += tempLen;
            //员工工号
            tempLen = tempData[locIdx++];
            byte[] userByte = new byte[tempLen];
            Array.Copy(tempData, locIdx, userByte, 0, tempLen);
            info.UserNumber = Encoding.ASCII.GetString(userByte);
            locIdx         += tempLen;

            return(info);
        }
Beispiel #2
0
        public byte[] HandlerClientData(byte[] buff)
        {
            byte[]           buffResp = { 1 };
            DbTableDbContext db       = new DbTableDbContext();

            try
            {
                DateTime        currentTime = DateTime.Now;
                DeviceStartEnd  outInfo     = this.DecodeData(buff);
                Machines        machine     = db.Machines.Find(outInfo.MachineId);
                Schedules       schedule    = db.Schedules.FirstOrDefault(item => item.Number == outInfo.ScheduleNumber);
                UserProfile     userInfo    = new UsersContext().UserProfiles.FirstOrDefault(item => item.UserName == outInfo.UserNumber);
                MachineStartEnd innerInfo   = this.exchangeData(outInfo, machine, schedule, userInfo);
                //记录原始数据

                if (outInfo.Status == enumDeviceWorkStatus.Start)
                {
                    innerInfo.DateStart = currentTime;
                    db.MachineStartEnd.Add(innerInfo);
                }
                else
                {
                    MachineStartEnd lastRecord = db.MachineStartEnd.FirstOrDefault(item => item.MachineId == outInfo.MachineId &&
                                                                                   item.SchueduleNumber == outInfo.ScheduleNumber &&
                                                                                   item.UserNumber == outInfo.UserNumber &&
                                                                                   item.Status == enumDeviceWorkStatus.Start);
                    if (lastRecord == null)
                    {
                        innerInfo.DateEnd = currentTime;
                        db.MachineStartEnd.Add(innerInfo);
                    }
                    else
                    {
                        db.MachineStartEnd.Attach(lastRecord);
                        lastRecord.DateEnd = currentTime;
                        lastRecord.Status  = enumDeviceWorkStatus.End;
                    }
                }

                db.SaveChanges();
                buffResp[0] = 0;
            }
            catch
            {
            }
            return(buffResp);
        }
Beispiel #3
0
 /// <summary>
 /// 内外部数据转换
 /// </summary>
 /// <param name="info"></param>
 /// <param name="machine"></param>
 /// <returns></returns>
 private Models.MachineStartEnd exchangeData(DeviceStartEnd outInfo, Machines machine, Schedules schedule, UserProfile userInfo)
 {
     return(new Models.MachineStartEnd()
     {
         MachineNumber = machine.Number,
         MachineId = machine.ID,
         RoomId = machine.RoomID,
         RoomNumber = machine.RoomName,
         OrderId = schedule.OrderId,
         OrderNumber = schedule.OrderNumber,
         ScheduleId = schedule.ID,
         SchueduleNumber = schedule.Number,
         UserId = userInfo == null ? 0 : userInfo.UserId,
         UserNumber = userInfo == null ? "" : userInfo.UserName,
         Status = outInfo.Status
     });
 }