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 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. public TMP_Dropdown 年下拉;
  36. public TMP_Dropdown 月下拉;
  37. [SerializeField] TextMeshProUGUI 標題;
  38. // Start is called before the first frame update
  39. void Start()
  40. {
  41. Screen.autorotateToPortrait = false;
  42. Screen.orientation = ScreenOrientation.LandscapeLeft;
  43. float rate = 900.0f / 1900.0f;
  44. if (Main.Global.rate<rate)
  45. {
  46. canvasScaler.matchWidthOrHeight = 1f;
  47. }
  48. else
  49. {
  50. canvasScaler.matchWidthOrHeight = 0f;
  51. }
  52. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/shto_main.php?";
  53. //Main.Global.預設伺服器路徑="official";
  54. StartCoroutine(AnimateText());
  55. 讀取面板.SetActive(true);
  56. DateTime currentDate = DateTime.Now;
  57. 年下拉.value = currentDate.Year - 2023;
  58. 月下拉.value = currentDate.Month - 1;
  59. 年下拉.onValueChanged.AddListener(年份改變);
  60. 月下拉.onValueChanged.AddListener(月份改變);
  61. StartCoroutine(出貨日報表清單(currentDate.Year.ToString(), currentDate.Month.ToString()));
  62. }
  63. IEnumerator AnimateText()
  64. {
  65. string qqq = 讀取.text.ToString();
  66. while (true)
  67. {
  68. yield return new WaitForSeconds(0.5f);
  69. if (dotCount < 3)
  70. {
  71. loadingText += ".";
  72. dotCount++;
  73. }
  74. else
  75. {
  76. loadingText = "";
  77. dotCount = 0;
  78. }
  79. 讀取.text = qqq+loadingText;
  80. }
  81. }
  82. IEnumerator 出貨日報表清單(string pa, string pa1)
  83. {
  84. if (copy != null)
  85. {
  86. DeletetextCopies();
  87. }
  88. string strcon = "出貨日報表清單";
  89. string se = Main.Global.預設伺服器路徑;
  90. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  91. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  92. yield return request.SendWebRequest();
  93. if (request.result == UnityWebRequest.Result.ConnectionError)
  94. {
  95. Debug.Log(request.error);
  96. yield break;
  97. }
  98. JSONNode json = JSON.Parse(request.downloadHandler.text);
  99. int sum = 3;
  100. for (int i = 0; i < json.Count; i++)
  101. {
  102. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  103. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(3, -sum);
  104. buttonObj.transform.SetParent(buttonParent, false);
  105. TextMeshProUGUI text = buttonObj.GetComponentInChildren<TextMeshProUGUI>();
  106. Button bt = buttonObj.GetComponentInChildren<Button>();
  107. int index = i;
  108. bt.onClick.AddListener(() =>
  109. {
  110. string str = json[index][1].ToString().Trim('"');
  111. StartCoroutine(出貨日報表明細(str));
  112. DateTime date = DateTime.ParseExact(str, "yyyy/MM/dd", null);
  113. DayOfWeek dayOfWeek = date.DayOfWeek;
  114. string weekdayString = dayOfWeek.ToString();
  115. string week = "";
  116. if (weekdayString =="Monday")
  117. {
  118. week="一";
  119. }
  120. else if (weekdayString =="Tuesday")
  121. {
  122. week="二";
  123. }
  124. else if (weekdayString =="Wednesday")
  125. {
  126. week="三";
  127. }
  128. else if (weekdayString =="Thursday")
  129. {
  130. week="四";
  131. }
  132. else if (weekdayString =="Friday")
  133. {
  134. week="五";
  135. }
  136. else if (weekdayString =="Saturday")
  137. {
  138. week="六";
  139. }
  140. else if (weekdayString =="Sunday")
  141. {
  142. week="天";
  143. }
  144. 標題.text=str+"-星期"+week;
  145. });
  146. text.text = json[i][1].ToString().Trim('"');
  147. sum+=75;
  148. copy.Add(buttonObj);
  149. }
  150. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  151. 讀取面板.SetActive(false);
  152. }
  153. public void 年份改變(int value)
  154. {
  155. 讀取面板.SetActive(true);
  156. int a = value + 2023;
  157. int b = 月下拉.value + 1;
  158. StartCoroutine(出貨日報表清單(a.ToString(), b.ToString()));
  159. 標題.text="";
  160. if (copy1 != null)
  161. {
  162. DeletetextCopies1();
  163. }
  164. }
  165. private void 月份改變(int value)
  166. {
  167. 讀取面板.SetActive(true);
  168. int a = 年下拉.value + 2023;
  169. int b = value + 1;
  170. StartCoroutine(出貨日報表清單(a.ToString(), b.ToString()));
  171. 標題.text="";
  172. if (copy1 != null)
  173. {
  174. DeletetextCopies1();
  175. }
  176. }
  177. IEnumerator 出貨日報表明細(string pa)
  178. {
  179. 讀取面板.SetActive(true);
  180. if (copy1 != null)
  181. {
  182. DeletetextCopies1();
  183. }
  184. string strcon = "出貨日報表明細";
  185. string se = Main.Global.預設伺服器路徑;
  186. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA2={2}", strcon, se, pa);
  187. Debug.Log(strUrl);
  188. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  189. yield return request.SendWebRequest();
  190. if (request.result == UnityWebRequest.Result.ConnectionError)
  191. {
  192. Debug.Log(request.error);
  193. yield break;
  194. }
  195. JSONNode json = JSON.Parse(request.downloadHandler.text);
  196. Debug.Log(json);
  197. int sum = 3;
  198. for (int i = 0; i < json.Count; i++)
  199. {
  200. GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
  201. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(3, -sum);
  202. buttonObj.transform.SetParent(buttonParent1, false);
  203. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  204. text[0].text = (i+1).ToString();
  205. text[1].text = json[i][1].ToString().Trim('"');
  206. text[2].text = json[i][2].ToString().Trim('"');
  207. text[3].text = json[i][3].ToString().Trim('"');
  208. sum+=80;
  209. copy1.Add(buttonObj);
  210. }
  211. buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
  212. 讀取面板.SetActive(false);
  213. }
  214. public void DeletetextCopies()
  215. {
  216. // 刪除複製出來的物件
  217. foreach (GameObject copy in copy)
  218. {
  219. Destroy(copy);
  220. }
  221. copy.Clear();
  222. }
  223. public void DeletetextCopies1()
  224. {
  225. // 刪除複製出來的物件
  226. foreach (GameObject copy in copy1)
  227. {
  228. Destroy(copy);
  229. }
  230. copy1.Clear();
  231. }
  232. public void back()
  233. {
  234. change_Secen(12);
  235. }
  236. public void change_Secen(int _screenNum)
  237. {
  238. SceneManager.LoadScene(_screenNum);
  239. }
  240. }