Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.34 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using MySql.Data.MySqlClient;
  4. using System;
  5. using UnityEngine.UI;
  6. using TMPro;
  7. using UnityEngine.Networking;
  8. public class DownloadIdeas : MonoBehaviour
  9. {
  10.  
  11. //DataBase
  12. static MySqlConnection polaczenie = new MySqlConnection("server=skydomesoftware.cba.pl; password=FridgeCook1234; user=FridgeCook; database=skydome_software;charset=utf8");
  13. static MySqlCommand komenda; static MySqlDataReader czytnik;
  14. static string polecenie = "";
  15. //DataBase
  16.  
  17.  
  18.  
  19. //PrefabInCategory
  20. public GameObject PrefabIdeaInCategories;
  21. public Transform[] CategoryParrents;
  22. //PrefabInCategory
  23.  
  24. //PrefabInSearcher
  25. public TMP_Text PlaceHolder;
  26. public TMP_InputField InputSearch;
  27. public GameObject PrefabInSearcher;
  28. public Transform SearcherParrent;
  29. //PrefabInSearcher
  30.  
  31. public String[] TableName;
  32. public Sprite[] CategorySprite;
  33.  
  34. //generally
  35. public GameObject IdeaContent;
  36. public GameObject InternetAlert;
  37. //generally
  38.  
  39. public GameObject demoalert;
  40.  
  41. private void Start()
  42. {
  43. MainFunction();
  44.  
  45. }
  46.  
  47. public void Update()
  48. {
  49. if (Application.internetReachability == NetworkReachability.NotReachable)
  50. {
  51. InternetAlert.SetActive(true);
  52. }
  53. else
  54. {
  55. InternetAlert.SetActive(false);
  56. }
  57. }
  58. public void searcher()
  59. {
  60.  
  61. for (int i = 0; i < SearcherParrent.childCount; i++)
  62. {
  63. if (SearcherParrent.GetChild(i).gameObject.transform.GetChild(0).GetComponent<TMP_Text>().text.ToLower().Contains(InputSearch.text.ToLower()))
  64. {
  65. SearcherParrent.GetChild(i).gameObject.SetActive(true);
  66. }
  67. else
  68. {
  69. SearcherParrent.GetChild(i).gameObject.SetActive(false);
  70. }
  71. }
  72.  
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79. public void MainFunction()
  80. {
  81. for (int i = 0; i < TableName.Length; i++)
  82. {
  83. Download(CategoryParrents[i], TableName[i], i, CategorySprite[i]);
  84. }
  85. }
  86.  
  87. public void AddLike(string sign, int id, int TableNR)
  88. {
  89. if (polaczenie.State == System.Data.ConnectionState.Closed)
  90. {
  91. polaczenie.Open();
  92. polecenie = "update "+TableName[TableNR] +" set Likes ="+ sign + " where ID = '" + id + "' ";
  93. komenda = new MySqlCommand(polecenie, polaczenie);
  94. komenda.ExecuteNonQuery();
  95.  
  96. }
  97. czytnik.Close();
  98. polaczenie.Close();
  99. polaczenie.Dispose();
  100. }
  101. public void AddComment(string Comment, int id, int TableNR)
  102. {
  103. if (polaczenie.State == System.Data.ConnectionState.Closed)
  104. {
  105. polaczenie.Open();
  106. polecenie = "update " + TableName[TableNR] + " set Comments = '" + Comment + "' where ID = '" + id + "' ";
  107. komenda = new MySqlCommand(polecenie, polaczenie);
  108. komenda.ExecuteNonQuery();
  109.  
  110. }
  111. czytnik.Close();
  112. polaczenie.Close();
  113. polaczenie.Dispose();
  114. }
  115.  
  116.  
  117.  
  118. public void AddView(string sign, int id, int TableNR)
  119. {
  120. if (polaczenie.State == System.Data.ConnectionState.Closed)
  121. {
  122. polaczenie.Open();
  123. polecenie = "update " + TableName[TableNR] + " set Views =" + sign + " where ID = '" + id + "' ";
  124. komenda = new MySqlCommand(polecenie, polaczenie);
  125. komenda.ExecuteNonQuery();
  126.  
  127. }
  128. czytnik.Close();
  129. polaczenie.Close();
  130. polaczenie.Dispose();
  131. }
  132.  
  133.  
  134.  
  135.  
  136. public void Download(Transform CategoryParrent, string table, int CategoryNumber, Sprite CategorySprite)
  137. {
  138. if (polaczenie.State == System.Data.ConnectionState.Closed)
  139. {
  140. polaczenie.Open();
  141. polecenie = "select * from " + table + " order by ID";
  142. komenda = new MySqlCommand(polecenie, polaczenie);
  143. komenda.ExecuteNonQuery();
  144. czytnik = komenda.ExecuteReader();
  145. int IdeaNumber = 0;
  146. while (czytnik.Read())
  147. {
  148. IdeaNumber++;
  149.  
  150. //PrefabIdeaInCategories
  151. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ID = int.Parse(czytnik["ID"].ToString()); //ID
  152. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().CategoryNumber = CategoryNumber; //Category Number
  153. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().TextNumber.text = IdeaNumber.ToString() + ".";
  154. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().Title = czytnik["Title"].ToString(); //Title
  155. Array.Resize(ref PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ContentPL, 9);
  156. Array.Resize(ref PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ContentENG, 9);
  157. for (int i = 0; i <= 8; i++)
  158. {
  159. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ContentPL[i] = czytnik["ContentPL" + (i + 1)].ToString(); //ContentPL
  160. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ContentENG[i] = czytnik["ContentENG" + (i + 1)].ToString(); //ContentENG
  161. }
  162. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().PictureUrl = czytnik["Picture"].ToString(); //Picture
  163. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().Link = czytnik["Link"].ToString();
  164. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().Likes = czytnik["Likes"].ToString();
  165. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().Comments = czytnik["Comments"].ToString();
  166. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().views = czytnik["Views"].ToString();
  167. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().CategorySprite = CategorySprite;
  168. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().IdeaContent = IdeaContent;
  169. PrefabIdeaInCategories.GetComponent<IdeaButtonName>().DownloadIdeasScript = this.gameObject;
  170. Instantiate(PrefabIdeaInCategories, CategoryParrent);
  171. //PrefabIdeaInCategories
  172.  
  173.  
  174. //PrefabInSearcher
  175. PrefabInSearcher.GetComponent<IdeaButtonName>().ID = int.Parse(czytnik["ID"].ToString()); //ID
  176. PrefabInSearcher.GetComponent<IdeaButtonName>().CategoryNumber = CategoryNumber; //Category Number
  177.  
  178. PrefabInSearcher.GetComponent<IdeaButtonName>().Title = czytnik["Title"].ToString(); //Title
  179. Array.Resize(ref PrefabInSearcher.GetComponent<IdeaButtonName>().ContentPL, 9);
  180. Array.Resize(ref PrefabInSearcher.GetComponent<IdeaButtonName>().ContentENG, 9);
  181. for (int i = 0; i <= 8; i++)
  182. {
  183. PrefabInSearcher.GetComponent<IdeaButtonName>().ContentPL[i] = czytnik["ContentPL" + (i + 1)].ToString(); //ContentPL
  184. PrefabInSearcher.GetComponent<IdeaButtonName>().ContentENG[i] = czytnik["ContentENG" + (i + 1)].ToString(); //ContentENG
  185. }
  186. PrefabInSearcher.GetComponent<IdeaButtonName>().PictureUrl = czytnik["Picture"].ToString();
  187. PrefabInSearcher.GetComponent<IdeaButtonName>().Link = czytnik["Link"].ToString();
  188. PrefabInSearcher.GetComponent<IdeaButtonName>().Likes = czytnik["Likes"].ToString();
  189. PrefabInSearcher.GetComponent<IdeaButtonName>().Comments = czytnik["Comments"].ToString();
  190. PrefabInSearcher.GetComponent<IdeaButtonName>().views = czytnik["Views"].ToString();
  191. PrefabInSearcher.GetComponent<IdeaButtonName>().CategorySprite = CategorySprite;
  192. PrefabInSearcher.GetComponent<IdeaButtonName>().IdeaContent = IdeaContent;
  193. PrefabInSearcher.GetComponent<IdeaButtonName>().DownloadIdeasScript = this.gameObject;
  194. Instantiate(PrefabInSearcher, SearcherParrent);
  195. // PrefabInSearcher
  196. }
  197. czytnik.Close();
  198. polaczenie.Close();
  199. polaczenie.Dispose();
  200. }
  201. PlaceHolder.text = "Wyszukaj wśród (" + SearcherParrent.childCount + ") pomysłów";
  202. }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement