Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

庫存盤營盤損.cs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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 UnityEngine.EventSystems;
  8. using System.Text.RegularExpressions;
  9. using System.Data.SqlClient;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using TMPro;
  13. using System;
  14. using System.IO;
  15. using ZXing;
  16. using ZXing.QrCode;
  17. using System.Net;
  18. using System.Data;
  19. using SimpleJSON;
  20. using System.Linq;
  21. using System.ComponentModel;
  22. using System.Runtime.InteropServices;
  23. using System.Globalization;
  24. using XCharts.Runtime;
  25. public class 庫存盤營盤損 : MonoBehaviour
  26. {
  27. [SerializeField] Toggle 非零切換;
  28. [SerializeField] Toggle 零切換;
  29. [SerializeField] GameObject 非零清單面板;
  30. [SerializeField] GameObject 零清單面板;
  31. private JSONNode 非零清單;
  32. private JSONNode 零清單;
  33. private JSONNode 非零清單計算;
  34. private JSONNode 零清單計算;
  35. public GameObject buttonPrefab;
  36. public Transform buttonParent;
  37. public GameObject buttonceneter;
  38. private List<GameObject> copy = new List<GameObject>();
  39. public GameObject buttonPrefab1;
  40. public Transform buttonParent1;
  41. public GameObject buttonceneter1;
  42. private List<GameObject> copy1 = new List<GameObject>();
  43. public CanvasScaler canvasScaler;
  44. [SerializeField] GameObject 讀取面板;
  45. [SerializeField] TextMeshProUGUI 讀取;
  46. [SerializeField] GameObject 彈跳面板;
  47. [SerializeField] TextMeshProUGUI 彈跳文字;
  48. private string loadingText = "";
  49. private int dotCount = 0;
  50. private int itemsPerPage = 17;
  51. private int currentPage = 0;
  52. private int currentPage1 = 0;
  53. // Start is called before the first frame update
  54. void Start()
  55. {
  56. Screen.autorotateToPortrait = false;
  57. Screen.orientation = ScreenOrientation.Portrait;
  58. float rate = 1000.0f / 1600.0f;
  59. if (canvasScaler == null)
  60. {
  61. canvasScaler = GetComponent<CanvasScaler>();
  62. }
  63. if (Main.Global.rate>rate)
  64. {
  65. canvasScaler.matchWidthOrHeight = 1f;
  66. }
  67. else
  68. {
  69. canvasScaler.matchWidthOrHeight = 0f;
  70. }
  71. StartCoroutine(AnimateText());
  72. //Main.Global.人員="李協叡";
  73. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/GF_main.php?";
  74. //Main.Global.預設伺服器路徑="GF99";
  75. 非零切換.isOn = true;
  76. 零切換.isOn = false;
  77. 非零清單面板.SetActive(true);
  78. 零清單面板.SetActive(false);
  79. StartCoroutine(庫存盤營盤損1());
  80. }
  81. public void 非零_click()
  82. {
  83. if (非零切換.isOn==false && 零切換.isOn==false)
  84. {
  85. 非零切換.isOn = true;
  86. 零切換.isOn = false;
  87. }
  88. else if (非零切換.isOn==true && 零切換.isOn==true)
  89. {
  90. 非零切換.isOn = true;
  91. 零切換.isOn = false;
  92. 非零清單面板.SetActive(true);
  93. 零清單面板.SetActive(false);
  94. }
  95. }
  96. public void 零_click()
  97. {
  98. if (非零切換.isOn==false && 零切換.isOn==false)
  99. {
  100. 非零切換.isOn = false;
  101. 零切換.isOn = true;
  102. }
  103. else if (非零切換.isOn==true && 零切換.isOn==true)
  104. {
  105. 非零切換.isOn = false;
  106. 零切換.isOn = true;
  107. 非零清單面板.SetActive(false);
  108. 零清單面板.SetActive(true);
  109. }
  110. }
  111. IEnumerator AnimateText()
  112. {
  113. string qqq = 讀取.text.ToString();
  114. while (true)
  115. {
  116. yield return new WaitForSeconds(0.5f);
  117. if (dotCount < 3)
  118. {
  119. loadingText += ".";
  120. dotCount++;
  121. }
  122. else
  123. {
  124. loadingText = "";
  125. dotCount = 0;
  126. }
  127. 讀取.text = qqq+loadingText;
  128. }
  129. }
  130. IEnumerator 庫存盤營盤損1()
  131. {
  132. 讀取面板.SetActive(true);
  133. string strcon = "庫存盤營盤損";
  134. string se = Main.Global.預設伺服器路徑;
  135. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  136. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  137. yield return request.SendWebRequest();
  138. if (request.result == UnityWebRequest.Result.ConnectionError)
  139. {
  140. Debug.Log(request.error);
  141. yield break;
  142. }
  143. 非零清單 = JSON.Parse(request.downloadHandler.text);
  144. 非零清單計算 = JSON.Parse(request.downloadHandler.text);
  145. yield return StartCoroutine(庫存盤營盤損2());
  146. }
  147. IEnumerator 庫存盤營盤損2()
  148. {
  149. string strcon = "庫存盤營盤損1";
  150. string se = Main.Global.預設伺服器路徑;
  151. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  152. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  153. yield return request.SendWebRequest();
  154. if (request.result == UnityWebRequest.Result.ConnectionError)
  155. {
  156. Debug.Log(request.error);
  157. yield break;
  158. }
  159. 零清單 = JSON.Parse(request.downloadHandler.text);
  160. 零清單計算 = JSON.Parse(request.downloadHandler.text);
  161. 非零();
  162. 零();
  163. 讀取面板.SetActive(false);
  164. }
  165. private void 非零()
  166. {
  167. if (copy != null)
  168. {
  169. DeleteCopies(copy);
  170. }
  171. int startIndex = currentPage * itemsPerPage;
  172. int endIndex = Mathf.Min((currentPage + 1) * itemsPerPage, 非零清單.Count);
  173. int sum = 2;
  174. for (int i = startIndex; i < endIndex; i++)
  175. {
  176. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  177. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  178. buttonObj.transform.SetParent(buttonParent, false);
  179. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  180. TMP_InputField text1 = buttonObj.GetComponentInChildren<TMP_InputField>();
  181. Button[] bt = buttonObj.GetComponentsInChildren<Button>();
  182. int index = i;
  183. text1.onValueChanged.AddListener((newValue) =>
  184. {
  185. if (string.IsNullOrEmpty(newValue))
  186. {
  187. text1.text = "0";
  188. }
  189. 非零清單[index][4] = newValue.ToString();
  190. });
  191. bt[0].onClick.AddListener(() =>
  192. {
  193. int intValue;
  194. if (int.TryParse(text1.text, out intValue) && intValue >= 0)
  195. {
  196. text1.text = (intValue + 1).ToString();
  197. }
  198. });
  199. bt[1].onClick.AddListener(() =>
  200. {
  201. int intValue;
  202. if (int.TryParse(text1.text, out intValue) && intValue > 0)
  203. {
  204. text1.text = (intValue - 1).ToString();
  205. }
  206. });
  207. text[0].text =非零清單[i][1].ToString().Trim('"');
  208. text[1].text =非零清單[i][2].ToString().Trim('"');
  209. text[2].text =非零清單[i][3].ToString().Trim('"');
  210. text1.text =非零清單[i][4].ToString().Trim('"');
  211. sum+=75;
  212. copy.Add(buttonObj);
  213. }
  214. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  215. }
  216. private void 零()
  217. {
  218. if (copy1 != null)
  219. {
  220. DeleteCopies(copy1);
  221. }
  222. int startIndex = currentPage1 * itemsPerPage;
  223. int endIndex = Mathf.Min((currentPage1 + 1) * itemsPerPage, 零清單.Count);
  224. int sum = 2;
  225. for (int i = startIndex; i < endIndex; i++)
  226. {
  227. GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
  228. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  229. buttonObj.transform.SetParent(buttonParent1, false);
  230. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  231. TMP_InputField text1 = buttonObj.GetComponentInChildren<TMP_InputField>();
  232. Button[] bt = buttonObj.GetComponentsInChildren<Button>();
  233. int index = i;
  234. text1.onValueChanged.AddListener((newValue) =>
  235. {
  236. if (string.IsNullOrEmpty(newValue))
  237. {
  238. text1.text = "0";
  239. }
  240. 零清單[index][4] = newValue.ToString();
  241. });
  242. bt[0].onClick.AddListener(() =>
  243. {
  244. int intValue;
  245. if (int.TryParse(text1.text, out intValue) && intValue >= 0)
  246. {
  247. text1.text = (intValue + 1).ToString();
  248. }
  249. });
  250. bt[1].onClick.AddListener(() =>
  251. {
  252. int intValue;
  253. if (int.TryParse(text1.text, out intValue) && intValue > 0)
  254. {
  255. text1.text = (intValue - 1).ToString();
  256. }
  257. });
  258. text[0].text =零清單[i][1].ToString().Trim('"');
  259. text[1].text =零清單[i][2].ToString().Trim('"');
  260. text[2].text =零清單[i][3].ToString().Trim('"');
  261. text1.text =零清單[i][4].ToString().Trim('"');
  262. sum+=75;
  263. copy1.Add(buttonObj);
  264. }
  265. buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
  266. }
  267. public void 下一頁()
  268. {
  269. if (非零切換.isOn=true && 零切換.isOn==false)
  270. {
  271. ChangePage(1);
  272. }
  273. else
  274. {
  275. ChangePage1(1);
  276. }
  277. }
  278. public void 上一頁()
  279. {
  280. if (非零切換.isOn=true && 零切換.isOn==false)
  281. {
  282. ChangePage(-1);
  283. }
  284. else
  285. {
  286. ChangePage1(-1);
  287. }
  288. }
  289. private void ChangePage(int offset)
  290. {
  291. currentPage = Mathf.Clamp(currentPage + offset, 0, Mathf.CeilToInt((float)非零清單.Count / itemsPerPage) - 1);
  292. // 调用刷新页面的方法
  293. 非零();
  294. }
  295. private void ChangePage1(int offset)
  296. {
  297. currentPage1 = Mathf.Clamp(currentPage1 + offset, 0, Mathf.CeilToInt((float)零清單.Count / itemsPerPage) - 1);
  298. // 调用刷新页面的方法
  299. 零();
  300. }
  301. public void 存檔()
  302. {
  303. 彈跳面板.SetActive(true);
  304. 彈跳文字.text = "儲存完成!!";
  305. 讀取面板.SetActive(true);
  306. StartCoroutine(存檔流程());
  307. }
  308. IEnumerator 存檔流程()
  309. {
  310. for (int i = 0; i < 非零清單.Count; i++)
  311. {
  312. double str = double.Parse(非零清單[i][4]);
  313. double str1 = double.Parse(非零清單計算[i][4]);
  314. double sum = 0;
  315. if (str != str1)
  316. {
  317. if (str >str1)
  318. {
  319. sum = str - str1;
  320. string aa = 非零清單[i][0].ToString().Trim('"');
  321. yield return StartCoroutine(倉儲明細表流水號查詢(aa,sum.ToString(),"0","盤營入庫"));
  322. }
  323. else
  324. {
  325. sum = str1 - str;
  326. string aa = 非零清單[i][0].ToString().Trim('"');
  327. yield return StartCoroutine(倉儲明細表流水號查詢(aa, "0", sum.ToString(), "盤損出庫"));
  328. }
  329. }
  330. }
  331. for (int j = 0; j < 零清單.Count; j++)
  332. {
  333. double str = double.Parse(零清單[j][4]);
  334. double str1 = double.Parse(零清單計算[j][4]);
  335. double sum = 0;
  336. if (str != str1)
  337. {
  338. if (str >str1)
  339. {
  340. sum = str - str1;
  341. string aa = 零清單[j][0].ToString().Trim('"');
  342. yield return StartCoroutine(倉儲明細表流水號查詢(aa, sum.ToString(), "0", "盤營入庫"));
  343. }
  344. else
  345. {
  346. sum = str1 - str;
  347. string aa = 零清單[j][0].ToString().Trim('"');
  348. yield return StartCoroutine(倉儲明細表流水號查詢(aa, "0", sum.ToString(), "盤損出庫"));
  349. }
  350. }
  351. }
  352. 非零切換.isOn = true;
  353. 零切換.isOn = false;
  354. 非零清單面板.SetActive(true);
  355. 零清單面板.SetActive(false);
  356. currentPage = 0;
  357. currentPage1 = 0;
  358. yield return StartCoroutine(庫存盤營盤損1());
  359. }
  360. IEnumerator 倉儲明細表流水號查詢(string 料號 , string 入庫, string 出庫, string 狀態)
  361. {
  362. string strcon = "倉儲明細表流水號查詢";
  363. string se = Main.Global.預設伺服器路徑;
  364. DateTime currentDate = DateTime.Now;
  365. string pa1 = currentDate.ToString("yyyyMMdd");
  366. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se, pa1);
  367. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  368. yield return request.SendWebRequest();
  369. if (request.result == UnityWebRequest.Result.ConnectionError)
  370. {
  371. Debug.Log(request.error);
  372. yield break;
  373. }
  374. string str = request.downloadHandler.text.ToString();
  375. string 流水;
  376. if (str == "n")
  377. {
  378. 流水="Z"+currentDate.ToString("yyyyMMdd") +"000";
  379. }
  380. else
  381. {
  382. int NUM1 = int.Parse(str.Substring(str.Length - 3)) + 1;
  383. 流水 = "Z"+currentDate.ToString("yyyyMMdd") + NUM1.ToString().PadLeft(3, '0');
  384. }
  385. yield return StartCoroutine(倉儲明細表盤營盤損(流水, 料號, 入庫, 出庫, 狀態));
  386. }
  387. IEnumerator 倉儲明細表盤營盤損(string 流水號 , string 料號, string 入庫, string 出庫, string 狀態)
  388. {
  389. string strcon = "倉儲明細表盤營盤損";
  390. string se = Main.Global.預設伺服器路徑;
  391. DateTime currentDate = DateTime.Now;
  392. string pa1 = 流水號;
  393. string pa2 = Main.Global.人員;
  394. string pa3 = currentDate.ToString("yyyy/MM/dd");
  395. string pa4 = 料號;
  396. string pa5 = 入庫;
  397. string pa6 = 出庫;
  398. string pa7 = 狀態;
  399. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}&PA3={4}&PA4={5}&PA5={6}&PA6={7}&PA7={8}", strcon, se, pa1, pa2, pa3, pa4, pa5, pa6, pa7);
  400. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  401. yield return request.SendWebRequest();
  402. if (request.result == UnityWebRequest.Result.ConnectionError)
  403. {
  404. Debug.Log(request.error);
  405. yield break;
  406. }
  407. }
  408. public void 彈跳面板關閉()
  409. {
  410. 彈跳面板.SetActive(false);
  411. 彈跳文字.text = "";
  412. }
  413. private void DeleteCopies(List<GameObject> copyList)
  414. {
  415. foreach (GameObject copy in copyList)
  416. {
  417. Destroy(copy);
  418. }
  419. copyList.Clear();
  420. }
  421. public void exit()
  422. {
  423. change_Secen(1);
  424. }
  425. public void change_Secen(int _screenNum)
  426. {
  427. //Main.Global.判斷是否第一次=true;
  428. SceneManager.LoadScene(_screenNum);
  429. }
  430. }