コード例 #1
0
ファイル: SignAc.cs プロジェクト: burstas/rmps
        /// <summary>
        /// 打开(&O)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MiOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog fdOpen = Main.OpenFileDialog;
            fdOpen.Filter = "阿木密码箱配置文件|*.cfg";
            fdOpen.FileName = CApp.AMON_CFG;
            fdOpen.InitialDirectory = _UserModel.SysHome;
            fdOpen.Multiselect = false;
            if (DialogResult.OK != fdOpen.ShowDialog(_Main))
            {
                return;
            }

            string path = fdOpen.FileName;
            if (!File.Exists(path))
            {
                Main.ShowAlert("无法访问您选择的文件!");
                return;
            }

            string file = (Path.GetFileName(path) ?? "").ToLower();
            if (CApp.AMON_CFG.ToLower() != file)
            {
                Main.ShowAlert(string.Format("请确认您选择的文件名是否为:{0}!", CApp.AMON_CFG));
                return;
            }

            DFEngine prop = new DFEngine();
            prop.Load(path);
            string name = prop.Get(CApp.AMON_CFG_NAME);
            string code = prop.Get(CApp.AMON_CFG_CODE);
            if (!CharUtil.IsValidateCode(code) || !CharUtil.IsValidate(name))
            {
                Main.ShowAlert("请确认您选择的数据路径是否正确!");
                return;
            }

            prop.Clear();
            string sysFile = Path.Combine(_UserModel.SysHome, CApp.AMON_SYS);
            prop.Load(sysFile);
            prop.Set(string.Format(CApp.AMON_SYS_CODE, name), code);
            path = Path.GetDirectoryName(path);
            if (path.StartsWith(Application.StartupPath))
            {
                path = path.Substring(Application.StartupPath.Length + 1);
            }
            prop.Set(string.Format(CApp.AMON_SYS_HOME, name), path);
            prop.Save(sysFile);
        }