using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using CK.SCP.Models; using CK.SCP.Models.Enums; using CK.SCP.UniApi.Config; using CK.SCP.Utils; using CK.SCP.Common; using DevComponents.DotNetBar; using DevComponents.DotNetBar.Controls; namespace CK.SCP.UniApi { public partial class PopupSetting : Office2007Form { private List _groupList = new List(); private void FormSetting_Load(object sender, EventArgs e) { ProjectName projectName; // GetConfig(GlobalConfig.CommonFileName); GetConfig(GlobalConfig.ScpDbFileName); GetConfig(GlobalConfig.UniApiConfigFileName); GetConfig(GlobalConfig.DurationFileName); Enum.TryParse(ScpCache.Config.项目名称, true, out projectName); switch (projectName) { case ProjectName.锦州锦恒: GetConfig(GlobalConfig.UniApiDbFileName); break; } listSetting.SelectedIndex = 0; } private void GetConfig(string filename) where T : new() { var group = SettingHelper.GetConfigValues(filename); pnlMain.Controls.Add(@group); pnlMain.ResumeLayout(); _groupList.Add(@group); listSetting.Items.Add(SettingHelper.GetPureName(filename)); } private void btnSave_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtSuperPassword.Text)) throw new Exception("请输入管理员密码!"); if (txtSuperPassword.Text != GlobalVar.SuperPassword) throw new Exception("管理员密码密码错误,请重新输入!"); ProjectName projectName; Enum.TryParse(ScpCache.Config.项目名称, true, out projectName); // GlobalVar.CommonConfig = SettingHelper.SetConfigValues(_groupList, GlobalConfig.CommonFileName); GlobalConfig.ScpDatabase = SettingHelper.SetConfigValues(_groupList, GlobalConfig.ScpDbFileName); GlobalVar.ApiConfig = SettingHelper.SetConfigValues(_groupList, GlobalConfig.UniApiConfigFileName); GlobalVar.DurationConfig = SettingHelper.SetConfigValues(_groupList, GlobalConfig.DurationFileName); switch (projectName) { case ProjectName.锦州锦恒: GlobalConfig.UniApiDatabase = SettingHelper.SetConfigValues(_groupList, GlobalConfig.UniApiDbFileName); break; } DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageHelper.ShowError(ex); txtSuperPassword.Focus(); } } private void btnCancel_Click(object sender, EventArgs e) { Close(); } private void listSetting_ItemClick(object sender, EventArgs e) { } private void listSetting_SelectedIndexChanged(object sender, EventArgs e) { if (listSetting.SelectedIndex < 0) return; var selectedName = listSetting.SelectedItem.ToString(); var group = _groupList.SingleOrDefault(p => p.Name == selectedName); if (group == null) return; foreach (var groupPanel in _groupList) { groupPanel.Visible = false; } group.Visible = true; } } }