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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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. [SerializeField] Button 新增;
  21. [SerializeField] Button 修改;
  22. [SerializeField] Button 存檔;
  23. [SerializeField] Button 刪除;
  24. [SerializeField] Button 看明細;
  25. [SerializeField] Button 回首頁;
  26. [SerializeField] TextMeshProUGUI 備註s;
  27. [SerializeField] TextMeshProUGUI 名稱s;
  28. [SerializeField] TextMeshProUGUI 上ISO;
  29. [SerializeField] TextMeshProUGUI 下ISO;
  30. [SerializeField] TextMeshProUGUI 明細標題;
  31. [SerializeField] GameObject 頁面一;
  32. [SerializeField] GameObject 頁面二;
  33. [SerializeField] GameObject 上一頁按鈕;
  34. public TMP_Dropdown 年;
  35. public TMP_Dropdown 月;
  36. public TMP_Dropdown 日;
  37. public TMP_Dropdown 名稱;
  38. public GameObject buttonPrefab;
  39. public Transform buttonParent;
  40. public GameObject buttonceneter;
  41. private List<GameObject> copy = new List<GameObject>();
  42. public GameObject buttonPrefab1;
  43. public Transform buttonParent1;
  44. public GameObject buttonceneter1;
  45. private List<GameObject> copy1 = new List<GameObject>();
  46. public GameObject buttonPrefab2;
  47. public Transform buttonParent2;
  48. public GameObject buttonceneter2;
  49. private List<GameObject> copy2 = new List<GameObject>();
  50. public CanvasScaler canvasScaler;
  51. private string loadingText = "";
  52. private int dotCount = 0;
  53. [SerializeField] GameObject 讀取面板;
  54. [SerializeField] TextMeshProUGUI 讀取;
  55. [SerializeField] GameObject 彈跳面板;
  56. [SerializeField] TextMeshProUGUI 彈跳文字;
  57. JSONArray 點檢表;
  58. string 控制流水號 = "";
  59. string 設備流水號 = "";
  60. string 編輯模式 = "";
  61. JSONNode 檢點明細;
  62. // Start is called before the first frame update
  63. void Start()
  64. {
  65. Screen.autorotateToPortrait = false;
  66. Screen.orientation = ScreenOrientation.LandscapeLeft;
  67. float rate = 1600.0f / 1000.0f;
  68. if (Main.Global.rate>rate)
  69. {
  70. canvasScaler.matchWidthOrHeight = 1f;
  71. }
  72. else
  73. {
  74. canvasScaler.matchWidthOrHeight = 0f;
  75. }
  76. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/ow_main.php?";
  77. //Main.Global.預設伺服器路徑="test";
  78. //Main.Global.人員="李卓叡";
  79. 讀取面板.SetActive(true);
  80. StartCoroutine(AnimateText());
  81. StartCoroutine(表單ISO編碼());
  82. 頁面一.SetActive(true);
  83. 頁面二.SetActive(false);
  84. 上一頁按鈕.SetActive(false);
  85. 新增.interactable = false;
  86. 修改.interactable = false;
  87. 存檔.interactable = false;
  88. 刪除.interactable = false;
  89. DateTime currentDate = DateTime.Now;
  90. int currentIndex = 年.options.FindIndex(option => option.text == currentDate.Year.ToString());
  91. 年.value = currentIndex;
  92. string monStr = $"{currentDate.Month:00}";
  93. int currentIndex1 = 月.options.FindIndex(option => option.text == monStr);
  94. 月.value = currentIndex1;
  95. string yearStr = 年.options[年.value].text;
  96. string monthStr = 月.options[月.value].text;
  97. if (int.TryParse(yearStr, out int year) && int.TryParse(monthStr, out int month))
  98. {
  99. 日期讀取(year, month);
  100. string dayStr = $"{currentDate.Day:00}";
  101. int currentIndex2 = 日.options.FindIndex(option => option.text == dayStr);
  102. 日.value = currentIndex2;
  103. }
  104. StartCoroutine(點檢表系統名稱下拉清單());
  105. 年.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
  106. 月.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
  107. 日.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
  108. }
  109. public void 日期讀取(int year, int month)
  110. {
  111. int daysInMonth = DateTime.DaysInMonth(year, month);
  112. 日.options.Clear();
  113. List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
  114. for (int i = 1; i <= daysInMonth; i++)
  115. {
  116. string dayStr = i < 10 ? "0" + i.ToString() : i.ToString();
  117. options.Add(new TMP_Dropdown.OptionData(dayStr));
  118. }
  119. 日.AddOptions(options);
  120. }
  121. private void OnDropdown1ValueChanged()
  122. {
  123. string yearStr = 年.options[年.value].text;
  124. string monthStr = 月.options[月.value].text;
  125. if (int.TryParse(yearStr, out int year) && int.TryParse(monthStr, out int month))
  126. {
  127. 日期讀取(year, month);
  128. 控制流水號 = "";
  129. 設備流水號 = "";
  130. 名稱s.text= "";
  131. 備註s.text="";
  132. 明細標題.text= "";
  133. 新增.interactable = false;
  134. 修改.interactable = false;
  135. 存檔.interactable = false;
  136. 刪除.interactable = false;
  137. if (copy2!= null)
  138. {
  139. DeleteCopies(copy2);
  140. }
  141. StartCoroutine(點檢表系統名稱清單());
  142. }
  143. }
  144. IEnumerator AnimateText()
  145. {
  146. string qqq = 讀取.text.ToString();
  147. while (true)
  148. {
  149. yield return new WaitForSeconds(0.5f);
  150. if (dotCount < 3)
  151. {
  152. loadingText += ".";
  153. dotCount++;
  154. }
  155. else
  156. {
  157. loadingText = "";
  158. dotCount = 0;
  159. }
  160. 讀取.text = qqq+loadingText;
  161. }
  162. }
  163. IEnumerator 表單ISO編碼()
  164. {
  165. string strcon = "表單ISO編碼";
  166. string se = Main.Global.預設伺服器路徑;
  167. string pa = "設備點檢表";
  168. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}", strcon, se,pa);
  169. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  170. yield return request.SendWebRequest();
  171. if (request.result == UnityWebRequest.Result.ConnectionError)
  172. {
  173. Debug.Log(request.error);
  174. yield break;
  175. }
  176. JSONNode json = JSON.Parse(request.downloadHandler.text);
  177. Debug.Log(json);
  178. 上ISO.text=json[0].ToString().Trim('"');
  179. 下ISO.text=json[1].ToString().Trim('"');
  180. }
  181. IEnumerator 點檢表系統名稱下拉清單()
  182. {
  183. string strcon = "點檢表系統名稱下拉清單";
  184. string se = Main.Global.預設伺服器路徑;
  185. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  186. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  187. yield return request.SendWebRequest();
  188. if (request.result == UnityWebRequest.Result.ConnectionError)
  189. {
  190. Debug.Log(request.error);
  191. yield break;
  192. }
  193. JSONNode json = JSON.Parse(request.downloadHandler.text);
  194. 名稱.options.Clear();
  195. List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
  196. for (int i = 0; i < json.Count; i++)
  197. {
  198. string str = json[i].ToString().Trim('"');
  199. options.Add(new TMP_Dropdown.OptionData(str));
  200. }
  201. 名稱.AddOptions(options);
  202. 名稱.onValueChanged.AddListener((value) => OnDropdown1ValueChanged1());
  203. yield return StartCoroutine(點檢表系統名稱清單());
  204. }
  205. private void OnDropdown1ValueChanged1()
  206. {
  207. 控制流水號 = "";
  208. 設備流水號 = "";
  209. 名稱s.text= "";
  210. 備註s.text="";
  211. 明細標題.text= "";
  212. 新增.interactable = false;
  213. 修改.interactable = false;
  214. 存檔.interactable = false;
  215. 刪除.interactable = false;
  216. if (copy2!= null)
  217. {
  218. DeleteCopies(copy2);
  219. }
  220. StartCoroutine(點檢表系統名稱清單());
  221. }
  222. IEnumerator 點檢表系統名稱清單()
  223. {
  224. 讀取面板.SetActive(true);
  225. if (copy!= null)
  226. {
  227. DeleteCopies(copy);
  228. }
  229. string strcon = "點檢表系統名稱清單";
  230. string se = Main.Global.預設伺服器路徑;
  231. string pa = 年.options[年.value].text+"/"+月.options[月.value].text;
  232. string pa1 = 名稱.options[名稱.value].text;
  233. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se,pa,pa1);
  234. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  235. yield return request.SendWebRequest();
  236. if (request.result == UnityWebRequest.Result.ConnectionError)
  237. {
  238. Debug.Log(request.error);
  239. yield break;
  240. }
  241. JSONNode json = JSON.Parse(request.downloadHandler.text);
  242. int sum = 5;
  243. GameObject selectedButton = null;
  244. for (int i = 0; i < json.Count; i++)
  245. {
  246. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  247. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  248. buttonObj.transform.SetParent(buttonParent, false);
  249. TextMeshProUGUI text = buttonObj.GetComponentInChildren<TextMeshProUGUI>();
  250. Button bt = buttonObj.GetComponentInChildren<Button>();
  251. Image[] im = buttonObj.GetComponentsInChildren<Image>();
  252. int index = i;
  253. bt.onClick.AddListener(() =>
  254. {
  255. if (selectedButton != null)
  256. {
  257. Image[] prevButtonImages = selectedButton.GetComponentsInChildren<Image>();
  258. prevButtonImages[1].color = Color.white;
  259. }
  260. 控制流水號 = json[index][1].ToString().Trim('"');
  261. 設備流水號 = json[index][8].ToString().Trim('"');
  262. 名稱s.text= json[index][4].ToString().Trim('"');
  263. 備註s.text= json[index][9].ToString().Trim('"');
  264. string str = json[index][3].ToString().Trim('"');
  265. 明細標題.text= 年.options[年.value].text+"/"+月.options[月.value].text+str+"設備日常檢點表";
  266. StartCoroutine(確認是否有明細());
  267. // 設定當前按鈕為選中狀態
  268. im[1].color = new Color32(160, 255, 160, 255);
  269. selectedButton = buttonObj;
  270. });
  271. text.text = json[i][4].ToString().Trim('"');
  272. sum+=75;
  273. copy.Add(buttonObj);
  274. }
  275. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  276. 讀取面板.SetActive(false);
  277. }
  278. IEnumerator 檢點項目內容()
  279. {
  280. 讀取面板.SetActive(true);
  281. string strcon = "檢點項目內容";
  282. string se = Main.Global.預設伺服器路徑;
  283. string pa = 設備流水號;
  284. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}", strcon, se, pa);
  285. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  286. yield return request.SendWebRequest();
  287. if (request.result == UnityWebRequest.Result.ConnectionError)
  288. {
  289. Debug.Log(request.error);
  290. yield break;
  291. }
  292. JSONNode json = JSON.Parse(request.downloadHandler.text);
  293. 點檢表 = new JSONArray();
  294. for (int i = 0; i < json.Count; i++)
  295. {
  296. JSONNode newValue = new JSONObject();
  297. newValue["項目"] = json[i][1].ToString().Trim('"');
  298. for (int j = 1; j < 32; j++)
  299. {
  300. newValue[j.ToString("D2")] = "";
  301. }
  302. 點檢表.Add(newValue);
  303. }
  304. JSONNode lastValue = new JSONObject();
  305. lastValue["項目"] = "點檢人員";
  306. for (int j = 1; j < 32; j++)
  307. {
  308. lastValue[j.ToString("D2")] = "";
  309. }
  310. 點檢表.Add(lastValue);
  311. yield return StartCoroutine(點檢明細表());
  312. }
  313. IEnumerator 點檢明細表()
  314. {
  315. string strcon = "點檢明細表";
  316. string se = Main.Global.預設伺服器路徑;
  317. string pa = 年.options[年.value].text+"/"+月.options[月.value].text;
  318. string pa1 = 控制流水號;
  319. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  320. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  321. yield return request.SendWebRequest();
  322. if (request.result == UnityWebRequest.Result.ConnectionError)
  323. {
  324. Debug.Log(request.error);
  325. yield break;
  326. }
  327. JSONNode json = JSON.Parse(request.downloadHandler.text);
  328. for (int i = 0; i < json.Count; i++)
  329. {
  330. string str = json[i][6].ToString().Trim('"');
  331. for (int j = 0; j < json.Count; j++)
  332. {
  333. string str1 = 點檢表[j][0].ToString().Trim('"');
  334. if (str1 == str)
  335. {
  336. string date = json[i][3].ToString().Trim('"');
  337. string ld = date.Substring(date.Length - 2);
  338. if (int.TryParse(ld, out int result))
  339. {
  340. 點檢表[j][result]=json[i][5].ToString().Trim('"');
  341. int a = 點檢表.Count - 1;
  342. 點檢表[a][result]=json[i][4].ToString().Trim('"');
  343. }
  344. }
  345. }
  346. }
  347. if (copy1!= null)
  348. {
  349. DeleteCopies(copy1);
  350. }
  351. int sum = 5;
  352. for (int i = 0; i < 點檢表.Count; i++)
  353. {
  354. GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
  355. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  356. string str = 點檢表[i][0].ToString().Trim('"');
  357. if (i == 點檢表.Count-1)
  358. {
  359. float xbar = buttonObj.GetComponent<RectTransform>().sizeDelta.x;
  360. float ybar = buttonObj.GetComponent<RectTransform>().sizeDelta.y*2;
  361. buttonObj.GetComponent<RectTransform>().sizeDelta=new Vector2(xbar, ybar);
  362. sum+=75;
  363. }
  364. buttonObj.transform.SetParent(buttonParent1, false);
  365. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  366. for (int j = 0; j < text.Length; j++)
  367. {
  368. text[j].text = 點檢表[i][j].ToString().Trim('"');
  369. }
  370. sum+=75;
  371. copy1.Add(buttonObj);
  372. }
  373. buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
  374. 讀取面板.SetActive(false);
  375. }
  376. IEnumerator 確認是否有明細()
  377. {
  378. string strcon = "點檢明細表";
  379. string se = Main.Global.預設伺服器路徑;
  380. string pa = 年.options[年.value].text+"/"+月.options[月.value].text+"/"+日.options[日.value].text;
  381. string pa1 = 控制流水號;
  382. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  383. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  384. yield return request.SendWebRequest();
  385. if (request.result == UnityWebRequest.Result.ConnectionError)
  386. {
  387. Debug.Log(request.error);
  388. yield break;
  389. }
  390. 檢點明細= JSON.Parse(request.downloadHandler.text);
  391. Debug.Log(檢點明細);
  392. if (檢點明細.Count>0)
  393. {
  394. 修改.interactable = true;
  395. 新增.interactable = false;
  396. if (編輯模式 == "新增")
  397. {
  398. 修改.interactable = false;
  399. }
  400. if (copy2!= null)
  401. {
  402. DeleteCopies(copy2);
  403. }
  404. int sum = 5;
  405. for (int i = 0; i < 檢點明細.Count; i++)
  406. {
  407. GameObject buttonObj = Instantiate(buttonPrefab2) as GameObject;
  408. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  409. buttonObj.transform.SetParent(buttonParent2, false);
  410. TextMeshProUGUI text = buttonObj.GetComponentInChildren<TextMeshProUGUI>();
  411. Toggle[] tg = buttonObj.GetComponentsInChildren<Toggle>();
  412. Button[] bt = buttonObj.GetComponentsInChildren<Button>();
  413. text.text =檢點明細[i][6].ToString().Trim('"');
  414. string str = 檢點明細[i][5].ToString().Trim('"');
  415. int index = i;
  416. if(str == "V")
  417. {
  418. tg[0].isOn =true;
  419. tg[1].isOn =false;
  420. }
  421. else if(str == "X")
  422. {
  423. tg[0].isOn =false;
  424. tg[1].isOn =true;
  425. }
  426. else
  427. {
  428. tg[0].isOn =false;
  429. tg[1].isOn =false;
  430. }
  431. bt[0].onClick.AddListener(() =>
  432. {
  433. if (編輯模式 == "修改" || 編輯模式 == "新增")
  434. {
  435. if(tg[0].isOn ==false && tg[1].isOn ==false)
  436. {
  437. tg[0].isOn=true;
  438. tg[1].isOn =false;
  439. 檢點明細[index][5]="V";
  440. }
  441. else if (tg[0].isOn ==false && tg[1].isOn ==true)
  442. {
  443. tg[0].isOn=true;
  444. tg[1].isOn =false;
  445. 檢點明細[index][5]="V";
  446. }
  447. else if (tg[0].isOn ==true && tg[1].isOn ==false)
  448. {
  449. tg[0].isOn=false;
  450. tg[1].isOn =false;
  451. 檢點明細[index][5]="";
  452. }
  453. Debug.Log(檢點明細);
  454. }
  455. });
  456. bt[1].onClick.AddListener(() =>
  457. {
  458. if (編輯模式 == "修改" || 編輯模式 == "新增")
  459. {
  460. if (tg[0].isOn ==false && tg[1].isOn ==false)
  461. {
  462. tg[1].isOn=true;
  463. tg[0].isOn =false;
  464. 檢點明細[index][5]="X";
  465. }
  466. else if (tg[0].isOn ==true && tg[1].isOn ==false)
  467. {
  468. tg[1].isOn=true;
  469. tg[0].isOn =false;
  470. 檢點明細[index][5]="X";
  471. }
  472. else if (tg[0].isOn ==false && tg[1].isOn ==true)
  473. {
  474. tg[0].isOn=false;
  475. tg[1].isOn =false;
  476. 檢點明細[index][5]="";
  477. }
  478. Debug.Log(檢點明細);
  479. }
  480. });
  481. sum+=75;
  482. copy2.Add(buttonObj);
  483. }
  484. buttonceneter2.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter2.GetComponent<RectTransform>().sizeDelta.x, sum);
  485. }
  486. else
  487. {
  488. 新增.interactable = true;
  489. 修改.interactable = false;
  490. if (copy2!= null)
  491. {
  492. DeleteCopies(copy2);
  493. }
  494. }
  495. }
  496. IEnumerator 查找檢點明細表最後一筆流水號()
  497. {
  498. string strcon = "查找檢點明細表最後一筆流水號";
  499. string se = Main.Global.預設伺服器路徑;
  500. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  501. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  502. yield return request.SendWebRequest();
  503. if (request.result == UnityWebRequest.Result.ConnectionError)
  504. {
  505. Debug.Log(request.error);
  506. yield break;
  507. }
  508. string num = request.downloadHandler.text.ToString();
  509. string 流水號 = "";
  510. if (num == "n")
  511. {
  512. 流水號 ="IS00000000";
  513. }
  514. else
  515. {
  516. 流水號 =num;
  517. }
  518. yield return StartCoroutine(新增項目內容(流水號));
  519. }
  520. IEnumerator 新增項目內容(string 流水號)
  521. {
  522. string strcon = "檢點項目內容";
  523. string se = Main.Global.預設伺服器路徑;
  524. string pa = 設備流水號;
  525. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}", strcon, se, pa);
  526. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  527. yield return request.SendWebRequest();
  528. if (request.result == UnityWebRequest.Result.ConnectionError)
  529. {
  530. Debug.Log(request.error);
  531. yield break;
  532. }
  533. JSONNode json = JSON.Parse(request.downloadHandler.text);
  534. string cnum = 流水號.Substring(2);
  535. int inum = int.Parse(cnum);
  536. for (int i = 0; i < json.Count; i++)
  537. {
  538. inum+=1;
  539. string 新流水 = "IS";
  540. if (inum<10)
  541. {
  542. 新流水+="0000000"+inum.ToString();
  543. }
  544. if (inum>9 && inum<100)
  545. {
  546. 新流水+="000000"+inum.ToString();
  547. }
  548. if (inum>99 && inum<1000)
  549. {
  550. 新流水+="00000"+inum.ToString();
  551. }
  552. if (inum>999 && inum<10000)
  553. {
  554. 新流水+="0000"+inum.ToString();
  555. }
  556. if (inum>9999 && inum<100000)
  557. {
  558. 新流水+="000"+inum.ToString();
  559. }
  560. if (inum>99999 && inum<10000000)
  561. {
  562. 新流水+="00"+inum.ToString();
  563. }
  564. if (inum>999999 && inum<10000000)
  565. {
  566. 新流水+="0"+inum.ToString();
  567. }
  568. if (inum>9999999 && inum<100000000)
  569. {
  570. 新流水+=inum.ToString();
  571. }
  572. string str = json[i][0].ToString().Trim('"');
  573. yield return StartCoroutine(新增檢點明細表(新流水, str));
  574. }
  575. yield return StartCoroutine(確認是否有明細());
  576. }
  577. IEnumerator 新增檢點明細表(string 流水號, string 項目流水號)
  578. {
  579. string strcon = "新增檢點明細表";
  580. string se = Main.Global.預設伺服器路徑;
  581. string pa = 流水號;
  582. string pa1 = 控制流水號;
  583. string pa2 = 項目流水號;
  584. string pa3 = 年.options[年.value].text+"/"+月.options[月.value].text+"/"+日.options[日.value].text;
  585. string pa4 = Main.Global.人員;
  586. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}&PA3={5}&PA4={6}",strcon,se,pa,pa1,pa2,pa3,pa4);
  587. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  588. yield return request.SendWebRequest();
  589. if (request.result == UnityWebRequest.Result.ConnectionError)
  590. {
  591. Debug.Log(request.error);
  592. yield break;
  593. }
  594. }
  595. IEnumerator 檢點明細表更新(string 明細流水號, string 狀態)
  596. {
  597. string strcon = "檢點明細表更新";
  598. string se = Main.Global.預設伺服器路徑;
  599. string pa = 狀態;
  600. string pa1 = 明細流水號;
  601. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  602. Debug.Log(strUrl);
  603. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  604. yield return request.SendWebRequest();
  605. if (request.result == UnityWebRequest.Result.ConnectionError)
  606. {
  607. Debug.Log(request.error);
  608. yield break;
  609. }
  610. }
  611. IEnumerator 檢點明細表刪除()
  612. {
  613. string strcon = "檢點明細表刪除";
  614. string se = Main.Global.預設伺服器路徑;
  615. string pa = 控制流水號;
  616. string pa1 = 年.options[年.value].text+"/"+月.options[月.value].text+"/"+日.options[日.value].text;
  617. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  618. Debug.Log(strUrl);
  619. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  620. yield return request.SendWebRequest();
  621. if (request.result == UnityWebRequest.Result.ConnectionError)
  622. {
  623. Debug.Log(request.error);
  624. yield break;
  625. }
  626. }
  627. public void 新增s()
  628. {
  629. 編輯模式="新增";
  630. 新增.interactable = false;
  631. 修改.interactable = false;
  632. 存檔.interactable = true;
  633. 刪除.interactable = true;
  634. 看明細.interactable = false;
  635. 年.interactable = false;
  636. 月.interactable = false;
  637. 日.interactable = false;
  638. 名稱.interactable = false;
  639. 回首頁.interactable = false;
  640. StartCoroutine(查找檢點明細表最後一筆流水號());
  641. }
  642. public void 修改s()
  643. {
  644. 編輯模式="修改";
  645. 新增.interactable = false;
  646. 修改.interactable = false;
  647. 存檔.interactable = true;
  648. 刪除.interactable = true;
  649. 看明細.interactable = false;
  650. 年.interactable = false;
  651. 月.interactable = false;
  652. 日.interactable = false;
  653. 名稱.interactable = false;
  654. 回首頁.interactable = false;
  655. }
  656. public void 存檔s()
  657. {
  658. 讀取面板.SetActive(true);
  659. for (int i = 0; i < 檢點明細.Count; i++)
  660. {
  661. string str = 檢點明細[i][0].ToString().Trim('"');
  662. string str1 = 檢點明細[i][5].ToString().Trim('"');
  663. StartCoroutine(檢點明細表更新(str,str1));
  664. }
  665. 編輯模式="";
  666. 新增.interactable = false;
  667. 修改.interactable = true;
  668. 存檔.interactable = false;
  669. 刪除.interactable = false;
  670. 看明細.interactable = true;
  671. 年.interactable = true;
  672. 月.interactable = true;
  673. 日.interactable = true;
  674. 名稱.interactable = true;
  675. 回首頁.interactable = true;
  676. 彈跳面板.SetActive(true);
  677. 彈跳文字.text="儲存成功";
  678. 讀取面板.SetActive(false);
  679. }
  680. public void 刪除s()
  681. {
  682. 編輯模式="";
  683. StartCoroutine(檢點明細表刪除());
  684. if (copy2!= null)
  685. {
  686. DeleteCopies(copy2);
  687. }
  688. 讀取面板.SetActive(true);
  689. 新增.interactable = true;
  690. 修改.interactable = false;
  691. 存檔.interactable = false;
  692. 刪除.interactable = false;
  693. 看明細.interactable = true;
  694. 年.interactable = true;
  695. 月.interactable = true;
  696. 日.interactable = true;
  697. 名稱.interactable = true;
  698. 回首頁.interactable = true;
  699. 彈跳面板.SetActive(true);
  700. 彈跳文字.text="刪除成功";
  701. 讀取面板.SetActive(false);
  702. }
  703. public void 顯示檢點內容()
  704. {
  705. if (控制流水號 == "")
  706. {
  707. 彈跳面板.SetActive(true);
  708. 彈跳文字.text="未選擇產品名稱";
  709. }
  710. else
  711. {
  712. 頁面一.SetActive(false);
  713. 頁面二.SetActive(true);
  714. 上一頁按鈕.SetActive(true);
  715. StartCoroutine(檢點項目內容());
  716. }
  717. }
  718. public void 彈出面板關閉()
  719. {
  720. 彈跳面板.SetActive(false);
  721. 彈跳文字.text="";
  722. }
  723. public void 上一頁()
  724. {
  725. 頁面一.SetActive(true);
  726. 頁面二.SetActive(false);
  727. 上一頁按鈕.SetActive(false);
  728. }
  729. private void DeleteCopies(List<GameObject> copyList)
  730. {
  731. foreach (GameObject copy in copyList)
  732. {
  733. Destroy(copy);
  734. }
  735. copyList.Clear();
  736. }
  737. public void back()
  738. {
  739. change_Secen(1);
  740. }
  741. public void change_Secen(int _screenNum)
  742. {
  743. SceneManager.LoadScene(_screenNum);
  744. }
  745. }