Пример #1
0
        public void WriteData(AbstractTransaction aTransaction, AbstractConnection aConnection, TouristDataSet dataSet)
        {
            NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter
            {
                UpdateCommand = new NpgsqlCommand("update sight set sight_name=:name, sight_descr=:descr where id=:id"),
                InsertCommand = new NpgsqlCommand("insert into sight (sight_name, sight_descr) values (:name, :descr)"),
                DeleteCommand = new NpgsqlCommand("delete from sight where id=:id")
            };

            dataAdapter.UpdateCommand.Connection  = aConnection.connection;
            dataAdapter.UpdateCommand.Transaction = aTransaction.transaction;
            dataAdapter.InsertCommand.Connection  = aConnection.connection;
            dataAdapter.InsertCommand.Transaction = aTransaction.transaction;
            dataAdapter.DeleteCommand.Connection  = aConnection.connection;
            dataAdapter.DeleteCommand.Transaction = aTransaction.transaction;

            NpgsqlParameter paramIdU = new NpgsqlParameter
            {
                SourceColumn  = "id",
                ParameterName = ":id"
            };
            NpgsqlParameter paramIdD = new NpgsqlParameter
            {
                SourceColumn  = "id",
                ParameterName = ":id"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramIdU);
            dataAdapter.DeleteCommand.Parameters.Add(paramIdD);

            NpgsqlParameter paramNameU = new NpgsqlParameter
            {
                SourceColumn  = "sight_name",
                ParameterName = ":name"
            };
            NpgsqlParameter paramNameI = new NpgsqlParameter
            {
                SourceColumn  = "sight_name",
                ParameterName = ":name"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramNameU);
            dataAdapter.InsertCommand.Parameters.Add(paramNameI);

            NpgsqlParameter paramDescrU = new NpgsqlParameter
            {
                SourceColumn  = "sight_descr",
                ParameterName = ":descr"
            };
            NpgsqlParameter paramDescrI = new NpgsqlParameter
            {
                SourceColumn  = "sight_descr",
                ParameterName = ":descr"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramDescrU);
            dataAdapter.InsertCommand.Parameters.Add(paramDescrI);

            dataAdapter.Update(dataSet, "sight");
        }
Пример #2
0
        public static void Main()
        {
            TouristDataSet     touristDataSet = new TouristDataSet();
            AbstractConnection connection     = ConnectionFactory.CreateConnection();

            connection.Open();
            try
            {
                AbstractTransaction transaction = connection.BeginTransaction();
                try
                {
                    sightDataAccessor.ReadData(transaction, connection, touristDataSet);
                    //sightDataAccessor.Update(connection, transaction, result);

                    //docAccessor.Update(connection, transaction, result);
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw e;
                }
            } finally {
                connection.Close();
            }
            Console.WriteLine(touristDataSet.Sight.Count);
            Console.ReadKey();
            return;
        }
Пример #3
0
        public AbstractTransaction BeginTransaction()
        {
            NpgsqlTransaction transaction = connection.BeginTransaction();

            AbstractTransaction result = new AbstractTransaction();

            result.transaction = transaction;
            return(result);
        }
Пример #4
0
        public void ReadData(AbstractTransaction aTransaction, AbstractConnection aConnection, TouristDataSet dataSet)
        {
            NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter
            {
                SelectCommand = new NpgsqlCommand("select * from instructor")
            };

            dataAdapter.SelectCommand.Connection  = aConnection.connection;
            dataAdapter.SelectCommand.Transaction = aTransaction.transaction;
            dataAdapter.Fill(dataSet, "instructor");
        }
Пример #5
0
        public void WriteData(AbstractTransaction aTransaction, AbstractConnection aConnection, TouristDataSet dataSet)
        {
            NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter
            {
                UpdateCommand = new NpgsqlCommand("update tourtype set tour_type_name=:tour_type_name where id=:id"),
                InsertCommand = new NpgsqlCommand("insert into tourtype (tour_type_name) values (:tour_type_name)"),
                DeleteCommand = new NpgsqlCommand("delete from tourtype where id=:id")
            };

            dataAdapter.UpdateCommand.Connection  = aConnection.connection;
            dataAdapter.UpdateCommand.Transaction = aTransaction.transaction;
            dataAdapter.InsertCommand.Connection  = aConnection.connection;
            dataAdapter.InsertCommand.Transaction = aTransaction.transaction;
            dataAdapter.DeleteCommand.Connection  = aConnection.connection;
            dataAdapter.DeleteCommand.Transaction = aTransaction.transaction;

            NpgsqlParameter paramIdU = new NpgsqlParameter
            {
                SourceColumn  = "id",
                ParameterName = ":id"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramIdU);

            NpgsqlParameter paramIdD = new NpgsqlParameter
            {
                SourceColumn  = "id",
                ParameterName = ":id"
            };

            dataAdapter.DeleteCommand.Parameters.Add(paramIdD);

            NpgsqlParameter paramTourTypeNameU = new NpgsqlParameter
            {
                SourceColumn  = "tour_type_name",
                ParameterName = ":tour_type_name"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramTourTypeNameU);

            NpgsqlParameter paramTourTypeNameI = new NpgsqlParameter
            {
                SourceColumn  = "tour_type_name",
                ParameterName = ":tour_type_name"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramTourTypeNameI);

            dataAdapter.Update(dataSet, "tourtype");
        }
Пример #6
0
        public void WriteData(AbstractTransaction aTransaction, AbstractConnection aConnection, TouristDataSet dataSet)
        {
            NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter
            {
                UpdateCommand = new NpgsqlCommand("update instructor set surname=:surname, forename=:forename, patronymic=:patronymic, id_schedule=:id_schedule, id_tour_type=:id_tour_type where id=:id"),
                InsertCommand = new NpgsqlCommand("insert into instructor (surname, forename, patronymic, id_schedule, id_tour_type) values (:surname, :forename, :patronymic, :id_schedule, :id_tour_type)"),
                DeleteCommand = new NpgsqlCommand("delete from instructor where id=:id")
            };

            dataAdapter.UpdateCommand.Connection  = aConnection.connection;
            dataAdapter.UpdateCommand.Transaction = aTransaction.transaction;
            dataAdapter.InsertCommand.Connection  = aConnection.connection;
            dataAdapter.InsertCommand.Transaction = aTransaction.transaction;
            dataAdapter.DeleteCommand.Connection  = aConnection.connection;
            dataAdapter.DeleteCommand.Transaction = aTransaction.transaction;

            NpgsqlParameter paramIdU = new NpgsqlParameter
            {
                SourceColumn  = "id",
                ParameterName = ":id"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramIdU);

            NpgsqlParameter paramIdD = new NpgsqlParameter
            {
                SourceColumn  = "id",
                ParameterName = ":id"
            };

            dataAdapter.DeleteCommand.Parameters.Add(paramIdD);

            NpgsqlParameter paramSurnameU = new NpgsqlParameter
            {
                SourceColumn  = "surname",
                ParameterName = ":surname"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramSurnameU);

            NpgsqlParameter paramSurnameI = new NpgsqlParameter
            {
                SourceColumn  = "surname",
                ParameterName = ":surname"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramSurnameI);

            NpgsqlParameter paramForenameU = new NpgsqlParameter
            {
                SourceColumn  = "forename",
                ParameterName = ":forename"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramForenameU);

            NpgsqlParameter paramForenameI = new NpgsqlParameter
            {
                SourceColumn  = "forename",
                ParameterName = ":forename"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramForenameI);

            NpgsqlParameter paramPatronymicU = new NpgsqlParameter
            {
                SourceColumn  = "patronymic",
                ParameterName = ":patronymic"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramPatronymicU);

            NpgsqlParameter paramPatronymicI = new NpgsqlParameter
            {
                SourceColumn  = "patronymic",
                ParameterName = ":patronymic"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramPatronymicI);

            NpgsqlParameter paramIdScheduleU = new NpgsqlParameter
            {
                SourceColumn  = "id_schedule",
                ParameterName = ":id_schedule"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramIdScheduleU);

            NpgsqlParameter paramIdScheduleI = new NpgsqlParameter
            {
                SourceColumn  = "id_schedule",
                ParameterName = ":id_schedule"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramIdScheduleI);

            NpgsqlParameter paramIdTourTypeU = new NpgsqlParameter
            {
                SourceColumn  = "id_tour_type",
                ParameterName = ":id_tour_type"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramIdTourTypeU);

            NpgsqlParameter paramIdTourTypeI = new NpgsqlParameter
            {
                SourceColumn  = "id_tour_type",
                ParameterName = ":id_tour_type"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramIdTourTypeI);

            dataAdapter.Update(dataSet, "instructor");
        }
Пример #7
0
        public void WriteData(AbstractTransaction aTransaction, AbstractConnection aConnection, TouristDataSet dataSet)
        {
            NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter
            {
                UpdateCommand = new NpgsqlCommand("update tour set tour_name=:name, tour_descr=:descr, id_sight=:id_sight, id_schedule=:id_schedule, id_tour_type=:id_tour_type where id=:id"),
                InsertCommand = new NpgsqlCommand("insert into tour (tour_name, tour_descr, id_sight, id_schedule, id_tour_type) values (:name, :descr, :id_sight, :id_schedule, :id_tour_type)"),
                DeleteCommand = new NpgsqlCommand("delete from tour where id=:id")
            };

            dataAdapter.UpdateCommand.Connection  = aConnection.connection;
            dataAdapter.UpdateCommand.Transaction = aTransaction.transaction;
            dataAdapter.InsertCommand.Connection  = aConnection.connection;
            dataAdapter.InsertCommand.Transaction = aTransaction.transaction;
            dataAdapter.DeleteCommand.Connection  = aConnection.connection;
            dataAdapter.DeleteCommand.Transaction = aTransaction.transaction;

            NpgsqlParameter paramIdU = new NpgsqlParameter
            {
                SourceColumn  = "id",
                ParameterName = ":id"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramIdU);

            NpgsqlParameter paramIdD = new NpgsqlParameter
            {
                SourceColumn  = "id",
                ParameterName = ":id"
            };

            dataAdapter.DeleteCommand.Parameters.Add(paramIdD);

            NpgsqlParameter paramNameU = new NpgsqlParameter
            {
                SourceColumn  = "tour_name",
                ParameterName = ":name"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramNameU);

            NpgsqlParameter paramNameI = new NpgsqlParameter
            {
                SourceColumn  = "tour_name",
                ParameterName = ":name"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramNameI);

            NpgsqlParameter paramDescrU = new NpgsqlParameter
            {
                SourceColumn  = "tour_descr",
                ParameterName = ":descr"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramDescrU);

            NpgsqlParameter paramDescrI = new NpgsqlParameter
            {
                SourceColumn  = "tour_descr",
                ParameterName = ":descr"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramDescrI);

            NpgsqlParameter paramIdSightU = new NpgsqlParameter
            {
                SourceColumn  = "id_sight",
                ParameterName = ":id_sight"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramIdSightU);

            NpgsqlParameter paramIdSightI = new NpgsqlParameter
            {
                SourceColumn  = "id_sight",
                ParameterName = ":id_sight"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramIdSightI);

            NpgsqlParameter paramIdScheduleU = new NpgsqlParameter
            {
                SourceColumn  = "id_schedule",
                ParameterName = ":id_schedule"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramIdScheduleU);

            NpgsqlParameter paramIdScheduleI = new NpgsqlParameter
            {
                SourceColumn  = "id_schedule",
                ParameterName = ":id_schedule"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramIdScheduleI);

            NpgsqlParameter paramIdTourTypeU = new NpgsqlParameter
            {
                SourceColumn  = "id_tour_type",
                ParameterName = ":id_tour_type"
            };

            dataAdapter.UpdateCommand.Parameters.Add(paramIdTourTypeU);

            NpgsqlParameter paramIdTourTypeI = new NpgsqlParameter
            {
                SourceColumn  = "id_tour_type",
                ParameterName = ":id_tour_type"
            };

            dataAdapter.InsertCommand.Parameters.Add(paramIdTourTypeI);

            dataAdapter.Update(dataSet, "tour");
        }