public async void ConnectSQLServer(object sender, RoutedEventArgs e) { try { if (!UIGlobal.sharedTCPObject.socket.Connected) { MessageBox.Show("Server is not available."); throw new SocketException(); } int sentBytes = await TCP.SendTask(UIGlobal.sharedTCPObject, Encoding.UTF8.GetBytes("Login:"******"| Password:"******"|")); await TCP.ReceiveAllPacketsSync(UIGlobal.sharedTCPObject); Console.WriteLine("Received message: {0} ", UIGlobal.sharedTCPObject.packet); if (isAuthorizationSuccessful(UIGlobal.sharedTCPObject.packet)) { sharedData = new SharedData(UIGlobal.LoginWindowUI.Username, accessLevel, UIGlobal.sharedTCPObject); DataWindowNS.DataWindow dataWindow = new DataWindowNS.DataWindow(sharedData); dataWindow.Show(); UIGlobal.LoginWindowUI.rect_window_close(); Console.WriteLine("Logged onto server with username: {0} and password: {1}", UIGlobal.LoginWindowUI.Username, UIGlobal.LoginWindowUI.Password); } else { MessageBox.Show("Incorrect username or password, please try again."); } } catch (SocketException ex) { MessageBox.Show(ex.ToString()); } }
public async void ConnectSQLServer(object sender, RoutedEventArgs e) { try { if (!UIGlobal.sharedTCPObject.socket.Connected){ MessageBox.Show("Server is not available."); throw new SocketException(); } int sentBytes = await TCP.SendTask(UIGlobal.sharedTCPObject, Encoding.UTF8.GetBytes("Login:"******"| Password:"******"|")); await TCP.ReceiveAllPacketsSync(UIGlobal.sharedTCPObject); Console.WriteLine("Received message: {0} ", UIGlobal.sharedTCPObject.packet); if (isAuthorizationSuccessful(UIGlobal.sharedTCPObject.packet)) { sharedData = new SharedData(UIGlobal.LoginWindowUI.Username, accessLevel, UIGlobal.sharedTCPObject); DataWindowNS.DataWindow dataWindow = new DataWindowNS.DataWindow(sharedData); dataWindow.Show(); UIGlobal.LoginWindowUI.rect_window_close(); Console.WriteLine("Logged onto server with username: {0} and password: {1}", UIGlobal.LoginWindowUI.Username, UIGlobal.LoginWindowUI.Password); } else { MessageBox.Show("Incorrect username or password, please try again."); } } catch (SocketException ex) { MessageBox.Show(ex.ToString()); } }