Bez popisu
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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. [SerializeField] GameObject 讀取面板;
  30. [SerializeField] TextMeshProUGUI 讀取;
  31. [SerializeField] GameObject 彈跳面板;
  32. [SerializeField] TextMeshProUGUI 彈跳文字;
  33. // Start is called before the first frame update
  34. void Start()
  35. {
  36. Screen.autorotateToPortrait = false;
  37. Screen.orientation = ScreenOrientation.LandscapeLeft;
  38. float rate = 900.0f / 1900.0f;
  39. if (Main.Global.rate<rate)
  40. {
  41. canvasScaler.matchWidthOrHeight = 1f;
  42. }
  43. else
  44. {
  45. canvasScaler.matchWidthOrHeight = 0f;
  46. }
  47. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/shto_main.php?";
  48. //Main.Global.預設伺服器路徑="official";
  49. //Main.Global.人員="王詩文";
  50. //Main.Global.部門 = "3.廠務部";
  51. StartCoroutine(AnimateText());
  52. 讀取面板.SetActive(true);
  53. StartCoroutine(出貨排程明細表());
  54. }
  55. IEnumerator AnimateText()
  56. {
  57. string qqq = 讀取.text.ToString();
  58. while (true)
  59. {
  60. yield return new WaitForSeconds(0.5f);
  61. if (dotCount < 3)
  62. {
  63. loadingText += ".";
  64. dotCount++;
  65. }
  66. else
  67. {
  68. loadingText = "";
  69. dotCount = 0;
  70. }
  71. 讀取.text = qqq+loadingText;
  72. }
  73. }
  74. IEnumerator 出貨排程明細表()
  75. {
  76. if (copy != null)
  77. {
  78. DeletetextCopies();
  79. }
  80. string strcon = "出貨排程明細表";
  81. string se = Main.Global.預設伺服器路徑;
  82. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  83. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  84. yield return request.SendWebRequest();
  85. if (request.result == UnityWebRequest.Result.ConnectionError)
  86. {
  87. Debug.Log(request.error);
  88. yield break;
  89. }
  90. JSONNode json = JSON.Parse(request.downloadHandler.text);
  91. int sum = 3;
  92. for (int i = 0; i < json.Count; i++)
  93. {
  94. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  95. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(3, -sum);
  96. buttonObj.transform.SetParent(buttonParent, false);
  97. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  98. Button bt = buttonObj.GetComponentInChildren<Button>();
  99. int index = i;
  100. bt.onClick.AddListener(() =>
  101. {
  102. string str = json[index][0].ToString().Trim('"');
  103. string str1 = json[index][4].ToString().Trim('"');
  104. if (Main.Global.部門 == "3.廠務部" || Main.Global.部門 == "0.NA")
  105. {
  106. 讀取面板.SetActive(true);
  107. StartCoroutine(出貨排程表修改(str, str1));
  108. }
  109. else
  110. {
  111. 彈跳面板.SetActive(true);
  112. 彈跳文字.text = "登入權限不足!!";
  113. }
  114. });
  115. text[0].text = json[i][2].ToString().Trim('"');
  116. text[1].text = json[i][3].ToString().Trim('"');
  117. text[2].text = json[i][4].ToString().Trim('"');
  118. sum+=80;
  119. copy.Add(buttonObj);
  120. }
  121. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  122. 讀取面板.SetActive(false);
  123. }
  124. IEnumerator 出貨排程表修改(string 流水, string 產量)
  125. {
  126. DateTime currentDate = DateTime.Now;
  127. string pa = currentDate.ToString("yyyy/MM/dd");
  128. string strcon = "出貨排程表修改";
  129. string se = Main.Global.預設伺服器路徑;
  130. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}&PA3={4}", strcon, se, pa, 產量, 流水);
  131. Debug.Log(strUrl);
  132. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  133. yield return request.SendWebRequest();
  134. if (request.result == UnityWebRequest.Result.ConnectionError)
  135. {
  136. Debug.Log(request.error);
  137. yield break;
  138. }
  139. StartCoroutine(查詢出貨控制表日期());
  140. }
  141. IEnumerator 查詢出貨控制表日期()
  142. {
  143. DateTime currentDate = DateTime.Now;
  144. string pa = currentDate.ToString("yyyy/MM/dd");
  145. string strcon = "查詢出貨控制表日期";
  146. string se = Main.Global.預設伺服器路徑;
  147. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se,pa);
  148. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  149. yield return request.SendWebRequest();
  150. if (request.result == UnityWebRequest.Result.ConnectionError)
  151. {
  152. Debug.Log(request.error);
  153. yield break;
  154. }
  155. string str = request.downloadHandler.text.ToString();
  156. Debug.Log(str);
  157. if (str == "0")
  158. {
  159. StartCoroutine(查找出貨日報最後流水號());
  160. }
  161. else
  162. {
  163. StartCoroutine(出貨排程明細表());
  164. }
  165. }
  166. IEnumerator 查找出貨日報最後流水號()
  167. {
  168. string strcon = "查找出貨日報最後流水號";
  169. string se = Main.Global.預設伺服器路徑;
  170. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  171. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  172. yield return request.SendWebRequest();
  173. if (request.result == UnityWebRequest.Result.ConnectionError)
  174. {
  175. Debug.Log(request.error);
  176. yield break;
  177. }
  178. string str = request.downloadHandler.text.ToString();
  179. Debug.Log(str);
  180. string 流水號 = "";
  181. if (str == "n")
  182. {
  183. 流水號= "PD00000000";
  184. }
  185. else
  186. {
  187. int NUM1 = int.Parse(str.Substring(8)) + 1;
  188. 流水號 = "PD" + NUM1.ToString().PadLeft(8, '0');
  189. }
  190. StartCoroutine(新增出貨日報表日期(流水號));
  191. }
  192. IEnumerator 新增出貨日報表日期(string 流水號)
  193. {
  194. string strcon = "新增出貨日報表日期";
  195. string se = Main.Global.預設伺服器路徑;
  196. DateTime currentDate = DateTime.Now;
  197. string pa = currentDate.ToString("yyyy/MM/dd");
  198. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}&PA3={4}", strcon, se,流水號,pa,Main.Global.人員);
  199. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  200. yield return request.SendWebRequest();
  201. if (request.result == UnityWebRequest.Result.ConnectionError)
  202. {
  203. Debug.Log(request.error);
  204. yield break;
  205. }
  206. StartCoroutine(出貨排程明細表());
  207. }
  208. public void DeletetextCopies()
  209. {
  210. // 刪除複製出來的物件
  211. foreach (GameObject copy in copy)
  212. {
  213. Destroy(copy);
  214. }
  215. copy.Clear();
  216. }
  217. public void 彈跳面板關閉()
  218. {
  219. 彈跳面板.SetActive(false);
  220. 彈跳文字.text = "";
  221. }
  222. public void back()
  223. {
  224. change_Secen(12);
  225. }
  226. public void change_Secen(int _screenNum)
  227. {
  228. SceneManager.LoadScene(_screenNum);
  229. }
  230. }