private void ClientChannel_OnLoginNeeded(object sender, LoginNeededEventArgs e) { // Performing login if (this.LogOn(Properties.Settings.Default.UserId, Properties.Settings.Default.Password)) { e.Retry = true; e.LoginSuccessful = true; return; } String lUserId; String lPassword; using (LogOnForm lLoginForm = new LogOnForm()) { if (lLoginForm.ShowDialog() != DialogResult.OK) { MessageBox.Show("Login cancelled"); return; } lUserId = lLoginForm.UserId; lPassword = lLoginForm.Password; } if (this.LogOn(lUserId, lPassword)) { e.Retry = true; e.LoginSuccessful = true; } else { MessageBox.Show("Login failed"); } }
private void ClientChannel_OnLoginNeeded(object sender, LoginNeededEventArgs e) //如果 fdatamodule需要登录,将会调用此函数。 { // 登录操作 if ((!string.IsNullOrEmpty(Properties.Settings.Default.Password)) && this.LogOn(Properties.Settings.Default.UserId, Properties.Settings.Default.Password)) //密码不为空 并且登录成功 { e.Retry = true; e.LoginSuccessful = true; return; } //下面为一次登录失败时的情况。 //String lUserId; //String lPassword; ////登录失败时的情况 //MessageBox.Show("登录失败 请重试"); //using (var lLoginForm = new LogOnForm()) //{ // if (lLoginForm.ShowDialog() != DialogResult.OK)//若用户点击了取消 // { // return; // } // lUserId = lLoginForm.UserId; // lPassword = lLoginForm.Password; //} //if (this.LogOn(lUserId, lPassword)) //{ // e.Retry = true; // e.LoginSuccessful = true; //} //else // MessageBox.Show("登录失败"); //Properties.Settings.Default.UserId = "";//拉取数据时需要获取ID 所以这个字段不能被删除。 //Properties.Settings.Default.Password = "";//清楚保存的密码 //Properties.Settings.Default.Save ();//清空用户名和密码并保存 }