Ejemplo n.º 1
0
        private void btn_DataBrowse_Click(object sender, EventArgs e)
        {
            this.txt_DataProtocolName.ReadOnly = true;
            this.txt_DataProtocolName.Enabled  = false;
            // 浏览本地dll文件
            if (!this.txt_DataDllPath.Text.Equals(""))
            {
                m_openFileDialog.InitialDirectory = txt_ChannelDllPath.Text;
            }

            m_openFileDialog.FileName = this.txt_DataDllFileName.Text;

            DialogResult result = m_openFileDialog.ShowDialog();

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

                //  更新接口实现类型
                string path = string.Format(@"{0}\{1}", this.txt_DataDllPath.Text.Trim(), this.txt_DataDllFileName.Text.Trim());
                string up, down, udisk, flash, soil;
                up = down = udisk = flash = soil = string.Empty;
                if (!ProtocolManager.AssertDataProtocolDllValid(path, out up, out down, out udisk, out flash, out soil))
                {
                    MessageBox.Show("不是合法的DLL!请重新添加!");
                    this.txt_DataDllPath.Text     = string.Empty;
                    this.txt_DataDllFileName.Text = string.Empty;
                    return;
                }
                //  更新界面ui
                this.txt_DataUp.Text    = up;
                this.txt_DataDown.Text  = down;
                this.txt_DataUDisk.Text = udisk;
                this.txt_DataFlash.Text = flash;
                if (this.txt_DataDllFileName.Text == "Protocol.Data.Lib.dll")
                {
                    this.txt_DataProtocolName.Text = "LN";
                }
                else if (this.txt_DataDllFileName.Text == "Protocol.Data.XYJBX.dll")
                {
                    this.txt_DataProtocolName.Text = "XYJBX";
                }
                else if (this.txt_DataDllFileName.Text == "Protocol.Data.ZYJBX.dll")
                {
                    this.txt_DataProtocolName.Text = "ZYJBX";
                }
                else if (this.txt_DataDllFileName.Text == "Protocol.Data.SXDZ.dll")
                {
                    this.txt_DataProtocolName.Text = "SXDZ";
                }
                else if (this.txt_DataDllFileName.Text == "Protocol.Data.HJJBX.dll")
                {
                    this.txt_DataProtocolName.Text = "HJJBX";
                }
            }
        }
Ejemplo n.º 2
0
        private void btnDataSaveAddNew_Click(object sender, EventArgs e)
        {
            string protocolName = this.txt_DataProtocolName.Text.Trim();

            if (String.IsNullOrEmpty(protocolName))
            {
                MessageBox.Show("协议名不能为空!");
                return;
            }
            string filename = this.txt_DataDllFileName.Text.Trim();
            string basedir  = this.txt_DataDllPath.Text.Trim();

            if (String.IsNullOrEmpty(filename) || String.IsNullOrEmpty(basedir))
            {
                MessageBox.Show("请选择DLL!");
                return;
            }
            string path = string.Format(@"{0}\{1}", basedir, filename);
            string up, down, udisk, flash, soil;

            up = down = udisk = flash = soil = string.Empty;
            if (!ProtocolManager.AssertDataProtocolDllValid(path, out up, out down, out udisk, out flash, out soil))
            {
                MessageBox.Show("不是合法的DLL!请重新添加!");
                this.txt_DataDllPath.Text     = string.Empty;
                this.txt_DataDllFileName.Text = string.Empty;
                return;
            }
            //  更新界面ui
            this.txt_DataUp.Text    = up;
            this.txt_DataDown.Text  = down;
            this.txt_DataUDisk.Text = udisk;
            this.txt_DataFlash.Text = flash;

            XmlMemberInfos members = new XmlMemberInfos();

            members.Add(new XmlMember()
            {
                ClassName     = this.txt_DataUDisk.Text.Trim(),
                Tag           = CS_DEFINE.TAG_DATA_UBatch,
                InterfaceName = CS_DEFINE.I_DATA_UDISK_BATCH
            });
            members.Add(new XmlMember()
            {
                ClassName     = this.txt_DataDown.Text.Trim(),
                Tag           = CS_DEFINE.TAG_DATA_Down,
                InterfaceName = CS_DEFINE.I_DATA_DOWN
            });
            members.Add(new XmlMember()
            {
                ClassName     = this.txt_DataFlash.Text.Trim(),
                Tag           = CS_DEFINE.TAG_DATA_FlashBatch,
                InterfaceName = CS_DEFINE.I_DATA_FLASH_BATCH
            });
            members.Add(new XmlMember()
            {
                ClassName     = this.txt_DataUp.Text.Trim(),
                Tag           = CS_DEFINE.TAG_DATA_Up,
                InterfaceName = CS_DEFINE.I_DATA_UP
            });
            members.Add(new XmlMember()
            {
                ClassName     = soil.Trim(),
                Tag           = CS_DEFINE.Tag_Data_Soil,
                InterfaceName = CS_DEFINE.I_DATA_SOIL
            });

            XmlDllInfo info = new XmlDllInfo()
            {
                BaseDir  = basedir,
                Coms     = new List <int>(),
                FileName = filename,
                Enabled  = true,
                DllType  = EDllType4Xml.none,
                Name     = protocolName,
                Type     = "data",
                Members  = members,
                Ports    = new List <CXMLPort>()
            };

            if (this.m_mapChannelInfo.ContainsKey(protocolName))
            {
                MessageBox.Show(string.Format("数据协议{0}已存在,不能重复添加!", protocolName));
                return;
            }
            if (MessageBox.Show("确定添加通讯方式?", "添加", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                m_dllCollections.Infos.Add(info);
                ResetDataPanel();
            }
        }