private void Settings_Load(object sender, EventArgs e) { this.cbClearMonth.DataSource = Asa.BackDB.BindComboxEnumType <ClearMonth> .BindTyps; this.cbClearMonth.DisplayMember = "Name"; this.cbClearMonth.ValueMember = "Type"; this.cbBakYear.SelectedIndex = 1; this.listDb.Items.Clear(); this.AssertExistsXmlConfig(); SettingConfig config = XmlHelper.XmlDeserialize <SettingConfig>(SystemParam.ConfigFilePath); this.txtServiceIp.Text = config.ServiceAddress; this.txtCreateNameRegulation.Text = config.NameRegulation; this.txtDbLoginName.Text = config.DataBaseLogin; this.txtDbPassword.Text = config.DataBasePassword; this.txtSaveDirectory.Text = config.BackDirectoryPath; this.txtTimeInterval.Text = config.TimeInterval; this.ckIsNewFolder.Checked = config.IsNewFolder; this.cbClearMonth.SelectedValue = (ClearMonth)config.ClearMonth; this.cbBakYear.SelectedIndex = config.BackupDbYear; foreach (string name in config.DataBaseNames) { this.listDb.Items.Add(name); } this.txtStartDate.Value = config.SyncDate.ObjToDateTime(); }
/// <summary> /// save /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveConfig_Click(object sender, EventArgs e) { SettingConfig configinfo = new SettingConfig() { BackDirectoryPath = this.txtSaveDirectory.Text, ServiceAddress = this.txtServiceIp.Text, TimeInterval = this.txtTimeInterval.Text, SyncDate = this.txtStartDate.Value.ToString("yyyy-MM-dd HH:mm:ss"), NameRegulation = this.txtCreateNameRegulation.Text, DataBaseLogin = this.txtDbLoginName.Text, DataBasePassword = this.txtDbPassword.Text, IsNewFolder = this.ckIsNewFolder.Checked, BackupDbYear = this.cbBakYear.SelectedIndex, ClearMonth = (int)this.cbClearMonth.SelectedValue }; foreach (object item in this.listDb.Items) { configinfo.DataBaseNames.Add(item.ObjToStr()); } if (configinfo.DataBaseNames.Count == 0) { MessageBox.Show("没有设置要备份的数据库,无法保存。", "系统提示"); return; } XmlHelper.XmlSerialize <SettingConfig>(SystemParam.ConfigFilePath, configinfo); if (MessageBox.Show("保存成功,点击是后,窗口关闭。", "系统提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { Application.Exit(); } }
public SyncDataClient() { this.log.Info("初始化定时器备份服务"); this.settingConfig = XmlHelper.XmlDeserialize <SettingConfig>(SystemParam.ConfigFilePath); //计算首次执行时间 毫秒数 this._syncTime = this.settingConfig.SyncDate.ObjToDateTime(); this._timer = new Timer(1000) { AutoReset = true }; this._timer.Elapsed += this.Timer_SyncData; log.Info($"起始执行时间:{this._syncTime:s}"); this.log.Info("初始化定时服务程序完成"); }
private void AssertExistsXmlConfig() { if (!File.Exists(SystemParam.ConfigFilePath)) { SettingConfig configinfo = new SettingConfig() { BackDirectoryPath = "d:\\DataBase\\BackupDB", ServiceAddress = ".", TimeInterval = "00天00小时01分钟", SyncDate = DateTime.Now.AddHours(1).ToString("yyyy-MM-dd HH:mm:ss"), NameRegulation = "{DB}-yyyyMMddHHmmssfff", DataBaseLogin = "******", DataBasePassword = "******", IsNewFolder = true, BackupDbYear = 1, ClearMonth = 0 }; XmlHelper.XmlSerialize <SettingConfig>(SystemParam.ConfigFilePath, configinfo); } }