private void Login_CheckBox_Click(object sender, RoutedEventArgs e) { if (this.LoginCheckBox.IsChecked == true) { UserLoginWindow ulw = new UserLoginWindow(); ulw.WindowStartupLocation = WindowStartupLocation.CenterOwner; ulw.Owner = AreaParty.MainWindow.main; ulw.ShowDialog(); string status = util.config.ConfigUtil.GetValue("longconnect"); if (status.Equals("false")) { this.LoginCheckBox.IsChecked = false; } else { this.LoginCheckBox.IsChecked = true; } } else { if (System.Windows.MessageBox.Show("确定断开长连接", "长连接", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { util.config.ConfigUtil.SetValue("longconnect", "false"); ClientPCNew2.StopService(); util.config.ConfigUtil.SetValue("longconnect", "false"); MainWindow.main.Status = "长连接断开"; } else { this.LoginCheckBox.IsChecked = true; } } }
public static void CLoseAll() { CloseHttpService(); ClientPCNew2.StopService(); ClosePCinfoService(); CloseUtorrent(); CloseBtReceive(); }
public void Init(string name, string password) { string serverIp = "119.23.12.116"; try { IPAddress remoteIP = IPAddress.Parse(serverIp); TcpClient mainServerTcpClient = new TcpClient(); mainServerTcpClient.Connect(new IPEndPoint(remoteIP, 13333)); SendToServer(mainServerTcpClient, name, password); LoginRsp result = LoginResult(mainServerTcpClient); if (LoginRsp.ResultCode.FAIL.Equals(result.resultCode)) { MessageBox.Show("用户名或密码错误,请重新输入"); mainServerTcpClient.Close(); return; } else if (LoginRsp.ResultCode.LOGGEDIN.Equals(result.resultCode)) { MessageBox.Show("该账号已登录"); mainServerTcpClient.Close(); return; } else if (LoginRsp.ResultCode.NOTMAINPHONE.Equals(result.resultCode)) { MessageBox.Show("该设备不是主设备"); Window loading = null; Thread t = new Thread(new ThreadStart(delegate { App.Current.Dispatcher.Invoke((Action)(() => { loading = new LoadingWindow(); loading.ShowDialog(); })); })); t.IsBackground = true; t.Start(); Console.WriteLine("waite result"); AccreditRsp accreditResult = AccreditResult(mainServerTcpClient); if (AccreditRsp.ResultCode.CANLOGIN.Equals(accreditResult.resultCode)) { SendToServer(mainServerTcpClient, name, password); MessageBox.Show("主设备同意登录"); App.Current.Dispatcher.Invoke((Action)(() => { if (loading != null) { loading.Close(); } })); MessageBox.Show("授权成功"); util.config.ConfigUtil.SetValue("longconnect", "true"); util.config.ConfigUtil.SetValue("username", name); util.config.ConfigUtil.SetValue("password", password); App.Current.Dispatcher.Invoke((Action)(() => { this.Close(); })); MainWindow.main.Status = "长连接开启"; } else if (AccreditRsp.ResultCode.FAIL.Equals(accreditResult.resultCode)) { App.Current.Dispatcher.Invoke((Action)(() => { if (loading != null) { loading.Close(); } })); MessageBox.Show("授权被拒绝"); MainWindow.main.Status = "长连接失败"; mainServerTcpClient.Close(); return; } } else if (LoginRsp.ResultCode.MAINPHONEOUTLINE.Equals(result.resultCode)) { MessageBox.Show("主设备不在线"); MainWindow.main.Status = "长连接失败"; mainServerTcpClient.Close(); return; } else if (LoginRsp.ResultCode.SUCCESS.Equals(result.resultCode)) { MessageBox.Show("登录成功"); util.config.ConfigUtil.SetValue("longconnect", "true"); util.config.ConfigUtil.SetValue("username", name); util.config.ConfigUtil.SetValue("password", password); App.Current.Dispatcher.Invoke((Action)(() => { this.Close(); })); // can also be any object you'd like to use as a parameter MainWindow.main.Status = "长连接已开启"; //启动长连接 ClientPCNew2.StartService(mainServerTcpClient); } } catch (Exception e) { MessageBox.Show(e.ToString()); } }