Exemplo n.º 1
0
 private void btn_Save_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("确定保存配置信息?", "保存修改", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         // 保存当前所做的修改到内存m_mapChannelInfo
         string keyChannel = listBox_ChannelList.SelectedItem.ToString();
         if (m_mapChannelInfo.ContainsKey(keyChannel))
         {
             string        newChannelName = txtProtocolName.Text.Trim();
             List <string> arrayIndex     = m_mapChannelInfo.Keys.ToList();
             if (newChannelName != keyChannel && m_mapChannelInfo.ContainsKey(newChannelName))
             {
                 // 如果协议名字发生了改变,并且在协议列表中存在与它名字相同的协议,说明已经重复了
                 MessageBox.Show(string.Format("\"{0}\"已存在!不能重复添加!", newChannelName));
             }
             else
             {
                 // 判断当前的配置是否是正确的配置
                 XmlDllInfo info = m_mapChannelInfo[keyChannel];
                 info.Name     = txtProtocolName.Text.Trim();
                 info.BaseDir  = textBox_DllPath.Text.Trim();
                 info.FileName = textBox_DllFileName.Text.Trim();
                 info.Members  = m_mapChannelInfo[keyChannel].Members;
                 //info.Type = m_mapChannelInfo[keyChannel].Type;
                 if (Protocol.Manager.ProtocolManager.AssertDllValid(info))
                 {
                     SetModified(false);
                     // dll有效
                     m_mapChannelInfo.Remove(keyChannel);
                     // 并添加到当前的Map中
                     m_mapChannelInfo.Add(newChannelName, info);
                     // 并更新ListView中的显示名字
                     listBox_ChannelList.Items[listBox_ChannelList.Items.IndexOf(keyChannel)] = newChannelName;
                     // 同时更新m_dllCollections内的内容,由于都是引用类型,map和collection中的内容一致
                     //for (int i = 0; i < m_dllCollections.Infos.Count; ++i)
                     //{
                     //    if (m_dllCollections.Infos[i].Name == keyChannel)
                     //    {
                     //        // 更新
                     //        m_dllCollections.Infos[i] = info;
                     //        break;
                     //    }
                     //}
                 }
                 else
                 {
                     // dll无效
                     MessageBox.Show("无效的dll文件");
                 }
             }
         }
     }
 }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
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();
            }
        }