Mauro de Lyon 10 rokov pred
rodič
commit
c3e6f71137

+ 4 - 4
Proftaak Remote Healthcare/FietsClientV2/Forms/Login.cs

@@ -21,9 +21,9 @@ namespace FietsClient
         [DllImport("User32.dll")]
         public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
 
-        public Login(TcpConnection conn)
+        public Login(TcpConnection connection)
         {
-            connection = conn;
+            this.connection = connection;
             InitializeComponent();
         }
 
@@ -76,7 +76,7 @@ namespace FietsClient
 
         private void checkConnection()
         {
-            if (!connection.isConnected())
+            if (!connection.isConnectedFlag)
             {
                 connLBL.Text = "No Connection established";
             }
@@ -88,7 +88,7 @@ namespace FietsClient
 
         private void reconnectBTN_Click(object sender, EventArgs e)
         {
-            if(!connection.isConnected())
+            if(!connection.isConnectedFlag)
             {
                 connection.connect();
                 checkConnection();

+ 0 - 3
Proftaak Remote Healthcare/FietsClientV2/Program.cs

@@ -12,9 +12,6 @@ namespace FietsClient
         [STAThread]
         static void Main()
         {
-
-            
-            
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             Application.Run(new Login(new TcpConnection()));

+ 22 - 31
Proftaak Remote Healthcare/FietsClientV2/TCPConnection.cs

@@ -13,52 +13,45 @@ namespace FietsClient
     public class TcpConnection
     {
         public TcpClient client;
+        public bool isConnectedFlag { private set; get; }
         private NetworkStream serverStream;
         private CurrentData currentData;
         private string userID;
-        private bool isConnectedFlag;
+        private Thread receiveThread;
 
         public TcpConnection()
         {
-            // create a connection
             client = new TcpClient();
-
             connect();
         }
 
-        public bool isConnected()
-        {
-            return isConnectedFlag;
-        }
-
         public void connect()
         {
-                try
-                {
-                    client.Connect("192.168.178.17", 1288);
+            try
+            {
+                client.Connect("192.168.178.17", 1288);
 
-                    // create streams
-                    serverStream = client.GetStream();
-                    Thread t = new Thread(recieve);
-                    t.Start();
-                    isConnectedFlag = true;
-                }
-                catch (Exception ex)
-                {
-                    Console.WriteLine(ex);
-                    Thread.Sleep(1000);
-                    isConnectedFlag = false;
-                }
+                // create streams
+                serverStream = client.GetStream();
+                receiveThread = new Thread(receive);
+                receiveThread.Start();
+                isConnectedFlag = true;
+            }
+            catch (Exception)
+            {
+                Thread.Sleep(1000);
+                isConnectedFlag = false;
+            }
         }
 
-        public void recieve ()
+        public void receive()
         {
             while (true)
             {
                 byte[] bytesFrom = new byte[(int)client.ReceiveBufferSize];
                 serverStream.Read(bytesFrom, 0, (int)client.ReceiveBufferSize);
-                String response = Encoding.ASCII.GetString(bytesFrom);
-                String[] response_parts = response.Split('|');
+                string response = Encoding.ASCII.GetString(bytesFrom);
+                string[] response_parts = response.Split('|');
 
                 if (response_parts.Length > 0)
                 {
@@ -73,16 +66,14 @@ namespace FietsClient
                                     new DoctorForm().Show();
                                     currentData = new CurrentData(userID);
                                 }
-                                else if(response_parts[2] == "0" && response_parts[1] == "1")
+                                else if (response_parts[2] == "0" && response_parts[1] == "1")
                                 {
                                     Form.ActiveForm.Dispose();
-                                    new PatientForm().Show();
                                     currentData = new CurrentData(userID);
+                                    new PatientForm().Show();
                                 }
                                 else
-                                {
                                     new Login("Geen gebruiker gevonden");
-                                }
                             }
                             break;
                         case "1":
@@ -107,7 +98,7 @@ namespace FietsClient
         public void sendGet(int GetWhat)
         {
             // send command ( cmdID | username )
-            sendString( GetWhat + "|" + userID );
+            sendString(GetWhat + "|" + userID);
 
         }