/// <summary> /// 读取配置文件 /// </summary> private SettingHelper GetSetting() { SettingHelper settingHelper = new SettingHelper(); settingHelper.GetSetting(); this.txtCompany.Text = settingHelper.Company; this.ProjectName = settingHelper.Project; this.txtAuthor.Text = settingHelper.Author; this.txtDesign.Text = settingHelper.Design; this.txtOutput.Text = settingHelper.Output; this.chkOverwrite.Checked = settingHelper.Overwrite; this.CurrentDb = settingHelper.CurrentDb; // 检查文件是否存在,可能文件被删除了或者移动了,重新命名了之类的。 if (!String.IsNullOrEmpty(this.txtDesign.Text) && (!File.Exists(this.txtDesign.Text))) { this.txtDesign.Text = string.Empty; } if (!String.IsNullOrEmpty(this.txtDesign.Text) && !Directory.Exists(this.txtOutput.Text)) { this.txtOutput.Text = string.Empty; } if (String.IsNullOrEmpty(this.txtCompany.Text)) { this.txtCompany.Text = "Hairihan"; } if (String.IsNullOrEmpty(this.txtAuthor.Text)) { this.txtAuthor.Text = "JiRiGaLa"; } return settingHelper; }
private void FrmCodeGenerator_FormClosing(object sender, FormClosingEventArgs e) { // 在这里检查配置项目是否发生过变化 SettingHelper settingHelper = new SettingHelper(); settingHelper.GetSetting(); SettingHelper formSettingHelper = this.GetFormSetting(); if (!settingHelper.Equals(formSettingHelper)) { DialogResult dialogResult = MessageBox.Show("保存设置", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (dialogResult == DialogResult.Cancel) { e.Cancel = true; } if (dialogResult == DialogResult.Yes) { // 保存配置文件 this.SaveSetting(); } } }