示例#1
0
文件: Program.cs 项目: KasperSK/I4DAB
        static void AddPerson1(AddresseKartotekDal myDal)
        {
            var folkeadr = new Addresse()
            {
                Bynavn = "Aarhus",
                Husnummer = "92",
                PostNummer = 8200,
                Vejnavn = "Finlandsgade"
            };
            myDal.CreateAddresse(folkeadr);

            var workadr = new Addresse()
            {
                Bynavn = "Aarhus",
                Husnummer = "80",
                PostNummer = 8200,
                Vejnavn = "Oslogade"
            };
            myDal.CreateAddresse(workadr);

            var person = new Person()
            {
                Fornavn = "Top",
                Mellemnavn = "Tom",
                Efternavn = "Hat",
                Forhold = "Anstrengt"
            };
            myDal.CreatePerson(person);

            var telefon = new Telefon()
            {
                Number = "80808080",
                Forhold = "Arbejde"
            };
            myDal.CreateTelefon(telefon, person);

            myDal.ConnectEkstraAddresse(person, workadr, "Arbejde");
            myDal.ConnectEkstraAddresse(person, folkeadr, "Hjemme");
            myDal.UpdateFolkeregisterAddresse(person, folkeadr);
        }
示例#2
0
文件: Program.cs 项目: KasperSK/I4DAB
 static void PrintTelefon(Telefon tlf)
 {
     Console.WriteLine("Forhold: " + tlf.Forhold);
     Console.WriteLine("Nummer: " + tlf.Number);
 }
示例#3
0
文件: Class1.cs 项目: KasperSK/I4DAB
 public void UpdateTelefon(Telefon telefon)
 {
     _akdc.Open();
     const string commandText = @"
                                 UPDATE
                                     Telefon
                                 SET
                                     Nummer=@Nummer,
                                     Forhold=@Forhold
                                 WHERE
                                     Id = @Id
                                 ";
     var cmd = new SqlCommand(commandText, _akdc);
     cmd.Parameters.AddWithValue("@Nummer", telefon.Number);
     cmd.Parameters.AddWithValue("@Forhold", telefon.Forhold);
     cmd.Parameters.AddWithValue("@Id", telefon.Id);
     cmd.ExecuteNonQuery();
     _akdc.Close();
 }
示例#4
0
文件: Class1.cs 项目: KasperSK/I4DAB
 public Telefon ReadTelefon(int telefonid)
 {
     _akdc.Open();
     const string commandText = @"
                                 SELECT
                                     Nummer, Forhold
                                 FROM
                                     Telefonnummer
                                 WHERE
                                     Id = @Id
                                 ";
     var cmd = new SqlCommand(commandText, _akdc);
     cmd.Parameters.AddWithValue("@Id", telefonid);
     var reader = cmd.ExecuteReader();
     reader.Read();
     var telefon = new Telefon
     {
         Id = telefonid,
         Number = reader["Nummer"].ToString(),
         Forhold = reader["Forhold"].ToString(),
     };
     _akdc.Close();
     return telefon;
 }
示例#5
0
文件: Class1.cs 项目: KasperSK/I4DAB
 public void DeleteTelefon(Telefon telefon)
 {
     _akdc.Open();
     const string commandText = @"
                                 DELETE FROM
                                     Telefon
                                 WHERE
                                     Id = @Id
                                 ";
     var cmd = new SqlCommand(commandText, _akdc);
     cmd.Parameters.AddWithValue("@Id", telefon.Id);
     cmd.ExecuteNonQuery();
     _akdc.Close();
 }
示例#6
0
文件: Class1.cs 项目: KasperSK/I4DAB
 public void CreateTelefon(Telefon telefon, Person person)
 {
     _akdc.Open();
     const string commandText = @"INSERT INTO
                                     Telefonnummer
                                     (Nummer, Forhold, PersonID)
                                 OUTPUT
                                     INSERTED.ID
                                 VALUES
                                     (@Nummer, @Forhold, @PersonID)";
     var cmd = new SqlCommand(commandText, _akdc);
     cmd.Parameters.AddWithValue("@Nummer", telefon.Number);
     cmd.Parameters.AddWithValue("@Forhold", telefon.Forhold);
     cmd.Parameters.AddWithValue("@PersonID", person.Id);
     var id = (int) cmd.ExecuteScalar();
     telefon.Id = id;
     _akdc.Close();
 }
示例#7
0
文件: Dal.cs 项目: KasperSK/I4DAB
 public Telefon ReadTelefon(int telefonid)
 {
     Telefon telefon = null;
     SqlDataReader reader = null;
     try
     {
         _akdc.Open();
         const string commandText = @"
                                 SELECT
                                     Nummer, Forhold
                                 FROM
                                     Telefonnummer
                                 WHERE
                                     Id = @Id
                                 ";
         using (var cmd = new SqlCommand(commandText, _akdc))
         {
             cmd.Parameters.AddWithValue("@Id", telefonid);
             reader = cmd.ExecuteReader();
             reader.Read();
             telefon = new Telefon
             {
                 Id = telefonid,
                 Number = reader["Nummer"].ToString(),
                 Forhold = reader["Forhold"].ToString(),
             };
         }
     }
     finally
     {
         reader?.Close();
         _akdc?.Close();
     }
     return telefon;
 }