コード例 #1
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            EditConfName = "";
            ConfEditor ce = new ConfEditor(this, ConfEditor.EditType.New);

            ce.ShowDialog(this);
        }
コード例 #2
0
        private void btnCopy_Click(object sender, EventArgs e)
        {
            ConfEditor ce = new ConfEditor(this, ConfEditor.EditType.Copy);

            if (-1 == confList.SelectedIndex)
            {
                showRedTip("在下面的列表选择一个配置");
                return;
            }
            EditConfName = confList.SelectedItem.ToString();
            ce.ShowDialog(this);
        }
コード例 #3
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            ConfEditor ce = new ConfEditor(this, ConfEditor.EditType.Rename);

            if (-1 == confList.SelectedIndex)
            {
                showRedTip("在下面的列表选择一个配置");
                return;
            }
            if (confList.SelectedItem.ToString() == ".cfg")
            {
                showRedTip("缺省配置不能重命名");
                return;
            }
            EditConfName = confList.SelectedItem.ToString();
            ce.ShowDialog(this);
        }
コード例 #4
0
        public string SetConfName(ConfEditor editor, string name)
        {
            if (name == null || name.Length < 4)
            {
                return("名称必须以 '.cfg' 作为后缀");
            }
            string ext = name.Substring(name.Length - 4, 4);

            if (ext.ToLower() != ".cfg")
            {
                return("名称必须以 '.cfg' 作为后缀");
            }
            string path  = ".\\conf\\" + name;
            bool   exist = File.Exists(path);

            if (editor.Type == ConfEditor.EditType.New)
            {
                //新建配置
                if (exist)
                {
                    return("名称为 [" + name + "] 的配置已经存在,请使用其它名称");
                }
                File.Create(path);
                refreshAllConfList(ConfListChangeType.Add, name);
            }
            else if (editor.Type == ConfEditor.EditType.Copy)
            {
                if (exist)
                {
                    return("名称为 [" + name + "] 的配置已经存在,请使用其它名称");
                }
                string src = ".\\conf\\" + EditConfName;
                try {
                    //File.Copy(src, path);
                    FileInfo file = new FileInfo(src);
                    if (file.Exists)
                    {
                        file.CopyTo(path);
                    }
                    else
                    {
                        return("源文件不存在: " + src);
                    }
                } catch (Exception e) {
                    return(e.Message + "(不能是 COM1 等串口名称)");
                }
                refreshAllConfList(ConfListChangeType.Add, name);
            }
            else
            {
                //编辑配置
                if (name.ToLower() == EditConfName.ToLower())
                {
                    //名字没有变化
                    return("");
                }
                if (exist)
                {
                    return("名称为 [" + name + "] 的配置已经存在,请使用其它名称");
                }
                FileInfo fi = new FileInfo(".\\conf\\" + EditConfName);

                try {
                    fi.MoveTo(path);
                } catch (Exception e) {
                    return(e.Message + "(不能是 COM1 等串口名称)");
                }
                refreshAllConfList(ConfListChangeType.Rename, name, EditConfName);
            }
            return("");
        }