Esempio n. 1
0
        private void f(string State, Questionnaire questionnaire, Production[] productions, double ku, List <Production> listProduction)
        {
            if (ku != 0)
            {
                for (int prodNum = 0; prodNum < productions.Length; prodNum++)
                {
                    if (State.Equals(productions[prodNum].State))
                    {
                        switch (productions[prodNum].Arg1)
                        {
                        case "Страна":
                            if (!productions[prodNum].Arg2.Equals(questionnaire.country))
                            {
                                continue;
                            }
                            break;

                        case "Регион":
                            if (!productions[prodNum].Arg2.Equals(questionnaire.region))
                            {
                                continue;
                            }
                            break;

                        case "Климат":
                            if (!productions[prodNum].Arg2.Equals(questionnaire.climate))
                            {
                                continue;
                            }

                            break;

                        case "Здоровье":
                            if (!productions[prodNum].Arg2.Equals(questionnaire.health))
                            {
                                continue;
                            }
                            else
                            {
                                ku *= Double.Parse(productions[prodNum].KU);
                            }
                            break;

                        case "Возраст":
                            /*
                             * int ost = questionnaire.age % 10 < 5 ? 0 : 5;
                             * int l1 = (questionnaire.age / 10) * 10 + ost;
                             * int l2 = (questionnaire.age / 10) * 10 + ost + 5;
                             * double d = ((questionnaire.age % 10)- ost ) / 5.0;
                             * double ku1 = 0, ku2 = 0;
                             * switch (productions[prodNum].KU)
                             * {
                             *  case "Назначение/Возраст":
                             *      ku1 = II.CurentII.DestinationAgeKU[productions[prodNum].Arg2][l1 + ""];
                             *      ku2 = II.CurentII.DestinationAgeKU[productions[prodNum].Arg2][l2 + ""];
                             *      break;
                             *  case "Питание/Возраст":
                             *      ku1 = II.CurentII.MealAgeKU[productions[prodNum].Arg2][l1 + ""];
                             *      ku2 = II.CurentII.MealAgeKU[productions[prodNum].Arg2][l2 + ""];
                             *      break;
                             *  case "Климат/Возраст":
                             *      ku1 = II.CurentII.ClimateAgeKU[productions[prodNum].Arg2][l1 + ""];
                             *      ku2 = II.CurentII.ClimateAgeKU[productions[prodNum].Arg2][l2 + ""];
                             *      break;
                             * }
                             *
                             * ku *= ku1 + (ku2-ku1) * d;*/
                            double ku1 = 0.0, ku2 = 0.0;
                            int    l1 = 0, l2 = 0;
                            switch (productions[prodNum].KU)
                            {
                            case "Назначение/Возраст":
                                l1  = int.Parse(II.CurentII.DestinationAgeKU[productions[prodNum].Arg2].Keys.Last(p => int.Parse(p) <= questionnaire.age));
                                l2  = int.Parse(II.CurentII.DestinationAgeKU[productions[prodNum].Arg2].Keys.First(p => int.Parse(p) > questionnaire.age));
                                ku1 = II.CurentII.DestinationAgeKU[productions[prodNum].Arg2][l1 + ""];
                                ku2 = II.CurentII.DestinationAgeKU[productions[prodNum].Arg2][l2 + ""];
                                break;

                            case "Питание/Возраст":
                                l1  = int.Parse(II.CurentII.MealAgeKU[productions[prodNum].Arg2].Keys.Last(p => int.Parse(p) <= questionnaire.age));
                                l2  = int.Parse(II.CurentII.MealAgeKU[productions[prodNum].Arg2].Keys.First(p => int.Parse(p) > questionnaire.age));
                                ku1 = II.CurentII.MealAgeKU[productions[prodNum].Arg2][l1 + ""];
                                ku2 = II.CurentII.MealAgeKU[productions[prodNum].Arg2][l2 + ""];
                                break;

                            case "Климат/Возраст":
                                l1  = int.Parse(II.CurentII.ClimateAgeKU[productions[prodNum].Arg2].Keys.Last(p => int.Parse(p) <= questionnaire.age));
                                l2  = int.Parse(II.CurentII.ClimateAgeKU[productions[prodNum].Arg2].Keys.First(p => int.Parse(p) > questionnaire.age));
                                ku1 = II.CurentII.ClimateAgeKU[productions[prodNum].Arg2][l1 + ""];
                                ku2 = II.CurentII.ClimateAgeKU[productions[prodNum].Arg2][l2 + ""];
                                break;
                            }
                            ku *= (ku2 - ku1) * (questionnaire.age - l1) / (l2 - l1) + ku1;
                            break;

                        case "Назначение":
                            if (!productions[prodNum].Arg2.Equals(questionnaire.destination))
                            {
                                continue;
                            }
                            break;

                        case "Страховка":
                            if (!productions[prodNum].Arg2.Equals(questionnaire.insurance))
                            {
                                continue;
                            }
                            else
                            {
                                ku *= Double.Parse(productions[prodNum].KU);
                            }
                            break;

                        case "Расположение":
                            if (!productions[prodNum].Arg2.Equals(questionnaire.location))
                            {
                                continue;
                            }
                            break;

                        case "Уровень":
                            if (!productions[prodNum].Arg2.Equals(questionnaire.level))
                            {
                                continue;
                            }
                            break;

                        case "Тип":
                            if (!productions[prodNum].Arg2.Equals(questionnaire.type))
                            {
                                continue;
                            }
                            break;

                        case "Питание":
                            if (!productions[prodNum].Arg2.Equals(questionnaire.meals))
                            {
                                continue;
                            }
                            break;

                        case "Услуги в номере":
                            if (!contain(productions[prodNum].Arg2, questionnaire.roomServices))
                            {
                                continue;
                            }
                            break;

                        case "Услуги в отеле":
                            if (!contain(productions[prodNum].Arg2, questionnaire.hotelServices))
                            {
                                continue;
                            }
                            break;

                        case "Услуги для детей":
                            if (!contain(productions[prodNum].Arg2, questionnaire.childService))
                            {
                                continue;
                            }
                            break;

                        case "Сумма":
                            int    price_sum  = (int)((Int32.Parse(productions[prodNum].Arg2) + II.CurentII.ServiceCost));
                            int    client_sum = (int)(questionnaire.price * 1.2 / questionnaire.holidaysLength);
                            double ku_pr;
                            if (price_sum <= client_sum)
                            {
                                ku_pr = 1.0;
                            }
                            else if (price_sum >= (int)(client_sum * 1.25))
                            {
                                ku_pr = 0.0;
                            }
                            else
                            {
                                ku_pr = (client_sum - price_sum) / (questionnaire.price * 0.3 / questionnaire.holidaysLength) + 1;
                            }
                            ku *= ku_pr;
                            break;

                        case "Отель":
                            string hotelname = productions[prodNum].StateResult;
                            ku *= PostProcessResult(hotelname, questionnaire);
                            if (ku == 0)
                            {
                                continue;
                            }
                            Console.WriteLine(hotelname + " " + ku);
                            HotelFindResult hotelFindResult = new HotelFindResult();
                            Hotel           hotel           = new Hotel();
                            hotel.name                  = hotelname;
                            hotelFindResult.Hotel       = hotel;
                            hotelFindResult.KU          = ku;
                            hotelFindResult.Productions = listProduction.ToArray();
                            hotelFindResults.Add(hotelFindResult);

                            continue;
                        }
                        List <Production> listProductionNew = new List <Production>();
                        for (int i = 0; i < listProduction.Count; i++)
                        {
                            listProductionNew.Add(listProduction[i]);
                        }
                        listProductionNew.Add(productions[prodNum]);
                        f(productions[prodNum].StateResult, questionnaire, productions, ku, listProductionNew);
                    }
                }
            }
        }
        private void initLists(Hotel[] hotels)
        {
            List<Region> regionsList = new List<Region>();
            List<Country> countrysList = new List<Country>();
            List<string> destinationsList = new List<string>();
            List<string> locationsList = new List<string>();
            List<string> levelsList = new List<string>();
            List<string> typesList = new List<string>();
            List<string> mealsesList = new List<string>();
            List<string> pricesList = new List<string>();

            for (int i = 0; i < hotels.Length; i++)
            {
                bool flag = true;
                for (int j = 0; j < regionsList.Count; j++)
                {
                    if (regionsList[j].Name.Equals(hotels[i].region.Name))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    regionsList.Add(hotels[i].region);
                }
            }

            for (int i = 0; i < hotels.Length; i++)
            {
                bool flag = true;
                for (int j = 0; j < countrysList.Count; j++)
                {
                    if (countrysList[j].Name.Equals(hotels[i].region.Country.Name))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    countrysList.Add(hotels[i].region.Country);
                }
            }

            for (int i = 0; i < hotels.Length; i++)
            {
                bool flag = true;
                for (int j = 0; j < destinationsList.Count; j++)
                {
                    if (destinationsList[j].Equals(hotels[i].destination))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    destinationsList.Add(hotels[i].destination);
                }
            }

            for (int i = 0; i < hotels.Length; i++)
            {
                bool flag = true;
                for (int j = 0; j < locationsList.Count; j++)
                {
                    if (locationsList[j].Equals(hotels[i].location))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    locationsList.Add(hotels[i].location);
                }
            }

            for (int i = 0; i < hotels.Length; i++)
            {
                bool flag = true;
                for (int j = 0; j < levelsList.Count; j++)
                {
                    if (levelsList[j].Equals(hotels[i].level))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    levelsList.Add(hotels[i].level);
                }
            }

            for (int i = 0; i < hotels.Length; i++)
            {
                bool flag = true;
                for (int j = 0; j < typesList.Count; j++)
                {
                    if (typesList[j].Equals(hotels[i].type))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    typesList.Add(hotels[i].type);
                }
            }

            for (int i = 0; i < hotels.Length; i++)
            {
                bool flag = true;
                for (int j = 0; j < mealsesList.Count; j++)
                {
                    if (mealsesList[j].Equals(hotels[i].meals))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    mealsesList.Add(hotels[i].meals);
                }
            }

            for (int i = 0; i < hotels.Length; i++)
            {
                List<string> l = new List<string>();
                for (int k = 0; k < hotels[i].hotelServices.Length; k++)
                {
                    l.Add(hotels[i].hotelServices[k]);
                }

                hotelServicesSets.Add(l);


            }

            for (int i = 0; i < hotels.Length; i++)
            {
                List<string> l = new List<string>();
                for (int k = 0; k < hotels[i].roomServices.Length; k++)
                {
                    l.Add(hotels[i].roomServices[k]);
                }

                roomServicesSets.Add(l);

            }

            for (int i = 0; i < hotels.Length; i++)
            {
                List<string> l = new List<string>();
                for (int k = 0; k < hotels[i].childServices.Length; k++)
                {
                    l.Add(hotels[i].childServices[k]);
                }

                childServicesSets.Add(l);

            }

            for (int i = 0; i < hotels.Length; i++)
            {
                bool flag = true;
                for (int j = 0; j < pricesList.Count; j++)
                {
                    if (pricesList[j].Equals(hotels[i].price))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    pricesList.Add(hotels[i].price);
                }
            }

            countrys = countrysList.ToArray();
            regions = regionsList.ToArray();
            destinations = destinationsList.ToArray();
            locations = locationsList.ToArray();
            levels = levelsList.ToArray();
            types = typesList.ToArray();
            mealses = mealsesList.ToArray();
            prices = pricesList.ToArray();

        }
        private Hotel[] loadHotels(string hotelsFile)
        {
            List<Hotel> hotels = new List<Hotel>();
            Excel.Application excel = new Excel.Application();
            Excel.Workbook workbook = excel.Workbooks.Open(hotelsFile);
            Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Sheets.get_Item(1);
            Excel.Range range = worksheet.UsedRange;


            for (int i = 2; i <= range.Rows.Count; i++)
            {
                if (Convert.ToString(worksheet.Cells[i, 1].Value)!=null &&
                    !Convert.ToString(worksheet.Cells[i, 1].Value).Equals("") &&
                    Convert.ToString(worksheet.Cells[i, 2].Value) != null &&
                    !Convert.ToString(worksheet.Cells[i, 2].Value).Equals("") &&
                    Convert.ToString(worksheet.Cells[i, 3].Value) != null &&
                    !Convert.ToString(worksheet.Cells[i, 3].Value).Equals("") &&
                    Convert.ToString(worksheet.Cells[i, 4].Value) != null &&
                    !Convert.ToString(worksheet.Cells[i, 4].Value).Equals("") &&
                    Convert.ToString(worksheet.Cells[i, 5].Value) != null &&
                    !Convert.ToString(worksheet.Cells[i, 5].Value).Equals("") &&
                    Convert.ToString(worksheet.Cells[i, 6].Value) != null &&
                    !Convert.ToString(worksheet.Cells[i, 6].Value).Equals("") &&
                    Convert.ToString(worksheet.Cells[i, 7].Value) != null &&
                    !Convert.ToString(worksheet.Cells[i, 7].Value).Equals("") &&
                    Convert.ToString(worksheet.Cells[i, 8].Value) != null &&
                    !Convert.ToString(worksheet.Cells[i, 8].Value).Equals("") &&
                    Convert.ToString(worksheet.Cells[i, 12].Value) != null &&
                    !Convert.ToString(worksheet.Cells[i, 12].Value).Equals(""))
                {
                    Hotel hotel = new Hotel();
                    hotel.name = Convert.ToString(worksheet.Cells[i, 1].Value);
                    Country country = Country.GetCountry(Convert.ToString(worksheet.Cells[i, 2].Value));
                    Region region = Region.GetRegion(country, Convert.ToString(worksheet.Cells[i, 3].Value));
                    hotel.region = region;
                    hotel.destination = Convert.ToString(worksheet.Cells[i, 4].Value);
                    hotel.location = Convert.ToString(worksheet.Cells[i, 5].Value);
                    hotel.level = Convert.ToString(worksheet.Cells[i, 6].Value);
                    hotel.type = Convert.ToString(worksheet.Cells[i, 7].Value);
                    hotel.meals = Convert.ToString(worksheet.Cells[i, 8].Value);

                    string roomServices = Convert.ToString(worksheet.Cells[i, 9].Value);

                    List<string> l = roomServices.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).OfType<string>().ToList();
                    l.Sort((x, y) => String.CompareOrdinal(x, y));
                    hotel.roomServices = l.ToArray();

                    string hotelServices = Convert.ToString(worksheet.Cells[i, 10].Value);

                    l = hotelServices.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).OfType<string>().ToList();
                    l.Sort((x, y) => String.CompareOrdinal(x, y));
                    hotel.hotelServices = l.ToArray();


                    string childServices = Convert.ToString(worksheet.Cells[i, 11].Value);

                    l = childServices.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).OfType<string>().ToList();
                    l.Sort((x, y) => String.CompareOrdinal(x, y));
                    hotel.childServices = l.ToArray();

                    hotel.price = Convert.ToString(worksheet.Cells[i, 12].Value);

                    hotels.Add(hotel);
                }
            }
            workbook.Close(true);
            excel.Quit();

            return hotels.ToArray();

        }
        private HotelQueue[] getHotelQueues(Hotel[] hotels)
        {

            List<HotelQueue> hotelQueues = new List<HotelQueue>();

            for (int i = 0; i < hotels.Length; i++)
            {
                HotelQueue queue = new HotelQueue();

                queue.Hotel = hotels[i];

                queue.Nodes = new string[11][];
                queue.Nodes[0] = new string[] { hotels[i].region.Country.Name };
                queue.Nodes[1] = new string[] { hotels[i].region.Name };
                queue.Nodes[2] = new string[] { hotels[i].destination };
                queue.Nodes[3] = new string[] { hotels[i].location };
                queue.Nodes[4] = new string[] { hotels[i].level };
                queue.Nodes[5] = new string[] { hotels[i].type };
                queue.Nodes[6] = new string[] { hotels[i].meals };
                queue.Nodes[7] = hotels[i].hotelServices;
                queue.Nodes[8] = hotels[i].roomServices;
                queue.Nodes[9] = hotels[i].childServices;
                queue.Nodes[10] = new string[] { hotels[i].price };

                hotelQueues.Add(queue);

            }

            return hotelQueues.ToArray();
        }
Esempio n. 5
0
        private void f(string State, Questionnaire questionnaire, Production[] productions, double ku, List<Production> listProduction)
        {
            
            if (ku != 0)
            {
                for (int prodNum = 0; prodNum < productions.Length; prodNum++)
                {
                    if (State.Equals(productions[prodNum].State))
                    {
                        switch (productions[prodNum].Arg1)
                        {
                            case "Страна":
                                if (!productions[prodNum].Arg2.Equals(questionnaire.country))
                                {
                                    continue;
                                }
                                break;
                            case "Регион":
                                if (!productions[prodNum].Arg2.Equals(questionnaire.region))
                                {
                                    continue;
                                }
                                break;
                            case "Климат":
                                if (!productions[prodNum].Arg2.Equals(questionnaire.climate))
                                {
                                    continue;
                                }

                                break;
                            case "Здоровье":
                                if (!productions[prodNum].Arg2.Equals(questionnaire.health))
                                {
                                    continue;
                                }
                                else
                                {
                                    ku *= Double.Parse(productions[prodNum].KU);
                                }
                                break;
                            case "Возраст":
                                /*
                                int ost = questionnaire.age % 10 < 5 ? 0 : 5;
                                int l1 = (questionnaire.age / 10) * 10 + ost;
                                int l2 = (questionnaire.age / 10) * 10 + ost + 5;
                                double d = ((questionnaire.age % 10)- ost ) / 5.0;
                                double ku1 = 0, ku2 = 0;
                                switch (productions[prodNum].KU)
                                {
                                    case "Назначение/Возраст":
                                        ku1 = II.CurentII.DestinationAgeKU[productions[prodNum].Arg2][l1 + ""];
                                        ku2 = II.CurentII.DestinationAgeKU[productions[prodNum].Arg2][l2 + ""];
                                        break;
                                    case "Питание/Возраст":
                                        ku1 = II.CurentII.MealAgeKU[productions[prodNum].Arg2][l1 + ""];
                                        ku2 = II.CurentII.MealAgeKU[productions[prodNum].Arg2][l2 + ""];
                                        break;
                                    case "Климат/Возраст":
                                        ku1 = II.CurentII.ClimateAgeKU[productions[prodNum].Arg2][l1 + ""];
                                        ku2 = II.CurentII.ClimateAgeKU[productions[prodNum].Arg2][l2 + ""];
                                        break;
                                }

                                ku *= ku1 + (ku2-ku1) * d;*/
                                double ku1 = 0.0, ku2=0.0;
                                int l1=0, l2=0;
                                switch (productions[prodNum].KU)
                                {
                                    case "Назначение/Возраст":
                                        l1 = int.Parse(II.CurentII.DestinationAgeKU[productions[prodNum].Arg2].Keys.Last(p => int.Parse(p) <= questionnaire.age));
                                        l2 = int.Parse(II.CurentII.DestinationAgeKU[productions[prodNum].Arg2].Keys.First(p => int.Parse(p) > questionnaire.age));
                                        ku1 = II.CurentII.DestinationAgeKU[productions[prodNum].Arg2][l1 + ""];
                                        ku2 = II.CurentII.DestinationAgeKU[productions[prodNum].Arg2][l2 + ""];
                                        break;
                                    case "Питание/Возраст":
                                        l1 = int.Parse(II.CurentII.MealAgeKU[productions[prodNum].Arg2].Keys.Last(p => int.Parse(p) <= questionnaire.age));
                                        l2 = int.Parse(II.CurentII.MealAgeKU[productions[prodNum].Arg2].Keys.First(p => int.Parse(p) > questionnaire.age));
                                        ku1 = II.CurentII.MealAgeKU[productions[prodNum].Arg2][l1 + ""];
                                        ku2 = II.CurentII.MealAgeKU[productions[prodNum].Arg2][l2 + ""];
                                        break;
                                    case "Климат/Возраст":
                                        l1 = int.Parse(II.CurentII.ClimateAgeKU[productions[prodNum].Arg2].Keys.Last(p => int.Parse(p) <= questionnaire.age));
                                        l2 = int.Parse(II.CurentII.ClimateAgeKU[productions[prodNum].Arg2].Keys.First(p => int.Parse(p) > questionnaire.age));
                                        ku1 = II.CurentII.ClimateAgeKU[productions[prodNum].Arg2][l1 + ""];
                                        ku2 = II.CurentII.ClimateAgeKU[productions[prodNum].Arg2][l2 + ""];
                                        break;
                                }
                                ku *= (ku2 - ku1) * (questionnaire.age - l1) / (l2 - l1) + ku1;
                                break;
                            case "Назначение":
                                if (!productions[prodNum].Arg2.Equals(questionnaire.destination))
                                {
                                    continue;
                                }
                                break;
                            case "Страховка":
                                if (!productions[prodNum].Arg2.Equals(questionnaire.insurance))
                                {
                                    continue;
                                }
                                else
                                {
                                    ku *= Double.Parse(productions[prodNum].KU);
                                }
                                break;
                            case "Расположение":
                                if (!productions[prodNum].Arg2.Equals(questionnaire.location))
                                {
                                    continue;
                                }
                                break;
                            case "Уровень":
                                if (!productions[prodNum].Arg2.Equals(questionnaire.level))
                                {
                                    continue;
                                }
                                break;
                            case "Тип":
                                if (!productions[prodNum].Arg2.Equals(questionnaire.type))
                                {
                                    continue;
                                }
                                break;
                            case "Питание":
                                if (!productions[prodNum].Arg2.Equals(questionnaire.meals))
                                {
                                    continue;
                                }
                                break;
                            case "Услуги в номере":
                                if (!contain(productions[prodNum].Arg2, questionnaire.roomServices))
                                {
                                    continue;
                                }
                                break;
                            case "Услуги в отеле":
                                if (!contain(productions[prodNum].Arg2, questionnaire.hotelServices))
                                {
                                    continue;
                                }
                                break;
                            case "Услуги для детей":
                                if (!contain(productions[prodNum].Arg2, questionnaire.childService))
                                {
                                    continue;
                                }
                                break;
                            case "Сумма":
                                int price_sum = (int)((Int32.Parse(productions[prodNum].Arg2) + II.CurentII.ServiceCost));
                                int client_sum = (int)(questionnaire.price * 1.2/questionnaire.holidaysLength);
                                double ku_pr;
                                if (price_sum <= client_sum)
                                {
                                    ku_pr = 1.0;
                                }
                                else if (price_sum >= (int)(client_sum * 1.25))
                                {
                                    ku_pr = 0.0;
                                }
                                else
                                {
                                    ku_pr = (client_sum - price_sum) / (questionnaire.price * 0.3/questionnaire.holidaysLength) + 1;
                                }
                                ku *= ku_pr;
                                break;
                            case "Отель":
                                string hotelname = productions[prodNum].StateResult;
                                ku *= PostProcessResult(hotelname, questionnaire);
                                if (ku == 0)
                                    continue;
                                Console.WriteLine(hotelname + " " + ku);
                                HotelFindResult hotelFindResult = new HotelFindResult();
                                Hotel hotel = new Hotel();
                                hotel.name = hotelname;
                                hotelFindResult.Hotel = hotel;
                                hotelFindResult.KU = ku;
                                hotelFindResult.Productions = listProduction.ToArray();
                                hotelFindResults.Add(hotelFindResult);

                                continue;
                        }
                        List<Production> listProductionNew = new List<Production>();
                        for (int i = 0; i < listProduction.Count; i++)
                        {
                            listProductionNew.Add(listProduction[i]);
                        }
                        listProductionNew.Add(productions[prodNum]);
                        f(productions[prodNum].StateResult, questionnaire, productions, ku, listProductionNew);

                    }
                }
            }
        }