/// <summary> /// 客户端返回消息解码 /// </summary> /// <param name="buff"></param> /// <returns></returns> private NetStructure.DeviceStartEnd DecodeData(byte[] buff) { NetStructure.DeviceStartEnd info = new NetStructure.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); }
public byte[] HandlerClientData(byte[] buff) { byte[] buffResp = { 1 }; DbHandler db = new DbHandler(); DateTime currentTime = DateTime.Now; NetStructure.DeviceStartEnd outInfo = this.DecodeData(buff); Machines machine = db.SelectMachine(outInfo.MachineId); Schedules schedule = db.SelectSchedule(outInfo.ScheduleNumber); UserProfile userInfo = db.SelectUser(outInfo.UserNumber); MachineStartEnd innerInfo = this.exchangeData(outInfo, machine, schedule, userInfo); //记录原始数据 if (outInfo.Status == enumDeviceWorkStatus.Start) { innerInfo.DateStart = currentTime; db.InsertMachineStartEnd(innerInfo); } else { int startId = db.GetStartEndID(new MachineStartEnd() { MachineId = outInfo.MachineId, SchueduleNumber = outInfo.ScheduleNumber, UserNumber = outInfo.UserNumber, Status = enumDeviceWorkStatus.Start }); if (startId == 0) { innerInfo.DateEnd = currentTime; db.InsertMachineStartEnd(innerInfo); } else { db.FinishStartStatus(startId); } } buffResp[0] = 0; return(buffResp); }
/// <summary> /// 内外部数据转换 /// </summary> /// <param name="info"></param> /// <param name="machine"></param> /// <returns></returns> private MachineStartEnd exchangeData(NetStructure.DeviceStartEnd outInfo, Machines machine, Schedules schedule, UserProfile userInfo) { MachineStartEnd startEndItem = new MachineStartEnd() { MachineNumber = machine.Number, MachineId = machine.ID, MachineName = machine.Name, RoomId = machine.RoomID, RoomNumber = machine.RoomName }; startEndItem.OrderId = schedule.OrderId; startEndItem.OrderNumber = schedule.OrderNumber; startEndItem.ScheduleId = schedule.ID; startEndItem.SchueduleNumber = schedule.Number; startEndItem.UserId = userInfo == null ? 0 : userInfo.UserId; startEndItem.UserNumber = userInfo == null ? "" : userInfo.UserName; startEndItem.Status = outInfo.Status; return(startEndItem); }