public void InitConfig(SystemConfig.DatabaseConfig config) { server.Text = config.Server; user.Text = config.UserName; password.Text = config.Password; database.Text = config.Database; }
public void SetConfig(SystemConfig.DatabaseConfig config) { config.Server = server.Text; config.UserName = user.Text; config.Password = password.Text; config.Database = database.Text; }
/// <summary> /// 设置系统配置 /// </summary> /// <param name="config">系统配置对象</param> public void Set(SystemConfig config) { var sw = CommonFunction.XmlSerializer(config); using (var file = File.OpenWrite(ConfigPath)) { var buf = Encoding.Default.GetBytes(sw.ToString()); file.Write(buf, 0, buf.Length); file.SetLength(buf.Length); file.Close(); } }
private void 数据库配置ToolStripMenuItem_Click(object sender, EventArgs e) { _sysCfg = new SysConfigManager().Get(); var form = new DbConfig(); form.InitConfig(_sysCfg.DbConfig); var result = form.ShowDialog(); if (result != DialogResult.OK) return; form.SetConfig(_sysCfg.DbConfig); var sh = new SqlHelper(_sysCfg.DbConfig.GetConnectionString()); try { sh.Open(); new SysConfigManager().Set(_sysCfg); try { sh.Execute(_sysCfg.Excel2TplusHistorySql); } catch { } } catch { MessageBox.Show("数据库无法连接"); } finally { sh.Close(); } }