123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503 |
- 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.Data;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Globalization;
- public class 考勤明細表 : MonoBehaviour
- {
- public GameObject buttonPrefab;
- public Transform buttonParent;
- public GameObject buttonceneter;
- private List<GameObject> copy = new List<GameObject>();
-
- [SerializeField] GameObject 左鈕;
- [SerializeField] GameObject 右鈕;
- [SerializeField] TextMeshProUGUI 人員;
- [SerializeField] TextMeshProUGUI 年;
- [SerializeField] TextMeshProUGUI 月;
- public CanvasScaler canvasScaler;
- private string loadingText = "";
- private int dotCount = 0;
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
- [SerializeField] GameObject 彈跳面板;
- [SerializeField] TextMeshProUGUI 彈跳文字;
- JSONNode 人員清單;
- JSONNode 明細表;
- JSONNode 打卡一;
- JSONNode 打卡二;
- int nd;
- int 人員總數;
- // Start is called before the first frame update
- void Start()
- {
- Screen.autorotateToPortrait = false;
- Screen.orientation = ScreenOrientation.Portrait;
- //Main.Global.固高=1900f;
- //Main.Global.固寬=900f;
- //Main.Global.固比1=1f;
- //Main.Global.螢幕格式="瘦";
- canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高);
- canvasScaler.matchWidthOrHeight=Main.Global.固比;
- //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/hskin_login.php?";
- //Main.Global.預設伺服器路徑="test";
- //Main.Global.排班主管權限=true;
- //Main.Global.PA="盧婕柔";
- //Main.Global.編號="121";
- Main.Global.螢幕方向="直";
- DateTime currentDate = DateTime.Now;
- 年.text = currentDate.Year.ToString();
- 月.text = currentDate.Month.ToString("D2");
- StartCoroutine(AnimateText());
- nd=0;
- if (Main.Global.排班主管權限==true)
- {
- 左鈕.SetActive(true);
- 右鈕.SetActive(true);
- StartCoroutine(考勤人員清單());
- }
- else
- {
- 左鈕.SetActive(false);
- 右鈕.SetActive(false);
- 人員.text=Main.Global.PA;
- StartCoroutine(讀取明細表());
- //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 考勤人員清單()
- {
- 讀取面板.SetActive(true);
- string strcon = "請假申請人員清單";
- string se = Main.Global.預設伺服器路徑;
- string pa = 月.text;
- string pa1 = 年.text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- 人員清單 = JSON.Parse(request.downloadHandler.text);
- 人員總數=人員清單.Count;
- if (人員總數>0)
- {
- if (Main.Global.排班主管權限==true)
- {
- string str = 人員.text;
- for (int i = 0; i < 人員清單.Count; i++)
- {
- if (人員清單[i][2].ToString().Trim('"') == str)
- {
- nd = i;
- }
- }
- }
- yield return StartCoroutine(讀取明細表());
- }
- else
- {
- if (Main.Global.排班主管權限==true)
- {
-
- 人員.text = "";
- }
- if (copy!= null)
- {
- DeleteCopies(copy);
- }
- 讀取面板.SetActive(false);
- }
- }
- IEnumerator 讀取明細表()
- {
- 讀取面板.SetActive(true);
- string strcon = "月份考勤明細表";
- string se = Main.Global.預設伺服器路徑;
- string pa = "";
- if (Main.Global.排班主管權限==true)
- {
- pa = 人員清單[nd][1].ToString().Trim('"');
- 人員.text = 人員清單[nd][2].ToString().Trim('"');
- }
- else
- {
- pa = Main.Global.編號;
- }
- string pa1 = 年.text + "/" + 月.text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- 明細表 = JSON.Parse(request.downloadHandler.text);
- for (int i = 0; i < 明細表.Count; i++)
- {
- if (明細表[i][2]==null)
- {
- 明細表[i][2]="";
- }
- 明細表[i][8]="";
- 明細表[i][9]="";
- 明細表[i][11]="";
- 明細表[i][12]="";
- 明細表[i][14]="";
- 明細表[i][15]="";
- }
- yield return StartCoroutine(打卡讀取上午上班());
- }
- IEnumerator 打卡讀取上午上班()
- {
- string strcon = "打卡讀取上午上班";
- string se = Main.Global.預設伺服器路徑;
- string pa = "";
- if (Main.Global.排班主管權限==true)
- {
- pa = 人員清單[nd][1].ToString().Trim('"');
- }
- else
- {
- pa = Main.Global.編號;
- }
- string pa1 = 年.text;
- string pa2 = 月.text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}", strcon, se, pa, pa1, pa2);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- 打卡一 = JSON.Parse(request.downloadHandler.text);
- yield return StartCoroutine(打卡讀取中午下上班());
- }
- IEnumerator 打卡讀取中午下上班()
- {
- string strcon = "打卡讀取中午下上班";
- string se = Main.Global.預設伺服器路徑;
- string pa = "";
- if (Main.Global.排班主管權限==true)
- {
- pa = 人員清單[nd][1].ToString().Trim('"');
- }
- else
- {
- pa = Main.Global.編號;
- }
- string pa1 = 年.text;
- string pa2 = 月.text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}", strcon, se, pa, pa1, pa2);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- 打卡二 = JSON.Parse(request.downloadHandler.text);
- 製表();
- 讀取面板.SetActive(false);
- }
- private void 製表()
- {
-
- for (int i = 0; i < 明細表.Count; i++)
- {
- string str = 明細表[i][0].ToString().Trim('"');
- if (打卡一.Count >0)
- {
- for (int ii = 0; ii < 打卡一.Count; ii++)
- {
- if (str == 打卡一[ii][1].ToString().Trim('"'))
- {
- 明細表[i][8]=打卡一[ii][0];
- break;
- }
- else
- {
- 明細表[i][8]="";
- }
- }
- }
- else
- {
- 明細表[i][8]="";
- }
- int 數量 = 0;
- for (int ii = 0; ii < 打卡二.Count; ii++)
- {
- if (str == 打卡二[ii][1].ToString().Trim('"'))
- {
- if (數量 == 0)
- {
-
- }
- else if (數量 == 1)
- {
- 明細表[i][9]=打卡二[ii][0];
- }
- else if (數量 == 2)
- {
- 明細表[i][11]=打卡二[ii][0];
- }
- else if (數量 == 3)
- {
- 明細表[i][12]=打卡二[ii][0];
- }
- else if (數量 == 4)
- {
- 明細表[i][14]=打卡二[ii][0];
- }
- else if (數量 == 5)
- {
- 明細表[i][15]=打卡二[ii][0];
- }
- 數量+=1;
- }
- }
- if (明細表[i][9].ToString().Trim('"') == 明細表[i][8].ToString().Trim('"'))
- {
- 明細表[i][9]="";
- }
- for (int j = 1; j < 5; j++)
- {
- if (明細表[i][14].ToString().Trim('"') == "" && 明細表[i][15].ToString().Trim('"') != "")
- {
- 明細表[i][14]=明細表[i][15];
- 明細表[i][15]="";
- }
- if (明細表[i][12].ToString().Trim('"') == "" && 明細表[i][14].ToString().Trim('"') != "")
- {
- 明細表[i][12]=明細表[i][14];
- 明細表[i][14]="";
- }
- if (明細表[i][11].ToString().Trim('"') == "" && 明細表[i][12].ToString().Trim('"') != "")
- {
- 明細表[i][11]=明細表[i][12];
- 明細表[i][12]="";
- }
- if (明細表[i][9].ToString().Trim('"') == "" && 明細表[i][11].ToString().Trim('"') != "")
- {
- 明細表[i][9]=明細表[i][11];
- 明細表[i][11]="";
- }
- }
- }
- int sum = 3;
- if (copy!= null)
- {
- DeleteCopies(copy);
- }
- for (int i = 0; i < 明細表.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(3, -sum);
- buttonObj.transform.SetParent(buttonParent, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- Image[] childImages = buttonObj.GetComponentsInChildren<Image>();
- string da = 明細表[i][1].ToString().Trim('"');
- string da1 = 明細表[i][2].ToString().Trim('"');
- if (da=="星期日")
- {
- foreach (Image childImage in childImages)
- {
- if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
- {
- childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
- }
-
- }
- }
- if (da=="星期六")
- {
- foreach (Image childImage in childImages)
- {
- if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
- {
- childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
- }
-
- }
- }
- if (da1=="國定假日")
- {
- foreach (Image childImage in childImages)
- {
- if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
- {
- childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
- }
-
- }
- }
- else if (da1 != "" )
- {
- foreach (Image childImage in childImages)
- {
- if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
- {
- childImage.color = new Color32(255, 255, 130, 255); // 改為紅色,你可以自己更改顏色
- }
-
- }
- }
- text[0].text = 明細表[i][0].ToString().Trim('"');
- text[1].text = 明細表[i][1].ToString().Trim('"');
- text[2].text = 明細表[i][8].ToString().Trim('"');
- text[3].text = 明細表[i][9].ToString().Trim('"');
- text[4].text = 明細表[i][11].ToString().Trim('"');
- text[5].text = 明細表[i][12].ToString().Trim('"');
-
- sum+=52;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- }
- public void 上頁()
- {
- if (nd < 1)
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "已經是第一筆人員資料!!";
- }
- else
- {
- nd = Mathf.Max(0, nd - 1); // 確保不會小於 1
- StartCoroutine(讀取明細表());
- }
- }
-
- public void 下頁()
- {
- if (nd > 人員總數-2)
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "已經是最後一筆人員資料!!";
- }
- else
- {
- nd = Mathf.Min(人員總數-1, nd+1);
- StartCoroutine(讀取明細表());
- }
- }
- public void 上月()
- {
- int y = int.Parse(年.text);
- int m = int.Parse(月.text);
- if (m != 1)
- {
- m -=1;
- if (m<10)
- {
- 月.text = "0"+m.ToString();
- }
- else
- {
- 月.text = m.ToString();
- }
- }
- else
- {
- y -=1;
- 年.text=y.ToString();
- 月.text="12";
- }
- nd=0;
- StartCoroutine(考勤人員清單());
- }
- public void 下月()
- {
- int y = int.Parse(年.text);
- int m = int.Parse(月.text);
- if (m != 12)
- {
- m +=1;
- if (m<10)
- {
- 月.text = "0"+m.ToString();
- }
- else
- {
- 月.text = m.ToString();
- }
- }
- else
- {
- y +=1;
- 年.text=y.ToString();
- 月.text="01";
- }
- nd=0;
- StartCoroutine(考勤人員清單());
- }
- public void 彈跳面板關閉()
- {
- 彈跳面板.SetActive(false);
- 彈跳文字.text = "";
- }
- private void DeleteCopies(List<GameObject> copyList)
- {
- foreach (GameObject copy in copyList)
- {
- Destroy(copy);
- }
- copyList.Clear();
- }
- public void back()
- {
- change_Secen(2);
- }
- public void 截圖()
- {
- string fileName = string.Format("{0}/screenshot_{1}.png", Application.persistentDataPath, System.DateTime.Now.ToString("yyyyMMdd_HHmmss"));
- ScreenCapture.CaptureScreenshot(fileName);
- }
- public void change_Secen(int _screenNum)
- {
-
- SceneManager.LoadScene(_screenNum);
- }
- }
|