123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- 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>();
-
- public GameObject buttonPrefab1;
- public Transform buttonParent1;
- public GameObject buttonceneter1;
- private List<GameObject> copy1 = new List<GameObject>();
-
- public GameObject buttonPrefab2;
-
- [SerializeField] TextMeshProUGUI 健保1;
- [SerializeField] TextMeshProUGUI 健保2;
- [SerializeField] TextMeshProUGUI 健保3;
- [SerializeField] TextMeshProUGUI 美容1;
- [SerializeField] TextMeshProUGUI 美容2;
- [SerializeField] TextMeshProUGUI 美容3;
-
- [SerializeField] TextMeshProUGUI 年;
- [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 班表;
- void Start()
- {
- Screen.autorotateToPortrait = false;
- Screen.orientation = ScreenOrientation.LandscapeLeft;
- //Main.Global.固高=1600f;
- //Main.Global.固寬=1000f;
- //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.螢幕方向="橫";
- DateTime currentDate = DateTime.Now;
- 年.text = currentDate.Year.ToString();
- 月.text = currentDate.Month.ToString("D2");
- 日.text = currentDate.Day.ToString("D2");
- StartCoroutine(AnimateText());
- 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 +"/" + 日.text;
- string pa1 = "健保";
- 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;
- }
- string pa2 = "醫美";
- string strUrl1 = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa2);
- UnityWebRequest request1 = UnityWebRequest.Get(strUrl1);
- yield return request1.SendWebRequest();
- if (request1.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- JSONNode json = JSON.Parse(request.downloadHandler.text);
- JSONNode json1 = JSON.Parse(request1.downloadHandler.text);
- if (json.Count<1)
- {
- 健保1.text="";
- 健保2.text="";
- 健保3.text="";
- }
- else
- {
- 健保1.text=json[0][2].ToString().Trim('"');
- 健保2.text=json[0][3].ToString().Trim('"');
- 健保3.text=json[0][4].ToString().Trim('"');
- }
- if (json1.Count<1)
- {
- 美容1.text="";
- 美容2.text="";
- 美容3.text="";
- }
- else
- {
- 美容1.text=json1[0][2].ToString().Trim('"');
- 美容2.text=json1[0][3].ToString().Trim('"');
- 美容3.text=json1[0][4].ToString().Trim('"');
- }
-
- yield return StartCoroutine(星期讀取());
- }
- IEnumerator 星期讀取()
- {
- string strcon = "星期讀取";
- string se = Main.Global.預設伺服器路徑;
- string pa = 年.text +"/" + 月.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);
- 星期.text=json[0].ToString().Trim('"');
- yield return StartCoroutine(排班明細班別());
- }
- IEnumerator 排班明細班別()
- {
- string strcon = "排班明細班別";
- string se = Main.Global.預設伺服器路徑;
- string pa = 年.text +"/" + 月.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);
- int sum = 3;
- if (copy!= null)
- {
- DeleteCopies(copy);
- }
- if (copy1!= null)
- {
- DeleteCopies(copy1);
- }
- for (int i = 0; i < json.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>();
- text[0].text = json[i][0].ToString().Trim('"');
- if (json[i][1].ToString().Trim('"') == "")
- {
- text[1].text = "休";
- }
- else
- {
- text[1].text = json[i][1].ToString().Trim('"');
- }
-
- GameObject buttonObj1 = Instantiate(buttonPrefab1) as GameObject;
- float 初始 = 0;
- if (Main.Global.螢幕格式=="胖")
- {
- 初始 = 258.5f;
- }
- else
- {
- 初始 = 266f;
- }
- buttonObj1.GetComponent<RectTransform>().anchoredPosition = new Vector2(初始, -sum);
- buttonObj1.transform.SetParent(buttonParent1, false);
- if (json[i][1].ToString().Trim('"')!= "" && json[i][1].ToString().Trim('"') != "休" )
- {
- string 開始時段 = json[i][2].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*41f) +(餘*40f/30);
- }
- else
- {
- 總 = 1+(商f*49) +(餘*48/30);
- }
- double 時數 = double.Parse(json[i][3].ToString().Trim('"'));
- float 時數f = (float)時數;
- double 後段 = double.Parse(json[i][12].ToString().Trim('"'));
- 後段 = 4 -後段;
- float 時數1f = (float)(8-時數-後段);
- float 總時 = 0;
- float 總時1 = 0;
- if (Main.Global.螢幕格式=="胖")
- {
- 總時 = (時數f*82) -1;
- 總時1 = (時數1f*82) -1;
- }
- else
- {
- 總時 = (時數f*98) -1;
- 總時1 = (時數1f*98) -1;
- }
- double 休息 = double.Parse(json[i][5].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*41f) +(餘1f*40f/30);
- }
- else
- {
- 總2 = 1+總+總時+(商1f*49) +(餘1f*48/30);
- }
- float 長 = 0;
- float 長B = 0;
- if (Main.Global.螢幕格式=="胖")
- {
- 長 = 40f;
- 長B = -4.5f;
- }
- else
- {
- 長 = 40f;
- 長B = -4.5f;
- }
-
-
- if (json[i][4]==1)
- {
- GameObject buttonObj2 = Instantiate(buttonPrefab2) as GameObject;
- buttonObj2.GetComponent<RectTransform>().sizeDelta = new Vector2(總時, 長);// 修改大小
- buttonObj2.GetComponent<RectTransform>().anchoredPosition = new Vector2(總, 長B); // 修改初始位置
- buttonObj2.transform.SetParent(buttonObj1.transform, false);
- TextMeshProUGUI texts = buttonObj2.GetComponentInChildren<TextMeshProUGUI>();
- texts.text =json[i][6].ToString().Trim('"');
- Image im = buttonObj2.GetComponentInChildren<Image>();
- string col = json[i][8].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<RectTransform>().sizeDelta = new Vector2(總時, 長);// 修改大小
- buttonObj2.GetComponent<RectTransform>().anchoredPosition = new Vector2(總, 長B); // 修改初始位置
- buttonObj2.transform.SetParent(buttonObj1.transform, false);
- TextMeshProUGUI texts = buttonObj2.GetComponentInChildren<TextMeshProUGUI>();
- texts.text =json[i][6].ToString().Trim('"');
- Image im = buttonObj2.GetComponentInChildren<Image>();
- string col = json[i][8].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<RectTransform>().sizeDelta = new Vector2(總時1, 長);// 修改大小
- buttonObj3.GetComponent<RectTransform>().anchoredPosition = new Vector2(總2, 長B); // 修改初始位置
- buttonObj3.transform.SetParent(buttonObj1.transform, false);
- TextMeshProUGUI texts1 = buttonObj3.GetComponentInChildren<TextMeshProUGUI>();
- texts1.text =json[i][7].ToString().Trim('"');
- Image im1 = buttonObj3.GetComponentInChildren<Image>();
- string col1 = json[i][9].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+=50;
- }
- else
- {
- sum+=50;
- }
-
- copy.Add(buttonObj);
- copy1.Add(buttonObj1);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- 讀取面板.SetActive(false);
- }
-
- public void 作天()
- {
- string date = 年.text +"/" + 月.text +"/" + 日.text;
- if (DateTime.TryParse(date, out DateTime result))
- {
- DateTime newDay = result.AddDays(-1);
- 年.text = newDay.Year.ToString();
- 月.text = newDay.Month.ToString("D2");
- 日.text = newDay.Day.ToString("D2");
- StartCoroutine(門診人員());
- }
- }
- public void 明天()
- {
- string date = 年.text +"/" + 月.text +"/" + 日.text;
- if (DateTime.TryParse(date, out DateTime result))
- {
- DateTime newDay = result.AddDays(1);
- 年.text = newDay.Year.ToString();
- 月.text = newDay.Month.ToString("D2");
- 日.text = newDay.Day.ToString("D2");
- 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(3);
- }
- public void change_Secen(int _screenNum)
- {
-
- SceneManager.LoadScene(_screenNum);
- }
- }
|