DoctorForm.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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)
  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. }
  56. private void printMessage(string[] data)
  57. {
  58. string finalMessage = data[0] + ":\t\t" + data[2] + "\r\n";
  59. chatBox.Invoke((MethodInvoker) delegate ()
  60. {
  61. chatBox.AppendText(finalMessage);
  62. });
  63. }
  64. public void AddSessionToTabcontrol(string patientID)
  65. {
  66. TabPage page = new TabPage("Patientsession " + patientID);
  67. page.Name = patientID;
  68. Forms.DoctorSessionUC sessionUC = new Forms.DoctorSessionUC(patientID);
  69. sessionUC.Name = "sessionUC" + patientID;
  70. doctorModel.doctorSessions.Add(patientID, sessionUC);
  71. doctorModel.doctorSessions.TryGetValue(patientID, out sessionUC);
  72. page.Controls.Add(sessionUC);
  73. doctorTabControl.TabPages.Add(page);
  74. }
  75. public void RemoveSessionFromTabcontrol(string patientID)
  76. {
  77. doctorTabControl.TabPages.RemoveByKey(patientID);
  78. }
  79. private void DoctorForm_FormClosing(object sender, FormClosingEventArgs e)
  80. {
  81. doctorModel.stopAskingData();
  82. doctorModel.tcpConnection.disconnect();
  83. Application.Exit();
  84. }
  85. }
  86. }