123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992 |
- 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 假別;
-
- [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(圖片資料庫選擇());
- }
-
- 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;
- Debug.Log(圖片資料庫);
- 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.編號;
- 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);
- 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++)
- {
- 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]);
- 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][9].ToString().Trim('"');
- 選擇流水號=json[index][10].ToString().Trim('"');
- 存檔紐.interactable = true;
- 刪除紐.interactable = true;
- 切換紐.interactable = true;
- 回首紐.interactable = true;
- SetTextValue1(事由, json[index][3]);
- 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 修改()
- {
-
- if (申請人.text == "" || 日期.text =="" )
- {
- 彈跳面板.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();
- Debug.Log(str);
- 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 strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}&PA3={5}&PA4={6}&PA5={7}", strcon, se, pa, pa1, pa2, pa3, pa4, pa5);
- 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 strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}&PA2={4}&PA3={5}&PA4={6}&PA5={7}", strcon, se, pa, pa1, pa2, pa3, pa4, pa5);
- 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;
- }
-
- return null;
- }
- private 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;
- }
- 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);
- }
-
- }
|