Няма описание
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 9.9KB

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