Exemple #1
0
 /// <summary>
 /// 采集记录数据
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void device_RecordHandle(object sender, DvRecordEventArgs e)
 {
     if (null == e || string.IsNullOrEmpty(e.DeviceID) || string.IsNullOrEmpty(e.TagInfo))
     {
         return;
     }
     this.sendclientdata(e.DeviceID, "record", Encoding.GetEncoding("GB2312").GetBytes(e.TagInfo));
 }
Exemple #2
0
        /// <summary>
        /// 触发记录事件
        /// </summary>
        /// <param name="arg"></param>
        public virtual void RaiseRecord(DvRecordEventArgs arg)
        {
            EventHandler <DvRecordEventArgs> handle = this.RecordHandle;

            if (null == handle || null == arg)
            {
                return;
            }
            if (string.IsNullOrEmpty(arg.DeviceID) || string.IsNullOrEmpty(arg.TagInfo))
            {
                return;
            }
            handle(this, arg);
        }
        /// <summary>
        /// 设备采集新记录时触发
        /// </summary>
        /// <param name="sender">智能设备</param>
        /// <param name="e">记录参数</param>
        void device_RecordHandle(object sender, DvRecordEventArgs arg)
        {
            EventHandler <DvRecordEventArgs> handle = this.RecordHandle;

            if (null == handle || null == arg || null == sender)
            {
                return;
            }
            if (string.IsNullOrEmpty(arg.DeviceID) || string.IsNullOrEmpty(arg.TagInfo))
            {
                return;
            }
            handle(sender, arg);
        }
Exemple #4
0
        /// <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;
Exemple #5
0
 /// <summary>
 /// ������¼�¼�
 /// </summary>
 /// <param name="arg"></param>
 public virtual void RaiseRecord(DvRecordEventArgs arg)
 {
     EventHandler<DvRecordEventArgs> handle = this.RecordHandle;
     if (null == handle || null == arg)
         return;
     if (string.IsNullOrEmpty(arg.DeviceID) || string.IsNullOrEmpty(arg.TagInfo))
         return;
     handle(this, arg);
 }
        /// <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);
            }
            NameObjectList ps = new NameObjectList();

            ps["卡号"] = cardnum;
            DataTable tabuser = null;

            try
            {
                Monitor.Enter(objquery);
                tabuser = this.qyemp.getTable("卡用户信息", ps);
            }
            finally
            {
                Monitor.PulseAll(objquery);
                Monitor.Exit(objquery);
            }
            if (null != tabuser && tabuser.Rows.Count > 0)
            {
                DataRow  dr     = tabuser.Rows[0];
                string[] strcol = { "部门ID", "部门代码", "部门", "姓名", "用户编号", "照片", "卡号", "卡号NUM", "卡片序列号", "卡片SN" };
                foreach (string c in strcol)
                {
                    msg = basefun.setvaltag(msg, "{" + c + "}", Convert.ToString(dr[c]));
                }
                if (DBNull.Value != dr["进入时间"])
                {
                    msg = basefun.setvaltag(msg, "{进入时间}", Convert.ToDateTime(dr["进入时间"]).ToString("yyyy-MM-dd HH:mm:ss"));
                }
            }
            string info = "";

            string[] cols = { "{卡号}", "{卡号NUM}", "{卡片序列号}", "{卡片SN}", "{部门}", "{部门ID}", "{部门代码}", "{姓名}", "{照片}", "{用户编号}", "状态编号", "读卡器", "{刷卡时间}", "{进入时间}" };
            for (int c = 0; c < cols.Length; c++)
            {
                info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c]));
            }
            string idx    = basefun.valtag(info, "读卡器");
            string chname = channels[0];

            if ("进出口" == devtype || "出入口" == devtype)
            {
                chname = "2" == idx || "3" == idx ? channels[1] : chname;
            }
            info = basefun.setvaltag(info, "通道", chname);
            info = basefun.setvaltag(info, "区域", region);
            info = basefun.setvaltag(info, "区域ID", regionID);
            info = basefun.setvaltag(info, "控制器类型", devtype);
            string strstate = this.getStateDoorCard(cardnum, basefun.valtag(info, "状态编号"), idx);

            msg       = basefun.setvaltag(msg, "状态", strstate);
            info      = basefun.setvaltag(info, "状态", strstate);
            ps        = ParamManager.createParam(info);
            ps["控制器"] = this.devid;
            ps["时间"]  = ps["刷卡时间"] = DateTime.MinValue;
            DateTime dt = DateTime.MinValue;

            try
            {
                string dtstr = basefun.valtag(msg, "{刷卡时间}");
                if (!string.IsNullOrEmpty(dtstr) && "0001-1-1 0:00:00" != dtstr)
                {
                    ps["时间"] = ps["刷卡时间"] = dt = Convert.ToDateTime(dtstr);
                }
            }
            catch { dt = DateTime.MinValue; }
            if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
            {
                if (null == dtobj)
                {
                    return(msg);
                }
                try { dt = Convert.ToDateTime(dtobj); }
                catch { return(msg); }
                if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
                {
                    return(msg);
                }
                ps["时间"] = ps["刷卡时间"] = dtobj;
            }
            else
            {
                dtobj = ps["时间"];
            }
            bool success = true;

            try
            {
                Monitor.Enter(objquery);
                success = qydata.ExecuteNonQuery("采集道闸数据", ps, ps, ps);
            }
            finally
            {
                Monitor.PulseAll(objquery);
                Monitor.Exit(objquery);
            }
            if (!success)
            {
                NameValueCollection attr = new NameValueCollection();
                attr["功能"] = "采集道闸数据保存失败";
                ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
            }
            this.AddRecord(info);
            DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);

            this.RaiseRecord(arg);
            return(msg);
        }
Exemple #7
0
 /// <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;
 }
Exemple #8
0
 /// <summary>
 /// Ѳ����Ӧ,����ʧ��5����(tsbusy)����Ϊͣ��,���tsbusyѲ��
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmdGather_ResponseHandle(object sender, ResponseEventArgs e)
 {
     if (null == sender || null == e)
         return;
     CmdProtocol cmdP = sender as CmdProtocol;
     if (null == cmdP || 0 == this.stateChecking)
         return;
     if (!e.Success)
     {
         //������ʱ��ʧ��ʱ������Ѳ������
         if (cmdP.TimeSendInv < this.tsbusy && DateTime.Now - cmdP.ResponseDatetime > this.tsbusy)
         {
             if (cmdP.TimeSendInv < this.tsbusy)
                 cmdP.TimeSendInv = this.tsbusy.Add(this.tsinv);
         }
         return;
     }
     string msg = cmdP.ResponseFormat;
     if ("true" != basefun.valtag(msg, "Success"))
         return;
     //���ߺ�ָ�����ʱ���ָ�Ѳ������
     if (cmdP.TimeSendInv > this.tsbusy)
         cmdP.TimeSendInv = this.tsinv;
     //�����л�û���¼�¼,��
     string valwk = basefun.valtag(msg, "������");
     int sum = Convert.ToInt32(basefun.valtag(msg, "{�ɼ���־}"));
     if ("1" == valwk || sum < 1)
         this.dtwork = DateTime.Now;
     this.validateSate(msg);
     //���¼�¼�Ҳ���æʱ�ɲɼ��¼�¼50��
     if (sum < 1 || DateTime.Now - this.dtwork < tsbusy)
         return;
     string[] cols ={ "{����}", "{����}", "{����ʱ��}", "{���ѽ��}", "{�����}", "{�ۼƲ������}", "{���ѻ���}", "{����Ա��}" };
     string tag = "@�豸��ַ=" + Convert.ToString(this.station);
     this.reChecking(0);
     TimeSpan tswait = this.waitTime;
     for (int i = 0; i < 51; i++)
     {
         if(i<1)
             cmdP.setCommand("����", "ȡ��ǰ���Ѽ�¼", tag);
         else if(i<2)
             cmdP.setCommand("����", "ȡ��һ�����Ѽ�¼", tag);
         msg = getResponse(this.commimgr, this.target, cmdP, tswait);
         if ("true" != basefun.valtag(msg, "Success"))
             break;
         string cardnum = basefun.valtag(msg, "{����}");
         if (string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum)
             continue;
         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);
         DateTime dt = Convert.ToDateTime(ps["����ʱ��"]);
         this.AddRecord(info);
         DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
         this.RaiseRecord(arg);
         if (!success)
             break;
     }
     this.reChecking(1);
 }
 /// <summary>
 /// 写入记录
 /// </summary>
 /// <param name="tagmsg">tag格式信息:{卡号}、状态编号,读卡器号,{刷卡时间}</param>
 /// <param name="isevent">是否触发事件</param>
 private string writeRecord(string tagmsg, bool isevent)
 {
     string cardnum = basefun.valtag(tagmsg, "{卡号}");
     string suc = basefun.valtag(tagmsg, "Success");
     // if ("true" != suc || "16777215" == cardnum || "0" == cardnum || string.IsNullOrEmpty(cardnum))
     if ("16777215" == cardnum || "0" == cardnum || string.IsNullOrEmpty(cardnum))
         return tagmsg;
     NameObjectList ps = new NameObjectList();
     ps["卡号"] = cardnum;
     DataTable tabuser = null;
     try
     {
         Monitor.Enter(objquery);
         tabuser = this.qyemp.getTable("卡用户信息", ps);
     }
     finally
     {
         Monitor.PulseAll(objquery);
         Monitor.Exit(objquery);
     }
     if (null != tabuser && tabuser.Rows.Count > 0)
     {
         DataRow dr = tabuser.Rows[0];
         tagmsg = basefun.setvaltag(tagmsg, "{部门ID}", Convert.ToString(dr["部门ID"]));
         tagmsg = basefun.setvaltag(tagmsg, "{部门代码}", Convert.ToString(dr["部门代码"]));
         tagmsg = basefun.setvaltag(tagmsg, "{部门}", Convert.ToString(dr["部门"]));
         tagmsg = basefun.setvaltag(tagmsg, "{姓名}", Convert.ToString(dr["姓名"]));
     }
     string info = "";
     string[] cols ={ "{卡号}", "{部门}", "{部门ID}", "{部门代码}", "{姓名}", "状态编号", "读卡器", "{刷卡时间}" };
     for (int c = 0; c < cols.Length; c++)
         info = basefun.setvaltag(info, cols[c], basefun.valtag(tagmsg, cols[c]));
     string strstate = this.getStateDoorCard(cardnum, basefun.valtag(info, "状态编号"), basefun.valtag(info, "读卡器"));
     tagmsg = basefun.setvaltag(tagmsg, "状态", strstate);
     info = basefun.setvaltag(info, "状态", strstate);
     ps = ParamManager.createParam(info);
     ps["控制器"] = this.devid;
     ps["时间"] = ps["刷卡时间"] = DateTime.MinValue;
     DateTime dt = DateTime.MinValue;
     try
     {
         string dtstr = basefun.valtag(tagmsg, "{刷卡时间}");
         if (!string.IsNullOrEmpty(dtstr) && "0001-1-1 0:00:00" != dtstr)
             ps["时间"] = ps["刷卡时间"] = dt = Convert.ToDateTime(dtstr);
     }
     catch { dt = DateTime.MinValue; }
     if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
     {
         if (null == dtobj) return tagmsg;
         try { dt = Convert.ToDateTime(dtobj); }
         catch { ServiceTool.LogMessage(info, null, EventLogEntryType.Warning); return tagmsg; }
         if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
         {
             ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
             return tagmsg;
         }
         ps["时间"] = ps["刷卡时间"] = dtobj;
     }
     else
         dtobj = ps["时间"];
     bool success = false;
     try
     {
         Monitor.Enter(objquery);
         success = qydata.ExecuteNonQuery("采集门禁数据", ps, ps, ps);
     }
     finally
     {
         Monitor.PulseAll(objquery);
         Monitor.Exit(objquery);
     }
     if (!success)
         ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
     if (isevent)
     {
         this.AddRecord(info);
         DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
         this.RaiseRecord(arg);
     }
     return tagmsg;
 }
 /// <summary>
 /// 采集记录数据
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void device_RecordHandle(object sender, DvRecordEventArgs e)
 {
     if (null == e || string.IsNullOrEmpty(e.DeviceID) || string.IsNullOrEmpty(e.TagInfo))
         return;
     this.sendclientdata(e.DeviceID, "record", Encoding.GetEncoding("GB2312").GetBytes(e.TagInfo));
 }
Exemple #11
0
        /// <summary>
        /// Ѳ����Ӧ,����ʧ��5����(tsbusy)����Ϊͣ��,���tsbusyѲ��
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdGather_ResponseHandle(object sender, ResponseEventArgs e)
        {
            if (null == sender || null == e)
                return;
            CmdProtocol cmdP = sender as CmdProtocol;
            if (null == cmdP || 0 == this.stateChecking)
                return;
            if (!e.Success)
            {
                //������ʱ��ʧ��ʱ������Ѳ������
                if (cmdP.TimeSendInv < this.tsbusy && DateTime.Now - cmdP.ResponseDatetime > this.tsbusy)
                {
                    if (cmdP.TimeSendInv < this.tsbusy)
                        cmdP.TimeSendInv = this.tsbusy.Add(this.tsinv);
                }
                return;
            }
            string msg = cmdP.ResponseFormat;
            if (string.IsNullOrEmpty(msg) || "true" != basefun.valtag(msg, "Success"))
                return;
            //���ߺ�ָ�����ʱ���ָ�Ѳ������
            if (cmdP.TimeSendInv > this.tsbusy)
                cmdP.TimeSendInv = this.tsinv;
            this.validateSate(msg);

            //2�����ڼ�¼������20��,���豸���ڷ�æ״̬,����ʱ�ɲɼ�
            string sumstr = basefun.valtag(msg, "{ˢ����¼��}");
            string dtstr = basefun.valtag(msg, "{ˢ��ʱ��}");
            if (string.IsNullOrEmpty(sumstr) || string.IsNullOrEmpty(dtstr))
                return;
            int sum = Convert.ToInt32(sumstr);
            DateTime dtcard = DateTime.MinValue;
            try { dtcard = Convert.ToDateTime(dtstr); }
            catch { }
            if ("���ڻ�" == this.devtype && this.posRecord > sum)
            {
                this.posRecord = 0;
                NameObjectList posps = new NameObjectList();
                posps["������"] = this.devid;
                this.query.ExecuteNonQuery("���ü�¼λ��", posps, posps, posps);
            }
            //�ж��Ƿ�æ״̬
            if (sum < 1 || (sum > 60 && DateTime.Now - dtcard < this.tsbusy))
                return;

            //���¼�¼�Ҳ���æʱ�ɲɼ��¼�¼50��
            string[] cols ={ "{����}", "״̬���", "������", "{ˢ��ʱ��}" };
            string tag = "@�豸��ַ=" + Convert.ToString(this.station);
            int st = this.stateChecking;
            this.reChecking(0);
            bool isreset = false;
            if (sum > 10 && DateTime.Now - dtcard > (this.tsbusy + this.tsbusy + this.tsbusy))
            {
                isreset = sum <= 50;
                sum = sum > 50 ? 51 : sum + 1;
            }
            else
            {
                isreset = sum <= 10;
                sum = sum > 10 ? 11 : sum + 1;
            }
            TimeSpan tswait = this.waitTime;
            for (int i = 0; i < sum; i++)
            {
                if ("���ڻ�" == this.devtype)
                    tag = basefun.setvaltag(tag, "{��¼����}", Convert.ToString(this.posRecord));
                cmdP.setCommand("�Ž�", "��ȡ��¼", tag);
                msg = getResponse(this.commimgr, e.Target, cmdP, tswait);
                if ("true" != basefun.valtag(msg, "Success"))
                    break;
                string cardnum = basefun.valtag(msg, "{����}");
                if (string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum)
                {
                    this.posRecord++;
                    continue;
                }
                string info = "";
                for (int c = 0; c < cols.Length; c++)
                    info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c]));
                info = basefun.setvaltag(info, "״̬", this.getStateDoorCard(basefun.valtag(info, "״̬���")));
                NameObjectList ps = ParamManager.createParam(info);
                ps["������"] = this.devid;
                ps["ʱ��"] = ps["ˢ��ʱ��"];
                bool success = this.query.ExecuteNonQuery("�ɼ��Ž�����", ps, ps, ps);
                if (!success)
                    ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
                DateTime dt = Convert.ToDateTime(ps["ˢ��ʱ��"]);
                this.AddRecord(info);
                DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
                this.RaiseRecord(arg);
                if (!success)
                    break;
                this.posRecord++;
                //���һ����ȡ��¼
                if (i == sum - 1 && isreset && this.posRecord > 10000)
                {
                    cmdP.setCommand("�Ž�", "��ռ�¼", tag);
                    cmdP.ResetState();
                    this.commimgr.SendCommand(this.target, cmdP);
                    if (cmdP.EventWh.WaitOne(this.waitTime, false))
                    {
                        string suc = basefun.valtag(cmdP.ResponseFormat, "Success");
                        if ("true" == suc)
                            this.query.ExecuteNonQuery("���ü�¼λ��", ps, ps, ps);
                    }
                }
            }
            this.reChecking(st);
        }
Exemple #12
0
        /// <summary>
        /// 巡检响应,连续失败5分钟(tsbusy)则认为停机,间隔tsbusy巡检
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdGather_ResponseHandle(object sender, ResponseEventArgs e)
        {
            if (null == sender || null == e)
            {
                return;
            }
            CmdProtocol cmdP = sender as CmdProtocol;

            if (null == cmdP || 0 == this.stateChecking)
            {
                return;
            }
            if (!e.Success)
            {
                //连续长时间失败时,增大巡检周期
                if (cmdP.TimeSendInv < this.tsbusy && DateTime.Now - cmdP.ResponseDatetime > this.tsbusy)
                {
                    if (cmdP.TimeSendInv < this.tsbusy)
                    {
                        cmdP.TimeSendInv = this.tsbusy.Add(this.tsinv);
                    }
                }
                return;
            }
            string msg = cmdP.ResponseFormat;

            if ("true" != basefun.valtag(msg, "Success"))
            {
                return;
            }
            //离线后恢复在线时,恢复巡检周期
            if (cmdP.TimeSendInv > this.tsbusy)
            {
                cmdP.TimeSendInv = this.tsinv;
            }
            //工作中或没有新记录,则
            string valwk = basefun.valtag(msg, "工作中");
            int    sum   = Convert.ToInt32(basefun.valtag(msg, "{采集标志}"));

            if ("1" == valwk || sum < 1)
            {
                this.dtwork = DateTime.Now;
            }
            this.validateSate(msg);
            //有新记录且不繁忙时可采集新记录50条
            if (sum < 1 || DateTime.Now - this.dtwork < tsbusy)
            {
                return;
            }
            string[] cols = { "{卡号}", "{卡类}", "{消费时间}", "{消费金额}", "{卡余额}", "{累计补助金额}", "{消费机号}", "{操作员号}" };
            string   tag  = "@设备地址=" + Convert.ToString(this.station);

            this.reChecking(0);
            TimeSpan tswait = this.waitTime;

            for (int i = 0; i < 51; i++)
            {
                if (i < 1)
                {
                    cmdP.setCommand("消费", "取当前消费记录", tag);
                }
                else if (i < 2)
                {
                    cmdP.setCommand("消费", "取下一条消费记录", tag);
                }
                msg = getResponse(this.commimgr, this.target, cmdP, tswait);
                if ("true" != basefun.valtag(msg, "Success"))
                {
                    break;
                }
                string cardnum = basefun.valtag(msg, "{卡号}");
                if (string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum)
                {
                    continue;
                }
                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);
                }
                DateTime dt = Convert.ToDateTime(ps["消费时间"]);
                this.AddRecord(info);
                DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
                this.RaiseRecord(arg);
                if (!success)
                {
                    break;
                }
            }
            this.reChecking(1);
        }
Exemple #13
0
        /// <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);

            if ("考勤机" == this.devtype)
            {
                tag = basefun.setvaltag(tag, "{记录索引}", Convert.ToString(this.posRecord));
            }
            this.reChecking(0);
            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)
            {
                this.posRecord++;
            }
            if ("true" != suc || string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum)
            {
                if (this.posRecord > 10000 && ("false" == suc || "16777215" == cardnum || "0" == cardnum))
                {
                    //清空记录
                    cmdP.setCommand("门禁", "清空记录", tag);
                    cmdP.ResetState();
                    this.commimgr.SendCommand(this.target, cmdP);
                    if (cmdP.EventWh.WaitOne(this.waitTime, false))
                    {
                        suc = basefun.valtag(cmdP.ResponseFormat, "Success");
                        if ("true" == suc)
                        {
                            this.posRecord = 0;
                            NameObjectList pspos = new NameObjectList();
                            pspos["控制器"] = this.devid;
                            this.query.ExecuteNonQuery("重置记录位置", pspos, pspos, pspos);
                        }
                    }
                }
                this.reChecking(1);
                return(msg);
            }
            string info = "";

            for (int c = 0; c < cols.Length; c++)
            {
                info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c]));
            }
            info = basefun.setvaltag(info, "状态", this.getStateDoorCard(basefun.valtag(info, "状态编号")));
            NameObjectList ps = ParamManager.createParam(info);

            ps["控制器"] = this.devid;
            ps["时间"]  = ps["刷卡时间"];
            DateTime dt = DateTime.MinValue;

            try
            {
                dt = Convert.ToDateTime(basefun.valtag(msg, "{刷卡时间}"));
            }
            catch { dt = DateTime.MinValue; }
            if (dt < DateTime.Today.AddYears(-5) || dt > DateTime.Today.AddYears(5))
            {
                ps["时间"] = ps["刷卡时间"] = null;
            }
            bool success = this.query.ExecuteNonQuery("采集门禁数据", ps, ps, ps);

            if (!success || dt < DateTime.Today.AddYears(-5) || dt > DateTime.Today.AddYears(5))
            {
                ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
            }
            this.AddRecord(info);
            DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);

            this.RaiseRecord(arg);
            return(msg);
        }
Exemple #14
0
        /// <summary>
        /// 巡检响应,连续失败5分钟(tsbusy)则认为停机,间隔tsbusy巡检
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdGather_ResponseHandle(object sender, ResponseEventArgs e)
        {
            if (null == sender || null == e)
            {
                return;
            }
            CmdProtocol cmdP = sender as CmdProtocol;

            if (null == cmdP || 0 == this.stateChecking)
            {
                return;
            }
            if (!e.Success)
            {
                //连续长时间失败时,增大巡检周期
                if (cmdP.TimeSendInv < this.tsbusy && DateTime.Now - cmdP.ResponseDatetime > this.tsbusy)
                {
                    if (cmdP.TimeSendInv < this.tsbusy)
                    {
                        cmdP.TimeSendInv = this.tsbusy.Add(this.tsinv);
                    }
                }
                return;
            }
            string msg = cmdP.ResponseFormat;

            if (string.IsNullOrEmpty(msg) || "true" != basefun.valtag(msg, "Success"))
            {
                return;
            }
            //离线后恢复在线时,恢复巡检周期
            if (cmdP.TimeSendInv > this.tsbusy)
            {
                cmdP.TimeSendInv = this.tsinv;
            }
            this.validateSate(msg);

            //2分钟内记录数大于20条,则设备处于繁忙状态,空闲时可采集
            string sumstr = basefun.valtag(msg, "{刷卡记录数}");
            string dtstr  = basefun.valtag(msg, "{刷卡时间}");

            if (string.IsNullOrEmpty(sumstr) || string.IsNullOrEmpty(dtstr))
            {
                return;
            }
            int      sum    = Convert.ToInt32(sumstr);
            DateTime dtcard = DateTime.MinValue;

            try { dtcard = Convert.ToDateTime(dtstr); }
            catch { }
            if ("考勤机" == this.devtype && this.posRecord > sum)
            {
                this.posRecord = 0;
                NameObjectList posps = new NameObjectList();
                posps["控制器"] = this.devid;
                this.query.ExecuteNonQuery("重置记录位置", posps, posps, posps);
            }
            //判定是否繁忙状态
            if (sum < 1 || (sum > 60 && DateTime.Now - dtcard < this.tsbusy))
            {
                return;
            }

            //有新记录且不繁忙时可采集新记录50条
            string[] cols = { "{卡号}", "状态编号", "读卡器", "{刷卡时间}" };
            string   tag  = "@设备地址=" + Convert.ToString(this.station);
            int      st   = this.stateChecking;

            this.reChecking(0);
            bool isreset = false;

            if (sum > 10 && DateTime.Now - dtcard > (this.tsbusy + this.tsbusy + this.tsbusy))
            {
                isreset = sum <= 50;
                sum     = sum > 50 ? 51 : sum + 1;
            }
            else
            {
                isreset = sum <= 10;
                sum     = sum > 10 ? 11 : sum + 1;
            }
            TimeSpan tswait = this.waitTime;

            for (int i = 0; i < sum; i++)
            {
                if ("考勤机" == this.devtype)
                {
                    tag = basefun.setvaltag(tag, "{记录索引}", Convert.ToString(this.posRecord));
                }
                cmdP.setCommand("门禁", "读取记录", tag);
                msg = getResponse(this.commimgr, e.Target, cmdP, tswait);
                if ("true" != basefun.valtag(msg, "Success"))
                {
                    break;
                }
                string cardnum = basefun.valtag(msg, "{卡号}");
                if (string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum)
                {
                    this.posRecord++;
                    continue;
                }
                string info = "";
                for (int c = 0; c < cols.Length; c++)
                {
                    info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c]));
                }
                info = basefun.setvaltag(info, "状态", this.getStateDoorCard(basefun.valtag(info, "状态编号")));
                NameObjectList ps = ParamManager.createParam(info);
                ps["控制器"] = this.devid;
                ps["时间"]  = ps["刷卡时间"];
                bool success = this.query.ExecuteNonQuery("采集门禁数据", ps, ps, ps);
                if (!success)
                {
                    ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
                }
                DateTime dt = Convert.ToDateTime(ps["刷卡时间"]);
                this.AddRecord(info);
                DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
                this.RaiseRecord(arg);
                if (!success)
                {
                    break;
                }
                this.posRecord++;
                //最后一条提取记录
                if (i == sum - 1 && isreset && this.posRecord > 10000)
                {
                    cmdP.setCommand("门禁", "清空记录", tag);
                    cmdP.ResetState();
                    this.commimgr.SendCommand(this.target, cmdP);
                    if (cmdP.EventWh.WaitOne(this.waitTime, false))
                    {
                        string suc = basefun.valtag(cmdP.ResponseFormat, "Success");
                        if ("true" == suc)
                        {
                            this.query.ExecuteNonQuery("重置记录位置", ps, ps, ps);
                        }
                    }
                }
            }
            this.reChecking(st);
        }
Exemple #15
0
        /// <summary>
        /// 写入记录
        /// </summary>
        /// <param name="tagmsg">tag格式信息:{卡号}、状态编号,读卡器号,{刷卡时间}</param>
        /// <param name="isevent">是否触发事件</param>
        private string writeRecord(string tagmsg, bool isevent)
        {
            string cardnum = basefun.valtag(tagmsg, "{卡号}");
            string suc     = basefun.valtag(tagmsg, "Success");

            // if ("true" != suc || "16777215" == cardnum || "0" == cardnum || string.IsNullOrEmpty(cardnum))
            if ("16777215" == cardnum || "0" == cardnum || string.IsNullOrEmpty(cardnum))
            {
                return(tagmsg);
            }
            NameObjectList ps = new NameObjectList();

            ps["卡号"] = cardnum;
            DataTable tabuser = null;

            try
            {
                Monitor.Enter(objquery);
                tabuser = this.qyemp.getTable("卡用户信息", ps);
            }
            finally
            {
                Monitor.PulseAll(objquery);
                Monitor.Exit(objquery);
            }
            if (null != tabuser && tabuser.Rows.Count > 0)
            {
                DataRow dr = tabuser.Rows[0];
                tagmsg = basefun.setvaltag(tagmsg, "{部门ID}", Convert.ToString(dr["部门ID"]));
                tagmsg = basefun.setvaltag(tagmsg, "{部门代码}", Convert.ToString(dr["部门代码"]));
                tagmsg = basefun.setvaltag(tagmsg, "{部门}", Convert.ToString(dr["部门"]));
                tagmsg = basefun.setvaltag(tagmsg, "{姓名}", Convert.ToString(dr["姓名"]));
            }
            string info = "";

            string[] cols = { "{卡号}", "{部门}", "{部门ID}", "{部门代码}", "{姓名}", "状态编号", "读卡器", "{刷卡时间}" };
            for (int c = 0; c < cols.Length; c++)
            {
                info = basefun.setvaltag(info, cols[c], basefun.valtag(tagmsg, cols[c]));
            }
            string strstate = this.getStateDoorCard(cardnum, basefun.valtag(info, "状态编号"), basefun.valtag(info, "读卡器"));

            tagmsg    = basefun.setvaltag(tagmsg, "状态", strstate);
            info      = basefun.setvaltag(info, "状态", strstate);
            ps        = ParamManager.createParam(info);
            ps["控制器"] = this.devid;
            ps["时间"]  = ps["刷卡时间"] = DateTime.MinValue;
            DateTime dt = DateTime.MinValue;

            try
            {
                string dtstr = basefun.valtag(tagmsg, "{刷卡时间}");
                if (!string.IsNullOrEmpty(dtstr) && "0001-1-1 0:00:00" != dtstr)
                {
                    ps["时间"] = ps["刷卡时间"] = dt = Convert.ToDateTime(dtstr);
                }
            }
            catch { dt = DateTime.MinValue; }
            if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
            {
                if (null == dtobj)
                {
                    return(tagmsg);
                }
                try { dt = Convert.ToDateTime(dtobj); }
                catch { ServiceTool.LogMessage(info, null, EventLogEntryType.Warning); return(tagmsg); }
                if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
                {
                    ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
                    return(tagmsg);
                }
                ps["时间"] = ps["刷卡时间"] = dtobj;
            }
            else
            {
                dtobj = ps["时间"];
            }
            bool success = false;

            try
            {
                Monitor.Enter(objquery);
                success = qydata.ExecuteNonQuery("采集门禁数据", ps, ps, ps);
            }
            finally
            {
                Monitor.PulseAll(objquery);
                Monitor.Exit(objquery);
            }
            if (!success)
            {
                ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
            }
            if (isevent)
            {
                this.AddRecord(info);
                DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
                this.RaiseRecord(arg);
            }
            return(tagmsg);
        }
 /// <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;
     NameObjectList ps = new NameObjectList();
     ps["卡号"] = cardnum;
     DataTable tabuser = null;
     try
     {
         Monitor.Enter(objquery);
         tabuser = this.qyemp.getTable("卡用户信息", ps);
     }
     finally
     {
         Monitor.PulseAll(objquery);
         Monitor.Exit(objquery);
     }
     if (null != tabuser && tabuser.Rows.Count > 0)
     {
         DataRow dr = tabuser.Rows[0];
         string[] strcol ={ "部门ID", "部门代码", "部门", "姓名", "用户编号", "照片", "卡号", "卡号NUM", "卡片序列号", "卡片SN" };
         foreach (string c in strcol)
             msg = basefun.setvaltag(msg, "{" + c + "}", Convert.ToString(dr[c]));
         if (DBNull.Value != dr["进入时间"])
             msg = basefun.setvaltag(msg, "{进入时间}", Convert.ToDateTime(dr["进入时间"]).ToString("yyyy-MM-dd HH:mm:ss"));
     }
     string info = "";
     string[] cols ={ "{卡号}", "{卡号NUM}", "{卡片序列号}", "{卡片SN}", "{部门}", "{部门ID}", "{部门代码}", "{姓名}", "{照片}", "{用户编号}", "状态编号", "读卡器", "{刷卡时间}", "{进入时间}" };
     for (int c = 0; c < cols.Length; c++)
         info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c]));
     string idx = basefun.valtag(info, "读卡器");
     string chname = channels[0];
     if ("进出口" == devtype || "出入口" == devtype)
         chname = "2" == idx || "3" == idx ? channels[1] : chname;
     info = basefun.setvaltag(info, "通道", chname);
     info = basefun.setvaltag(info, "区域", region);
     info = basefun.setvaltag(info, "区域ID", regionID);
     info = basefun.setvaltag(info, "控制器类型", devtype);
     string strstate = this.getStateDoorCard(cardnum, basefun.valtag(info, "状态编号"), idx);
     msg = basefun.setvaltag(msg, "状态", strstate);
     info = basefun.setvaltag(info, "状态", strstate);
     ps = ParamManager.createParam(info);
     ps["控制器"] = this.devid;
     ps["时间"] = ps["刷卡时间"] = DateTime.MinValue;
     DateTime dt = DateTime.MinValue;
     try
     {
         string dtstr = basefun.valtag(msg, "{刷卡时间}");
         if (!string.IsNullOrEmpty(dtstr) && "0001-1-1 0:00:00" != dtstr)
             ps["时间"] = ps["刷卡时间"] = dt = Convert.ToDateTime(dtstr);
     }
     catch { dt = DateTime.MinValue; }
     if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
     {
         if (null == dtobj) return msg;
         try { dt = Convert.ToDateTime(dtobj); }
         catch { return msg; }
         if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
             return msg;
         ps["时间"] = ps["刷卡时间"] = dtobj;
     }
     else
         dtobj = ps["时间"];
     bool success = true;
     try
     {
         Monitor.Enter(objquery);
         success = qydata.ExecuteNonQuery("采集道闸数据", ps, ps, ps);
     }
     finally
     {
         Monitor.PulseAll(objquery);
         Monitor.Exit(objquery);
     }
     if (!success)
     {
         NameValueCollection attr = new NameValueCollection();
         attr["功能"] = "采集道闸数据保存失败";
         ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
     }
     this.AddRecord(info);
     DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
     this.RaiseRecord(arg);
     return msg;
 }
Exemple #17
0
 /// <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);
     if ("���ڻ�" == this.devtype)
         tag = basefun.setvaltag(tag, "{��¼����}", Convert.ToString(this.posRecord));
     this.reChecking(0);
     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)
         this.posRecord++;
     if ("true" != suc ||string.IsNullOrEmpty(cardnum)|| "16777215" == cardnum || "0" == cardnum)
     {
         if (this.posRecord > 10000 && ("false" == suc || "16777215" == cardnum || "0" == cardnum))
         {
             //��ռ�¼
             cmdP.setCommand("�Ž�", "��ռ�¼", tag);
             cmdP.ResetState();
             this.commimgr.SendCommand(this.target, cmdP);
             if (cmdP.EventWh.WaitOne(this.waitTime, false))
             {
                 suc = basefun.valtag(cmdP.ResponseFormat, "Success");
                 if ("true" == suc)
                 {
                     this.posRecord = 0;
                     NameObjectList pspos = new NameObjectList();
                     pspos["������"] = this.devid;
                     this.query.ExecuteNonQuery("���ü�¼λ��", pspos, pspos, pspos);
                 }
             }
         }
         this.reChecking(1);
         return msg;
     }
     string info = "";
     for (int c = 0; c < cols.Length; c++)
         info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c]));
     info = basefun.setvaltag(info, "״̬", this.getStateDoorCard(basefun.valtag(info, "״̬���")));
     NameObjectList ps = ParamManager.createParam(info);
     ps["������"] = this.devid;
     ps["ʱ��"] = ps["ˢ��ʱ��"];
     DateTime dt = DateTime.MinValue;
     try
     {
         dt = Convert.ToDateTime(basefun.valtag(msg, "{ˢ��ʱ��}"));
     }
     catch { dt = DateTime.MinValue; }
     if (dt < DateTime.Today.AddYears(-5) || dt > DateTime.Today.AddYears(5))
         ps["ʱ��"] = ps["ˢ��ʱ��"] = null;
     bool success = this.query.ExecuteNonQuery("�ɼ��Ž�����", ps, ps, ps);
     if (!success || dt < DateTime.Today.AddYears(-5) || dt > DateTime.Today.AddYears(5))
         ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
     this.AddRecord(info);
     DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
     this.RaiseRecord(arg);
     return msg;
 }
        /// <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;
        }
 /// <summary>
 /// 设备采集新记录时触发
 /// </summary>
 /// <param name="sender">设备</param>
 /// <param name="e">数据参数</param>
 void monimgr_RecordHandle(object sender, DvRecordEventArgs e)
 {
     if (null == sender || null == e || string.IsNullOrEmpty(e.TagInfo))
         return;
     string state = basefun.valtag(e.TagInfo, "状态");
     if ("正常开门" != state)
         return;
     channelmgr.setPassChannel(e.TagInfo);
 }
Exemple #20
0
        /// <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>
 /// <param name="sender">智能设备</param>
 /// <param name="e">记录参数</param>
 void device_RecordHandle(object sender, DvRecordEventArgs arg)
 {
     EventHandler<DvRecordEventArgs> handle = this.RecordHandle;
     if (null == handle || null == arg || null == sender)
         return;
     if (string.IsNullOrEmpty(arg.DeviceID) || string.IsNullOrEmpty(arg.TagInfo))
         return;
     handle(sender, arg);
 }