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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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] GameObject 切換;
  21. [SerializeField] GameObject 查看;
  22. [SerializeField] GameObject 核准;
  23. [SerializeField] GameObject 查頁;
  24. public TMP_Dropdown 年;
  25. [SerializeField] RawImage 放圖用;
  26. [SerializeField] GameObject 主頁;
  27. [SerializeField] GameObject 圖頁;
  28. public GameObject buttonPrefab;
  29. public Transform buttonParent;
  30. public GameObject buttonceneter;
  31. private List<GameObject> copy = new List<GameObject>();
  32. public GameObject buttonPrefab1;
  33. public Transform buttonParent1;
  34. public GameObject buttonceneter1;
  35. private List<GameObject> copy1 = new List<GameObject>();
  36. [SerializeField] TextMeshProUGUI 假別;
  37. [SerializeField] TextMeshProUGUI 日期;
  38. [SerializeField] TextMeshProUGUI 申請人;
  39. [SerializeField] TextMeshProUGUI 編號;
  40. [SerializeField] TextMeshProUGUI 事由;
  41. [SerializeField] TextMeshProUGUI 申請人1;
  42. [SerializeField] TextMeshProUGUI 編號1;
  43. public CanvasScaler canvasScaler;
  44. [SerializeField] GameObject 讀取面板;
  45. [SerializeField] TextMeshProUGUI 讀取;
  46. [SerializeField] GameObject 彈跳面板;
  47. [SerializeField] TextMeshProUGUI 彈跳文字;
  48. private string loadingText = "";
  49. private int dotCount = 0;
  50. string 選擇資料庫;
  51. string 選擇流水號;
  52. void Start()
  53. {
  54. Screen.autorotateToPortrait = false;
  55. Screen.orientation = ScreenOrientation.Portrait;
  56. Main.Global.螢幕方向="直";
  57. //Main.Global.固高=1900f;
  58. //Main.Global.固寬=900f;
  59. //Main.Global.固比=1f;
  60. //Main.Global.螢幕格式="瘦";
  61. //Main.Global.PA="侯宜伶";
  62. canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高);
  63. canvasScaler.matchWidthOrHeight=Main.Global.固比;
  64. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/hskin_login.php?";
  65. //Main.Global.預設伺服器路徑="test";
  66. 主頁.SetActive(true);
  67. 圖頁.SetActive(false);
  68. 切換.SetActive(false);
  69. 查看.SetActive(false);
  70. 查頁.SetActive(false);
  71. 核准.SetActive(false);
  72. StartCoroutine(AnimateText());
  73. StartCoroutine(年份清單());
  74. StartCoroutine(休假核准清單());
  75. }
  76. IEnumerator AnimateText()
  77. {
  78. string qqq = 讀取.text.ToString();
  79. while (true)
  80. {
  81. yield return new WaitForSeconds(0.5f);
  82. if (dotCount < 3)
  83. {
  84. loadingText += ".";
  85. dotCount++;
  86. }
  87. else
  88. {
  89. loadingText = "";
  90. dotCount = 0;
  91. }
  92. 讀取.text = qqq+loadingText;
  93. }
  94. }
  95. IEnumerator 年份清單()
  96. {
  97. string strcon = "年份清單";
  98. string se = Main.Global.預設伺服器路徑;
  99. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  100. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  101. yield return request.SendWebRequest();
  102. if (request.result == UnityWebRequest.Result.ConnectionError)
  103. {
  104. //Debug.Log(request.error);
  105. yield break;
  106. }
  107. JSONNode json = JSON.Parse(request.downloadHandler.text);
  108. 年.options.Clear();
  109. List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
  110. for (int i = 0; i < json.Count; i++)
  111. {
  112. string str = json[i].ToString().Trim('"');
  113. options.Add(new TMP_Dropdown.OptionData(str));
  114. }
  115. 年.AddOptions(options);
  116. DateTime currentDate = DateTime.Now;
  117. string year = currentDate.Year.ToString();
  118. int currentIndex = 年.options.FindIndex(option => option.text == year);
  119. 年.value = currentIndex;
  120. 年.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
  121. }
  122. private void OnDropdown1ValueChanged()
  123. {
  124. StartCoroutine(休假統計());
  125. }
  126. IEnumerator 休假核准清單()
  127. {
  128. 讀取面板.SetActive(true);
  129. if (copy!= null)
  130. {
  131. DeleteCopies(copy);
  132. }
  133. string strcon = "休假核准清單";
  134. string se = Main.Global.預設伺服器路徑;
  135. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  136. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  137. yield return request.SendWebRequest();
  138. if (request.result == UnityWebRequest.Result.ConnectionError)
  139. {
  140. //Debug.Log(request.error);
  141. yield break;
  142. }
  143. JSONNode json = JSON.Parse(request.downloadHandler.text);
  144. int sum = 5;
  145. for (int i = 0; i < json.Count; i++)
  146. {
  147. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  148. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  149. buttonObj.transform.SetParent(buttonParent, false);
  150. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  151. SetTextValue(text[0], json[i][0]);
  152. SetTextValue(text[1], json[i][1]);
  153. SetTextValue(text[2], json[i][2]);
  154. SetTextValue(text[3], json[i][3]);
  155. SetTextValue(text[4], json[i][4]);
  156. SetTextValue(text[5], json[i][5]);
  157. Button bt = buttonObj.GetComponentInChildren<Button>();
  158. int index = i;
  159. bt.onClick.AddListener(() =>
  160. {
  161. SetTextValue(申請人, json[index][0]);
  162. SetTextValue(編號, json[index][1]);
  163. SetTextValue(申請人1, json[index][0]);
  164. SetTextValue(編號1, json[index][1]);
  165. SetTextValue(日期, json[index][2]);
  166. SetTextValue(假別, json[index][4]);
  167. SetTextValue(事由, json[index][5]);
  168. 主頁.SetActive(false);
  169. 圖頁.SetActive(true);
  170. 切換.SetActive(true);
  171. 查看.SetActive(true);
  172. 查頁.SetActive(false);
  173. 核准.SetActive(true);
  174. if (json[index][9] ==null )
  175. {
  176. 選擇資料庫="";
  177. }
  178. else
  179. {
  180. 選擇資料庫=json[index][9].ToString().Trim('"');
  181. }
  182. if (json[index][10] ==null)
  183. {
  184. 選擇流水號="";
  185. }
  186. else
  187. {
  188. 選擇流水號=json[index][10].ToString().Trim('"');
  189. }
  190. if (選擇資料庫 !="" && 選擇流水號 !="")
  191. {
  192. 讀取圖片();
  193. }
  194. else
  195. {
  196. 放圖用.texture =Texture2D.blackTexture;
  197. }
  198. StartCoroutine(休假統計());
  199. });
  200. sum+=75;
  201. copy.Add(buttonObj);
  202. }
  203. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  204. 讀取面板.SetActive(false);
  205. }
  206. IEnumerator 休假統計()
  207. {
  208. if (copy1!= null)
  209. {
  210. DeleteCopies(copy1);
  211. }
  212. string strcon = "休假統計";
  213. string se = Main.Global.預設伺服器路徑;
  214. string pa = 編號1.text;
  215. string pa1= 年.options[年.value].text;
  216. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se,pa,pa1);
  217. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  218. yield return request.SendWebRequest();
  219. if (request.result == UnityWebRequest.Result.ConnectionError)
  220. {
  221. //Debug.Log(request.error);
  222. yield break;
  223. }
  224. JSONNode json = JSON.Parse(request.downloadHandler.text);
  225. int sum = 5;
  226. for (int i = 0; i < json.Count; i++)
  227. {
  228. GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
  229. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  230. buttonObj.transform.SetParent(buttonParent1, false);
  231. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  232. SetTextValue(text[0], json[i][0]);
  233. SetTextValue(text[1], json[i][1]);
  234. SetTextValue(text[2], json[i][2]);
  235. sum+=50;
  236. copy1.Add(buttonObj);
  237. }
  238. buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
  239. }
  240. public void 讀取圖片()
  241. {
  242. string ip = "";
  243. if (Main.Global.預設伺服器路徑=="test")
  244. {
  245. ip="106.1.48.106,4567";
  246. }
  247. else
  248. {
  249. ip="mssql-147629-0.cloudclusters.net,12711";
  250. }
  251. string connectionString = "Data Source="+ ip +";Initial Catalog="+ 選擇資料庫 +";User ID=B70340;Password=Lee0911274990";
  252. Debug.Log(connectionString);
  253. using (SqlConnection connection = new SqlConnection(connectionString))
  254. {
  255. try
  256. {
  257. connection.Open();
  258. string query = "SELECT 圖片 FROM 請假圖片庫 WHERE 流水號 LIKE '" + 選擇流水號 + "'";
  259. using (SqlCommand command = new SqlCommand(query, connection))
  260. {
  261. using (SqlDataReader reader = command.ExecuteReader())
  262. {
  263. if (reader.Read())
  264. {
  265. // 讀取圖片的二進位資料
  266. byte[] imageData = (byte[])reader["圖片"];
  267. // 將二進位資料轉換為 Texture2D
  268. Texture2D texture = new Texture2D(1, 1);
  269. texture.LoadImage(imageData);
  270. // 將 Texture2D 設置為 RawImage 的 texture
  271. 放圖用.texture = texture;
  272. float aspectRatio = (float)texture.width / texture.height;
  273. float newWidth = Mathf.Min(720f, 放圖用.rectTransform.rect.width);
  274. float newHeight = newWidth / aspectRatio;
  275. 放圖用.rectTransform.sizeDelta = new Vector2(newWidth, newHeight);
  276. }
  277. }
  278. }
  279. }
  280. catch (Exception ex)
  281. {
  282. Debug.LogError("Error connecting to the database: " + ex.Message);
  283. 彈跳面板.SetActive(true);
  284. 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
  285. }
  286. finally
  287. {
  288. connection.Close();
  289. }
  290. }
  291. }
  292. private void SetTextValue(TextMeshProUGUI text, string value)
  293. {
  294. if (value == null)
  295. {
  296. text.text = "";
  297. }
  298. else
  299. {
  300. string jsonString = value.Trim('"');
  301. string unescapedString = Regex.Unescape(jsonString);
  302. text.text = unescapedString;
  303. }
  304. }
  305. public void 核准紐()
  306. {
  307. if (日期.text != "" && 編號.text != "")
  308. {
  309. StartCoroutine(休假核准());
  310. }
  311. else
  312. {
  313. 彈跳面板.SetActive(false);
  314. 彈跳文字.text = "未選擇日期";
  315. }
  316. }
  317. IEnumerator 休假核准()
  318. {
  319. 讀取面板.SetActive(true);
  320. string strcon = "休假修改";
  321. string se = Main.Global.預設伺服器路徑;
  322. string pa = Main.Global.PA;
  323. DateTime currentDate = DateTime.Now;
  324. string pa1 = currentDate.ToString("yyyy/MM/dd");
  325. string pa2 = 日期.text;
  326. string pa3 = 編號.text;
  327. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}&PA3={5}",strcon,se,pa,pa1,pa2,pa3);
  328. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  329. yield return request.SendWebRequest();
  330. if (request.result == UnityWebRequest.Result.ConnectionError)
  331. {
  332. //Debug.Log(request.error);
  333. yield break;
  334. }
  335. 圖頁.SetActive(false);
  336. 主頁.SetActive(true);
  337. 切換.SetActive(false);
  338. 查看.SetActive(false);
  339. 查頁.SetActive(false);
  340. 核准.SetActive(false);
  341. 彈跳面板.SetActive(true);
  342. 彈跳文字.text = "核准成功";
  343. StartCoroutine(休假核准清單());
  344. }
  345. public void 清單紐()
  346. {
  347. if (主頁.activeSelf && !圖頁.activeSelf)
  348. {
  349. 主頁.SetActive(false);
  350. 圖頁.SetActive(true);
  351. 切換.SetActive(true);
  352. 查看.SetActive(true);
  353. 查頁.SetActive(false);
  354. 核准.SetActive(true);
  355. }
  356. else if (圖頁.activeSelf && !主頁.activeSelf)
  357. {
  358. 圖頁.SetActive(false);
  359. 主頁.SetActive(true);
  360. 切換.SetActive(false);
  361. 查看.SetActive(false);
  362. 查頁.SetActive(false);
  363. 核准.SetActive(false);
  364. }
  365. }
  366. public void 查看紐()
  367. {
  368. if (查頁.activeSelf && !圖頁.activeSelf)
  369. {
  370. 主頁.SetActive(false);
  371. 圖頁.SetActive(true);
  372. 切換.SetActive(true);
  373. 查看.SetActive(true);
  374. 查頁.SetActive(false);
  375. 核准.SetActive(true);
  376. }
  377. else if (圖頁.activeSelf && !查頁.activeSelf)
  378. {
  379. 圖頁.SetActive(false);
  380. 主頁.SetActive(false);
  381. 切換.SetActive(false);
  382. 查看.SetActive(true);
  383. 查頁.SetActive(true);
  384. 核准.SetActive(false);
  385. }
  386. }
  387. public void 彈跳面板關閉()
  388. {
  389. 彈跳面板.SetActive(false);
  390. 彈跳文字.text = "";
  391. }
  392. private void DeleteCopies(List<GameObject> copyList)
  393. {
  394. foreach (GameObject copy in copyList)
  395. {
  396. Destroy(copy);
  397. }
  398. copyList.Clear();
  399. }
  400. public void back()
  401. {
  402. change_Secen(2);
  403. }
  404. public void change_Secen(int _screenNum)
  405. {
  406. SceneManager.LoadScene(_screenNum);
  407. }
  408. }