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 SD.LLBLGen.Pro.ORMSupportClasses.Miscellaneous; using System.IO; namespace PatientMan.Forms { public partial class frmSettings : PatientMan.BasicForms.frmCommon { public frmSettings() { InitializeComponent(); } private void LoadInfo_Click(object sender, EventArgs e) { if (SettingDlg.ShowDialog() == DialogResult.OK) { var doc = new XmlDocument(); string SettingsPath = SettingDlg.FileName; doc.Load(SettingsPath); this.ProvinceId.EditValue = doc.GetElementsByTagName("ProvinceId")[0].InnerText; this.Districtid.EditValue = doc.GetElementsByTagName("DistictId")[0].InnerText; this.CommuneId.EditValue = doc.GetElementsByTagName("CommuneId")[0].InnerText; this.SiteCode.EditValue = doc.GetElementsByTagName("SiteCode")[0].InnerText; this.SiteName.Text = doc.GetElementsByTagName("SiteName")[0].InnerText; this.Address.Text = doc.GetElementsByTagName("Address")[0].InnerText; this.Description.Text = doc.GetElementsByTagName("Description")[0].InnerText; ; this.Language.EditValue = Convert.ToInt16(doc.GetElementsByTagName("Language")[0].InnerText); ; } } private void frmSettings_Load(object sender, EventArgs e) { try { EntityCollection prov = new EntityCollection(); EntityCollection dist = new EntityCollection(); EntityCollection communes = new EntityCollection(); adapter.FetchEntityCollection(prov, null); adapter.FetchEntityCollection(dist, null); adapter.FetchEntityCollection(communes, null); this.tblCommuneEntityBindingSource.DataSource = communes; this.tblDistrictEntityBindingSource.DataSource = dist; this.tblProvinceEntityBindingSource.DataSource = prov; this.ProvinceId.EditValue = SettingInfo.ProvinceId; this.Districtid.EditValue = SettingInfo.DistrictId; this.CommuneId.EditValue = SettingInfo.CommuneId; this.SiteCode.EditValue = SettingInfo.SiteCode; this.SiteName.Text = SettingInfo.SiteName; this.installid.EditValue = SettingInfo.InstallId; this.RegisterNo.Text = SettingInfo.RegisterNo; this.Address.Text = SettingInfo.Address; this.Description.Text = SettingInfo.Description; this.Language.EditValue = (short)SettingInfo.Language; this.Databasefile.Text = SettingInfo.DatabaseFile; this.BackupFolder.Text = SettingInfo.BackupFolder; this.dbPassword.Text = SettingInfo.dbPassword; reginfo.Text = SettingInfo.Registered ? "Registered Version" : "Unregistered Version"; } catch(Exception err) { MessageBox.Show(err.Message + " 1 " + SettingInfo.Constr); } } private void SaveInfo_Click (object sender, EventArgs e) { var doc = new XmlDocument(); string SettingsPath = Application.StartupPath + @"\Settings.fhi"; doc.Load(SettingsPath); doc.GetElementsByTagName("ProvinceId")[0].InnerText = this.ProvinceId.EditValue.ToString(); doc.GetElementsByTagName("DistictId")[0].InnerText = this.Districtid.EditValue.ToString(); doc.GetElementsByTagName("CommuneId")[0].InnerText = this.CommuneId.EditValue.ToString(); doc.GetElementsByTagName("SiteCode")[0].InnerText = this.SiteCode.Text; doc.GetElementsByTagName("SiteName")[0].InnerText = this.SiteName.Text; doc.GetElementsByTagName("Address")[0].InnerText = this.Address.Text; doc.GetElementsByTagName("Description")[0].InnerText = this.Description.Text; doc.GetElementsByTagName("Language")[0].InnerText = this.Language.EditValue.ToString(); doc.Save(SettingsPath); SettingInfo.InitInfo(); (new frmShowSaveInfo()).Show(); } private void Language_EditValueChanged(object sender, EventArgs e) { if (this.Language.EditValue.ToString().Trim()=="0") { Thread.CurrentThread.CurrentUICulture = new CultureInfo("vi-VN"); } else { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en"); } } private void ChangePass_Click(object sender, EventArgs e) { (new frmChangePass()).Show(); } private void Databasefile_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { string tmp = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={file};User Id=admin;Password=;Jet OLEDB:System Database=;Jet OLEDB:Database password={dbPassword}"; if (this.openFileDialog.ShowDialog()== DialogResult.OK) { 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; SettingInfo.Constr = newvalue.Replace("{dbPassword}", this.dbPassword.Text); config.Save(); ConfigurationManager.RefreshSection("appSettings"); SettingInfo.DatabaseFile = this.Databasefile.Text; } } 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; } { confCollection.Add("BackupFolder", this.BackupFolder.Text); } config.Save(ConfigurationSaveMode.Modified); } } private void barLoad_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (SettingDlg.ShowDialog() == DialogResult.OK) { var doc = new XmlDocument(); string SettingsPath = SettingDlg.FileName; doc.Load(SettingsPath); this.ProvinceId.EditValue = doc.GetElementsByTagName("ProvinceId")[0].InnerText; this.Districtid.EditValue = doc.GetElementsByTagName("DistictId")[0].InnerText; this.CommuneId.EditValue = doc.GetElementsByTagName("CommuneId")[0].InnerText; this.SiteCode.EditValue = doc.GetElementsByTagName("SiteCode")[0].InnerText; this.SiteName.Text = doc.GetElementsByTagName("SiteName")[0].InnerText; this.Address.Text = doc.GetElementsByTagName("Address")[0].InnerText; this.Description.Text = doc.GetElementsByTagName("Description")[0].InnerText; ; this.Language.EditValue = Convert.ToInt16(doc.GetElementsByTagName("Language")[0].InnerText); ; } } private void barSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var doc = new XmlDocument(); string SettingsPath = Application.StartupPath + @"\Settings.fhi"; doc.Load(SettingsPath); doc.GetElementsByTagName("ProvinceId")[0].InnerText = this.ProvinceId.EditValue.ToString(); doc.GetElementsByTagName("DistictId")[0].InnerText = this.Districtid.EditValue.ToString(); doc.GetElementsByTagName("CommuneId")[0].InnerText = this.CommuneId.EditValue.ToString(); doc.GetElementsByTagName("SiteCode")[0].InnerText = this.SiteCode.Text; doc.GetElementsByTagName("SiteName")[0].InnerText = this.SiteName.Text; doc.GetElementsByTagName("Address")[0].InnerText = this.Address.Text; doc.GetElementsByTagName("Description")[0].InnerText = this.Description.Text; doc.GetElementsByTagName("Language")[0].InnerText = this.Language.EditValue.ToString(); if (this.dbPassword.Text != "") { doc.GetElementsByTagName("dbPassword")[0].InnerText = Utility.Encrypt(this.dbPassword.Text.Trim()); } else { doc.GetElementsByTagName("dbPassword")[0].InnerText = ""; } doc.Save(SettingsPath); SettingInfo.InitInfo(); (new frmShowSaveInfo()).Show(); } 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 dbPassword_EditValueChanged(object sender, EventArgs e) { } private void RegisterNo_EditValueChanged(object sender, EventArgs e) { } private void barGeogs_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { frmGeoLocations frm = new frmGeoLocations(); frm.LoadData(); frm.ShowDialog(); } private void barRegimens_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { frmRegimens frm = new frmRegimens(); frm.LoadData(); frm.ShowDialog(); } private void barTest_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { frmTests frm = new frmTests(); frm.LoadData(); frm.ShowDialog(); } private void barTreatments_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { frmTreatmentList frm = new frmTreatmentList(); frm.LoadData(); frm.ShowDialog(); } private void barEncypt_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if( !(this.barPassword.EditValue!=null && this.barPassword.EditValue.ToString() == DateTime.Today.ToShortDateString())) { return; } if(MessageBox.Show("Bạn thực sự muốn mã hóa dữ liệu?","Mã hóa",MessageBoxButtons.OKCancel)== DialogResult.OK) { EntityCollection Patients = new EntityCollection(); adapter.FetchEntityCollection(Patients, null); foreach( TblPatientEntity patient in Patients) { patient.PatientName = strUtil.Crypt(patient.PatientName); // patient.IdentityCardNo = strUtil.Crypt(patient.IdentityCardNo); } adapter.SaveEntityCollection(Patients); } } } }