public void AddSessionToTabcontrol(string patientID)
        {
            TabPage page = new TabPage("Patientsession " + patientID);

            page.Name = patientID;
            Forms.DoctorSessionUC sessionUC = new Forms.DoctorSessionUC(patientID);
            sessionUC.Name = "sessionUC" + patientID;
            doctorModel.doctorSessions.Add(patientID, sessionUC);
            doctorModel.doctorSessions.TryGetValue(patientID, out sessionUC);
            page.Controls.Add(sessionUC);
            doctorTabControl.TabPages.Add(page);
        }
Пример #2
0
        public void StartNewSession(bool isDoctor, string PatientID)
        {
            Session session = new Session(currentData.sessions.Count + 1);

            currentData.sessions.Add(session);
            if (!isDoctor)
            {
                SendNewSession();
                PatientModel.patientModel.startAskingData();
            }
            else if (isDoctor)
            {
                Forms.DoctorSessionUC sessionUC = null;
                bool b = DoctorModel.doctorModel.doctorSessions.TryGetValue(PatientID, out sessionUC);
                if (b)
                {
                    sessionUC.ClearOldSession();
                }
            }
        }
Пример #3
0
        public void receive()
        {
            while (client.Connected)
            {
                byte[] bytesFrom = new byte[(int)client.ReceiveBufferSize];
                try
                {
                    sslStream.Read(bytesFrom, 0, client.ReceiveBufferSize);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.StackTrace);
                    break;
                }

                string   response       = Encoding.ASCII.GetString(bytesFrom);
                string[] response_parts = response.Split('|');

                if (response_parts.Length > 0)
                {
                    switch (response_parts[0])
                    {
                    case "0":       //login and display correct window after login
                        if (response_parts.Length == 4)
                        {
                            if (response_parts[1] == "1" && response_parts[2] == "1")
                            {
                                currentData          = new CurrentData(userID);
                                currentData.isDoctor = true;
                                SendGet(1);
                            }
                            else if (response_parts[2] == "0" && response_parts[1] == "1")
                            {
                                currentData          = new CurrentData(userID);
                                currentData.isDoctor = false;
                                SendGet(1);
                            }
                            else
                            {
                                new Login("Geen gebruiker gevonden");
                            }
                        }
                        break;

                    case "1":
                        response_parts[1] = response_parts[1].TrimEnd('\0');
                        currentData.setSessionList(JsonConvert.DeserializeObject <List <Session> >(response_parts[1]));

                        if (currentData.isDoctor == true)
                        {
                            Form activeForm = Form.ActiveForm;
                            activeForm.Invoke((MethodInvoker) delegate()
                            {
                                DoctorForm doctorForm = new DoctorForm(this);
                                activeForm.Hide();
                                doctorForm.Show();
                            });
                        }
                        else
                        {
                            Form activeForm = Form.ActiveForm;
                            if (activeForm != null)
                            {
                                activeForm.Invoke((MethodInvoker) delegate()
                                {
                                    PatientForm patientForm = new PatientForm(this);
                                    activeForm.Hide();
                                    patientForm.Show();
                                });
                            }
                        }

                        break;

                    case "2":
                        dynamic     DynMeasurement    = JsonConvert.DeserializeObject <dynamic>(response_parts[2].TrimEnd('\0'));
                        Measurement outputMeasurement = new Measurement((int)DynMeasurement.pulse, (int)DynMeasurement.rpm, (int)DynMeasurement.speed, (int)DynMeasurement.distance, (int)DynMeasurement.requestedPower, (int)DynMeasurement.energy, (int)DynMeasurement.actualPower, (int)DynMeasurement.time);
                        currentData.GetSessions().Last().AddMeasurement(outputMeasurement);
                        Forms.DoctorSessionUC sessionUC = null;
                        bool b = DoctorModel.doctorModel.doctorSessions.TryGetValue(response_parts[1], out sessionUC);
                        if (b)
                        {
                            sessionUC.HandleSessionBikeData(outputMeasurement);
                        }
                        break;

                    case "7":
                        //                                        sender              receiver          message
                        onIncomingChatMessage(new string[] { response_parts[1], response_parts[2], response_parts[3].TrimEnd('\0') });
                        break;

                    case "8":
                        if (response_parts[1].TrimEnd('\0') != "-1")
                        {
                            DoctorModel.doctorModel.onlinePatients = response_parts[1].TrimEnd('\0').Split('\t').ToList();
                        }
                        else if (response_parts[1].TrimEnd('\0') == "-1")
                        {
                            DoctorModel.doctorModel.onlinePatients = new List <String>();
                        }
                        break;

                    case "9":
                        dynamic results = JsonConvert.DeserializeObject <dynamic>(response_parts[1]);

                        foreach (dynamic r in results)
                        {
                            User user = r as User;
                            users.Add(new User(r.id.ToString(), r.password.ToString(), Int32.Parse(r.age.ToString()),
                                               Boolean.Parse(r.gender.ToString()), Int32.Parse(r.weight.ToString()),
                                               Boolean.Parse(r.isDoctor.ToString())));

                            int i = 1;

                            foreach (dynamic ses in r.sessions)
                            {
                                Session tempSession = new Session(i);
                                i++;

                                foreach (dynamic m in ses.measurements)
                                {
                                    Measurement measurement = new Measurement((int)m.pulse, (int)m.rpm, (int)m.speed, (int)m.distance, (int)m.requestedPower, (int)m.energy, (int)m.actualPower, (int)m.time);;
                                    tempSession.AddMeasurement(measurement);
                                }

                                users.Last().AddSession(tempSession);
                            }
                            Console.WriteLine(users);
                        }
                        break;

                    case "10":
                        if (!currentData.isDoctor)
                        {
                            PatientModel.patientModel.CurrentDoctorID = response_parts[3].TrimEnd('\0');
                            if (response_parts[1] == "1")
                            {
                                PatientModel.patientModel.startSession();
                            }
                            else if (response_parts[1] == "0")
                            {
                                StopSessoin();
                            }
                        }
                        else
                        {
                            if (response_parts[1] == "1")
                            {
                                StartNewSession(true, response_parts[2]);
                            }
                        }
                        break;

                    case "20":
                        PatientModel.patientModel.setDistanceMode(response_parts[1].TrimEnd('\0'), false);
                        break;

                    case "21":
                        PatientModel.patientModel.setTimeMode(response_parts[1].TrimEnd('\0') + response_parts[2].TrimEnd('\0'), false);
                        break;

                    case "22":
                        //PatientModel.patientModel.setPower(response_parts[1].TrimEnd('\0'));

                        PatientModel.patientModel.powerLog = response_parts[1].TrimEnd('\0');
                        break;
                    }
                }
            }
        }
        public void AddSessionToTabcontrol(string patientID)
        {
            TabPage page = new TabPage("Patientsession " + patientID);
            page.Name = patientID;
            Forms.DoctorSessionUC sessionUC = new Forms.DoctorSessionUC(patientID);
            sessionUC.Name = "sessionUC" + patientID;
            doctorModel.doctorSessions.Add(patientID, sessionUC);
            doctorModel.doctorSessions.TryGetValue(patientID, out sessionUC);
            page.Controls.Add(sessionUC);
            doctorTabControl.TabPages.Add(page);

        }