No Description
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 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 System.Text.RegularExpressions;
  8. using System.Data.SqlClient;
  9. using TMPro;
  10. using System;
  11. using System.IO;
  12. using ZXing;
  13. using ZXing.QrCode;
  14. using System.Net;
  15. using SimpleJSON;
  16. using System.ComponentModel;
  17. using System.Runtime.InteropServices;
  18. public class 庫存表 : MonoBehaviour
  19. {
  20. public CanvasScaler canvasScaler;
  21. float screenWidth;
  22. float screenHeight;
  23. private string loadingText = "";
  24. private int dotCount = 0;
  25. public GameObject buttonPrefab;
  26. public Transform buttonParent;
  27. public GameObject buttonceneter;
  28. private List<GameObject> copy = new List<GameObject>();
  29. public GameObject buttonPrefab1;
  30. public Transform buttonParent1;
  31. public GameObject buttonceneter1;
  32. private List<GameObject> copy1 = new List<GameObject>();
  33. [SerializeField] GameObject 讀取面板;
  34. [SerializeField] TextMeshProUGUI 讀取;
  35. [SerializeField] TMP_InputField 關鍵字;
  36. // Start is called before the first frame update
  37. void Start()
  38. {
  39. Screen.autorotateToPortrait = false;
  40. Screen.orientation = ScreenOrientation.Portrait;
  41. float rate = 900.0f / 1900.0f;
  42. if (canvasScaler == null)
  43. {
  44. canvasScaler = GetComponent<CanvasScaler>();
  45. }
  46. if (Main.Global.rate>rate)
  47. {
  48. canvasScaler.matchWidthOrHeight = 1f;
  49. }
  50. else
  51. {
  52. canvasScaler.matchWidthOrHeight = 0f;
  53. }
  54. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/shto_main.php?";
  55. //Main.Global.預設伺服器路徑="official";
  56. StartCoroutine(AnimateText());
  57. 讀取面板.SetActive(true);
  58. 關鍵字.text="";
  59. 搜尋();
  60. }
  61. IEnumerator AnimateText()
  62. {
  63. string qqq = 讀取.text.ToString();
  64. while (true)
  65. {
  66. yield return new WaitForSeconds(0.5f);
  67. if (dotCount < 3)
  68. {
  69. loadingText += ".";
  70. dotCount++;
  71. }
  72. else
  73. {
  74. loadingText = "";
  75. dotCount = 0;
  76. }
  77. 讀取.text = qqq+loadingText;
  78. }
  79. }
  80. IEnumerator 庫存明細表()
  81. {
  82. if (copy != null)
  83. {
  84. DeletetextCopies();
  85. }
  86. string strcon = "庫存明細表";
  87. string se = Main.Global.預設伺服器路徑;
  88. string pa1 = 關鍵字.text;
  89. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se,pa1);
  90. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  91. yield return request.SendWebRequest();
  92. if (request.result == UnityWebRequest.Result.ConnectionError)
  93. {
  94. Debug.Log(request.error);
  95. yield break;
  96. }
  97. JSONNode json = JSON.Parse(request.downloadHandler.text);
  98. GameObject selectedButton = null;
  99. int sum = 0;
  100. for (int i = 0; i < json.Count; i++)
  101. {
  102. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  103. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(5, -sum);
  104. buttonObj.transform.SetParent(buttonParent, false);
  105. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  106. Button bt = buttonObj.GetComponentInChildren<Button>();
  107. Image[] im = buttonObj.GetComponentsInChildren<Image>();
  108. int index = i;
  109. bt.onClick.AddListener(() =>
  110. {
  111. string str = json[index][3].ToString().Trim('"');
  112. StartCoroutine(庫存表物料明細(str));
  113. if (selectedButton != null)
  114. {
  115. Image[] prevButtonImages = selectedButton.GetComponentsInChildren<Image>();
  116. prevButtonImages[2].color = new Color32(255, 255, 255, 255);
  117. }
  118. // 設定當前按鈕為選中狀態
  119. im[2].color = new Color32(160, 255, 160, 255);
  120. selectedButton = buttonObj;
  121. });
  122. text[0].text = (i+1).ToString();
  123. text[1].text = json[i][1].ToString().Trim('"');
  124. text[2].text = json[i][2].ToString().Trim('"');
  125. sum+=100;
  126. copy.Add(buttonObj);
  127. }
  128. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  129. 讀取面板.SetActive(false);
  130. }
  131. IEnumerator 庫存表物料明細(string str)
  132. {
  133. if (copy1 != null)
  134. {
  135. DeletetextCopies1();
  136. }
  137. string strcon = "庫存表物料明細";
  138. string se = Main.Global.預設伺服器路徑;
  139. string pa1 = str;
  140. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se, pa1);
  141. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  142. Debug.Log(strUrl);
  143. yield return request.SendWebRequest();
  144. if (request.result == UnityWebRequest.Result.ConnectionError)
  145. {
  146. Debug.Log(request.error);
  147. yield break;
  148. }
  149. JSONNode json = JSON.Parse(request.downloadHandler.text);
  150. Debug.Log(json);
  151. GameObject selectedButton = null;
  152. int sum = 0;
  153. for (int i = 0; i < json.Count; i++)
  154. {
  155. GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
  156. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(5, -sum);
  157. buttonObj.transform.SetParent(buttonParent1, false);
  158. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  159. Button bt = buttonObj.GetComponentInChildren<Button>();
  160. Image[] im = buttonObj.GetComponentsInChildren<Image>();
  161. int index = i;
  162. text[0].text = json[i][0].ToString().Trim('"');
  163. text[1].text = json[i][1].ToString().Trim('"');
  164. text[2].text = json[i][2].ToString().Trim('"');
  165. text[3].text = json[i][3].ToString().Trim('"');
  166. text[4].text = json[i][4].ToString().Trim('"');
  167. text[5].text = json[i][5].ToString().Trim('"');
  168. sum+=100;
  169. copy1.Add(buttonObj);
  170. }
  171. buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
  172. 讀取面板.SetActive(false);
  173. }
  174. public void 搜尋()
  175. {
  176. if (copy1 != null)
  177. {
  178. DeletetextCopies1();
  179. }
  180. StartCoroutine(庫存明細表());
  181. }
  182. public void DeletetextCopies()
  183. {
  184. // 刪除複製出來的物件
  185. foreach (GameObject copy in copy)
  186. {
  187. Destroy(copy);
  188. }
  189. copy.Clear();
  190. }
  191. public void DeletetextCopies1()
  192. {
  193. // 刪除複製出來的物件
  194. foreach (GameObject copy in copy1)
  195. {
  196. Destroy(copy);
  197. }
  198. copy1.Clear();
  199. }
  200. public void back()
  201. {
  202. change_Secen(1);
  203. }
  204. public void change_Secen(int _screenNum)
  205. {
  206. SceneManager.LoadScene(_screenNum);
  207. }
  208. }