private void ConsumerQuene_MessageReceived(string obj) { if (status == EnLoginStatus.Login) { var result = JsonConvert.DeserializeObject <LoginResult>(obj); string userName = ""; if (result.Result) { status = EnLoginStatus.LoadUser; this.Dispatcher.Invoke(new Action(() => { this.btnLogin.IsEnabled = false; this.btnLogin.Content = "登录成功,正在获取用户信息..."; userName = this.cbUserName.Text; })); MsgModel model = new MsgModel(); model.From = guid; model.To = "ServerQuene"; model.MsgType = MsgType.LoadUserDetail; model.Msg = userName; DriverHelper.SendMsgToQuene("ServerQuene", JsonConvert.SerializeObject(model)); } else { MessageBox.Show(result.Msg); } } else if (status == EnLoginStatus.LoadUser) { CurrentUser = JsonConvert.DeserializeObject <User>(obj); if (CurrentUser == null) { MessageBox.Show("加载用户信息失败!"); this.Dispatcher.Invoke((Action)(() => this.DialogResult = false)); } else { System.Threading.Thread.Sleep(500); this.Dispatcher.Invoke(new Action(() => { DoubleAnimation animation = new DoubleAnimation(); animation.From = this.Width; animation.To = 0; animation.Duration = TimeSpan.FromMilliseconds(500); animation.Completed += (s, e) => this.Dispatcher.Invoke((Action)(() => this.DialogResult = true)); this.BeginAnimation(Window.WidthProperty, animation); })); } } }
private void btnLogin_Click(object sender, RoutedEventArgs e) { if (status == EnLoginStatus.Ready) { MsgModel model = new MsgModel(); model.From = guid; model.To = "ServerQuene"; model.MsgType = MsgType.Login; User user = new User() { UserName = this.cbUserName.Text, Password = this.tbPassword.Password }; model.Msg = JsonConvert.SerializeObject(user); DriverHelper.SendMsgToQuene("ServerQuene", JsonConvert.SerializeObject(model)); status = EnLoginStatus.Login; this.btnLogin.Content = "取消"; //开始动画 DoubleAnimation ani1 = new DoubleAnimation(); ani1.From = 1; ani1.To = 0; ani1.Duration = TimeSpan.FromMilliseconds(100); spLogin.BeginAnimation(StackPanel.OpacityProperty, ani1); DoubleAnimation ani2 = new DoubleAnimation(); ani2.From = 0; ani2.To = 1; ani2.Duration = TimeSpan.FromMilliseconds(100); spLoading.BeginAnimation(StackPanel.OpacityProperty, ani2); } else if (status == EnLoginStatus.Login) { status = EnLoginStatus.Ready; this.btnLogin.Content = "登录"; //开始动画 DoubleAnimation ani1 = new DoubleAnimation(); ani1.From = 0; ani1.To = 1; ani1.Duration = TimeSpan.FromMilliseconds(500); spLogin.BeginAnimation(StackPanel.OpacityProperty, ani1); DoubleAnimation ani2 = new DoubleAnimation(); ani2.From = 1; ani2.To = 0; ani2.Duration = TimeSpan.FromMilliseconds(500); spLoading.BeginAnimation(StackPanel.OpacityProperty, ani2); } }