123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- 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] RawImage 放圖用;
- [SerializeField] GameObject 主頁;
- [SerializeField] GameObject 圖頁;
- public GameObject buttonPrefab;
- public Transform buttonParent;
- public GameObject buttonceneter;
- private List<GameObject> copy = new List<GameObject>();
-
-
- [SerializeField] TextMeshProUGUI 假別;
- [SerializeField] TextMeshProUGUI 日期;
- [SerializeField] TextMeshProUGUI 申請人;
- [SerializeField] TextMeshProUGUI 編號;
- [SerializeField] TextMeshProUGUI 事由;
-
- 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);
- 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);
- 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][2]);
- SetTextValue(text[2], json[i][3]);
- SetTextValue(text[3], json[i][5]);
- SetTextValue(text[4], json[i][6]);
- Button bt = buttonObj.GetComponentInChildren<Button>();
- int index = i;
- bt.onClick.AddListener(() =>
- {
- SetTextValue(申請人, json[index][0]);
- SetTextValue(編號, json[index][1]);
- SetTextValue(日期, json[index][2]);
- SetTextValue(假別, json[index][5]);
- SetTextValue(事由, json[index][6]);
- 主頁.SetActive(false);
- 圖頁.SetActive(true);
- 選單.SetActive(true);
- 未准.SetActive(true);
- 核准.SetActive(true);
- if (json[index][12] ==null)
- {
- 選擇資料庫="";
- }
- else
- {
- 選擇資料庫=json[index][12].ToString().Trim('"');
- }
- if (json[index][13] ==null)
- {
- 選擇流水號="";
- }
- else
- {
- 選擇流水號=json[index][13].ToString().Trim('"');
- }
- if (選擇資料庫 !="" && 選擇流水號 !="")
- {
- 讀取圖片();
- }
- else
- {
- 放圖用.texture =Texture2D.blackTexture;
- }
- });
- sum+=75;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- 讀取面板.SetActive(false);
-
- }
-
- 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(true);
- 彈跳文字.text = "核准成功";
- StartCoroutine(加班核准清單());
- }
- 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(true);
- 彈跳文字.text = "未准成功";
- StartCoroutine(加班核准清單());
- }
- public void 切換紐()
- {
- if (主頁.activeSelf && !圖頁.activeSelf)
- {
- 主頁.SetActive(false);
- 圖頁.SetActive(true);
- 選單.SetActive(true);
- 未准.SetActive(true);
- 核准.SetActive(true);
- }
- else if (圖頁.activeSelf && !主頁.activeSelf)
- {
-
- 圖頁.SetActive(false);
- 主頁.SetActive(true);
- 選單.SetActive(false);
- 未准.SetActive(false);
- 核准.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);
- }
- }
|