using System; using System.Collections.Generic; using System.Windows.Forms; using System.Xml; using System.Linq; using Datalib.DatabaseSpecific; using Datalib.EntityClasses; using Datalib.FactoryClasses; using Datalib.HelperClasses; using Datalib.Linq; using Datalib.RelationClasses; using System.Threading; using System.Globalization; using System.Configuration; using System.IO; using SD.LLBLGen.Pro.ORMSupportClasses.Miscellaneous; namespace Omega.Forms { public partial class frmSettings : Omega.BasicForms.frmCommon { public frmSettings() { InitializeComponent(); } private void barChangePass_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { (new frmChangePass()).Show(); } private void BackupFolder_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (this.folderBrowserDialog.ShowDialog() == DialogResult.OK) { this.BackupFolder.Text = this.folderBrowserDialog.SelectedPath; var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); KeyValueConfigurationCollection confCollection = config.AppSettings.Settings; if (confCollection["BackupFolder"] != null) { confCollection["BackupFolder"].Value = this.BackupFolder.Text; }else { confCollection.Add("BackupFolder", this.BackupFolder.Text); } config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); SettingInfo.BackupFolder = this.BackupFolder.Text; } } private void Databasefile_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (this.openFileDialog.ShowDialog() == DialogResult.OK) { string tmp = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={file};User Id=admin;Password=;Jet OLEDB:System Database=;Jet OLEDB:Database password="; this.Databasefile.Text = this.openFileDialog.FileName; string newvalue = tmp.Replace("{file}", this.Databasefile.Text); var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings["ConnectionString.MS Access (OleDb)"].Value = newvalue; config.Save(); ConfigurationManager.RefreshSection("appSettings"); SettingInfo.DatabaseFile = this.Databasefile.Text; } } private void OutputFolder_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (this.folderBrowserDialog.ShowDialog() == DialogResult.OK) { this.OutputFolder.Text = this.folderBrowserDialog.SelectedPath; var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); KeyValueConfigurationCollection confCollection = config.AppSettings.Settings; if (confCollection["OutputFolder"] != null) { confCollection["OutputFolder"].Value = this.OutputFolder.Text; }else { confCollection.Add("OutputFolder", this.OutputFolder.Text); } config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); SettingInfo.OutputFolder = this.OutputFolder.Text; } } private void frmSettings_Load(object sender, EventArgs e) { List Admins = new List() { "Admin", "SuperUser" }; try { this.BackupFolder.Text = SettingInfo.BackupFolder; this.OutputFolder.Text = SettingInfo.OutputFolder; this.Databasefile.Text = SettingInfo.DatabaseFile; this.Exclucive.EditValue = SettingInfo.Exclusive; this.InstallId.Text = SettingInfo.InstallId; this.RegisterNo.Text = SettingInfo.RegisterNo; this.RegisterNo.Enabled = Admins.Exists(Name => Name.Equals(SettingInfo.UserName)); this.OutputFolder.Enabled = Admins.Exists(Name => Name.Equals(SettingInfo.UserName)); this.BackupFolder.Enabled = Admins.Exists(Name => Name.Equals(SettingInfo.UserName)); this.Exclucive.Enabled = Admins.Exists(Name => Name.Equals(SettingInfo.UserName)); this.Databasefile.Enabled = Admins.Exists(Name => Name.Equals(SettingInfo.UserName)); this.barSave.Enabled = Admins.Exists(Name => Name.Equals(SettingInfo.UserName)); } catch { } } private void barClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.Close(); } private void barBackup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { string DesFile = SettingInfo.BackupFolder + @"\" + "Data" + DateTime.Today.ToString("ddMMyyyy") + ".mdb"; File.Copy(SettingInfo.DatabaseFile, DesFile); MessageBox.Show("Dữ liệu đã được sao lưu ra tệp " + DesFile); } catch { } } private void barSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } private void Exclucive_EditValueChanged(object sender, EventArgs e) { var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); KeyValueConfigurationCollection confCollection = config.AppSettings.Settings; if (confCollection["Exclusive"] != null) { confCollection["Exclusive"].Value = this.Exclucive.EditValue.ToString().Trim(); } else { confCollection.Add("Exclusive", this.Exclucive.EditValue.ToString().Trim()); } config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); SettingInfo.Exclusive = this.Exclucive.EditValue.ToString().Trim(); } private void RegisterNo_EditValueChanged(object sender, EventArgs e) { var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); KeyValueConfigurationCollection confCollection = config.AppSettings.Settings; if (confCollection["RegisterNo"] != null) { confCollection["RegisterNo"].Value = this.RegisterNo.EditValue.ToString().Trim(); } else { confCollection.Add("RegisterNo", this.RegisterNo.Text.ToString().Trim()); } config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); SettingInfo.RegisterNo = this.RegisterNo.Text.ToString().Trim(); } } }