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(); } }
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(); } }