Esempio n. 1
0
        /// <summary>
        /// 保存配置-所有配置
        /// </summary>
        /// <param name="systemConfig">配置对象</param>
        /// <returns>String</returns>
        public string SaveConfig(AMSystemConfig systemConfig)
        {
            try
            {
                if (!systemConfig.LoginSavePass) //如果不是自动登陆,要清除自动登陆的密码
                {
                    systemConfig.LoginPassword = "";
                }

                AuthDao.ADSecret ads = new AuthDao.ADSecret();//创建加密类
                systemConfig.ConnectionString = ads.DesEncrypt(systemConfig.ConnectionString, "JinDi123");//加密连接字符串
                //systemConfig.AutoPassword = ads.MD5Encrypt(systemConfig.AutoPassword);//加密用户密码
                string FileName = Environment.CurrentDirectory + "\\Config.dat"; //配置文件保存路径与文件名
                Stream fStr = new FileStream(FileName, FileMode.Create);
                BinaryFormatter bf = new BinaryFormatter();
                fStr.Position = 0;
                bf.Serialize(fStr, systemConfig);
                fStr.Close();
                return "true";
            }
            catch (Exception x)
            {
                return "SaveConfig:" + x.Message;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 单项保存配置
        /// </summary>
        /// <param name="Item">要保存的数据的类型</param>
        /// <param name="a">可以转换成字符串的数据</param>
        /// <param name="b">是否保存密码,可以不设</param>
        /// <returns></returns>
        public string SaveConfig(ConfigItem Item, object a, bool b=false)
        {
            try
            {
                //是否有配置文件,没有就新建
                HasConfig();
                AMSystemConfig amsc = new AMSystemConfig();
                ReadConfig(out amsc);

                switch (Item)
                {
                    case ConfigItem.ConnectionString:
                        amsc.ConnectionString = (string)a;
                        break;
                    case ConfigItem.LoginUserName:
                        amsc.LoginUserNames = (string)a;
                        break;
                    case ConfigItem.LoginPassword:
                        if (b)
                        {
                            amsc.LoginSavePass = b;
                            amsc.LoginPassword = (string)a;
                        }
                        else
                        {
                            amsc.LoginPassword = "";
                        }
                        break;
                    default:
                        break;
                }
                AuthDao.ADSecret ads = new AuthDao.ADSecret();//创建加密类
                amsc.ConnectionString = ads.DesEncrypt(amsc.ConnectionString, "JinDi123");//加密连接字符串
                string FileName = Environment.CurrentDirectory + "\\Config.dat"; //配置文件保存路径与文件名
                Stream fStr = new FileStream(FileName, FileMode.Create);
                BinaryFormatter bf = new BinaryFormatter();
                fStr.Position = 0;
                bf.Serialize(fStr, amsc);
                fStr.Close();

                return "true";
            }
            catch (Exception x)
            {
                return "SaveConfig:" + x.Message;
            }
        }