Ejemplo n.º 1
0
        public void NewTestee(Testee temp)
        {
            using (NpgsqlConnection connection = new NpgsqlConnection(connections))
            {
                connection.Open();
                using (NpgsqlTransaction transaction = connection.BeginTransaction())
                {
                    using (NpgsqlCommand command = new NpgsqlCommand(testeeInsertQuery, connection))
                    {
                        command.Transaction = transaction;
                        command.Parameters.Add("@surname", NpgsqlTypes.NpgsqlDbType.Varchar, 200);
                        command.Parameters.Add("@name", NpgsqlTypes.NpgsqlDbType.Varchar, 200);
                        command.Parameters.Add("@patronium", NpgsqlTypes.NpgsqlDbType.Varchar, 200);
                        command.Parameters.Add("@birth_date", NpgsqlTypes.NpgsqlDbType.Date);
                        command.Parameters.Add("@id_gender", NpgsqlTypes.NpgsqlDbType.Integer);

                        try
                        {
                            command.Parameters[0].Value = temp.Surname;
                            command.Parameters[1].Value = temp.Name;
                            command.Parameters[2].Value = temp.Patronium;
                            command.Parameters[3].Value = temp.BirthDate;
                            command.Parameters[4].Value = temp.ID_gender;
                            if (command.ExecuteNonQuery() != 1)
                            {
                                throw new InvalidProgramException();
                            }
                            transaction.Commit();
                        }
                        catch (Exception) { transaction.Rollback(); }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void PopulateTesteesList()
 {
     testeesList.Clear();
     using (NpgsqlConnection connection = new NpgsqlConnection(connections))
     {
         using (NpgsqlCommand command = new NpgsqlCommand(testeeSelectQuery, connection))
         {
             connection.Open();
             NpgsqlDataReader reader = command.ExecuteReader();
             if (reader.HasRows)
             {
                 while (reader.Read())
                 {
                     Testee temp = new Testee
                     {
                         ID_testee = reader.GetInt16(0),
                         ID_gender = reader.GetInt16(1),
                         Surname   = reader.GetString(2),
                         Name      = reader.GetString(3),
                         Patronium = reader.GetString(4),
                         BirthDate = reader.GetDateTime(5)
                     };
                     testeesList.Add(temp);
                 }
             }
             reader.Close();
         }
     }
 }
        //----------ИСПЫТУЕМЫЕ----------//

        private void AddTestee(object sender, RoutedEventArgs e)
        {
            Testee temp = new Testee
            {
                Surname   = tbSurname.Text,
                Name      = tbName.Text,
                Patronium = tbPatronium.Text,
                BirthDate = (DateTime)dpBirthDate.SelectedDate,
                ID_gender = (int)cbGender.SelectedValue
            };

            dbsender.NewTestee(temp);
            testeesList = RefreshTesteesList();
        }