123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- using UnityEngine.EventSystems;
- using System.Text.RegularExpressions;
- using System.Data.SqlClient;
- using System.Runtime.InteropServices;
- using System.Text;
- using TMPro;
- using System;
- using System.IO;
- using ZXing;
- using ZXing.QrCode;
- using System.Net;
- using System.Data;
- using SimpleJSON;
- using System.Linq;
- using System.ComponentModel;
- using System.Runtime.InteropServices;
- using System.Globalization;
- using XCharts.Runtime;
-
- public class 車輛紀錄 : MonoBehaviour
- {
- [SerializeField] TextMeshProUGUI 姓名;
- [SerializeField] TextMeshProUGUI 車號;
- [SerializeField] GameObject 選擇面板;
- [SerializeField] TMP_InputField 關鍵字;
-
- private JSONArray newjson;
-
- 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>();
-
- public CanvasScaler canvasScaler;
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
-
- [SerializeField] GameObject 彈跳面板;
- [SerializeField] TextMeshProUGUI 彈跳文字;
-
- private string loadingText = "";
- private int dotCount = 0;
- // Start is called before the first frame update
- void Start()
- {
- Screen.autorotateToPortrait = false;
- Screen.orientation = ScreenOrientation.Portrait;
- float rate = 1000.0f / 1600.0f;
- if (canvasScaler == null)
- {
- canvasScaler = GetComponent<CanvasScaler>();
- }
- if (Main.Global.rate>rate)
- {
- canvasScaler.matchWidthOrHeight = 1f;
- }
- else
- {
- canvasScaler.matchWidthOrHeight = 0f;
- }
- StartCoroutine(AnimateText());
- //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/GF_main.php?";
- //Main.Global.預設伺服器路徑="GF01";
- 選擇面板.SetActive(true);
- }
- IEnumerator 客戶搜尋()
- {
- 讀取面板.SetActive(true);
- if (copy != null)
- {
- DeletetextCopy();
- }
- 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);
- int sum = 2;
- for (int i = 0; i < json.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- buttonObj.transform.SetParent(buttonParent, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- Button bt = buttonObj.GetComponentInChildren<Button>();
- int index = i;
- bt.onClick.AddListener(() =>
- {
- 關鍵字.text="";
- 姓名.text=json[index][1].ToString().Trim('"');
- 車號.text=json[index][3].ToString().Trim('"');
- StartCoroutine(單號搜尋());
- 選擇面板.SetActive(false);
- });
- text[0].text =json[i][1].ToString().Trim('"');
- text[1].text =json[i][3].ToString().Trim('"');
- sum+=75;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- 讀取面板.SetActive(false);
- }
- public void 搜尋()
- {
- StartCoroutine(客戶搜尋());
- }
- IEnumerator 單號搜尋()
- {
- 讀取面板.SetActive(true);
- if (copy1 != null)
- {
- DeletetextCopy1();
- }
- string strcon = "單號搜尋";
- string se = Main.Global.預設伺服器路徑;
- string pa1 = 姓名.text;
- string pa2 = 車號.text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}", strcon, se, pa1, pa2);
- 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);
- newjson = new JSONArray();
- for (int i = 0; i < json.Count; i++)
- {
- string str = json[i][0].ToString().Trim('"');
- yield return StartCoroutine(明細搜尋(str));
- }
- int sum = 2;
- string asd = newjson[0][0].ToString().Trim('"');
- int j = 0;
- for (int i = 0; i < newjson.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- buttonObj.transform.SetParent(buttonParent1, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- Image[] childImages = buttonObj.GetComponentsInChildren<Image>();
- if (i < newjson.Count - 1 && asd != newjson[i+1][0].ToString().Trim('"'))
- {
- asd = newjson[i+1][0].ToString().Trim('"');
- }
- else
- {
- childImages[5].gameObject.SetActive(false);
- }
- text[0].text =(i+1).ToString();
- string str = newjson[i][0].ToString().Trim('"');
- text[1].text=str.Substring(3, 8);
- text[2].text =newjson[i][1].ToString().Trim('"').Replace("\\\\", "\\");
- text[3].text =newjson[i][2].ToString().Trim('"');
- sum+=75;
- copy1.Add(buttonObj);
- }
- buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
- 讀取面板.SetActive(false);
- }
-
-
- IEnumerator 明細搜尋(string str)
- {
- string strcon = "明細搜尋";
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se, str);
- 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);
- for (int i = 0; i < json.Count; i++)
- {
- JSONNode newValue = new JSONObject();
- newValue["單號"] = json[i][0].ToString().Trim('"');
- newValue["細項"] = json[i][2].ToString().Trim('"').Replace("\\\\", "\\");
- newValue["數量"] = json[i][3].ToString().Trim('"');
- newjson.Add(newValue);
- }
-
- }
- public void 清單()
- {
- 選擇面板.SetActive(true);
- }
- public void DeletetextCopy()
- {
- foreach (GameObject i in copy)
- {
- Destroy(i);
- }
- copy.Clear();
-
- }
- public void DeletetextCopy1()
- {
- foreach (GameObject i in copy1)
- {
- Destroy(i);
- }
- copy1.Clear();
-
- }
- 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;
- }
- }
-
- public void exit()
- {
- change_Secen(1);
- }
- public void change_Secen(int _screenNum)
- {
- //Main.Global.判斷是否第一次=true;
- SceneManager.LoadScene(_screenNum);
- }
- }
|