/// <summary> /// 直接采集一条数据,并自动存入数据库,返回获取数据的记录 /// 没有记录时恢复巡检 /// </summary> /// <param name="isfirst">是否首次提取,首次会补充采集当前记录以防漏采</param> public override string GatherData(bool isfirst) { if (null == this.commimgr || null == this.target || string.IsNullOrEmpty(this.devid) || this.station < 1) { return(""); } CmdProtocol cmdP = this.cmdGather; if (null == cmdP) { cmdP = new CmdProtocol(false); } string[] cols = { "{卡号}", "{卡类}", "{消费时间}", "{消费金额}", "{卡余额}", "{累计补助金额}", "{消费机号}", "{操作员号}" }; string tag = "@设备地址=" + Convert.ToString(this.station); this.reChecking(0); if (recordpos.ContainsKey(this.devid)) { tag = basefun.setvaltag(tag, "{记录值指针}", Convert.ToString(recordpos[this.devid])); cmdP.setCommand("消费", "取指定记录", tag); } else { if (isfirst) { this.getSubsidy(); cmdP.setCommand("消费", "取当前消费记录", tag); } else { cmdP.setCommand("消费", "取下一条消费记录", tag); } } string msg = getResponse(this.commimgr, this.target, cmdP, this.waitTime); string cardnum = basefun.valtag(msg, "{卡号}"); string suc = basefun.valtag(msg, "Success"); if ("true" != suc || string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum) { this.reChecking(1); if ("false" == suc || "16777215" == cardnum || "0" == cardnum) { recordpos.Remove(this.devid); } return(msg); } string info = ""; for (int c = 0; c < cols.Length; c++) { info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c])); } NameObjectList ps = ParamManager.createParam(info); ps["消费机"] = this.devid; bool success = this.query.ExecuteNonQuery("采集数据", ps, ps, ps); if (!success) { ServiceTool.LogMessage(info, null, EventLogEntryType.Warning); } if (recordpos.ContainsKey(this.devid)) { recordpos[this.devid]++; ps.Clear(); ps["消费机"] = this.devid; ps["记录位置"] = recordpos[this.devid]; query.ExecuteNonQuery("记录指针", ps, ps, ps); } DateTime dt = DateTime.MinValue; try { dt = Convert.ToDateTime(ps["消费时间"]); } catch { } this.AddRecord(info); DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info); this.RaiseRecord(arg); return(msg); }
/// <summary> /// 设置用户信息 /// </summary> private void createUserInfo() { NameObjectList paramList = new NameObjectList(); paramList["userid"] = this.UserAccounts; if (null == this.userQuery) { this.userQuery = QueryDataRes.CreateQuerySys(); } DataTable tab = this.userQuery.getTable("人员基本信息", paramList); if (tab.Rows.Count < 1) { this._userName = "******"; } else { this._userName = (null == tab.Rows[0]["姓名"]) ? "" : tab.Rows[0]["姓名"].ToString(); this._dept = (null == tab.Rows[0]["部门"]) ? "" : tab.Rows[0]["部门"].ToString(); this._deptcode = (null == tab.Rows[0]["部门编号"]) ? "" : tab.Rows[0]["部门编号"].ToString(); this._deptid = (null == tab.Rows[0]["部门ID"]) ? "" : tab.Rows[0]["部门ID"].ToString(); this._deptsub = (null == tab.Rows[0]["分部门"]) ? "" : tab.Rows[0]["分部门"].ToString(); this._deptsubcode = (null == tab.Rows[0]["分部门编号"]) ? "" : tab.Rows[0]["分部门编号"].ToString(); this._deptsubid = (null == tab.Rows[0]["分部门ID"]) ? "" : tab.Rows[0]["分部门ID"].ToString(); this._unitName = (null == tab.Rows[0]["单位"]) ? "" : tab.Rows[0]["单位"].ToString(); this._unitcode = (null == tab.Rows[0]["单位编号"]) ? "" : tab.Rows[0]["单位编号"].ToString(); this._unitID = (null == tab.Rows[0]["单位ID"]) ? "" : tab.Rows[0]["单位ID"].ToString(); this._roleName = (null == tab.Rows[0]["角色"]) ? "" : tab.Rows[0]["角色"].ToString(); if (null == tab.Rows[0]["限制天数"] || DBNull.Value == tab.Rows[0]["限制天数"]) { this._limitDays = 0; } else { this._limitDays = Convert.ToInt16(tab.Rows[0]["限制天数"]); } if (null == tab.Rows[0]["公网访问"] || DBNull.Value == tab.Rows[0]["公网访问"]) { this._visitOut = false; } else { this._visitOut = Convert.ToBoolean(tab.Rows[0]["公网访问"]); } } string fileName = ""; if (tab.Rows.Count > 0 && null != tab.Rows[0]["分部门独立管理"] && (tab.Rows[0]["分部门独立管理"].Equals(true) || "true" == tab.Rows[0]["分部门独立管理"].ToString().ToLower())) { fileName = (null == tab.Rows[0]["分部门编号"]) ? "" : tab.Rows[0]["分部门编号"].ToString(); } else if (tab.Rows.Count > 0 && null != tab.Rows[0]["部门独立管理"] && (tab.Rows[0]["部门独立管理"].Equals(true) || "true" == tab.Rows[0]["部门独立管理"].ToString().ToLower())) { fileName = (null == tab.Rows[0]["部门编号"]) ? "" : tab.Rows[0]["部门编号"].ToString(); } else if (tab.Rows.Count > 0) { fileName = (null == tab.Rows[0]["单位编号"]) ? "" : tab.Rows[0]["单位编号"].ToString(); } this._OPTUnitID = fileName; //根据this._OPTUnitID查出权限数据 if ("" != fileName) { //打开权限数据,条件:角色,部门,所在单位(this._OPTUnitID),得出所属节点的操作集 paramList.Clear(); paramList["deptcode"] = this.DeptmentCode; paramList["role"] = this.RoleName; this.userQuery.FillDataSet("rightsql", paramList, this.dsDeptRight); } paramList.Clear(); paramList["DeptCode"] = this.DeptmentCode; paramList["OPTUnitID"] = this.UnitID; if (null == this.userQuery) { this.userQuery = QueryDataRes.CreateQuerySys(); } tab = this.userQuery.getTable("上级部门", paramList); if (null != tab && tab.Rows.Count > 0 && null != tab.Rows[0]["名称"]) { this._deptParent = tab.Rows[0]["名称"].ToString(); } tab = this.userQuery.getTable("销售部门", paramList); if (null != tab && tab.Rows.Count > 0 && null != tab.Rows[0]["名称"]) { this._deptSaleName = tab.Rows[0]["名称"].ToString(); } tab = this.userQuery.getTable("上级单位", paramList); if (null != tab && tab.Rows.Count > 0 && null != tab.Rows[0]["名称"]) { this._unitParent = tab.Rows[0]["名称"].ToString(); } }
public User(string userID, Boolean reset, ref Boolean blBad) { this._userId = userID; this._workRight = new WorkUnitRight(); NameObjectList paramList = new NameObjectList(); if (null == User.tabUser || reset == true) { if (null == this.userQuery) { this.userQuery = QueryDataRes.CreateQuerySys(); } User.tabUser = this.userQuery.getTable("用户登录基本信息结构", paramList); } DataRow drUser = null; if (User.tabUser == null) { blBad = true; return; } for (int i = User.tabUser.Rows.Count - 1; i > -1; i--) { DataRow dr = User.tabUser.Rows[i]; DateTime dStart = Convert.ToDateTime(dr["登录时间"]); DateTime dEnd = Convert.ToDateTime(dr["离线时间"]); //超时10分钟 if (dStart.Add(new TimeSpan(0, 10, 0)) < dEnd) { NameObjectList param = new NameObjectList(); param["帐号"] = dr["帐号"]; param["登录时间"] = dr["登录时间"]; param["离线时间"] = dr["离线时间"]; param["登录IP"] = dr["登录IP"]; paramList[paramList.Count.ToString()] = param; User.tabUser.Rows.Remove(dr); continue; } string userAddress = Dns.GetHostName(); if (null != HttpContext.Current && null != HttpContext.Current.Request) { userAddress = HttpContext.Current.Request.UserHostAddress; } if (this.UserAccounts == dr["帐号"].ToString() && dr["登录IP"].ToString() == userAddress) { drUser = dr; dr["离线时间"] = DateTime.Now; } } User.tabUser.AcceptChanges(); NameObjectList[] paramListArry = new NameObjectList[paramList.Count]; for (int i = 0; i < paramListArry.Length; i++) { paramListArry[i] = paramList[i] as NameObjectList; } if (paramListArry.Length > 0) { if (null == this.userQuery) { this.userQuery = QueryDataRes.CreateQuerySys(); } this.userQuery.ExecuteInsert("用户登录日志", paramListArry); } if (null == drUser) { this.createUserInfo(); drUser = User.tabUser.NewRow(); drUser["帐号"] = this.UserAccounts; drUser["登录时间"] = DateTime.Now; drUser["离线时间"] = DateTime.Now; drUser["登录IP"] = Dns.GetHostName(); if (null != HttpContext.Current && null != HttpContext.Current.Request) { drUser["登录IP"] = HttpContext.Current.Request.UserHostAddress; } drUser["姓名"] = this._userName; drUser["部门"] = this._dept; drUser["部门编号"] = this._deptcode; drUser["部门ID"] = this._deptid; drUser["销售部门"] = this._deptSaleName; drUser["分部门"] = this._deptsub; drUser["分部门编号"] = this._deptsubcode; drUser["分部门ID"] = this._deptsubid; drUser["公司"] = this._company; drUser["单位"] = this._unitName; drUser["单位编号"] = this._unitcode; drUser["单位ID"] = this._unitID; drUser["角色"] = this._roleName; drUser["权限类别"] = this._rights; drUser["限制天数"] = this._limitDays; drUser["上级单位"] = this._unitParent; drUser["上级部门"] = this._deptParent; drUser["权限文件"] = this._OPTUnitID; drUser["公网访问"] = this._visitOut; User.tabUser.Rows.Add(drUser); } else { this._userName = (null == drUser["姓名"]) ? "" : drUser["姓名"].ToString(); this._dept = (null == drUser["部门"]) ? "" : drUser["部门"].ToString(); this._deptcode = (null == drUser["部门编号"]) ? "" : drUser["部门编号"].ToString(); this._deptid = (null == drUser["部门ID"]) ? "" : drUser["部门ID"].ToString(); this._deptSaleName = (null == drUser["销售部门"]) ? "" : drUser["销售部门"].ToString(); this._deptsub = (null == drUser["分部门"]) ? "" : drUser["分部门"].ToString(); this._deptsubcode = (null == drUser["分部门编号"]) ? "" : drUser["分部门编号"].ToString(); this._deptsubid = (null == drUser["分部门ID"]) ? "" : drUser["分部门ID"].ToString(); this._company = (null == drUser["公司"]) ? "" : drUser["公司"].ToString(); this._unitName = (null == drUser["单位"]) ? "" : drUser["单位"].ToString(); this._unitcode = (null == drUser["单位编号"]) ? "" : drUser["单位编号"].ToString(); this._unitID = (null == drUser["单位ID"]) ? "" : drUser["单位ID"].ToString(); this._unitParent = (null == drUser["上级单位"]) ? "" : drUser["上级单位"].ToString(); this._deptParent = (null == drUser["上级部门"]) ? "" : drUser["上级部门"].ToString(); this._roleName = (null == drUser["角色"]) ? "" : drUser["角色"].ToString(); this._rights = (null == drUser["权限类别"]) ? "" : drUser["权限类别"].ToString(); this._OPTUnitID = (null == drUser["权限文件"]) ? "" : drUser["权限文件"].ToString(); if (null == drUser["限制天数"]) { this._limitDays = 0; } else { this._limitDays = Convert.ToInt16(drUser["限制天数"]); } if (null == drUser["公网访问"]) { this._visitOut = false; } else { this._visitOut = Convert.ToBoolean(drUser["公网访问"]); } //将加入权限文件收为加入权限数据,来自于表mnu_rights, string fileName = this._OPTUnitID; //取操作员的上级独立单位的ID做为权限文件名(+.xml) if ("" != fileName) { paramList.Clear(); paramList["deptcode"] = this._deptcode; paramList["role"] = this._roleName; } } }
/// <summary> /// 写入记录,分补助或消费分别保存 /// </summary> /// <param name="msg">tag格式信息:{卡号}、状态编号,读卡器号,{刷卡时间}</param> private string writeRecord(string msg) { string cardnum = basefun.valtag(msg, "{卡号}"); string suc = basefun.valtag(msg, "Success"); if ("true" != suc || "16777215" == cardnum || "0" == cardnum || string.IsNullOrEmpty(cardnum)) { return(msg); } string info = ""; string[] cols = { "{卡号}", "{卡类}", "{消费时间}", "{消费金额}", "{卡余额}", "{累计补助金额}", "{消费机号}", "{操作员号}" }; if ("补助机" == this.devName) { cols = new string[] { "{卡号}", "{卡类}", "{充值时间}", "{本次补助金额}", "{补助后总额}" } } ; for (int c = 0; c < cols.Length; c++) { info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c])); } NameObjectList ps = ParamManager.createParam(info); ps["消费机"] = this.devid; //msg = "@{帧头}=C0,@{设备地址}=17,@{控制场}=01,@{长度场}=25,@Success=true,@{状态}=操作成功!,@{命令长度}=23,@{消费机号}=17,@{操作员号}=255,@{卡号}=16777215,@{卡类}=255,@{消费时间}=0001/1/1 0:00:00,@{卡余额}=1677721.5,@{累计补助金额}=6553.5,@{消费金额}=6553.5,@{记录指针}=11297,@{校验字}=32,@{帧尾}=C0"; ///*************************查看时间格式是否正确 2012-06-20 string dtTime = Convert.ToString(basefun.valtag(msg, "{消费时间}")); try { DateTime s = Convert.ToDateTime(dtTime); if (dtTime.ToString() == "0001/1/1 0:00:00" || Convert.ToDateTime(dtTime) < Convert.ToDateTime("2000-01-01 00:00:00")) { ps["设备ID"] = this.devid; ps["卡号"] = cardnum; ps["日期"] = dtTime; ps["金额"] = basefun.valtag(msg, "{卡余额}"); this.query.ExecuteNonQuery("错误记录", ps, ps, ps); } } catch { ps["设备ID"] = this.devid; ps["卡号"] = cardnum; ps["日期"] = dtTime; ps["金额"] = basefun.valtag(msg, "{卡余额}"); this.query.ExecuteNonQuery("错误记录", ps, ps, ps); } ///*************************查看时间格式是否正确 2012-06-20 DateTime dt = DateTime.MinValue; string fld = "补助机" == this.devName ? "充值时间" : "消费时间"; try { dt = Convert.ToDateTime(ps[fld]); } catch { } if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3)) { if (null == dtobj) { return(msg); } try { dt = Convert.ToDateTime(dtobj); } catch { return(msg); } ps[fld] = dtobj; } else { dtobj = ps[fld]; } bool success = false; if ("补助机" == this.devName) { success = this.query.ExecuteNonQuery("消费接收补助", ps, ps, ps); } else { success = this.query.ExecuteNonQuery("采集数据", ps, ps, ps); } Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 保存:" + this.devName + " " + this.station.ToString()); myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 保存:" + this.devName + " " + this.station.ToString()); if (!success) { ServiceTool.LogMessage(info, null, EventLogEntryType.Warning); } if (recordpos.ContainsKey(this.devid)) { recordpos[this.devid]++; ps.Clear(); ps["消费机"] = this.devid; ps["记录位置"] = recordpos[this.devid]; query.ExecuteNonQuery("记录指针", ps, ps, ps); } this.AddRecord(info); DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info); this.RaiseRecord(arg); return(msg); } object dtobj = null;