0
這是我的服務,檢查用戶名和密碼啓用Silverlight的WCF服務重新調諧價值
[OperationContract]
public bool LoginCheck(string username, string password)
{
RoadTransDataContext db = new RoadTransDataContext();
var _Pass = (from d in db.users where d.username == username select d.password).SingleOrDefault();
if (_Pass == password)
{
return true;
}
else
{
return false;
}
}
這是子窗口
private void LoginCheckCompleted(object sender, ServiceReference.LoginCheckCompletedEventArgs e)
{
_Log = e.Result;
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
ServiceReference.ServiceClient webservice = new ServiceReference.ServiceClient();
webservice.LoginCheckCompleted += new EventHandler<ServiceReference.LoginCheckCompletedEventArgs>(LoginCheckCompleted);
webservice.LoginCheckAsync(txtUserName.Text, txtPassword.Password);
if (_Log == true)
{
this.DialogResult = true;
this.Close();
}
}
問題是,當OKButton_Click
方法完成LoginCheckCompleted
方法調用。所以如果它輸入正確的用戶名,傳遞並按下按鈕它什麼都不做,如果我再次單擊一次窗口關閉
順便說一句,服務方法的代碼大小可以減少:'return db.users.Where(d => d.username == username && d.password ==密碼).Any();' – vorrtex