Пример #1
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            string sMess = null;

            try
            {
                this.Text = MyPublic.g_SysCation;
                mIniListControlData();
                sMess = "系统需要加载数据,请确保硬件环境到位,然后点击【启动】";
                mAddListData(MyPublic.g_LogStatus, sMess);
                mIniTreeViewData();
                lst_Status.Visible = true;
                lst_Dps.Visible    = false;
                lst_Mcs.Visible    = false;
                lst_Ecs.Visible    = false;
                lst_Pda.Visible    = false;
                lst_cps.Visible    = false;
                lst_Prn.Visible    = false;
                lst_Skt.Visible    = false;
                lst_Err.Visible    = false;
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(-1, m_sClsName, "FrmMain_Load", sMess);
            }
        }
Пример #2
0
        //初始化数据
        public int mIniSocketData()
        {
            string sMess = null;

            try
            {
                m_clnSocket = new _socketThread[MyPublic.m_SysTreadCount];
                for (int i = 0; i < MyPublic.m_SysTreadCount; i++)
                {
                    m_clnSocket[i]._clnThread = null;
                    m_clnSocket[i]._clnSocket = null;
                    m_clnSocket[i]._DoStatus  = 0;
                }

                mThreadServerLsn = new Thread(new ThreadStart(mCreateServerSocketListen));
                mThreadServerLsn.Start();
                return(0);
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mIniSocketData", sMess);
                return(-1);
            }
        }
Пример #3
0
        private int mIniLogin()
        {
            string sMess = null;

            try
            {
                //初始界面大小
                this.Height = 206;
                this.Width  = 366;
                //初始化数据库设置
                txt_wmsDbName.Text    = MyPublic.m_DbWMSServer;
                txt_WMSDBUserID.Text  = MyPublic.m_DbWMSUserID;
                txt_WMSDBUserPWD.Text = MyPublic.m_DbWMSUserPWD;
                txt_SvrIP.Text        = MyPublic.m_LocalIP;
                txt_SvrPort.Text      = MyPublic.m_LocalPort.ToString();
                txt_KeyCnntCount.Text = MyPublic.m_SysTreadCount.ToString();

                txt_SysUserID.Text  = MyPublic.m_SysUserID;
                txt_SysUserPWD.Text = MyPublic.m_SysUserPwd;
                return(0);
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mIniLogin", sMess);
                return(1);
            }
        }
Пример #4
0
        //初始化树控件数据
        private void mIniTreeViewData()
        {
            string sMess = "";

            try
            {
                string[] sFun = new string[9];
                sFun[0] = "【运行状态】";
                sFun[1] = "【DPS 日志】";
                sFun[2] = "【MCS 日志】";
                sFun[3] = "【ECS 日志】";
                sFun[4] = "【PDA 日志】";
                sFun[5] = "【CPS 日志】";
                sFun[6] = "【打印日志】";
                sFun[7] = "【通信日志】";
                sFun[8] = "【异常日志】";

                TreeNode rootNode = new TreeNode("【全部功能】");
                Tv_Fun.Nodes.Add(rootNode);
                for (int i = 0; i < sFun.GetLength(0); i++)
                {
                    TreeNode MyNode2 = new TreeNode(sFun[i]);
                    rootNode.Nodes.Add(MyNode2);
                }
                rootNode.ExpandAll();
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(-1, m_sClsName, "mIniTreeViewData", sMess);
            }
        }
Пример #5
0
        private string mGetLocalIP(string _IP)
        {
            string sMess = null;

            try
            {
                string hostName = System.Net.Dns.GetHostName();
                System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(hostName);
                //ip地址列表
                System.Net.IPAddress[] addr = ipEntry.AddressList;
                for (int i = 0; i < addr.GetLength(0); i++)
                {
                    string IPAddress = addr[i].ToString();
                    if (IPAddress == _IP)
                    {
                        return(IPAddress);
                    }
                }
                sMess = "物理IP与系统设置IP不匹配,请联系系统管理员";
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mGetLocalIP", sMess);
                OnDisCmdMess(1, sMess);
                return(null);
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mGetLocalIP", sMess);
                return(null);
            }
        }
Пример #6
0
        //创建Socket服务端监听
        private void mCreateServerSocketListen()
        {
            string sMess = null;

            try
            {
                IPAddress  ip       = IPAddress.Parse(MyPublic.m_LocalIP);
                IPEndPoint ipe_ctrl = new IPEndPoint(ip, MyPublic.m_LocalPort);
                m_ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                m_ServerSocket.Bind(ipe_ctrl);
                m_ServerSocket.Listen(MyPublic.m_SysTreadCount);
                sMess = "Socket服务监听创建成功;本地;IP【" + MyPublic.m_LocalIP + "】;端口号【" + MyPublic.m_LocalPort.ToString() + "】";
                OnDisCmdMess(MyPublic.g_LogStatus, sMess);
                MyPublic.gWriteLog(MyPublic.g_LogSkt, "Socket通信", "Socket通信", sMess);
                while (1 == 1)
                {
                    m_iCurSocketIndex = mFindNullSocket();
                    if (m_iCurSocketIndex == -1)
                    {
                        sMess = "没有可用的连接Socket,请联系系统管理员.";
                        MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mCreateServerSocketListen", sMess);
                        MyPublic.gWriteLog(MyPublic.g_LogSkt, "Socket通信", "Socket通信", sMess);
                        OnDisCmdMess(MyPublic.g_LogErr, sMess);
                        Thread.Sleep(1000);
                        continue;
                    }
                    m_clnSocket[m_iCurSocketIndex]._clnSocket = m_ServerSocket.Accept();

                    //获取客户端的IP地址
                    string sClnIP = null;
                    sClnIP = ((System.Net.IPEndPoint)m_clnSocket[m_iCurSocketIndex]._clnSocket.RemoteEndPoint).Address.ToString();
                    //启动客户端线程
                    m_clnSocket[m_iCurSocketIndex]._DoStatus  = 1;
                    m_clnSocket[m_iCurSocketIndex]._IpAddress = sClnIP;
                    m_clnSocket[m_iCurSocketIndex]._clnThread = new Thread(new ThreadStart(mCreateConnectClientData));
                    m_clnSocket[m_iCurSocketIndex]._clnThread.Start();

                    sMess = string.Format("客户端:{0};线程【{1}】;连接成功;", sClnIP, m_iCurSocketIndex);
                    OnDisCmdMess(MyPublic.g_LogStatus, sMess);
                    Thread.Sleep(100);
                }
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                sMess = "严重的系统问题;Socket服务监听创建失败或者运行中出错;" + ex.Message;
                OnDisCmdMess(MyPublic.g_LogErr, sMess);
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mCreateServerSocketListen", sMess);
            }
        }
Пример #7
0
        //关闭线程
        public void mCloseThread()
        {
            string sMess = null;

            try
            {
                mThreadServerLsn.Abort();
                m_ServerSocket.Shutdown(0);
                m_ServerSocket.Close();
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mCloseThread", sMess);
            }
        }
Пример #8
0
        //回滚事务
        public int mRollbackTran()
        {
            string sMess = null;

            try
            {
                m_oraTact.Rollback();
                return(0);
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mRollbackTran", sMess);
                return(-1);
            }
        }
Пример #9
0
        static void Main()
        {
            MyPublic.gIniSysParam();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            FrmLogin mFrmLogin = new FrmLogin();

            mFrmLogin.ShowDialog();
            mFrmLogin.Dispose();
            mFrmLogin = null;
            if (MyPublic.m_LoginSuccess == 0)
            {
                return;
            }
            Application.Run(new FrmMain());
            Process.GetCurrentProcess().Kill();
        }
Пример #10
0
        //开始事务
        public int mBeginTran()
        {
            string sMess = null;

            try
            {
                m_oraTact            = m_oraCon.BeginTransaction();
                m_oraCmd.Transaction = m_oraTact;
                m_oraPro.Transaction = m_oraTact;
                return(0);
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mBeginTran", sMess);
                return(-1);
            }
        }
Пример #11
0
        //写数据
        public int mExecuteSQL(string _SQL)
        {
            string sMess = null;

            try
            {
                int iRow = 0;
                m_oraCmd.CommandText = _SQL;
                m_oraCmd.Connection  = m_oraCon;
                iRow = m_oraCmd.ExecuteNonQuery();
                return(iRow);
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mExecuteSQL", sMess);
                return(-1);
            }
        }
Пример #12
0
        public string m_DbCnntStr          = null; //数据库连接字符串



        //定义数据库连接函数
        public int mConnectDB(ref string _errMess)
        {
            try
            {
                if (m_oraCon.State == ConnectionState.Open)
                {
                    m_oraCon.Close();
                }
                m_oraCon.ConnectionString = m_DbCnntStr;
                m_oraCon.Open();
                return(0);
            }
            catch (System.Exception ex)
            {
                _errMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mConnectWCSDB" + m_DbCnntStr, _errMess);
                return(-1);
            }
        }
Пример #13
0
        //打开数据集
        public DataSet mOpenDataSet(string _SQL, ref string _errMess)
        {
            string sMess = null;

            try
            {
                //新建一个DataAdapter用于填充DataSet
                OracleDataAdapter oraDap = new OracleDataAdapter(_SQL, m_oraCon);
                //新建一个DataSet
                DataSet ds = new DataSet();
                //填充DataSet
                oraDap.Fill(ds);
                return(ds);
            }
            catch (System.Exception ex)
            {
                _errMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mOpenDataSetStatic", sMess + _SQL);
                mConnectDB(ref _errMess);
                return(null);
            }
        }
Пример #14
0
        private void mIniData()
        {
            string sMess = null;

            try
            {
                string sSQL = null;
                sSQL     = " select t.groupno,t.ip,t.Port,mark,t.cnntnum,t.ipno from wcs_ip t where t.type='S' and t.groupno='" + MyPublic.m_SysGroupNo + "'";
                m_dsMain = FrmLogin.m_LWcsDB.mOpenDataSet(sSQL, ref sMess);
                this.dg_MainData.DataSource = m_dsMain.Tables[0];

                if (m_dsMain.Tables[0].Rows.Count == 0)
                {
                    ts_AddSvr.Enabled  = true;
                    ts_EditSvr.Enabled = false;
                }
                else
                {
                    ts_AddSvr.Enabled = false;
                }

                sSQL = " select t.groupno,t.ip,t.MARK,t.WTYPE,ipno from wcs_ip t " +
                       "  where t.type='C' and t.groupno='" + MyPublic.m_SysGroupNo + "'" +
                       "  order by WTYPE,ip";
                m_dsDetail = FrmLogin.m_LWcsDB.mOpenDataSet(sSQL, ref sMess);
                this.dg_DetailData.DataSource = m_dsDetail.Tables[0];
                if (m_dsDetail.Tables[0].Rows.Count == 0)
                {
                    ts_EditCln.Enabled = false;
                }
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mIniServerParam", sMess);
            }
        }
Пример #15
0
        private void ts_Start_Click(object sender, EventArgs e)
        {
            string sMess = null;

            try
            {
                //clsOutput _clsWCps = new clsOutput();
                //string[] _sResult = null;
                //string _sDoWorkData = "";
                //_sResult = _clsWCps.mDoCPSWorkData(_sDoWorkData);


                m_ServerSocket = new clsServerSocket();
                m_ServerSocket.OnDisCmdMess += new clsServerSocket.DisCmdMess(FrmMain_OnDisCmdMess);
                m_ServerSocket.mIniSocketData();
                ts_Start.Enabled = false;
                m_iStart         = 1;
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(-1, m_sClsName, "bt_Start_Click", sMess);
            }
        }
Пример #16
0
        //查找可用的Socket
        private int mFindNullSocket()
        {
            string sMess = null;

            try
            {
                for (int i = 0; i < m_clnSocket.GetLength(0); i++)
                {
                    if (m_clnSocket[i]._DoStatus == 0)
                    {
                        m_clnSocket[i]._clnSocket = null;
                        m_clnSocket[i]._clnThread = null;
                        return(i);
                    }
                }
                return(-1);
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mFindNullSocket", sMess);
                return(-1);
            }
        }
Пример #17
0
        public void bt_Ok_Click(object sender, EventArgs e)
        {
            string sMess = null;

            try
            {
                int iRet = 0;
                bt_Ok.Enabled = false;
                //WMS数据库信息
                txt_WMSDBUserID.Text  = txt_WMSDBUserID.Text.Trim();
                txt_WMSDBUserPWD.Text = txt_WMSDBUserPWD.Text.Trim();
                txt_wmsDbName.Text    = txt_wmsDbName.Text.Trim();

                if (txt_WMSDBUserPWD.Text.Length == 0 || txt_WMSDBUserID.Text.Length == 0 || txt_wmsDbName.Text.Length == 0 ||
                    txt_wmsDbName.Text.Length == 0 || txt_SvrPort.Text.Length == 0 || txt_KeyCnntCount.Text.Length == 0)
                {
                    lbl_Mess.Text = "WMS数据库信息输入不完整,请核对!";
                    txt_WMSDBUserID.Focus();
                    bt_Ok.Enabled = true;
                    return;
                }
                //WCS数据库信息
                txt_SvrIP.Text        = txt_SvrIP.Text.Trim();
                txt_SvrPort.Text      = txt_SvrPort.Text.Trim();
                txt_KeyCnntCount.Text = txt_KeyCnntCount.Text.Trim();
                if (txt_wmsDbName.Text.Length == 0 || txt_SvrPort.Text.Length == 0 || txt_KeyCnntCount.Text.Length == 0)
                {
                    lbl_Mess.Text = "配置信息输入不完整,请核对!";
                    txt_SvrIP.Focus();
                    bt_Ok.Enabled = true;
                    return;
                }


                //系统用户信息
                txt_SysUserID.Text  = txt_SysUserID.Text.Trim();
                txt_SysUserPWD.Text = txt_SysUserPWD.Text.Trim();


                if (txt_SysUserID.Text.Length == 0 ||
                    txt_SysUserPWD.Text.Length == 0)
                {
                    lbl_Mess.Text = "系统用户信息输入不完整,请核对!";
                    txt_WMSDBUserID.Focus();
                    bt_Ok.Enabled = true;
                    return;
                }

                //连接数据库wcs/wcs6mose@lwcs_2b
                lbl_Mess.Text = "系统正在连接数据库,请稍等...";

                MyPublic.m_LocalIP       = txt_SvrIP.Text;
                MyPublic.m_LocalPort     = int.Parse(txt_SvrPort.Text);
                MyPublic.m_SysTreadCount = int.Parse(txt_KeyCnntCount.Text);

                MyPublic.m_DbWMSUserID   = txt_WMSDBUserID.Text;
                MyPublic.m_DbWMSServer   = txt_wmsDbName.Text;
                MyPublic.m_DbWMSUserPWD  = txt_WMSDBUserPWD.Text;
                MyPublic.m_DbLMISCnntStr = " user id=" + MyPublic.m_DbWMSUserID +
                                           ";data source=" + MyPublic.m_DbWMSServer +
                                           ";password="******"系统连接LMIS数据库失败,请核对数据库信息!";
                    txt_WMSDBUserID.Focus();
                    bt_Ok.Enabled = true;
                    return;
                }
                lbl_Mess.Text = "系统连接LMIS数据库成功,正在验证用户信息...";
                //系统用户信息
                MyPublic.m_SysUserID  = txt_SysUserID.Text;
                MyPublic.m_SysUserPwd = txt_SysUserPWD.Text;

                MyPublic.gUpdateIniData();

                //用户校验成功
                MyPublic.m_LoginSuccess = 1;
                this.Close();
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "bt_Ok_Click", sMess);
            }
        }
Пример #18
0
 public DataSet mGetTaskDataSet(string _PreName, string[,] _VarrData, ref string _errMess)
 {
     try
     {
         int iArrCount = -1, i = 0;
         OracleParameter[] vParam = null;
         m_oraPro.Connection  = m_oraCon;
         m_oraPro.CommandText = _PreName;
         m_oraPro.CommandType = CommandType.StoredProcedure;
         iArrCount            = _VarrData.GetLength(0);
         vParam = new OracleParameter[iArrCount];
         m_oraPro.Parameters.Clear();
         for (i = 0; i < iArrCount; i++)
         {
             //字段输入/输出
             if (_VarrData[i, 2] == g_Oracle_InPut)
             {
                 //字段类型
                 if (_VarrData[i, 1] == g_Oracle_Char)
                 {
                     vParam[i] = new OracleParameter(_VarrData[i, 0], OracleType.VarChar, 1000);
                 }
                 else if (_VarrData[i, 1] == g_Oracle_Int)
                 {
                     vParam[i] = new OracleParameter(_VarrData[i, 0], OracleType.Float, 1000);
                 }
                 else if (_VarrData[i, 1] == g_Oracle_Cursor)
                 {
                     vParam[i] = new OracleParameter(_VarrData[i, 0], OracleType.Cursor, 1000);
                 }
                 vParam[i].Direction = ParameterDirection.Input;
                 //字段值
                 vParam[i].Value = _VarrData[i, 3];
             }
             else if (_VarrData[i, 2] == g_Oracle_OutPut)
             {
                 //字段类型
                 if (_VarrData[i, 1] == g_Oracle_Char)
                 {
                     vParam[i] = new OracleParameter(_VarrData[i, 0], OracleType.VarChar, 1000);
                 }
                 else if (_VarrData[i, 1] == g_Oracle_Int)
                 {
                     vParam[i] = new OracleParameter(_VarrData[i, 0], OracleType.Float, 1000);
                 }
                 else if (_VarrData[i, 1] == g_Oracle_Cursor)
                 {
                     vParam[i] = new OracleParameter(_VarrData[i, 0], OracleType.Cursor, 1000);
                 }
                 vParam[i].Direction = ParameterDirection.Output;
             }
             m_oraPro.Parameters.Add(vParam[i]);
         }
         //执行存储过程
         DataSet           ds = new DataSet();
         OracleDataAdapter da = new OracleDataAdapter(m_oraPro);
         da.Fill(ds);
         return(ds);
     }
     catch (System.Exception ex)
     {
         _errMess = ex.Message.ToString();
         MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mRunProcedure", _errMess);
         mConnectDB(ref _errMess);
         return(null);
     }
 }
Пример #19
0
        //初始化List控件数据
        private void mIniListControlData()
        {
            string sMess = null;

            try
            {
                int iDateLen = 80;
                int iTimeLen = 120;
                int iDataLen = 600;
                //显示模式
                lst_Status.View          = View.Details;
                lst_Status.FullRowSelect = true;
                lst_Status.MultiSelect   = false;
                //创建标题
                lst_Status.Columns.Add("日期", iDateLen);
                lst_Status.Columns.Add("时间", iTimeLen);
                lst_Status.Columns.Add("描述", iDataLen);

                //显示模式
                lst_Dps.View          = View.Details;
                lst_Dps.FullRowSelect = true;
                lst_Dps.MultiSelect   = false;
                //创建标题
                lst_Dps.Columns.Add("日期", iDateLen);
                lst_Dps.Columns.Add("时间", iTimeLen);
                lst_Dps.Columns.Add("描述", iDataLen);


                //显示模式
                lst_Mcs.View          = View.Details;
                lst_Mcs.FullRowSelect = true;
                lst_Mcs.MultiSelect   = false;
                //创建标题
                lst_Mcs.Columns.Add("日期", iDateLen);
                lst_Mcs.Columns.Add("时间", iTimeLen);
                lst_Mcs.Columns.Add("描述", iDataLen);


                //显示模式
                lst_Ecs.View          = View.Details;
                lst_Ecs.FullRowSelect = true;
                lst_Ecs.MultiSelect   = false;
                //创建标题
                lst_Ecs.Columns.Add("日期", iDateLen);
                lst_Ecs.Columns.Add("时间", iTimeLen);
                lst_Ecs.Columns.Add("描述", iDataLen);



                //显示模式
                lst_Pda.View          = View.Details;
                lst_Pda.FullRowSelect = true;
                lst_Pda.MultiSelect   = false;
                //创建标题
                lst_Pda.Columns.Add("日期", iDateLen);
                lst_Pda.Columns.Add("时间", iTimeLen);
                lst_Pda.Columns.Add("描述", iDataLen);


                //显示模式
                lst_Prn.View          = View.Details;
                lst_Prn.FullRowSelect = true;
                lst_Prn.MultiSelect   = false;
                //创建标题
                lst_Prn.Columns.Add("日期", iDateLen);
                lst_Prn.Columns.Add("时间", iTimeLen);
                lst_Prn.Columns.Add("描述", iDataLen);


                //显示模式
                lst_cps.View          = View.Details;
                lst_cps.FullRowSelect = true;
                lst_cps.MultiSelect   = false;
                //创建标题
                lst_cps.Columns.Add("日期", iDateLen);
                lst_cps.Columns.Add("时间", iTimeLen);
                lst_cps.Columns.Add("描述", iDataLen);

                //显示模式
                lst_Skt.View          = View.Details;
                lst_Skt.FullRowSelect = true;
                lst_Skt.MultiSelect   = false;
                //创建标题
                lst_Skt.Columns.Add("日期", iDateLen);
                lst_Skt.Columns.Add("时间", iTimeLen);
                lst_Skt.Columns.Add("描述", 1024);

                //显示模式
                lst_Err.View          = View.Details;
                lst_Err.FullRowSelect = true;
                lst_Err.MultiSelect   = false;
                //创建标题
                lst_Err.Columns.Add("日期", iDateLen);
                lst_Err.Columns.Add("时间", iTimeLen);
                lst_Err.Columns.Add("描述", iDataLen);
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(-1, m_sClsName, "mIniListControlData", sMess);
            }
        }
Пример #20
0
        //添加List控件显示数据
        private void mAddListData(int _lstIndex, string _Data)
        {
            string sMess = null;

            try
            {
                string   sDate = null;
                string   sTime = null;
                DateTime dt    = DateTime.Now;
                sDate = dt.ToShortDateString().ToString();
                sTime = dt.TimeOfDay.ToString();
                ListViewItem lvItem;
                ListViewItem.ListViewSubItem lvSubItem;
                lvItem         = new ListViewItem();
                lvItem.Text    = sDate;
                lvSubItem      = new ListViewItem.ListViewSubItem();
                lvSubItem.Text = sTime;
                lvItem.SubItems.Add(lvSubItem);
                lvSubItem      = new ListViewItem.ListViewSubItem();
                lvSubItem.Text = _Data;
                lvItem.SubItems.Add(lvSubItem);
                switch (_lstIndex)
                {
                case MyPublic.g_LogStatus:
                    //运行状态
                    lst_Status.Items.Insert(0, lvItem);
                    lst_Status.Items[0].Selected = true;
                    if (lst_Status.Items.Count == 200)
                    {
                        lst_Status.Items.RemoveAt(199);
                    }
                    break;

                case MyPublic.g_LogDps:
                    //DPS日志
                    lst_Dps.Items.Insert(0, lvItem);
                    lst_Dps.Items[0].Selected = true;
                    if (lst_Dps.Items.Count == 200)
                    {
                        lst_Dps.Items.RemoveAt(199);
                    }
                    break;

                case MyPublic.g_LogMcs:
                    lst_Mcs.Items.Insert(0, lvItem);
                    lst_Mcs.Items[0].Selected = true;
                    if (lst_Mcs.Items.Count == 200)
                    {
                        lst_Mcs.Items.RemoveAt(199);
                    }
                    break;

                case MyPublic.g_LogEcs:
                    lst_Ecs.Items.Insert(0, lvItem);
                    lst_Ecs.Items[0].Selected = true;
                    if (lst_Ecs.Items.Count == 200)
                    {
                        lst_Ecs.Items.RemoveAt(199);
                    }
                    break;

                case MyPublic.g_LogPda:
                    lst_Pda.Items.Insert(0, lvItem);
                    lst_Pda.Items[0].Selected = true;
                    if (lst_Pda.Items.Count == 200)
                    {
                        lst_Pda.Items.RemoveAt(199);
                    }
                    break;

                case MyPublic.g_LogCps:
                    lst_cps.Items.Insert(0, lvItem);
                    lst_cps.Items[0].Selected = true;
                    if (lst_cps.Items.Count == 200)
                    {
                        lst_cps.Items.RemoveAt(199);
                    }
                    break;

                case MyPublic.g_LogPrn:
                    lst_Prn.Items.Insert(0, lvItem);
                    lst_Prn.Items[0].Selected = true;
                    if (lst_Prn.Items.Count == 200)
                    {
                        lst_Prn.Items.RemoveAt(199);
                    }
                    break;

                case MyPublic.g_LogSkt:
                    lst_Skt.Items.Insert(0, lvItem);
                    lst_Skt.Items[0].Selected = true;
                    if (lst_Skt.Items.Count == 200)
                    {
                        lst_Skt.Items.RemoveAt(199);
                    }
                    break;

                case MyPublic.g_LogErr:
                    lst_Err.Items.Insert(0, lvItem);
                    lst_Err.Items[0].Selected = true;
                    if (lst_Err.Items.Count == 200)
                    {
                        lst_Err.Items.RemoveAt(199);
                    }
                    break;
                }
            }
            catch (System.Exception ex)
            {
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(-1, m_sClsName, "mAddListData", sMess);
            }
        }
Пример #21
0
        //创建Socket服务端监听
        private void mCreateConnectClientData()
        {
            string sMess      = "";
            int    _iCurIndex = m_iCurSocketIndex;

            try
            {
                int    iRet           = -1;
                string _sMainReceData = "";
                m_clnSocket[_iCurIndex]._clnSocket.ReceiveTimeout = 10000;
                while (1 == 1)
                {
                    byte[] _receData    = new byte[40960];
                    byte[] _sendData    = null;
                    int    iReceLength  = 0;
                    int    _iStartPos   = -1;
                    string _sDoWorkData = "";
                    try
                    {
                        iReceLength = m_clnSocket[_iCurIndex]._clnSocket.Receive(_receData);
                        if (iReceLength == 0)
                        {
                            sMess = string.Format("客户端:{0};线程【{1}】;结束工作;接受为空;", m_clnSocket[_iCurIndex]._IpAddress, m_iCurSocketIndex);
                            OnDisCmdMess(MyPublic.g_LogStatus, sMess);
                            Thread.Sleep(100);
                            m_clnSocket[_iCurIndex]._DoStatus = 0;
                            m_clnSocket[_iCurIndex]._clnSocket.Close();
                            return;
                        }

                        string sReceData = null;
                        sReceData = Encoding.Default.GetString(_receData, 0, iReceLength);
                        int iDelPos = -1;
                        iDelPos = sReceData.IndexOf(Convert.ToChar(10)); //删除/n
                        if (iDelPos >= 0)
                        {
                            sReceData = sReceData.Remove(iDelPos, 1);
                        }

                        sMess = string.Format("客户端:{0};接受数据:{1}", m_clnSocket[_iCurIndex]._IpAddress, sReceData);
                        OnDisCmdMess(MyPublic.g_LogSkt, sMess);
                        MyPublic.gWriteLog(MyPublic.g_LogSkt, "Socket通信", "Socket通信", sMess);
                        _sMainReceData += sReceData;

                        _iStartPos = _sMainReceData.IndexOf(MyPublic.g_sktDataEndChar);
                        if (_iStartPos > 0)
                        {
                            _sDoWorkData = _sMainReceData.Substring(0, _iStartPos + 3);
                            clsOutput _clsWCps = new clsOutput();
                            string[]  _sResult = null;
                            _sResult = _clsWCps.mDoCPSWorkData(_sDoWorkData);
                            for (int i = 0; i < _sResult.GetLength(0); i++)
                            {
                                _sResult[i] += MyPublic.g_sktDataEndChar;
                                _sendData    = Encoding.Default.GetBytes(_sResult[i]);
                                iRet         = m_clnSocket[_iCurIndex]._clnSocket.Send(_sendData, _sendData.Length, 0);
                                sMess        = string.Format("客户端:{0};发送状态:{1};数据:{2}", m_clnSocket[_iCurIndex]._IpAddress, iRet, _sResult[i]);
                                OnDisCmdMess(MyPublic.g_LogSkt, sMess);
                                MyPublic.gWriteLog(MyPublic.g_LogSkt, "Socket通信", "Socket通信", sMess);
                                Thread.Sleep(50);
                            }
                        }
                        sMess = string.Format("客户端:{0};线程【{1}】;结束工作;正常结束;", m_clnSocket[_iCurIndex]._IpAddress, m_iCurSocketIndex);
                        OnDisCmdMess(MyPublic.g_LogStatus, sMess);

                        m_clnSocket[_iCurIndex]._DoStatus = 0;
                        m_clnSocket[_iCurIndex]._clnSocket.Close();
                        return;
                    }
                    catch (System.Exception ex)
                    {
                        sMess = string.Format("客户端:{0};线程【{1}】;结束工作;接受超时;", m_clnSocket[_iCurIndex]._IpAddress, m_iCurSocketIndex);
                        OnDisCmdMess(MyPublic.g_LogStatus, sMess);
                        m_clnSocket[_iCurIndex]._DoStatus = 0;
                        m_clnSocket[_iCurIndex]._clnSocket.Close();
                        sMess = string.Format("客户端:{0};{1}", m_clnSocket[_iCurIndex]._IpAddress, ex.Message.ToString());
                        OnDisCmdMess(MyPublic.g_LogErr, sMess);
                        return;
                    }
                }
            }
            catch (System.Exception ex)
            {
                sMess = string.Format("客户端:{0};线程【{1}】;结束工作;异常退出;", m_clnSocket[_iCurIndex]._IpAddress, m_iCurSocketIndex);
                OnDisCmdMess(MyPublic.g_LogStatus, sMess);
                sMess = ex.Message.ToString();
                MyPublic.gWriteLog(MyPublic.g_LogErr, m_sClsName, "mCreateConnectClientData", sMess);
                OnDisCmdMess(MyPublic.g_LogErr, sMess);
            }
        }