1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000 |
- 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] Button 存檔紐;
- [SerializeField] Button 刪除紐;
- [SerializeField] Button 切換紐;
- [SerializeField] Button 回首紐;
- [SerializeField] RawImage 縮圖;
- [SerializeField] RawImage 拍照用;
- [SerializeField] RawImage 放圖用;
- [SerializeField] GameObject 主頁;
- [SerializeField] GameObject 圖頁;
- [SerializeField] TextMeshProUGUI 提示字;
- private WebCamTexture myCam;//接收攝影機返回的圖片數據
-
- 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 TMP_Dropdown 年;
- public TMP_Dropdown 月;
- public TMP_Dropdown 假別;
- public TMP_Dropdown 時數;
- [SerializeField] TextMeshProUGUI 日期;
- [SerializeField] TextMeshProUGUI 申請人;
- [SerializeField] TextMeshProUGUI 編號;
- [SerializeField] TMP_InputField 事由;
- public CanvasScaler canvasScaler;
- [SerializeField] GameObject 人員清單面板;
- [SerializeField] GameObject 人員清單按鈕;
-
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
-
- [SerializeField] GameObject 彈跳面板;
- [SerializeField] TextMeshProUGUI 彈跳文字;
- private string loadingText = "";
- private int dotCount = 0;
- string 生效;
- string 圖片資料庫;
- bool 是否有圖;
- 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.考勤主管權限=false;
- //Main.Global.PA="盧婕柔";
- //Main.Global.編號="999";
- 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";
- 存檔紐.interactable = false;
- 刪除紐.interactable = false;
- 切換紐.interactable = false;
- 回首紐.interactable = true;
- 主頁.SetActive(true);
- 圖頁.SetActive(false);
- if (Main.Global.考勤主管權限==true)
- {
- 人員清單按鈕.SetActive(true);
- }
- else
- {
- 人員清單按鈕.SetActive(false);
- }
-
- StartCoroutine(AnimateText());
- StartCoroutine(圖片資料庫選擇());
- 是否有圖=false;
- }
-
- 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 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;
- }
- string str = request.downloadHandler.text.ToString();
-
- if(str == "n")
- {
- 讀取面板.SetActive(false);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "圖片資料庫已滿,請找系統管理員!!";
- yield return new WaitForSeconds(2);
- change_Secen(2);
- }
- else
- {
- 圖片資料庫 =str;
- yield return StartCoroutine(年份清單());
- }
-
- }
- 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();
- string month = currentDate.Month.ToString("D2");
- int currentIndex = 年.options.FindIndex(option => option.text == year);
- 年.value = currentIndex;
- int currentIndex1 = 月.options.FindIndex(option => option.text == month);
- 月.value = currentIndex1;
- 年.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
- 月.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
- if (Main.Global.PA=="測試號")
- {
- 申請人.text=Main.Global.PA;
- 編號.text=Main.Global.編號;
- yield return StartCoroutine(請假申請明細表());
- }
- else
- {
- yield return StartCoroutine(請假申請人員清單());
- }
-
-
- }
- private void OnDropdown1ValueChanged()
- {
- StartCoroutine(請假申請人員清單());
- }
- IEnumerator 請假申請人員清單()
- {
- 讀取面板.SetActive(true);
- if (copy!= null)
- {
- DeleteCopies(copy);
- }
- string strcon = "請假申請人員清單";
- string se = Main.Global.預設伺服器路徑;
- string pa = 月.options[月.value].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(buttonPrefab) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- buttonObj.transform.SetParent(buttonParent, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- text[0].text = (i+1).ToString();
- text[1].text = json[i][1].ToString().Trim('"');
- text[2].text = json[i][2].ToString().Trim('"');
- Button bt = buttonObj.GetComponentInChildren<Button>();
- int index = i;
- bt.onClick.AddListener(() =>
- {
- 人員清單面板.SetActive(false);
- 申請人.text=json[index][2].ToString().Trim('"');
- 編號.text=json[index][1].ToString().Trim('"');
- 日期.text ="";
- 事由.text ="";
- StartCoroutine(請假申請明細表());
- });
- sum+=75;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
-
- if (Main.Global.考勤主管權限==true)
- {
- StartCoroutine(請假申請明細表());
- }
- else
- {
- 申請人.text=Main.Global.PA;
- 編號.text=Main.Global.編號;
- yield return StartCoroutine(請假申請明細表());
- }
- }
- IEnumerator 請假申請明細表()
- {
- 讀取面板.SetActive(true);
- if (copy1!= null)
- {
- DeleteCopies(copy1);
- }
- string strcon = "請假申請明細表";
- string se = Main.Global.預設伺服器路徑;
- string pa = 編號.text;
- string pa1 = 年.options[年.value].text + "/" + 月.options[月.value].text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
- Debug.Log(strUrl);
- 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);
- Debug.Log(json);
- int sum = 5;
- for (int i = 0; i < json.Count; i++)
- {
- for (int j = 0; j < json[0].Count; j++)
- {
-
- if (json[i][j] == null)
- {
- json[i][j]="";
- }
- }
-
- }
-
- 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]);
- SetTextValue(text[3], json[i][3]);
- SetTextValue(text[4], json[i][4]);
- SetTextValue(text[5], json[i][9]);
- Image[] childImages = buttonObj.GetComponentsInChildren<Image>();
- string da = json[i][1].ToString().Trim('"');
- string da1 = json[i][2].ToString().Trim('"');
- if (da=="星期日")
- {
- foreach (Image childImage in childImages)
- {
- if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
- {
- childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
- }
-
- }
- }
- if (da=="星期六")
- {
- foreach (Image childImage in childImages)
- {
- if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
- {
- childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
- }
-
- }
- }
- if (da1=="國定假日")
- {
- foreach (Image childImage in childImages)
- {
- if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
- {
- childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
- }
-
- }
- }
- else if (da1 != "" )
- {
- foreach (Image childImage in childImages)
- {
- if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
- {
- childImage.color = new Color32(255, 255, 130, 255); // 改為紅色,你可以自己更改顏色
- }
-
- }
- }
- Button bt = buttonObj.GetComponentInChildren<Button>();
- Image im = bt.GetComponentInChildren<Image>();
- im.color = new Color32(255, 255, 255, 0);
- int index = i;
- bt.onClick.AddListener(() =>
- {
- if (json[index][1].ToString().Trim('"')=="星期六" || json[index][1].ToString().Trim('"')=="星期日" || json[index][2].ToString().Trim('"')=="國定假日")
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "星期六/星期日或國定假日不需要申請休假!!";
- }
- else
- {
- 日期.text =json[index][0].ToString().Trim('"');
- 生效 =json[index][4].ToString().Trim('"');
- 選擇資料庫=json[index][7].ToString().Trim('"');
- 選擇流水號=json[index][8].ToString().Trim('"');
- 存檔紐.interactable = true;
- 刪除紐.interactable = true;
- 切換紐.interactable = true;
- 回首紐.interactable = true;
- SetTextValue1(事由, json[index][3]);
- int currentIndex1 = 時數.options.FindIndex(option => option.text == json[index][9].ToString().Trim('"'));
- 時數.value = currentIndex1;
- int currentIndex = 假別.options.FindIndex(option => option.text == json[index][2].ToString().Trim('"'));
- 假別.value = currentIndex;
-
- 縮圖.texture = Texture2D.blackTexture;
- if (選擇資料庫 !="" && 選擇流水號 !="")
- {
- 讀取圖片();
- }
- else
- {
- 放圖用.texture =Texture2D.blackTexture;
- }
- Debug.Log(生效);
- Debug.Log(選擇資料庫);
- Debug.Log(選擇流水號);
- }
-
- });
- sum+=75;
- copy1.Add(buttonObj);
- }
- buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.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 SetTextValue1(TMP_InputField text, string value)
- {
- if (value == null)
- {
- text.text = "";
- }
- else
- {
- string jsonString = value.Trim('"');
- string unescapedString = Regex.Unescape(jsonString);
- text.text = unescapedString;
- }
- }
- 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 修改()
- {
- string str = 時數.options[時數.value].text;
- if (申請人.text == "" || 日期.text =="" || str =="")
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "人員、日期、請休假時數 不能為空白!!";
- }
- else
- {
- if (生效 == "已核准" || 生效 =="未核准")
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "已簽核的資料不能再做修改";
- }
- else
- {
- StartCoroutine(是否有請假資料());
- }
- }
- }
- public void 刪除()
- {
- if (申請人.text == "" || 日期.text =="" )
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "人員、日期 不能為空白!!";
- }
- else
- {
- if (生效 == "已核准" || 生效 =="未核准")
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "已簽核的資料不能再做修改";
- }
- else
- {
- StartCoroutine(請假資料刪除());
- }
- }
- }
- IEnumerator 是否有請假資料()
- {
- 讀取面板.SetActive(true);
- string strcon = "是否有請假資料";
- string se = Main.Global.預設伺服器路徑;
- string pa = 日期.text;
- string pa1 = 編號.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;
- }
- string str = request.downloadHandler.text.ToString();
- if (str == "n")
- {
- yield return StartCoroutine(查詢最後一筆圖片編號("新增"));
- }
- else
- {
- if (選擇資料庫 !="" && 選擇流水號 !="")
- {
- yield return StartCoroutine(請假資料修改(""));
- }
- else
- {
- yield return StartCoroutine(查詢最後一筆圖片編號("修改"));
- }
-
- }
- }
- IEnumerator 請假資料新增(string 新流水)
- {
- string pa4 = "";
- string pa5 = "";
- if (縮圖.texture != null && 縮圖.texture != Texture2D.blackTexture)
- {
- 圖片上傳(新流水);
- pa4 = 圖片資料庫;
- pa5 = 新流水;
- }
- string strcon = "請假資料新增";
- string se = Main.Global.預設伺服器路徑;
- string pa = 編號.text;
- string pa1 = 日期.text;
- string pa2 = 假別.options[假別.value].text;
- string pa3 = 事由.text;
- string pa6 = 時數.options[時數.value].text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}&PA3={5}&PA4={6}&PA5={7}&PA6={8}", strcon, se, pa, pa1, pa2, pa3, pa4, pa5, pa6);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- yield return StartCoroutine(請假申請明細表());
-
- 縮圖.texture = Texture2D.blackTexture;
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "新增成功";
- }
- IEnumerator 查詢最後一筆圖片編號(string 狀態)
- {
- string strcon = "查詢最後一筆圖片編號";
- string se = Main.Global.預設伺服器路徑;
- string pa1 = 圖片資料庫;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se,pa1);
- Debug.Log(strUrl);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- string str = request.downloadHandler.text.ToString();
- if (str == "n")
- {
- str ="IR00000000";
- }
- string cnum = str.Substring(2);
- int inum = int.Parse(cnum);
- inum+=1;
- string 新流水 = "IR";
- if (inum<10)
- {
- 新流水+="0000000"+inum.ToString();
- }
- if (inum>9 && inum<100)
- {
- 新流水+="000000"+inum.ToString();
- }
- if (inum>99 && inum<1000)
- {
- 新流水+="00000"+inum.ToString();
- }
- if (inum>999 && inum<10000)
- {
- 新流水+="0000"+inum.ToString();
- }
- if (inum>9999 && inum<100000)
- {
- 新流水+="000"+inum.ToString();
- }
- if (inum>99999 && inum<10000000)
- {
- 新流水+="00"+inum.ToString();
- }
- if (inum>999999 && inum<10000000)
- {
- 新流水+="0"+inum.ToString();
- }
- if (inum>9999999 && inum<100000000)
- {
- 新流水+=inum.ToString();
- }
- if (狀態 == "修改")
- {
- yield return StartCoroutine(請假資料修改(新流水));
- }
- else
- {
- yield return StartCoroutine(請假資料新增(新流水));
- }
-
- }
- public void 圖片上傳(string 流水)
- {
- 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();
- Texture2D texture2D = new Texture2D((放圖用.texture as Texture2D).width, (放圖用.texture as Texture2D).height);
- Graphics.CopyTexture(放圖用.texture, texture2D);
-
- // 將 Texture2D 轉換為 PNG 格式的二進制數據
- byte[] imageBytes = texture2D.EncodeToPNG();
-
- string query = "INSERT INTO 請假圖片庫 (流水號, 圖片) VALUES (@流水號, @binary_file)";
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- // 添加流水號參數
- command.Parameters.AddWithValue("@流水號", 流水);
-
- // 添加二進制圖片數據參數
- command.Parameters.AddWithValue("@binary_file", imageBytes);
- int rowsAffected = command.ExecuteNonQuery();
- Debug.Log("成功插入 " + rowsAffected + " 行數據");
- }
- }
- catch (Exception ex)
- {
- Debug.LogError("Error connecting to the database: " + ex.Message);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
- }
- finally
- {
- connection.Close();
- }
- }
- }
- public void 圖片修改()
- {
- string 流水=選擇流水號;
-
- 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();
- Texture2D texture2D = new Texture2D((放圖用.texture as Texture2D).width, (放圖用.texture as Texture2D).height);
- Graphics.CopyTexture(放圖用.texture, texture2D);
-
- // 將 Texture2D 轉換為 PNG 格式的二進制數據
- byte[] imageBytes = texture2D.EncodeToPNG();
-
- string query = "UPDATE 請假圖片庫 SET 圖片 = @binary_file WHERE 流水號 LIKE @流水號";
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- // 添加流水號參數
- command.Parameters.AddWithValue("@流水號", 流水);
-
- // 添加二進制圖片數據參數
- command.Parameters.AddWithValue("@binary_file", imageBytes);
- int rowsAffected = command.ExecuteNonQuery();
- Debug.Log("成功修改 " + rowsAffected + " 行數據");
- }
- }
- catch (Exception ex)
- {
- Debug.LogError("Error connecting to the database: " + ex.Message);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
- }
- finally
- {
- connection.Close();
- }
- }
- }
- IEnumerator 請假資料修改(string 流水)
- {
- string strcon = "請假資料修改";
- string pa4 = 選擇資料庫;
- string pa5 = 選擇流水號;
- if (縮圖.texture != null && 縮圖.texture != Texture2D.blackTexture)
- {
- if (選擇資料庫 !="" && 選擇流水號 !="")
- {
- 圖片修改();
- }
- else
- {
- 圖片上傳(流水);
- pa4 = 圖片資料庫;
- pa5 = 流水;
- }
- }
- string se = Main.Global.預設伺服器路徑;
- string pa = 編號.text;
- string pa1 = 日期.text;
- string pa2 = 假別.options[假別.value].text;
- string pa3 = 事由.text;
-
- string pa6 = 時數.options[時數.value].text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}&PA3={5}&PA4={6}&PA5={7}&PA6={8}", strcon, se, pa, pa1, pa2, pa3, pa4, pa5, pa6);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- Debug.Log(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- //Debug.Log(request.error);
- yield break;
- }
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "修改成功";
- 縮圖.texture = Texture2D.blackTexture;
- yield return StartCoroutine(請假申請明細表());
-
- }
- IEnumerator 請假資料刪除()
- {
- 讀取面板.SetActive(true);
- string strcon = "請假資料刪除";
- string se = Main.Global.預設伺服器路徑;
- string pa = 日期.text;
- string pa1 = 編號.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;
- }
- 事由.text = "";
- 生效="";
- yield return StartCoroutine(請假資料圖片刪除());
- }
- IEnumerator 請假資料圖片刪除()
- {
- string strcon = "請假資料圖片刪除";
- string se = Main.Global.預設伺服器路徑;
- string pa1 = 選擇資料庫;
- string pa = 選擇流水號;
- 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;
- }
- 選擇資料庫="";
- 選擇流水號="";
- 放圖用.texture =Texture2D.blackTexture;
- 縮圖.texture = Texture2D.blackTexture;
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "刪除成功";
- yield return StartCoroutine(請假申請明細表());
- }
- public void 頁面切換()
- {
- if (主頁.activeSelf && !圖頁.activeSelf)
- {
-
- 主頁.SetActive(false);
- 圖頁.SetActive(true);
- 拍照用.gameObject.SetActive(false);
- 放圖用.gameObject.SetActive(true);
- 存檔紐.interactable = false;
- 刪除紐.interactable = false;
- 切換紐.interactable = true;
- 回首紐.interactable = true;
-
- }
- else if (圖頁.activeSelf && !主頁.activeSelf)
- {
-
- 圖頁.SetActive(false);
- 主頁.SetActive(true);
- if (myCam != null)
- {
- myCam.Stop();
- myCam = null;
- }
- 存檔紐.interactable = true;
- 刪除紐.interactable = true;
- 切換紐.interactable = true;
- 回首紐.interactable = true;
- }
-
- }
- public void 相機鈕()
- {
- if (拍照用.gameObject.activeSelf && !放圖用.gameObject.activeSelf)
- {
-
- Texture2D photoTexture = CapturePhoto();
- if (photoTexture != null)
- {
- 放圖用.rectTransform.sizeDelta = new Vector2(720f, 1280f);
- 放圖用.texture = photoTexture;
- 縮圖.texture = photoTexture;
- }
-
- 存檔紐.interactable = true;
- 刪除紐.interactable = true;
- 切換紐.interactable = true;
- 回首紐.interactable = true;
- myCam.Stop();
- myCam = null;
- 提示字.text ="";
- 拍照用.gameObject.SetActive(false);
- 放圖用.gameObject.SetActive(true);
- 圖頁.SetActive(false);
- 主頁.SetActive(true);
-
- }
- else if (放圖用.gameObject.activeSelf && !拍照用.gameObject.activeSelf)
- {
-
- StartCoroutine(open_Camera(60));
- 提示字.text ="拍照中";
- 存檔紐.interactable = false;
- 刪除紐.interactable = false;
- 切換紐.interactable = false;
- 回首紐.interactable = false;
- 拍照用.gameObject.SetActive(true);
- 放圖用.gameObject.SetActive(false);
- }
-
- }
- private IEnumerator open_Camera(int fps)
- {
- yield return Application.RequestUserAuthorization(UserAuthorization.WebCam); //授權開啟鏡頭
- if (Application.HasUserAuthorization(UserAuthorization.WebCam))
- {
- /* (攝影機名稱, 攝影機要拍到的寬度, 攝影機要拍到的高度, 攝影機的FPS) */
- myCam = new WebCamTexture(WebCamTexture.devices[0].name, 720, 1280, fps);
- 拍照用.texture = myCam;
- myCam.Play();//開啟攝影機
- }
- }
- private Texture2D CapturePhoto()
- {
- if (myCam != null)
- {
- int width = myCam.width;
- int height = myCam.height;
-
- // 创建一个新的 Texture2D,并读取当前帧的像素
- Texture2D photoTexture = new Texture2D(width, height);
- photoTexture.SetPixels(myCam.GetPixels());
- photoTexture.Apply();
-
- Texture2D rotatedTexture = RotateTexture(photoTexture, true);
-
- return rotatedTexture;
- }
- Texture2D RotateTexture(Texture2D originalTexture, bool clockwise)
- {
- int width = originalTexture.width;
- int height = originalTexture.height;
- Texture2D rotatedTexture = new Texture2D(height, width);
-
- Color32[] originalPixels = originalTexture.GetPixels32();
- Color32[] rotatedPixels = new Color32[width * height];
-
- for (int y = 0; y < height; y++)
- {
- for (int x = 0; x < width; x++)
- {
- int newX = clockwise ? y : height - y - 1;
- int newY = clockwise ? width - x - 1 : x;
- rotatedPixels[newY * height + newX] = originalPixels[y * width + x];
- }
- }
-
- rotatedTexture.SetPixels32(rotatedPixels);
- rotatedTexture.Apply();
-
- return rotatedTexture;
- }
- return null;
- }
-
- public void 彈跳面板關閉()
- {
- 彈跳面板.SetActive(false);
- 彈跳文字.text = "";
- }
- public void 人員面板關閉()
- {
- 人員清單面板.SetActive(false);
-
- }
- public void 人員面板開啟()
- {
- 人員清單面板.SetActive(true);
- }
- 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);
- }
-
- }
|