Exemple #1
0
        /// <summary>
        /// Метод для сохранения содержимого модели на сервере
        /// </summary>
        /// <param name="root">Ссылка на корневой объект модели</param>
        /// <param name="connection">Строка подключения</param>
        /// <returns></returns>
        public static bool StoreTables(Root root, string connection)
        {
            var server = new Database.SqlServer {
                Connection = connection
            };

            // предметы
            server.DeleteInto("Matters", "IdMatter", root.Matters.Select(item => item.IdMatter));
            OperationResult = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(false);
            }
            foreach (var item in root.Matters)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdMatter", item.IdMatter.ToString() },
                    { "Name", item.Name }
                };
                if (!server.InsertInto("Matters", columns))
                {
                    server.UpdateInto("Matters", columns);
                }
                OperationResult = server.LastError;
            }
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(false);
            }
            // специальности
            server.DeleteInto("Specialities", "IdSpeciality", root.Specialities.Select(item => item.IdSpeciality));
            OperationResult = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(false);
            }
            foreach (var item in root.Specialities)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdSpeciality", item.IdSpeciality.ToString() },
                    { "Name", item.Name }
                };
                if (!server.InsertInto("Specialities", columns))
                {
                    server.UpdateInto("Specialities", columns);
                }
                OperationResult = server.LastError;
            }
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(false);
            }
            // сдаваемые предметы
            server.DeleteInto("PassMatters", "IdPassMatter", root.PassMatters.Select(item => item.IdPassMatter));
            OperationResult = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(false);
            }
            foreach (var item in root.PassMatters)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdPassMatter", item.IdPassMatter.ToString() },
                    { "IdSpeciality", item.IdSpeciality.ToString() },
                    { "IdMatter", item.IdMatter.ToString() },
                    { "PassForm", item.PassForm.ToString() }
                };
                if (!server.InsertInto("PassMatters", columns))
                {
                    server.UpdateInto("PassMatters", columns);
                }
                OperationResult = server.LastError;
            }
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(false);
            }
            // абитуриенты
            server.DeleteInto("Enrollees", "IdEnrollee", root.Enrollees.Select(item => item.IdEnrollee));
            OperationResult = server.LastError;
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(false);
            }
            foreach (var item in root.Enrollees)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdEnrollee", item.IdEnrollee.ToString() },
                    { "RegistrationNumber", item.RegistrationNumber },
                    { "Surname", item.Surname },
                    { "FirstName", item.FirstName },
                    { "LastName", item.LastName },
                    { "BirthDay", item.BirthDay.ToString("O") },
                    { "SecodarySchoolName", item.SecodarySchoolName },
                    { "SecodarySchoolNumber", item.SecodarySchoolNumber },
                    { "SecodarySchoolTown", item.SecodarySchoolTown },
                    { "GraduationDate", item.GraduationDate.ToString("O") },
                    { "GoldMedal", item.GoldMedal.ToString() },
                    { "Town", item.Town },
                    { "Street", item.Street },
                    { "HouseNumber", item.HouseNumber },
                    { "PhoneNumber", item.PhoneNumber },
                    { "IdSpeciality", item.IdSpeciality.ToString() }
                };
                if (!server.InsertInto("Enrollees", columns))
                {
                    server.UpdateInto("Enrollees", columns);
                }
                OperationResult = server.LastError;
            }
            if (!string.IsNullOrWhiteSpace(OperationResult))
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Метод сохранения конфигурации в базу данных
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="hotel"></param>
        public static void SaveToBase(string connection, Hotel hotel)
        {
            var server = new Database.SqlServer {
                Connection = connection
            };

            // категории
            server.DeleteInto("Categories", "IdCategory", hotel.Categories.Select(item => item.Value.IdCategory));
            OperationResult = server.LastError;
            foreach (var item in hotel.Categories.Values)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdCategory", item.IdCategory.ToString() },
                    { "NameCategory", item.NameCategory }
                };
                if (!server.InsertInto("Categories", columns))
                {
                    server.UpdateInto("Categories", columns);
                }
                OperationResult = server.LastError;
            }
            // услуги
            server.DeleteInto("Services", "IdService", hotel.Services.Select(item => item.IdService));
            OperationResult = server.LastError;
            foreach (var item in hotel.Services)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdService", item.IdService.ToString() },
                    { "NameService", item.NameService },
                    { "PriceDay", item.PriceDay.ToString() }
                };
                if (!server.InsertInto("Services", columns))
                {
                    server.UpdateInto("Services", columns);
                }
                OperationResult = server.LastError;
            }
            // комнаты
            server.DeleteInto("Rooms", "IdRoom", hotel.Rooms.Select(item => item.IdRoom));
            foreach (var room in hotel.Rooms)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdRoom", room.IdRoom.ToString() },
                    { "IdCategory", room.IdCategory.ToString() },
                    { "NumberSeat", room.NumberSeat.ToString() },
                    { "Floor", room.Floor.ToString() },
                    { "PriceDay", room.PriceDay.ToString() },
                    { "RoomNumber", room.RoomNumber }
                };
                server.DeleteInto("RoomServices", columns);
                OperationResult = server.LastError;
                if (!server.InsertInto("Rooms", columns))
                {
                    server.UpdateInto("Rooms", columns);
                }
                foreach (var service in room.Services)
                {
                    var cols = new Dictionary <string, string>
                    {
                        { "IdRoom", room.IdRoom.ToString() },
                        { "IdService", service.IdService.ToString() }
                    };
                    if (!server.InsertInto("RoomServices", cols))
                    {
                        server.UpdateInto("RoomServices", cols);
                    }
                    OperationResult = server.LastError;
                }
            }
            // должности
            server.DeleteInto("EmployeeRoles", "IdEmployeeRole", hotel.EmployeeRoles.Select(item => item.IdEmployeeRole));
            foreach (var item in hotel.EmployeeRoles)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdEmployeeRole", item.IdEmployeeRole.ToString() },
                    { "NameRole", item.NameRole },
                    { "Salary", item.Salary.ToString() },
                    { "AllowedOperations", ((uint)item.AllowedOperations).ToString() }
                };
                if (!server.InsertInto("EmployeeRoles", columns))
                {
                    server.UpdateInto("EmployeeRoles", columns);
                }
            }
            // штат сотрудников
            server.DeleteInto("RegistryStaff", "IdEmployee", hotel.RegistryStaff.Select(item => item.IdEmployee));
            OperationResult = server.LastError;
            foreach (var item in hotel.RegistryStaff)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdEmployee", item.IdEmployee.ToString() },
                    { "Surname", item.Surname },
                    { "Name", item.Name },
                    { "LastName", item.LastName },
                    { "PhoneNumber", item.PhoneNumber },
                    { "IdEmployeeRole", item.IdEmployeeRole.ToString() },
                    { "Password", item.Password }
                };
                if (!server.InsertInto("RegistryStaff", columns))
                {
                    server.UpdateInto("RegistryStaff", columns);
                }
                OperationResult = server.LastError;
            }
            // клиенты
            server.DeleteInto("Clients", "IdClient", hotel.Clients.Select(item => item.IdClient));
            OperationResult = server.LastError;
            foreach (var item in hotel.Clients)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdClient", item.IdClient.ToString() },
                    { "Surname", item.Surname },
                    { "Name", item.Name },
                    { "LastName", item.LastName },
                    { "Birthday", item.Birthday.ToString("O") },
                    { "City", item.City },
                    { "PhoneNumber", item.PhoneNumber },
                    { "Passport", item.Passport },
                    { "NumberChild", item.NumberChild.ToString() }
                };
                if (!server.InsertInto("Clients", columns))
                {
                    server.UpdateInto("Clients", columns);
                }
                OperationResult = server.LastError;
            }
            // бронирование
            server.DeleteInto("Reservations", "IdReservation", hotel.Reservations.Select(item => item.IdReservation));
            OperationResult = server.LastError;
            foreach (var item in hotel.Reservations)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdReservation", item.IdReservation.ToString() },
                    { "IdClient", item.IdClient.ToString() },
                    { "IdRoom", item.IdRoom.ToString() },
                    { "ArrivalDate", item.ArrivalDate.ToString("O") },
                    { "DepartureDate", item.DepartureDate.ToString("O") },
                    { "IdEmployee", item.IdEmployee.ToString() }
                };
                if (!server.InsertInto("Reservations", columns))
                {
                    server.UpdateInto("Reservations", columns);
                }
                OperationResult = server.LastError;
            }
            // доставка до гостиницы
            server.DeleteInto("Transfers", "IdTransfer", hotel.Transfers.Select(item => item.IdTransfer));
            OperationResult = server.LastError;
            foreach (var item in hotel.Transfers)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdTransfer", item.IdTransfer.ToString() },
                    { "IdReservation", item.IdReservation.ToString() },
                    { "FeedAddress", item.FeedAddress },
                    { "FeedDateTime", item.FeedDateTime.ToString("O") },
                    { "NumberSeat", item.NumberSeat.ToString() }
                };
                if (!server.InsertInto("Transfers", columns))
                {
                    server.UpdateInto("Transfers", columns);
                }
                OperationResult = server.LastError;
            }
            // перечень каналов
            server.DeleteInto("PayChannels", "IdPayChannel", hotel.PayChannels.Select(item => item.IdPayChannel));
            OperationResult = server.LastError;
            foreach (var item in hotel.PayChannels)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdPayChannel", item.IdPayChannel.ToString() },
                    { "NameChannel", item.NameChannel },
                    { "PriceHour", item.PriceHour.ToString() }
                };
                if (!server.InsertInto("PayChannels", columns))
                {
                    server.UpdateInto("PayChannels", columns);
                }
                OperationResult = server.LastError;
            }
            // перечень подписок
            server.DeleteInto("AccordancePayChannels", "IdAccordancePayChannel",
                              hotel.AccordancePayChannels.Select(item => item.IdAccordancePayChannel));
            OperationResult = server.LastError;
            foreach (var accordance in hotel.AccordancePayChannels)
            {
                var columns = new Dictionary <string, string>
                {
                    { "IdAccordancePayChannel", accordance.IdAccordancePayChannel.ToString() },
                    { "IdReservation", accordance.IdReservation.ToString() }
                };
                server.DeleteInto("RoomPayChannels", columns);
                OperationResult = server.LastError;
                if (!server.InsertInto("AccordancePayChannels", columns))
                {
                    server.UpdateInto("AccordancePayChannels", columns);
                }
                OperationResult = server.LastError;
                foreach (var channel in accordance.PayChannels)
                {
                    var cols = new Dictionary <string, string>
                    {
                        { "IdAccordancePayChannel", accordance.IdAccordancePayChannel.ToString() },
                        { "IdPayChannel", channel.IdPayChannel.ToString() }
                    };
                    if (!server.InsertInto("RoomPayChannels", cols))
                    {
                        server.UpdateInto("RoomPayChannels", cols);
                    }
                    OperationResult = server.LastError;
                }
            }
        }