Example #1
0
 private void LoginBT_Click(object sender, EventArgs e)
 {
     if (UserTB.Text == "doctor" && PasswordTB.Text == "password")
     {
         if (comboBox1.SelectedIndex == 0)
         {
             DataForm form1 = new DataForm();
             form1.Show();
             this.Close();
         }
         else
         {
             HistoryForm form4 = new HistoryForm();
             form4.Show();
             this.Close();
         }
     }
     else
     {
         MessageBox.Show("verkeerde username of wachtwoord ingevoerd");
     }
 }
        private void LoginBT_Click(object sender, EventArgs e)
        {
            try
            {
                TcpClient client = new TcpClient();
                client.Connect("127.0.0.1", 13000);
                stream = client.GetStream();

                string  usernameText = UserTB.Text;
                string  passwordText = PasswordTB.Text;
                dynamic toJson       = new
                {
                    id   = "doctor/login",
                    data = new
                    {
                        username = usernameText,
                        password = passwordText
                    }
                };

                string message = JsonConvert.SerializeObject(toJson);
                byte[] prefix  = BitConverter.GetBytes(message.Length);
                byte[] request = Encoding.Default.GetBytes(message);

                byte[] buffer = new Byte[prefix.Length + message.Length];
                prefix.CopyTo(buffer, 0);
                request.CopyTo(buffer, prefix.Length);

                stream.Write(buffer, 0, buffer.Length);
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine("ArgumentNullException: {0}", ex);
            }
            catch (SocketException ex)
            {
                Console.WriteLine("SocketException: {0}", ex);
            }

            JObject Json = readObject();

            if (Json.SelectToken("id").ToString() == "login/succes")
            {
                if (comboBox1.SelectedIndex == 0)
                {
                    DataForm dataForm = new DataForm(stream);
                    dataForm.Show();
                    this.Close();
                }
                else
                {
                    HistoryForm historyForm = new HistoryForm();
                    historyForm.Show();
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("verkeerde username of wachtwoord ingevoerd");
            }
        }