public void OnAskAccountInfo(object sender, AskAccountInfoEventArgs e) { if (this.AskAccountInfo == null) { e.ErrorInfo = "AskAccountInfo事件函数未设置"; e.Result = -1; return; } if (this.AskAccountInfo != null) this.AskAccountInfo(sender, e); }
public void OnAskAccountInfo(object sender, AskAccountInfoEventArgs e) { if (this.AskAccountInfo == null) { e.ErrorInfo = "AskAccountInfo事件函数未设置"; e.Result = -1; return; } if (this.AskAccountInfo != null) { this.AskAccountInfo(sender, e); } }
void RmsChannels_AskAccountInfo(object sender, AskAccountInfoEventArgs e) { e.Owner = null; /// e.UserName = this.Dp2UserName; e.Password = this.Dp2Password; e.Result = 1; }
void channels_AskAccountInfo(object sender, AskAccountInfoEventArgs e) { e.Owner = this; LoginDlg dlg = new LoginDlg(); GuiUtil.AutoSetDefaultFont(dlg); dlg.textBox_serverAddr.Text = this.textBox_kernelUrl.Text; dlg.textBox_serverAddr.ReadOnly = true; dlg.textBox_comment.Text = e.Comment; dlg.textBox_userName.Text = this.ManagerUserName; dlg.textBox_password.Text = this.ManagerPassword; dlg.checkBox_savePassword.Checked = this.SavePassword; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) { e.Result = 0; return; } this.ManagerPassword = dlg.textBox_userName.Text; if (dlg.checkBox_savePassword.Checked == true) this.ManagerPassword = dlg.textBox_password.Text; else this.ManagerPassword = ""; e.UserName = dlg.textBox_userName.Text; e.Password = dlg.textBox_password.Text; e.Result = 1; }
// 获得缺省帐户信息 // return: // 2 already login succeed // 1 dialog return OK // 0 dialog return Cancel // -1 other error public void OnAskAccountInfo(object sender, AskAccountInfoEventArgs e) { bool bFirst = true; bool bAutoLogin = (e.LoginStyle & LoginStyle.AutoLogin) == LoginStyle.AutoLogin; bool bFillDefault = (e.LoginStyle & LoginStyle.FillDefaultInfo) == LoginStyle.FillDefaultInfo; e.Owner = this.ownerForm; e.UserName = ""; e.Password = ""; LoginDlg dlg = new LoginDlg(); dlg.Font = GuiUtil.GetDefaultFont(); Server server = this[e.Url]; dlg.textBox_serverAddr.Text = e.Url; if (bFillDefault == true) { if (server != null) { dlg.textBox_userName.Text = (server.DefaultUserName == "" ? "public" : server.DefaultUserName); dlg.textBox_password.Text = server.DefaultPassword; dlg.checkBox_savePassword.Checked = server.SavePassword; } else { dlg.textBox_userName.Text = "public"; dlg.textBox_password.Text = ""; dlg.checkBox_savePassword.Checked = false; } } if (e.Comment != null) dlg.textBox_comment.Text = e.Comment; DOLOGIN: if (e.Channels != null) { if (bAutoLogin == false && bFirst == true) goto REDOINPUT; // 找到Channel RmsChannel channel = e.Channel; // 2013/2/14 if (channel == null) channel = e.Channels.GetChannel(dlg.textBox_serverAddr.Text); Debug.Assert(channel != null, "Channels.GetChannel()异常..."); string strError; // 登录 int nRet = channel.Login(dlg.textBox_userName.Text, dlg.textBox_password.Text, out strError); if (nRet != 1) { strError = "以用户名 '" + dlg.textBox_userName.Text + "' 登录到 '" + dlg.textBox_serverAddr.Text + "' 失败: " + strError; if (this.ownerForm != null) { MessageBox.Show(this.ownerForm, strError); } else { e.ErrorInfo = strError; e.Result = -1; } goto REDOINPUT; } else // 登录成功 { if (String.Compare(e.Url, dlg.textBox_serverAddr.Text, true) != 0) { // 创建一个新的Server对象 // return: // -1 出错 // 0 加入了 // 1 发现重复,没有加入 nRet = this.NewServer(dlg.textBox_serverAddr.Text, -1); if (nRet == 0) e.Url = channel.Url; } server = this[dlg.textBox_serverAddr.Text]; if (server == null) // 2006/8/19 add { // 创建一个新的Server对象 // return: // -1 出错 // 0 加入了 // 1 发现重复,没有加入 nRet = this.NewServer(dlg.textBox_serverAddr.Text, -1); if (nRet == 0) e.Url = channel.Url; server = this[dlg.textBox_serverAddr.Text]; } Debug.Assert(server != null, "此时server不可能为null"); server.DefaultUserName = dlg.textBox_userName.Text; server.DefaultPassword = dlg.textBox_password.Text; server.SavePassword = dlg.checkBox_savePassword.Checked; this.m_bChanged = true; e.Result = 2; return; } } REDOINPUT: bFirst = false; dlg.ShowDialog(ownerForm); if (dlg.DialogResult != DialogResult.OK) { e.Result = 0; return; } if (e.Channels == null) { e.UserName = dlg.textBox_userName.Text; e.Password = dlg.textBox_password.Text; e.Result = 1; return; } goto DOLOGIN; }
// 登录。如果必要,出现对话框 // parameters: // strPath 资源路径。不包含URL部分。 // bAutoLogin 是否不出现对话框先自动登录一次。 // return: // -1 error // 0 login failed,出错信息在strError中 // 1 login succeed public int UiLogin( string strComment, string strPath, LoginStyle loginStyle, out string strError) { strError = ""; /* if (this.Container.AskAccountInfo == null) { strError = "AskAccountInfo事件函数未设置"; return -1; } */ string strUserName; string strPassword; IWin32Window owner = null; REDOINPUT: // 获得缺省帐户信息 // return: // 2 already login succeed // 1 dialog return OK // 0 dialog return Cancel // -1 other error /* int nRet = this.Container.procAskAccountInfo( this.Container, strComment, this.Url, strPath, loginStyle, out owner, out strUserName, out strPassword); */ AskAccountInfoEventArgs e = new AskAccountInfoEventArgs(); e.Channels = this.Container; e.Comment = strComment; e.Url = this.Url; e.Path = strPath; e.LoginStyle = loginStyle; e.Channel = this; // 2013/2/14 this.Container.OnAskAccountInfo(this, e); owner = e.Owner; strUserName = e.UserName; strPassword = e.Password; if (e.Result == -1) { if (e.ErrorInfo == "") strError = "procAskAccountInfo() error"; else strError = e.ErrorInfo; return -1; } if (e.Result == 2) return 1; if (e.Result == 1) { // 登录 // return: // -1 出错。错误信息在strError中 // 0 登录失败。错误信息也在strError // 1 登录成功 int nRet = this.Login(strUserName, strPassword, out strError); if (nRet == -1) return -1; if (nRet == 0) { if (this.Container.GUI == true) MessageBox.Show(owner, strError); else { return -1; } goto REDOINPUT; } // this.m_nRedoCount = 0; return 1; // 登录成功,可以重做API功能了 } if (e.Result == 0) { strError = "放弃登录"; return -1; } strError = "UiLogin() 不应该走到这里"; return -1; }
// 获得缺省帐户信息 // return: // 2 already login succeed // 1 dialog return OK // 0 dialog return Cancel // -1 other error public void OnAskAccountInfo(object sender, AskAccountInfoEventArgs e) { bool bFirst = true; bool bAutoLogin = (e.LoginStyle & LoginStyle.AutoLogin) == LoginStyle.AutoLogin; bool bFillDefault = (e.LoginStyle & LoginStyle.FillDefaultInfo) == LoginStyle.FillDefaultInfo; e.Owner = this.ownerForm; e.UserName = ""; e.Password = ""; LoginDlg dlg = new LoginDlg(); dlg.Font = GuiUtil.GetDefaultFont(); Server server = this[e.Url]; dlg.textBox_serverAddr.Text = e.Url; if (bFillDefault == true) { if (server != null) { dlg.textBox_userName.Text = (server.DefaultUserName == "" ? "public" : server.DefaultUserName); dlg.textBox_password.Text = server.DefaultPassword; dlg.checkBox_savePassword.Checked = server.SavePassword; } else { dlg.textBox_userName.Text = "public"; dlg.textBox_password.Text = ""; dlg.checkBox_savePassword.Checked = false; } } if (e.Comment != null) { dlg.textBox_comment.Text = e.Comment; } DOLOGIN: if (e.Channels != null) { if (bAutoLogin == false && bFirst == true) { goto REDOINPUT; } // 找到Channel RmsChannel channel = e.Channel; // 2013/2/14 if (channel == null) { channel = e.Channels.GetChannel(dlg.textBox_serverAddr.Text); } Debug.Assert(channel != null, "Channels.GetChannel()异常..."); string strError; // 登录 int nRet = channel.Login(dlg.textBox_userName.Text, dlg.textBox_password.Text, out strError); if (nRet != 1) { strError = "以用户名 '" + dlg.textBox_userName.Text + "' 登录到 '" + dlg.textBox_serverAddr.Text + "' 失败: " + strError; if (this.ownerForm != null) { MessageBox.Show(this.ownerForm, strError); } else { e.ErrorInfo = strError; e.Result = -1; } goto REDOINPUT; } else // 登录成功 { if (String.Compare(e.Url, dlg.textBox_serverAddr.Text, true) != 0) { // 创建一个新的Server对象 // return: // -1 出错 // 0 加入了 // 1 发现重复,没有加入 nRet = this.NewServer(dlg.textBox_serverAddr.Text, -1); if (nRet == 0) { e.Url = channel.Url; } } server = this[dlg.textBox_serverAddr.Text]; if (server == null) // 2006/8/19 add { // 创建一个新的Server对象 // return: // -1 出错 // 0 加入了 // 1 发现重复,没有加入 nRet = this.NewServer(dlg.textBox_serverAddr.Text, -1); if (nRet == 0) { e.Url = channel.Url; } server = this[dlg.textBox_serverAddr.Text]; } Debug.Assert(server != null, "此时server不可能为null"); server.DefaultUserName = dlg.textBox_userName.Text; server.DefaultPassword = dlg.textBox_password.Text; server.SavePassword = dlg.checkBox_savePassword.Checked; this.m_bChanged = true; e.Result = 2; return; } } REDOINPUT: bFirst = false; dlg.ShowDialog(ownerForm); if (dlg.DialogResult != DialogResult.OK) { e.Result = 0; return; } if (e.Channels == null) { e.UserName = dlg.textBox_userName.Text; e.Password = dlg.textBox_password.Text; e.Result = 1; return; } goto DOLOGIN; }