DoctorForm.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. namespace FietsClient
  11. {
  12. public partial class DoctorForm : Form
  13. {
  14. private DoctorModel doctorModel;
  15. public Forms.DoctorSummaryUC summaryUserControl { get; private set; }
  16. public DoctorForm(TcpConnection connection)
  17. {
  18. InitializeComponent();
  19. doctorModel = DoctorModel.doctorModel;
  20. doctorModel.doctorform = this;
  21. doctorModel.tcpConnection = connection;
  22. this.summaryUserControl = doctorSummaryUC1;
  23. DataHandler.IncomingErrorEvent += HandleError;
  24. connection.IncomingChatmessageEvent += new TcpConnection.ChatmassegeDelegate(printMessage);
  25. }
  26. private void HandleError(string error)
  27. {
  28. switch (error)
  29. {
  30. default:
  31. break;
  32. }
  33. }
  34. private void Form1_Load(object sender, EventArgs e)
  35. {
  36. }
  37. private void messageBox_KeyPress(object sender, KeyPressEventArgs e)
  38. {
  39. if (e.KeyChar == '\r')
  40. {
  41. messageButton_Click(sender, e);
  42. }
  43. }
  44. private void messageButton_Click(object sender, EventArgs e)
  45. {
  46. if (messageBox.Text != null && doctorTabControl.SelectedTab.Name != "tabPageSummary")
  47. {
  48. String[] data = new String[2];
  49. data[0] = messageBox.Text;
  50. //current patient:
  51. data[1] = doctorTabControl.SelectedTab.Name;
  52. messageBox.Clear();
  53. doctorModel.tcpConnection.SendChatMessage(data);
  54. }
  55. else if (messageBox.Text != null && doctorTabControl.SelectedTab.Name == "tabPageSummary")
  56. {
  57. String[] data = new String[2];
  58. data[0] = "This is a broadcast: " + messageBox.Text;
  59. //all patients:
  60. for (int tabs = 1; tabs <= doctorTabControl.TabCount -1; tabs++)
  61. {
  62. doctorTabControl.SelectTab(tabs);
  63. data[1] = doctorTabControl.SelectedTab.Name;
  64. doctorModel.tcpConnection.SendChatMessage(data);
  65. }
  66. messageBox.Clear();
  67. }
  68. }
  69. private void printMessage(string[] data)
  70. {
  71. string finalMessage = "\r\n" + data[0] + ":\t" + data[2];
  72. chatBox.Invoke((MethodInvoker) delegate ()
  73. {
  74. chatBox.AppendText(finalMessage);
  75. });
  76. }
  77. public void AddSessionToTabcontrol(string patientID)
  78. {
  79. TabPage page = new TabPage("Patientsession " + patientID);
  80. page.Name = patientID;
  81. Forms.DoctorSessionUC sessionUC = new Forms.DoctorSessionUC(patientID);
  82. sessionUC.Name = "sessionUC" + patientID;
  83. doctorModel.doctorSessions.Add(patientID, sessionUC);
  84. doctorModel.doctorSessions.TryGetValue(patientID, out sessionUC);
  85. page.Controls.Add(sessionUC);
  86. doctorTabControl.TabPages.Add(page);
  87. }
  88. public void RemoveSessionFromTabcontrol(string patientID)
  89. {
  90. doctorTabControl.TabPages.RemoveByKey(patientID);
  91. }
  92. private void DoctorForm_FormClosing(object sender, FormClosingEventArgs e)
  93. {
  94. doctorModel.stopAskingData();
  95. doctorModel.tcpConnection.disconnect();
  96. Application.Exit();
  97. }
  98. }
  99. }