Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using MySql.Data.MySqlClient;
- using System;
- using UnityEngine.UI;
- using TMPro;
- using UnityEngine.Networking;
- public class DownloadIdeas : MonoBehaviour
- {
- //DataBase
- static String ConnectionString = "server=XXX; password=XXX; user=XXX; database=XXX;charset=utf8";
- static MySqlCommand komenda;
- static MySqlDataReader czytnik;
- static string polecenie = "";
- //DataBase
- //PrefabInCategory
- public GameObject PrefabIdeaInCategories;
- public Transform[] CategoryParrents;
- //PrefabInCategory
- //PrefabInSearcher
- public TMP_Text PlaceHolder;
- public TMP_InputField InputSearch;
- public GameObject PrefabInSearcher;
- public Transform SearcherParrent;
- //PrefabInSearcher
- public String[] TableName;
- public Sprite[] CategorySprite;
- //generally
- public GameObject IdeaContent;
- public GameObject InternetAlert;
- //generally
- public GameObject PanelAlert, ButtonAlertExit;
- public Text TextAlert;
- void OnEnable()
- {
- StartCoroutine(CheckVersion());
- }
- public void UpdateCanvas()
- {
- for (int i = 0; i < CategoryParrents.Length; i++)
- {
- LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)CategoryParrents[i].transform);
- Canvas.ForceUpdateCanvases();
- CategoryParrents[i].GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
- }
- LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)SearcherParrent.transform);
- Canvas.ForceUpdateCanvases();
- SearcherParrent.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
- }
- IEnumerator CheckVersion()
- {
- ShowAlert("Sprawdzam wersję aplikacji", false);
- WWW WWWCheckVerion = new WWW("http://skydomesoftware.cba.pl/CLP-Wersja.txt");
- yield return WWWCheckVerion;
- float CheckedVersion = float.Parse(WWWCheckVerion.text);
- if (CheckedVersion > float.Parse(Application.version))
- {
- ShowAlert("Aplikacja jest nieaktualna. Pobierz najnowszą wersję ze sklepu Play", true);
- }
- else
- {
- ShowAlert("Aplikacja jest aktualna. Pobieram pomysły...", false);
- MainFunction();
- }
- // CheckAllIdeas();
- }
- public void CheckAllIdeas()
- {
- if(SearcherParrent.childCount > 0)
- {
- Debug.Log("Wszystko w porządku :)");
- }
- else
- {
- ShowAlert("Spróbuj połączyć się z innym źródłem internetu. Prawdopodobnie połączenie z bazą danych jest blokowane przez dostawcę internetu", true);
- }
- }
- public void ShowAlert(string message, bool ButtonOn)
- {
- TextAlert.text = message;
- PanelAlert.SetActive(true);
- if (ButtonOn == true)
- ButtonAlertExit.SetActive(true);
- else
- ButtonAlertExit.SetActive(false);
- }
- public void Update()
- {
- if (Application.internetReachability == NetworkReachability.NotReachable)
- {
- InternetAlert.SetActive(true);
- }
- else
- {
- InternetAlert.SetActive(false);
- }
- }
- public void searcher()
- {
- for (int i = 0; i < SearcherParrent.childCount; i++)
- {
- if (SearcherParrent.GetChild(i).gameObject.transform.GetChild(0).GetComponent<TMP_Text>().text.ToLower().Contains(InputSearch.text.ToLower()))
- {
- SearcherParrent.GetChild(i).gameObject.SetActive(true);
- }
- else
- {
- SearcherParrent.GetChild(i).gameObject.SetActive(false);
- }
- }
- }
- public void MainFunction()
- {
- PanelAlert.SetActive(true);
- TextAlert.text = "Pobieranie pomysłów...";
- for (int i = 0; i < TableName.Length; i++)
- {
- Download(CategoryParrents[i], TableName[i], i, CategorySprite[i]);
- }
- }
- public void AddLike(string sign, int id, int TableNR)
- {
- try
- {
- using (MySqlConnection polaczenie = new MySqlConnection(ConnectionString))
- {
- polaczenie.Open();
- polecenie = "update " + TableName[TableNR] + " set Likes =" + sign + " where ID = '" + id + "' ";
- komenda = new MySqlCommand(polecenie, polaczenie);
- komenda.ExecuteNonQuery();
- czytnik = komenda.ExecuteReader();
- czytnik.Close();
- polaczenie.Close();
- }
- }
- catch (MySqlException ex)
- {
- ShowAlert("Add like " + ex.ToString(), true);
- }
- }
- public void DownloadContent(GameObject Idea, int id, int TableNR)
- {
- try
- {
- using (MySqlConnection polaczenie = new MySqlConnection(ConnectionString))
- {
- polaczenie.Open();
- polecenie = "select * from " + TableName[TableNR] + " where ID = '" + id + "' ";
- komenda = new MySqlCommand(polecenie, polaczenie);
- komenda.ExecuteNonQuery();
- czytnik = komenda.ExecuteReader();
- while (czytnik.Read())
- {
- for (int i = 0; i <= 8; i++)
- {
- Idea.GetComponent<IdeaButtonName>().ContentPL[i] = czytnik["ContentPL" + (i+1)].ToString();
- Idea.GetComponent<IdeaButtonName>().ContentENG[i] = czytnik["ContentENG" + (i+1)].ToString();
- }
- }
- czytnik.Close();
- polaczenie.Close();
- }
- }
- catch (MySqlException ex)
- {
- ShowAlert("DOWNLOAD CONTENT ERROR: " + ex.ToString(), true);
- }
- }
- public void AddComment(string Comment, int id, int TableNR)
- {
- try
- {
- using (MySqlConnection polaczenie = new MySqlConnection(ConnectionString))
- {
- polaczenie.Open();
- polecenie = "update " + TableName[TableNR] + " set Comments = '" + Comment + "' where ID = '" + id + "' ";
- komenda = new MySqlCommand(polecenie, polaczenie);
- komenda.ExecuteNonQuery();
- czytnik = komenda.ExecuteReader();
- czytnik.Close();
- polaczenie.Close();
- }
- }
- catch (MySqlException ex)
- {
- ShowAlert("Add Comment " + ex.ToString(), true);
- }
- }
- public void AddView(string sign, int id, int TableNR)
- {
- try
- {
- using (MySqlConnection polaczenie = new MySqlConnection(ConnectionString))
- {
- polaczenie.Open();
- polecenie = "update " + TableName[TableNR] + " set Views =" + sign + " where ID = '" + id + "' ";
- komenda = new MySqlCommand(polecenie, polaczenie);
- komenda.ExecuteNonQuery();
- czytnik = komenda.ExecuteReader();
- czytnik.Close();
- polaczenie.Close();
- }
- }
- catch (MySqlException ex)
- {
- ShowAlert("Add view " + ex.ToString(), true);
- }
- }
- public void Download(Transform CategoryParrent, string table, int CategoryNumber, Sprite CategorySprite)
- {
- try
- {
- using (MySqlConnection polaczenie = new MySqlConnection(ConnectionString))
- {
- polaczenie.Open();
- polecenie = "select * from " + table + " order by ID";
- komenda = new MySqlCommand(polecenie, polaczenie);
- komenda.ExecuteNonQuery();
- czytnik = komenda.ExecuteReader();
- int IdeaNumber = 0;
- while (czytnik.Read())
- {
- IdeaNumber++;
- int id = int.Parse(czytnik["ID"].ToString());
- int categoryNumber = CategoryNumber;
- string title = czytnik["Title"].ToString();
- string[] ContentPL = new string[9];
- string[] ContentENG = new string[9];
- //for (int i = 0; i <= 8; i++)
- //{
- // ContentPL[i] = czytnik["ContentPL" + (i + 1)].ToString();
- // ContentENG[i] = czytnik["ContentENG" + (i + 1)].ToString();
- //}
- string pictureUrl = czytnik["Picture"].ToString();
- string link = czytnik["Link"].ToString();
- string likes = czytnik["Likes"].ToString();
- string comments = czytnik["Comments"].ToString();
- string views = czytnik["Views"].ToString();
- //PrefabIdeaInCategories
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ID = id;
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().CategoryNumber = categoryNumber;
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().TextNumber.text = IdeaNumber.ToString() + ".";
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().Title = title;
- Array.Resize(ref PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ContentPL, 9);
- Array.Resize(ref PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ContentENG, 9);
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().PictureUrl = pictureUrl;
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().Link = link;
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().Likes = likes;
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().Comments = comments;
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().views = views;
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().CategorySprite = CategorySprite;
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().IdeaContent = IdeaContent;
- PrefabIdeaInCategories.GetComponent<IdeaButtonName>().DownloadIdeasScript = this.gameObject;
- Instantiate(PrefabIdeaInCategories, CategoryParrent);
- //PrefabIdeaInCategories
- //PrefabInSearcher
- PrefabInSearcher.GetComponent<IdeaButtonName>().ID = id;
- PrefabInSearcher.GetComponent<IdeaButtonName>().CategoryNumber = CategoryNumber;
- PrefabInSearcher.GetComponent<IdeaButtonName>().Title = title;
- Array.Resize(ref PrefabInSearcher.GetComponent<IdeaButtonName>().ContentPL, 9);
- Array.Resize(ref PrefabInSearcher.GetComponent<IdeaButtonName>().ContentENG, 9);
- //for (int i = 0; i <= 8; i++)
- //{
- // PrefabInSearcher.GetComponent<IdeaButtonName>().ContentPL[i] = ContentPL[i];
- // PrefabInSearcher.GetComponent<IdeaButtonName>().ContentENG[i] = ContentENG[i];
- //}
- PrefabInSearcher.GetComponent<IdeaButtonName>().PictureUrl = pictureUrl;
- PrefabInSearcher.GetComponent<IdeaButtonName>().Link = link;
- PrefabInSearcher.GetComponent<IdeaButtonName>().Likes = likes;
- PrefabInSearcher.GetComponent<IdeaButtonName>().Comments = comments;
- PrefabInSearcher.GetComponent<IdeaButtonName>().views = views;
- PrefabInSearcher.GetComponent<IdeaButtonName>().CategorySprite = CategorySprite;
- PrefabInSearcher.GetComponent<IdeaButtonName>().IdeaContent = IdeaContent;
- PrefabInSearcher.GetComponent<IdeaButtonName>().DownloadIdeasScript = this.gameObject;
- Instantiate(PrefabInSearcher, SearcherParrent);
- // PrefabInSearcher
- }
- polaczenie.Close();
- }
- czytnik.Close();
- PlaceHolder.text = "Wyszukaj wśród (" + SearcherParrent.childCount + ") pomysłów";
- PanelAlert.SetActive(false);
- if (SearcherParrent.childCount < 10)
- {
- ShowAlert("Błąd. Baza danych jest pusta. Spróbuj zaktualizować aplikację.\n" +
- "Twoja wersja aplikacji: " + Application.version + Environment.NewLine +
- "Twoje urządzenie: " + SystemInfo.deviceModel +
- "Ilość pomysłów: " + SearcherParrent.childCount, true);
- }
- }
- catch (MySqlException ex)
- {
- ShowAlert("First run " + ex.ToString(), true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement