Advertisement
Guest User

Untitled

a guest
Aug 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.49 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.  
  8. public class DownloadIdeas : MonoBehaviour {
  9.  
  10.     //DataBase
  11.     static MySqlConnection polaczenie = new MySqlConnection("server=skydomesoftware.cba.pl; password=xxxxxxxxxxxx; user=FridgeCook; database=skydome_software;charset=utf8");
  12.     static MySqlCommand komenda; static MySqlDataReader czytnik;
  13.     static string polecenie = "";
  14.     //DataBase
  15.  
  16.  
  17.     public GameObject PrefabIdeaInCategories;
  18.  
  19.  
  20.     public Transform[] CategoryParrents;
  21.  
  22.     private void Start()
  23.     {
  24.         MainFunction();
  25.     }
  26.  
  27.     public void MainFunction()
  28.     {
  29.         Download(CategoryParrents[0], "CLPKonwersacje", 0);
  30.         Download(CategoryParrents[1], "CLPSlownictwo", 1);
  31.         Download(CategoryParrents[2], "CLPPisanie", 2);
  32.         Download(CategoryParrents[3], "CLPPracaZTekstem", 3);
  33.         Download(CategoryParrents[4], "CLPSluchanie", 4);
  34.         Download(CategoryParrents[5], "CLPPracaZFilmem", 5);
  35.         Download(CategoryParrents[6], "CLPPracaZIlustracja", 6);
  36.         Download(CategoryParrents[7], "CLPGramatyka", 7);
  37.         Download(CategoryParrents[8], "CLPGry", 8);
  38.         Download(CategoryParrents[9], "CLPTechnologie", 9);
  39.         Download(CategoryParrents[10], "CLPFunkcjeJezykowe", 10);
  40.         Download(CategoryParrents[11], "CLPGadzety", 11);
  41.         Download(CategoryParrents[12], "CLPLodolamacze", 12);
  42.         Download(CategoryParrents[13], "CLPMetodnik", 13);
  43.     }
  44.  
  45.     public void Download(Transform CategoryParrent, string table, int CategoryNumber)
  46.     {
  47.         if (polaczenie.State == System.Data.ConnectionState.Closed) polaczenie.Open();
  48.         {
  49.             polecenie = "select * from "+ table + " order by ID";
  50.             komenda = new MySqlCommand(polecenie, polaczenie);
  51.             komenda.ExecuteNonQuery();
  52.             czytnik = komenda.ExecuteReader();
  53.             int IdeaNumber = 0;
  54.             while (czytnik.Read())
  55.             {
  56.                 IdeaNumber++;
  57.  
  58.                 //PrefabIdeaInCategories
  59.                 PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ID = int.Parse(czytnik["ID"].ToString());     //ID
  60.                 PrefabIdeaInCategories.GetComponent<IdeaButtonName>().CategoryNumber = CategoryNumber;              //Category Number
  61.                 PrefabIdeaInCategories.GetComponent<IdeaButtonName>().TextNumber.text = IdeaNumber.ToString();
  62.                 PrefabIdeaInCategories.GetComponent<IdeaButtonName>().Title = czytnik["Title"].ToString();          //Title
  63.                 Array.Resize(ref PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ContentPL, 9);
  64.                 Array.Resize(ref PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ContentENG, 9);
  65.                 for (int i = 0; i <= 8; i++)
  66.                 {
  67.                     PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ContentPL[i] = czytnik["ContentPL"+(i+1)].ToString();       //ContentPL
  68.                     PrefabIdeaInCategories.GetComponent<IdeaButtonName>().ContentENG[i] = czytnik["ContentENG" + (i+1)].ToString();   //ContentENG
  69.                 }
  70.                 PrefabIdeaInCategories.GetComponent<IdeaButtonName>().PictureUrl = czytnik["Picture"].ToString();                     //Picture
  71.                 Instantiate(PrefabIdeaInCategories, CategoryParrent);
  72.                 //PrefabIdeaInCategories
  73.             }
  74.             czytnik.Close();
  75.             polaczenie.Close();
  76.            
  77.         }
  78.     }  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement