/// <summary> /// 保存登录信息 /// </summary> private void SaveLoginSetting() { var localSetting = Config.LocalSetting; var testSetting = (TestOption)AppSettings["DefaultTestOption"]; localSetting.DefaultTestOption = testSetting; localSetting.ScriptErrorsSuppressed = (bool)AppSettings["ScriptErrorsSuppressed"]; localSetting.AutoChangeProxyInterval = (int)AppSettings["AutoChangeProxyInterval"]; localSetting.TestTimeOut = (int)AppSettings["TestTimeOut"]; localSetting.TestThreadsCount = (int)AppSettings["TestThreadsCount"]; localSetting.AutoProxySpeed = (int)AppSettings["AutoProxySpeed"]; localSetting.ExportMode = (string)AppSettings["ExportMode"]; localSetting.IsUseSystemProxy = (bool)AppSettings["IsUseSystemProxy"]; localSetting.LanguageFileName = (string)AppSettings["LanguageFileName"]; localSetting.UserAgent = string.IsNullOrEmpty((string)AppSettings["UserAgent"]) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)" : (string)AppSettings["UserAgent"]; var dal = new SettingDAL(); var model = dal.FindAll().FirstOrDefault(); var res = 0; if (model == null) { res = dal.Insert(localSetting); } else { TestOption searchSetting = model.TestOptionsList.FirstOrDefault(temp => temp.TestUrl == testSetting.TestUrl); if (searchSetting != null && searchSetting.TestUrl != "") { if (searchSetting.TestUrl == testSetting.TestUrl) //如果已经设置,则移除换成新的 { model.TestOptionsList.Remove(searchSetting); model.DefaultTestOption = testSetting; localSetting.DefaultTestOption = testSetting; } } if (!model.TestOptionsList.Any(te => te.TestUrl.ToLower() == testSetting.TestUrl.ToLower())) { model.TestOptionsList.Add(testSetting); } localSetting.TestOptionsList = model.TestOptionsList; localSetting.Id = model.Id; res = dal.Update(localSetting) ? 1 : 0; } if (res == 0) { MsgBox.ShowErrorMessage("保存失败!"); } }