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(); }
// 创建数据目录 public int CreateDataDir( string strRootDir, string strDefaultInstanceName, string strDefaultDataDir, out string strResultStartFileName, out string strResultDataDir, out string strError) { strError = ""; int nRet = 0; strResultStartFileName = ""; strResultDataDir = ""; bool bFinished = false; // 要求在temp内准备要安装的数据文件(初次安装而不是升级安装) string strTempDataDir = PathUtil.MergePath(strRootDir, "temp"); REDO_INPUT: // 获得数据目录 DataDirDlg datadir_dlg = new DataDirDlg(); GuiUtil.AutoSetDefaultFont(datadir_dlg); datadir_dlg.Comment = "请指定一个独立的数据目录, 用于存储dp2Kernel内核的各种配置信息。"; datadir_dlg.MessageBoxTitle = "setup_dp2Kernel"; datadir_dlg.DataDir = strDefaultDataDir; datadir_dlg.StartPosition = FormStartPosition.CenterScreen; datadir_dlg.ShowDialog(ForegroundWindow.Instance); if (datadir_dlg.DialogResult != DialogResult.OK) { strError = "用户放弃指定数据目录。安装未完成。"; throw new InstallException(strError); } string strDataDir = datadir_dlg.DataDir; string strExistingDatabasesFileName = PathUtil.MergePath(strDataDir, "databases.xml"); if (File.Exists(strExistingDatabasesFileName) == true) { // 从以前的rmsws数据目录升级 string strText = "数据目录 '" + strDataDir + "' 中已经存在以前的数据库内核版本遗留下来的数据文件。\r\n\r\n确实要利用这个数据目录来进行升级安装么?\r\n(注意:如果利用以前的rmsws的数据目录来进行升级安装,则必须先行卸载rmsws,以避免它和(正在安装的)dp2Kernel同时运行引起冲突)\r\n\r\n(是)继续进行升级安装 (否)重新指定数据目录 (取消)放弃安装"; DialogResult result = MessageBox.Show( ForegroundWindow.Instance, strText, "setup_dp2kernel", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == DialogResult.Cancel) { strError = "用户放弃指定数据目录。安装未完成。"; throw new InstallException(strError); } if (result == DialogResult.No) { goto REDO_INPUT; } // 创建start.xml文件 string strStartXmlFileName = PathUtil.MergePath(strRootDir, "start.xml"); nRet = this.CreateStartXml(strStartXmlFileName, strDataDir, out strError); if (nRet == -1) { throw new InstallException(strError); } // 删除临时目录 try { Directory.Delete(strTempDataDir, true); } catch (Exception ex) { MessageBox.Show(ForegroundWindow.Instance, "删除临时目录'" + strTempDataDir + "'出错:" + ex.Message); } strResultStartFileName = strStartXmlFileName; strResultDataDir = strDataDir; return(0); } // Debug.Assert(false, ""); nRet = PathUtil.CopyDirectory(strTempDataDir, strDataDir, true, out strError); if (nRet == -1) { strError = "拷贝临时目录 '" + strTempDataDir + "' 到数据目录'" + strDataDir + "'发生错误:" + strError; Debug.Assert(false, ""); throw new InstallException(strError); } try { strResultDataDir = strDataDir; // 删除临时目录 try { Directory.Delete(strTempDataDir, true); } catch (Exception ex) { MessageBox.Show(ForegroundWindow.Instance, "删除临时目录'" + strTempDataDir + "'出错:" + ex.Message); } // 调对话框得到数据源配置参数 MsSqlServerDataSourceDlg datasource_dlg = new MsSqlServerDataSourceDlg(); GuiUtil.AutoSetDefaultFont(datasource_dlg); datasource_dlg.Comment = "dp2Kernel内核的数据库功能是基于 SQL Server 2000 以上版本实现的。请设置下列SQL Server相关参数。"; datasource_dlg.StartPosition = FormStartPosition.CenterScreen; datasource_dlg.InstanceName = strDefaultInstanceName; datasource_dlg.KernelLoginName = strDefaultInstanceName; // 2010/12/15 datasource_dlg.ShowDialog(ForegroundWindow.Instance); if (datasource_dlg.DialogResult != DialogResult.OK) { strError = "放弃设置数据源,安装未完成。"; throw new InstallException(strError); } string strDatabasesFileName = strDataDir + "\\" + "databases.xml"; nRet = this.ModifyDatabasesXml(strDatabasesFileName, datasource_dlg.SqlServerName, false, // datasource_dlg.SSPI, datasource_dlg.KernelLoginName, datasource_dlg.KernelLoginPassword, datasource_dlg.InstanceName, out strError); if (nRet == -1) { throw new InstallException(strError); } // 设置root密码 RootUserDlg root_dlg = new RootUserDlg(); GuiUtil.AutoSetDefaultFont(root_dlg); root_dlg.UserName = "******"; root_dlg.Rights = "this:management;children_database:management;children_directory:management;children_leaf:management;descendant_directory:management;descendant_record:management;descendant_leaf:management"; root_dlg.StartPosition = FormStartPosition.CenterScreen; root_dlg.ShowDialog(ForegroundWindow.Instance); if (root_dlg.DialogResult != DialogResult.OK) { strError = "放弃设置root用户特性,安装未完成。"; throw new InstallException(strError); } nRet = ModifyRootUser(strDataDir, root_dlg.UserName, root_dlg.Password, root_dlg.Rights, out strError); if (nRet == -1) { throw new InstallException(strError); } // 创建start.xml文件 string strStartXmlFileName = PathUtil.MergePath(strRootDir, "start.xml"); nRet = this.CreateStartXml(strStartXmlFileName, strDataDir, out strError); if (nRet == -1) { throw new InstallException(strError); } bFinished = true; strResultStartFileName = strStartXmlFileName; return(0); } finally { if (bFinished == false) { try { Directory.Delete(strDataDir, true); } catch (Exception ex) { MessageBox.Show(ForegroundWindow.Instance, "回滚时删除数据目录'" + strDataDir + "'出错:" + ex.Message); } } } }
// 创建数据目录 public int CreateDataDir( string strRootDir, string strDefaultInstanceName, string strDefaultDataDir, out string strResultStartFileName, out string strResultDataDir, out string strError) { strError = ""; int nRet = 0; strResultStartFileName = ""; strResultDataDir = ""; bool bFinished = false; // 要求在temp内准备要安装的数据文件(初次安装而不是升级安装) string strTempDataDir = PathUtil.MergePath(strRootDir, "temp"); REDO_INPUT: // 获得数据目录 DataDirDlg datadir_dlg = new DataDirDlg(); GuiUtil.AutoSetDefaultFont(datadir_dlg); datadir_dlg.Comment = "请指定一个独立的数据目录, 用于存储dp2Kernel内核的各种配置信息。"; datadir_dlg.MessageBoxTitle = "setup_dp2Kernel"; datadir_dlg.DataDir = strDefaultDataDir; datadir_dlg.StartPosition = FormStartPosition.CenterScreen; datadir_dlg.ShowDialog(ForegroundWindow.Instance); if (datadir_dlg.DialogResult != DialogResult.OK) { strError = "用户放弃指定数据目录。安装未完成。"; throw new InstallException(strError); } string strDataDir = datadir_dlg.DataDir; string strExistingDatabasesFileName = PathUtil.MergePath(strDataDir, "databases.xml"); if (File.Exists(strExistingDatabasesFileName) == true) { // 从以前的rmsws数据目录升级 string strText = "数据目录 '" + strDataDir + "' 中已经存在以前的数据库内核版本遗留下来的数据文件。\r\n\r\n确实要利用这个数据目录来进行升级安装么?\r\n(注意:如果利用以前的rmsws的数据目录来进行升级安装,则必须先行卸载rmsws,以避免它和(正在安装的)dp2Kernel同时运行引起冲突)\r\n\r\n(是)继续进行升级安装 (否)重新指定数据目录 (取消)放弃安装"; DialogResult result = MessageBox.Show( ForegroundWindow.Instance, strText, "setup_dp2kernel", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == DialogResult.Cancel) { strError = "用户放弃指定数据目录。安装未完成。"; throw new InstallException(strError); } if (result == DialogResult.No) goto REDO_INPUT; // 创建start.xml文件 string strStartXmlFileName = PathUtil.MergePath(strRootDir, "start.xml"); nRet = this.CreateStartXml(strStartXmlFileName, strDataDir, out strError); if (nRet == -1) throw new InstallException(strError); // 删除临时目录 try { Directory.Delete(strTempDataDir, true); } catch (Exception ex) { MessageBox.Show(ForegroundWindow.Instance, "删除临时目录'" + strTempDataDir + "'出错:" + ex.Message); } strResultStartFileName = strStartXmlFileName; strResultDataDir = strDataDir; return 0; } // Debug.Assert(false, ""); nRet = PathUtil.CopyDirectory(strTempDataDir, strDataDir, true, out strError); if (nRet == -1) { strError = "拷贝临时目录 '" + strTempDataDir + "' 到数据目录'" + strDataDir + "'发生错误:" + strError; Debug.Assert(false, ""); throw new InstallException(strError); } try { strResultDataDir = strDataDir; // 删除临时目录 try { Directory.Delete(strTempDataDir, true); } catch (Exception ex) { MessageBox.Show(ForegroundWindow.Instance, "删除临时目录'" + strTempDataDir + "'出错:" + ex.Message); } // 调对话框得到数据源配置参数 MsSqlServerDataSourceDlg datasource_dlg = new MsSqlServerDataSourceDlg(); GuiUtil.AutoSetDefaultFont(datasource_dlg); datasource_dlg.Comment = "dp2Kernel内核的数据库功能是基于 SQL Server 2000 以上版本实现的。请设置下列SQL Server相关参数。"; datasource_dlg.StartPosition = FormStartPosition.CenterScreen; datasource_dlg.InstanceName = strDefaultInstanceName; datasource_dlg.KernelLoginName = strDefaultInstanceName; // 2010/12/15 datasource_dlg.ShowDialog(ForegroundWindow.Instance); if (datasource_dlg.DialogResult != DialogResult.OK) { strError = "放弃设置数据源,安装未完成。"; throw new InstallException(strError); } string strDatabasesFileName = strDataDir + "\\" + "databases.xml"; nRet = this.ModifyDatabasesXml(strDatabasesFileName, datasource_dlg.SqlServerName, false, // datasource_dlg.SSPI, datasource_dlg.KernelLoginName, datasource_dlg.KernelLoginPassword, datasource_dlg.InstanceName, out strError); if (nRet == -1) throw new InstallException(strError); // 设置root密码 RootUserDlg root_dlg = new RootUserDlg(); GuiUtil.AutoSetDefaultFont(root_dlg); root_dlg.UserName = "******"; root_dlg.Rights = "this:management;children_database:management;children_directory:management;children_leaf:management;descendant_directory:management;descendant_record:management;descendant_leaf:management"; root_dlg.StartPosition = FormStartPosition.CenterScreen; root_dlg.ShowDialog(ForegroundWindow.Instance); if (root_dlg.DialogResult != DialogResult.OK) { strError = "放弃设置root用户特性,安装未完成。"; throw new InstallException(strError); } nRet = ModifyRootUser(strDataDir, root_dlg.UserName, root_dlg.Password, root_dlg.Rights, out strError); if (nRet == -1) throw new InstallException(strError); // 创建start.xml文件 string strStartXmlFileName = PathUtil.MergePath(strRootDir, "start.xml"); nRet = this.CreateStartXml(strStartXmlFileName, strDataDir, out strError); if (nRet == -1) throw new InstallException(strError); bFinished = true; strResultStartFileName = strStartXmlFileName; return 0; } finally { if (bFinished == false) { try { Directory.Delete(strDataDir, true); } catch (Exception ex) { MessageBox.Show(ForegroundWindow.Instance, "回滚时删除数据目录'" + strDataDir + "'出错:" + ex.Message); } } } }
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(); }