Exemplo n.º 1
0
        public static async Task <string> ShowRezult(string type, string question, Find.Sh sh)
        {
            DataBase dataBase = new DataBase();

            string content = "";

            try
            {
                question.Replace(' ', '+');

                string url = $"https://api.themoviedb.org/3/search/{type}?api_key={Find.Search.API_key}&query={question}";
                if ((content = dataBase.Search(question, type, sh)) == null)
                {
                    if (type == "movie")
                    {
                        Find.AnswerMovie rez = await Find.Search.GetRezaltAsync <Find.AnswerMovie>(url);

                        Find.Genres genres = await Find.Search.GetRezaltAsync <Find.Genres>($"https://api.themoviedb.org/3/genre/movie/list?api_key={Find.Search.API_key}&language=en-US");

                        dataBase.Insert($"insert into Search_History(Text_Of_Search,Type,User_search) values('{question}','{type}','vlad')");

                        for (int o = 0; o < rez.results.Count; o++)
                        {
                            string genrez = "";
                            for (int q = 0; q < rez.results[o].genre_ids.Length; q++)
                            {
                                genrez += rez.results[o].genre_ids[q].ToString();
                                genrez += ",";
                            }
                            dataBase.Insert($"Insert into Content (Genre_ids,Popularity,Vote_count,Backdrop_path,Original_language,Vote_average,Overview," +
                                            $"Poster_path,Adult,Release_date,Original_title,Title,Video) values" +
                                            $"('{genrez}',{rez.results[o].popularity.ToString(CultureInfo.CreateSpecificCulture("en-US"))},{rez.results[o].vote_count},'{rez.results[o].backdrop_path}','{rez.results[o].original_language}'" +
                                            $",{rez.results[o].vote_average.ToString(CultureInfo.CreateSpecificCulture("en-US"))}, '{rez.results[o].overview.Replace("’", "").Replace("'", "")}','{rez.results[o].poster_path}'," +
                                            $"{(rez.results[o].adult ? 1 : 0)},'{rez.results[o].release_date}','{rez.results[o].original_title.Replace("’", "").Replace("'", "")}','{rez.results[o].title.Replace("’", "").Replace("'", "")}',{(rez.results[o].video ? 1 : 0)})");
                            dataBase.Insert($"insert into Content_Answer(Search_Id,Content_Id) values((select top(1) Id from Search_History where Text_Of_Search='{question}' and Type='{type}'),(select top(1) Id from Content where Original_title='{rez.results[o].original_title}'))");
                        }

                        for (int g = 0; g < genres.genres.Count; g++)
                        {
                            try
                            {
                                dataBase.Insert($"Insert into Genres(Id,Name) values('{genres.genres[g].id}','{genres.genres[g].name}')");
                            }
                            catch (Exception) { }
                        }
                        content = sh(rez, null, genres);
                    }
                    else
                    {
                        Find.AnswerTV reza = await Find.Search.GetRezaltAsync <Find.AnswerTV>(url);

                        Find.Genres genress = await Find.Search.GetRezaltAsync <Find.Genres>($"https://api.themoviedb.org/3/genre/tv/list?api_key={Find.Search.API_key}&language=en-US");

                        dataBase.Insert($"insert into Search_History(Text_Of_Search,Type,User_search) values('{question}','{type}','vlad')");

                        for (int o = 0; o < reza.results.Count; o++)
                        {
                            string genrez = "", countries = "";
                            for (int q = 0; q < reza.results[o].genre_ids.Length; q++)
                            {
                                genrez += reza.results[o].genre_ids[q].ToString();
                                genrez += ",";
                            }
                            for (int q = 0; q < reza.results[o].origin_country.Length; q++)
                            {
                                countries += reza.results[o].origin_country[q].ToString();
                                countries += ",";
                            }
                            dataBase.Insert($"Insert into Content(Genre_ids,Popularity,Vote_count,Backdrop_path,Original_language,Vote_average," +
                                            $"Overview,Poster_path,Original_name,Name,Origin_country,First_air_date)" +
                                            $" values('{genrez}',{reza.results[o].popularity.ToString(CultureInfo.CreateSpecificCulture("en-US"))}," +
                                            $"{reza.results[o].vote_count},'{reza.results[o].backdrop_path}','{reza.results[o].original_language}'," +
                                            $"{reza.results[o].vote_average.ToString(CultureInfo.CreateSpecificCulture("en-US"))}," +
                                            $"'{reza.results[o].overview.Replace("’", "").Replace("'", "")}','{reza.results[o].poster_path}','{reza.results[o].original_name.Replace("’", "").Replace("'", "")}','{reza.results[o].name.Replace("’", "").Replace("'", "")}','{countries}','{reza.results[o].first_air_date}')");

                            dataBase.Insert($"insert into Content_Answer(Search_Id,Content_Id) values((select top(1) Id from Search_History where Text_Of_Search='{question}' and Type='{type}'),(select top(1) Id from Content where Original_name='{reza.results[o].original_name}'))");
                        }
                        for (int g = 0; g < genress.genres.Count; g++)
                        {
                            try
                            {
                                dataBase.Insert($"Insert into Genres(Id,Name) values('{genress.genres[g].id}','{genress.genres[g].name}')");
                            }
                            catch (Exception) { }
                        }
                        content = sh(null, reza, genress);
                    }
                }
            }
            catch (Exception e)
            {
                IKernel kernel = new StandardKernel();
                ModuleLoader.Load(kernel, LoggerType.File);
                DIExperiment dI = kernel.Get <DIExperiment>();
                dI.UseLogger(e.Message);
            }
            return(content);
        }
Exemplo n.º 2
0
        static string Display(Find.AnswerMovie x, Find.AnswerTV tV, Find.Genres z)
        {
            string content = "<html><head><meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/></head><body>";

            if (x != null)
            {
                if (x.total_results != 0)
                {
                    for (int i = 0; i < x.total_results && i < 20; i++)
                    {
                        content += $"<div><img width=200 height=300 style=\"display:inline-block;\" src=\"https://image.tmdb.org/t/p/w300_and_h450_bestv2{x.results[i].poster_path}\">" +
                                   $"<p>Название:{x.results[i].original_title}</p>" +
                                   $"<p>Популярность:{x.results[i].popularity}</p>" +
                                   $"<p>Рейтинг:{x.results[i].vote_average}</p>" +
                                   $"<p>Описание:{x.results[i].overview}</p>" +
                                   $"<p>Жанp:";

                        for (int t = 0; t < x.results[i].genre_ids.Length; t++)
                        {
                            content += z.genres.Find(o => o.id == x.results[i].genre_ids[t]).name;
                            if (x.results[i].genre_ids.Length - 1 != t)
                            {
                                content += ",";
                            }
                        }

                        content += $"</p><p>Дата реализации:{x.results[i].release_date}</p><p><button onclick=\"window.external.Create_Comment('(select top(1) Id from Content where Original_title=\\'{x.results[i].original_title}\\')')\">Комментарии</button> </p></div><br><hr></ body ></ html > ";
                    }
                }
                else
                {
                    content = ("<html><head><meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/></head><body><h1>Ничего не найдено!</h1></body><html>");
                }
            }
            if (tV != null)
            {
                if (tV.total_results != 0)
                {
                    for (int i = 0; i < tV.total_results && i < 20; i++)
                    {
                        content += $"<div><img width=200 height=300 style=\"display:inline-block;\" src=\"https://image.tmdb.org/t/p/w300_and_h450_bestv2{tV.results[i].poster_path}\">" +
                                   $"<p>Название:{tV.results[i].original_name}</p>" +
                                   $"<p>Популярность:{tV.results[i].popularity}</p>" +
                                   $"<p>Рейтинг:{tV.results[i].vote_average}</p>" +
                                   $"<p>Описание:{tV.results[i].overview}</p>" +
                                   $"<p>Жанр: ";

                        for (int t = 0; t < tV.results[i].genre_ids.Length; t++)
                        {
                            content += z.genres.Find(o => o.id == tV.results[i].genre_ids[t]).name;
                            if (tV.results[i].genre_ids.Length - 1 != t)
                            {
                                content += ",";
                            }
                        }

                        content += $"</p><p>Дата реализации:{tV.results[i].first_air_date}</p><p><button onclick=\"window.external.Create_Comment('(select top(1) Id from Content where Original_title=\\'{tV.results[i].original_name}\\')')\">Комментарии</button> </p></div><br><hr></ body ></ html > ";
                    }
                }
                else
                {
                    content = ("<html><head><meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/></head><body><h1>Ничего не найдено!</h1></body><html>");
                }
            }

            return(content);
        }
Exemplo n.º 3
0
        public string Search(string question, string type, Find.Sh sh)
        {
            string    rezalts    = null;
            DataTable dataTable  = new DataTable("dataBase");
            DataTable dataTable1 = new DataTable("dataBase");

            SqlCommand sqlCommand = sqlConnection.CreateCommand();

            sqlCommand.CommandText = $"select Id,Genre_ids,Popularity,Vote_count,Backdrop_path,Original_language,Vote_average,Overview," +
                                     $"Poster_path,Adult,Release_date,Original_title,Title,Video,Original_name,Name,Origin_country,First_air_date from Content where Id=any(select Content_Id from Content_Answer where Search_Id=(select top(1) Id from Search_History where Type='{type}' and Text_Of_Search='{question}'))";
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);

            sqlDataAdapter.Fill(dataTable);

            SqlCommand sqlCommand1 = sqlConnection.CreateCommand();

            sqlCommand1.CommandText = $"select * from Genres";
            SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter(sqlCommand1);

            sqlDataAdapter1.Fill(dataTable1);



            if (type == "movie")
            {
                Find.AnswerMovie rez = new Find.AnswerMovie();
                rez.results = new List <Find.Movie>();
                Find.Genres genress = new Find.Genres();
                genress.genres = new List <Find.Genres.genre>();
                for (int u = 0; u < dataTable1.Rows.Count; u++)
                {
                    Find.Genres.genre genre = new Find.Genres.genre();
                    genre.id   = (int)dataTable1.Rows[u].ItemArray[0];
                    genre.name = (string)dataTable1.Rows[u].ItemArray[1];
                    genress.genres.Add(genre);
                }
                for (int r = 0; r < dataTable.Rows.Count; r++)
                {
                    rez.results.Add(new Find.Movie());
                    rez.results[r].adult             = (bool)dataTable.Rows[r].ItemArray[9];
                    rez.results[r].video             = (bool)dataTable.Rows[r].ItemArray[13];
                    rez.results[r].vote_average      = (float)(double)dataTable.Rows[r].ItemArray[6];
                    rez.results[r].vote_count        = (int)dataTable.Rows[r].ItemArray[3];
                    rez.results[r].title             = (string)dataTable.Rows[r].ItemArray[12];
                    rez.results[r].release_date      = (string)dataTable.Rows[r].ItemArray[10];
                    rez.results[r].poster_path       = (string)dataTable.Rows[r].ItemArray[8];
                    rez.results[r].popularity        = (float)(double)dataTable.Rows[r].ItemArray[2];
                    rez.results[r].overview          = (string)dataTable.Rows[r].ItemArray[7];
                    rez.results[r].original_title    = (string)dataTable.Rows[r].ItemArray[11];
                    rez.results[r].original_language = (string)dataTable.Rows[r].ItemArray[5];
                    rez.results[r].id            = (int)dataTable.Rows[r].ItemArray[0];
                    rez.results[r].backdrop_path = (string)dataTable.Rows[r].ItemArray[4];

                    string     str = "";
                    int        e   = 0;
                    List <int> vs  = new List <int>();
                    for (int i = 0; i < dataTable.Rows[r].ItemArray[1].ToString().Length; i++)
                    {
                        while (i != dataTable.Rows[r].ItemArray[1].ToString().Length)
                        {
                            if (dataTable.Rows[r].ItemArray[1].ToString()[i] == ',')
                            {
                                break;
                            }
                            str += dataTable.Rows[r].ItemArray[1].ToString()[i];
                            i++;
                        }
                        vs.Add(Convert.ToInt32(str));
                        str = "";
                    }
                    rez.results[r].genre_ids = vs.ToArray();
                }
                rez.total_results = rez.results.Count;
                if (dataTable.Rows.Count != 0)
                {
                    rezalts = sh(rez, null, genress);
                }
            }
            else
            {
                Find.AnswerTV rez = new Find.AnswerTV();
                rez.results = new List <Find.TV>();
                Find.Genres genress = new Find.Genres();
                genress.genres = new List <Find.Genres.genre>();
                for (int u = 0; u < dataTable1.Rows.Count; u++)
                {
                    Find.Genres.genre genre = new Find.Genres.genre();
                    genre.id   = (int)dataTable1.Rows[u].ItemArray[0];
                    genre.name = (string)dataTable1.Rows[u].ItemArray[1];
                    genress.genres.Add(genre);
                }
                for (int r = 0; r < dataTable.Rows.Count; r++)
                {
                    rez.results.Add(new Find.TV());
                    rez.results[r].original_name     = (string)dataTable.Rows[r].ItemArray[14];
                    rez.results[r].name              = (string)dataTable.Rows[r].ItemArray[15];
                    rez.results[r].vote_average      = (float)(double)dataTable.Rows[r].ItemArray[6];
                    rez.results[r].vote_count        = (int)dataTable.Rows[r].ItemArray[3];
                    rez.results[r].first_air_date    = (string)dataTable.Rows[r].ItemArray[17];
                    rez.results[r].poster_path       = (string)dataTable.Rows[r].ItemArray[8];
                    rez.results[r].popularity        = (float)(double)dataTable.Rows[r].ItemArray[2];
                    rez.results[r].overview          = (string)dataTable.Rows[r].ItemArray[7];
                    rez.results[r].original_language = (string)dataTable.Rows[r].ItemArray[5];
                    rez.results[r].id            = (int)dataTable.Rows[r].ItemArray[0];
                    rez.results[r].backdrop_path = (string)dataTable.Rows[r].ItemArray[4];

                    string        str = "", str1 = "";
                    int           e   = 0;
                    List <int>    vs  = new List <int>();
                    List <string> vs1 = new List <string>();
                    for (int i = 0; i < dataTable.Rows[r].ItemArray[1].ToString().Length; i++)
                    {
                        while (i != dataTable.Rows[r].ItemArray[1].ToString().Length)
                        {
                            if (dataTable.Rows[r].ItemArray[1].ToString()[i] == ',')
                            {
                                break;
                            }
                            str += dataTable.Rows[r].ItemArray[1].ToString()[i];
                            i++;
                        }
                        vs.Add(Convert.ToInt32(str));
                        str = "";
                    }
                    rez.results[r].genre_ids = vs.ToArray();

                    for (int i = 0; i < dataTable.Rows[r].ItemArray[16].ToString().Length; i++)
                    {
                        while (i != dataTable.Rows[r].ItemArray[16].ToString().Length)
                        {
                            if (dataTable.Rows[r].ItemArray[16].ToString()[i] == ',')
                            {
                                break;
                            }
                            str1 += dataTable.Rows[r].ItemArray[16].ToString()[i];
                            i++;
                        }
                        vs1.Add(str1);

                        str1 = "";
                    }

                    rez.results[r].origin_country = vs1.ToArray();
                }
                rez.total_results = rez.results.Count;
                if (dataTable.Rows.Count != 0)
                {
                    rezalts = sh(null, rez, genress);
                }
            }
            return(rezalts);
        }