DoctorForm.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using FietsClient.Forms;
  11. namespace FietsClient
  12. {
  13. public partial class DoctorForm : Form
  14. {
  15. private DoctorModel doctorModel;
  16. public Forms.DoctorSummaryUC summaryUserControl { get; private set; }
  17. public DoctorForm(TcpConnection connection)
  18. {
  19. InitializeComponent();
  20. doctorModel = DoctorModel.doctorModel;
  21. doctorModel.doctorform = this;
  22. doctorModel.tcpConnection = connection;
  23. this.summaryUserControl = doctorSummaryUC1;
  24. DataHandler.IncomingErrorEvent += HandleError;
  25. connection.IncomingChatmessageEvent += new TcpConnection.ChatmassegeDelegate(printMessage);
  26. }
  27. private void HandleError(string error)
  28. {
  29. switch (error)
  30. {
  31. default:
  32. break;
  33. }
  34. }
  35. private void Form1_Load(object sender, EventArgs e)
  36. {
  37. }
  38. private void messageBox_KeyPress(object sender, KeyPressEventArgs e)
  39. {
  40. if (e.KeyChar == '\r')
  41. {
  42. messageButton_Click(sender, e);
  43. }
  44. }
  45. private void messageButton_Click(object sender, EventArgs e)
  46. {
  47. if (messageBox.Text != null)
  48. {
  49. String[] data = new String[2];
  50. data[0] = messageBox.Text;
  51. //current patient:
  52. data[1] = doctorTabControl.SelectedTab.Name;
  53. messageBox.Clear();
  54. doctorModel.tcpConnection.SendChatMessage(data);
  55. }
  56. }
  57. private void printMessage(string[] data)
  58. {
  59. string finalMessage = "\r\n" + data[0] + ":\t" + data[2];
  60. chatBox.Invoke((MethodInvoker) delegate ()
  61. {
  62. chatBox.AppendText(finalMessage);
  63. });
  64. }
  65. public void AddSessionToTabcontrol(string patientID)
  66. {
  67. TabPage page = new TabPage("Patientsession " + patientID);
  68. page.Name = patientID;
  69. Forms.DoctorSessionUC sessionUC = new Forms.DoctorSessionUC(patientID);
  70. sessionUC.Name = "sessionUC" + patientID;
  71. doctorModel.doctorSessions.Add(patientID, sessionUC);
  72. doctorModel.doctorSessions.TryGetValue(patientID, out sessionUC);
  73. page.Controls.Add(sessionUC);
  74. doctorTabControl.TabPages.Add(page);
  75. }
  76. public void RemoveSessionFromTabcontrol(string patientID)
  77. {
  78. doctorTabControl.TabPages.RemoveByKey(patientID);
  79. }
  80. private void DoctorForm_FormClosing(object sender, FormClosingEventArgs e)
  81. {
  82. doctorModel.stopAskingData();
  83. doctorModel.tcpConnection.disconnect();
  84. Application.Exit();
  85. }
  86. private void nieuwePatientToolStripMenuItem_Click(object sender, EventArgs e)
  87. {
  88. var newPatient = new NewPatientForm(doctorModel.tcpConnection);
  89. newPatient.Show();
  90. }
  91. }
  92. }