private void button_editRootUserInfo_Click(object sender, EventArgs e) { RootUserDlg dlg = new RootUserDlg(); GuiUtil.AutoSetDefaultFont(dlg); if (this.LineInfo == null || (this.LineInfo.RootUserName == null && this.LineInfo.RootPassword == null && this.LineInfo.RootUserRights == null) ) { dlg.UserName = "******"; dlg.Password = ""; dlg.Rights = "this:management;children_database:management;children_directory:management;children_leaf:management;descendant_directory:management;descendant_record:management;descendant_leaf:management"; } else { Debug.Assert(this.LineInfo != null, ""); dlg.UserName = this.LineInfo.RootUserName; dlg.Password = this.LineInfo.RootPassword; dlg.Rights = this.LineInfo.RootUserRights; } dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) return; if (this.LineInfo == null) { this.LineInfo = new dp2Kernel.LineInfo(); } this.LineInfo.RootUserName = dlg.UserName; this.LineInfo.RootPassword = dlg.Password; this.LineInfo.RootUserRights = dlg.Rights; RefreshRootUserInfo(); }
// 检测目录是否已经存在 private void textBox_dataDir_Leave(object sender, EventArgs e) { // 已经准备Cancel,就不检查了 if (IsMouseOnCancelButton() == true) return; // 新建时 if (IsNew == true && String.IsNullOrEmpty(this.textBox_dataDir.Text) == false && this.LoadedDataDir != this.textBox_dataDir.Text) { // 注意检查,不能是别的instance的数据目录 if (this.VerifyDataDir != null) { VerifyEventArgs e1 = new VerifyEventArgs(); e1.Value = this.textBox_dataDir.Text; this.VerifyDataDir(this, e1); if (String.IsNullOrEmpty(e1.ErrorInfo) == false) { MessageBox.Show(this, e1.ErrorInfo); return; } } string strXmlFilename = PathUtil.MergePath(this.textBox_dataDir.Text, "databases.xml"); if (File.Exists(strXmlFilename) == true) { DialogResult result = MessageBox.Show(ForegroundWindow.Instance, "您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 database.xml 文件。\r\n\r\n是否要直接利用此其中(指xml文件和目录中有关帐户文件)的配置信息?", "安装 dp2Kernel", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.No) { this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复询问 return; } if (this.LoadXmlFileInfo != null) { LoadXmlFileInfoEventArgs e1 = new LoadXmlFileInfoEventArgs(); e1.DataDir = this.textBox_dataDir.Text; this.LoadXmlFileInfo(this, e1); if (string.IsNullOrEmpty(e1.ErrorInfo) == false) { MessageBox.Show(this, e1.ErrorInfo); return; } // refresh this.LineInfo = e1.LineInfo; RefreshSqlDef(); RefreshRootUserInfo(); this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复装载 this.m_bDataDirExist = true; // 防止OK时不合适的检查警告 } } return; } // 修改时 if (IsNew == false && String.IsNullOrEmpty(this.textBox_dataDir.Text) == false && this.LoadedDataDir != this.textBox_dataDir.Text) { // 注意检查,不能是别的instance的数据目录 if (this.VerifyDataDir != null) { VerifyEventArgs e1 = new VerifyEventArgs(); e1.Value = this.textBox_dataDir.Text; this.VerifyDataDir(this, e1); if (String.IsNullOrEmpty(e1.ErrorInfo) == false) { MessageBox.Show(this, e1.ErrorInfo); return; } } string strXmlFilename = PathUtil.MergePath(this.textBox_dataDir.Text, "databases.xml"); if (File.Exists(strXmlFilename) == true) { DialogResult result = MessageBox.Show(ForegroundWindow.Instance, "您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 database.xml 文件。\r\n\r\n是否要直接利用其中(指xml文件和目录中有关帐户文件)的配置信息?\r\n\r\n是:直接利用其中的信息,也即将其中的配置信息装入当前对话框\r\n否:利用这个数据目录,但其中xml文件和帐户文件的相关信息即将被当前对话框中的值覆盖\r\n\r\n(提示:无论您选“是”“否”,原有目录 '" + this.LoadedDataDir + "' 都会被闲置)", "安装 dp2Kernel", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.No) { this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复询问 return; } if (this.LoadXmlFileInfo != null) { LoadXmlFileInfoEventArgs e1 = new LoadXmlFileInfoEventArgs(); e1.DataDir = this.textBox_dataDir.Text; this.LoadXmlFileInfo(this, e1); if (string.IsNullOrEmpty(e1.ErrorInfo) == false) { MessageBox.Show(this, e1.ErrorInfo); return; } // refresh this.LineInfo = e1.LineInfo; RefreshSqlDef(); RefreshRootUserInfo(); this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复装载 this.m_bDataDirExist = true; // 防止OK时不合适的检查警告 } } else if (String.IsNullOrEmpty(this.LoadedDataDir) == false) { // 修改目录名 DialogResult result = MessageBox.Show(ForegroundWindow.Instance, "要将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '"+this.textBox_dataDir.Text+"' 么?\r\n\r\n(如果选择“否”,则安装程序在稍后将新创建一个数据目录,并复制进初始内容)", "安装 dp2Kernel", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.No) { this.m_bDataDirExist = false; return; } try { // TODO: 需要测试当数据目录中内容尺寸太大,而目标盘无妨容纳时的报错情况 Directory.Move(this.LoadedDataDir, this.textBox_dataDir.Text); this.LoadedDataDir = this.textBox_dataDir.Text; // 防止重复装载 } catch (Exception ex) { MessageBox.Show(this, "将已经存在的数据目录 '" + this.LoadedDataDir + "' 更名为 '"+this.textBox_dataDir.Text+"' 时发生错误: " + ex.Message); } } return; } }
private void button_editSqlDef_Click(object sender, EventArgs e) { string strError = ""; if (this.comboBox_sqlServerType.Text == "SQLite") { SqliteDataSourceDlg datasource_dlg = new SqliteDataSourceDlg(); GuiUtil.AutoSetDefaultFont(datasource_dlg); datasource_dlg.Comment = "dp2Kernel 内核的数据库功能可以基于内置的 SQLite 实现,不再需要任何其他数据库底层软件。请设置下列 SQLite 相关参数。"; if (this.LineInfo != null) { datasource_dlg.InstanceName = this.LineInfo.DatabaseInstanceName; } else { datasource_dlg.InstanceName = "dp2kernel" + (String.IsNullOrEmpty(this.InstanceName) == false ? "_" : "") + this.InstanceName; // 应当没有空格和特殊字符 } datasource_dlg.StartPosition = FormStartPosition.CenterScreen; datasource_dlg.ShowDialog(this); if (datasource_dlg.DialogResult != DialogResult.OK) return; if (this.LineInfo == null) this.LineInfo = new LineInfo(); this.LineInfo.SqlServerType = "SQLite"; this.LineInfo.SqlServerName = "~sqlite"; this.LineInfo.DatabaseInstanceName = datasource_dlg.InstanceName; this.LineInfo.DatabaseLoginName = ""; this.LineInfo.DatabaseLoginPassword = ""; RefreshSqlDef(); } else if (this.comboBox_sqlServerType.Text == "MS SQL Server") { // MS SQL Server // 调对话框得到数据源配置参数 MsSqlServerDataSourceDlg datasource_dlg = new MsSqlServerDataSourceDlg(); GuiUtil.AutoSetDefaultFont(datasource_dlg); datasource_dlg.Comment = "dp2Kernel 内核的数据库功能可以基于 MS SQL Server 2000 以上版本实现。请设置下列 SQL Server 相关参数。"; if (this.LineInfo != null) { datasource_dlg.SqlServerName = this.LineInfo.SqlServerName; datasource_dlg.InstanceName = this.LineInfo.DatabaseInstanceName; datasource_dlg.KernelLoginName = this.LineInfo.DatabaseLoginName; datasource_dlg.KernelLoginPassword = this.LineInfo.DatabaseLoginPassword; } else { datasource_dlg.SqlServerName = ""; datasource_dlg.InstanceName = "dp2kernel" + (String.IsNullOrEmpty(this.InstanceName) == false ? "_" : "") + this.InstanceName; // 应当没有空格和特殊字符 datasource_dlg.KernelLoginName = "dp2kernel" + (String.IsNullOrEmpty(this.InstanceName) == false ? "_" : "") + this.InstanceName; datasource_dlg.KernelLoginPassword = ""; } datasource_dlg.StartPosition = FormStartPosition.CenterScreen; datasource_dlg.ShowDialog(this); if (datasource_dlg.DialogResult != DialogResult.OK) return; if (this.LineInfo == null) this.LineInfo = new LineInfo(); this.LineInfo.SqlServerType = "MS SQL Server"; this.LineInfo.SqlServerName = datasource_dlg.SqlServerName; this.LineInfo.DatabaseInstanceName = datasource_dlg.InstanceName; this.LineInfo.DatabaseLoginName = datasource_dlg.KernelLoginName; this.LineInfo.DatabaseLoginPassword = datasource_dlg.KernelLoginPassword; RefreshSqlDef(); } else if (this.comboBox_sqlServerType.Text == "MySQL Server") { // MySQL Server // 调对话框得到数据源配置参数 MySqlDataSourceDlg datasource_dlg = new MySqlDataSourceDlg(); GuiUtil.AutoSetDefaultFont(datasource_dlg); datasource_dlg.Comment = "dp2Kernel 内核的数据库功能可以基于 MySQL Server 5.5 以上版本实现。请设置下列 MySQL Server 相关参数。"; if (this.LineInfo != null) { datasource_dlg.SqlServerName = this.LineInfo.SqlServerName; datasource_dlg.InstanceName = this.LineInfo.DatabaseInstanceName; datasource_dlg.KernelLoginName = this.LineInfo.DatabaseLoginName; datasource_dlg.KernelLoginPassword = this.LineInfo.DatabaseLoginPassword; } else { datasource_dlg.SqlServerName = ""; datasource_dlg.InstanceName = "dp2kernel" + (String.IsNullOrEmpty(this.InstanceName) == false ? "_" : "") + this.InstanceName; // 应当没有空格和特殊字符 datasource_dlg.KernelLoginName = "dp2kernel" + (String.IsNullOrEmpty(this.InstanceName) == false ? "_" : "") + this.InstanceName; datasource_dlg.KernelLoginPassword = ""; } datasource_dlg.StartPosition = FormStartPosition.CenterScreen; datasource_dlg.ShowDialog(this); if (datasource_dlg.DialogResult != DialogResult.OK) return; if (this.LineInfo == null) this.LineInfo = new LineInfo(); this.LineInfo.SqlServerType = "MySQL Server"; this.LineInfo.SqlServerName = datasource_dlg.SqlServerName; this.LineInfo.DatabaseInstanceName = datasource_dlg.InstanceName; this.LineInfo.DatabaseLoginName = datasource_dlg.KernelLoginName; this.LineInfo.DatabaseLoginPassword = datasource_dlg.KernelLoginPassword; RefreshSqlDef(); } else if (this.comboBox_sqlServerType.Text == "Oracle") { // Oracle // 调对话框得到数据源配置参数 OracleDataSourceDlg datasource_dlg = new OracleDataSourceDlg(); GuiUtil.AutoSetDefaultFont(datasource_dlg); datasource_dlg.Comment = "dp2Kernel 内核的数据库功能可以基于 Oracle 11g 以上版本实现。请设置下列 Oracle 相关参数。"; if (this.LineInfo != null) { datasource_dlg.SqlServerName = this.LineInfo.SqlServerName; // datasource_dlg.InstanceName = this.LineInfo.DatabaseInstanceName; datasource_dlg.KernelLoginName = this.LineInfo.DatabaseLoginName; datasource_dlg.KernelLoginPassword = this.LineInfo.DatabaseLoginPassword; } else { datasource_dlg.SqlServerName = ""; /* datasource_dlg.InstanceName = "dp2kernel" + (String.IsNullOrEmpty(this.InstanceName) == false ? "_" : "") + this.InstanceName; // 应当没有空格和特殊字符 * */ datasource_dlg.KernelLoginName = "dp2kernel" + (String.IsNullOrEmpty(this.InstanceName) == false ? "_" : "") + this.InstanceName; datasource_dlg.KernelLoginPassword = ""; } datasource_dlg.StartPosition = FormStartPosition.CenterScreen; datasource_dlg.ShowDialog(this); if (datasource_dlg.DialogResult != DialogResult.OK) return; if (this.LineInfo == null) this.LineInfo = new LineInfo(); this.LineInfo.SqlServerType = "Oracle"; this.LineInfo.SqlServerName = datasource_dlg.SqlServerName; this.LineInfo.DatabaseInstanceName = datasource_dlg.InstanceName; this.LineInfo.DatabaseLoginName = datasource_dlg.KernelLoginName; this.LineInfo.DatabaseLoginPassword = datasource_dlg.KernelLoginPassword; RefreshSqlDef(); } else { strError = "未知的 SQL 服务器类型 '" + this.comboBox_sqlServerType.Text + "'"; goto ERROR1; } return; ERROR1: MessageBox.Show(this, strError); return; }