private void btnSave_Click(object sender, EventArgs e)
        {
            var note       = tbNote.Text;
            var medication = tbMedication.Text;
            var entry      = tbEntry.Text;

            if (entry != String.Empty)
            {
                if (Treatment != null) // edit handover Treatment
                {
                    Treatment.Note       = tbNote.Text;
                    Treatment.Medication = tbMedication.Text;
                    Treatment.Entry      = tbEntry.Text;
                    Treatment.Update();
                    this.DialogResult = DialogResult.OK;
                }
                else // save new Treatment
                {
                    var treatment = new Model.Treatment(SelectedPatient.Id, DateTime.Now, entry, medication, note);
                    SelectedPatient.Treatments.Add(treatment);
                    this.DialogResult = DialogResult.OK;
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Um die Behandlung zu speichern, muss ein Eintrag getätigt werden.");
            }
        }
        public FrmTreatment(List <Model.Patient> patientList, Model.Treatment treatment) // edit handover treatment
        {
            InitializeComponent();

            Patients  = patientList;
            Treatment = treatment;

            foreach (var patient in patientList)
            {
                if (patient.Id == treatment.PatientId)
                {
                    SelectedPatient = patient;
                    break;
                }
            }

            cbPatient.Items.Add(SelectedPatient.Name);
            cbPatient.SelectedIndex = 0;
            cbPatient.Enabled       = false;

            tbEntry.Text      = treatment.Entry;
            tbMedication.Text = treatment.Medication;
            lblDate.Text      = treatment.Date.ToString("dd.MM.yyyy");
            tbNote.Text       = treatment.Note;

            tbEntry.Enabled      = true;
            tbMedication.Enabled = true;
            tbNote.Enabled       = true;
            btnSave.Enabled      = true;
        }
Ejemplo n.º 3
0
        public static Patient CreateTestPatient()
        {
            var birthday       = new DateTime(1999, 6, 18);
            var patientAddress = new Address("Heinz Peter", 86732, "deutschland", "bobostraße", "1", "elefanthausen",
                                             "01768743793", "banana");
            var docAddress = new Address("Dr. Olaf Günter", 72722, "deutschland", "tiefstraße", "5", "tiefendorf",
                                         "0908287483", "no banana");
            var cassAddress = new Address("Aok Hb", 72572, "deutschland", "blubstraße", "52", "blubdorf", "065422483",
                                          "maybe banana");
            var insuranceAgency = new InsuranceAgency(cassAddress, "definitly banana");
            var doctor          = new Doctor(docAddress, "Psychologie", "psychisch krank");


            var patient = new Patient(birthday, "male", insuranceAgency, 00001, doctor, patientAddress,
                                      "master Banana");
            var treatment = new Treatment(patient.Id, DateTime.Now, "testentry", "phenylpiracetam", "testnotiz");

            patient.Treatments.Add(treatment);

            return(patient);
        }
        public static int SaveTreatment(Treatment treatment)
        {
            var sql =
                $"INSERT INTO {Fieldnames.Treatments.Tablename}({Fieldnames.Treatments.PatientId}, {Fieldnames.Treatments.Date}, {Fieldnames.Treatments.Entry}, {Fieldnames.Treatments.Medication}, {Fieldnames.Treatments.Note})";

            sql +=
                $"VALUES(@{Fieldnames.Treatments.PatientId}, @{Fieldnames.Treatments.Date}, @{Fieldnames.Treatments.Entry}, @{Fieldnames.Treatments.Medication}, @{Fieldnames.Treatments.Note})";

            using (var c = new SQLiteConnection(@"Data Source = ..\..\..\..\DB\MYDb.db; Version = 3;"))
            {
                c.Open();

                using (var command = new SQLiteCommand(sql, c))
                {
                    command.Parameters.Add($"@{Fieldnames.Treatments.PatientId}", DbType.Int32).Value =
                        treatment.PatientId;
                    command.Parameters.Add($"@{Fieldnames.Treatments.Date}", DbType.String).Value =
                        Convert.ToString(treatment.Date);
                    command.Parameters.Add($"@{Fieldnames.Treatments.Entry}", DbType.String).Value      = treatment.Entry;
                    command.Parameters.Add($"@{Fieldnames.Treatments.Medication}", DbType.String).Value =
                        treatment.Medication;
                    command.Parameters.Add($"@{Fieldnames.Treatments.Note}", DbType.String).Value = treatment.Note;

                    command.ExecuteNonQuery();
                    command.Parameters.Clear();
                    command.CommandText = $"SELECT max(Id) FROM {Fieldnames.Treatments.Tablename}";

                    using (var reader = command.ExecuteReader())
                    {
                        reader.Read();
                        var maxId = reader.GetInt32(0);
                        treatment.SetId(maxId);
                        return(maxId);
                    }
                }
            }
        }