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 copy = new List(); public GameObject buttonPrefab1; public Transform buttonParent1; public GameObject buttonceneter1; private List copy1 = new List(); public GameObject buttonPrefab2; [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 人員清單; JSONArray 班表; int nd; int 人員總數; void Start() { Screen.autorotateToPortrait = false; Screen.orientation = ScreenOrientation.LandscapeLeft; //Main.Global.固高=1900f; //Main.Global.固寬=900f; //Main.Global.固比1=1f; //Main.Global.螢幕格式="瘦"; canvasScaler.referenceResolution = new Vector2(Main.Global.固高,Main.Global.固寬); canvasScaler.matchWidthOrHeight=Main.Global.固比1; //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.螢幕方向="橫"; 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(個人月班表()); } } 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 +"/" + 月.text; string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}", strcon, se, pa); 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 (Main.Global.排班主管權限==true) { string str = 人員.text; for (int i = 0; i < 人員清單.Count; i++) { if (人員清單[i][0].ToString().Trim('"') == str) { nd = i; } } } yield return StartCoroutine(個人月班表()); } IEnumerator 個人月班表() { 讀取面板.SetActive(true); string pa1 = ""; if (Main.Global.排班主管權限==true) { if (人員清單.Count<1) { 人員.text=""; } else { 人員.text =人員清單[nd][0].ToString().Trim('"'); } pa1 = 人員清單[nd][0].ToString().Trim('"'); } else { pa1 = 人員.text; } string strcon = "個人月班表"; string se = Main.Global.預設伺服器路徑; string pa = 年.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; } JSONNode json = JSON.Parse(request.downloadHandler.text); 班表 = new JSONArray(); for (int i = 1; i < 32; i++) { JSONNode newValue = new JSONObject(); string str = ""; if (i<10) { str ="0"+i.ToString(); } else { str = i.ToString(); } newValue["日期"]= str; newValue["姓名"]= ""; newValue["班別"]= ""; newValue["上班時段"]= ""; newValue["時數"]= ""; newValue["半天"]= ""; newValue["休息"]= ""; newValue["一段"]= ""; newValue["二段"]= ""; newValue["顏色1"]= ""; newValue["顏色2"]= ""; newValue["星期"]= ""; newValue["鎖定"]= ""; newValue["後段"]= ""; for (int j = 0; j < json.Count; j++) { string str1 = json[j][0].ToString().Trim('"'); if (str == str1) { newValue["姓名"]= json[j][1].ToString().Trim('"'); newValue["班別"]= json[j][2].ToString().Trim('"'); newValue["上班時段"]= json[j][3].ToString().Trim('"'); newValue["時數"]= json[j][4].ToString().Trim('"'); newValue["半天"]= json[j][5].ToString().Trim('"'); newValue["休息"]= json[j][6].ToString().Trim('"'); newValue["一段"]= json[j][7].ToString().Trim('"'); newValue["二段"]= json[j][8].ToString().Trim('"'); newValue["顏色1"]= json[j][9].ToString().Trim('"'); newValue["顏色2"]= json[j][10].ToString().Trim('"'); newValue["後段"]= json[j][11].ToString().Trim('"'); } } 班表.Add(newValue); } yield return StartCoroutine(整月星期讀取()); } IEnumerator 整月星期讀取() { string strcon = "整月星期讀取"; string se = Main.Global.預設伺服器路徑; string pa = 年.text +"/" + 月.text; string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}", strcon, se, pa); 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); for (int i = 0; i < json.Count; i++) { 班表[i][11]= json[i][0].ToString().Trim('"'); 班表[i][12]= json[i][1].ToString().Trim('"'); } int sum = 3; if (copy!= null) { DeleteCopies(copy); } if (copy1!= null) { DeleteCopies(copy1); } for (int i = 0; i < 班表.Count; i++) { GameObject buttonObj = Instantiate(buttonPrefab) as GameObject; buttonObj.GetComponent().anchoredPosition = new Vector2(3, -sum); buttonObj.transform.SetParent(buttonParent, false); TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren(); text[0].text = 班表[i][0].ToString().Trim('"'); text[1].text = 班表[i][11].ToString().Trim('"'); if (班表[i][2].ToString().Trim('"') == "") { text[2].text = "休"; } else { text[2].text = 班表[i][2].ToString().Trim('"'); } GameObject buttonObj1 = Instantiate(buttonPrefab1) as GameObject; float 初始 = 0; if (Main.Global.螢幕格式=="胖") { 初始 = 242.75f; } else { 初始 = 281.5f; } buttonObj1.GetComponent().anchoredPosition = new Vector2(初始, -sum); buttonObj1.transform.SetParent(buttonParent1, false); if (Main.Global.排班主管權限==true) { if (班表[i][2].ToString().Trim('"')!= "" && 班表[i][2].ToString().Trim('"') != "休") { string 開始時段 = 班表[i][3].ToString().Trim('"'); DateTime time1 = DateTime.ParseExact("08:00:00", "HH:mm:ss", CultureInfo.InvariantCulture); DateTime time2 = DateTime.ParseExact(開始時段, "HH:mm:ss", CultureInfo.InvariantCulture); int hoursDiff = (int)time2.Subtract(time1).TotalMinutes; int 商 = hoursDiff / 30; // 整數除法,得到商 int 餘 = hoursDiff % 30; // 餘數運算,得到餘數 float 商f = (float)商; float 餘f = (float)餘; float 總 = 0; if (Main.Global.螢幕格式=="胖") { 總 = 1+(商f*41.5f) +(餘*40.5f/30); } else { 總 = 1+(商f*48) +(餘*47/30); } double 時數 = double.Parse(班表[i][4].ToString().Trim('"')); float 時數f = (float)時數; double 後段 = double.Parse(班表[i][13].ToString().Trim('"')); 後段 = 4 -後段; float 時數1f = (float)(8-時數-後段); float 總時 = 0; float 總時1 = 0; if (Main.Global.螢幕格式=="胖") { 總時 = (時數f*83) -1; 總時1 = (時數1f*83) -1; } else { 總時 = (時數f*96) -1; 總時1 = (時數1f*96) -1; } double 休息 = double.Parse(班表[i][6].ToString().Trim('"')); 休息 = 休息*60; int 休息1 = (int)休息; int 商2 = 休息1 / 30; // 整數除法,得到商 int 餘2 = 休息1 % 30; float 商1f = (float)商2; float 餘1f = (float)餘2; float 總2 = 0; if (Main.Global.螢幕格式=="胖") { 總2 = 1+總+總時+(商1f*41.5f) +(餘1f*40.5f/30); } else { 總2 = 1+總+總時+(商1f*48) +(餘1f*47/30); } float 長 = 0; float 長B = 0; if (Main.Global.螢幕格式=="胖") { 長 = 25f; 長B = -2f; } else { 長 = 40f; 長B = -4.5f; } if (班表[i][5]=="1") { GameObject buttonObj2 = Instantiate(buttonPrefab2) as GameObject; buttonObj2.GetComponent().sizeDelta = new Vector2(總時, 長);// 修改大小 buttonObj2.GetComponent().anchoredPosition = new Vector2(總, 長B); // 修改初始位置 buttonObj2.transform.SetParent(buttonObj1.transform, false); TextMeshProUGUI texts = buttonObj2.GetComponentInChildren(); texts.text =班表[i][7].ToString().Trim('"'); Image im = buttonObj2.GetComponentInChildren(); string col = 班表[i][9].ToString().Trim('"'); switch (col) { case "0": im.color = new Color32(128, 128, 128, 255); break; case "1": im.color = new Color32(124, 252, 0, 255); break; case "2": im.color = new Color32(173, 216, 230, 255); break; case "3": im.color = new Color32(240, 128, 128, 255); break; case "4": im.color = new Color32(224, 255, 255, 255); break; case "5": im.color = new Color32(250, 250, 210, 255); break; case "6": im.color = new Color32(211, 211, 211, 255); break; case "7": im.color = new Color32(144, 238, 144, 255); break; case "8": im.color = new Color32(255, 182, 193, 255); break; case "9": im.color = new Color32(255, 160, 122, 255); break; default: im.color = new Color32(255, 255, 255, 255); // 預設白色 break; } } else { GameObject buttonObj2 = Instantiate(buttonPrefab2) as GameObject; buttonObj2.GetComponent().sizeDelta = new Vector2(總時, 長);// 修改大小 buttonObj2.GetComponent().anchoredPosition = new Vector2(總, 長B); // 修改初始位置 buttonObj2.transform.SetParent(buttonObj1.transform, false); TextMeshProUGUI texts = buttonObj2.GetComponentInChildren(); texts.text =班表[i][7].ToString().Trim('"'); Image im = buttonObj2.GetComponentInChildren(); string col = 班表[i][9].ToString().Trim('"'); switch (col) { case "0": im.color = new Color32(128, 128, 128, 255); break; case "1": im.color = new Color32(124, 252, 0, 255); break; case "2": im.color = new Color32(173, 216, 230, 255); break; case "3": im.color = new Color32(240, 128, 128, 255); break; case "4": im.color = new Color32(224, 255, 255, 255); break; case "5": im.color = new Color32(250, 250, 210, 255); break; case "6": im.color = new Color32(211, 211, 211, 255); break; case "7": im.color = new Color32(144, 238, 144, 255); break; case "8": im.color = new Color32(255, 182, 193, 255); break; case "9": im.color = new Color32(255, 160, 122, 255); break; default: im.color = new Color32(255, 255, 255, 255); // 預設白色 break; } GameObject buttonObj3 = Instantiate(buttonPrefab2) as GameObject; buttonObj3.GetComponent().sizeDelta = new Vector2(總時1, 長);// 修改大小 buttonObj3.GetComponent().anchoredPosition = new Vector2(總2, 長B); // 修改初始位置 buttonObj3.transform.SetParent(buttonObj1.transform, false); TextMeshProUGUI texts1 = buttonObj3.GetComponentInChildren(); texts1.text =班表[i][8].ToString().Trim('"'); Image im1 = buttonObj3.GetComponentInChildren(); string col1 = 班表[i][10].ToString().Trim('"'); switch (col1) { case "0": im1.color = new Color32(128, 128, 128, 255); break; case "1": im1.color = new Color32(124, 252, 0, 255); break; case "2": im1.color = new Color32(173, 216, 230, 255); break; case "3": im1.color = new Color32(240, 128, 128, 255); break; case "4": im1.color = new Color32(224, 255, 255, 255); break; case "5": im1.color = new Color32(250, 250, 210, 255); break; case "6": im1.color = new Color32(211, 211, 211, 255); break; case "7": im1.color = new Color32(144, 238, 144, 255); break; case "8": im1.color = new Color32(255, 182, 193, 255); break; case "9": im1.color = new Color32(255, 160, 122, 255); break; default: im1.color = new Color32(255, 255, 255, 255); // 預設白色 break; } } } } else { if (班表[i][2].ToString().Trim('"')!= "" && 班表[i][2].ToString().Trim('"') != "休" && 班表[i][12].ToString().Trim('"') == "Y") { string 開始時段 = 班表[i][3].ToString().Trim('"'); DateTime time1 = DateTime.ParseExact("08:00:00", "HH:mm:ss", CultureInfo.InvariantCulture); DateTime time2 = DateTime.ParseExact(開始時段, "HH:mm:ss", CultureInfo.InvariantCulture); int hoursDiff = (int)time2.Subtract(time1).TotalMinutes; int 商 = hoursDiff / 30; // 整數除法,得到商 int 餘 = hoursDiff % 30; // 餘數運算,得到餘數 float 商f = (float)商; float 餘f = (float)餘; float 總 = 0; if (Main.Global.螢幕格式=="胖") { 總 = 1+(商f*41.5f) +(餘*40.5f/30); } else { 總 = 1+(商f*48) +(餘*47/30); } double 時數 = double.Parse(班表[i][4].ToString().Trim('"')); float 時數f = (float)時數; double 後段 = double.Parse(班表[i][13].ToString().Trim('"')); 後段 = 4 -後段; float 時數1f = (float)(8-時數-後段); float 總時 = 0; float 總時1 = 0; if (Main.Global.螢幕格式=="胖") { 總時 = (時數f*83) -1; 總時1 = (時數1f*83) -1; } else { 總時 = (時數f*96) -1; 總時1 = (時數1f*96) -1; } double 休息 = double.Parse(班表[i][6].ToString().Trim('"')); 休息 = 休息*60; int 休息1 = (int)休息; int 商2 = 休息1 / 30; // 整數除法,得到商 int 餘2 = 休息1 % 30; float 商1f = (float)商2; float 餘1f = (float)餘2; float 總2 = 0; if (Main.Global.螢幕格式=="胖") { 總2 = 1+總+總時+(商1f*41.5f) +(餘1f*40.5f/30); } else { 總2 = 1+總+總時+(商1f*48) +(餘1f*47/30); } float 長 = 0; float 長B = 0; if (Main.Global.螢幕格式=="胖") { 長 = 25f; 長B = -2f; } else { 長 = 40f; 長B = -4.5f; } if (班表[i][5]=="1") { GameObject buttonObj2 = Instantiate(buttonPrefab2) as GameObject; buttonObj2.GetComponent().sizeDelta = new Vector2(總時, 長);// 修改大小 buttonObj2.GetComponent().anchoredPosition = new Vector2(總, 長B); // 修改初始位置 buttonObj2.transform.SetParent(buttonObj1.transform, false); TextMeshProUGUI texts = buttonObj2.GetComponentInChildren(); texts.text =班表[i][7].ToString().Trim('"'); Image im = buttonObj2.GetComponentInChildren(); string col = 班表[i][9].ToString().Trim('"'); switch (col) { case "0": im.color = new Color32(128, 128, 128, 255); break; case "1": im.color = new Color32(124, 252, 0, 255); break; case "2": im.color = new Color32(173, 216, 230, 255); break; case "3": im.color = new Color32(240, 128, 128, 255); break; case "4": im.color = new Color32(224, 255, 255, 255); break; case "5": im.color = new Color32(250, 250, 210, 255); break; case "6": im.color = new Color32(211, 211, 211, 255); break; case "7": im.color = new Color32(144, 238, 144, 255); break; case "8": im.color = new Color32(255, 182, 193, 255); break; case "9": im.color = new Color32(255, 160, 122, 255); break; default: im.color = new Color32(255, 255, 255, 255); // 預設白色 break; } } else { GameObject buttonObj2 = Instantiate(buttonPrefab2) as GameObject; buttonObj2.GetComponent().sizeDelta = new Vector2(總時, 長);// 修改大小 buttonObj2.GetComponent().anchoredPosition = new Vector2(總, 長B); // 修改初始位置 buttonObj2.transform.SetParent(buttonObj1.transform, false); TextMeshProUGUI texts = buttonObj2.GetComponentInChildren(); texts.text =班表[i][7].ToString().Trim('"'); Image im = buttonObj2.GetComponentInChildren(); string col = 班表[i][9].ToString().Trim('"'); switch (col) { case "0": im.color = new Color32(128, 128, 128, 255); break; case "1": im.color = new Color32(124, 252, 0, 255); break; case "2": im.color = new Color32(173, 216, 230, 255); break; case "3": im.color = new Color32(240, 128, 128, 255); break; case "4": im.color = new Color32(224, 255, 255, 255); break; case "5": im.color = new Color32(250, 250, 210, 255); break; case "6": im.color = new Color32(211, 211, 211, 255); break; case "7": im.color = new Color32(144, 238, 144, 255); break; case "8": im.color = new Color32(255, 182, 193, 255); break; case "9": im.color = new Color32(255, 160, 122, 255); break; default: im.color = new Color32(255, 255, 255, 255); // 預設白色 break; } GameObject buttonObj3 = Instantiate(buttonPrefab2) as GameObject; buttonObj3.GetComponent().sizeDelta = new Vector2(總時1, 長);// 修改大小 buttonObj3.GetComponent().anchoredPosition = new Vector2(總2, 長B); // 修改初始位置 buttonObj3.transform.SetParent(buttonObj1.transform, false); TextMeshProUGUI texts1 = buttonObj3.GetComponentInChildren(); texts1.text =班表[i][8].ToString().Trim('"'); Image im1 = buttonObj3.GetComponentInChildren(); string col1 = 班表[i][10].ToString().Trim('"'); switch (col1) { case "0": im1.color = new Color32(128, 128, 128, 255); break; case "1": im1.color = new Color32(124, 252, 0, 255); break; case "2": im1.color = new Color32(173, 216, 230, 255); break; case "3": im1.color = new Color32(240, 128, 128, 255); break; case "4": im1.color = new Color32(224, 255, 255, 255); break; case "5": im1.color = new Color32(250, 250, 210, 255); break; case "6": im1.color = new Color32(211, 211, 211, 255); break; case "7": im1.color = new Color32(144, 238, 144, 255); break; case "8": im1.color = new Color32(255, 182, 193, 255); break; case "9": im1.color = new Color32(255, 160, 122, 255); break; default: im1.color = new Color32(255, 255, 255, 255); // 預設白色 break; } } } } if (Main.Global.螢幕格式=="胖") { sum+=30; } else { sum+=50; } copy.Add(buttonObj); copy1.Add(buttonObj1); } buttonceneter.GetComponent().sizeDelta = new Vector2(buttonceneter.GetComponent().sizeDelta.x, sum); 讀取面板.SetActive(false); } 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 copyList) { foreach (GameObject copy in copyList) { Destroy(copy); } copyList.Clear(); } public void back() { change_Secen(3); } public void change_Secen(int _screenNum) { SceneManager.LoadScene(_screenNum); } }