⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workfrm.cs

📁 实现在smartphone中使用wmplayer播放多媒体内容的功能
💻 CS
📖 第 1 页 / 共 2 页
字号:
        {
            try
            {
                TcpClient normalClient = new TcpClient();
                NetworkStream normalStream;

                IPAddress ipAddress = IPAddress.Parse("192.168.1.125");
                IPEndPoint remoteEP = new IPEndPoint(ipAddress, 50000);
                connectDone.Reset();
                normalClient.Client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), normalClient);
                connectDone.WaitOne(m_TimeOut, false);

                if (!normalClient.Client.Connected)
                {
                    frm.SetLable("连接失败,请检查服务器");
                    frm.Show();
                    frm.Update();
                    this.Close();
                    //return;

                    Thread.Sleep(2000);

                    if (normalClient.Client.Connected == true)
                    {
                        normalClient.Client.Shutdown(SocketShutdown.Both);
                        normalClient.Client.Close();
                    }
                }
                else
                {
                    Byte[] SendData = new Byte[7];

                    SendData[0] = (Byte)MOBILE_PC_MESSAGE_TYPE.MPMT_EQUIPMENT_SET;
                    SendData[1] = 0x02;
                    SendData[2] = SendData[3] = SendData[4] = 0;
                    SendData[5] = eqID;
                    SendData[6] = USER_CODE;

                    normalStream = normalClient.GetStream();

                    normalStream.Write(SendData, 0, SendData.Length);

                    int bufferSize = normalClient.ReceiveBufferSize;
                    Byte[] RecvData = new Byte[bufferSize];

                    normalStream.Read(RecvData, 0, bufferSize);

                    if (RecvData[0] == (Byte)MOBILE_PC_MESSAGE_TYPE.MPMT_EQUIPMENT_SET_RESPONSE)
                    {
                    }

                    if (normalClient.Client.Connected == true)
                    {
                        normalClient.Client.Shutdown(SocketShutdown.Both);
                        normalClient.Client.Close();
                    }

                    Thread.Sleep(2000);
                }
            }
            catch (Exception err)
            {
            }
        }

 

        
        private Socket ClientSocket = null;


        private void NumberKeyDown(Byte eqID)
        {
            if (m_Processing)
                return;

            m_Processing = true;

//             ShowProcessing processFrm = new ShowProcessing(this);
// 
//             Thread processThread = new Thread(processFrm.ThreadProc);
// 
//             processThread.Start();

            ProcessingFrm notice = new ProcessingFrm(this);

            notice.Show();

            notice.Update();

            //this.Parent.Show(); 
            //MessageBox.Show("探测服务器,请稍后");
            labelInit_work.Text = "探测服务器,请稍侯";
            labelInit_work.Update();
            try
            {
                ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress ipAddress = IPAddress.Parse("192.168.1.125");
                IPEndPoint remoteEP = new IPEndPoint(ipAddress, 50000);
                connectDone.Reset();
                ClientSocket.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), ClientSocket);
                connectDone.WaitOne(10000, false);
            }
            catch (Exception err)
            {
                /*OnErrorEvent(new ErrorEventArgs(err));*/
            }

            if (ClientSocket.Connected)
            {
                Byte[] SendData = new Byte[5];

                SendData[0] = (Byte)MOBILE_PC_MESSAGE_TYPE.MPMT_INITIAL_REQUEST;
                SendData[1] = SendData[2] = SendData[3] = SendData[4] = 0;

                NetworkStream initStream;

                TcpClient initClient = new TcpClient();

                initClient.Client = ClientSocket;

                initStream = initClient.GetStream();

                initStream.Write(SendData, 0, SendData.Length);

                int bufferSize = initClient.ReceiveBufferSize;

                Byte[] RecvData = new Byte[bufferSize];

                initStream.Read(RecvData, 0, bufferSize);

                if (RecvData[0] == (Byte)MOBILE_PC_MESSAGE_TYPE.MPMT_INITIAL_RESPONSE)
                {

                    //labelInit_work.Text = "连接成功";

                    //labelInit_work.Update();
                    MessageBox.Show("连接成功");
                    labelInit_work.Text = "";
                    labelInit_work.Update();
                    initClient.Client.Shutdown(SocketShutdown.Both);
                    initClient.Client.Close();
                    CoreSender(eqID, notice);

                    notice.Close();

                    notice.Dispose();

                    m_Processing = false;

                }
            }
                else
                {
                    MessageBox.Show("连接失败,请检查服务器后重启本软件");
                    labelInit_work.Text = "";
                    labelInit_work.Update();

                    Thread.Sleep(2000);
                    notice.Close();

                    notice.Dispose();

                    //this.Hide();
                }



            //CoreSender(eqID, notice);

            //notice.Close();

            //notice.Dispose();

            m_Processing = false;

            

           
        }
       
        private void WorkFrm_KeyDown(object sender, KeyEventArgs e)
        {
            
            if (m_Processing)
            {
                e.Handled = true;

                return;
            }

            if ((e.KeyCode == System.Windows.Forms.Keys.F1))
            {
                // Soft Key 1
                // Not handled when menu is present.
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.F2))
            {
                // Soft Key 2
                // Not handled when menu is present.
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Up))
            {
                // Up
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Down))
            {
                // Down
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Left))
            {
                // Left
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Right))
            {
                // Right
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Enter))
            {
                // Enter
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D1))
            {
                // 1
                NumberKeyDown(0xa1);
                //labelInit_work.Text = "";
                //labelInit_work.Update();
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D2))
            {
                // 2
                NumberKeyDown(0xa2);

            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D3))
            {
                // 3
                NumberKeyDown(0xa3);
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D4))
            {
                // 4

                DoorAccessKeyDown(0xa4);

            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D5))
            {
                // 5

                NumberKeyDown(0xa5);

            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D6))
            {
                // 6
                NumberKeyDown(0xa6);
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D7))
            {
                // 7
                NumberKeyDown(0xa7);
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D8))
            {
                // 8
                NumberKeyDown(0xa8);
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D9))
            {
                // 9
                NumberKeyDown(0xa9);
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.F8))
            {
                // *
                /*AllLightOff();*/

                SetParam();
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.D0))
            {
                // 0
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.F9))
            {
                // #
                /*AllLightOn();*/
            }

        }

        public void SetParam()
        {
            PasswordFrm passFrm = new PasswordFrm();
            DialogResult result = passFrm.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (passFrm.textBox_Password.Text == "7993")
                {
                    ParamSettingFrm paramFrm = new ParamSettingFrm();
                    DialogResult result_s = paramFrm.ShowDialog();
                    
                    if (result_s == DialogResult.OK)
                    {
                        try
                        {
                            if (paramFrm.textBox_Number.Text == "")
                            {
                                GetPhoneNumber();
                            }
                            else
                            {
                                m_PhoneNumber = paramFrm.textBox_Number.Text;
                            }

                            if (paramFrm.textBox_TimeOut.Text == "")
                            {
                                m_TimeOut = 2000;
                            }
                            else
                            {
                                int timeout_s = Convert.ToInt32(paramFrm.textBox_TimeOut.Text);
                                m_TimeOut = (timeout_s * 1000);
                            }                            
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show("设置失败,数据格式错误");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("密码错误");
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -