123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- 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 GameObject buttonPrefab;
- public ScrollRect buttonscroll;
- private List<GameObject> copy = new List<GameObject>();
-
- [SerializeField] TextMeshProUGUI 日期;
- [SerializeField] TextMeshProUGUI 名稱;
- [SerializeField] TextMeshProUGUI 主旨;
- [SerializeField] TextMeshProUGUI 說明;
- [SerializeField] ScrollRect 說明滑動;
-
- [SerializeField] GameObject 主頁;
- [SerializeField] GameObject 內容頁;
- [SerializeField] GameObject 上一頁紐;
- [SerializeField] GameObject 電簽紐;
- public CanvasScaler canvasScaler;
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
-
- [SerializeField] GameObject 彈跳面板;
- [SerializeField] TextMeshProUGUI 彈跳文字;
- private string loadingText = "";
- private int dotCount = 0;
- bool 已簽;
- void Start()
- {
- Screen.autorotateToPortrait = false;
- Screen.orientation = ScreenOrientation.Portrait;
- //Main.Global.螢幕方向 = "直";
- //Main.Global.固高 = 1900f;
- //Main.Global.固寬 = 900f;
- //Main.Global.固比 = 1f;
- //Main.Global.螢幕格式 = "瘦";
- //Main.Global.考勤主管權限 = false;
- //Main.Global.PA = "*系統管理員";
- //Main.Global.編號= "21";
- canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高);
- canvasScaler.matchWidthOrHeight = Main.Global.固比;
- //Main.Global.阿帕契路徑 = "http://106.1.48.106:8080/event-star/hskin_logint.php?";
- //Main.Global.預設伺服器路徑 = "test";
- StartCoroutine(AnimateText());
- 主頁.SetActive(true);
- 內容頁.SetActive(false);
- 上一頁紐.SetActive(false);
- 電簽紐.SetActive(false);
- StartCoroutine(文件控制表讀取());
- }
-
- 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)
- {
- DeleteCopies(copy);
- }
- string strcon = "文件控制表讀取";
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}&se={1}", strcon, se);
- 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 = 5;
- if (Main.Global.編號 == "999" || Main.Global.編號 == "18" || Main.Global.編號 == "19" || Main.Global.編號 == "21" )
- {
- for (int i = 0; i < json.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- Transform tran = buttonscroll.content;
- buttonObj.transform.SetParent(tran, false);
- TextMeshProUGUI[] texts = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- int index = i;
- Button bt = buttonObj.GetComponentInChildren<Button>();
- texts[0].text = json[i][2].ToString().Trim('"');
- texts[1].text = json[i][1].ToString().Trim('"');
- bt.onClick.AddListener(() =>
- {
- Main.Global.控制表流水 = json[index][0].ToString().Trim('"');
- 日期.text = json[index][2].ToString().Trim('"');
- 名稱.text = json[index][1].ToString().Trim('"');
- 主旨.text = json[index][3].ToString().Trim('"');
- string jsonString = json[index][4].ToString().Trim('"');
- 說明.text = Regex.Unescape(jsonString);
- Canvas.ForceUpdateCanvases();
- LayoutRebuilder.ForceRebuildLayoutImmediate(說明.rectTransform);
- StartCoroutine(DelayedHeightCheck());
- 主頁.SetActive(false);
- 內容頁.SetActive(true);
- 上一頁紐.SetActive(true);
- if (Main.Global.編號 == "999" || Main.Global.編號 == "18" || Main.Global.編號 == "19" || Main.Global.編號 == "21")
- {
- 電簽紐.SetActive(false);
- }
- else
- {
- 電簽紐.SetActive(true);
- }
- });
- sum += 100;
- copy.Add(buttonObj);
- }
-
- }
- else
- {
- for (int i = 0; i < json.Count; i++)
- {
- string strcon1 = "文件控制表人員讀取";
- string pa = json[i][0].ToString().Trim('"');
- string pa1 = Main.Global.PA;
- string strUrl1 = string.Format(Main.Global.阿帕契路徑 + "comm={0}&se={1}&PA={2}&PA1={3}", strcon1, se, pa, pa1);
- UnityWebRequest request1 = UnityWebRequest.Get(strUrl1);
- yield return request1.SendWebRequest();
- if (request1.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- JSONNode json1 = JSON.Parse(request1.downloadHandler.text);
- if (json1[0][1].ToString().Trim('"') == "")
- {
- json[i][5] = false;
- }
- else
- {
- json[i][5] = true;
- }
- Debug.Log(json);
- if (json1.Count > 0)
- {
- GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- Transform tran = buttonscroll.content;
- buttonObj.transform.SetParent(tran, false);
- TextMeshProUGUI[] texts = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- int index = i;
- Button bt = buttonObj.GetComponentInChildren<Button>();
- texts[0].text = json[i][2].ToString().Trim('"');
- texts[1].text = json[i][1].ToString().Trim('"');
- bt.onClick.AddListener(() =>
- {
- Main.Global.控制表流水 = json[index][0].ToString().Trim('"');
- 日期.text = json[index][2].ToString().Trim('"');
- 名稱.text = json[index][1].ToString().Trim('"');
- 主旨.text = json[index][3].ToString().Trim('"');
- if(json[index][5] == true)
- {
- 已簽 = true;
- }
- else
- {
- 已簽 = false;
- }
- string jsonString = json[index][4].ToString().Trim('"');
- 說明.text = Regex.Unescape(jsonString);
- Canvas.ForceUpdateCanvases();
- LayoutRebuilder.ForceRebuildLayoutImmediate(說明.rectTransform);
- StartCoroutine(DelayedHeightCheck());
- 主頁.SetActive(false);
- 內容頁.SetActive(true);
- 上一頁紐.SetActive(true);
- if (Main.Global.編號 == "999" || Main.Global.編號 == "18" || Main.Global.編號 == "19" || Main.Global.編號 == "21")
- {
- 電簽紐.SetActive(false);
- }
- else
- {
- 電簽紐.SetActive(true);
- }
- });
- sum += 100;
- copy.Add(buttonObj);
- }
- }
- }
- RectTransform contentTransform = buttonscroll.content;
- contentTransform.anchoredPosition = new Vector2(contentTransform.anchoredPosition.x, 0);
- contentTransform.sizeDelta = new Vector2(contentTransform.sizeDelta.x, sum);
- if (Main.Global.螢幕格式 == "瘦")
- {
- if (sum > 1605)
- {
- buttonscroll.vertical = true;
- }
- else
- {
- buttonscroll.vertical = false;
- }
- }
- else
- {
- if (sum > 1305)
- {
- buttonscroll.vertical = true;
- }
- else
- {
- buttonscroll.vertical = false;
- }
- }
- }
- private IEnumerator DelayedHeightCheck()
- {
- yield return new WaitForEndOfFrame();
- Debug.Log("Delayed height check: " + 說明.preferredHeight);
- float textWidth = 說明.preferredHeight;
-
- if (Main.Global.螢幕格式 == "瘦")
- {
- 說明滑動.content.sizeDelta = new Vector2(說明滑動.content.sizeDelta.x, 1207);
- }
- else
- {
- 說明滑動.content.sizeDelta = new Vector2(說明滑動.content.sizeDelta.x, 957);
- }
-
- float contentWidth = 說明滑動.GetComponent<RectTransform>().rect.height;
- 說明滑動.content.anchoredPosition = new Vector2(說明滑動.content.anchoredPosition.x, 0);
-
- if (textWidth > contentWidth)
- {
- 說明滑動.content.sizeDelta = new Vector2(說明滑動.content.sizeDelta.x, textWidth + 100);
- 說明滑動.vertical = true;
- }
- else
- {
- 說明滑動.vertical = false;
- }
- }
- private void DeleteCopies(List<GameObject> copyList)
- {
- foreach (GameObject copy in copyList)
- {
- Destroy(copy);
- }
- copyList.Clear();
- }
- public void 上一頁()
- {
- 主頁.SetActive(true);
- 內容頁.SetActive(false);
- 上一頁紐.SetActive(false);
- 電簽紐.SetActive(false);
- }
- public void 彈跳面板關閉()
- {
- 彈跳面板.SetActive(false);
- 彈跳文字.text = "";
- }
- public void 電簽()
- {
- if (已簽)
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "已簽過名";
- }
- else
- {
- change_Secen(22);
- }
-
- }
- public void back()
- {
- change_Secen(2);
- }
- public void change_Secen(int _screenNum)
- {
-
- SceneManager.LoadScene(_screenNum);
- }
- }
|