Ei kuvausta
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 13KB

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