Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. public GameObject buttonPrefab;
  21. public ScrollRect buttonscroll;
  22. private List<GameObject> copy = new List<GameObject>();
  23. [SerializeField] TextMeshProUGUI 日期;
  24. [SerializeField] TextMeshProUGUI 名稱;
  25. [SerializeField] TextMeshProUGUI 主旨;
  26. [SerializeField] TextMeshProUGUI 說明;
  27. [SerializeField] ScrollRect 說明滑動;
  28. [SerializeField] GameObject 主頁;
  29. [SerializeField] GameObject 內容頁;
  30. [SerializeField] GameObject 上一頁紐;
  31. [SerializeField] GameObject 電簽紐;
  32. public CanvasScaler canvasScaler;
  33. [SerializeField] GameObject 讀取面板;
  34. [SerializeField] TextMeshProUGUI 讀取;
  35. [SerializeField] GameObject 彈跳面板;
  36. [SerializeField] TextMeshProUGUI 彈跳文字;
  37. private string loadingText = "";
  38. private int dotCount = 0;
  39. bool 已簽;
  40. void Start()
  41. {
  42. Screen.autorotateToPortrait = false;
  43. Screen.orientation = ScreenOrientation.Portrait;
  44. //Main.Global.螢幕方向 = "直";
  45. //Main.Global.固高 = 1900f;
  46. //Main.Global.固寬 = 900f;
  47. //Main.Global.固比 = 1f;
  48. //Main.Global.螢幕格式 = "瘦";
  49. //Main.Global.考勤主管權限 = false;
  50. //Main.Global.PA = "*系統管理員";
  51. //Main.Global.編號= "21";
  52. canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高);
  53. canvasScaler.matchWidthOrHeight = Main.Global.固比;
  54. //Main.Global.阿帕契路徑 = "http://106.1.48.106:8080/event-star/hskin_logint.php?";
  55. //Main.Global.預設伺服器路徑 = "test";
  56. StartCoroutine(AnimateText());
  57. 主頁.SetActive(true);
  58. 內容頁.SetActive(false);
  59. 上一頁紐.SetActive(false);
  60. 電簽紐.SetActive(false);
  61. StartCoroutine(文件控制表讀取());
  62. }
  63. IEnumerator AnimateText()
  64. {
  65. string qqq = 讀取.text.ToString();
  66. while (true)
  67. {
  68. yield return new WaitForSeconds(0.5f);
  69. if (dotCount < 3)
  70. {
  71. loadingText += ".";
  72. dotCount++;
  73. }
  74. else
  75. {
  76. loadingText = "";
  77. dotCount = 0;
  78. }
  79. 讀取.text = qqq + loadingText;
  80. }
  81. }
  82. IEnumerator 文件控制表讀取()
  83. {
  84. if (copy != null)
  85. {
  86. DeleteCopies(copy);
  87. }
  88. string strcon = "文件控制表讀取";
  89. string se = Main.Global.預設伺服器路徑;
  90. string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}&se={1}", strcon, se);
  91. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  92. yield return request.SendWebRequest();
  93. if (request.result == UnityWebRequest.Result.ConnectionError)
  94. {
  95. //Debug.Log(request.error);
  96. yield break;
  97. }
  98. JSONNode json = JSON.Parse(request.downloadHandler.text);
  99. int sum = 5;
  100. if (Main.Global.編號 == "999" || Main.Global.編號 == "18" || Main.Global.編號 == "19" || Main.Global.編號 == "21" )
  101. {
  102. for (int i = 0; i < json.Count; i++)
  103. {
  104. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  105. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  106. Transform tran = buttonscroll.content;
  107. buttonObj.transform.SetParent(tran, false);
  108. TextMeshProUGUI[] texts = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  109. int index = i;
  110. Button bt = buttonObj.GetComponentInChildren<Button>();
  111. texts[0].text = json[i][2].ToString().Trim('"');
  112. texts[1].text = json[i][1].ToString().Trim('"');
  113. bt.onClick.AddListener(() =>
  114. {
  115. Main.Global.控制表流水 = json[index][0].ToString().Trim('"');
  116. 日期.text = json[index][2].ToString().Trim('"');
  117. 名稱.text = json[index][1].ToString().Trim('"');
  118. 主旨.text = json[index][3].ToString().Trim('"');
  119. string jsonString = json[index][4].ToString().Trim('"');
  120. 說明.text = Regex.Unescape(jsonString);
  121. Canvas.ForceUpdateCanvases();
  122. LayoutRebuilder.ForceRebuildLayoutImmediate(說明.rectTransform);
  123. StartCoroutine(DelayedHeightCheck());
  124. 主頁.SetActive(false);
  125. 內容頁.SetActive(true);
  126. 上一頁紐.SetActive(true);
  127. if (Main.Global.編號 == "999" || Main.Global.編號 == "18" || Main.Global.編號 == "19" || Main.Global.編號 == "21")
  128. {
  129. 電簽紐.SetActive(false);
  130. }
  131. else
  132. {
  133. 電簽紐.SetActive(true);
  134. }
  135. });
  136. sum += 100;
  137. copy.Add(buttonObj);
  138. }
  139. }
  140. else
  141. {
  142. for (int i = 0; i < json.Count; i++)
  143. {
  144. string strcon1 = "文件控制表人員讀取";
  145. string pa = json[i][0].ToString().Trim('"');
  146. string pa1 = Main.Global.PA;
  147. string strUrl1 = string.Format(Main.Global.阿帕契路徑 + "comm={0}&se={1}&PA={2}&PA1={3}", strcon1, se, pa, pa1);
  148. UnityWebRequest request1 = UnityWebRequest.Get(strUrl1);
  149. yield return request1.SendWebRequest();
  150. if (request1.result == UnityWebRequest.Result.ConnectionError)
  151. {
  152. //Debug.Log(request.error);
  153. yield break;
  154. }
  155. JSONNode json1 = JSON.Parse(request1.downloadHandler.text);
  156. if (json1[0][1].ToString().Trim('"') == "")
  157. {
  158. json[i][5] = false;
  159. }
  160. else
  161. {
  162. json[i][5] = true;
  163. }
  164. Debug.Log(json);
  165. if (json1.Count > 0)
  166. {
  167. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  168. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  169. Transform tran = buttonscroll.content;
  170. buttonObj.transform.SetParent(tran, false);
  171. TextMeshProUGUI[] texts = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  172. int index = i;
  173. Button bt = buttonObj.GetComponentInChildren<Button>();
  174. texts[0].text = json[i][2].ToString().Trim('"');
  175. texts[1].text = json[i][1].ToString().Trim('"');
  176. bt.onClick.AddListener(() =>
  177. {
  178. Main.Global.控制表流水 = json[index][0].ToString().Trim('"');
  179. 日期.text = json[index][2].ToString().Trim('"');
  180. 名稱.text = json[index][1].ToString().Trim('"');
  181. 主旨.text = json[index][3].ToString().Trim('"');
  182. if(json[index][5] == true)
  183. {
  184. 已簽 = true;
  185. }
  186. else
  187. {
  188. 已簽 = false;
  189. }
  190. string jsonString = json[index][4].ToString().Trim('"');
  191. 說明.text = Regex.Unescape(jsonString);
  192. Canvas.ForceUpdateCanvases();
  193. LayoutRebuilder.ForceRebuildLayoutImmediate(說明.rectTransform);
  194. StartCoroutine(DelayedHeightCheck());
  195. 主頁.SetActive(false);
  196. 內容頁.SetActive(true);
  197. 上一頁紐.SetActive(true);
  198. if (Main.Global.編號 == "999" || Main.Global.編號 == "18" || Main.Global.編號 == "19" || Main.Global.編號 == "21")
  199. {
  200. 電簽紐.SetActive(false);
  201. }
  202. else
  203. {
  204. 電簽紐.SetActive(true);
  205. }
  206. });
  207. sum += 100;
  208. copy.Add(buttonObj);
  209. }
  210. }
  211. }
  212. RectTransform contentTransform = buttonscroll.content;
  213. contentTransform.anchoredPosition = new Vector2(contentTransform.anchoredPosition.x, 0);
  214. contentTransform.sizeDelta = new Vector2(contentTransform.sizeDelta.x, sum);
  215. if (Main.Global.螢幕格式 == "瘦")
  216. {
  217. if (sum > 1605)
  218. {
  219. buttonscroll.vertical = true;
  220. }
  221. else
  222. {
  223. buttonscroll.vertical = false;
  224. }
  225. }
  226. else
  227. {
  228. if (sum > 1305)
  229. {
  230. buttonscroll.vertical = true;
  231. }
  232. else
  233. {
  234. buttonscroll.vertical = false;
  235. }
  236. }
  237. }
  238. private IEnumerator DelayedHeightCheck()
  239. {
  240. yield return new WaitForEndOfFrame();
  241. Debug.Log("Delayed height check: " + 說明.preferredHeight);
  242. float textWidth = 說明.preferredHeight;
  243. if (Main.Global.螢幕格式 == "瘦")
  244. {
  245. 說明滑動.content.sizeDelta = new Vector2(說明滑動.content.sizeDelta.x, 1207);
  246. }
  247. else
  248. {
  249. 說明滑動.content.sizeDelta = new Vector2(說明滑動.content.sizeDelta.x, 957);
  250. }
  251. float contentWidth = 說明滑動.GetComponent<RectTransform>().rect.height;
  252. 說明滑動.content.anchoredPosition = new Vector2(說明滑動.content.anchoredPosition.x, 0);
  253. if (textWidth > contentWidth)
  254. {
  255. 說明滑動.content.sizeDelta = new Vector2(說明滑動.content.sizeDelta.x, textWidth + 100);
  256. 說明滑動.vertical = true;
  257. }
  258. else
  259. {
  260. 說明滑動.vertical = false;
  261. }
  262. }
  263. private void DeleteCopies(List<GameObject> copyList)
  264. {
  265. foreach (GameObject copy in copyList)
  266. {
  267. Destroy(copy);
  268. }
  269. copyList.Clear();
  270. }
  271. public void 上一頁()
  272. {
  273. 主頁.SetActive(true);
  274. 內容頁.SetActive(false);
  275. 上一頁紐.SetActive(false);
  276. 電簽紐.SetActive(false);
  277. }
  278. public void 彈跳面板關閉()
  279. {
  280. 彈跳面板.SetActive(false);
  281. 彈跳文字.text = "";
  282. }
  283. public void 電簽()
  284. {
  285. if (已簽)
  286. {
  287. 彈跳面板.SetActive(true);
  288. 彈跳文字.text = "已簽過名";
  289. }
  290. else
  291. {
  292. change_Secen(22);
  293. }
  294. }
  295. public void back()
  296. {
  297. change_Secen(2);
  298. }
  299. public void change_Secen(int _screenNum)
  300. {
  301. SceneManager.LoadScene(_screenNum);
  302. }
  303. }