public static List <InsuranceAgency> GetInsuranceAgencies()
        {
            var agencies = new List <InsuranceAgency>();
            var sql      = $"SELECT * FROM {Fieldnames.InsuranceAgencys.TableName}";

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

                using (var command = new SQLiteCommand(sql, c))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var id        = reader.GetInt32((int)Fieldnames.InsuranceAgencys.Index.Id);
                            var addressId = reader.GetInt32((int)Fieldnames.InsuranceAgencys.Index.Address);
                            var note      = reader.GetString((int)Fieldnames.InsuranceAgencys.Index.Note);

                            Address address = GetAddress(addressId);

                            var agency = new InsuranceAgency();
                            agency.SetValues(id, address, note);
                            agencies.Add(agency);
                        }
                    }
                }
            }

            return(agencies);
        }
        private static InsuranceAgency GetInsuranceAgency(int insuranceAgencyId)
        {
            var insuranceAgency = new InsuranceAgency();
            var sql             = $"SELECT * FROM {Fieldnames.InsuranceAgencys.TableName} WHERE ID = " +
                                  Convert.ToString(insuranceAgencyId);

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

                using (var command = new SQLiteCommand(sql, c))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            var id        = reader.GetInt32((int)Fieldnames.InsuranceAgencys.Index.Id);
                            var addressId = reader.GetInt32((int)Fieldnames.InsuranceAgencys.Index.Address);
                            var note      = reader.GetString((int)Fieldnames.InsuranceAgencys.Index.Note);

                            var address = GetAddress(addressId);
                            insuranceAgency.SetValues(id, address, note);
                        }
                        else
                        {
                            throw DataError;
                        }
                    }
                }
            }

            return(insuranceAgency);
        }
        public static int SaveInsuranceAgency(InsuranceAgency agency)
        {
            int maxId;

            var sql =
                $"INSERT INTO {Fieldnames.InsuranceAgencys.TableName}({Fieldnames.InsuranceAgencys.Address}, {Fieldnames.InsuranceAgencys.Note})";

            sql += " VALUES(@Address, @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("@Address", DbType.Int32).Value = agency.Address.Id;
                    command.Parameters.Add("@Note", DbType.String).Value   = agency.Note;
                    command.ExecuteNonQuery();

                    command.Parameters.Clear();
                    command.CommandText = $"select max(Id) from {Fieldnames.InsuranceAgencys.TableName}";

                    using (var reader = command.ExecuteReader())
                    {
                        reader.Read();
                        maxId     = reader.GetInt32(0);
                        agency.Id = maxId;
                    }
                }
            }

            return(maxId);
        }
예제 #4
0
 public Patient(int id, DateTime birthday, string gender, InsuranceAgency insuranceAgency, int insuranceNr,
                Doctor localDoctor, Address address, string note) //für implementierung aus Datenbankdaten
 {
     Id              = id;
     Birthday        = birthday;
     Gender          = gender;
     InsuranceAgency = insuranceAgency;
     InsuranceNr     = insuranceNr;
     LocalDoctor     = localDoctor;
     Address         = address;
     Note            = note;
     Treatments      = Databasemanager.GetTreatments(id);
 }
예제 #5
0
 public Patient(DateTime birthday, string gender, InsuranceAgency insuranceAgency, int insuranceNr,
                Doctor localDoctor, Address address, string note) //für Neuimplementierung
 {
     Birthday        = birthday;
     Gender          = gender;
     InsuranceAgency = insuranceAgency;
     InsuranceNr     = insuranceNr;
     LocalDoctor     = localDoctor;
     Address         = address;
     Note            = note;
     Id         = Databasemanager.SavePatient(this);
     Treatments = new List <Treatment>();
 }
        public static void UpdateInsuranceAgency(InsuranceAgency insuranceAgency)
        {
            var validDataSet = false;

            var sqlCheck =
                $"SELECT * FROM {Fieldnames.InsuranceAgencys.TableName} WHERE {Fieldnames.InsuranceAgencys.Id} = @{Fieldnames.InsuranceAgencys.Id}";

            var sqlUpdate = $"UPDATE {Fieldnames.InsuranceAgencys.TableName} SET " +
                            $"{Fieldnames.InsuranceAgencys.Address} = @{Fieldnames.InsuranceAgencys.Address}, " +
                            $"{Fieldnames.InsuranceAgencys.Note} = @{Fieldnames.InsuranceAgencys.Note} " +
                            $"WHERE {Fieldnames.InsuranceAgencys.Id} = @{Fieldnames.InsuranceAgencys.Id}";

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

                using (var command = new SQLiteCommand(sqlCheck, c))
                {
                    command.Parameters.Add($@"{Fieldnames.InsuranceAgencys.Id}", DbType.Int32).Value = insuranceAgency.Id;
                    using (SQLiteDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            validDataSet = true;
                        }
                    }

                    if (validDataSet)
                    {
                        command.Parameters.Clear();
                        command.CommandText = sqlUpdate;

                        command.Parameters.Add($"@{Fieldnames.InsuranceAgencys.Address}", DbType.Int32).Value =
                            insuranceAgency.Address.Id;
                        command.Parameters.Add($"@{Fieldnames.InsuranceAgencys.Note}", DbType.String).Value =
                            insuranceAgency.Note;
                        command.Parameters.Add($"@{Fieldnames.InsuranceAgencys.Id}", DbType.Int32).Value =
                            insuranceAgency.Id;

                        command.ExecuteNonQuery();
                    }
                }
            }
        }
        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);
        }