Пример #1
0
        private void FrameYouSee_Load(object sender, EventArgs e)
        {
            cmb_Type.Items.Clear();
            cmbTiaojian.Items.Clear();
            cmbTiaojian.Enabled = false;

            Grid_seebaowen.AutoGenerateColumns      = false;
            Grid_seebaowen.AutoSizeRowsMode         = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
            Grid_seebaowen.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
            Grid_seebaowen.CellBorderStyle          = DataGridViewCellBorderStyle.Single;
            Grid_seebaowen.GridColor = SystemColors.ActiveBorder;
            tableLayoutPanel1.Top    = 5;


            txt_time1.Text = "例如:2008-08-08";
            txt_time2.Text = "例如:2008-09-08";

            cmb_Type.Items.Add("全部");
            cmb_Type.Items.Add("控制");
            cmb_Type.Items.Add("端口号");
            cmb_Type.Items.Add("排除端口");

            CLDC_DataCore.DataBase.DbHelperOleDb.connectionString = strPath;

            Strsql = "select top 25 * from FrameLog order by chrSTime desc";
            dr     = CLDC_DataCore.DataBase.DbHelperOleDb.ExecuteReader(Strsql);
            List <CLDC_DataCore.Model.LogModel.LogFrameInfo> BaowenList = new List <CLDC_DataCore.Model.LogModel.LogFrameInfo>();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    CLDC_DataCore.Model.LogModel.LogFrameInfo see = new CLDC_DataCore.Model.LogModel.LogFrameInfo();
                    see.chrPortNo    = dr["chrPortNo"].ToString();
                    see.chrEquipName = dr["chrEquipName"].ToString();
                    see.chrItemName  = dr["chrItemName"].ToString();
                    see.chrMessage   = dr["chrMessage"].ToString();
                    see.chrSFrame    = dr["chrSFrame"].ToString();
                    see.chrSMeaning  = dr["chrSMeaning"].ToString();
                    see.chrSTime     = dr["chrSTime"].ToString();
                    see.chrRFrame    = dr["chrRFrame"].ToString();
                    see.chrRMeaning  = dr["chrRMeaning"].ToString();
                    see.chrRTime     = dr["chrRTime"].ToString();
                    see.chrOther     = dr["chrOther"].ToString();
                    BaowenList.Add(see);
                }
                dr.Close();
            }

            Grid_seebaowen.DataSource = BaowenList;

            string colName = "";

            _XmlNode = clsXmlControl.LoadXml(Application.StartupPath + CLDC_DataCore.Const.Variable.CONST_SHOW_BWCOL, out _ErrorString);
            if (_XmlNode == null || _ErrorString != "")
            {
                _XmlNode = clsXmlControl.CreateXmlNode("ColsConfig");
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "端口号", "Name", "端口号", "ShowType", "1"));
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "设备名称", "Name", "设备名称", "ShowType", "1"));
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "项目名称", "Name", "项目名称", "ShowType", "1"));
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "操作消息", "Name", "操作消息", "ShowType", "1"));
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "发帧字符串", "Name", "发帧字符串", "ShowType", "1"));
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "发帧解析", "Name", "发帧解析", "ShowType", "1"));
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "发帧时间", "Name", "发帧时间", "ShowType", "1"));
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "收帧字符串", "Name", "收帧字符串", "ShowType", "1"));
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "收帧解析", "Name", "收帧解析", "ShowType", "1"));
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "收帧时间", "Name", "收帧时间", "ShowType", "1"));
                _XmlNode.AppendChild(clsXmlControl.CreateXmlNode("R", "ID", "备用", "Name", "备用", "ShowType", "1"));

                clsXmlControl.SaveXml(_XmlNode, Application.StartupPath + CLDC_DataCore.Const.Variable.CONST_SHOW_BWCOL);
            }
            else
            {
                for (int _j = 0; _j < _XmlNode.ChildNodes.Count; _j++)
                {
                    if (_XmlNode.ChildNodes[_j].Attributes[2].Value != "1")
                    {
                        colName = _XmlNode.ChildNodes[_j].Attributes[1].Value;
                        Grid_seebaowen.Columns[colName].Visible = false;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 发送并且接收返回数据
        /// </summary>
        /// <param name="sendPack">发送数据包</param>
        /// <param name="recvPack">接收数据包</param>
        /// <param name="PortName">仅用于报文日志,无实际端口作用</param>
        /// <returns></returns>
        public bool Send(Packet.SendPacket sendPack, Packet.RecvPacket recvPack, string PortName)
        {
            Monitor.Enter(objPackLock);
            //fjk
            CLDC_DataCore.Model.LogModel.LogFrameInfo Lf = new CLDC_DataCore.Model.LogModel.LogFrameInfo();
            Lf.strPortNo    = PortName;
            Lf.strEquipName = sendPack.ToString();
            Lf.strItemName  = "";
            Lf.strMessage   = sendPack.GetPacketName();

            byte[] vData = sendPack.GetPacketData();

            Lf.sendFrm              = new CLDC_DataCore.Struct.StSRFrame();
            Lf.sendFrm.Frame        = vData;
            Lf.sendFrm.FrameMeaning = sendPack.GetPacketResolving();
            Lf.sendFrm.FrameTime    = DateTime.Now;


            //

            //接到的数据存放在recvPack中,通过检测

            if (vData == null)
            {
                Lf.ResvFrm.Frame        = null;
                Lf.ResvFrm.FrameMeaning = "发送数据包为null";
                Lf.ResvFrm.FrameTime    = DateTime.Now;

                CLDC_DataCore.Const.GlobalUnit.FrameLog.WriteFrameLog(Lf);
                Monitor.Exit(objPackLock);
                return(false);
            }

            {
                //TODO:控制,带协议2018
            }

            Console.WriteLine("SendData:({0}) {1}", sendPack.GetPacketName(), BitConverter.ToString(vData, 0));
            if (!Send(ref vData, sendPack.IsNeedReturn, sendPack.WaiteTime()))
            {
                Lf.ResvFrm.Frame        = vData;
                Lf.ResvFrm.FrameMeaning = "发送失败";
                Lf.ResvFrm.FrameTime    = DateTime.Now;

                CLDC_DataCore.Const.GlobalUnit.FrameLog.WriteFrameLog(Lf);
                Monitor.Exit(objPackLock);
                return(false);
            }
            //if (!Send(ref vData, sendPack.IsNeedReturn, 1))
            //{

            //    Lf.ResvFrm.Frame = vData;
            //    Lf.ResvFrm.FrameMeaning = "发送失败";
            //    Lf.ResvFrm.FrameTime = DateTime.Now;

            //    CLDC_DataCore.Const.GlobalUnit.FrameLog.WriteFrameLog(Lf);
            //    Monitor.Exit(objPackLock);
            //    return false;
            //}
            if (sendPack.IsNeedReturn == false)//  && vData.Length < 1
            {
                Console.WriteLine("不需要回复数据");

                Lf.ResvFrm.Frame        = vData;
                Lf.ResvFrm.FrameMeaning = "不需要回复数据";
                Lf.ResvFrm.FrameTime    = DateTime.Now;

                CLDC_DataCore.Const.GlobalUnit.FrameLog.WriteFrameLog(Lf);
                Monitor.Exit(objPackLock);
                return(true);
            }

            if (sendPack.IsNeedReturn == true && (vData == null || vData.Length < 1))
            {
                Console.WriteLine("无回复数据");

                Lf.ResvFrm.Frame        = vData;
                Lf.ResvFrm.FrameMeaning = "无回复数据";
                Lf.ResvFrm.FrameTime    = DateTime.Now;

                CLDC_DataCore.Const.GlobalUnit.FrameLog.WriteFrameLog(Lf);
                Monitor.Exit(objPackLock);
                return(false);
            }
            if (sendPack.IsNeedReturn == true && recvPack == null)
            {
                Console.WriteLine("没有传入解析包");

                Lf.ResvFrm.Frame        = vData;
                Lf.ResvFrm.FrameMeaning = "没有传入解析包";
                Lf.ResvFrm.FrameTime    = DateTime.Now;

                CLDC_DataCore.Const.GlobalUnit.FrameLog.WriteFrameLog(Lf);
                Monitor.Exit(objPackLock);
                return(false);
            }
            if (sendPack.IsNeedReturn == true && recvPack != null)
            {
                Console.WriteLine("收到数据{0}", BitConverter.ToString(vData, 0));
                if (false)
                {
                    //TODO:2018带协议 ,解包
                }
                bool ret = recvPack.ParsePacket(vData);

                Lf.ResvFrm.Frame        = vData;
                Lf.ResvFrm.FrameMeaning = recvPack.GetPacketResolving();
                Lf.ResvFrm.FrameTime    = DateTime.Now;

                CLDC_DataCore.Const.GlobalUnit.FrameLog.WriteFrameLog(Lf);
                Monitor.Exit(objPackLock);
                return(ret);
            }
            else
            {
                Console.WriteLine("其他发送接收错误");

                Lf.ResvFrm.Frame        = vData;
                Lf.ResvFrm.FrameMeaning = "其他发送接收错误";
                Lf.ResvFrm.FrameTime    = DateTime.Now;

                CLDC_DataCore.Const.GlobalUnit.FrameLog.WriteFrameLog(Lf);
                Monitor.Exit(objPackLock);
                return(false);
            }
        }
Пример #3
0
        private void btn_Search_Click(object sender, EventArgs e)
        {
            string Strsql = "";

            if (txt_time1.Text.Trim() == "例如:2008-08-08")
            {
                txt_time1.Text = "";
            }
            if (txt_time2.Text.Trim() == "例如:2008-09-08")
            {
                txt_time2.Text = "";
            }

            if (cmb_Type.Text.Trim() == "全部")
            {
                if (txt_time1.Text.Trim() != "")
                {
                    if (txt_No.Text.Trim() != "" && txt_time2.Text.Trim() == "")
                    {
                        Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrSTime like '%" + txt_time1.Text.Trim() + "%' order by chrSTime desc";
                    }
                    else if (txt_time2.Text.Trim() != "" && txt_No.Text.Trim() != "")
                    {
                        Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrSTime >= '" + txt_time1.Text.Trim() + "' and chrSTime <= '" + txt_time2.Text.Trim() + "' order by chrSTime desc";
                    }
                    else if (txt_No.Text.Trim() == "" && txt_time2.Text.Trim() != "")
                    {
                        Strsql = "select  * from FrameLog where chrSTime >= '" + txt_time1.Text.Trim() + "' and chrSTime <= '" + txt_time2.Text.Trim() + "' order by chrSTime desc";
                    }
                    else
                    {
                        Strsql = "select * from FrameLog where chrSTime like '%" + txt_time1.Text.Trim() + "%' order by chrSTime desc";
                    }
                }
                else if (txt_time1.Text.Trim() == "" && txt_No.Text.Trim() != "")
                {
                    Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog order by chrSTime desc ";
                }
                else
                {
                    Strsql = " select * from FrameLog order by chrSTime desc";
                }
            }
            else if (cmb_Type.Text.Trim() == "排除端口")
            {
                if (txt_time1.Text.Trim() != "")
                {
                    if (txt_No.Text.Trim() != "" && txt_time2.Text.Trim() == "")
                    {
                        Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrPortNo <> '" + cmbTiaojian.Text.Trim() + "' and chrSTime like '%" + txt_time1.Text.Trim() + "%' order by chrSTime desc";
                    }
                    else if (txt_time2.Text.Trim() != "" && txt_No.Text.Trim() != "")
                    {
                        Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrPortNo <>'" + cmbTiaojian.Text.Trim() + "' and chrSTime >= '" + txt_time1.Text.Trim() + "' and chrSTime <= '" + txt_time2.Text.Trim() + "' order by chrSTime desc";
                    }
                    else if (txt_No.Text.Trim() == "" && txt_time2.Text.Trim() != "")
                    {
                        Strsql = "select  * from FrameLog where chrPortNo <> '" + cmbTiaojian.Text.Trim() + "' and chrSTime >= '" + txt_time1.Text.Trim() + "' and chrSTime <= '" + txt_time2.Text.Trim() + "' order by chrSTime desc";
                    }
                    else
                    {
                        Strsql = "select * from FrameLog where chrPortNo <> '" + cmbTiaojian.Text.Trim() + "' and chrSTime like '%" + txt_time1.Text.Trim() + "%' order by chrSTime desc";
                    }
                }
                else if (txt_time1.Text.Trim() == "" && txt_No.Text.Trim() != "")
                {
                    Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrPortNo <> '" + cmbTiaojian.Text.Trim() + "' order by chrSTime desc ";
                }
                else
                {
                    Strsql = " select * from FrameLog where chrPortNo <> '" + cmbTiaojian.Text.Trim() + "' order by chrSTime desc";
                }
            }
            else if (cmb_Type.Text.Trim() == "端口号")
            {
                if (txt_time1.Text.Trim() != "")
                {
                    if (txt_No.Text.Trim() != "" && txt_time2.Text.Trim() == "")
                    {
                        Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrPortNo = '" + cmbTiaojian.Text.Trim() + "' and chrSTime like '%" + txt_time1.Text.Trim() + "%' order by chrSTime desc";
                    }
                    else if (txt_time2.Text.Trim() != "" && txt_No.Text.Trim() != "")
                    {
                        Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrPortNo = '" + cmbTiaojian.Text.Trim() + "' and chrSTime >= '" + txt_time1.Text.Trim() + "' and chrSTime <= '" + txt_time2.Text.Trim() + "' order by chrSTime desc";
                    }
                    else if (txt_No.Text.Trim() == "" && txt_time2.Text.Trim() != "")
                    {
                        Strsql = "select  * from FrameLog where chrPortNo = '" + cmbTiaojian.Text.Trim() + "' and chrSTime >= '" + txt_time1.Text.Trim() + "' and chrSTime <= '" + txt_time2.Text.Trim() + "' order by chrSTime desc";
                    }
                    else
                    {
                        Strsql = "select * from FrameLog where chrPortNo = '" + cmbTiaojian.Text.Trim() + "' and chrSTime like '%" + txt_time1.Text.Trim() + "%' order by chrSTime desc";
                    }
                }
                else if (txt_time1.Text.Trim() == "" && txt_No.Text.Trim() != "")
                {
                    Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrPortNo = '" + cmbTiaojian.Text.Trim() + "' order by chrSTime desc ";
                }
                else
                {
                    Strsql = " select * from FrameLog where chrPortNo = '" + cmbTiaojian.Text.Trim() + "' order by chrSTime desc";
                }
            }
            else if (cmb_Type.Text.Trim() == "控制")
            {
                if (txt_time1.Text.Trim() != "")
                {
                    if (txt_No.Text.Trim() != "" && txt_time2.Text.Trim() == "")
                    {
                        Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrItemName = '" + cmbTiaojian.Text.Trim() + "' and chrSTime like '%" + txt_time1.Text.Trim() + "%' order by chrSTime desc";
                    }
                    else if (txt_time2.Text.Trim() != "" && txt_No.Text.Trim() != "")
                    {
                        Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrItemName = '" + cmbTiaojian.Text.Trim() + "' and chrSTime >= '" + txt_time1.Text.Trim() + "' and chrSTime <= '" + txt_time2.Text.Trim() + "' order by chrSTime desc";
                    }
                    else if (txt_No.Text.Trim() == "" && txt_time2.Text.Trim() != "")
                    {
                        Strsql = "select  * from FrameLog where chrItemName = '" + cmbTiaojian.Text.Trim() + "' and chrSTime >= '" + txt_time1.Text.Trim() + "' and chrSTime <= '" + txt_time2.Text.Trim() + "' order by chrSTime desc";
                    }
                    else
                    {
                        Strsql = "select * from FrameLog where chrItemName = '" + cmbTiaojian.Text.Trim() + "' and chrSTime like '%" + txt_time1.Text.Trim() + "%' order by chrSTime desc";
                    }
                }
                else if (txt_time1.Text.Trim() == "" && txt_No.Text.Trim() != "")
                {
                    Strsql = "select top " + txt_No.Text.Trim() + " * from FrameLog where chrItemName = '" + cmbTiaojian.Text.Trim() + "' order by chrSTime desc ";
                }
                else
                {
                    Strsql = " select * from FrameLog where chrItemName = '" + cmbTiaojian.Text.Trim() + "' order by chrSTime desc";
                }
            }
            else
            {
                Strsql = "select top 25 * from FrameLog order by chrSTime desc";
            }

            OleDbDataReader dr = CLDC_DataCore.DataBase.DbHelperOleDb.ExecuteReader(Strsql);
            List <CLDC_DataCore.Model.LogModel.LogFrameInfo> BaowenList = new List <CLDC_DataCore.Model.LogModel.LogFrameInfo>();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    CLDC_DataCore.Model.LogModel.LogFrameInfo see = new CLDC_DataCore.Model.LogModel.LogFrameInfo();
                    see.chrPortNo    = dr["chrPortNo"].ToString();
                    see.chrEquipName = dr["chrEquipName"].ToString();
                    see.chrItemName  = dr["chrItemName"].ToString();
                    see.chrMessage   = dr["chrMessage"].ToString();
                    see.chrSFrame    = dr["chrSFrame"].ToString();
                    see.chrSMeaning  = dr["chrSMeaning"].ToString();
                    see.chrSTime     = dr["chrSTime"].ToString();
                    see.chrRFrame    = dr["chrRFrame"].ToString();
                    see.chrRMeaning  = dr["chrRMeaning"].ToString();
                    see.chrRTime     = dr["chrRTime"].ToString();
                    see.chrOther     = dr["chrOther"].ToString();
                    BaowenList.Add(see);
                }
                dr.Close();
            }

            Grid_seebaowen.DataSource = BaowenList;
        }