Пример #1
0
        /// <summary>
        /// 加载数据面板
        /// </summary>
        /// <returns></returns>
        public static bool LoadFaceDataPanel(bool commType)
        {
            if (commType)
            {
                rtxtMsg = new KJRichTextBox[1];
                rtxtMsgo = new KJRichTextBox[1];
                rtxtMsgc = new KJRichTextBox[1];
                //rtxtMsge = new KJRichTextBox[1];

                // 标准数据面板
                TabPage tpSerialPort = new TabPage("环网");

                rtxtMsg[0] = new KJRichTextBox("CriterionData_" + 0);
                rtxtMsg[0].ReadOnly = true;
                rtxtMsg[0].Dock = DockStyle.Fill;
                tpSerialPort.Controls.Add(rtxtMsg[0]);

                tcMsg.Controls.Add(tpSerialPort);

                // 中文数据面版
                TabPage tpSerialPortC = new TabPage("环网(c)");

                rtxtMsgc[0] = new KJRichTextBox("ChineseData_" + 0);
                rtxtMsgc[0].ReadOnly = true;
                rtxtMsgc[0].Dock = DockStyle.Fill;
                tpSerialPortC.Controls.Add(rtxtMsgc[0]);

                tcMsg.Controls.Add(tpSerialPortC);

                // 原始回送数据面板
                TabPage tpSerialPortO = new TabPage("环网(o)");

                rtxtMsgo[0] = new KJRichTextBox("OrgData_" + 0);
                rtxtMsgo[0].ReadOnly = true;
                rtxtMsgo[0].Dock = DockStyle.Fill;
                tpSerialPortO.Controls.Add(rtxtMsgo[0]);

                tcMsg.Controls.Add(tpSerialPortO);

                // 错误数据面板
                //TabPage tpSerialPortE = new TabPage("环网(e)");

                //rtxtMsge[0] = new KJRichTextBox("ErrData_" + 0);
                //rtxtMsge[0].ReadOnly = true;
                //rtxtMsge[0].Dock = DockStyle.Fill;
                //tpSerialPortE.Controls.Add(rtxtMsge[0]);

                //tcMsg.Controls.Add(tpSerialPortE);

            }
            else
            {
                if (memSerialPort != null)
                {
                    // 根据串口数量构建创建面板的数量
                    int iSerialPortLength = memSerialPort.Length;

                    rtxtMsg = new KJRichTextBox[iSerialPortLength];
                    rtxtMsgo = new KJRichTextBox[iSerialPortLength];
                    rtxtMsgc = new KJRichTextBox[iSerialPortLength];
                    rtxtMsge = new KJRichTextBox[iSerialPortLength];

                    for (int i = 0; i < iSerialPortLength; i++)
                    {
                        // 标准数据面板
                        TabPage tpSerialPort = new TabPage(memSerialPort[i].PortName);

                        rtxtMsg[i] = new KJRichTextBox("CriterionData_" + i);
                        rtxtMsg[i].ReadOnly = true;
                        rtxtMsg[i].Dock = DockStyle.Fill;
                        tpSerialPort.Controls.Add(rtxtMsg[i]);

                        tcMsg.Controls.Add(tpSerialPort);

                        // 中文数据面版
                        TabPage tpSerialPortC = new TabPage(memSerialPort[i].PortName + "(c)");

                        rtxtMsgc[i] = new KJRichTextBox("ChineseData_" + i);
                        rtxtMsgc[i].ReadOnly = true;
                        rtxtMsgc[i].Dock = DockStyle.Fill;
                        tpSerialPortC.Controls.Add(rtxtMsgc[i]);

                        tcMsg.Controls.Add(tpSerialPortC);

                        // 原始回送数据面板
                        TabPage tpSerialPortO = new TabPage(memSerialPort[i].PortName + "(o)");

                        rtxtMsgo[i] = new KJRichTextBox("OrgData_" + i);
                        rtxtMsgo[i].ReadOnly = true;
                        rtxtMsgo[i].Dock = DockStyle.Fill;
                        tpSerialPortO.Controls.Add(rtxtMsgo[i]);

                        tcMsg.Controls.Add(tpSerialPortO);

                        // 错误数据面板
                        //TabPage tpSerialPortE = new TabPage(memSerialPort[i].PortName + "(e)");

                        //rtxtMsge[i] = new KJRichTextBox("ErrData_" + i);
                        //rtxtMsge[i].ReadOnly = true;
                        //rtxtMsge[i].Dock = DockStyle.Fill;

                        //tpSerialPortE.Controls.Add(rtxtMsge[i]);

                        //tcMsg.Controls.Add(tpSerialPortE);
                    }
                }
            }
            return true;
        }
Пример #2
0
        /// <summary>
        /// 同步功能菜单
        /// </summary>
        public void MenuSyncFunction(KJRichTextBox _RtxtSysMsg)
        {
            if (frmMain.commType)
            {
                if (StartTcp.m_TcpClientPort != null)
                {
                    ToolStripMenuItem menuItemSerialPortPause = new ToolStripMenuItem("环网发送暂停");

                    menuItemSerialPortPause.Click += delegate(object sender, EventArgs e)
                    {
                        if (StartTcp.m_TcpClientPort.IsPause)
                        {
                            ((ToolStripMenuItem)(sender)).Text = "环网发送暂停";
                        }
                        else
                        {
                            ((ToolStripMenuItem)(sender)).Text = "环网继续发送";
                        }

                        StartTcp.m_TcpClientPort.IsPause = !StartTcp.m_TcpClientPort.IsPause;
                        if (StartTcp.m_TcpClientPort.IsPause == false)
                        {
                            StartTcp.m_TcpClientPort.SendCmd();
                        }
                    };
                    menuItemPause.DropDownItems.Add(menuItemSerialPortPause);
                }
            }
            else
            {
                // 暂停子菜单
                if (StartPort.s_serialPort != null)
                {
                    ToolStripMenuItem[] menuItemSerialPortPause = new ToolStripMenuItem[StartPort.s_serialPort.Length];
                    for (int i = 0; i < StartPort.s_serialPort.Length; i++)
                    {
                        menuItemSerialPortPause[i] = new ToolStripMenuItem(StartPort.s_serialPort[i].PortName + " 发送暂停");
                        menuItemSerialPortPause[i].Tag = i;
                        menuItemSerialPortPause[i].Click += delegate(object sender, EventArgs e)
                        {
                            if (StartPort.s_serialPort[int.Parse(((ToolStripMenuItem)(sender)).Tag.ToString())].IsPause)
                            {
                                ((ToolStripMenuItem)(sender)).Text = StartPort.s_serialPort[int.Parse(((ToolStripMenuItem)(sender)).Tag.ToString())].PortName + " 发送暂停";
                            }
                            else
                            {
                                ((ToolStripMenuItem)(sender)).Text = StartPort.s_serialPort[int.Parse(((ToolStripMenuItem)(sender)).Tag.ToString())].PortName + " 继续发送";
                            }

                            StartPort.s_serialPort[int.Parse(((ToolStripMenuItem)(sender)).Tag.ToString())].IsPause = !StartPort.s_serialPort[int.Parse(((ToolStripMenuItem)(sender)).Tag.ToString())].IsPause;
                            if (StartPort.s_serialPort[int.Parse(((ToolStripMenuItem)(sender)).Tag.ToString())].IsPause == false)
                            {
                                StartPort.s_serialPort[int.Parse(((ToolStripMenuItem)(sender)).Tag.ToString())].SendCmd();
                            }
                        };
                        menuItemPause.DropDownItems.Add(menuItemSerialPortPause[i]);
                    }
                }
            }

            // 启动应用程序
            menuItemDataCopy.Click += delegate
            {

                string strTran = string.Empty;  // 需要传送的内容
                bool blnNotepad = false;         // 记事本成功启动

                #region [ 启动记事本 ]

                System.Diagnostics.Process Proc;

                try
                {
                    // 启动记事本
                    Proc = new System.Diagnostics.Process();
                    Proc.StartInfo.FileName = "notepad.exe";
                    Proc.StartInfo.UseShellExecute = false;
                    Proc.StartInfo.RedirectStandardInput = true;
                    Proc.StartInfo.RedirectStandardOutput = true;

                    Proc.Start();

                    blnNotepad = true;
                }
                catch
                {
                    Proc = null;
                }

                #endregion

                #region [ 系统消息面板 ]

                if (_RtxtSysMsg != null)
                {
                    // 如果记事本启动成功,则将系统消息面板中的数据提交给记事本,否则发送到内存中。
                    if (blnNotepad)
                    {
                        strTran = _RtxtSysMsg.Text.Replace("\n", "\r\n");
                    }
                    else
                    {
                        _RtxtSysMsg.SelectAll();
                        _RtxtSysMsg.Copy();
                    }
                }

                #endregion

                #region [ 数据面板 ]
                if (frmMain.commType)
                {
                    // 如果记事本启动成功,则将数据面板中的数据提交给记事本,否则发送到内存中。
                    if (StartTcp.m_TcpClientPort.RTxtMsg != null)
                    {
                        if (StartTcp.m_TcpClientPort.RTxtMsg.Focused)
                        {
                            if (blnNotepad)
                            {
                                strTran = StartTcp.m_TcpClientPort.RTxtMsg.Text.Replace("\n", "\r\n");
                            }
                            else
                            {
                                StartTcp.m_TcpClientPort.RTxtMsg.SelectAll();
                                StartTcp.m_TcpClientPort.RTxtMsg.Copy();
                            }

                        }
                    }

                    if (StartTcp.m_TcpClientPort.RTxtMsgc != null)
                    {
                        if (StartTcp.m_TcpClientPort.RTxtMsgc.Focused)
                        {
                            if (blnNotepad)
                            {
                                strTran = StartTcp.m_TcpClientPort.RTxtMsgc.Text.Replace("\n", "\r\n");
                            }
                            else
                            {
                                StartTcp.m_TcpClientPort.RTxtMsgc.SelectAll();
                                StartTcp.m_TcpClientPort.RTxtMsgc.Copy();
                            }

                        }
                    }

                    if (StartTcp.m_TcpClientPort.RTxtMsge != null)
                    {
                        if (StartTcp.m_TcpClientPort.RTxtMsge.Focused)
                        {
                            if (blnNotepad)
                            {
                                strTran = StartTcp.m_TcpClientPort.RTxtMsge.Text.Replace("\n", "\r\n");
                            }
                            else
                            {
                                StartTcp.m_TcpClientPort.RTxtMsge.SelectAll();
                                StartTcp.m_TcpClientPort.RTxtMsge.Copy();
                            }

                        }
                    }

                    if (StartTcp.m_TcpClientPort.RTxtMsgo != null)
                    {
                        if (StartTcp.m_TcpClientPort.RTxtMsgo.Focused)
                        {
                            if (blnNotepad)
                            {
                                strTran = StartTcp.m_TcpClientPort.RTxtMsgo.Text.Replace("\n", "\r\n");
                            }
                            else
                            {
                                StartTcp.m_TcpClientPort.RTxtMsgo.SelectAll();
                                StartTcp.m_TcpClientPort.RTxtMsgo.Copy();
                            }

                        }
                    }
                }
                else
                {
                    // 如果记事本启动成功,则将数据面板中的数据提交给记事本,否则发送到内存中。
                    for (int i = 0; i < StartPort.s_serialPort.Length; i++)
                    {
                        if (StartPort.s_serialPort[i].RTxtMsg != null)
                        {
                            if (StartPort.s_serialPort[i].RTxtMsg.Focused)
                            {
                                if (blnNotepad)
                                {
                                    strTran = StartPort.s_serialPort[i].RTxtMsg.Text.Replace("\n", "\r\n");
                                }
                                else
                                {
                                    StartPort.s_serialPort[i].RTxtMsg.SelectAll();
                                    StartPort.s_serialPort[i].RTxtMsg.Copy();
                                }
                                break;
                            }
                        }

                        if (StartPort.s_serialPort[i].RTxtMsgc != null)
                        {
                            if (StartPort.s_serialPort[i].RTxtMsgc.Focused)
                            {
                                if (blnNotepad)
                                {
                                    strTran = StartPort.s_serialPort[i].RTxtMsgc.Text.Replace("\n", "\r\n");
                                }
                                else
                                {
                                    StartPort.s_serialPort[i].RTxtMsgc.SelectAll();
                                    StartPort.s_serialPort[i].RTxtMsgc.Copy();
                                }
                                break;
                            }
                        }

                        if (StartPort.s_serialPort[i].RTxtMsge != null)
                        {
                            if (StartPort.s_serialPort[i].RTxtMsge.Focused)
                            {
                                if (blnNotepad)
                                {
                                    strTran = StartPort.s_serialPort[i].RTxtMsge.Text.Replace("\n", "\r\n");
                                }
                                else
                                {
                                    StartPort.s_serialPort[i].RTxtMsge.SelectAll();
                                    StartPort.s_serialPort[i].RTxtMsge.Copy();
                                }
                                break;
                            }
                        }

                        if (StartPort.s_serialPort[i].RTxtMsgo != null)
                        {
                            if (StartPort.s_serialPort[i].RTxtMsgo.Focused)
                            {
                                if (blnNotepad)
                                {
                                    strTran = StartPort.s_serialPort[i].RTxtMsgo.Text.Replace("\n", "\r\n");
                                }
                                else
                                {
                                    StartPort.s_serialPort[i].RTxtMsgo.SelectAll();
                                    StartPort.s_serialPort[i].RTxtMsgo.Copy();
                                }
                                break;
                            }
                        }
                    }
                }
                #endregion

                #region [ 传递数据给记事本 ]

                if (blnNotepad && Proc != null)
                {
                    // 调用 API, 传递数据
                    while (Proc.MainWindowHandle == IntPtr.Zero)
                    {
                        Proc.Refresh();
                    }

                    IntPtr vHandle = FindWindowEx(Proc.MainWindowHandle, IntPtr.Zero, "Edit", null);

                    // 传递数据给记事本
                    SendMessage(vHandle, WM_SETTEXT, 0, strTran);
                }

                #endregion

            };
        }
Пример #3
0
        /// <summary>
        /// 加载界面布局
        /// </summary>
        /// <returns></returns>
        public static bool LoadFaceLayout(FrmMain frmMain, KJRichTextBox rtxtSysMsg)
        {
            _RtxtSysMsg = rtxtSysMsg;

            // 加载数据面板
            Panel pnl = new Panel();
            pnl.Dock = DockStyle.Fill;
            //pnl.BackColor = System.Drawing.Color.YellowGreen;
            frmMain.Controls.Add(pnl);

            #region [ 数据面板: 加载系统消息面板 ]

            // 加载数据面板中的内容

            tcMsg.Dock = DockStyle.Fill;

            rtxtSysMsg.Visible = false;
            pnl.Controls.Add(rtxtSysMsg);

            // 系统消息面板
            //TabPage tpSysMsg = new TabPage("系统消息");
            //rtxtSysMsg.Dock = DockStyle.Fill;
            //tpSysMsg.Controls.Add(rtxtSysMsg);
            //tcMsg.Controls.Add(tpSysMsg);

            pnl.Controls.Add(tcMsg);

            #endregion

            // 加载传输分站面板
            gbBox.Text = "被巡检的传输分站信息";
            gbBox.Dock = DockStyle.Left;
            gbBox.Width = 175;
            frmMain.Controls.Add(gbBox);

            return true;
        }