예제 #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());
            }
        }
예제 #2
0
        public DataWindow(SharedData sharedData)
        {
            InitializeComponent();
            this.DataContext = this;
            
            // get data from shared data
            loginName = sharedData._name;
            accessLevel = sharedData._accesslevel.ToString();
            client = sharedData._clientObject;

            // set GUI info
            AccessLevel.Content = "Access level: " + accessLevel;
            UI_Username.Content = "Logged in as: " + loginName;

            // set client variables
            currentPacket = RECEIVED_PACKET_TYPE.DEFAULT;

            // show GUI
            showMenuGUI();

            // receive async
            receiveAsync();
        }