Ingen beskrivning
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 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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. public GameObject buttonPrefab1;
  28. public Transform buttonParent1;
  29. public GameObject buttonceneter1;
  30. private List<GameObject> copy1 = new List<GameObject>();
  31. public GameObject buttonPrefab2;
  32. [SerializeField] TextMeshProUGUI 健保1;
  33. [SerializeField] TextMeshProUGUI 健保2;
  34. [SerializeField] TextMeshProUGUI 健保3;
  35. [SerializeField] TextMeshProUGUI 美容1;
  36. [SerializeField] TextMeshProUGUI 美容2;
  37. [SerializeField] TextMeshProUGUI 美容3;
  38. [SerializeField] TextMeshProUGUI 年;
  39. [SerializeField] TextMeshProUGUI 月;
  40. [SerializeField] TextMeshProUGUI 日;
  41. [SerializeField] TextMeshProUGUI 星期;
  42. public CanvasScaler canvasScaler;
  43. private string loadingText = "";
  44. private int dotCount = 0;
  45. [SerializeField] GameObject 讀取面板;
  46. [SerializeField] TextMeshProUGUI 讀取;
  47. [SerializeField] GameObject 彈跳面板;
  48. [SerializeField] TextMeshProUGUI 彈跳文字;
  49. JSONNode 人員清單;
  50. JSONArray 班表;
  51. void Start()
  52. {
  53. Screen.autorotateToPortrait = false;
  54. Screen.orientation = ScreenOrientation.LandscapeLeft;
  55. //Main.Global.固高=1600f;
  56. //Main.Global.固寬=1000f;
  57. //Main.Global.固比1=1f;
  58. //Main.Global.螢幕格式="胖";
  59. canvasScaler.referenceResolution = new Vector2(Main.Global.固高, Main.Global.固寬);
  60. canvasScaler.matchWidthOrHeight=Main.Global.固比1;
  61. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/hskin_login.php?";
  62. //Main.Global.預設伺服器路徑="test";
  63. Main.Global.螢幕方向="橫";
  64. DateTime currentDate = DateTime.Now;
  65. 年.text = currentDate.Year.ToString();
  66. 月.text = currentDate.Month.ToString("D2");
  67. 日.text = currentDate.Day.ToString("D2");
  68. StartCoroutine(AnimateText());
  69. StartCoroutine(門診人員());
  70. }
  71. IEnumerator AnimateText()
  72. {
  73. string qqq = 讀取.text.ToString();
  74. while (true)
  75. {
  76. yield return new WaitForSeconds(0.5f);
  77. if (dotCount < 3)
  78. {
  79. loadingText += ".";
  80. dotCount++;
  81. }
  82. else
  83. {
  84. loadingText = "";
  85. dotCount = 0;
  86. }
  87. 讀取.text = qqq+loadingText;
  88. }
  89. }
  90. IEnumerator 門診人員()
  91. {
  92. 讀取面板.SetActive(true);
  93. string strcon = "門診人員";
  94. string se = Main.Global.預設伺服器路徑;
  95. string pa = 年.text +"/" + 月.text +"/" + 日.text;
  96. string pa1 = "健保";
  97. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  98. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  99. yield return request.SendWebRequest();
  100. if (request.result == UnityWebRequest.Result.ConnectionError)
  101. {
  102. //Debug.Log(request.error);
  103. yield break;
  104. }
  105. string pa2 = "醫美";
  106. string strUrl1 = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa2);
  107. UnityWebRequest request1 = UnityWebRequest.Get(strUrl1);
  108. yield return request1.SendWebRequest();
  109. if (request1.result == UnityWebRequest.Result.ConnectionError)
  110. {
  111. //Debug.Log(request.error);
  112. yield break;
  113. }
  114. JSONNode json = JSON.Parse(request.downloadHandler.text);
  115. JSONNode json1 = JSON.Parse(request1.downloadHandler.text);
  116. if (json.Count<1)
  117. {
  118. 健保1.text="";
  119. 健保2.text="";
  120. 健保3.text="";
  121. }
  122. else
  123. {
  124. 健保1.text=json[0][2].ToString().Trim('"');
  125. 健保2.text=json[0][3].ToString().Trim('"');
  126. 健保3.text=json[0][4].ToString().Trim('"');
  127. }
  128. if (json1.Count<1)
  129. {
  130. 美容1.text="";
  131. 美容2.text="";
  132. 美容3.text="";
  133. }
  134. else
  135. {
  136. 美容1.text=json1[0][2].ToString().Trim('"');
  137. 美容2.text=json1[0][3].ToString().Trim('"');
  138. 美容3.text=json1[0][4].ToString().Trim('"');
  139. }
  140. yield return StartCoroutine(星期讀取());
  141. }
  142. IEnumerator 星期讀取()
  143. {
  144. string strcon = "星期讀取";
  145. string se = Main.Global.預設伺服器路徑;
  146. string pa = 年.text +"/" + 月.text +"/" + 日.text;
  147. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}", strcon, se, pa);
  148. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  149. yield return request.SendWebRequest();
  150. if (request.result == UnityWebRequest.Result.ConnectionError)
  151. {
  152. Debug.Log(request.error);
  153. yield break;
  154. }
  155. JSONNode json = JSON.Parse(request.downloadHandler.text);
  156. 星期.text=json[0].ToString().Trim('"');
  157. yield return StartCoroutine(排班明細班別());
  158. }
  159. IEnumerator 排班明細班別()
  160. {
  161. string strcon = "排班明細班別";
  162. string se = Main.Global.預設伺服器路徑;
  163. string pa = 年.text +"/" + 月.text +"/" + 日.text;
  164. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}", strcon, se, pa);
  165. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  166. yield return request.SendWebRequest();
  167. if (request.result == UnityWebRequest.Result.ConnectionError)
  168. {
  169. Debug.Log(request.error);
  170. yield break;
  171. }
  172. JSONNode json = JSON.Parse(request.downloadHandler.text);
  173. int sum = 3;
  174. if (copy!= null)
  175. {
  176. DeleteCopies(copy);
  177. }
  178. if (copy1!= null)
  179. {
  180. DeleteCopies(copy1);
  181. }
  182. for (int i = 0; i < json.Count; i++)
  183. {
  184. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  185. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(3, -sum);
  186. buttonObj.transform.SetParent(buttonParent, false);
  187. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  188. text[0].text = json[i][0].ToString().Trim('"');
  189. if (json[i][1].ToString().Trim('"') == "")
  190. {
  191. text[1].text = "休";
  192. }
  193. else
  194. {
  195. text[1].text = json[i][1].ToString().Trim('"');
  196. }
  197. GameObject buttonObj1 = Instantiate(buttonPrefab1) as GameObject;
  198. float 初始 = 0;
  199. if (Main.Global.螢幕格式=="胖")
  200. {
  201. 初始 = 258.5f;
  202. }
  203. else
  204. {
  205. 初始 = 266f;
  206. }
  207. buttonObj1.GetComponent<RectTransform>().anchoredPosition = new Vector2(初始, -sum);
  208. buttonObj1.transform.SetParent(buttonParent1, false);
  209. if (json[i][1].ToString().Trim('"')!= "" && json[i][1].ToString().Trim('"') != "休" )
  210. {
  211. string 開始時段 = json[i][2].ToString().Trim('"');
  212. DateTime time1 = DateTime.ParseExact("08:00:00", "HH:mm:ss", CultureInfo.InvariantCulture);
  213. DateTime time2 = DateTime.ParseExact(開始時段, "HH:mm:ss", CultureInfo.InvariantCulture);
  214. int hoursDiff = (int)time2.Subtract(time1).TotalMinutes;
  215. int 商 = hoursDiff / 30; // 整數除法,得到商
  216. int 餘 = hoursDiff % 30; // 餘數運算,得到餘數
  217. float 商f = (float)商;
  218. float 餘f = (float)餘;
  219. float 總 = 0;
  220. if (Main.Global.螢幕格式=="胖")
  221. {
  222. 總 = 1+(商f*41f) +(餘*40f/30);
  223. }
  224. else
  225. {
  226. 總 = 1+(商f*49) +(餘*48/30);
  227. }
  228. double 時數 = double.Parse(json[i][3].ToString().Trim('"'));
  229. float 時數f = (float)時數;
  230. double 後段 = double.Parse(json[i][12].ToString().Trim('"'));
  231. 後段 = 4 -後段;
  232. float 時數1f = (float)(8-時數-後段);
  233. float 總時 = 0;
  234. float 總時1 = 0;
  235. if (Main.Global.螢幕格式=="胖")
  236. {
  237. 總時 = (時數f*82) -1;
  238. 總時1 = (時數1f*82) -1;
  239. }
  240. else
  241. {
  242. 總時 = (時數f*98) -1;
  243. 總時1 = (時數1f*98) -1;
  244. }
  245. double 休息 = double.Parse(json[i][5].ToString().Trim('"'));
  246. 休息 = 休息*60;
  247. int 休息1 = (int)休息;
  248. int 商2 = 休息1 / 30; // 整數除法,得到商
  249. int 餘2 = 休息1 % 30;
  250. float 商1f = (float)商2;
  251. float 餘1f = (float)餘2;
  252. float 總2 = 0;
  253. if (Main.Global.螢幕格式=="胖")
  254. {
  255. 總2 = 1+總+總時+(商1f*41f) +(餘1f*40f/30);
  256. }
  257. else
  258. {
  259. 總2 = 1+總+總時+(商1f*49) +(餘1f*48/30);
  260. }
  261. float 長 = 0;
  262. float 長B = 0;
  263. if (Main.Global.螢幕格式=="胖")
  264. {
  265. 長 = 40f;
  266. 長B = -4.5f;
  267. }
  268. else
  269. {
  270. 長 = 40f;
  271. 長B = -4.5f;
  272. }
  273. if (json[i][4]==1)
  274. {
  275. GameObject buttonObj2 = Instantiate(buttonPrefab2) as GameObject;
  276. buttonObj2.GetComponent<RectTransform>().sizeDelta = new Vector2(總時, 長);// 修改大小
  277. buttonObj2.GetComponent<RectTransform>().anchoredPosition = new Vector2(總, 長B); // 修改初始位置
  278. buttonObj2.transform.SetParent(buttonObj1.transform, false);
  279. TextMeshProUGUI texts = buttonObj2.GetComponentInChildren<TextMeshProUGUI>();
  280. texts.text =json[i][6].ToString().Trim('"');
  281. Image im = buttonObj2.GetComponentInChildren<Image>();
  282. string col = json[i][8].ToString().Trim('"');
  283. switch (col)
  284. {
  285. case "0":
  286. im.color = new Color32(128, 128, 128, 255);
  287. break;
  288. case "1":
  289. im.color = new Color32(124, 252, 0, 255);
  290. break;
  291. case "2":
  292. im.color = new Color32(173, 216, 230, 255);
  293. break;
  294. case "3":
  295. im.color = new Color32(240, 128, 128, 255);
  296. break;
  297. case "4":
  298. im.color = new Color32(224, 255, 255, 255);
  299. break;
  300. case "5":
  301. im.color = new Color32(250, 250, 210, 255);
  302. break;
  303. case "6":
  304. im.color = new Color32(211, 211, 211, 255);
  305. break;
  306. case "7":
  307. im.color = new Color32(144, 238, 144, 255);
  308. break;
  309. case "8":
  310. im.color = new Color32(255, 182, 193, 255);
  311. break;
  312. case "9":
  313. im.color = new Color32(255, 160, 122, 255);
  314. break;
  315. default:
  316. im.color = new Color32(255, 255, 255, 255); // 預設白色
  317. break;
  318. }
  319. }
  320. else
  321. {
  322. GameObject buttonObj2 = Instantiate(buttonPrefab2) as GameObject;
  323. buttonObj2.GetComponent<RectTransform>().sizeDelta = new Vector2(總時, 長);// 修改大小
  324. buttonObj2.GetComponent<RectTransform>().anchoredPosition = new Vector2(總, 長B); // 修改初始位置
  325. buttonObj2.transform.SetParent(buttonObj1.transform, false);
  326. TextMeshProUGUI texts = buttonObj2.GetComponentInChildren<TextMeshProUGUI>();
  327. texts.text =json[i][6].ToString().Trim('"');
  328. Image im = buttonObj2.GetComponentInChildren<Image>();
  329. string col = json[i][8].ToString().Trim('"');
  330. switch (col)
  331. {
  332. case "0":
  333. im.color = new Color32(128, 128, 128, 255);
  334. break;
  335. case "1":
  336. im.color = new Color32(124, 252, 0, 255);
  337. break;
  338. case "2":
  339. im.color = new Color32(173, 216, 230, 255);
  340. break;
  341. case "3":
  342. im.color = new Color32(240, 128, 128, 255);
  343. break;
  344. case "4":
  345. im.color = new Color32(224, 255, 255, 255);
  346. break;
  347. case "5":
  348. im.color = new Color32(250, 250, 210, 255);
  349. break;
  350. case "6":
  351. im.color = new Color32(211, 211, 211, 255);
  352. break;
  353. case "7":
  354. im.color = new Color32(144, 238, 144, 255);
  355. break;
  356. case "8":
  357. im.color = new Color32(255, 182, 193, 255);
  358. break;
  359. case "9":
  360. im.color = new Color32(255, 160, 122, 255);
  361. break;
  362. default:
  363. im.color = new Color32(255, 255, 255, 255); // 預設白色
  364. break;
  365. }
  366. GameObject buttonObj3 = Instantiate(buttonPrefab2) as GameObject;
  367. buttonObj3.GetComponent<RectTransform>().sizeDelta = new Vector2(總時1, 長);// 修改大小
  368. buttonObj3.GetComponent<RectTransform>().anchoredPosition = new Vector2(總2, 長B); // 修改初始位置
  369. buttonObj3.transform.SetParent(buttonObj1.transform, false);
  370. TextMeshProUGUI texts1 = buttonObj3.GetComponentInChildren<TextMeshProUGUI>();
  371. texts1.text =json[i][7].ToString().Trim('"');
  372. Image im1 = buttonObj3.GetComponentInChildren<Image>();
  373. string col1 = json[i][9].ToString().Trim('"');
  374. switch (col1)
  375. {
  376. case "0":
  377. im1.color = new Color32(128, 128, 128, 255);
  378. break;
  379. case "1":
  380. im1.color = new Color32(124, 252, 0, 255);
  381. break;
  382. case "2":
  383. im1.color = new Color32(173, 216, 230, 255);
  384. break;
  385. case "3":
  386. im1.color = new Color32(240, 128, 128, 255);
  387. break;
  388. case "4":
  389. im1.color = new Color32(224, 255, 255, 255);
  390. break;
  391. case "5":
  392. im1.color = new Color32(250, 250, 210, 255);
  393. break;
  394. case "6":
  395. im1.color = new Color32(211, 211, 211, 255);
  396. break;
  397. case "7":
  398. im1.color = new Color32(144, 238, 144, 255);
  399. break;
  400. case "8":
  401. im1.color = new Color32(255, 182, 193, 255);
  402. break;
  403. case "9":
  404. im1.color = new Color32(255, 160, 122, 255);
  405. break;
  406. default:
  407. im1.color = new Color32(255, 255, 255, 255); // 預設白色
  408. break;
  409. }
  410. }
  411. }
  412. if (Main.Global.螢幕格式=="胖")
  413. {
  414. sum+=50;
  415. }
  416. else
  417. {
  418. sum+=50;
  419. }
  420. copy.Add(buttonObj);
  421. copy1.Add(buttonObj1);
  422. }
  423. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  424. 讀取面板.SetActive(false);
  425. }
  426. public void 作天()
  427. {
  428. string date = 年.text +"/" + 月.text +"/" + 日.text;
  429. if (DateTime.TryParse(date, out DateTime result))
  430. {
  431. DateTime newDay = result.AddDays(-1);
  432. 年.text = newDay.Year.ToString();
  433. 月.text = newDay.Month.ToString("D2");
  434. 日.text = newDay.Day.ToString("D2");
  435. StartCoroutine(門診人員());
  436. }
  437. }
  438. public void 明天()
  439. {
  440. string date = 年.text +"/" + 月.text +"/" + 日.text;
  441. if (DateTime.TryParse(date, out DateTime result))
  442. {
  443. DateTime newDay = result.AddDays(1);
  444. 年.text = newDay.Year.ToString();
  445. 月.text = newDay.Month.ToString("D2");
  446. 日.text = newDay.Day.ToString("D2");
  447. StartCoroutine(門診人員());
  448. }
  449. }
  450. public void 彈跳面板關閉()
  451. {
  452. 彈跳面板.SetActive(false);
  453. 彈跳文字.text = "";
  454. }
  455. private void DeleteCopies(List<GameObject> copyList)
  456. {
  457. foreach (GameObject copy in copyList)
  458. {
  459. Destroy(copy);
  460. }
  461. copyList.Clear();
  462. }
  463. public void back()
  464. {
  465. change_Secen(3);
  466. }
  467. public void change_Secen(int _screenNum)
  468. {
  469. SceneManager.LoadScene(_screenNum);
  470. }
  471. }