1 Star 0 Fork 0

loveyu/JiaowuHelper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Config.cs 2.29 KB
一键复制 编辑 原始数据 按行查看 历史
loveyu 提交于 2013-12-25 22:41 . Update first to 1.1.0
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.IO;
using System.Configuration;
namespace JiaowuHelper
{
class ConfigInfo
{
public string url = "";
public string username = "";
public string password = "";
public bool autoLogin = false;
}
class Config
{
public static ConfigInfo get()
{
ConfigInfo ci = new ConfigInfo();
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings.AllKeys.Contains("user"))
ci.username = config.AppSettings.Settings["user"].Value;
if (config.AppSettings.Settings.AllKeys.Contains("url"))
ci.url = config.AppSettings.Settings["url"].Value;
if (config.AppSettings.Settings.AllKeys.Contains("password"))
ci.password = config.AppSettings.Settings["password"].Value;
if (config.AppSettings.Settings.AllKeys.Contains("autoLogin"))
ci.autoLogin = Boolean.Parse(config.AppSettings.Settings["autoLogin"].Value);
return ci;
}
public static bool save(ConfigInfo ci)
{
try
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings.AllKeys.Contains("user"))
config.AppSettings.Settings["user"].Value = ci.username;
else
config.AppSettings.Settings.Add("user", ci.username);
if (config.AppSettings.Settings.AllKeys.Contains("url"))
config.AppSettings.Settings["url"].Value = ci.url;
else
config.AppSettings.Settings.Add("url", ci.url);
if (config.AppSettings.Settings.AllKeys.Contains("password"))
config.AppSettings.Settings["password"].Value = ci.password;
else
config.AppSettings.Settings.Add("password", ci.password);
if (config.AppSettings.Settings.AllKeys.Contains("autoLogin"))
config.AppSettings.Settings["autoLogin"].Value = ci.autoLogin.ToString();
else
config.AppSettings.Settings.Add("autoLogin", ci.autoLogin.ToString());
config.Save(ConfigurationSaveMode.Minimal);
return true;
}
catch
{
return false;
}
}
public static bool delete() {
try
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
File.Delete(config.FilePath);
return true;
}
catch {
return false;
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/iloveyulove/JiaowuHelper.git
git@gitee.com:iloveyulove/JiaowuHelper.git
iloveyulove
JiaowuHelper
JiaowuHelper
master

搜索帮助