Ejemplo n.º 1
0
        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());
            }
        }
Ejemplo n.º 2
0
        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());
            }
        }