private void TriggerAccess_RestoreFromMySQL() { Accountant curr_acc = mApplicationController.mAccountant; Accountant source_acc = new ImAccountant("SourceAccount(MySQL)"); DbManager default_factory = new MySQLDbManager(source_acc, "PrimaryFactory"); default_factory.Database = txtMySQLDb.Text; default_factory.HostExePath = txtMySQLHost.Text; default_factory.Port = txtMySQLPort.Text; default_factory.DbPassword = txtMySQLPWD.Text; default_factory.DbUsername = txtMySQLUID.Text; source_acc.DefaultMgrFactory = default_factory; string error; if (source_acc.ConnectMgrFactories(out error)) { if (chkBackupItemAddOn.Checked) { curr_acc.ItemAddOnMgr.RecreateTable(); IList <ItemAddOn> CurrItemAddOns = source_acc.ItemAddOnMgr.FindAllCollection(); foreach (ItemAddOn s in CurrItemAddOns) { curr_acc.ItemAddOnMgr.Store(s); } curr_acc.DataFieldMgr.RecreateTable(); IList <DataField> DataFields = source_acc.DataFieldMgr.FindAllCollection(); foreach (DataField s in DataFields) { curr_acc.DataFieldMgr.Store(s); } curr_acc.ItemDataFieldEntryMgr.RecreateTable(); IList <ItemDataFieldEntry> ItemDataFieldEntries = source_acc.ItemDataFieldEntryMgr.FindAllCollection(); foreach (ItemDataFieldEntry s in ItemDataFieldEntries) { curr_acc.ItemDataFieldEntryMgr.Store(s); } } } else { MessageBox.Show(error); } source_acc.Release(); }
public void BackupToMySQL() { bool BackupByMySQL = mAccountant.ConfigMgr.GetParamValue("BACKUP_MySQLUSE").Equals("1"); if (!BackupByMySQL) { return; } Accountant backup_acc = new ImAccountant("BackupAccount(MySQL)"); DbManager default_factory = new MySQLDbManager(backup_acc, "PrimaryFactory"); string MySQLUID = mAccountant.ConfigMgr.GetParamValue("BACKUP_MySQLUID"); string MySQLPWD = mAccountant.ConfigMgr.GetParamValue("BACKUP_MySQLPWD"); string MySQLDb = mAccountant.ConfigMgr.GetParamValue("BACKUP_MySQLDB"); string MySQLHost = mAccountant.ConfigMgr.GetParamValue("BACKUP_MySQLHOST"); string MySQLPort = mAccountant.ConfigMgr.GetParamValue("BACKUP_MySQLPORT"); bool BackupItemAddOn = mAccountant.ConfigMgr.GetParamValue("BACKUP_ITEMADDON").Equals("1"); bool BackupAuthentication = mAccountant.ConfigMgr.GetParamValue("BACKUP_AUTHENTICATION").Equals("1"); bool BackupAuthorization = mAccountant.ConfigMgr.GetParamValue("BACKUP_AUTHORIZATION").Equals("1"); default_factory.Database = MySQLDb; default_factory.HostExePath = MySQLHost; default_factory.Port = MySQLPort; default_factory.DbPassword = MySQLPWD; default_factory.DbUsername = MySQLUID; backup_acc.DefaultMgrFactory = default_factory; string error; if (backup_acc.ConnectMgrFactories(out error)) { if (BackupItemAddOn) { backup_acc.ItemAddOnMgr.RecreateTable(); IList <ItemAddOn> CurrItemAddOns = mAccountant.ItemAddOnMgr.FindAllCollection(); foreach (ItemAddOn s in CurrItemAddOns) { backup_acc.ItemAddOnMgr.Store(s); } backup_acc.DataFieldMgr.RecreateTable(); IList <DataField> DataFields = mAccountant.DataFieldMgr.FindAllCollection(); foreach (DataField s in DataFields) { backup_acc.DataFieldMgr.Store(s); } backup_acc.ItemDataFieldEntryMgr.RecreateTable(); IList <ItemDataFieldEntry> ItemDataFieldEntries = mAccountant.ItemDataFieldEntryMgr.FindAllCollection(); foreach (ItemDataFieldEntry s in ItemDataFieldEntries) { backup_acc.ItemDataFieldEntryMgr.Store(s); } } } else { System.Windows.Forms.MessageBox.Show(error); } backup_acc.Release(); }