Exemple #1
0
        /// <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("保存失败!");
            }
        }
Exemple #2
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                var path = Config.LanguagePath;
                if (!Config.IsChineseOs) //如果不是中文操作系统
                {
                    if (!File.Exists(Path.Combine(path, "English.xml")))
                    {
                        path = Path.Combine(Application.StartupPath, "Languages");
                    }
                }

                var objOpen = new OpenFileDialog
                {
                    Filter           = @"(*.xml)|*.xml|(*.*)|*.*",
                    InitialDirectory = path
                };

                if (objOpen.ShowDialog() == DialogResult.OK)
                {
                    txtLanguageFile.Text = objOpen.FileName;
                    var language = XmlHelper.XmlDeserialize(
                        objOpen.FileName,
                        typeof(Language)) as Language;

                    if (language != null)
                    {
                        lblForLPHVersion.Text       = language.LanguageFileForLPHVersion;
                        lblLanguageFileAuthor.Text  = language.LanguageFileAuthor;
                        lblLanguageFileVersion.Text = language.LanguageFileVersion;
                        lblLanguageName.Text        = language.LanguageName;

                        LoadLanguage(language);
                    }
                    var dal   = new SettingDAL();
                    var model = dal.FindAll().FirstOrDefault();
                    if (model != null)
                    {
                        model.LanguageFileName = objOpen.FileName;
                        dal.Update(model);
                    }

                    ApplicationMustRestart = true;
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowExceptionMessage(ex);
            }
        }