123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- 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.Runtime.InteropServices;
-
- public class 休假審核 : MonoBehaviour
- {
-
- [SerializeField] GameObject 切換;
- [SerializeField] GameObject 查看;
- [SerializeField] GameObject 核准;
- [SerializeField] GameObject 查頁;
- public TMP_Dropdown 年;
- [SerializeField] RawImage 放圖用;
- [SerializeField] GameObject 主頁;
- [SerializeField] GameObject 圖頁;
- 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>();
-
- [SerializeField] TextMeshProUGUI 假別;
- [SerializeField] TextMeshProUGUI 日期;
- [SerializeField] TextMeshProUGUI 申請人;
- [SerializeField] TextMeshProUGUI 編號;
- [SerializeField] TextMeshProUGUI 事由;
- [SerializeField] TextMeshProUGUI 申請人1;
- [SerializeField] TextMeshProUGUI 編號1;
- public CanvasScaler canvasScaler;
-
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
-
- [SerializeField] GameObject 彈跳面板;
- [SerializeField] TextMeshProUGUI 彈跳文字;
- private string loadingText = "";
- private int dotCount = 0;
- string 選擇資料庫;
- string 選擇流水號;
- void Start()
- {
- Screen.autorotateToPortrait = false;
- Screen.orientation = ScreenOrientation.Portrait;
- Main.Global.螢幕方向="直";
- //Main.Global.固高=1900f;
- //Main.Global.固寬=900f;
- //Main.Global.固比=1f;
- //Main.Global.螢幕格式="瘦";
- //Main.Global.PA="侯宜伶";
- 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";
- 主頁.SetActive(true);
- 圖頁.SetActive(false);
- 切換.SetActive(false);
- 查看.SetActive(false);
- 查頁.SetActive(false);
- 核准.SetActive(false);
- StartCoroutine(AnimateText());
- 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 年份清單()
- {
- string strcon = "年份清單";
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
- 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);
- 年.options.Clear();
- List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
- for (int i = 0; i < json.Count; i++)
- {
- string str = json[i].ToString().Trim('"');
- options.Add(new TMP_Dropdown.OptionData(str));
- }
- 年.AddOptions(options);
- DateTime currentDate = DateTime.Now;
- string year = currentDate.Year.ToString();
- int currentIndex = 年.options.FindIndex(option => option.text == year);
- 年.value = currentIndex;
- 年.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
- }
- private void OnDropdown1ValueChanged()
- {
- StartCoroutine(休假統計());
- }
- IEnumerator 休假核准清單()
- {
- 讀取面板.SetActive(true);
- if (copy!= null)
- {
- DeleteCopies(copy);
- }
- string strcon = "休假核准清單";
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
- 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 = 5;
- for (int i = 0; i < json.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- buttonObj.transform.SetParent(buttonParent, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- SetTextValue(text[0], json[i][0]);
- SetTextValue(text[1], json[i][1]);
- SetTextValue(text[2], json[i][2]);
- SetTextValue(text[3], json[i][3]);
- SetTextValue(text[4], json[i][4]);
- SetTextValue(text[5], json[i][5]);
- Button bt = buttonObj.GetComponentInChildren<Button>();
- int index = i;
- bt.onClick.AddListener(() =>
- {
- SetTextValue(申請人, json[index][0]);
- SetTextValue(編號, json[index][1]);
- SetTextValue(申請人1, json[index][0]);
- SetTextValue(編號1, json[index][1]);
- SetTextValue(日期, json[index][2]);
- SetTextValue(假別, json[index][4]);
- SetTextValue(事由, json[index][5]);
- 主頁.SetActive(false);
- 圖頁.SetActive(true);
- 切換.SetActive(true);
- 查看.SetActive(true);
- 查頁.SetActive(false);
- 核准.SetActive(true);
- if (json[index][9] ==null )
- {
- 選擇資料庫="";
- }
- else
- {
- 選擇資料庫=json[index][9].ToString().Trim('"');
- }
- if (json[index][10] ==null)
- {
- 選擇流水號="";
- }
- else
- {
- 選擇流水號=json[index][10].ToString().Trim('"');
- }
- if (選擇資料庫 !="" && 選擇流水號 !="")
- {
- 讀取圖片();
- }
- else
- {
- 放圖用.texture =Texture2D.blackTexture;
- }
- StartCoroutine(休假統計());
- });
- sum+=75;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- 讀取面板.SetActive(false);
-
- }
- IEnumerator 休假統計()
- {
- if (copy1!= null)
- {
- DeleteCopies(copy1);
- }
- string strcon = "休假統計";
- string se = Main.Global.預設伺服器路徑;
- string pa = 編號1.text;
- string pa1= 年.options[年.value].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);
- int sum = 5;
- for (int i = 0; i < json.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- buttonObj.transform.SetParent(buttonParent1, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- SetTextValue(text[0], json[i][0]);
- SetTextValue(text[1], json[i][1]);
- SetTextValue(text[2], json[i][2]);
- sum+=50;
- copy1.Add(buttonObj);
- }
- buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
-
- }
- public void 讀取圖片()
- {
- string ip = "";
- if (Main.Global.預設伺服器路徑=="test")
- {
- ip="106.1.48.106,4567";
- }
- else
- {
- ip="mssql-147629-0.cloudclusters.net,12711";
- }
- string connectionString = "Data Source="+ ip +";Initial Catalog="+ 選擇資料庫 +";User ID=B70340;Password=Lee0911274990";
- Debug.Log(connectionString);
-
- using (SqlConnection connection = new SqlConnection(connectionString))
- {
- try
- {
- connection.Open();
-
- string query = "SELECT 圖片 FROM 請假圖片庫 WHERE 流水號 LIKE '" + 選擇流水號 + "'";
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- if (reader.Read())
- {
- // 讀取圖片的二進位資料
- byte[] imageData = (byte[])reader["圖片"];
-
- // 將二進位資料轉換為 Texture2D
- Texture2D texture = new Texture2D(1, 1);
- texture.LoadImage(imageData);
-
- // 將 Texture2D 設置為 RawImage 的 texture
- 放圖用.texture = texture;
- float aspectRatio = (float)texture.width / texture.height;
- float newWidth = Mathf.Min(720f, 放圖用.rectTransform.rect.width);
- float newHeight = newWidth / aspectRatio;
- 放圖用.rectTransform.sizeDelta = new Vector2(newWidth, newHeight);
- }
- }
- }
- }
- catch (Exception ex)
- {
- Debug.LogError("Error connecting to the database: " + ex.Message);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
- }
- finally
- {
- connection.Close();
- }
- }
- }
- private void SetTextValue(TextMeshProUGUI text, string value)
- {
- if (value == null)
- {
- text.text = "";
- }
- else
- {
- string jsonString = value.Trim('"');
- string unescapedString = Regex.Unescape(jsonString);
- text.text = unescapedString;
- }
- }
- public void 核准紐()
- {
- if (日期.text != "" && 編號.text != "")
- {
- StartCoroutine(休假核准());
- }
- else
- {
- 彈跳面板.SetActive(false);
- 彈跳文字.text = "未選擇日期";
- }
- }
- IEnumerator 休假核准()
- {
- 讀取面板.SetActive(true);
- string strcon = "休假修改";
- string se = Main.Global.預設伺服器路徑;
- string pa = Main.Global.PA;
- DateTime currentDate = DateTime.Now;
- string pa1 = currentDate.ToString("yyyy/MM/dd");
- string pa2 = 日期.text;
- string pa3 = 編號.text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}&PA3={5}",strcon,se,pa,pa1,pa2,pa3);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- 圖頁.SetActive(false);
- 主頁.SetActive(true);
- 切換.SetActive(false);
- 查看.SetActive(false);
- 查頁.SetActive(false);
- 核准.SetActive(false);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "核准成功";
- StartCoroutine(休假核准清單());
- }
- public void 清單紐()
- {
- if (主頁.activeSelf && !圖頁.activeSelf)
- {
- 主頁.SetActive(false);
- 圖頁.SetActive(true);
- 切換.SetActive(true);
- 查看.SetActive(true);
- 查頁.SetActive(false);
- 核准.SetActive(true);
- }
- else if (圖頁.activeSelf && !主頁.activeSelf)
- {
-
- 圖頁.SetActive(false);
- 主頁.SetActive(true);
- 切換.SetActive(false);
- 查看.SetActive(false);
- 查頁.SetActive(false);
- 核准.SetActive(false);
- }
- }
- public void 查看紐()
- {
- if (查頁.activeSelf && !圖頁.activeSelf)
- {
- 主頁.SetActive(false);
- 圖頁.SetActive(true);
- 切換.SetActive(true);
- 查看.SetActive(true);
- 查頁.SetActive(false);
- 核准.SetActive(true);
- }
- else if (圖頁.activeSelf && !查頁.activeSelf)
- {
-
- 圖頁.SetActive(false);
- 主頁.SetActive(false);
- 切換.SetActive(false);
- 查看.SetActive(true);
- 查頁.SetActive(true);
- 核准.SetActive(false);
- }
- }
- 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 change_Secen(int _screenNum)
- {
-
- SceneManager.LoadScene(_screenNum);
- }
- }
|