/// <summary> /// 处理考勤数据 /// </summary> /// <param name="bytes"></param> private void handlerAttMsg(byte[] bytes) { try { LogMg.AddDebug("udp协议接收的考勤数据============= " + ToHexString(bytes)); int stationNo = 0; int pid = 0; int state = 0; DateTime date = DateTime.Now; parseDataAtt(bytes, ref stationNo, ref pid, ref state, ref date); //找出编号对应的站点 SWS_DB.guangdai_station_link link = V88StationLink.SingleOrDefault(c => Int32.Parse(c.wsid) == stationNo); if (link == null) { return; } SWSDataContext sws = new SWSDataContext(ConnectStringHelper.GetConnection(SysConfig.userProfile.DbAddress, link.db_name, SysConfig.userProfile.DbUserName, SysConfig.userProfile.DbPassword)); updateStationLine(sws, (int)link.station_id); users user = findUserByPid(sws, pid); if (user == null) { return; } country_attendance att = sws.country_attendance.Where(c => c.RFID == pid.ToString() && c.station_id == link.station_id && c.edate != null && DateTime.Now.AddHours(-1).CompareTo(c.edate) < 0).OrderByDescending(c => c.id).FirstOrDefault(); if (att == null) { att = new country_attendance(); if (user == null) { att.userid = 0; } else { att.userid = user.userid; } att.station_id = link.station_id; att.sdate = date; att.edate = date; att.type = "01"; att.remark = "V88设备的考勤数据"; att.RFID = pid.ToString(); sws.country_attendance.InsertOnSubmit(att); sws.SubmitChanges(); } else { att.edate = date; sws.SubmitChanges(); } } catch (Exception ex) { LogMg.AddError(ex); } }
private void handlerV88Msg(string data) { LogMg.AddDebug("udp协议接收的数据============= " + data); List <String> datas = CaiBao(data); DateTime date = DateTime.Now; List <Dictionary <string, string> > listDir = parseDataV88(datas, ref date); foreach (Dictionary <string, string> item in listDir) { try { //找出设备编号 String stationNo = getStationNo(item); if (String.IsNullOrEmpty(stationNo)) { continue; } //找出编号对应的站点 SWS_DB.guangdai_station_link link = V88StationLink.SingleOrDefault(c => c.wsid == stationNo); if (link == null) { continue; } SWSDataContext sws = new SWSDataContext(ConnectStringHelper.GetConnection(SysConfig.userProfile.DbAddress, link.db_name, SysConfig.userProfile.DbUserName, SysConfig.userProfile.DbPassword)); updateStationLine(sws, (int)link.station_id); foreach (string key in item.Keys) { //数据 KeyValuePair <string, string> data1 = item.Single(c => c.Key == key); try { KeyValuePair <string, int>?keyAndValue = getRegisterByKey(key); if (keyAndValue == null) { continue; } List <gong_kuang_config> gks = sws.gong_kuang_config.Where(c => c.station_id == link.station_id && c.read_register == ((KeyValuePair <string, int>)keyAndValue).Value.ToString()).ToList(); foreach (gong_kuang_config gk in gks) { if (gk == null || gk.testid == null || gk.testid == 0) { continue; } AutoCollectionThread.updateStationOnlineInfo(sws, (int)link.station_id); //保存数据 double multiple = gk.Multiple == null ? 1 : (double)gk.Multiple; double addNumber = gk.AddNumber == null ? 0 : (double)gk.AddNumber; String strValue = data1.Value; if (key.StartsWith("k") || key.StartsWith("K")) { if (strValue == "1") { strValue = "0"; } else { strValue = "1"; } } double value = Double.Parse(strValue) * multiple + addNumber; gk.read_value = value.ToString(); realrec rec = new realrec(); rec.testid = gk.testid; rec.value = (decimal)value; rec.testtime = date; rec.remark = "V88协议的设备数据"; sws.realrec.InsertOnSubmit(rec); } } catch (Exception ex) { LogMg.AddError(ex); } } sws.SubmitChanges(); } catch (Exception ex) { LogMg.AddError(ex); } } }