DoctorForm.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 && doctorTabControl.SelectedTab.Name != "tabPageSummary")
  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. else if (messageBox.Text != null && doctorTabControl.SelectedTab.Name == "tabPageSummary")
  57. {
  58. String[] data = new String[2];
  59. data[0] = "This is a broadcast: " + messageBox.Text + "\r\n";
  60. //all patients:
  61. for (int tabs = 1; tabs <= doctorTabControl.TabCount -1; tabs++)
  62. {
  63. doctorTabControl.SelectTab(tabs);
  64. data[1] = doctorTabControl.SelectedTab.Name;
  65. doctorModel.tcpConnection.SendChatMessage(data);
  66. }
  67. messageBox.Clear();
  68. }
  69. }
  70. private void printMessage(string[] data)
  71. {
  72. string finalMessage = data[0] + ":\t" + data[2] + "\r\n";
  73. chatBox.Invoke((MethodInvoker) delegate ()
  74. {
  75. chatBox.AppendText(finalMessage);
  76. });
  77. }
  78. public void AddSessionToTabcontrol(string patientID)
  79. {
  80. TabPage page = new TabPage("Patientsession " + patientID);
  81. page.Name = patientID;
  82. Forms.DoctorSessionUC sessionUC = new Forms.DoctorSessionUC(patientID);
  83. sessionUC.Name = "sessionUC" + patientID;
  84. doctorModel.doctorSessions.Add(patientID, sessionUC);
  85. doctorModel.doctorSessions.TryGetValue(patientID, out sessionUC);
  86. page.Controls.Add(sessionUC);
  87. doctorTabControl.TabPages.Add(page);
  88. }
  89. public void RemoveSessionFromTabcontrol(string patientID)
  90. {
  91. doctorTabControl.TabPages.RemoveByKey(patientID);
  92. }
  93. private void DoctorForm_FormClosing(object sender, FormClosingEventArgs e)
  94. {
  95. doctorModel.stopAskingData();
  96. doctorModel.tcpConnection.disconnect();
  97. Application.Exit();
  98. }
  99. private void nieuwePatientToolStripMenuItem_Click(object sender, EventArgs e)
  100. {
  101. var newPatient = new NewPatientForm(doctorModel.tcpConnection);
  102. newPatient.Show();
  103. }
  104. }
  105. }