Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        public void TourTypeReadNotEmptyTable()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet       ds = new TouristDataSet();
            TourTypeDataAccessor tourTypeDataAccessor = new TourTypeDataAccessor();
            AbstractTransaction  abstractTransaction  = abstractConnection.BeginTransaction();

            //Читаем строки с БД и смотрим их число
            tourTypeDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElements = ds.TourType.Count;

            //Добавляем строку и пишем в базу
            ds.TourType.AddTourTypeRow("Поход в горы");
            tourTypeDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.TourType.Clear();

            //Читаем снова и смотрим на последнюю строку
            tourTypeDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();
            Assert.AreEqual("Поход в горы", ds.TourType[countElements].tour_type_name);
        }
Exemplo n.º 3
0
        public void SightDelete()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet      ds = new TouristDataSet();
            SightDataAccessor   sightDataAccessor   = new SightDataAccessor();
            AbstractTransaction abstractTransaction = abstractConnection.BeginTransaction();

            //Читаем данные с БД в датасет и смотрим число строк
            sightDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElements = ds.Sight.Count;

            ds.Sight.Clear();

            //Добавляем строку в датасет и записываем в БД
            ds.Sight.AddSightRow("String", "ToDelete");
            sightDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);

            //Чистим датасет, записываем в него ещё раз и удаляем из него последнюю запись
            ds.Sight.Clear();
            sightDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            ds.Sight[countElements].Delete();

            //Пишем в БД и снова читаем из неё в датасет
            sightDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Sight.Clear();
            sightDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();

            //Смотрим число строк до всех манипуляций и после
            Assert.AreEqual(ds.Sight.Count, countElements);
        }
Exemplo n.º 4
0
        void ReloadTable()
        {
            //Очистка колонок нужна для удаления кастомных колонок: "Дата тура" и "Название тура"
            //После переустановки DataSource остальные колонки подтянутся автоматически, а кастомные - заново сгенерируются
            dataGridView_instructor.Columns.Clear();

            touristDataSet = touristServiceExporter.ReadInstructor();
            dataGridView_instructor.DataSource = touristDataSet;
            dataGridView_instructor.DataMember = "Instructor";
            dataGridView_instructor.Columns.Add("tour_type_name", "Тип тура");
            dataGridView_instructor.Columns.Add("tour_date", "Дата выхода");
            foreach (DataGridViewRow row in dataGridView_instructor.Rows)
            {
                row.Cells["tour_type_name"].Value = touristDataSet.TourType.Rows.Find(row.Cells["id_tour_type"].Value)["tour_type_name"];
                row.Cells["tour_date"].Value      = touristDataSet.Schedule.Rows.Find(row.Cells["id_schedule"].Value)["tour_date"];
            }
            dataGridView_instructor.Columns["surname"].HeaderText    = "Фамилия";
            dataGridView_instructor.Columns["surname"].Width         = 150;
            dataGridView_instructor.Columns["forename"].HeaderText   = "Имя";
            dataGridView_instructor.Columns["forename"].Width        = 150;
            dataGridView_instructor.Columns["patronymic"].HeaderText = "Отчество";
            dataGridView_instructor.Columns["patronymic"].Width      = 150;
            dataGridView_instructor.Columns["id"].Visible            = false;
            dataGridView_instructor.Columns["id_schedule"].Visible   = false;
            dataGridView_instructor.Columns["id_tour_type"].Visible  = false;
        }
Exemplo n.º 5
0
        public void BLSightUpdate()
        {
            Tourist.BusinessLogic.BusinessLogic bl = new Tourist.BusinessLogic.BusinessLogic();
            TouristDataSet ds = new TouristDataSet();

            //Читаем и проверяем, что в таблице хоть что-то есть
            ds = bl.ReadSight();
            int countElement = ds.Sight.Count;

            if (countElement == 0)
            {
                //Если ничего нет, добавляем 1 строку
                ds.Sight.AddSightRow("Insert", "Str.");
                ds = bl.WriteSight(ds);
            }
            //Читаем снова, пересчитываем число строк
            ds.Sight.Clear();
            ds           = bl.ReadSight();
            countElement = ds.Sight.Count;

            //Проверяем, что число строк >= 1
            Assert.GreaterOrEqual(countElement, 1);

            //Меняем поле и пишем в БД
            ds.Sight[countElement - 1].sight_descr = "Hello from Update";
            ds = bl.WriteSight(ds);
            ds.Sight.Clear();

            //Читаем снова и сравниваем
            ds = bl.ReadSight();

            Assert.AreEqual("Hello from Update", ds.Sight[countElement - 1].sight_descr);
        }
Exemplo n.º 6
0
        public void ScheduleReadNotEmptyTable()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet       ds = new TouristDataSet();
            ScheduleDataAccessor scheduleDataAccessor = new ScheduleDataAccessor();
            AbstractTransaction  abstractTransaction  = abstractConnection.BeginTransaction();

            //Читаем строки с БД и смотрим их число
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElements = ds.Schedule.Count;

            //Добавляем строку и пишем в базу
            DateTime currentDateTime = DateTime.Now;

            currentDateTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day,
                                           currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
            ds.Schedule.AddScheduleRow(currentDateTime);
            scheduleDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Schedule.Clear();

            //Читаем снова и смотрим на последнюю строку
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();
            Assert.AreEqual(currentDateTime, ds.Schedule[countElements].tour_date);
        }
Exemplo n.º 7
0
        public void BLSightDelete()
        {
            Tourist.BusinessLogic.BusinessLogic bl = new Tourist.BusinessLogic.BusinessLogic();
            TouristDataSet ds = new TouristDataSet();

            //Читаем данные с БД в датасет и смотрим число строк
            ds = bl.ReadSight();
            int countElements = ds.Sight.Count;

            ds.Sight.Clear();

            //Добавляем строку в датасет и записываем в БД
            ds.Sight.AddSightRow("String", "ToDelete");
            ds = bl.WriteSight(ds);

            //Чистим датасет, записываем в него ещё раз и удаляем из него последнюю запись
            ds.Sight.Clear();
            ds = bl.ReadSight();
            ds.Sight[countElements].Delete();

            //Пишем в БД и снова читаем из неё в датасет
            ds = bl.WriteSight(ds);
            ds.Sight.Clear();
            ds = bl.ReadSight();

            //Смотрим число строк до всех манипуляций и после
            Assert.AreEqual(ds.Sight.Count, countElements);
        }
Exemplo n.º 8
0
        public void ScheduleInsert()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet       ds = new TouristDataSet();
            ScheduleDataAccessor scheduleDataAccessor = new ScheduleDataAccessor();
            AbstractTransaction  abstractTransaction  = abstractConnection.BeginTransaction();

            //Читаем данные с БД, считаем число записей в датасете
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElement = ds.Schedule.Count;

            //Добавляем строку в датасет, сохраняем в БД, снова читаем в датасет
            DateTime currentDateTime = DateTime.Now;

            currentDateTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day,
                                           currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
            ds.Schedule.AddScheduleRow(currentDateTime);
            scheduleDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Schedule.Clear();
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();

            Assert.AreEqual(currentDateTime, ds.Schedule[countElement].tour_date);
        }
Exemplo n.º 9
0
        public void BLSightReadEmptyTable()
        {
            Tourist.BusinessLogic.BusinessLogic bl = new Tourist.BusinessLogic.BusinessLogic();
            TouristDataSet ds = new TouristDataSet();

            //Чтение в датасет и удаление оттуда всех записей
            ds = bl.ReadSight();

            for (int i = 0; i < ds.Tour.Count; i++)
            {
                ds.Tour[i].Delete();
            }
            for (int i = 0; i < ds.Sight.Count; i++)
            {
                ds.Sight[i].Delete();
            }

            //Сохранение в БД
            ds = bl.WriteSight(ds);

            //Очистка таблиц
            ds.Tour.Clear();
            ds.Sight.Clear();

            //Чтение в датасет из пустой таблицы
            ds = bl.ReadSight();
            int countElement = ds.Sight.Count;

            Assert.AreEqual(0, countElement);
        }
Exemplo n.º 10
0
        public void BLScheduleDelete()
        {
            Tourist.BusinessLogic.BusinessLogic bl = new Tourist.BusinessLogic.BusinessLogic();
            TouristDataSet ds = new TouristDataSet();

            //Читаем данные с БД в датасет и смотрим число строк
            ds = bl.ReadSchedule();
            int countElements = ds.Schedule.Count;

            ds.Schedule.Clear();

            //Добавляем строку в датасет и записываем в БД
            DateTime currentDateTime = DateTime.Now;

            currentDateTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day,
                                           currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
            ds.Schedule.AddScheduleRow(currentDateTime);
            ds = bl.WriteSchedule(ds);

            //Чистим датасет, записываем в него ещё раз и удаляем из него последнюю запись
            ds.Schedule.Clear();
            ds = bl.ReadSchedule();
            ds.Schedule[countElements].Delete();

            //Пишем в БД и снова читаем из неё в датасет
            ds = bl.WriteSchedule(ds);
            ds.Schedule.Clear();
            ds = bl.ReadSchedule();

            //Смотрим число строк до всех манипуляций и после
            Assert.AreEqual(ds.Schedule.Count, countElements);
        }
Exemplo n.º 11
0
        public void SightInsert()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet      ds = new TouristDataSet();
            SightDataAccessor   sightDataAccessor   = new SightDataAccessor();
            AbstractTransaction abstractTransaction = abstractConnection.BeginTransaction();

            //Читаем данные с БД, считаем число записей в датасете
            sightDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElement = ds.Sight.Count;

            //Добавляем строку в датасет, сохраняем в БД, снова читаем в датасет
            ds.Sight.AddSightRow("Insert", "Str.");
            sightDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Sight.Clear();
            sightDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();

            Assert.AreEqual("Insert", ds.Sight[countElement].sight_name);
            Assert.AreEqual("Str.", ds.Sight[countElement].sight_descr);
        }
Exemplo n.º 12
0
        public void SightReadNotEmptyTable()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet      ds = new TouristDataSet();
            SightDataAccessor   sightDataAccessor   = new SightDataAccessor();
            AbstractTransaction abstractTransaction = abstractConnection.BeginTransaction();

            //Читаем строки с БД и смотрим их число
            sightDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElements = ds.Sight.Count;

            //Добавляем строку и пишем в базу
            ds.Sight.AddSightRow("Памятник Ленину", "Обычный памятник в городе");
            sightDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Sight.Clear();

            //Читаем снова и смотрим на последнюю строку
            sightDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();
            Assert.AreEqual("Памятник Ленину", ds.Sight[countElements].sight_name);
            Assert.AreEqual("Обычный памятник в городе", ds.Sight[countElements].sight_descr);
        }
Exemplo n.º 13
0
        void ReloadTable()
        {
            //Очистка колонок нужна для удаления кастомных колонок: "Дата тура" и "Название тура"
            //После переустановки DataSource остальные колонки подтянутся автоматически, а кастомные - заново сгенерируются
            dataGridView_tour.Columns.Clear();

            touristDataSet = touristServiceExporter.ReadTour();
            dataGridView_tour.DataSource = touristDataSet;
            dataGridView_tour.DataMember = "Tour";
            dataGridView_tour.Columns.Add("sight_name", "Главная достопримечательность");
            dataGridView_tour.Columns.Add("tour_type_name", "Тип тура");
            dataGridView_tour.Columns.Add("tour_date", "Дата тура");
            foreach (DataGridViewRow row in dataGridView_tour.Rows)
            {
                row.Cells["sight_name"].Value     = touristDataSet.Sight.Rows.Find(row.Cells["id_sight"].Value)["sight_name"];
                row.Cells["tour_type_name"].Value = touristDataSet.TourType.Rows.Find(row.Cells["id_tour_type"].Value)["tour_type_name"];
                row.Cells["tour_date"].Value      = touristDataSet.Schedule.Rows.Find(row.Cells["id_schedule"].Value)["tour_date"];
            }
            dataGridView_tour.Columns["tour_name"].HeaderText  = "Название тура";
            dataGridView_tour.Columns["tour_name"].Width       = 150;
            dataGridView_tour.Columns["tour_descr"].HeaderText = "Описание тура";
            dataGridView_tour.Columns["tour_descr"].Width      = 200;
            dataGridView_tour.Columns["sight_name"].Width      = 200;

            dataGridView_tour.Columns["id"].Visible           = false;
            dataGridView_tour.Columns["id_sight"].Visible     = false;
            dataGridView_tour.Columns["id_schedule"].Visible  = false;
            dataGridView_tour.Columns["id_tour_type"].Visible = false;
        }
Exemplo n.º 14
0
        public void TourReadEmptyTable()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet      ds = new TouristDataSet();
            TourDataAccessor    tourDataAccessor    = new TourDataAccessor();
            AbstractTransaction abstractTransaction = abstractConnection.BeginTransaction();

            //Чтение в датасет и удаление оттуда всех записей
            tourDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            for (int i = 0; i < ds.Tour.Count; i++)
            {
                ds.Tour[i].Delete();
            }

            //Сохранение в БД
            tourDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Tour.Clear();

            //Чтение в датасет из пустой таблицы
            tourDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElement = ds.Tour.Count;

            abstractTransaction.Commit();
            abstractConnection.Close();

            Assert.AreEqual(0, countElement);
        }
Exemplo n.º 15
0
        public void InstructorReadNotEmptyTable()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet         ds = new TouristDataSet();
            InstructorDataAccessor instructorDataAccessor = new InstructorDataAccessor();
            ScheduleDataAccessor   scheduleDataAccessor   = new ScheduleDataAccessor();
            TourTypeDataAccessor   tourTypeDataAccessor   = new TourTypeDataAccessor();
            AbstractTransaction    abstractTransaction    = abstractConnection.BeginTransaction();

            //Читаем строки с БД и смотрим их число
            instructorDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            tourTypeDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElements = ds.Instructor.Count;

            //Проверка, есть ли значения в таблицах расписания и типа экскурсии. Если значения нет, записываем его и считываем еще раз
            if (ds.Schedule.Count == 0)
            {
                DateTime currentDateTime = DateTime.Now;
                currentDateTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day,
                                               currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
                ds.Schedule.AddScheduleRow(currentDateTime);
                scheduleDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            }
            if (ds.TourType.Count == 0)
            {
                ds.TourType.AddTourTypeRow("Первая строка списка туров");
                tourTypeDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            }
            //Чистим таблицы датасета и читаем заново данные с базы
            ds.Instructor.Clear();
            ds.Schedule.Clear();
            ds.TourType.Clear();
            instructorDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            tourTypeDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            //Сохраняем ID первой записи таблиц
            Int32 savedScheduleId = ds.Schedule[0].id;
            Int32 savedTourTypeId = ds.TourType[0].id;

            //Добавляем строку и пишем в базу
            ds.Instructor.AddInstructorRow("Петров", "Алексей", "Петрович", ds.Schedule[0], ds.TourType[0]);
            instructorDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Instructor.Clear();

            //Читаем снова и смотрим на последнюю строку
            instructorDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();
            Assert.AreEqual("Петров", ds.Instructor[countElements].surname);
            Assert.AreEqual("Алексей", ds.Instructor[countElements].forename);
            Assert.AreEqual("Петрович", ds.Instructor[countElements].patronymic);
            Assert.AreEqual(savedScheduleId, ds.Instructor[countElements].id_schedule);
            Assert.AreEqual(savedTourTypeId, ds.Instructor[countElements].id_tour_type);
        }
Exemplo n.º 16
0
        public void InstructorDelete()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet         ds = new TouristDataSet();
            ScheduleDataAccessor   scheduleDataAccessor   = new ScheduleDataAccessor();
            TourTypeDataAccessor   tourTypeDataAccessor   = new TourTypeDataAccessor();
            InstructorDataAccessor instructorDataAccessor = new InstructorDataAccessor();
            AbstractTransaction    abstractTransaction    = abstractConnection.BeginTransaction();

            //Читаем строки с БД и смотрим их число
            instructorDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            tourTypeDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElements = ds.Instructor.Count;

            //Проверка, есть ли значения в таблицах расписания и типа экскурсии. Если значения нет, записываем его и считываем еще раз
            if (ds.Schedule.Count == 0)
            {
                DateTime currentDateTime = DateTime.Now;
                currentDateTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day,
                                               currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
                ds.Schedule.AddScheduleRow(currentDateTime);
                scheduleDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            }
            if (ds.TourType.Count == 0)
            {
                ds.TourType.AddTourTypeRow("Первая строка списка туров от делита");
                tourTypeDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            }
            //Чистим таблицы датасета и читаем заново данные с базы
            ds.Instructor.Clear();
            ds.Schedule.Clear();
            ds.TourType.Clear();
            instructorDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            tourTypeDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            //Добавляем строку и пишем в базу
            ds.Instructor.AddInstructorRow("Делитов", "Алексей", "Петрович", ds.Schedule[0], ds.TourType[0]);
            instructorDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);

            //Чистим датасет, записываем в него ещё раз и удаляем из него последнюю запись
            ds.Instructor.Clear();
            instructorDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            ds.Instructor[countElements].Delete();

            //Пишем в БД и снова читаем из неё в датасет
            instructorDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Instructor.Clear();
            instructorDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();

            //Смотрим число строк до всех манипуляций и после
            Assert.AreEqual(ds.Instructor.Count, countElements);
        }
        public void BLInstructorUpdate()
        {
            Tourist.BusinessLogic.BusinessLogic bl = new Tourist.BusinessLogic.BusinessLogic();
            TouristDataSet ds = new TouristDataSet();

            //Читаем строки с БД и смотрим их число
            ds = bl.ReadInstructor();
            int countElements = ds.Instructor.Count;

            //Проверка, есть ли значения в таблицах расписания и типа экскурсии. Если значения нет, записываем его и считываем еще раз
            if (ds.Schedule.Count == 0)
            {
                DateTime currentDateTime = DateTime.Now;
                currentDateTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day,
                                               currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
                ds.Schedule.AddScheduleRow(currentDateTime);
                ds = bl.WriteSchedule(ds);
            }
            if (ds.TourType.Count == 0)
            {
                ds.TourType.AddTourTypeRow("Первая строка списка туров от апдейта");
                ds = bl.WriteTourType(ds);
            }
            //Чистим таблицы датасета и читаем заново данные с базы
            ds.Instructor.Clear();
            ds.Schedule.Clear();
            ds.TourType.Clear();
            ds = bl.ReadInstructor();

            //Сохраняем ID первой записи таблиц
            Int32 savedScheduleId = ds.Schedule[0].id;
            Int32 savedTourTypeId = ds.TourType[0].id;

            //Добавляем строку и пишем в базу
            ds.Instructor.AddInstructorRow("Изменяйло", "Алексей", "Петрович", ds.Schedule[0], ds.TourType[0]);
            ds = bl.WriteInstructor(ds);
            ds.Instructor.Clear();

            ds            = bl.ReadInstructor();
            countElements = ds.Instructor.Count;

            //Проверяем, что число строк >= 1
            Assert.GreaterOrEqual(countElements, 1);

            //Меняем поле и пишем в БД
            ds.Instructor[countElements - 1].forename = "Hello from Update";
            ds = bl.WriteInstructor(ds);
            ds.Instructor.Clear();

            //Читаем снова и сравниваем
            ds = bl.ReadInstructor();

            Assert.AreEqual("Изменяйло", ds.Instructor[countElements - 1].surname);
            Assert.AreEqual("Hello from Update", ds.Instructor[countElements - 1].forename);
            Assert.AreEqual("Петрович", ds.Instructor[countElements - 1].patronymic);
            Assert.AreEqual(savedScheduleId, ds.Instructor[countElements - 1].id_schedule);
            Assert.AreEqual(savedTourTypeId, ds.Instructor[countElements - 1].id_tour_type);
        }
Exemplo n.º 18
0
 void ReloadTable()
 {
     touristDataSet = touristServiceExporter.ReadTourType();
     dataGridView_tourType.DataSource = touristDataSet;
     dataGridView_tourType.DataMember = "TourType";
     dataGridView_tourType.Columns["tour_type_name"].HeaderText = "Название";
     dataGridView_tourType.Columns["tour_type_name"].Width      = 700;
     dataGridView_tourType.Columns["id"].Visible = false;
 }
Exemplo n.º 19
0
 void ReloadTable()
 {
     touristDataSet = touristServiceExporter.ReadSchedule();
     dataGridView_schedule.DataSource = touristDataSet;
     dataGridView_schedule.DataMember = "Schedule";
     dataGridView_schedule.Columns["tour_date"].HeaderText = "Дата";
     dataGridView_schedule.Columns["tour_date"].Width      = 700;
     dataGridView_schedule.Columns["id"].Visible           = false;
 }
Exemplo n.º 20
0
 void ReloadTable()
 {
     touristDataSet = touristServiceExporter.ReadSight();
     dataGridView_sight.DataSource = touristDataSet;
     dataGridView_sight.DataMember = "Sight";
     dataGridView_sight.Columns["sight_name"].HeaderText  = "Название";
     dataGridView_sight.Columns["sight_name"].Width       = 300;
     dataGridView_sight.Columns["sight_descr"].HeaderText = "Описание";
     dataGridView_sight.Columns["sight_descr"].Width      = 400;
     dataGridView_sight.Columns["id"].Visible             = false;
 }
        public void BLInstructorDelete()
        {
            Tourist.BusinessLogic.BusinessLogic bl = new Tourist.BusinessLogic.BusinessLogic();
            TouristDataSet ds = new TouristDataSet();

            //Читаем строки с БД и смотрим их число
            ds = bl.ReadInstructor();
            int countElements = ds.Instructor.Count;

            //Проверка, есть ли значения в таблицах расписания и типа экскурсии. Если значения нет, записываем его и считываем еще раз
            if (ds.Schedule.Count == 0)
            {
                DateTime currentDateTime = DateTime.Now;
                currentDateTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day,
                                               currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
                ds.Schedule.AddScheduleRow(currentDateTime);
                ds = bl.WriteSchedule(ds);
            }
            if (ds.TourType.Count == 0)
            {
                ds.TourType.AddTourTypeRow("Первая строка списка туров от делита");
                ds = bl.WriteTourType(ds);
            }
            //Чистим таблицы датасета и читаем заново данные с базы
            ds.Instructor.Clear();
            ds.Schedule.Clear();
            ds.TourType.Clear();
            ds = bl.ReadInstructor();

            //Добавляем строку и пишем в базу
            ds.Instructor.AddInstructorRow("Делитов", "Алексей", "Петрович", ds.Schedule[0], ds.TourType[0]);
            ds = bl.WriteInstructor(ds);

            //Чистим датасет, записываем в него ещё раз и удаляем из него последнюю запись
            ds.Instructor.Clear();
            ds = bl.ReadInstructor();
            ds.Instructor[countElements].Delete();

            //Пишем в БД и снова читаем из неё в датасет
            ds = bl.WriteInstructor(ds);
            ds.Instructor.Clear();
            ds = bl.ReadInstructor();

            //Смотрим число строк до всех манипуляций и после
            Assert.AreEqual(ds.Instructor.Count, countElements);
        }
Exemplo n.º 22
0
        public void ScheduleUpdate()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet       ds = new TouristDataSet();
            ScheduleDataAccessor scheduleDataAccessor = new ScheduleDataAccessor();
            AbstractTransaction  abstractTransaction  = abstractConnection.BeginTransaction();

            DateTime currentDateTime = DateTime.Now;

            currentDateTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day,
                                           currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);

            //Читаем и проверяем, что в таблице хоть что-то есть
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElement = ds.Sight.Count;

            if (countElement == 0)
            {
                //Если ничего нет, добавляем 1 строку

                ds.Schedule.AddScheduleRow(currentDateTime);
                scheduleDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            }
            //Читаем снова, пересчитываем число строк
            ds.Schedule.Clear();
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            countElement = ds.Schedule.Count;

            //Проверяем, что число строк >= 1
            Assert.GreaterOrEqual(countElement, 1);

            //Меняем поле и пишем в БД
            ds.Schedule[countElement - 1].tour_date = currentDateTime.AddDays(3);
            scheduleDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Schedule.Clear();

            //Читаем снова и сравниваем
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();
            Assert.AreEqual(currentDateTime.AddDays(3), ds.Schedule[countElement - 1].tour_date);
        }
Exemplo n.º 23
0
        public void BLSightInsert()
        {
            Tourist.BusinessLogic.BusinessLogic bl = new Tourist.BusinessLogic.BusinessLogic();
            TouristDataSet ds = new TouristDataSet();

            //Читаем данные с БД, считаем число записей в датасете
            ds = bl.ReadSight();
            int countElement = ds.Sight.Count;

            //Добавляем строку в датасет, сохраняем в БД, снова читаем в датасет
            ds.Sight.AddSightRow("Insert", "Str.");
            ds = bl.WriteSight(ds);
            ds.Sight.Clear();
            ds = bl.ReadSight();

            Assert.AreEqual("Insert", ds.Sight[countElement].sight_name);
            Assert.AreEqual("Str.", ds.Sight[countElement].sight_descr);
        }
Exemplo n.º 24
0
        private void button_edit_Click(object sender, EventArgs e)
        {
            if (dataGridView_tourType.SelectedRows.Count <= 0)
            {
                MessageBox.Show("Не выбрана ни одна строка для редактирования", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //Получение 1й выбранной строки и отправка соответствующей строки датасета в форму редактирования
            AddTourType addTourType = new AddTourType(touristDataSet.TourType, touristDataSet.TourType.Rows.Find(dataGridView_tourType.SelectedRows[0].Cells["id"].Value));

            addTourType.Text = "Редактирование типа туров";
            addTourType.ShowDialog();
            if (addTourType.DialogResult == DialogResult.OK)
            {
                touristDataSet = touristServiceExporter.WriteTourType(touristDataSet);
                ReloadTable();
            }
        }
Exemplo n.º 25
0
 public TouristDataSet WriteSight(TouristDataSet dataSet)
 {
     using (AbstractConnection abstractConnection = ConnectionFactory.CreateConnection())
     {
         abstractConnection.Open();
         AbstractTransaction abstractTransaction = abstractConnection.BeginTransaction();
         try
         {
             tourDataAccessor.WriteData(abstractTransaction, abstractConnection, dataSet);
             sightDataAccessor.WriteData(abstractTransaction, abstractConnection, dataSet);
             abstractTransaction.Commit();
         }
         catch (Exception e)
         {
             abstractTransaction.Rollback();
             throw e;
         }
     }
     return(dataSet);
 }
Exemplo n.º 26
0
        public void BLScheduleInsert()
        {
            Tourist.BusinessLogic.BusinessLogic bl = new Tourist.BusinessLogic.BusinessLogic();
            TouristDataSet ds = new TouristDataSet();

            //Читаем данные с БД, считаем число записей в датасете
            ds = bl.ReadSchedule();
            int countElement = ds.Schedule.Count;

            //Добавляем строку в датасет, сохраняем в БД, снова читаем в датасет
            DateTime currentDateTime = DateTime.Now;

            currentDateTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day,
                                           currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
            ds.Schedule.AddScheduleRow(currentDateTime);
            ds = bl.WriteSchedule(ds);
            ds.Schedule.Clear();
            ds = bl.ReadSchedule();

            Assert.AreEqual(currentDateTime, ds.Schedule[countElement].tour_date);
        }
Exemplo n.º 27
0
        public void BLSightReadNotEmptyTable()
        {
            Tourist.BusinessLogic.BusinessLogic bl = new Tourist.BusinessLogic.BusinessLogic();
            TouristDataSet ds = new TouristDataSet();

            //Читаем строки с БД и смотрим их число
            ds = bl.ReadSight();

            int countElements = ds.Sight.Count;

            //Добавляем строку и пишем в базу
            ds.Sight.AddSightRow("Памятник Ленину", "Обычный памятник в городе");
            ds = bl.WriteSight(ds);
            ds.Sight.Clear();

            //Читаем снова и смотрим на последнюю строку
            ds = bl.ReadSight();

            Assert.AreEqual("Памятник Ленину", ds.Sight[countElements].sight_name);
            Assert.AreEqual("Обычный памятник в городе", ds.Sight[countElements].sight_descr);
        }
Exemplo n.º 28
0
        public void SightUpdate()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet      ds = new TouristDataSet();
            SightDataAccessor   sightDataAccessor   = new SightDataAccessor();
            AbstractTransaction abstractTransaction = abstractConnection.BeginTransaction();

            //Читаем и проверяем, что в таблице хоть что-то есть
            sightDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElement = ds.Sight.Count;

            if (countElement == 0)
            {
                //Если ничего нет, добавляем 1 строку
                ds.Sight.AddSightRow("Insert", "Str.");
                sightDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            }
            //Читаем снова, пересчитываем число строк
            ds.Sight.Clear();
            sightDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            countElement = ds.Sight.Count;

            //Проверяем, что число строк >= 1
            Assert.GreaterOrEqual(countElement, 1);

            //Меняем поле и пишем в БД
            ds.Sight[countElement - 1].sight_descr = "Hello from Update";
            sightDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Sight.Clear();

            //Читаем снова и сравниваем
            sightDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();
            Assert.AreEqual("Hello from Update", ds.Sight[countElement - 1].sight_descr);
        }
Exemplo n.º 29
0
        public void ScheduleDelete()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet       ds = new TouristDataSet();
            ScheduleDataAccessor scheduleDataAccessor = new ScheduleDataAccessor();
            AbstractTransaction  abstractTransaction  = abstractConnection.BeginTransaction();

            //Читаем данные с БД в датасет и смотрим число строк
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElements = ds.Schedule.Count;

            ds.Schedule.Clear();

            //Добавляем строку в датасет и записываем в БД
            DateTime currentDateTime = DateTime.Now;

            currentDateTime = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day,
                                           currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
            ds.Schedule.AddScheduleRow(currentDateTime);
            scheduleDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);

            //Чистим датасет, записываем в него ещё раз и удаляем из него последнюю запись
            ds.Schedule.Clear();
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            ds.Schedule[countElements].Delete();

            //Пишем в БД и снова читаем из неё в датасет
            scheduleDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.Schedule.Clear();
            scheduleDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();

            //Смотрим число строк до всех манипуляций и после
            Assert.AreEqual(ds.Schedule.Count, countElements);
        }
Exemplo n.º 30
0
        public void TourTypeUpdate()
        {
            AbstractConnection abstractConnection = ConnectionFactory.CreateConnection();

            abstractConnection.Open();
            TouristDataSet       ds = new TouristDataSet();
            TourTypeDataAccessor tourTypeDataAccessor = new TourTypeDataAccessor();
            AbstractTransaction  abstractTransaction  = abstractConnection.BeginTransaction();

            //Читаем и проверяем, что в таблице хоть что-то есть
            tourTypeDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            int countElement = ds.TourType.Count;

            if (countElement == 0)
            {
                //Если ничего нет, добавляем 1 строку
                ds.TourType.AddTourTypeRow("InsertAgain");
                tourTypeDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            }
            //Читаем снова, пересчитываем число строк
            ds.TourType.Clear();
            tourTypeDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);
            countElement = ds.TourType.Count;

            //Проверяем, что число строк >= 1
            Assert.GreaterOrEqual(countElement, 1);

            //Меняем поле и пишем в БД
            ds.TourType[countElement - 1].tour_type_name = "Hello from Update TT";
            tourTypeDataAccessor.WriteData(abstractTransaction, abstractConnection, ds);
            ds.TourType.Clear();

            //Читаем снова и сравниваем
            tourTypeDataAccessor.ReadData(abstractTransaction, abstractConnection, ds);

            abstractTransaction.Commit();
            abstractConnection.Close();
            Assert.AreEqual("Hello from Update TT", ds.TourType[countElement - 1].tour_type_name);
        }