// 检测目录是否已经存在 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, "library.xml"); if (File.Exists(strXmlFilename) == true) { DialogResult result = MessageBox.Show(ForegroundWindow.Instance, "您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 library.xml 文件。\r\n\r\n是否要直接利用其中的配置信息?", "安装 dp2Library", 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; Refreshdp2KernelDef(); RefreshSupervisorUserInfo(); RefreshLibraryName(); RefreshUpdateCfgsDir(); 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, "library.xml"); if (File.Exists(strXmlFilename) == true) { DialogResult result = MessageBox.Show(ForegroundWindow.Instance, "您指定的数据目录 '" + this.textBox_dataDir.Text + "' 中已经存在 library.xml 文件。\r\n\r\n是否要直接利用其中的配置信息?\r\n\r\n是:直接利用其中的信息,也即将其中的配置信息装入当前对话框\r\n否:利用这个数据目录,但其中xml文件的相关信息即将被当前对话框中的值覆盖\r\n\r\n(提示:无论您选“是”“否”,原有目录 '" + this.LoadedDataDir + "' 都会被闲置)", "安装 dp2Library", 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; Refreshdp2KernelDef(); RefreshSupervisorUserInfo(); RefreshLibraryName(); RefreshUpdateCfgsDir(); 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(如果选择“否”,则安装程序在稍后将新创建一个数据目录,并复制进初始内容)", "安装 dp2Library", 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_editdp2KernelDef_Click(object sender, EventArgs e) { // string strError = ""; InstallLibraryParamDlg param_dlg = new InstallLibraryParamDlg(); GuiUtil.AutoSetDefaultFont(param_dlg); param_dlg.StartPosition = FormStartPosition.CenterScreen; if (this.LineInfo != null) { param_dlg.KernelUrl = this.LineInfo.KernelUrl; param_dlg.ManageUserName = this.LineInfo.KernelUserName; param_dlg.ManagePassword = this.LineInfo.KernelPassword; } else { // param_dlg.KernelUrl = this.LineInfo.KernelUrl; param_dlg.ManageUserName = "******"; // 不能叫 supervisor ,那样容易和dpLibrary层的supervisor用户名混淆 // param_dlg.ManagePassword = this.LineInfo.KernelPassword; } param_dlg.ShowDialog(this); if (param_dlg.DialogResult != DialogResult.OK) return; if (this.LineInfo == null) this.LineInfo = new LineInfo(); this.LineInfo.KernelUrl = param_dlg.KernelUrl; this.LineInfo.KernelUserName = param_dlg.ManageUserName; this.LineInfo.KernelPassword = param_dlg.ManagePassword; Refreshdp2KernelDef(); return; /* ERROR1: MessageBox.Show(this, strError); return; * */ }
private void button_editSupervisorUserInfo_Click(object sender, EventArgs e) { CreateSupervisorDlg dlg = new CreateSupervisorDlg(); GuiUtil.AutoSetDefaultFont(dlg); if (this.LineInfo == null || (this.LineInfo.SupervisorUserName == null && this.LineInfo.SupervisorPassword == null && this.LineInfo.SupervisorRights == 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.SupervisorUserName; dlg.Password = this.LineInfo.SupervisorPassword; dlg.Rights = this.LineInfo.SupervisorRights; } dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) return; if (this.LineInfo == null) { this.LineInfo = new dp2Library.LineInfo(); } this.LineInfo.SupervisorUserName = dlg.UserName; this.LineInfo.SupervisorPassword = dlg.Password; this.LineInfo.SupervisorRights = dlg.Rights; RefreshSupervisorUserInfo(); }
private void button_OK_Click(object sender, EventArgs e) { string strError = ""; // 检查 // 数据目录 if (String.IsNullOrEmpty(this.textBox_dataDir.Text) == true) { strError = "尚未指定数据目录"; goto ERROR1; } // dp2Kernel服务器信息 if (String.IsNullOrEmpty(this.textBox_dp2KernelDef.Text) == true) { strError = "尚未指定dp2Kernel服务器信息"; goto ERROR1; } // 协议绑定 if (String.IsNullOrEmpty(this.textBox_bindings.Text) == true) { strError = "尚未指定协议绑定信息"; goto ERROR1; } // 图书馆名 if (String.IsNullOrEmpty(this.textBox_libraryName.Text) == true) { strError = "尚未指定图书馆名"; goto ERROR1; } if (this.LineInfo == null) this.LineInfo = new LineInfo(); this.LineInfo.LibraryName = this.textBox_libraryName.Text; this.LineInfo.UpdateCfgsDir = this.checkBox_updateCfgsDir.Checked; // 检查是否为旧式url地址 string strKernelUrl = this.LineInfo.KernelUrl; if (strKernelUrl.IndexOf(".asmx") != -1) { strError = "安装程序发现当前使用了旧版本数据库内核的地址 '" + strKernelUrl + "',需要您将它修改为新版dp2Kernel(内核)的URL地址。"; goto ERROR1; } if (this.IsNew == true && this.m_bDataDirExist == false) { // supervisor用户信息 if (this.LineInfo.SupervisorUserName == null || this.LineInfo.SupervisorPassword == null || this.LineInfo.SupervisorRights == null) { strError = "尚未设定supervisor账户的用户名、密码、权限"; goto ERROR1; } } // 如果修改时,需要创建新的数据目录 if (this.IsNew == false) { // 探测数据目录,是否已经存在数据,是不是属于升级情形 // return: // -1 error // 0 数据目录不存在 // 1 数据目录存在,但是xml文件不存在 // 2 xml文件已经存在 int nRet = InstanceDialog.DetectDataDir(this.textBox_dataDir.Text, out strError); if (nRet == -1) { strError = "探测数据目录 '" + this.textBox_dataDir.Text + "' 是否存在时,出现错误: " + strError; goto ERROR1; } if (nRet == 0 || nRet == 1) { // supervisor用户信息 if (this.LineInfo.SupervisorUserName == null || this.LineInfo.SupervisorPassword == null || this.LineInfo.SupervisorRights == null) { strError = "尚未设定supervisor账户的用户名、密码、权限"; goto ERROR1; } } } // TODO: 如果在编辑状态,需要排除和listview中自己重的情况 if (this.VerifyInstanceName != null) { VerifyEventArgs e1 = new VerifyEventArgs(); e1.Value = this.textBox_instanceName.Text; this.VerifyInstanceName(this, e1); if (String.IsNullOrEmpty(e1.ErrorInfo) == false) { strError = e1.ErrorInfo; goto ERROR1; } } if (this.VerifyDataDir != null) { VerifyEventArgs e1 = new VerifyEventArgs(); e1.Value = this.textBox_dataDir.Text; this.VerifyDataDir(this, e1); if (String.IsNullOrEmpty(e1.ErrorInfo) == false) { strError = e1.ErrorInfo; goto ERROR1; } } if (this.VerifyBindings != null) { VerifyEventArgs e1 = new VerifyEventArgs(); e1.Value = this.textBox_bindings.Text; this.VerifyBindings(this, e1); if (String.IsNullOrEmpty(e1.ErrorInfo) == false) { strError = e1.ErrorInfo; goto ERROR1; } } this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); return; ERROR1: MessageBox.Show(this, strError); }