123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- using System.Text.RegularExpressions;
- using System.Data.SqlClient;
- using TMPro;
- using System;
- using System.IO;
- using ZXing;
- using ZXing.QrCode;
- using System.Net;
- using SimpleJSON;
- using System.ComponentModel;
- using System.Runtime.InteropServices;
- public class 庫存表 : MonoBehaviour
- {
- public CanvasScaler canvasScaler;
- float screenWidth;
- float screenHeight;
- private string loadingText = "";
- private int dotCount = 0;
-
- public GameObject buttonPrefab;
- public Transform buttonParent;
- public GameObject buttonceneter;
- private List<GameObject> copy = new List<GameObject>();
-
- public GameObject buttonPrefab1;
- public Transform buttonParent1;
- public GameObject buttonceneter1;
- private List<GameObject> copy1 = new List<GameObject>();
-
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
- [SerializeField] TMP_InputField 關鍵字;
-
- // Start is called before the first frame update
- void Start()
- {
- Screen.autorotateToPortrait = false;
- Screen.orientation = ScreenOrientation.Portrait;
- float rate = 900.0f / 1900.0f;
- if (canvasScaler == null)
- {
- canvasScaler = GetComponent<CanvasScaler>();
- }
-
- if (Main.Global.rate>rate)
- {
- canvasScaler.matchWidthOrHeight = 1f;
- }
- else
- {
- canvasScaler.matchWidthOrHeight = 0f;
- }
- //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/shto_main.php?";
- //Main.Global.預設伺服器路徑="official";
-
- StartCoroutine(AnimateText());
- 讀取面板.SetActive(true);
- 關鍵字.text="";
- 搜尋();
- }
- IEnumerator AnimateText()
- {
- string qqq = 讀取.text.ToString();
- while (true)
- {
- yield return new WaitForSeconds(0.5f);
-
- if (dotCount < 3)
- {
- loadingText += ".";
- dotCount++;
- }
- else
- {
- loadingText = "";
- dotCount = 0;
- }
-
- 讀取.text = qqq+loadingText;
- }
- }
- IEnumerator 庫存明細表()
- {
- if (copy != null)
- {
- DeletetextCopies();
- }
- string strcon = "庫存明細表";
- string se = Main.Global.預設伺服器路徑;
- string pa1 = 關鍵字.text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se,pa1);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- yield break;
- }
- JSONNode json = JSON.Parse(request.downloadHandler.text);
- GameObject selectedButton = null;
- int sum = 0;
- for (int i = 0; i < json.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(5, -sum);
- buttonObj.transform.SetParent(buttonParent, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- Button bt = buttonObj.GetComponentInChildren<Button>();
- Image[] im = buttonObj.GetComponentsInChildren<Image>();
- int index = i;
- bt.onClick.AddListener(() =>
- {
- string str = json[index][3].ToString().Trim('"');
- StartCoroutine(庫存表物料明細(str));
- if (selectedButton != null)
- {
- Image[] prevButtonImages = selectedButton.GetComponentsInChildren<Image>();
- prevButtonImages[2].color = new Color32(255, 255, 255, 255);
- }
- // 設定當前按鈕為選中狀態
- im[2].color = new Color32(160, 255, 160, 255);
- selectedButton = buttonObj;
- });
- text[0].text = (i+1).ToString();
- text[1].text = json[i][1].ToString().Trim('"');
- text[2].text = json[i][2].ToString().Trim('"');
- sum+=100;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- 讀取面板.SetActive(false);
- }
- IEnumerator 庫存表物料明細(string str)
- {
- if (copy1 != null)
- {
- DeletetextCopies1();
- }
- string strcon = "庫存表物料明細";
- string se = Main.Global.預設伺服器路徑;
- string pa1 = str;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se, pa1);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- Debug.Log(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- yield break;
- }
- JSONNode json = JSON.Parse(request.downloadHandler.text);
- Debug.Log(json);
- GameObject selectedButton = null;
- int sum = 0;
- for (int i = 0; i < json.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(5, -sum);
- buttonObj.transform.SetParent(buttonParent1, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- Button bt = buttonObj.GetComponentInChildren<Button>();
- Image[] im = buttonObj.GetComponentsInChildren<Image>();
- int index = i;
- text[0].text = json[i][0].ToString().Trim('"');
- text[1].text = json[i][1].ToString().Trim('"');
- text[2].text = json[i][2].ToString().Trim('"');
- text[3].text = json[i][3].ToString().Trim('"');
- text[4].text = json[i][4].ToString().Trim('"');
- text[5].text = json[i][5].ToString().Trim('"');
- sum+=100;
- copy1.Add(buttonObj);
- }
- buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
- 讀取面板.SetActive(false);
- }
- public void 搜尋()
- {
- if (copy1 != null)
- {
- DeletetextCopies1();
- }
- StartCoroutine(庫存明細表());
- }
- public void DeletetextCopies()
- {
- // 刪除複製出來的物件
- foreach (GameObject copy in copy)
- {
- Destroy(copy);
- }
- copy.Clear();
- }
- public void DeletetextCopies1()
- {
- // 刪除複製出來的物件
- foreach (GameObject copy in copy1)
- {
- Destroy(copy);
- }
- copy1.Clear();
- }
- public void back()
- {
- change_Secen(1);
- }
- public void change_Secen(int _screenNum)
- {
-
- SceneManager.LoadScene(_screenNum);
- }
- }
|