No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

考勤明細表.cs 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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.Data;
  18. using System.Linq;
  19. using System.Runtime.InteropServices;
  20. using System.Globalization;
  21. public class 考勤明細表 : MonoBehaviour
  22. {
  23. public GameObject buttonPrefab;
  24. public Transform buttonParent;
  25. public GameObject buttonceneter;
  26. private List<GameObject> copy = new List<GameObject>();
  27. [SerializeField] GameObject 左鈕;
  28. [SerializeField] GameObject 右鈕;
  29. [SerializeField] TextMeshProUGUI 人員;
  30. [SerializeField] TextMeshProUGUI 年;
  31. [SerializeField] TextMeshProUGUI 月;
  32. public CanvasScaler canvasScaler;
  33. private string loadingText = "";
  34. private int dotCount = 0;
  35. [SerializeField] GameObject 讀取面板;
  36. [SerializeField] TextMeshProUGUI 讀取;
  37. [SerializeField] GameObject 彈跳面板;
  38. [SerializeField] TextMeshProUGUI 彈跳文字;
  39. JSONNode 人員清單;
  40. JSONNode 明細表;
  41. JSONNode 打卡一;
  42. JSONNode 打卡二;
  43. int nd;
  44. int 人員總數;
  45. // Start is called before the first frame update
  46. void Start()
  47. {
  48. Screen.autorotateToPortrait = false;
  49. Screen.orientation = ScreenOrientation.Portrait;
  50. //Main.Global.固高=1900f;
  51. //Main.Global.固寬=900f;
  52. //Main.Global.固比1=1f;
  53. //Main.Global.螢幕格式="瘦";
  54. canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高);
  55. canvasScaler.matchWidthOrHeight=Main.Global.固比;
  56. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/hskin_login.php?";
  57. //Main.Global.預設伺服器路徑="test";
  58. //Main.Global.排班主管權限=true;
  59. //Main.Global.PA="盧婕柔";
  60. //Main.Global.編號="121";
  61. Main.Global.螢幕方向="直";
  62. DateTime currentDate = DateTime.Now;
  63. 年.text = currentDate.Year.ToString();
  64. 月.text = currentDate.Month.ToString("D2");
  65. StartCoroutine(AnimateText());
  66. nd=0;
  67. if (Main.Global.排班主管權限==true)
  68. {
  69. 左鈕.SetActive(true);
  70. 右鈕.SetActive(true);
  71. StartCoroutine(考勤人員清單());
  72. }
  73. else
  74. {
  75. 左鈕.SetActive(false);
  76. 右鈕.SetActive(false);
  77. 人員.text=Main.Global.PA;
  78. StartCoroutine(讀取明細表());
  79. //StartCoroutine(個人月班表());
  80. }
  81. }
  82. IEnumerator AnimateText()
  83. {
  84. string qqq = 讀取.text.ToString();
  85. while (true)
  86. {
  87. yield return new WaitForSeconds(0.5f);
  88. if (dotCount < 3)
  89. {
  90. loadingText += ".";
  91. dotCount++;
  92. }
  93. else
  94. {
  95. loadingText = "";
  96. dotCount = 0;
  97. }
  98. 讀取.text = qqq+loadingText;
  99. }
  100. }
  101. IEnumerator 考勤人員清單()
  102. {
  103. 讀取面板.SetActive(true);
  104. string strcon = "請假申請人員清單";
  105. string se = Main.Global.預設伺服器路徑;
  106. string pa = 月.text;
  107. string pa1 = 年.text;
  108. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  109. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  110. yield return request.SendWebRequest();
  111. if (request.result == UnityWebRequest.Result.ConnectionError)
  112. {
  113. //Debug.Log(request.error);
  114. yield break;
  115. }
  116. 人員清單 = JSON.Parse(request.downloadHandler.text);
  117. 人員總數=人員清單.Count;
  118. if (人員總數>0)
  119. {
  120. if (Main.Global.排班主管權限==true)
  121. {
  122. string str = 人員.text;
  123. for (int i = 0; i < 人員清單.Count; i++)
  124. {
  125. if (人員清單[i][2].ToString().Trim('"') == str)
  126. {
  127. nd = i;
  128. }
  129. }
  130. }
  131. yield return StartCoroutine(讀取明細表());
  132. }
  133. else
  134. {
  135. if (Main.Global.排班主管權限==true)
  136. {
  137. 人員.text = "";
  138. }
  139. if (copy!= null)
  140. {
  141. DeleteCopies(copy);
  142. }
  143. 讀取面板.SetActive(false);
  144. }
  145. }
  146. IEnumerator 讀取明細表()
  147. {
  148. 讀取面板.SetActive(true);
  149. string strcon = "月份考勤明細表";
  150. string se = Main.Global.預設伺服器路徑;
  151. string pa = "";
  152. if (Main.Global.排班主管權限==true)
  153. {
  154. pa = 人員清單[nd][1].ToString().Trim('"');
  155. 人員.text = 人員清單[nd][2].ToString().Trim('"');
  156. }
  157. else
  158. {
  159. pa = Main.Global.編號;
  160. }
  161. string pa1 = 年.text + "/" + 月.text;
  162. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  163. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  164. yield return request.SendWebRequest();
  165. if (request.result == UnityWebRequest.Result.ConnectionError)
  166. {
  167. //Debug.Log(request.error);
  168. yield break;
  169. }
  170. 明細表 = JSON.Parse(request.downloadHandler.text);
  171. for (int i = 0; i < 明細表.Count; i++)
  172. {
  173. if (明細表[i][2]==null)
  174. {
  175. 明細表[i][2]="";
  176. }
  177. 明細表[i][8]="";
  178. 明細表[i][9]="";
  179. 明細表[i][11]="";
  180. 明細表[i][12]="";
  181. 明細表[i][14]="";
  182. 明細表[i][15]="";
  183. }
  184. yield return StartCoroutine(打卡讀取上午上班());
  185. }
  186. IEnumerator 打卡讀取上午上班()
  187. {
  188. string strcon = "打卡讀取上午上班";
  189. string se = Main.Global.預設伺服器路徑;
  190. string pa = "";
  191. if (Main.Global.排班主管權限==true)
  192. {
  193. pa = 人員清單[nd][1].ToString().Trim('"');
  194. }
  195. else
  196. {
  197. pa = Main.Global.編號;
  198. }
  199. string pa1 = 年.text;
  200. string pa2 = 月.text;
  201. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}", strcon, se, pa, pa1, pa2);
  202. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  203. yield return request.SendWebRequest();
  204. if (request.result == UnityWebRequest.Result.ConnectionError)
  205. {
  206. //Debug.Log(request.error);
  207. yield break;
  208. }
  209. 打卡一 = JSON.Parse(request.downloadHandler.text);
  210. yield return StartCoroutine(打卡讀取中午下上班());
  211. }
  212. IEnumerator 打卡讀取中午下上班()
  213. {
  214. string strcon = "打卡讀取中午下上班";
  215. string se = Main.Global.預設伺服器路徑;
  216. string pa = "";
  217. if (Main.Global.排班主管權限==true)
  218. {
  219. pa = 人員清單[nd][1].ToString().Trim('"');
  220. }
  221. else
  222. {
  223. pa = Main.Global.編號;
  224. }
  225. string pa1 = 年.text;
  226. string pa2 = 月.text;
  227. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}", strcon, se, pa, pa1, pa2);
  228. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  229. yield return request.SendWebRequest();
  230. if (request.result == UnityWebRequest.Result.ConnectionError)
  231. {
  232. //Debug.Log(request.error);
  233. yield break;
  234. }
  235. 打卡二 = JSON.Parse(request.downloadHandler.text);
  236. 製表();
  237. 讀取面板.SetActive(false);
  238. }
  239. private void 製表()
  240. {
  241. for (int i = 0; i < 明細表.Count; i++)
  242. {
  243. string str = 明細表[i][0].ToString().Trim('"');
  244. if (打卡一.Count >0)
  245. {
  246. for (int ii = 0; ii < 打卡一.Count; ii++)
  247. {
  248. if (str == 打卡一[ii][1].ToString().Trim('"'))
  249. {
  250. 明細表[i][8]=打卡一[ii][0];
  251. break;
  252. }
  253. else
  254. {
  255. 明細表[i][8]="";
  256. }
  257. }
  258. }
  259. else
  260. {
  261. 明細表[i][8]="";
  262. }
  263. int 數量 = 0;
  264. for (int ii = 0; ii < 打卡二.Count; ii++)
  265. {
  266. if (str == 打卡二[ii][1].ToString().Trim('"'))
  267. {
  268. if (數量 == 0)
  269. {
  270. }
  271. else if (數量 == 1)
  272. {
  273. 明細表[i][9]=打卡二[ii][0];
  274. }
  275. else if (數量 == 2)
  276. {
  277. 明細表[i][11]=打卡二[ii][0];
  278. }
  279. else if (數量 == 3)
  280. {
  281. 明細表[i][12]=打卡二[ii][0];
  282. }
  283. else if (數量 == 4)
  284. {
  285. 明細表[i][14]=打卡二[ii][0];
  286. }
  287. else if (數量 == 5)
  288. {
  289. 明細表[i][15]=打卡二[ii][0];
  290. }
  291. 數量+=1;
  292. }
  293. }
  294. if (明細表[i][9].ToString().Trim('"') == 明細表[i][8].ToString().Trim('"'))
  295. {
  296. 明細表[i][9]="";
  297. }
  298. for (int j = 1; j < 5; j++)
  299. {
  300. if (明細表[i][14].ToString().Trim('"') == "" && 明細表[i][15].ToString().Trim('"') != "")
  301. {
  302. 明細表[i][14]=明細表[i][15];
  303. 明細表[i][15]="";
  304. }
  305. if (明細表[i][12].ToString().Trim('"') == "" && 明細表[i][14].ToString().Trim('"') != "")
  306. {
  307. 明細表[i][12]=明細表[i][14];
  308. 明細表[i][14]="";
  309. }
  310. if (明細表[i][11].ToString().Trim('"') == "" && 明細表[i][12].ToString().Trim('"') != "")
  311. {
  312. 明細表[i][11]=明細表[i][12];
  313. 明細表[i][12]="";
  314. }
  315. if (明細表[i][9].ToString().Trim('"') == "" && 明細表[i][11].ToString().Trim('"') != "")
  316. {
  317. 明細表[i][9]=明細表[i][11];
  318. 明細表[i][11]="";
  319. }
  320. }
  321. }
  322. int sum = 3;
  323. if (copy!= null)
  324. {
  325. DeleteCopies(copy);
  326. }
  327. for (int i = 0; i < 明細表.Count; i++)
  328. {
  329. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  330. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(3, -sum);
  331. buttonObj.transform.SetParent(buttonParent, false);
  332. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  333. Image[] childImages = buttonObj.GetComponentsInChildren<Image>();
  334. string da = 明細表[i][1].ToString().Trim('"');
  335. string da1 = 明細表[i][2].ToString().Trim('"');
  336. if (da=="星期日")
  337. {
  338. foreach (Image childImage in childImages)
  339. {
  340. if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
  341. {
  342. childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
  343. }
  344. }
  345. }
  346. if (da=="星期六")
  347. {
  348. foreach (Image childImage in childImages)
  349. {
  350. if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
  351. {
  352. childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
  353. }
  354. }
  355. }
  356. if (da1=="國定假日")
  357. {
  358. foreach (Image childImage in childImages)
  359. {
  360. if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
  361. {
  362. childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
  363. }
  364. }
  365. }
  366. else if (da1 != "" )
  367. {
  368. foreach (Image childImage in childImages)
  369. {
  370. if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
  371. {
  372. childImage.color = new Color32(255, 255, 130, 255); // 改為紅色,你可以自己更改顏色
  373. }
  374. }
  375. }
  376. text[0].text = 明細表[i][0].ToString().Trim('"');
  377. text[1].text = 明細表[i][1].ToString().Trim('"');
  378. text[2].text = 明細表[i][8].ToString().Trim('"');
  379. text[3].text = 明細表[i][9].ToString().Trim('"');
  380. text[4].text = 明細表[i][11].ToString().Trim('"');
  381. text[5].text = 明細表[i][12].ToString().Trim('"');
  382. sum+=52;
  383. copy.Add(buttonObj);
  384. }
  385. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  386. }
  387. public void 上頁()
  388. {
  389. if (nd < 1)
  390. {
  391. 彈跳面板.SetActive(true);
  392. 彈跳文字.text = "已經是第一筆人員資料!!";
  393. }
  394. else
  395. {
  396. nd = Mathf.Max(0, nd - 1); // 確保不會小於 1
  397. StartCoroutine(讀取明細表());
  398. }
  399. }
  400. public void 下頁()
  401. {
  402. if (nd > 人員總數-2)
  403. {
  404. 彈跳面板.SetActive(true);
  405. 彈跳文字.text = "已經是最後一筆人員資料!!";
  406. }
  407. else
  408. {
  409. nd = Mathf.Min(人員總數-1, nd+1);
  410. StartCoroutine(讀取明細表());
  411. }
  412. }
  413. public void 上月()
  414. {
  415. int y = int.Parse(年.text);
  416. int m = int.Parse(月.text);
  417. if (m != 1)
  418. {
  419. m -=1;
  420. if (m<10)
  421. {
  422. 月.text = "0"+m.ToString();
  423. }
  424. else
  425. {
  426. 月.text = m.ToString();
  427. }
  428. }
  429. else
  430. {
  431. y -=1;
  432. 年.text=y.ToString();
  433. 月.text="12";
  434. }
  435. nd=0;
  436. StartCoroutine(考勤人員清單());
  437. }
  438. public void 下月()
  439. {
  440. int y = int.Parse(年.text);
  441. int m = int.Parse(月.text);
  442. if (m != 12)
  443. {
  444. m +=1;
  445. if (m<10)
  446. {
  447. 月.text = "0"+m.ToString();
  448. }
  449. else
  450. {
  451. 月.text = m.ToString();
  452. }
  453. }
  454. else
  455. {
  456. y +=1;
  457. 年.text=y.ToString();
  458. 月.text="01";
  459. }
  460. nd=0;
  461. StartCoroutine(考勤人員清單());
  462. }
  463. public void 彈跳面板關閉()
  464. {
  465. 彈跳面板.SetActive(false);
  466. 彈跳文字.text = "";
  467. }
  468. private void DeleteCopies(List<GameObject> copyList)
  469. {
  470. foreach (GameObject copy in copyList)
  471. {
  472. Destroy(copy);
  473. }
  474. copyList.Clear();
  475. }
  476. public void back()
  477. {
  478. change_Secen(2);
  479. }
  480. public void 截圖()
  481. {
  482. string fileName = string.Format("{0}/screenshot_{1}.png", Application.persistentDataPath, System.DateTime.Now.ToString("yyyyMMdd_HHmmss"));
  483. ScreenCapture.CaptureScreenshot(fileName);
  484. }
  485. public void change_Secen(int _screenNum)
  486. {
  487. SceneManager.LoadScene(_screenNum);
  488. }
  489. }