Beispiel #1
0
        /// <summary>
        /// �����豸�ĺڰ�������,ִ�гɹ�����ºڰ�������������
        /// </summary>
        /// <param name="arg">����ָ�����</param>
        private bool downPayRule(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            CmdProtocol cmdP = new CmdProtocol(false);
            NameObjectList ps = new NameObjectList();
            ps["�豸ID"] = devID;
            bool success = false;

            string tpl = "ͣ����";
            DataTable tabpay = this.query.getTable("�շѱ�׼�б�", ps);
            string[,] dbpay ={ { "���ѷ�ʽ1", "�շѱ�׼1", "1", "�����շѱ�׼1" }, { "���ѷ�ʽ2", "�շѱ�׼2", "2", "�����շѱ�׼2" }, { "���ѷ�ʽ3", "�շѱ�׼3", "3", "�����շѱ�׼3" },
                               { "���ѷ�ʽ4", "�շѱ�׼4", "4", "�����շѱ�׼4" }, { "���ѷ�ʽ5", "�շѱ�׼5", "5", "�����շѱ�׼5" }, { "���ѷ�ʽ6", "�շѱ�׼6", "6", "�����շѱ�׼6" } };
            int ct = 0;
            if (null != tabpay && tabpay.Rows.Count > 0)
                ct = tabpay.Rows.Count;
            for (int j = 0; j < ct; j++)
            {
                DataRow drpay = tabpay.Rows[j];
                string ncar = tabpay.Rows[j]["����"].ToString();
                ps["����"] = ncar;
                string ntype = Convert.ToString(drpay["�Ʒѷ�ʽ"]);
                int k = -1;
                for (int m = 0; m < dbpay.GetLength(0); m++)
                    if (ntype == dbpay[m, 0])
                    {
                        k = m; break;
                    }
                if (k < 0) continue;
                //ָ����������ִ��
                if (!string.IsNullOrEmpty(attrcmd) && attrcmd.IndexOf("|" + dbpay[k, 3] + "|") < 0)
                    continue;
                DataTable tabitem = this.query.getTable(dbpay[k, 1], ps);
                if (null == tabitem || tabitem.Rows.Count < 1)
                    continue;
                string tag = "";
                switch (k)
                {
                    case 0: tag = getpaypm1(drpay, tabitem); break;
                    case 1: tag = getpaypm2(drpay, tabitem); break;
                    case 2: tag = getpaypm3(drpay, tabitem); break;
                    case 3: tag = getpaypm4(drpay, tabitem); break;
                    case 4: tag = getpaypm5(drpay, tabitem); break;
                    case 5: tag = getpaypm6(drpay, tabitem); break;
                }
                if (string.IsNullOrEmpty(tag))
                    continue;
                tag = basefun.setvaltag(tag, "�豸��ַ", addrst);
                tag = basefun.setvaltag(tag, "{���ʹ���}", ncar);
                tag = basefun.setvaltag(tag, "{��ʽ����}", dbpay[k, 2]);
                //ͨѶ�����շѲ���
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, dbpay[k, 3], tag);
                if (!success) return false;
            }
            return true;
        }
        /// <summary>
        /// 下载控制参数
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private bool downchannelctrlpm(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            this.setTimeout(cmdP);
            NameObjectList ps = new NameObjectList();
            ps["设备ID"] = devID;
            Monitor.Enter(query);
            DataTable tabpm = this.query.getTable("道闸控制参数", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            if (null == tabpm || tabpm.Rows.Count < 1)
                return true;
            bool success = false;
            string tpl = "门禁";
            string tag = "@设备地址=" + addrst;
            //设置门参数
            string[,] colmapdoor ={ { "{控制方式}", "控制方式" }, { "{延时}", "开门延时" }, { "{门号}", "门号" } };
            foreach (DataRow dr in tabpm.Rows)
            {
                tag = "@设备地址=" + addrst;
                string mode = Convert.ToString(dr["控制方式"]);
                switch (mode)
                {
                    case "常开": mode = "1"; break;
                    case "常闭": mode = "1"; break;
                    default: mode = "3"; break;
                }
                tag = basefun.setvaltag(tag, "{控制方式}", mode);
                tag = basefun.setvaltag(tag, "{延时}", Convert.ToString(dr["开门延时"]));
                tag = basefun.setvaltag(tag, "{门号}", Convert.ToString(Convert.ToInt16(dr["门号"]) + 1));
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "设置控制参数", tag);
                if (!success) return false;
            }
            //设置报警参数
            string[,] colmapalarm ={ { "{报警状态}.{火警}", "火警告警" }, { "{报警状态}.{无效刷卡}", "非法刷卡告警" },
                        { "{报警状态}.{联动报警}", "联动告警" }, { "{报警状态}.{非法闯入}", "非法开门告警" },
                        { "{报警状态}.{超时}", "超时开门告警" }, { "{报警状态}.{胁迫}", "胁迫报警" },
                        {"{开门超时时间}","开门超时"}, {"{联动输出时间}","报警联动延时"} };
            DataRow drpm = tabpm.Rows[0];
            tag = "@设备地址=" + addrst;
            for (int c = 0; c < colmapalarm.GetLength(0); c++)
            {
                string val = Convert.ToString(drpm[colmapalarm[c, 1]]);
                if (true.Equals(drpm[colmapalarm[c, 1]]))
                    val = "1";
                else if (false.Equals(drpm[colmapalarm[c, 1]]))
                    val = "0";
                tag = basefun.setvaltag(tag, colmapalarm[c, 0], val);
            }
            success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "设置报警", tag);
            if (!success) return false;
            //设置事件日志;三个记录指令
            string[,] colmaplog ={ { "记录开门按钮", "2D" }, { "记录告警事件", "2E" }, { "记录门磁事件", "DC" } };
            for (int m = 0; m < colmaplog.GetLength(0); m++)
            {
                tag = "@设备地址=" + addrst;
                tag = basefun.setvaltag(tag, "{功能码}", colmaplog[m, 1]);
                tag = basefun.setvaltag(tag, "{开启}", "0");
                if (true.Equals(drpm[colmaplog[m, 0]]))
                    tag = basefun.setvaltag(tag, "{开启}", "1");
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "设置事件日志", tag);
                if (!success) return false;
            }
            //设置反潜;反潜指令需要有确认指令
            tag = "@设备地址=" + addrst;
            string unhide = Convert.ToString(drpm["反潜类别"]);
            string unhideOK = "00";
            switch (unhide)
            {
                case "禁用反潜": unhide = "0"; unhideOK = "0A"; break;
                case "单独反潜": unhide = "1"; unhideOK = "FA"; break;
                case "关联反潜": unhide = "2"; unhideOK = "FA"; break;
                case "一进两出": unhide = "3"; unhideOK = "7E"; break;
                case "一进多出": unhide = "4"; unhideOK = "FE"; break;
                default: unhide = "0"; unhideOK = "00"; break;
            }
            tag = basefun.setvaltag(tag, "{反潜号}", unhide);
            success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "设置反潜", tag);
            if (!success) return false;
            tag = basefun.setvaltag(tag, "{反潜号}", unhideOK);
            success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "设置反潜确定", tag);
            if (!success) return false;
            //设置互锁;互锁需发多个指令配合
            tag = "@设备地址=" + addrst;
            string[] cmds = new string[] { "001E", "001F", "0020", "0021" };
            string locklink = Convert.ToString(drpm["互锁类别"]);
            switch (locklink)
            {
                case "禁用互锁": locklink = "00"; break;
                case "关联互锁": locklink = "01"; break;
                case "多门互锁":
                    locklink = "71";
                    cmds = new string[] { "001E", "001F", "0020" };
                    break;
                case "全部互锁": locklink = "F1"; break;
                default: locklink = "00"; break;
            }
            tag = basefun.setvaltag(tag, "{开启}", locklink);
            for (int i = 0; i < cmds.Length; i++)
            {
                tag = basefun.setvaltag(tag, "{功能码}", cmds[i]);
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "设置互锁", tag);
                if (!success) return false;
            }
            //设置扩展板参数
            Monitor.Enter(query);
            DataTable tabext = this.query.getTable("道闸扩展板参数", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            if (null == tabext || tabext.Rows.Count < 1)
                return true;
            //四组扩展板指令;每组扩展板分别发四个指令
            string[,] codefun ={
                                 { "98", "9A", "9B", "9C", "9D" }, { "9E", "A0", "A1", "A2", "A3" },
                                 { "A4", "A6", "A7", "A8", "A9" }, { "AA", "AC", "AD", "AE", "AF" }  };
            colmapdoor = new string[,]{ { "{门位}.{门1}", "一号门" }, { "{门位}.{门2}", "二号门" }, 
                                 { "{门位}.{门3}", "三号门" }, { "{门位}.{门4}", "四号门" } };
            colmapalarm = new string[,]{ { "{报警状态}.{火警}", "火警告警" }, { "{报警状态}.{无效刷卡}", "非法刷卡告警" },
                        { "{报警状态}.{联动报警}", "联动告警" }, { "{报警状态}.{非法闯入}", "非法开门报警" },
                        { "{报警状态}.{超时}", "超时开门告警" }, { "{报警状态}.{胁迫}", "胁迫报警" } };
            string strtime = Convert.ToString(drpm["报警联动延时"]);
            if (string.IsNullOrEmpty(strtime))
                strtime = "0";
            long latetime = Convert.ToInt64(strtime);
            string latestr = Convert.ToString(latetime, 16).PadLeft(4, '0');
            latestr = latestr.Substring(latestr.Length - 4);
            foreach (DataRow drext in tabext.Rows)
            {
                string strbh = Convert.ToString(drext["编号"]);
                if (string.IsNullOrEmpty(strbh))
                    continue;
                int index = Convert.ToInt32(strbh) - 1;
                if (index < 0 || index > 3)
                    continue;
                //设置事件源
                tag = "@设备地址=" + addrst;
                tag = basefun.setvaltag(tag, "{功能码}", codefun[index, 0]);
                for (int i = 0; i < colmapdoor.GetLength(0); i++)
                    tag = basefun.setvaltag(tag, colmapdoor[i, 0], true.Equals(drext[colmapdoor[i, 1]]) ? "1" : "0");
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "扩展板事件源", tag);
                if (!success) return false;
                //设置报警
                tag = "@设备地址=" + addrst;
                tag = basefun.setvaltag(tag, "{功能码}", codefun[index, 1]);
                for (int i = 0; i < colmapalarm.GetLength(0); i++)
                    tag = basefun.setvaltag(tag, colmapalarm[i, 0], true.Equals(drext[colmapalarm[i, 1]]) ? "1" : "0");
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "扩展板报警参数", tag);
                if (!success) return false;
                //设置延时低位
                tag = "@设备地址=" + addrst;
                tag = basefun.setvaltag(tag, "{功能码}", codefun[index, 3]);
                tag = basefun.setvaltag(tag, "{延时}", Convert.ToString(Convert.ToInt32(latestr.Substring(2), 16)));
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "扩展板延时低位", tag);
                if (!success) return false;
                //设置延时高位
                tag = "@设备地址=" + addrst;
                tag = basefun.setvaltag(tag, "{功能码}", codefun[index, 4]);
                tag = basefun.setvaltag(tag, "{延时}", Convert.ToString(Convert.ToInt32(latestr.Substring(0, 2))));
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "扩展板延时高位", tag);
                if (!success) return false;
            }
            return true;
        }
Beispiel #3
0
        /// <summary>
        /// ����ʱ��
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private bool downeaterytime(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            NameObjectList ps = new NameObjectList();
            ps["�豸ID"] = devID;
            //ͬ��ͨѶ�ȴ�ʱ��15��
            bool success = false;

            DataTable tab = this.query.getTable("����ʱ������", ps);
            string tpl = "����", cmd = "����ʱ������";
            string[,] colmap ={ { "{ʱ�������}", "���" }, { "{��ʼʱ��}", "��ʼ" }, { "{����ʱ��}", "����" },
                                { "{�����޶�}", "ʱ���޶�" }, { "{�����޴�}", "ʱ���޴�" } };
            string tagdata = "@�豸��ַ=" + addrst;
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow drtime = tab.Rows[i];
                for (int c = 0; c < colmap.GetLength(0); c++)
                {
                    string val = "0";
                    if (DBNull.Value != drtime[colmap[c, 1]])
                        val = Convert.ToString(drtime[colmap[c, 1]]);
                    tagdata = basefun.setvaltag(tagdata, colmap[c, 0], val);
                }
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                if (!success) return false;
            }
            cmd = "����ʱ��";
            colmap = new string[,]{ { "{����}", "�������" },
                                { "{ʱ��1}", "����" }, { "{ʱ��2}", "���" }, { "{ʱ��3}", "���" }, { "{ʱ��4}", "�����" },
                                { "{ʱ��5}", "���" }, { "{ʱ��6}", "ҹ��" },{ "{ʱ��7}", "�Ӳ�1" }, { "{ʱ��8}", "�Ӳ�2" },
                                { "{�����޶�}", "ÿ���޶�" }, { "{��������}", "ÿ���޴�" } };
            tagdata = "@�豸��ַ=" + addrst;
            tab = this.query.getTable("������ʱ��", ps);
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow drtime = tab.Rows[i];
                for (int c = 0; c < colmap.GetLength(0); c++)
                {
                    string val = "0";
                    if (DBNull.Value != drtime[colmap[c, 1]])
                        val = Convert.ToString(drtime[colmap[c, 1]]);
                    tagdata = basefun.setvaltag(tagdata, colmap[c, 0], val);
                }
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                if (!success) return false;
            }
            return true;
        }
 /// <summary>
 /// 传递通讯指令
 ///     包含参数: len,dir=request/response,cmd=TransFile.trans,source,target,
 ///               CommiType,addr=ipaddr/COM1,port,baudRate,parity,dataBits,stopBits
 /// </summary>
 /// <param name="src">当前指令自身IP地址</param>
 /// <param name="proxy">执行目标的代理IP地址</param>
 /// <param name="dest">最终目标位置</param>
 /// <param name="dtpl">目标协议类型名称</param>
 /// <param name="dcmd">目标指令名称</param>
 /// <param name="data">传送的指令字节,本地执行时返回响应字节,非本地执行则返回0长度字节</param>
 /// <returns></returns>
 public void CommiTrans(IPAddress proxy, CommiTarget dest,string dtpl, string dcmd, ref byte[] data)
 {
     if (null == proxy || null == dest || null == data || data.Length < 1)
         return;
     string ipaddr = proxy.ToString();
     if (string.IsNullOrEmpty(this.CmdId))
         this.CmdId = Guid.NewGuid().ToString();
     NameValueCollection info = new NameValueCollection();
     info["dtpl"] = dtpl;
     info["dcmd"] = dcmd;
     string[,] head ={ {"id",this.CmdId},{"cmd","TransFile.trans"},{"len", data.LongLength.ToString()},
                 {"dir","request"},{"target",proxy.ToString()},{"CommiType",dest.ProtocolType.ToString()}};
     for (int i = 0; i < head.GetLength(0); i++)
         info.Add(head[i, 0], head[i, 1]);
     if (CommiType.SerialPort != dest.ProtocolType)
     {
         info.Add("addr", dest.SrvEndPoint.Address.ToString());
         info.Add("port", dest.SrvEndPoint.Port.ToString());
     }
     else
     {
         info.Add("addr", dest.PortName);
         info.Add("baudRate", dest.BaudRate.ToString());
         info.Add("parity", dest.Parity.ToString());
         info.Add("dataBits", dest.DataBits.ToString());
         info.Add("stopBits", dest.StopBits.ToString());
     }
     bool islocal = false;
     string addr = proxy.ToString();
     IPAddress[] locals = Dns.GetHostAddresses(Dns.GetHostName());
     foreach (IPAddress ip in locals)
         if (addr == ip.ToString())
         {
             islocal = true;
             break;
         }
     if ("127.0.0.1" == addr)
         islocal = true;
     //本机通讯或目标是代理机本机则直接通讯
     if (islocal || proxy.ToString() == info["addr"])
     {
         info["dir"] = "response";
         info["source"] = info["target"];
         CmdProtocol cmd = new CmdProtocol(false);
         cmd.setCommand(dtpl, dcmd, "");
         cmd.setCommand(data);
         CommiManager.GlobalManager.SendCommand(dest, cmd);
         if (!cmd.EventWh.WaitOne(800, false))
             info["msg"] = "目标通讯超时失败";
         data = cmd.ResponseData;
         info["len"] = data.LongLength.ToString();
         CommiManager.GlobalManager.RemoveCommand(dest, cmd);
     }
     byte[] fh = SvrFileTrans.ParseInfo(info);
     byte[] context = new byte[fh.LongLength + data.LongLength];
     Array.Copy(fh, context, fh.LongLength);
     Array.Copy(data, 0, context, fh.LongLength, data.LongLength);
     this.setCommand(context);
     if (!islocal) data = new byte[0];
 }
Beispiel #5
0
        /// <summary>
        /// 传递通讯指令
        ///     包含参数: len,dir=request/response,cmd=TransFile.trans,source,target,
        ///               CommiType,addr=ipaddr/COM1,port,baudRate,parity,dataBits,stopBits
        /// </summary>
        /// <param name="src">当前指令自身IP地址</param>
        /// <param name="proxy">执行目标的代理IP地址</param>
        /// <param name="dest">最终目标位置</param>
        /// <param name="dtpl">目标协议类型名称</param>
        /// <param name="dcmd">目标指令名称</param>
        /// <param name="data">传送的指令字节,本地执行时返回响应字节,非本地执行则返回0长度字节</param>
        /// <returns></returns>
        public void CommiTrans(IPAddress proxy, CommiTarget dest, string dtpl, string dcmd, ref byte[] data)
        {
            if (null == proxy || null == dest || null == data || data.Length < 1)
            {
                return;
            }
            string ipaddr = proxy.ToString();

            if (string.IsNullOrEmpty(this.CmdId))
            {
                this.CmdId = Guid.NewGuid().ToString();
            }
            NameValueCollection info = new NameValueCollection();

            info["dtpl"]   = dtpl;
            info["dcmd"]   = dcmd;
            string[,] head = { { "id",  this.CmdId }, { "cmd",    "TransFile.trans" }, { "len",       data.LongLength.ToString()   },
                               { "dir", "request"  }, { "target", proxy.ToString()  }, { "CommiType", dest.ProtocolType.ToString() } };
            for (int i = 0; i < head.GetLength(0); i++)
            {
                info.Add(head[i, 0], head[i, 1]);
            }
            if (CommiType.SerialPort != dest.ProtocolType)
            {
                info.Add("addr", dest.SrvEndPoint.Address.ToString());
                info.Add("port", dest.SrvEndPoint.Port.ToString());
            }
            else
            {
                info.Add("addr", dest.PortName);
                info.Add("baudRate", dest.BaudRate.ToString());
                info.Add("parity", dest.Parity.ToString());
                info.Add("dataBits", dest.DataBits.ToString());
                info.Add("stopBits", dest.StopBits.ToString());
            }
            bool   islocal = false;
            string addr    = proxy.ToString();

            IPAddress[] locals = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress ip in locals)
            {
                if (addr == ip.ToString())
                {
                    islocal = true;
                    break;
                }
            }
            if ("127.0.0.1" == addr)
            {
                islocal = true;
            }
            //本机通讯或目标是代理机本机则直接通讯
            if (islocal || proxy.ToString() == info["addr"])
            {
                info["dir"]    = "response";
                info["source"] = info["target"];
                CmdProtocol cmd = new CmdProtocol(false);
                cmd.setCommand(dtpl, dcmd, "");
                cmd.setCommand(data);
                CommiManager.GlobalManager.SendCommand(dest, cmd);
                if (!cmd.EventWh.WaitOne(800, false))
                {
                    info["msg"] = "目标通讯超时失败";
                }
                data        = cmd.ResponseData;
                info["len"] = data.LongLength.ToString();
                CommiManager.GlobalManager.RemoveCommand(dest, cmd);
            }
            byte[] fh      = SvrFileTrans.ParseInfo(info);
            byte[] context = new byte[fh.LongLength + data.LongLength];
            Array.Copy(fh, context, fh.LongLength);
            Array.Copy(data, 0, context, fh.LongLength, data.LongLength);
            this.setCommand(context);
            if (!islocal)
            {
                data = new byte[0];
            }
        }
Beispiel #6
0
        /// <summary>
        /// ͣ�����豸��ʼ�������ز���,���ºڰ�����
        /// </summary>
        /// <param name="tarsrv">��ת������</param>
        /// <param name="trans">����ָ��</param>
        /// <param name="proxy">�豸ͨѶ�������IP��ַ</param>
        /// <param name="dest">Ŀ���豸</param>
        /// <param name="drdevice">�豸��Ϣ��¼��</param>
        /// <param name="attrcmd">ִ��ָ��</param>
        /// <returns>����ͨѶ���ز����Ƿ�ɹ�</returns>
        private bool commiDevicePark(CommiTarget tarsrv, CmdFileTrans trans, IPAddress proxy, CommiTarget dest, DataRow drdevice, string attrcmd)
        {
            if (null == tarsrv || null == proxy || null == dest || null == trans || null == drdevice || string.IsNullOrEmpty(attrcmd))
                return true;
            CmdProtocol cmdP = new CmdProtocol(false);
            string devID = Convert.ToString(drdevice["ID"]);
            NameObjectList ps = new NameObjectList();
            ps["�豸ID"] = devID;
            bool success = false;

            //ϵͳʱ��
            string tpl = "ͣ����";
            string valst = Convert.ToString(drdevice["վַ"]);
            DateTime dtsystem = Convert.ToDateTime(this.query.ExecuteScalar("ϵͳʱ��", ps));
            string cmdstr = ",��ʽ��,��ʼ��ID������,��ʼ��������,����ϵͳʱ��,���ؿ��Ʋ���,��ȡ���Ʋ���,����������Ϣ,";
            string[] cmds = attrcmd.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < cmds.Length; i++)
            {
                if (cmdstr.IndexOf("," + cmds[i] + ",") < 0)
                    continue;
                string tagdata = "@�豸��ַ=" + valst;
                if ("���ؿ��Ʋ���" == cmds[i])
                {
                    DataTable tabctrlpm = this.query.getTable("�豸���Ʋ���", ps);
                    if (null == tabctrlpm || tabctrlpm.Rows.Count < 1)
                        continue;
                    tagdata = this.getctrlpm(tabctrlpm.Rows[0], valst);
                }
                else if ("����ϵͳʱ��" == cmds[i])
                {
                    tagdata = basefun.setvaltag(tagdata, "{ϵͳʱ��}", dtsystem.ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else if ("����������Ϣ" == cmds[i])
                {
                    DataTable tabScress = this.query.getTable("����������Ϣ", ps);
                    if (null == tabScress || tabScress.Rows.Count < 1)
                        continue;
                    string cmd = "";
                    string downtype = "";
                    string datatype = "";
                    string message = "";
                    if (string.IsNullOrEmpty(Convert.ToString(tabScress.Rows[0]["������Ϣ"])))
                    {
                        cmd = "0000" + Internal_code(Convert.ToString(tabScress.Rows[0]["������Ϣ"]));
                        downtype = "00";
                        datatype = "00";
                        message = Convert.ToString(tabScress.Rows[0]["������Ϣ"]);
                    }
                    else
                    {
                        cmd = "0100" + Internal_code(Convert.ToString(tabScress.Rows[0]["��ӡ��Ϣ"]));
                        downtype = "01";
                        datatype = "00";
                        message = Convert.ToString(tabScress.Rows[0]["��ӡ��Ϣ"]);
                    }
                    tagdata = basefun.setvaltag(tagdata, "{���ط�ʽ}", downtype);
                    tagdata = basefun.setvaltag(tagdata, "��������", datatype);
                    tagdata = basefun.setvaltag(tagdata, "�Զ�����Ϣ", Internal_code(message));
                    string sLen = (cmd.Length / 2).ToString("X");
                    tagdata = basefun.setvaltag(tagdata, "{�����}", sLen);
                }
                cmdP.setCommand(tpl, cmds[i], tagdata);
                success = this.sendCommand(tarsrv, trans, proxy, dest, cmdP, tpl, cmds[i], tagdata);
                if (!success) return false;
                //��ʽ��ʱ�豸��2.5s��Ӧ��
                if ("��ʽ��" == cmds[i])
                    System.Threading.Thread.Sleep(3500);
            }

            //��������ָ�����ʵ��
            TransArg arg = new TransArg();
            arg.trans = trans;
            arg.target = tarsrv;
            arg.proxy = proxy;
            arg.dest = dest;
            arg.devID = devID;
            arg.addrst = Convert.ToString(drdevice["վַ"]);
            arg.attrCmdtag = attrcmd;

            //���ؼƷѱ�׼
            success = this.downPayRule(arg);
            //if (!success) return false;
            ////������������
            //this.query.ExecuteNonQuery("�豸���ر�־����", ps, ps, ps);

            //���úڰ�����
            if (attrcmd.IndexOf("|��ʽ��|") > -1 || attrcmd.IndexOf("|��ʼ��ID������|") > -1 || attrcmd.IndexOf("|��ʼ��������|") > -1)
                this.query.ExecuteNonQuery("�����豸����", ps, ps, ps);
            success = this.downparkCardList(arg);
            //�豸������ʾ
            string tag = "@�豸��ַ=" + valst;
            this.sendCommand(tarsrv, trans, proxy, dest, cmdP, tpl, "����", tag);
            return success;
        }
Beispiel #7
0
        /// <summary>
        /// ���ؿ��Ʋ���
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private bool downdoorctrlpm(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            NameObjectList ps = new NameObjectList();
            ps["�豸ID"] = devID;
            DataTable tabpm = this.query.getTable("�Ž����Ʋ���", ps);
            if (null == tabpm || tabpm.Rows.Count < 1)
                return true;
            bool success = false;
            string tpl = "�Ž�";
            string tag = "@�豸��ַ=" + addrst;
            //�����Ų���
            string[,] colmapdoor ={ { "{���Ʒ�ʽ}", "���Ʒ�ʽ" }, { "{��ʱ}", "������ʱ" }, { "{�ź�}", "�ź�" } };
            foreach (DataRow dr in tabpm.Rows)
            {
                tag = "@�豸��ַ=" + addrst;
                string mode = Convert.ToString(dr["���Ʒ�ʽ"]);
                switch (mode)
                {
                    case "����": mode = "1"; break;
                    case "����": mode = "1"; break;
                    default: mode = "3"; break;
                }
                tag = basefun.setvaltag(tag, "{���Ʒ�ʽ}", mode);
                tag = basefun.setvaltag(tag, "{��ʱ}", Convert.ToString(dr["������ʱ"]));
                tag = basefun.setvaltag(tag, "{�ź�}", Convert.ToString(Convert.ToInt16(dr["�ź�"]) + 1));
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "���ÿ��Ʋ���", tag);
                if (!success) return false;
            }
            //��������
            string[,] colmapalarm ={ { "{����״̬}.{��}", "�𾯸澯" }, { "{����״̬}.{��Чˢ��}", "�Ƿ�ˢ���澯" },
                        { "{����״̬}.{��������}", "�����澯" }, { "{����״̬}.{�Ƿ�����}", "�Ƿ����Ÿ澯" },
                        { "{����״̬}.{��ʱ}", "��ʱ���Ÿ澯" }, { "{����״̬}.{в��}", "в�ȱ���" },
                        {"{���ų�ʱʱ��}","���ų�ʱ"}, {"{�������ʱ��}","����������ʱ"} };
            DataRow drpm = tabpm.Rows[0];
            tag = "@�豸��ַ=" + addrst;
            for (int c = 0; c < colmapalarm.GetLength(0); c++)
            {
                string val = Convert.ToString(drpm[colmapalarm[c, 1]]);
                if (true.Equals(drpm[colmapalarm[c, 1]]))
                    val = "1";
                else if (false.Equals(drpm[colmapalarm[c, 1]]))
                    val = "0";
                tag = basefun.setvaltag(tag, colmapalarm[c, 0], val);
            }
            success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "����", tag);
            if (!success) return false;
            //�����¼���־��������¼ָ��
            string[,] colmaplog ={ { "��¼���Ű�ť", "2D" }, { "��¼�澯�¼�", "2E" }, { "��¼�Ŵ��¼�", "DC" } };
            for (int m = 0; m < colmaplog.GetLength(0); m++)
            {
                tag = "@�豸��ַ=" + addrst;
                tag = basefun.setvaltag(tag, "{������}", colmaplog[m, 1]);
                tag = basefun.setvaltag(tag, "{����}", "0");
                if (true.Equals(drpm[colmaplog[m, 0]]))
                    tag = basefun.setvaltag(tag, "{����}", "1");
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "�����¼���־", tag);
                if (!success) return false;
            }
            //���÷�DZ����DZָ����Ҫ��ȷ��ָ��
            tag = "@�豸��ַ=" + addrst;
            string unhide = Convert.ToString(drpm["��DZ���"]);
            string unhideOK = "00";
            switch (unhide)
            {
                case "���÷�DZ": unhide = "0"; unhideOK = "0A"; break;
                case "������DZ": unhide = "1"; unhideOK = "FA"; break;
                case "������DZ": unhide = "2"; unhideOK = "FA"; break;
                case "һ������": unhide = "3"; unhideOK = "7E"; break;
                case "һ�����": unhide = "4"; unhideOK = "FE"; break;
                default: unhide = "0"; unhideOK = "00"; break;
            }
            tag = basefun.setvaltag(tag, "{��DZ��}", unhide);
            success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "���÷�DZ", tag);
            if (!success) return false;
            tag = basefun.setvaltag(tag, "{��DZ��}", unhideOK);
            success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "���÷�DZȷ��", tag);
            if (!success) return false;
            //���û����������跢���ָ�����
            tag = "@�豸��ַ=" + addrst;
            string[] cmds = new string[] { "001E", "001F", "0020", "0021" };
            string locklink = Convert.ToString(drpm["�������"]);
            switch (locklink)
            {
                case "���û���": locklink = "00"; break;
                case "��������": locklink = "01"; break;
                case "���Ż���":
                    locklink = "71";
                    cmds = new string[] { "001E", "001F", "0020" };
                    break;
                case "ȫ������": locklink = "F1"; break;
                default: locklink = "00"; break;
            }
            tag = basefun.setvaltag(tag, "{����}", locklink);
            for (int i = 0; i < cmds.Length; i++)
            {
                tag = basefun.setvaltag(tag, "{������}", cmds[i]);
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "���û���", tag);
                if (!success) return false;
            }
            //������չ�����
            DataTable tabext = this.query.getTable("�Ž���չ�����", ps);
            if (null == tabext || tabext.Rows.Count < 1)
                return true;
            //������չ��ָ�ÿ����չ��ֱ��ĸ�ָ��
            string[,] codefun ={
                                 { "98", "9A", "9B", "9C", "9D" }, { "9E", "A0", "A1", "A2", "A3" },
                                 { "A4", "A6", "A7", "A8", "A9" }, { "AA", "AC", "AD", "AE", "AF" }  };
            colmapdoor = new string[,]{ { "{��λ}.{��1}", "һ����" }, { "{��λ}.{��2}", "������" },
                                 { "{��λ}.{��3}", "������" }, { "{��λ}.{��4}", "�ĺ���" } };
            colmapalarm = new string[,]{ { "{����״̬}.{��}", "�𾯸澯" }, { "{����״̬}.{��Чˢ��}", "�Ƿ�ˢ���澯" },
                        { "{����״̬}.{��������}", "�����澯" }, { "{����״̬}.{�Ƿ�����}", "�Ƿ����ű���" },
                        { "{����״̬}.{��ʱ}", "��ʱ���Ÿ澯" }, { "{����״̬}.{в��}", "в�ȱ���" } };
            string strtime = Convert.ToString(drpm["����������ʱ"]);
            if (string.IsNullOrEmpty(strtime))
                strtime = "0";
            long latetime = Convert.ToInt64(strtime);
            string latestr = Convert.ToString(latetime, 16).PadLeft(4, '0');
            latestr = latestr.Substring(latestr.Length - 4);
            foreach (DataRow drext in tabext.Rows)
            {
                string strbh = Convert.ToString(drext["���"]);
                if (string.IsNullOrEmpty(strbh))
                    continue;
                int index = Convert.ToInt32(strbh);
                if (index < 0 || index > 3)
                    continue;
                //�����¼�Դ
                tag = "@�豸��ַ=" + addrst;
                tag = basefun.setvaltag(tag, "{������}", codefun[index, 0]);
                for (int i = 0; i < colmapdoor.GetLength(0); i++)
                    tag = basefun.setvaltag(tag, colmapdoor[i, 0], true.Equals(drext[colmapdoor[i, 1]]) ? "1" : "0");
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "��չ���¼�Դ", tag);
                if (!success) return false;
                //����
                tag = "@�豸��ַ=" + addrst;
                tag = basefun.setvaltag(tag, "{������}", codefun[index, 1]);
                for (int i = 0; i < colmapalarm.GetLength(0); i++)
                    tag = basefun.setvaltag(tag, colmapalarm[i, 0], true.Equals(drext[colmapalarm[i, 1]]) ? "1" : "0");
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "��չ�屨������", tag);
                if (!success) return false;
                //������ʱ��λ
                tag = "@�豸��ַ=" + addrst;
                tag = basefun.setvaltag(tag, "{������}", codefun[index, 3]);
                tag = basefun.setvaltag(tag, "{��ʱ}", latestr.Substring(2));
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "��չ����ʱ��λ", tag);
                if (!success) return false;
                //������ʱ��λ
                tag = "@�豸��ַ=" + addrst;
                tag = basefun.setvaltag(tag, "{������}", codefun[index, 4]);
                tag = basefun.setvaltag(tag, "{��ʱ}", latestr.Substring(0, 2));
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, "��չ����ʱ��λ", tag);
                if (!success) return false;
            }
            return true;
        }
        /// <summary>
        /// 中转执行指令
        /// </summary>
        /// <param name="tarsrv">服务器</param>
        /// <param name="trans">传输实例</param>
        /// <param name="proxy">设备代理电脑IP地址</param>
        /// <param name="dest">设备目标</param>
        /// <param name="cmdP">指令实例</param>
        /// <param name="tpl">协议名称</param>
        /// <param name="cmd">指令名称</param>
        /// <param name="tagdata">指令数据 tag格式</param>
        /// <returns>是否执行成功</returns>
        private bool sendCommand(CommiTarget tarsrv, CmdFileTrans trans, IPAddress proxy, CommiTarget dest, CmdProtocol cmdP, string tpl, string cmd, string tagdata)
        {
            if (null == tarsrv || null == proxy || null == dest || null == trans || null == cmdP)
                return false;
            if (string.IsNullOrEmpty(tpl) || string.IsNullOrEmpty(cmd) || string.IsNullOrEmpty(tagdata))
                return false;
            CommiManager mgr = CommiManager.GlobalManager;
            string msg = "";

            bool islocal = false;
            string addr = proxy.ToString();
            IPAddress[] locals = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress ip in locals)
                if (addr == ip.ToString())
                {
                    islocal = true;
                    break;
                }
            if ("127.0.0.1" == addr)
                islocal = true;
            int tmout = this.timeout;
            if ("门禁" == tpl && "清空白名单" == cmd)
            {
                tmout = 35 * 1000;
                cmdP.TimeOut = new TimeSpan(0, 0, 35);
                cmdP.TimeLimit = new TimeSpan(0, 0, 2 * 35);
                cmdP.TimeFailLimit = cmdP.TimeLimit;
            }
            //本机通讯或目标是代理机本机则直接通讯
            string wordcmd = basefun.valtag(tagdata, "{命令字}");
            if (islocal || CommiType.SerialPort != dest.ProtocolType)
            {
                if (null == cmdP.EventWh)
                    cmdP.EventWh = new ManualResetEvent(false);
                for (int i = 0; i < 2; i++)
                {

                    cmdP.setCommand(tpl, cmd, tagdata);
                    msg = "";
                    Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + cmd + " " + tagdata);
                    myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + cmd + " " + tagdata);
                    mgr.SendCommand(dest, cmdP, true);
                    if (cmdP.EventWh.WaitOne(tmout, false))
                        msg = cmdP.ResponseFormat;
                    Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
                    myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
                    string rtn = basefun.valtag(msg, "Success");
                    string wd2 = basefun.valtag(msg, "{命令字}");
                    if ("true" == rtn && (wordcmd == wd2 || string.IsNullOrEmpty(wordcmd) || string.IsNullOrEmpty(wd2)))
                        break;
                    if ("false" == rtn && (wordcmd == wd2 || string.IsNullOrEmpty(wordcmd) || string.IsNullOrEmpty(wd2)))
                        break;
                    if (this.cnnout < 1)
                        break;
                    if (string.IsNullOrEmpty(msg) && CommiType.SerialPort != dest.ProtocolType)
                    {
                        Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 测试网络连接...");
                        myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 测试网络连接...");
                        if (!Ping(dest)) break;
                    }
                }
            }
            else
            {
                for (int i = 0; i < 1; i++)
                {
                    cmdP.setCommand(tpl, cmd, tagdata);
                    byte[] data = cmdP.getCommand();
                    trans.CommiTrans(proxy, dest, tpl, cmd, ref data);
                    mgr.SendCommand(tarsrv, trans, true);
                    //同步通讯等待时间1.5秒
                    if (trans.EventWh.WaitOne(2 * tmout, false))
                        data = trans.FileContext;
                    msg = cmdP.FormatResponse(data);
                    string rtn = basefun.valtag(msg, "Success");
                    string wd2 = basefun.valtag(msg, "{命令字}");
                    if ("true" == rtn && (wordcmd == wd2 || string.IsNullOrEmpty(wordcmd) || string.IsNullOrEmpty(wd2)))
                        break;
                    if ("false" == rtn && (wordcmd == wd2 || string.IsNullOrEmpty(wordcmd) || string.IsNullOrEmpty(wd2)))
                        break;
                }
            }
            if ("门禁" == tpl && "清空白名单" == cmd)
                this.setTimeout(cmdP);
            if ("true" != basefun.valtag(msg, "Success"))
            {
                NameValueCollection attr = new NameValueCollection();
                attr["协议"] = tpl;
                attr["操作"] = tagdata + "\r\n" + cmd;
                ServiceTool.LogMessage(msg, attr, EventLogEntryType.Error);
                return false;
            }
            return true;
        }
        /// <summary>
        /// 中转执行指令,返回响应结果
        /// </summary>
        /// <param name="tarsrv">服务器</param>
        /// <param name="trans">传输实例</param>
        /// <param name="proxy">设备代理电脑IP地址</param>
        /// <param name="dest">设备目标</param>
        /// <param name="cmdP">指令实例</param>
        /// <param name="tpl">协议名称</param>
        /// <param name="cmd">指令名称</param>
        /// <param name="tagdata">指令数据 tag格式</param>
        /// <returns>返回执行结果</returns>
        private string getResponse(CommiTarget tarsrv, CmdFileTrans trans, IPAddress proxy, CommiTarget dest, CmdProtocol cmdP, string tpl, string cmd, string tagdata)
        {
            if (null == tarsrv || null == proxy || null == dest || null == trans || null == cmdP)
                return "";
            if (string.IsNullOrEmpty(tpl) || string.IsNullOrEmpty(cmd) || string.IsNullOrEmpty(tagdata))
                return "";
            CommiManager mgr = CommiManager.GlobalManager;
            string msg = "";

            bool islocal = false;
            string addr = proxy.ToString();
            IPAddress[] locals = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress ip in locals)
                if (addr == ip.ToString())
                {
                    islocal = true;
                    break;
                }
            if ("127.0.0.1" == addr)
                islocal = true;
            //本机通讯或目标是代理机本机则直接通讯
            string wordcmd = basefun.valtag(tagdata, "{命令字}");
            if (islocal || CommiType.SerialPort != dest.ProtocolType)
            {
                if (null == cmdP.EventWh)
                    cmdP.EventWh = new ManualResetEvent(false);
                for (int i = 0; i < 2; i++)
                {
                    cmdP.setCommand(tpl, cmd, tagdata);
                    msg = "";
                    Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + cmd + " " + tagdata);
                    myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + cmd + " " + tagdata);
                    mgr.SendCommand(dest, cmdP, true);
                    if (cmdP.EventWh.WaitOne(timeout, false))
                        msg = cmdP.ResponseFormat;
                    Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
                    myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
                    string rtn = basefun.valtag(msg, "Success");
                    string wd2 = basefun.valtag(msg, "{命令字}");
                    if ("true" == rtn && (wordcmd == wd2 || string.IsNullOrEmpty(wordcmd) || string.IsNullOrEmpty(wd2)))
                        break;
                    if ("false" == rtn && (wordcmd == wd2 || string.IsNullOrEmpty(wordcmd) || string.IsNullOrEmpty(wd2)))
                        break;
                    if (this.cnnout < 1)
                        break;
                    if (string.IsNullOrEmpty(msg) && CommiType.SerialPort != dest.ProtocolType)
                    {
                        Debug.WriteLine(String.Format("{0:HH:mm:ss.fff} 测试网络连接...", DateTime.Now));
                        myLog.WriteLine(String.Format("{0:HH:mm:ss.fff} 测试网络连接...", DateTime.Now));
                        if (!Ping(dest)) break;
                    }
                }
            }
            else
            {
                for (int i = 0; i < 1; i++)
                {
                    cmdP.setCommand(tpl, cmd, tagdata);
                    byte[] data = cmdP.getCommand();
                    trans.CommiTrans(proxy, dest, tpl, cmd, ref data);
                    mgr.SendCommand(tarsrv, trans, true);
                    //同步通讯等待时间1.5秒
                    if (trans.EventWh.WaitOne(2 * timeout, false))
                        data = trans.FileContext;
                    msg = cmdP.FormatResponse(data);
                    string rtn = basefun.valtag(msg, "Success");
                    string wd2 = basefun.valtag(msg, "{命令字}");
                    if ("true" == rtn && (wordcmd == wd2 || string.IsNullOrEmpty(wordcmd) || string.IsNullOrEmpty(wd2)))
                        break;
                    if ("false" == rtn && (wordcmd == wd2 || string.IsNullOrEmpty(wordcmd) || string.IsNullOrEmpty(wd2)))
                        break;
                }
            }
            return msg;
        }
        /// <summary>
        /// 下载控制参数
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private bool downeateryctrlpm(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            this.setTimeout(cmdP);
            NameObjectList ps = new NameObjectList();
            ps["设备ID"] = devID;
            bool success = false;
            //清空菜单
            string tpl = "消费", cmd = "清空消费参数";
            string tagdata = "@设备地址=" + addrst;
            success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
            //if (!success) return false;
            //下载控制参数
            Monitor.Enter(query);
            DataTable tab = this.query.getTable("消费控制参数", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            if (null == tab || tab.Rows.Count < 1)
                return false;
            DataRow drctrl = tab.Rows[0];
            string[,] colmap ={ { "{通信密码}", "通讯密码" }, { "{系统密码}", "系统密码" }, { "{用户密码}", "用户密码" }, { "{卡片区域}", "卡片区号" },
                    { "{记录门限}", "空间告警" }, { "{黑名单门限}", "黑名单门限" }, { "{取消交易门限}", "取消交易门限" },
                    { "{单卡单次限额}", "单次限额" }, { "{卡最大余额}", "卡限额" }, { "{操作延时}", "操作延时" }, { "{显示延时}", "显示延时" }, 
                    { "{操作控制}.{记录溢出允许消费}", "允许溢出" }, { "{操作控制}.{时段限制}", "时段限制" }, { "{操作控制}.{操作员凭密取消上笔交易}", "凭密取消交易" },
                    { "{操作控制}.{操作员直接取消上笔交易}", "直接取消交易" }, { "{操作控制}.{管理卡可设置参数}", "可设置参数" }, 
                    { "{操作控制}.{授权卡可初始化设备}", "可初始化" }, 
                    { "{消费控制}.{定额直接扣费}", "定额直接扣费" }, { "{消费控制}.{副卡独立}", "副卡独立" }, { "{消费控制}.{打印记录}", "打印记录" }, 
                    { "{消费控制}.{可现金消费}", "可现金消费" }, { "{消费控制}.{可赊账消费}", "可赊账消费" }, { "{消费控制}.{可超额}", "可超额" }, 
                    { "{消费控制}.{凭密消费}", "凭密消费" }, 
                    { "{赊账限额}", "赊账限额" }, { "{开机方式}", "开机方式" }, { "{食堂编号}", "编号" } };
            for (int i = 0; i < colmap.GetLength(0); i++)
                tagdata = basefun.setvaltag(tagdata, colmap[i, 0], Convert.ToString(drctrl[colmap[i, 1]]));
            cmd = "设置控制参数";
            success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
            if (!success) return false;
            //下载菜单
            tagdata = "@设备地址=" + addrst;
            Monitor.Enter(query);
            tab = this.query.getTable("消费价格参数", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            colmap = new string[,] { { "{编码}", "编号" }, { "{价格}", "价格" } };
            cmd = "下载消费参数";
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow drmenu = tab.Rows[i];
                for (int c = 0; c < colmap.GetLength(0); c++)
                {
                    string val = Convert.ToString(drmenu[colmap[c, 1]]);
                    tagdata = basefun.setvaltag(tagdata, colmap[c, 0], val);
                }
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                if (!success) return false;
            }
            return true;
        }
        /// <summary>
        /// 回收补助机没有下载的补助,清空补助后,合并到未下载补助一起下载
        /// </summary>
        /// <param name="arg">传输指令参数</param>
        /// <returns></returns>
        private bool downeaterySubsidy(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            //判断是否下载补助
            if (string.IsNullOrEmpty(attrcmd) || attrcmd.IndexOf("|下载补助名单|") < 0)
                return true;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            this.setTimeout(cmdP);
            NameObjectList ps = new NameObjectList();
            ps["设备ID"] = devID;
            string tpl = "消费", cmd = "取当前补助记录";
            string tag = "@设备地址=" + addrst;
            //首先提取补助记录
            string msg = this.getResponse(target, trans, proxy, dest, cmdP, tpl, cmd, tag);
            if (string.IsNullOrEmpty(msg))
                return false;
            string cardnum = basefun.valtag(msg, "{卡号}");
            cmd = "取下一条补助记录";
            string rsl = basefun.valtag(msg, "Success");
            while ("false" == rsl || (!string.IsNullOrEmpty(cardnum) && "16777215" != cardnum && "0" != cardnum))
            {
                NameObjectList pm = createParam(msg);
                if ("true" == rsl)
                {
                    Monitor.Enter(query);
                    bool rtn = this.query.ExecuteNonQuery("消费接收补助", pm, pm, pm);
                    Monitor.PulseAll(query);
                    Monitor.Exit(query);
                    if (!rtn) return false;
                }
                msg = this.getResponse(target, trans, proxy, dest, cmdP, tpl, cmd, tag);
                cardnum = basefun.valtag(msg, "{卡号}");
                rsl = basefun.valtag(msg, "Success");
            }
            //读取没有接收的补助记录,回收合并到补助记录
            Monitor.Enter(query);
            DataTable tab = this.query.getTable("消费回收补助", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            if (null == tab) return false;
            cmd = "查询用户补助金额";
            string[,] cols = { { "卡号", "{用户编号}" }, { "卡片序列号", "{卡片物理序号}" } };
            string[,] pn = { { "卡号", "{用户编号}" }, { "卡片序列号", "{卡片物理序号}" }, { "补助金额", "{补助金额}" }, { "补助状态", "{补助状态}" } };
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow dr = tab.Rows[i];
                for (int c = 0; c < cols.GetLength(0); c++)
                    tag = basefun.setvaltag(tag, cols[c, 1], Convert.ToString(dr[cols[c, 0]]));
                msg = this.getResponse(target, trans, proxy, dest, cmdP, tpl, cmd, tag);
                if (string.IsNullOrEmpty(msg))
                {
                    if (!testConnect(target, dest))
                        return false;
                }
                if ("true" != basefun.valtag(msg, "Success"))
                    continue;
                NameObjectList pm = new NameObjectList();
                for (int p = 0; p < pn.GetLength(0); p++)
                    pm[pn[p, 0]] = basefun.valtag(msg, pn[p, 1]);
                Monitor.Enter(query);
                this.query.ExecuteNonQuery("消费回收补助", pm, pm, pm);
                Monitor.PulseAll(query);
                Monitor.Exit(query);
            }
            Monitor.Enter(query);
            tab = this.query.getTable("消费下载补助", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            cmd = "下载补助名单";
            tag = "@设备地址=" + addrst;
            cols = new string[,] { { "卡号", "{用户编号}" }, { "卡片序列号", "{卡片物理序号}" }, { "补助充值", "{补助金额}" } };
            bool success = true;
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow dr = tab.Rows[i];
                for (int c = 0; c < cols.GetLength(0); c++)
                    tag = basefun.setvaltag(tag, cols[c, 1], Convert.ToString(dr[cols[c, 0]]));
                bool suc = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tag);
                success = success && suc;
                if (!suc)
                {
                    if (!testConnect(target, dest))
                        return false;
                    continue;
                }
                ps["卡号"] = Convert.ToString(dr["卡号"]);
                Monitor.Enter(query);
                suc = this.query.ExecuteNonQuery("消费下载补助", ps, ps, ps);
                Monitor.PulseAll(query);
                Monitor.Exit(query);
                if (!suc) return false;
            }
            return success;
        }
        /// <summary>
        /// 下载时段
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private bool downeaterytime(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            this.setTimeout(cmdP);
            NameObjectList ps = new NameObjectList();
            ps["设备ID"] = devID;
            //同步通讯等待时间15秒
            bool success = false;

            Monitor.Enter(query);
            DataTable tab = this.query.getTable("消费时间区间", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            string tpl = "消费", cmd = "下载时间区间";
            string[,] colmap ={ { "{时间区间号}", "序号" }, { "{起始时间}", "开始" }, { "{结束时间}", "结束" },
                                { "{消费限额}", "时段限额" }, { "{消费限次}", "时段限次" } };
            string tagdata = "@设备地址=" + addrst;
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow drtime = tab.Rows[i];
                for (int c = 0; c < colmap.GetLength(0); c++)
                {
                    string val = "0";
                    if (DBNull.Value != drtime[colmap[c, 1]])
                        val = Convert.ToString(drtime[colmap[c, 1]]);
                    tagdata = basefun.setvaltag(tagdata, colmap[c, 0], val);
                }
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                if (!success) return false;
            }
            cmd = "设置时段";
            colmap = new string[,]{ { "{星期}", "星期序号" }, 
                                { "{时段1}", "晨餐" }, { "{时段2}", "早餐" }, { "{时段3}", "午餐" }, { "{时段4}", "下午茶" }, 
                                { "{时段5}", "晚餐" }, { "{时段6}", "夜宵" },{ "{时段7}", "加餐1" }, { "{时段8}", "加餐2" },
                                { "{消费限额}", "每天限额" }, { "{次数限制}", "每日限次" } };
            tagdata = "@设备地址=" + addrst;
            Monitor.Enter(query);
            tab = this.query.getTable("消费周时段", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow drtime = tab.Rows[i];
                for (int c = 0; c < colmap.GetLength(0); c++)
                {
                    string val = "0";
                    if (DBNull.Value != drtime[colmap[c, 1]])
                        val = Convert.ToString(drtime[colmap[c, 1]]);
                    tagdata = basefun.setvaltag(tagdata, colmap[c, 0], val);
                }
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                if (!success) return false;
            }
            return true;
        }
        /// <summary>
        /// 消费设备初始化和下载参数,更新黑白名单
        /// </summary>
        /// <param name="tarsrv">中转服务器</param>
        /// <param name="trans">传输指令</param>
        /// <param name="proxy">设备通讯代理电脑IP地址</param>
        /// <param name="dest">目标设备</param>
        /// <param name="drdevice">设备信息记录行</param>
        /// <param name="attrcmd">执行指令</param>
        /// <returns>返回通讯下载参数是否成功</returns>
        private bool commiDeviceEatery(CommiTarget tarsrv, CmdFileTrans trans, IPAddress proxy, CommiTarget dest, DataRow drdevice, string attrcmd)
        {
            if (null == tarsrv || null == proxy || null == dest || null == trans || null == drdevice || string.IsNullOrEmpty(attrcmd))
                return true;
            CmdProtocol cmdP = new CmdProtocol(false);
            this.setTimeout(cmdP);
            string devID = Convert.ToString(drdevice["ID"]);
            //建立传输指令参数实例
            TransArg arg = new TransArg();
            arg.trans = trans;
            arg.target = tarsrv;
            arg.proxy = proxy;
            arg.dest = dest;
            arg.devID = devID;
            arg.addrst = Convert.ToString(drdevice["站址"]);
            arg.attrCmdtag = attrcmd;

            NameObjectList ps = new NameObjectList();
            ps["设备ID"] = devID;
            bool success = false;
            string tpl = "消费";
            string valst = Convert.ToString(drdevice["站址"]);
            //系统时间
            Monitor.Enter(query);
            DateTime dtsystem = Convert.ToDateTime(this.query.ExecuteScalar("系统时间", ps));
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            string cmdstr = ",格式化,清空记录,清空补助名单,清空黑名单,清空时段,设置时间,设置时段,设置控制参数,";
            string[] cmds = attrcmd.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < cmds.Length; i++)
            {
                if (cmdstr.IndexOf("," + cmds[i] + ",") < 0)
                    continue;
                string tagdata = "@设备地址=" + valst;
                if ("设置时间" == cmds[i])
                    tagdata = basefun.setvaltag(tagdata, "{日期时间}", dtsystem.ToString("yyyy-MM-dd HH:mm:ss"));
                if ("设置时段" == cmds[i])
                {
                    success = this.downeaterytime(arg);
                    if (!success) return false;
                    continue;
                }
                if ("设置控制参数" == cmds[i])
                {
                    success = this.downeateryctrlpm(arg);
                    if (!success) return false;
                    continue;
                }
                success = this.sendCommand(tarsrv, trans, proxy, dest, cmdP, tpl, cmds[i], tagdata);
                //格式化时设备有2.5s不应期
                if ("格式化" == cmds[i])
                {
                    System.Threading.Thread.Sleep(3500);
                    continue;
                }
                if (!success) return false;
            }
            //更新下载日期
            Monitor.Enter(query);
            this.query.ExecuteNonQuery("设备下载标志更新", ps, ps, ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);

            //重置黑白名单
            if (attrcmd.IndexOf("|格式化|") > -1 || attrcmd.IndexOf("|清空白名单|") > -1)
            {
                Monitor.Enter(query);
                this.query.ExecuteNonQuery("重置设备名单", ps, ps, ps);
                Monitor.PulseAll(query);
                Monitor.Exit(query);
            }
            success = this.downeateryCardList(arg);
            if (!success) return false;
            //回收消费卡没有接收到的补助,并下载未下载的补助
            success = this.downeaterySubsidy(arg);
            return success;
        }
        /// <summary>
        /// 更新设备的黑白清名单,执行成功后更新黑白名单下载日期
        /// </summary>
        /// <param name="arg">传输指令参数</param>
        private bool downchannelCardList(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            if (string.IsNullOrEmpty(attrcmd) || (attrcmd.IndexOf("|删除白名单|") < 0 && attrcmd.IndexOf("|下载白名单|") < 0))
                return true;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            this.setTimeout(cmdP);
            cmdP.TimeSendInv = new TimeSpan(1, 0, 0);
            NameValueCollection data = new NameValueCollection();
            NameObjectList ps = new NameObjectList();
            ps["设备ID"] = devID;
            //同步通讯等待时间15秒
            bool success = true, isconn = true;
            DataTable tab = null;
            string tpl = "门禁", cmd = "删除白名单";
            string tagdata = "@设备地址=" + addrst;
            if (attrcmd.IndexOf("|删除白名单|") > -1)
            {
                Monitor.Enter(query);
                tab = this.query.getTable("道闸清名单", ps);
                Monitor.PulseAll(query);
                Monitor.Exit(query);
                ps["状态"] = "清";
                for (int i = 0, len = null != tab ? tab.Rows.Count : 0; isconn && i < len; i++)
                {
                    DataRow dr = tab.Rows[i];
                    string cardnum = Convert.ToString(dr["卡号"]);
                    tagdata = basefun.setvaltag(tagdata, "{卡号}", cardnum);
                    //附加字段保存了对应门号(读卡器号)
                    string dstr = Convert.ToString(dr["撤权"]);
                    if (string.IsNullOrEmpty(dstr))
                        continue;
                    string dndoors = Convert.ToString(dr["已下载"]);
                    string[] bh = dstr.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    bool rtn = true;
                    for (int b = 0; b < bh.Length; b++)
                    {
                        //门号以1起始
                        bh[b] = Convert.ToString(Convert.ToInt32(bh[b]) + 1);
                        tagdata = basefun.setvaltag(tagdata, "{门号}", bh[b]);
                        rtn = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                        if (!rtn) break;
                        dndoors.Replace(bh[b], "").Replace(",,", ",");
                    }
                    success = success && rtn;
                    if (!rtn)
                    {
                        isconn = testConnect(target, dest);
                        continue;
                    }
                    dstr = Convert.ToString(dr["授权"]);
                    bh = dstr.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    for (int b = 0; b < bh.Length; b++)
                    {
                        if (dndoors.Contains(bh[b]))
                            continue;
                        rtn = false;
                        break;
                    }
                    ps["卡号"] = cardnum;
                    ps["是否完成"] = rtn;
                    ps["已下载"] = dndoors;
                    //更新数据
                    Monitor.Enter(query);
                    this.query.ExecuteNonQuery("名单下载标志更新", ps, ps, ps);
                    Monitor.PulseAll(query);
                    Monitor.Exit(query);
                }
            }
            if (attrcmd.IndexOf("|下载白名单|") < 0)
            {
                CommiManager.GlobalManager.RemoveCommand(dest, cmdP);
                return success;
            }
            int sleep = 0;
            try
            {
                string strsleep = DataAccRes.AppSettings("doorsleep");
                if (!string.IsNullOrEmpty(strsleep))
                    sleep = Convert.ToInt32(strsleep);
            }
            catch { }
            Monitor.Enter(query);
            tab = this.query.getTable("道闸白名单", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            if (null == tab)
            {
                CommiManager.GlobalManager.RemoveCommand(dest, cmdP);
                return false;
            }
            tab.Columns.Add("是否完成", typeof(bool));
            string[,] colmap ={ { "{卡号}", "卡号" }, { "{起始日期}", "发布日期" }, { "{终止日期}", "有效日期" }, { "{时段}", "时段" },
                                        { "{姓名}", "姓名" }, { "{编号}", "用户编号" } };
            cmd = "下载白名单";
            if (attrcmd.IndexOf("|清空白名单|") > -1)
                cmd = "下载加权白名单";
            string devtype = "进出口";
            if (tab.Rows.Count > 0)
                devtype = Convert.ToString(tab.Rows[0]["控制器类型"]);
            int indexdoor = 1;
            ps["状态"] = "白";
            for (int d = 0; d < 4; d++)
            {
                string idxd = Convert.ToString(d + 1);
                string strd = Convert.ToString(d);
                if (d > 0 && ("进出口" == devtype || "出入口" == devtype))
                    idxd = "2";
                for (int i = 0; isconn && i < tab.Rows.Count; i++)
                {
                    DataRow dr = tab.Rows[i];
                    string cardnum = Convert.ToString(dr["卡号"]);
                    string dstr = Convert.ToString(dr["授权"]);
                    string dndoors = Convert.ToString(dr["已下载"]);
                    if (d > 0 && ("进出口" == devtype || "出入口" == devtype))
                    {
                        if (string.IsNullOrEmpty(dstr) || (dstr.IndexOf("1") < 0 && dstr.IndexOf("2") < 0 && dstr.IndexOf("3") < 0))
                            continue;
                    }
                    else if (string.IsNullOrEmpty(dstr) || dstr.IndexOf(strd) < 0)
                        continue;
                    if (true.Equals(dr["是否完成"])) continue;
                    bool rtn = true;
                    if (!dndoors.Contains(strd))
                    {
                        tagdata = "@设备地址=" + addrst;
                        for (int j = 0; j < colmap.GetLength(0); j++)
                            tagdata = basefun.setvaltag(tagdata, colmap[j, 0], Convert.ToString(dr[colmap[j, 1]]));
                        tagdata = basefun.setvaltag(tagdata, "{门号}", idxd);
                        tagdata = basefun.setvaltag(tagdata, "{密码}", "255");
                        //增加白名单
                        tagdata = basefun.setvaltag(tagdata, "{保留字1}", "0100");
                        //增加尾部授权白名单
                        tagdata = basefun.setvaltag(tagdata, "{索引号}", Convert.ToString(indexdoor));
                        rtn = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                        if (!rtn && "下载加权白名单" == cmd)
                        {
                            //兼容不同版本
                            cmd = "下载白名单";
                            rtn = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                        }
                        success = success && rtn;
                        if (!rtn)
                        {
                            isconn = testConnect(target, dest);
                            continue;
                        }
                        indexdoor++;
                        dr["已下载"] = dndoors += "," + strd;
                    }
                    string[] bh = dstr.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    for (int b = 0; b < bh.Length; b++)
                    {
                        if (dndoors.Contains(bh[b]))
                            continue;
                        rtn = false;
                        break;
                    }
                    dr["是否完成"] = rtn;
                    if (!rtn) continue;
                    //ps["卡号"] = cardnum;
                    //ps["是否完成"] = rtn;
                    //ps["已下载"] = dstr;
                    //Monitor.Enter(query);
                    //this.query.ExecuteNonQuery("名单下载标志更新", ps, ps, ps);
                    //Monitor.PulseAll(query);
                    //Monitor.Exit(query);
                    //if (sleep > 0) Thread.Sleep(sleep);
                }//for (int i = 0; isconn && i < tab.Rows.Count; i++)
                if (d > 0 && ("进出口" == devtype || "出入口" == devtype))
                    break;
            }//for (int id = 0; id < 4; id++)
            CommiManager.GlobalManager.RemoveCommand(dest, cmdP);
            Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "设备(" + addrst + ") 共下载白名单:" + Convert.ToString(indexdoor - 1));
            myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "设备(" + addrst + ") 共下载白名单:" + Convert.ToString(indexdoor - 1));
            if (success)
            {
                Monitor.Enter(query);
                this.query.ExecuteNonQuery("设备黑白名单标志更新", ps, ps, ps);
                Monitor.PulseAll(query);
                Monitor.Exit(query);
            }
            else if (null != tab && tab.Rows.Count > 0)
            {
                //下载不成功时,分别更新黑白名单标志
                try
                {
                    Monitor.Enter(query);
                    this.query.BeginTransaction();
                    foreach (DataRow dr in tab.Rows)
                    {
                        if (null == dr) continue;
                        if (DataRowState.Modified != dr.RowState)
                            continue;
                        string cardnum = Convert.ToString(dr["卡号"]);
                        ps["状态"] = "白";
                        ps["卡号"] = cardnum;
                        ps["已下载"] = Convert.ToString(dr["已下载"]);
                        ps["是否完成"] = true.Equals(dr["是否完成"]);
                        this.query.ExecuteNonQuery("名单下载标志更新", ps, ps, ps);
                    }
                    this.query.Commit();
                }
                finally
                {
                    Monitor.PulseAll(query);
                    Monitor.Exit(query);
                    this.query.Close();
                }
            }
            return success;
        }
Beispiel #15
0
        /// <summary>
        /// ͣ����
        /// </summary>
        /// <param name="tarsrv"></param>
        /// <param name="trans"></param>
        /// <param name="proxy"></param>
        /// <param name="dest"></param>
        /// <param name="cmdP"></param>
        /// <param name="tpl"></param>
        /// <param name="cmd"></param>
        /// <param name="tagdata"></param>
        /// <returns></returns>
        public string getParkResponse(CommiTarget tarsrv, CmdFileTrans trans, IPAddress proxy, CommiTarget dest, CmdProtocol cmdP, string tpl, string cmd, string tagdata)
        {
            if (null == tarsrv || null == proxy || null == dest || null == trans || null == cmdP)
                return "";
            if (string.IsNullOrEmpty(tpl) || string.IsNullOrEmpty(cmd) || string.IsNullOrEmpty(tagdata))
                return "";
            CommiManager mgr = CommiManager.GlobalManager;
            string msg = "";

            bool islocal = false;
            string addr = proxy.ToString();
            IPAddress[] locals = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress ip in locals)
                if (addr == ip.ToString())
                {
                    islocal = true;
                    break;
                }
            if ("127.0.0.1" == addr)
                islocal = true;
            //����ͨѶ��Ŀ���Ǵ����������ֱ��ͨѶ
            if (islocal || CommiType.SerialPort != dest.ProtocolType)
            {
                if (null == cmdP.EventWh)
                    cmdP.EventWh = new ManualResetEvent(false);
                for (int i = 0; i < 3; i++)
                {
                    cmdP.setCommand(tpl, cmd, tagdata);
                    cmdP.ResetState();
                    mgr.SendCommand(dest, cmdP);
                    msg = "";
                    if (cmdP.EventWh.WaitOne(800, false))
                        msg = cmdP.ResponseFormat;
                    if ("true" == basefun.valtag(msg, "Success"))
                        break;
                    if (!string.IsNullOrEmpty(basefun.valtag(msg, "{״̬}")))
                        break;
                }
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    cmdP.setCommand(tpl, cmd, tagdata);
                    byte[] data = cmdP.getCommand();
                    trans.CommiTrans(proxy, dest, tpl, cmd, ref data);
                    trans.ResetState();
                    mgr.SendCommand(tarsrv, trans);
                    //ͬ��ͨѶ�ȴ�ʱ��1.5��
                    if (trans.EventWh.WaitOne(1500, false))
                        data = trans.FileContext;
                    msg = cmdP.FormatResponse(data);
                    if ("true" == basefun.valtag(msg, "Success"))
                        break;
                    if (!string.IsNullOrEmpty(basefun.valtag(msg, "{״̬}")))
                        break;
                }
            }
            if ("true" != basefun.valtag(msg, "Success"))
            {
                NameValueCollection attr = new NameValueCollection();
                attr["��"] = tpl;
                attr["����"] = tagdata + "\r\n" + cmd;
                ServiceTool.LogMessage(msg, attr, EventLogEntryType.Error);
                return msg;
            }
            return msg;
        }
        /// <summary>
        /// 停车场设备初始化和下载参数,更新黑白名单
        /// </summary>
        /// <param name="tarsrv">中转服务器</param>
        /// <param name="trans">传输指令</param>
        /// <param name="proxy">设备通讯代理电脑IP地址</param>
        /// <param name="dest">目标设备</param>
        /// <param name="drdevice">设备信息记录行</param>
        /// <param name="attrcmd">执行指令</param>
        /// <returns>返回通讯下载参数是否成功</returns>
        private bool commiDevicePark(CommiTarget tarsrv, CmdFileTrans trans, IPAddress proxy, CommiTarget dest, DataRow drdevice, string attrcmd)
        {
            if (null == tarsrv || null == proxy || null == dest || null == trans || null == drdevice || string.IsNullOrEmpty(attrcmd))
                return true;
            CmdProtocol cmdP = new CmdProtocol(false);
            this.setTimeout(cmdP);
            string devID = Convert.ToString(drdevice["ID"]);
            NameObjectList ps = new NameObjectList();
            ps["设备ID"] = devID;
            bool success = false;

            //系统时间
            string tpl = "停车场";
            string valst = Convert.ToString(drdevice["站址"]);
            Monitor.Enter(query);
            DateTime dtsystem = Convert.ToDateTime(this.query.ExecuteScalar("系统时间", ps));
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            string cmdstr = ",格式化,初始化ID白名单,初始化黑名单,加载系统时间,下载控制参数,";
            string[] cmds = attrcmd.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < cmds.Length; i++)
            {
                if (cmdstr.IndexOf("," + cmds[i] + ",") < 0)
                    continue;
                string tagdata = "@设备地址=" + valst;
                if ("下载控制参数" == cmds[i])
                {
                    Monitor.Enter(query);
                    DataTable tabctrlpm = this.query.getTable("设备控制参数", ps);
                    Monitor.PulseAll(query);
                    Monitor.Exit(query);
                    if (null == tabctrlpm || tabctrlpm.Rows.Count < 1)
                        continue;
                    tagdata = this.getctrlpm(tabctrlpm.Rows[0], valst);
                }
                else if ("加载系统时间" == cmds[i])
                {
                    tagdata = basefun.setvaltag(tagdata, "{系统时间}", dtsystem.ToString("yyyy-MM-dd HH:mm:ss"));
                }
                success = this.sendCommand(tarsrv, trans, proxy, dest, cmdP, tpl, cmds[i], tagdata);
                if (!success) return false;
                //格式化时设备有2.5s不应期
                if ("格式化" == cmds[i])
                    System.Threading.Thread.Sleep(3500);
            }

            //建立传输指令参数实例
            TransArg arg = new TransArg();
            arg.trans = trans;
            arg.target = tarsrv;
            arg.proxy = proxy;
            arg.dest = dest;
            arg.devID = devID;
            arg.addrst = Convert.ToString(drdevice["站址"]);
            arg.attrCmdtag = attrcmd;

            //下载计费标准
            success = this.downPayRule(arg);
            if (!success) return false;
            //更新下载日期
            Monitor.Enter(query);
            this.query.ExecuteNonQuery("设备下载标志更新", ps, ps, ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            //重置黑白名单
            if (attrcmd.IndexOf("|格式化|") > -1 || attrcmd.IndexOf("|初始化ID白名单|") > -1 || attrcmd.IndexOf("|初始化黑名单|") > -1)
            {
                Monitor.Enter(query);
                this.query.ExecuteNonQuery("重置设备名单", ps, ps, ps);
                Monitor.PulseAll(query);
                Monitor.Exit(query);
            }
            success = this.downparkCardList(arg);
            //设备蜂鸣提示
            string tag = "@设备地址=" + valst;
            this.sendCommand(tarsrv, trans, proxy, dest, cmdP, tpl, "蜂鸣", tag);
            return success;
        }
Beispiel #17
0
        /// <summary>
        /// �����豸��ʼ�������ز���,���ºڰ�����
        /// </summary>
        /// <param name="tarsrv">��ת������</param>
        /// <param name="trans">����ָ��</param>
        /// <param name="proxy">�豸ͨѶ�������IP��ַ</param>
        /// <param name="dest">Ŀ���豸</param>
        /// <param name="drdevice">�豸��Ϣ��¼��</param>
        /// <param name="attrcmd">ִ��ָ��</param>
        /// <returns>����ͨѶ���ز����Ƿ�ɹ�</returns>
        private bool commiDeviceEatery(CommiTarget tarsrv, CmdFileTrans trans, IPAddress proxy, CommiTarget dest, DataRow drdevice, string attrcmd)
        {
            if (null == tarsrv || null == proxy || null == dest || null == trans || null == drdevice || string.IsNullOrEmpty(attrcmd))
                return true;
            CmdProtocol cmdP = new CmdProtocol(false);
            string devID = Convert.ToString(drdevice["ID"]);
            //��������ָ�����ʵ��
            TransArg arg = new TransArg();
            arg.trans = trans;
            arg.target = tarsrv;
            arg.proxy = proxy;
            arg.dest = dest;
            arg.devID = devID;
            arg.addrst = Convert.ToString(drdevice["վַ"]);
            arg.attrCmdtag = attrcmd;

            NameObjectList ps = new NameObjectList();
            ps["�豸ID"] = devID;
            bool success = false;
            string tpl = "����";
            string valst = Convert.ToString(drdevice["վַ"]);
            //ϵͳʱ��
            DateTime dtsystem = Convert.ToDateTime(this.query.ExecuteScalar("ϵͳʱ��", ps));
            string cmdstr = ",��ʽ��,��ռ�¼,��ղ�������,��պ�����,���ʱ��,����ʱ��,����ʱ��,���ÿ��Ʋ���,";
            string[] cmds = attrcmd.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < cmds.Length; i++)
            {
                if (cmdstr.IndexOf("," + cmds[i] + ",") < 0)
                    continue;
                string tagdata = "@�豸��ַ=" + valst;
                if ("����ʱ��" == cmds[i])
                    tagdata = basefun.setvaltag(tagdata, "{����ʱ��}", dtsystem.ToString("yyyy-MM-dd HH:mm:ss"));
                if ("����ʱ��" == cmds[i])
                {
                    success = this.downeaterytime(arg);
                    if (!success) return false;
                    continue;
                }
                if ("���ÿ��Ʋ���" == cmds[i])
                {
                    success = this.downeateryctrlpm(arg);
                    if (!success) return false;
                    continue;
                }
                success = this.sendCommand(tarsrv, trans, proxy, dest, cmdP, tpl, cmds[i], tagdata);
                //��ʽ��ʱ�豸��2.5s��Ӧ��
                if ("��ʽ��" == cmds[i])
                {
                    System.Threading.Thread.Sleep(3500);
                    continue;
                }
                if (!success) return false;
            }
            //������������
            this.query.ExecuteNonQuery("�豸���ر�־����", ps, ps, ps);

            //���úڰ�����
            if (attrcmd.IndexOf("|��ʽ��|") > -1 || attrcmd.IndexOf("|��հ�����|") > -1)
                this.query.ExecuteNonQuery("�����豸����", ps, ps, ps);
            success = this.downeateryCardList(arg);
            if (!success) return false;
            //�������ѿ�û�н��յ��IJ�����������δ���صIJ���
            success = this.downeaterySubsidy(arg);
            return success;
        }
        /// <summary>
        /// 更新设备的黑白清名单,执行成功后更新黑白名单下载日期
        /// </summary>
        /// <param name="arg">传输指令参数</param>
        private bool downparkCardList(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            CmdProtocol cmdP = new CmdProtocol(false);
            this.setTimeout(cmdP);
            cmdP.TimeSendInv = new TimeSpan(1, 0, 0);
            NameValueCollection data = new NameValueCollection();
            NameObjectList ps = new NameObjectList();
            ps["设备ID"] = devID;
            //同步通讯等待时间15秒
            bool success = true;
            Monitor.Enter(query);
            DataTable tab = this.query.getTable("设备清名单", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            string tpl = "停车场", cmd = "删除ID白名单";
            string tagdata = "@设备地址=" + addrst;
            if (string.IsNullOrEmpty(attrcmd) || attrcmd.IndexOf("|删除ID白名单|") > -1)
                for (int i = 0; i < tab.Rows.Count; i++)
                {
                    DataRow dr = tab.Rows[i];
                    tagdata = basefun.setvaltag(tagdata, "{卡号}", Convert.ToString(dr["卡号"]));
                    bool rtn = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                    success = success && rtn;
                    if (!rtn)
                    {
                        if (!testConnect(target, dest))
                        {
                            CommiManager.GlobalManager.RemoveCommand(dest, cmdP);
                            return false;
                        }
                        continue;
                    }
                    ps["状态"] = "清";
                    ps["卡号"] = Convert.ToString(dr["卡号"]);
                    Monitor.Enter(query);
                    this.query.ExecuteNonQuery("名单下载标志更新", ps, ps, ps);
                    Monitor.PulseAll(query);
                    Monitor.Exit(query);
                }
            Monitor.Enter(query);
            tab = this.query.getTable("设备白名单", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            cmd = "下载ID白名单";
            if (string.IsNullOrEmpty(attrcmd) || attrcmd.IndexOf("|下载ID白名单|") > -1)
                for (int i = 0; i < tab.Rows.Count; i++)
                {
                    DataRow dr = tab.Rows[i];
                    string[,] colmap ={ { "{卡号}", "卡号" }, { "{卡类}", "卡型" }, { "{车型}", "车型" }, { "{时段}", "时段" }, { "{有效日期}", "有效日期" } };
                    for (int j = 0; j < colmap.GetLength(0); j++)
                        tagdata = basefun.setvaltag(tagdata, colmap[j, 0], Convert.ToString(dr[colmap[j, 1]]));
                    bool rtn = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                    success = success && rtn;
                    if (!rtn)
                    {
                        if (!testConnect(target, dest))
                        {
                            CommiManager.GlobalManager.RemoveCommand(dest, cmdP);
                            return false;
                        }
                        continue;
                    }
                    ps["状态"] = "白";
                    ps["卡号"] = Convert.ToString(dr["卡号"]);
                    Monitor.Enter(query);
                    this.query.ExecuteNonQuery("名单下载标志更新", ps, ps, ps);
                    Monitor.PulseAll(query);
                    Monitor.Exit(query);
                }
            CommiManager.GlobalManager.RemoveCommand(dest, cmdP);
            return success;
        }
Beispiel #19
0
        /// <summary>
        /// �����豸�ĺڰ�������,ִ�гɹ�����ºڰ�������������
        /// </summary>
        /// <param name="arg">����ָ�����</param>
        private bool downdoorCardList(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            if (string.IsNullOrEmpty(attrcmd) || (attrcmd.IndexOf("|ɾ��������|") < 0 && attrcmd.IndexOf("|���ذ�����|") < 0))
                return true;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            NameValueCollection data = new NameValueCollection();
            NameObjectList ps = new NameObjectList();
            ps["�豸ID"] = devID;
            //ͬ��ͨѶ�ȴ�ʱ��15��
            bool success = true, isconn = true;
            string cardsdel = "", cardswh = "";
            DataTable tab = this.query.getTable("�Ž�������", ps);
            string tpl = "�Ž�", cmd = "ɾ��������";
            string tagdata = "@�豸��ַ=" + addrst;
            if (string.IsNullOrEmpty(attrcmd) || attrcmd.IndexOf("|ɾ��������|") > -1)
                for (int i = 0; isconn && i < tab.Rows.Count; i++)
                {
                    DataRow dr = tab.Rows[i];
                    string cardnum = Convert.ToString(dr["����"]);
                    tagdata = basefun.setvaltag(tagdata, "{����}", cardnum);
                    //�����ֶα����˶�Ӧ�ź�(��������)
                    string dstr = Convert.ToString(dr["��Ȩ"]);
                    if (string.IsNullOrEmpty(dstr))
                        continue;
                    string[] bh = dstr.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    bool rtn = true;
                    for (int b = 0; b < bh.Length; b++)
                    {
                        //�ź���1��ʼ
                        bh[b] = Convert.ToString(Convert.ToInt32(bh[b]) + 1);
                        tagdata = basefun.setvaltag(tagdata, "{�ź�}", bh[b]);
                        rtn = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                        if (!rtn) break;
                    }
                    success = success && rtn;
                    if (!rtn)
                    {
                        isconn = testConnect(target, dest);
                        continue;
                    }
                    cardsdel += "," + cardnum;
                    //ps["״̬"] = "��";
                    //ps["����"] = Convert.ToString(dr["����"]);
                    //this.query.ExecuteNonQuery("�������ر�־����", ps, ps, ps);
                }
            tab = this.query.getTable("�Ž�������", ps);
            cmd = "���ذ�����";
            if (string.IsNullOrEmpty(attrcmd) || attrcmd.IndexOf("|���ذ�����|") > -1)
                for (int i = 0; isconn && i < tab.Rows.Count; i++)
                {
                    DataRow dr = tab.Rows[i];
                    string cardnum = Convert.ToString(dr["����"]);
                    string[,] colmap ={ { "{����}", "����" }, { "{��ʼ����}", "��������" }, { "{��ֹ����}", "��Ч����" }, { "{ʱ��}", "ʱ��" },
                                        { "{����}", "����" }, { "{���}", "�û����" } };
                    for (int j = 0; j < colmap.GetLength(0); j++)
                        tagdata = basefun.setvaltag(tagdata, colmap[j, 0], Convert.ToString(dr[colmap[j, 1]]));
                    tagdata = basefun.setvaltag(tagdata, "{����}", "FF");
                    ps["״̬"] = "��";
                    ps["����"] = cardnum;

                    cmd = "���ذ�����";
                    bool rtn = true;
                    if ("���ڻ�" == Convert.ToString(dr["����������"]))
                    {
                        cmd = "���ؿ�������";
                        rtn = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                        success = success && rtn;
                        if (!rtn)
                        {
                            isconn = testConnect(target, dest);
                            continue;
                        }
                        cardswh += "," + cardnum;
                        continue;
                        //this.query.ExecuteNonQuery("�������ر�־����", ps, ps, ps);
                        //continue;
                    }
                    //{ "{�ź�}", "��������" },
                    string dstr = Convert.ToString(dr["��Ȩ"]);
                    if (string.IsNullOrEmpty(dstr))
                        continue;
                    string[] bh = dstr.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    for (int b = 0; b < bh.Length; b++)
                    {
                        //�ź���1��ʼ
                        bh[b] = Convert.ToString(Convert.ToInt32(bh[b]) + 1);
                        tagdata = basefun.setvaltag(tagdata, "{�ź�}", bh[b]);
                        rtn = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                        if (!rtn) break;
                    }
                    success = success && rtn;
                    if (!rtn)
                    {
                        isconn = testConnect(target, dest);
                        continue;
                    }
                    cardswh += "," + cardnum;
                    //this.query.ExecuteNonQuery("�������ر�־����", ps, ps, ps);
                }
            if (success)
            {
                ps["�豸ID"] = devID;
                this.query.ExecuteNonQuery("�豸�ڰ�������־����", ps, ps, ps);
            }
            else
            {
                //���ز��ɹ�ʱ���ֱ���ºڰ�������־
                string[] cards = cardsdel.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string c in cards)
                {
                    ps["״̬"] = "��";
                    ps["����"] = c;
                    this.query.ExecuteNonQuery("�������ر�־����", ps, ps, ps);
                }
                cards = cardswh.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string c in cards)
                {
                    ps["״̬"] = "��";
                    ps["����"] = c;
                    this.query.ExecuteNonQuery("�������ر�־����", ps, ps, ps);
                }
            }
            return success;
        }
        /// <summary>
        /// 更新设备的黑白清名单,执行成功后更新黑白名单下载日期
        /// </summary>
        /// <param name="arg">传输指令参数</param>
        private bool downPayRule(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            CmdProtocol cmdP = new CmdProtocol(false);
            this.setTimeout(cmdP);
            NameObjectList ps = new NameObjectList();
            ps["设备ID"] = devID;
            bool success = false;

            string tpl = "停车场";
            Monitor.Enter(query);
            DataTable tabpay = this.query.getTable("收费标准列表", ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            string[,] dbpay ={ { "消费方式1", "收费标准1", "1", "下载收费标准1" }, { "消费方式2", "收费标准2", "2", "下载收费标准2" }, { "消费方式3", "收费标准3", "3", "下载收费标准3" },
                               { "消费方式4", "收费标准4", "4", "下载收费标准4" }, { "消费方式5", "", "5", "下载收费标准5" }, { "消费方式6", "收费标准6", "6", "下载收费标准6" } };
            int ct = 0;
            if (null != tabpay && tabpay.Rows.Count > 0)
                ct = tabpay.Rows.Count;
            for (int j = 0; j < ct; j++)
            {
                DataRow drpay = tabpay.Rows[j];
                string ncar = Convert.ToString(drpay["车型"]);
                ps["车型"] = ncar;
                string ntype = Convert.ToString(drpay["计费方式"]);
                int k = -1;
                for (int m = 0; m < dbpay.GetLength(0); m++)
                    if (ntype == dbpay[m, 0])
                    {
                        k = m; break;
                    }
                if (k < 0) continue;
                //指令过滤则忽略执行
                if (!string.IsNullOrEmpty(attrcmd) && attrcmd.IndexOf("|" + dbpay[k, 3] + "|") < 0)
                    continue;
                Monitor.Enter(query);
                DataTable tabitem = this.query.getTable(dbpay[k, 1], ps);
                Monitor.PulseAll(query);
                Monitor.Exit(query);
                if (null == tabitem || tabitem.Rows.Count < 1)
                    continue;
                string tag = "";
                switch (k)
                {
                    case 0: tag = getpaypm1(drpay, tabitem); break;
                    case 1: tag = getpaypm2(drpay, tabitem); break;
                    case 2: tag = getpaypm3(drpay, tabitem); break;
                    case 3: tag = getpaypm4(drpay, tabitem); break;
                    case 4: tag = getpaypm5(drpay, tabitem); break;
                    case 5: tag = getpaypm6(drpay, tabitem); break;
                }
                if (string.IsNullOrEmpty(tag))
                    continue;
                tag = basefun.setvaltag(tag, "设备地址", addrst);
                tag = basefun.setvaltag(tag, "{车型代码}", ncar);
                tag = basefun.setvaltag(tag, "{方式代码}", dbpay[k, 2]);
                //通讯下载收费参数
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, dbpay[k, 3], tag);
                if (!success) return false;
            }
            return true;
        }
Beispiel #21
0
        /// <summary>
        /// �����豸�ĺڰ�������,ִ�гɹ�����ºڰ�������������
        /// </summary>
        /// <param name="arg">����ָ�����</param>
        private bool downeateryCardList(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            NameValueCollection data = new NameValueCollection();
            NameObjectList ps = new NameObjectList();
            ps["�豸ID"] = devID;
            //ͬ��ͨѶ�ȴ�ʱ��15��
            bool success = true;
            DataTable tab = this.query.getTable("����������", ps);
            string tpl = "����", cmd = "ɾ��������";
            string tagdata = "@�豸��ַ=" + addrst;
            if (string.IsNullOrEmpty(attrcmd) || attrcmd.IndexOf("|ɾ��������|") > -1)
                for (int i = 0; i < tab.Rows.Count; i++)
                {
                    DataRow dr = tab.Rows[i];
                    tagdata = basefun.setvaltag(tagdata, "{����}", Convert.ToString(dr["����"]));
                    bool rtn = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                    success = success && rtn;
                    if (!rtn)
                    {
                        if (testConnect(target, dest))
                            return false;
                        continue;
                    }
                    ps["״̬"] = "��";
                    ps["����"] = Convert.ToString(dr["����"]);
                    this.query.ExecuteNonQuery("�������ر�־����", ps, ps, ps);
                }
            tab = this.query.getTable("���Ѻ�����", ps);
            cmd = "���غ�����";
            if (string.IsNullOrEmpty(attrcmd) || attrcmd.IndexOf("|���غ�����|") > -1)
                for (int i = 0; i < tab.Rows.Count; i++)
                {
                    DataRow dr = tab.Rows[i];
                    tagdata = basefun.setvaltag(tagdata, "{����}", Convert.ToString(dr["����"]));
                    bool rtn = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                    success = success && rtn;
                    if (!rtn)
                    {
                        if (testConnect(target, dest))
                            return false;
                        continue;
                    }
                    ps["״̬"] = "��";
                    ps["����"] = Convert.ToString(dr["����"]);
                    this.query.ExecuteNonQuery("�������ر�־����", ps, ps, ps);
                }
            return success;
        }
Beispiel #22
0
        /// <summary>
        /// ���ؿ��Ʋ���
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private bool downeateryctrlpm(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            NameObjectList ps = new NameObjectList();
            ps["�豸ID"] = devID;
            bool success = false;
            //��ղ˵�
            string tpl = "����", cmd = "������Ѳ���";
            string tagdata = "@�豸��ַ=" + addrst;
            success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
            if (!success) return false;
            //���ؿ��Ʋ���
            DataTable tab = this.query.getTable("���ѿ��Ʋ���", ps);
            if (null == tab || tab.Rows.Count < 1)
                return false;
            DataRow drctrl = tab.Rows[0];
            string[,] colmap ={ { "{ͨ������}", "ͨѶ����" }, { "{ϵͳ����}", "ϵͳ����" }, { "{�û�����}", "�û�����" }, { "{��Ƭ����}", "��Ƭ����" },
                    { "{��¼����}", "�ռ�澯" }, { "{����������}", "����������" }, { "{ȡ����������}", "ȡ����������" },
                    { "{���������޶�}", "�����޶�" }, { "{��������}", "���޶�" }, { "{������ʱ}", "������ʱ" }, { "{��ʾ��ʱ}", "��ʾ��ʱ" },
                    { "{��������}.{��¼�����������}", "�������" }, { "{��������}.{ʱ������}", "ʱ������" }, { "{��������}.{����Աƾ��ȡ���ϱʽ���}", "ƾ��ȡ������" },
                    { "{��������}.{����Աֱ��ȡ���ϱʽ���}", "ֱ��ȡ������" }, { "{��������}.{����������ò���}", "�����ò���" },
                    { "{��������}.{��Ȩ���ɳ�ʼ���豸}", "�ɳ�ʼ��" },
                    { "{���ѿ���}.{����ֱ�ӿ۷�}", "����ֱ�ӿ۷�" }, { "{���ѿ���}.{��������}", "��������" }, { "{���ѿ���}.{��ӡ��¼}", "��ӡ��¼" },
                    { "{���ѿ���}.{���ֽ�����}", "���ֽ�����" }, { "{���ѿ���}.{����������}", "����������" }, { "{���ѿ���}.{�ɳ���}", "�ɳ���" },
                    { "{���ѿ���}.{ƾ������}", "ƾ������" },
                    { "{�����޶�}", "�����޶�" }, { "{������ʽ}", "������ʽ" }, { "{ʳ�ñ��}", "���" } };
            for (int i = 0; i < colmap.GetLength(0); i++)
                tagdata = basefun.setvaltag(tagdata, colmap[i, 0], Convert.ToString(drctrl[colmap[i, 1]]));
            cmd = "���ÿ��Ʋ���";
            success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
            if (!success) return false;
            //���ز˵�
            tagdata = "@�豸��ַ=" + addrst;
            tab = this.query.getTable("���Ѽ۸����", ps);
            colmap = new string[,] { { "{����}", "���" }, { "{�۸�}", "�۸�" } };
            cmd = "�������Ѳ���";
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow drmenu = tab.Rows[i];
                for (int c = 0; c < colmap.GetLength(0); c++)
                {
                    string val = Convert.ToString(drmenu[colmap[c, 1]]);
                    tagdata = basefun.setvaltag(tagdata, colmap[c, 0], val);
                }
                success = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tagdata);
                if (!success) return false;
            }
            return true;
        }
Beispiel #23
0
 /// <summary>
 /// 接收传递通讯
 ///     包含参数: len,dir=request/response,cmd=TransFile.trans,source,target,
 ///               CommiType,addr=ipaddr/COM1,port,baudRate,parity,dataBits,stopBits
 /// </summary>
 /// <param name="sender">触发事件的实例</param>
 /// <param name="e">响应参数</param>
 private static void onCommiTransHandle(object sender, ResponseEventArgs e)
 {
     CmdFileTrans trans = sender as CmdFileTrans;
     if (null == trans || null == e || null == e.Target)
         return;
     NameValueCollection ps = trans.FileHeader;
     byte[] data = trans.FileContext;
     if ("TransFile.trans" != ps["cmd"] || "request" != ps["dir"])
         return;
     if (string.IsNullOrEmpty(ps["CommiType"]) || string.IsNullOrEmpty(ps["addr"]))
         return;
     CommiType commitype = CommiType.SerialPort;
     string addr = ps["addr"];
     int port = -1;
     //检测地址
     try
     {
         addr = addr.ToUpper();
         if (!addr.StartsWith("COM"))
             commitype = (CommiType)Enum.Parse(typeof(CommiType), ps["CommiType"], true);
         if (!string.IsNullOrEmpty(ps["port"]))
             port = Convert.ToInt32(ps["port"]);
     }
     catch { return; }
     //检测通讯参数
     if (CommiType.SerialPort != commitype && port < 0)
         return;
     if (CommiType.SerialPort == commitype &&
         (string.IsNullOrEmpty(ps["baudRate"]) || string.IsNullOrEmpty(ps["parity"])
             || string.IsNullOrEmpty(ps["dataBits"]) || string.IsNullOrEmpty(ps["stopBits"])))
         return;
     //创建通讯目标
     CommiTarget target = null;
     if (CommiType.SerialPort != commitype)
         target = new CommiTarget(addr, port, commitype);
     else
         try
         {
             int baudRate = Convert.ToInt32(ps["baudRate"]);
             Parity parity = (Parity)Enum.Parse(typeof(Parity), ps["parity"], true);
             int databits = Convert.ToInt16(ps["dataBits"]);
             StopBits stopBits = (StopBits)Enum.Parse(typeof(StopBits), ps["stopBits"], true);
             target = new CommiTarget(addr, baudRate, parity, databits, stopBits);
         }
         catch { return; }
     target.setProtocol(Protocol.PTLCard);
     switch (ps["dtpl"])
     {
         case "停车场":
             target.setProtocol(Protocol.PTLPark); break;
         case "门禁":
             target.setProtocol(Protocol.PTLDoor); break;
         case "消费":
             target.setProtocol(Protocol.PTLEatery); break;
     }
     //执行传递的指令
     CmdProtocol cmd = new CmdProtocol(false);
     cmd.setCommand(data);
     ps["dir"] = "response";
     CommiManager.GlobalManager.SendCommand(target, cmd);
     if (!cmd.EventWh.WaitOne(800, false))
         ps["msg"] = "目标通讯超时失败";
     data = cmd.ResponseData;
     ps["len"] = data.LongLength.ToString();
     byte[] fh = SvrFileTrans.ParseInfo(ps);
     byte[] response = new byte[fh.LongLength + data.LongLength];
     Array.Copy(fh, response, fh.LongLength);
     if (data.Length > 0)
         Array.Copy(data, 0, response, fh.LongLength, data.LongLength);
     cmd.setCommand(response);
     CommiManager.GlobalManager.SendCommand(e.Target, cmd, true);
 }
Beispiel #24
0
        /// <summary>
        /// ���ղ�����û�����صIJ���,��ղ�����,�ϲ���δ���ز���һ������
        /// </summary>
        /// <param name="arg">����ָ�����</param>
        /// <returns></returns>
        private bool downeaterySubsidy(TransArg arg)
        {
            CmdFileTrans trans = arg.trans;
            CommiTarget target = arg.target;
            IPAddress proxy = arg.proxy;
            CommiTarget dest = arg.dest;
            string devID = arg.devID;
            string addrst = arg.addrst;
            string attrcmd = arg.attrCmdtag;

            if (null == trans || null == proxy || null == dest || string.IsNullOrEmpty(devID) || string.IsNullOrEmpty(addrst))
                return false;
            //�ж��Ƿ����ز���
            if (string.IsNullOrEmpty(attrcmd) || attrcmd.IndexOf("|���ز�������|") < 0)
                return true;
            CommiManager mgr = CommiManager.GlobalManager;
            CmdProtocol cmdP = new CmdProtocol(false);
            NameObjectList ps = new NameObjectList();
            ps["�豸ID"] = devID;
            string tpl = "����", cmd = "ȡ��ǰ������¼";
            string tag = "@�豸��ַ=" + addrst;
            //������ȡ������¼
            string msg = this.getResponse(target, trans, proxy, dest, cmdP, tpl, cmd, tag);
            if (string.IsNullOrEmpty(msg))
                return false;
            string cardnum = basefun.valtag(msg, "{����}");
            cmd = "ȡ��һ��������¼";
            while (!string.IsNullOrEmpty(cardnum) && "16777215" != cardnum && "0" != cardnum)
            {
                NameObjectList pm = createParam(msg);
                bool rtn = this.query.ExecuteNonQuery("���ѽ��ղ���", pm, pm, pm);
                if (!rtn) return false;
                msg = this.getResponse(target, trans, proxy, dest, cmdP, tpl, cmd, tag);
                cardnum = basefun.valtag(msg, "{����}");
            }
            //��ȡû�н��յIJ�����¼�����պϲ���������¼
            DataTable tab = this.query.getTable("���ѻ��ղ���", ps);
            if (null == tab) return false;
            cmd = "��ѯ�û��������";
            string[,] cols = { { "����", "{�û����}" }, { "��Ƭ���к�", "{��Ƭ�������}" } };
            string[,] pn = { { "����", "{�û����}" }, { "��Ƭ���к�", "{��Ƭ�������}" }, { "�������", "{�������}" }, { "����״̬", "{����״̬}" } };
            bool success = true;
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow dr = tab.Rows[i];
                for (int c = 0; c < cols.GetLength(0); c++)
                    tag = basefun.setvaltag(tag, cols[c, 1], Convert.ToString(dr[cols[c, 0]]));
                msg = this.getResponse(target, trans, proxy, dest, cmdP, tpl, cmd, tag);
                if (string.IsNullOrEmpty(msg))
                {
                    success = false;
                    break;
                }
                if ("true" != basefun.valtag(msg, "Success"))
                    continue;
                NameObjectList pm = new NameObjectList();
                for (int p = 0; p < pn.GetLength(0); p++)
                    pm[pn[p, 0]] = basefun.valtag(msg, pn[p, 1]);
                this.query.ExecuteNonQuery("���ѻ��ղ���", pm, pm, pm);
            }
            if (!success) return false;
            tab = this.query.getTable("�������ز���", ps);
            cmd = "���ز�������";
            tag = "@�豸��ַ=" + addrst;
            cols = new string[,] { { "����", "{�û����}" }, { "��Ƭ���к�", "{��Ƭ�������}" }, { "������ֵ", "{�������}" } };
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow dr = tab.Rows[i];
                for (int c = 0; c < cols.GetLength(0); c++)
                    tag = basefun.setvaltag(tag, cols[c, 1], Convert.ToString(dr[cols[c, 0]]));
                bool suc = this.sendCommand(target, trans, proxy, dest, cmdP, tpl, cmd, tag);
                if (!suc)
                {
                    success = suc;
                    continue;
                }
                ps["����"] = Convert.ToString(dr["����"]);
                this.query.ExecuteNonQuery("�������ز���", ps, ps, ps);
            }
            return success;
        }
Beispiel #25
0
        /// <summary>
        /// 接收传递通讯
        ///     包含参数: len,dir=request/response,cmd=TransFile.trans,source,target,
        ///               CommiType,addr=ipaddr/COM1,port,baudRate,parity,dataBits,stopBits
        /// </summary>
        /// <param name="sender">触发事件的实例</param>
        /// <param name="e">响应参数</param>
        private static void onCommiTransHandle(object sender, ResponseEventArgs e)
        {
            CmdFileTrans trans = sender as CmdFileTrans;

            if (null == trans || null == e || null == e.Target)
            {
                return;
            }
            NameValueCollection ps = trans.FileHeader;

            byte[] data = trans.FileContext;
            if ("TransFile.trans" != ps["cmd"] || "request" != ps["dir"])
            {
                return;
            }
            if (string.IsNullOrEmpty(ps["CommiType"]) || string.IsNullOrEmpty(ps["addr"]))
            {
                return;
            }
            CommiType commitype = CommiType.SerialPort;
            string    addr      = ps["addr"];
            int       port      = -1;

            //检测地址
            try
            {
                addr = addr.ToUpper();
                if (!addr.StartsWith("COM"))
                {
                    commitype = (CommiType)Enum.Parse(typeof(CommiType), ps["CommiType"], true);
                }
                if (!string.IsNullOrEmpty(ps["port"]))
                {
                    port = Convert.ToInt32(ps["port"]);
                }
            }
            catch { return; }
            //检测通讯参数
            if (CommiType.SerialPort != commitype && port < 0)
            {
                return;
            }
            if (CommiType.SerialPort == commitype &&
                (string.IsNullOrEmpty(ps["baudRate"]) || string.IsNullOrEmpty(ps["parity"]) ||
                 string.IsNullOrEmpty(ps["dataBits"]) || string.IsNullOrEmpty(ps["stopBits"])))
            {
                return;
            }
            //创建通讯目标
            CommiTarget target = null;

            if (CommiType.SerialPort != commitype)
            {
                target = new CommiTarget(addr, port, commitype);
            }
            else
            {
                try
                {
                    int      baudRate = Convert.ToInt32(ps["baudRate"]);
                    Parity   parity   = (Parity)Enum.Parse(typeof(Parity), ps["parity"], true);
                    int      databits = Convert.ToInt16(ps["dataBits"]);
                    StopBits stopBits = (StopBits)Enum.Parse(typeof(StopBits), ps["stopBits"], true);
                    target = new CommiTarget(addr, baudRate, parity, databits, stopBits);
                }
                catch { return; }
            }
            target.setProtocol(Protocol.PTLCard);
            switch (ps["dtpl"])
            {
            case "停车场":
                target.setProtocol(Protocol.PTLPark); break;

            case "门禁":
                target.setProtocol(Protocol.PTLDoor); break;

            case "消费":
                target.setProtocol(Protocol.PTLEatery); break;
            }
            //执行传递的指令
            CmdProtocol cmd = new CmdProtocol(false);

            cmd.setCommand(data);
            ps["dir"] = "response";
            CommiManager.GlobalManager.SendCommand(target, cmd);
            if (!cmd.EventWh.WaitOne(800, false))
            {
                ps["msg"] = "目标通讯超时失败";
            }
            data      = cmd.ResponseData;
            ps["len"] = data.LongLength.ToString();
            byte[] fh       = SvrFileTrans.ParseInfo(ps);
            byte[] response = new byte[fh.LongLength + data.LongLength];
            Array.Copy(fh, response, fh.LongLength);
            if (data.Length > 0)
            {
                Array.Copy(data, 0, response, fh.LongLength, data.LongLength);
            }
            cmd.setCommand(response);
            CommiManager.GlobalManager.SendCommand(e.Target, cmd, true);
        }
        /// <summary>
        /// 门禁设备初始化和下载参数,更新黑白名单
        /// </summary>
        /// <param name="tarsrv">中转服务器</param>
        /// <param name="trans">传输指令</param>
        /// <param name="proxy">设备通讯代理电脑IP地址</param>
        /// <param name="dest">目标设备</param>
        /// <param name="drdevice">设备信息记录行</param>
        /// <param name="attrcmd">执行指令</param>
        /// <returns>返回通讯下载参数是否成功</returns>
        private bool commiDeviceDoor(CommiTarget tarsrv, CmdFileTrans trans, IPAddress proxy, CommiTarget dest, DataRow drdevice, string attrcmd)
        {
            string iskq = "";
            if (null == tarsrv || null == proxy || null == dest || null == trans || null == drdevice || string.IsNullOrEmpty(attrcmd))
                return true;

            CmdProtocol cmdP = new CmdProtocol(false);
            this.setTimeout(cmdP);
            string devID = Convert.ToString(drdevice["ID"]);
            //建立传输指令参数实例
            TransArg arg = new TransArg();
            arg.trans = trans;
            arg.target = tarsrv;
            arg.proxy = proxy;
            arg.dest = dest;
            arg.devID = devID;
            arg.addrst = Convert.ToString(drdevice["站址"]);
            arg.attrCmdtag = attrcmd;

            NameObjectList ps = new NameObjectList();
            ps["设备ID"] = devID;
            bool success = false;
            string tpl = "门禁";
            string valst = Convert.ToString(drdevice["站址"]);
            //系统时间
            Monitor.Enter(query);
            DateTime dtsystem = Convert.ToDateTime(this.query.ExecuteScalar("系统时间", ps));
            Monitor.PulseAll(query);
            Monitor.Exit(query);
            string cmdstr = ",格式化,清空记录,清空白名单,清空时段,设置时间,设置时段,设置控制参数,修改名单,";
            string[] cmds = attrcmd.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < cmds.Length; i++)
            {
                if (cmdstr.IndexOf("," + cmds[i] + ",") < 0)
                    continue;
                string tagdata = "@设备地址=" + valst;
                if ("设置时间" == cmds[i])
                    tagdata = basefun.setvaltag(tagdata, "{日期时间}", dtsystem.ToString("yyyy-MM-dd HH:mm:ss"));
                if ("设置时段" == cmds[i])
                {
                    Monitor.Enter(query);
                    DataTable tabtime = this.query.getTable("门禁时段", ps);
                    Monitor.PulseAll(query);
                    Monitor.Exit(query);
                    if (null == tabtime || tabtime.Rows.Count < 1)
                        continue;
                    foreach (DataRow dr in tabtime.Rows)
                    {
                        tagdata = this.getdoortime(dr);
                        tagdata = basefun.setvaltag(tagdata, "设备地址", valst);
                        success = this.sendCommand(tarsrv, trans, proxy, dest, cmdP, tpl, cmds[i], tagdata);
                        if (!success) return false;
                    }
                    continue;
                }
                if ("设置控制参数" == cmds[i])
                {
                    success = this.downdoorctrlpm(arg);
                    if (!success) return false;
                    continue;
                }
                success = this.sendCommand(tarsrv, trans, proxy, dest, cmdP, tpl, cmds[i], tagdata);
                //格式化时设备有2.5s不应期
                if ("格式化" == cmds[i])
                {
                    Monitor.Enter(query);
                    this.query.ExecuteNonQuery("门禁记录位置重置", ps, ps, ps);
                    Monitor.PulseAll(query);
                    Monitor.Exit(query);
                    System.Threading.Thread.Sleep(3500);
                    continue;
                }
                if (!success) return false;
                if ("清空记录" == cmds[i])
                {

                    Monitor.Enter(query);
                    this.query.ExecuteNonQuery("门禁记录位置重置", ps, ps, ps);
                    Monitor.PulseAll(query);
                    Monitor.Exit(query);
                }
                if ("清空白名单" == cmds[i])
                    System.Threading.Thread.Sleep(20000);
                if ("修改名单" == cmds[i])
                {

                    iskq = "修改名单";

                }

                myLog.WriteLine("当前指令   11111" + iskq);

            }
            //更新下载日期
            Monitor.Enter(query);
            this.query.ExecuteNonQuery("设备下载标志更新", ps, ps, ps);
            Monitor.PulseAll(query);
            Monitor.Exit(query);

            //重置黑白名单
            if (attrcmd.IndexOf("|格式化|") > -1 || attrcmd.IndexOf("|清空白名单|") > -1)
            {
                Monitor.Enter(query);
                this.query.ExecuteNonQuery("重置设备名单", ps, ps, ps);
                Monitor.PulseAll(query);
                Monitor.Exit(query);
            }



            success = this.downdoorCardList(arg, iskq);
            return success;
        }