/// <summary> /// 每间隔3个小时重置记录一次 /// </summary> public void ResetRecord() { NameObjectList ps = new NameObjectList(); DataTable t = query.getTable("工作区人员数汇总", ps); if (null != t) { tabRegionSum = t; } DataTable tab = query.getTable("卡号通道状态", ps); if (null == tab || tab.Rows.Count < 1) { return; } List <ChannelWorker> list = new List <ChannelWorker>(); string[] cols = { "部门", "部门ID", "部门代码", "姓名", "用户编号", "卡号", "门名称", "区域", "区域ID", "卡号NUM", "卡片序列号", "卡片SN" }; foreach (DataRow dr in tab.Rows) { string[] info = new string[12]; for (int i = 0; i < cols.Length; i++) { if (tab.Columns.Contains(cols[i])) { info[i] = Convert.ToString(dr[cols[i]]); } } ChannelWorker wk = new ChannelWorker(info[0], info[1], info[2], info[3], "", info[4], info[5], info[6], info[7], info[8], "", "", ""); wk.DtIn = DBNull.Value == dr["进入时间"] ? DateTime.MinValue : Convert.ToDateTime(dr["进入时间"]); wk.DtRein = DBNull.Value == dr["重进时间"] ? DateTime.MinValue : Convert.ToDateTime(dr["重进时间"]); wk.DtOut = DBNull.Value == dr["出离时间"] ? DateTime.MinValue : Convert.ToDateTime(dr["出离时间"]); wk.DtReout = DBNull.Value == dr["重出时间"] ? DateTime.MinValue : Convert.ToDateTime(dr["重出时间"]); wk.Memo = Convert.ToString(dr["刷卡状态"]); wk.CardNUM = info[9]; wk.CardID = info[10]; wk.CardSN = info[11]; list.Add(wk); } Monitor.Enter(listwk); listwk.Clear(); foreach (ChannelWorker wk in list) { listwk.Add(wk); } Monitor.PulseAll(listwk); Monitor.Exit(listwk); }
/// <summary> /// 搜索停车场验票机 /// </summary> private void searchPark() { QueryDataRes query = new QueryDataRes("cardone"); NameObjectList ps = new NameObjectList(); DataTable tab = query.getTable("devlist", ps); if (null == tab || tab.Rows.Count < 1) { return; } for (int i = 0; i < tab.Rows.Count; i++) { DataRow dr = tab.Rows[i]; string commitype = Convert.ToString(dr["访问方式"]); if ("1" == commitype) { commitype = "Ser"; } if ("2" == commitype) { commitype = "TCP"; } if ("Ser" != commitype && "TCP" != commitype) { commitype = "UDP"; } string port = Convert.ToString(dr["端口"]); if ("Ser" == commitype) { port = "COM" + port; } //表格字段顺序:序号, 设备类型, 设备名称, IP地址, 端口, 通讯类别, 通讯站址, 子网掩码, 默认网关, 物理地址 string[] ipAddrs = new string[10]; ipAddrs[0] = i.ToString(); ipAddrs[1] = "停车场验票机"; ipAddrs[2] = Convert.ToString(dr["名称"]); ipAddrs[3] = Convert.ToString(dr["地址"]); ipAddrs[4] = port; ipAddrs[5] = commitype; ipAddrs[6] = Convert.ToString(dr["设备地址"]); ipAddrs[7] = ""; ipAddrs[8] = ""; ipAddrs[9] = ""; DataGridViewRow drPark = this.getRow(ipAddrs[3], port, ipAddrs[6]); if (null != drPark) { drPark.SetValues(ipAddrs); } else { this.gdGrid.Rows.Add(ipAddrs); } } }
/// <summary> /// 定时执行业务 /// </summary> /// <param name="obj"></param> void executeTimer(object obj) { DateTime dt = DateTime.Today.AddDays(-1); NameObjectList ps = new NameObjectList(); ps.Add("开始日期", dt); ps.Add("结束日期", dt); QueryDataRes query = new QueryDataRes("基础类"); DataTable tab = query.getTable("考勤人员列表", null); if (null == tab || tab.Rows.Count < 1) { isTmRunning = false; return; } NameValueCollection data = new NameValueCollection(); data["服务"] = "考勤作业"; DataColumnCollection cols = tab.Columns; foreach (DataRow dr in tab.Rows) { foreach (DataColumn c in cols) { ps[c.ColumnName] = Convert.ToString(dr[c]); } try { bool b = query.ExecuteNonQuery("考勤人员列表", ps, ps, ps); if (b) { continue; } } catch (Exception ex) { foreach (string key in ps.AllKeys) { data.Add(key, Convert.ToString(ps[key])); } LogMessage(ex, data, EventLogEntryType.Error); continue; } foreach (string key in ps.AllKeys) { data.Add(key, Convert.ToString(ps[key])); } LogMessage("考勤作业失败!", data, EventLogEntryType.Warning); } isTmRunning = false; }
/// <summary> /// 重置设备记录位置,自 /// </summary> /// <param name="devid">设备ID,为空则清空所有设备记录位置,有则重置为1,没有则添加</param> public static void ResetPosition(string devid) { bool isreset = false; if ("true" == devid) { isreset = true; } if ("true" == devid || "false" == devid) { devid = ""; } if (recordpos.ContainsKey(devid)) { return; } QueryDataRes query = null; if (isreset || !string.IsNullOrEmpty(devid)) { query = new QueryDataRes(unitItem.DataSrcFile); } NameObjectList ps = new NameObjectList(); if (isreset) { query.ExecuteNonQuery("记录指针", ps, ps, ps); } if (string.IsNullOrEmpty(devid)) { recordpos.Clear(); return; } ps["消费机"] = devid; DataTable tab = query.getTable("记录指针", ps); if (null == tab || tab.Rows.Count < 1) { return; } if (DBNull.Value == tab.Rows[0]["记录位置"] || null == tab.Rows[0]["记录位置"]) { tab.Rows[0]["记录位置"] = 1; } recordpos.Add(devid, Convert.ToInt32(tab.Rows[0]["记录位置"])); }
/// <summary> /// 设置设备指令,使用dvID做指令ID /// </summary> /// <param name="tpl">协议类型</param> /// <param name="cmd">指令</param> /// <param name="tagdata">数据参数,使用tag标记格式</param> public bool setCommand(string tpl, string cmd, string tagdata) { if (CmdState.Response == this.CheckState()) { return(false); } Estar.Common.Tools.NameObjectList ps = new Estar.Common.Tools.NameObjectList(); ps["tpl"] = tpl; ps["cmd"] = cmd; DataTable tab = query.getTable(dbItem, ps); if (null == tab || tab.Rows.Count < 1) { return(false); } //设备参数 string pmdevice = ""; //输入格式参数 string pminput = ""; //输出格式参数 string pmout = ""; //从数据库中取出的参数转换成tag格式参数 DataColumnCollection dbcols = tab.Columns; if (!dbcols.Contains("type") || !dbcols.Contains("pms")) { return(false); } foreach (DataRow dr in tab.Rows) { if (DBNull.Value == dr["type"]) { continue; } string pmtype = Convert.ToString(dr["type"]); switch (pmtype) { case "协议": pmdevice = Convert.ToString(dr["pms"]); break; case "Input": pminput += Convert.ToString(dr["pms"]) + ";"; break; case "Output": pmout += Convert.ToString(dr["pms"]) + ";"; break; } } if (pmdevice.EndsWith(";")) { pmdevice = pmdevice.Substring(0, pmdevice.Length - 1); } if (pminput.EndsWith(";")) { pminput = pminput.Substring(0, pminput.Length - 1); } if (pmout.EndsWith(";")) { pmout = pmout.Substring(0, pmout.Length - 1); } pmdevice = pmdevice.Replace(";;", ";"); this.inputParam = pminput = pminput.Replace(";;", ";"); this.outterParam = pmout = pmout.Replace(";;", ";"); // begin 临时补充,在将来完善协议解析后去掉 pmdevice = basefun.setvaltag(pmdevice, "devid", basefun.valtag(tagdata, "设备地址")); // end string cmdstr = comparse.CommandString(pmdevice, pminput, tagdata, ref dvParam); IsAscii = dvParam.IsAsc; Exchanges = dvParam.Exchanges; //转义成字节,使用""""代替原来帧头帧尾的处理 if (dvParam.IsAsc) { if (cmdstr.StartsWith("02") && cmdstr.EndsWith("03")) { cmdstr = "" + cmdstr.Substring(2, cmdstr.Length - 4) + ""; } return(this.setCommand(cmdstr)); } return(this.setCommand(cmdstr, true)); }