Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

車輛紀錄.cs 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. using UnityEngine.Networking;
  7. using UnityEngine.EventSystems;
  8. using System.Text.RegularExpressions;
  9. using System.Data.SqlClient;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using TMPro;
  13. using System;
  14. using System.IO;
  15. using ZXing;
  16. using ZXing.QrCode;
  17. using System.Net;
  18. using System.Data;
  19. using SimpleJSON;
  20. using System.Linq;
  21. using System.ComponentModel;
  22. using System.Runtime.InteropServices;
  23. using System.Globalization;
  24. using XCharts.Runtime;
  25. public class 車輛紀錄 : MonoBehaviour
  26. {
  27. [SerializeField] TextMeshProUGUI 姓名;
  28. [SerializeField] TextMeshProUGUI 車號;
  29. [SerializeField] GameObject 選擇面板;
  30. [SerializeField] TMP_InputField 關鍵字;
  31. private JSONArray newjson;
  32. public GameObject buttonPrefab;
  33. public Transform buttonParent;
  34. public GameObject buttonceneter;
  35. private List<GameObject> copy = new List<GameObject>();
  36. public GameObject buttonPrefab1;
  37. public Transform buttonParent1;
  38. public GameObject buttonceneter1;
  39. private List<GameObject> copy1 = new List<GameObject>();
  40. public CanvasScaler canvasScaler;
  41. [SerializeField] GameObject 讀取面板;
  42. [SerializeField] TextMeshProUGUI 讀取;
  43. [SerializeField] GameObject 彈跳面板;
  44. [SerializeField] TextMeshProUGUI 彈跳文字;
  45. private string loadingText = "";
  46. private int dotCount = 0;
  47. // Start is called before the first frame update
  48. void Start()
  49. {
  50. Screen.autorotateToPortrait = false;
  51. Screen.orientation = ScreenOrientation.Portrait;
  52. float rate = 1000.0f / 1600.0f;
  53. if (canvasScaler == null)
  54. {
  55. canvasScaler = GetComponent<CanvasScaler>();
  56. }
  57. if (Main.Global.rate>rate)
  58. {
  59. canvasScaler.matchWidthOrHeight = 1f;
  60. }
  61. else
  62. {
  63. canvasScaler.matchWidthOrHeight = 0f;
  64. }
  65. StartCoroutine(AnimateText());
  66. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/GF_main.php?";
  67. //Main.Global.預設伺服器路徑="GF01";
  68. 選擇面板.SetActive(true);
  69. }
  70. IEnumerator 客戶搜尋()
  71. {
  72. 讀取面板.SetActive(true);
  73. if (copy != null)
  74. {
  75. DeletetextCopy();
  76. }
  77. string strcon = "客戶搜尋";
  78. string se = Main.Global.預設伺服器路徑;
  79. string pa1 = 關鍵字.text;
  80. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se, pa1);
  81. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  82. yield return request.SendWebRequest();
  83. if (request.result == UnityWebRequest.Result.ConnectionError)
  84. {
  85. Debug.Log(request.error);
  86. yield break;
  87. }
  88. JSONNode json = JSON.Parse(request.downloadHandler.text);
  89. int sum = 2;
  90. for (int i = 0; i < json.Count; i++)
  91. {
  92. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  93. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  94. buttonObj.transform.SetParent(buttonParent, false);
  95. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  96. Button bt = buttonObj.GetComponentInChildren<Button>();
  97. int index = i;
  98. bt.onClick.AddListener(() =>
  99. {
  100. 關鍵字.text="";
  101. 姓名.text=json[index][1].ToString().Trim('"');
  102. 車號.text=json[index][3].ToString().Trim('"');
  103. StartCoroutine(單號搜尋());
  104. 選擇面板.SetActive(false);
  105. });
  106. text[0].text =json[i][1].ToString().Trim('"');
  107. text[1].text =json[i][3].ToString().Trim('"');
  108. sum+=75;
  109. copy.Add(buttonObj);
  110. }
  111. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  112. 讀取面板.SetActive(false);
  113. }
  114. public void 搜尋()
  115. {
  116. StartCoroutine(客戶搜尋());
  117. }
  118. IEnumerator 單號搜尋()
  119. {
  120. 讀取面板.SetActive(true);
  121. if (copy1 != null)
  122. {
  123. DeletetextCopy1();
  124. }
  125. string strcon = "單號搜尋";
  126. string se = Main.Global.預設伺服器路徑;
  127. string pa1 = 姓名.text;
  128. string pa2 = 車號.text;
  129. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}", strcon, se, pa1, pa2);
  130. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  131. yield return request.SendWebRequest();
  132. if (request.result == UnityWebRequest.Result.ConnectionError)
  133. {
  134. Debug.Log(request.error);
  135. yield break;
  136. }
  137. JSONNode json = JSON.Parse(request.downloadHandler.text);
  138. newjson = new JSONArray();
  139. for (int i = 0; i < json.Count; i++)
  140. {
  141. string str = json[i][0].ToString().Trim('"');
  142. yield return StartCoroutine(明細搜尋(str));
  143. }
  144. int sum = 2;
  145. string asd = newjson[0][0].ToString().Trim('"');
  146. int j = 0;
  147. for (int i = 0; i < newjson.Count; i++)
  148. {
  149. GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
  150. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  151. buttonObj.transform.SetParent(buttonParent1, false);
  152. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  153. Image[] childImages = buttonObj.GetComponentsInChildren<Image>();
  154. if (i < newjson.Count - 1 && asd != newjson[i+1][0].ToString().Trim('"'))
  155. {
  156. asd = newjson[i+1][0].ToString().Trim('"');
  157. }
  158. else
  159. {
  160. childImages[5].gameObject.SetActive(false);
  161. }
  162. text[0].text =(i+1).ToString();
  163. string str = newjson[i][0].ToString().Trim('"');
  164. text[1].text=str.Substring(3, 8);
  165. text[2].text =newjson[i][1].ToString().Trim('"').Replace("\\\\", "\\");
  166. text[3].text =newjson[i][2].ToString().Trim('"');
  167. sum+=75;
  168. copy1.Add(buttonObj);
  169. }
  170. buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
  171. 讀取面板.SetActive(false);
  172. }
  173. IEnumerator 明細搜尋(string str)
  174. {
  175. string strcon = "明細搜尋";
  176. string se = Main.Global.預設伺服器路徑;
  177. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se, str);
  178. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  179. yield return request.SendWebRequest();
  180. if (request.result == UnityWebRequest.Result.ConnectionError)
  181. {
  182. Debug.Log(request.error);
  183. yield break;
  184. }
  185. JSONNode json = JSON.Parse(request.downloadHandler.text);
  186. for (int i = 0; i < json.Count; i++)
  187. {
  188. JSONNode newValue = new JSONObject();
  189. newValue["單號"] = json[i][0].ToString().Trim('"');
  190. newValue["細項"] = json[i][2].ToString().Trim('"').Replace("\\\\", "\\");
  191. newValue["數量"] = json[i][3].ToString().Trim('"');
  192. newjson.Add(newValue);
  193. }
  194. }
  195. public void 清單()
  196. {
  197. 選擇面板.SetActive(true);
  198. }
  199. public void DeletetextCopy()
  200. {
  201. foreach (GameObject i in copy)
  202. {
  203. Destroy(i);
  204. }
  205. copy.Clear();
  206. }
  207. public void DeletetextCopy1()
  208. {
  209. foreach (GameObject i in copy1)
  210. {
  211. Destroy(i);
  212. }
  213. copy1.Clear();
  214. }
  215. IEnumerator AnimateText()
  216. {
  217. string qqq = 讀取.text.ToString();
  218. while (true)
  219. {
  220. yield return new WaitForSeconds(0.5f);
  221. if (dotCount < 3)
  222. {
  223. loadingText += ".";
  224. dotCount++;
  225. }
  226. else
  227. {
  228. loadingText = "";
  229. dotCount = 0;
  230. }
  231. 讀取.text = qqq+loadingText;
  232. }
  233. }
  234. public void exit()
  235. {
  236. change_Secen(1);
  237. }
  238. public void change_Secen(int _screenNum)
  239. {
  240. //Main.Global.判斷是否第一次=true;
  241. SceneManager.LoadScene(_screenNum);
  242. }
  243. }