Esempio n. 1
0
        private void btnChannelSaveAddNew_Click(object sender, EventArgs e)
        {
            string protocolName = this.txt_ChannelProtocolName.Text.Trim();

            if (String.IsNullOrEmpty(protocolName))
            {
                MessageBox.Show("协议名不能为空!");
                return;
            }
            //  string stringThePath1 = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
            // string baseDir = stringEXEPath;
            // string baseDir = this.txt_ChannelDllFileName.Text.Trim();
            string baseDir  = this.txt_ChannelDllPath.Text.Trim();
            string fileName = this.txt_ChannelDllFileName.Text.Trim();

            if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(baseDir))
            {
                MessageBox.Show("请选择DLL!");
                return;
            }
            string tag = this.cmb_ChannelInterfaceNames.Text.Trim();

            string path = string.Format(@"{0}\{1}", baseDir, fileName);

            string       className     = string.Empty;
            string       interfaceName = string.Empty;
            string       dllInfoTag    = string.Empty;
            EDllType4Xml dllInfoType   = EDllType4Xml.none;

            if (!ProtocolManager.AssertChannelProtocolDllValid(path,
                                                               tag,
                                                               out className,
                                                               out interfaceName,
                                                               out dllInfoTag,
                                                               out dllInfoType))
            {
                MessageBox.Show("不是合法的DLL!请重新添加!");
                this.txt_ChannelDllPath.Text     = string.Empty;
                this.txt_ChannelDllFileName.Text = string.Empty;
                return;
            }
            this.txt_ChannelClassName.Text = className;

            XmlMemberInfos members = new XmlMemberInfos();

            members.Add(new XmlMember()
            {
                ClassName     = className,
                Tag           = dllInfoTag,
                InterfaceName = interfaceName
            });
            // baseDir = "..";
            XmlDllInfo info = new XmlDllInfo()
            {
                BaseDir  = baseDir,
                FileName = fileName,
                Enabled  = true,
                DllType  = dllInfoType,
                Name     = protocolName,
                Type     = "channel",
                Members  = members,
                Coms     = new List <int>(),
                Ports    = new List <CXMLPort>()
            };

            if (m_mapChannelInfo.ContainsKey(protocolName))
            {
                MessageBox.Show(string.Format("通讯方式{0}已存在,不能重复添加!", protocolName));
                return;
            }
            if (MessageBox.Show("确定添加通讯方式?", "添加", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                m_dllCollections.Infos.Add(info);
                ResetChannelPanel();
            }
        }
Esempio n. 2
0
        private void btn_ChannelBrowse_Click(object sender, EventArgs e)
        {
            // 浏览本地dll文件
            //m_openFileDialog.InitialDirectory = Directory.GetCurrentDirectory();// 设置起始目录
            if (!txt_ChannelDllPath.Text.Equals(""))
            {
                m_openFileDialog.InitialDirectory = txt_ChannelDllPath.Text;
            }

            //m_openFileDialog.InitialDirectory = @"E:\陈乐宁相关\水文监测\HelloWorld.1228\MDITest\bin\Debug";

            m_openFileDialog.FileName = txt_ChannelDllFileName.Text;
            //  m_openFileDialog.InitialDirectory = Application.StartupPath;
            string       stringThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
            DialogResult result        = m_openFileDialog.ShowDialog();

            if (result == DialogResult.OK && (!m_openFileDialog.FileName.ToString().Equals("")))
            {
                // 显示路径
                this.txt_ChannelDllFileName.Text = Path.GetFileName(m_openFileDialog.FileName);
                this.txt_ChannelDllPath.Text     = Path.GetDirectoryName(m_openFileDialog.FileName);
                //  this.txt_ChannelDllPath.Text = "..";

                //  更新接口实现类型
                string tag = this.cmb_ChannelInterfaceNames.Text;
                // string baseDir = this.txt_ChannelDllPath.Text.Trim();
                string baseDir  = stringThePath;
                string fileName = this.txt_ChannelDllFileName.Text.Trim();
                string path     = string.Format(@"{0}\{1}", baseDir, fileName);

                string       className     = string.Empty;
                string       interfaceName = string.Empty;
                string       dllInfoTag    = string.Empty;
                EDllType4Xml dllInfoType   = EDllType4Xml.none;
                if (!ProtocolManager.AssertChannelProtocolDllValid(path,
                                                                   tag,
                                                                   out className,
                                                                   out interfaceName,
                                                                   out dllInfoTag,
                                                                   out dllInfoType))
                {
                    MessageBox.Show("不是合法的DLL!请重新添加!");
                    this.txt_ChannelDllPath.Text     = string.Empty;
                    this.txt_ChannelDllFileName.Text = string.Empty;
                    return;
                }
                this.txt_ChannelClassName.Text = className;
                // this.txt_ChannelProtocolName.Text = this.txt_ChannelDllFileName.Text.Replace(".dll", "");
                if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.Gprs.dll")
                {
                    this.txt_ChannelProtocolName.Text = "SX-GPRS";
                }
                else if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.HDGprs.dll")
                {
                    this.txt_ChannelProtocolName.Text = "HD-GPRS";
                }

                else if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.Gsm.dll")
                {
                    this.txt_ChannelProtocolName.Text = "GSM";
                }
                else if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.Beidou.dll")
                {
                    this.txt_ChannelProtocolName.Text = "Beidou-Normal";
                }
                else if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.Beidou500.dll")
                {
                    this.txt_ChannelProtocolName.Text = "Beidou-500";
                }
                else if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.Transparen.dll")
                {
                    this.txt_ChannelProtocolName.Text = "Transparen";
                }


                else
                {
                    MessageBox.Show("不是合法的DLL!请重新添加!");
                    this.txt_ChannelDllPath.Text     = string.Empty;
                    this.txt_ChannelDllFileName.Text = string.Empty;
                    return;
                }
            }
        }