Нема описа
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  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.Runtime.InteropServices;
  18. public class 加班申請 : MonoBehaviour
  19. {
  20. [SerializeField] Button 存檔紐;
  21. [SerializeField] Button 刪除紐;
  22. [SerializeField] Button 切換紐;
  23. [SerializeField] Button 回首紐;
  24. [SerializeField] RawImage 縮圖;
  25. [SerializeField] RawImage 拍照用;
  26. [SerializeField] RawImage 放圖用;
  27. [SerializeField] GameObject 主頁;
  28. [SerializeField] GameObject 圖頁;
  29. [SerializeField] TextMeshProUGUI 提示字;
  30. private WebCamTexture myCam;//接收攝影機返回的圖片數據
  31. public GameObject buttonPrefab;
  32. public Transform buttonParent;
  33. public GameObject buttonceneter;
  34. private List<GameObject> copy = new List<GameObject>();
  35. public GameObject buttonPrefab1;
  36. public Transform buttonParent1;
  37. public GameObject buttonceneter1;
  38. private List<GameObject> copy1 = new List<GameObject>();
  39. public TMP_Dropdown 年;
  40. public TMP_Dropdown 月;
  41. public TMP_Dropdown 假別;
  42. [SerializeField] TextMeshProUGUI 日期;
  43. [SerializeField] TextMeshProUGUI 申請人;
  44. [SerializeField] TextMeshProUGUI 編號;
  45. [SerializeField] TMP_InputField 事由;
  46. public CanvasScaler canvasScaler;
  47. [SerializeField] GameObject 人員清單面板;
  48. [SerializeField] GameObject 人員清單按鈕;
  49. [SerializeField] GameObject 讀取面板;
  50. [SerializeField] TextMeshProUGUI 讀取;
  51. [SerializeField] GameObject 彈跳面板;
  52. [SerializeField] TextMeshProUGUI 彈跳文字;
  53. private string loadingText = "";
  54. private int dotCount = 0;
  55. string 生效;
  56. string 圖片資料庫;
  57. bool 是否有圖;
  58. string 選擇資料庫;
  59. string 選擇流水號;
  60. void Start()
  61. {
  62. Screen.autorotateToPortrait = false;
  63. Screen.orientation = ScreenOrientation.Portrait;
  64. Main.Global.螢幕方向="直";
  65. //Main.Global.固高=1900f;
  66. //Main.Global.固寬=900f;
  67. //Main.Global.固比=1f;
  68. //Main.Global.螢幕格式="瘦";
  69. //Main.Global.考勤主管權限=false;
  70. //Main.Global.PA="盧婕柔";
  71. //Main.Global.編號="999";
  72. canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高);
  73. canvasScaler.matchWidthOrHeight=Main.Global.固比;
  74. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/hskin_login.php?";
  75. //Main.Global.預設伺服器路徑="test";
  76. 存檔紐.interactable = false;
  77. 刪除紐.interactable = false;
  78. 切換紐.interactable = false;
  79. 回首紐.interactable = true;
  80. 主頁.SetActive(true);
  81. 圖頁.SetActive(false);
  82. if (Main.Global.考勤主管權限==true)
  83. {
  84. 人員清單按鈕.SetActive(true);
  85. }
  86. else
  87. {
  88. 人員清單按鈕.SetActive(false);
  89. }
  90. StartCoroutine(AnimateText());
  91. StartCoroutine(圖片資料庫選擇());
  92. }
  93. IEnumerator AnimateText()
  94. {
  95. string qqq = 讀取.text.ToString();
  96. while (true)
  97. {
  98. yield return new WaitForSeconds(0.5f);
  99. if (dotCount < 3)
  100. {
  101. loadingText += ".";
  102. dotCount++;
  103. }
  104. else
  105. {
  106. loadingText = "";
  107. dotCount = 0;
  108. }
  109. 讀取.text = qqq+loadingText;
  110. }
  111. }
  112. IEnumerator 圖片資料庫選擇()
  113. {
  114. 讀取面板.SetActive(true);
  115. string strcon = "圖片資料庫選擇";
  116. string se = Main.Global.預設伺服器路徑;
  117. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  118. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  119. yield return request.SendWebRequest();
  120. if (request.result == UnityWebRequest.Result.ConnectionError)
  121. {
  122. //Debug.Log(request.error);
  123. yield break;
  124. }
  125. string str = request.downloadHandler.text.ToString();
  126. if (str == "n")
  127. {
  128. 讀取面板.SetActive(false);
  129. 彈跳面板.SetActive(true);
  130. 彈跳文字.text = "圖片資料庫已滿,請找系統管理員!!";
  131. yield return new WaitForSeconds(2);
  132. change_Secen(2);
  133. }
  134. else
  135. {
  136. 圖片資料庫 =str;
  137. Debug.Log(圖片資料庫);
  138. yield return StartCoroutine(年份清單());
  139. }
  140. }
  141. IEnumerator 年份清單()
  142. {
  143. string strcon = "年份清單";
  144. string se = Main.Global.預設伺服器路徑;
  145. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  146. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  147. yield return request.SendWebRequest();
  148. if (request.result == UnityWebRequest.Result.ConnectionError)
  149. {
  150. //Debug.Log(request.error);
  151. yield break;
  152. }
  153. JSONNode json = JSON.Parse(request.downloadHandler.text);
  154. 年.options.Clear();
  155. List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
  156. for (int i = 0; i < json.Count; i++)
  157. {
  158. string str = json[i].ToString().Trim('"');
  159. options.Add(new TMP_Dropdown.OptionData(str));
  160. }
  161. 年.AddOptions(options);
  162. DateTime currentDate = DateTime.Now;
  163. string year = currentDate.Year.ToString();
  164. string month = currentDate.Month.ToString("D2");
  165. int currentIndex = 年.options.FindIndex(option => option.text == year);
  166. 年.value = currentIndex;
  167. int currentIndex1 = 月.options.FindIndex(option => option.text == month);
  168. 月.value = currentIndex1;
  169. 年.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
  170. 月.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
  171. if (Main.Global.PA=="測試號")
  172. {
  173. 申請人.text=Main.Global.PA;
  174. 編號.text=Main.Global.編號;
  175. yield return StartCoroutine(加班申請明細表());
  176. }
  177. else
  178. {
  179. yield return StartCoroutine(請假申請人員清單());
  180. }
  181. }
  182. private void OnDropdown1ValueChanged()
  183. {
  184. StartCoroutine(請假申請人員清單());
  185. }
  186. IEnumerator 請假申請人員清單()
  187. {
  188. 讀取面板.SetActive(true);
  189. if (copy!= null)
  190. {
  191. DeleteCopies(copy);
  192. }
  193. string strcon = "請假申請人員清單";
  194. string se = Main.Global.預設伺服器路徑;
  195. string pa = 月.options[月.value].text;
  196. string pa1 = 年.options[年.value].text;
  197. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  198. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  199. yield return request.SendWebRequest();
  200. if (request.result == UnityWebRequest.Result.ConnectionError)
  201. {
  202. //Debug.Log(request.error);
  203. yield break;
  204. }
  205. JSONNode json = JSON.Parse(request.downloadHandler.text);
  206. int sum = 5;
  207. for (int i = 0; i < json.Count; i++)
  208. {
  209. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  210. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  211. buttonObj.transform.SetParent(buttonParent, false);
  212. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  213. text[0].text = (i+1).ToString();
  214. text[1].text = json[i][1].ToString().Trim('"');
  215. text[2].text = json[i][2].ToString().Trim('"');
  216. Button bt = buttonObj.GetComponentInChildren<Button>();
  217. int index = i;
  218. bt.onClick.AddListener(() =>
  219. {
  220. 人員清單面板.SetActive(false);
  221. 申請人.text=json[index][2].ToString().Trim('"');
  222. 編號.text=json[index][1].ToString().Trim('"');
  223. 日期.text ="";
  224. 事由.text ="";
  225. StartCoroutine(加班申請明細表());
  226. });
  227. sum+=75;
  228. copy.Add(buttonObj);
  229. }
  230. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  231. if (Main.Global.考勤主管權限==true)
  232. {
  233. StartCoroutine(加班申請明細表());
  234. }
  235. else
  236. {
  237. 申請人.text=Main.Global.PA;
  238. 編號.text=Main.Global.編號;
  239. StartCoroutine(加班申請明細表());
  240. }
  241. }
  242. IEnumerator 加班申請明細表()
  243. {
  244. 讀取面板.SetActive(true);
  245. if (copy1!= null)
  246. {
  247. DeleteCopies(copy1);
  248. }
  249. string strcon = "加班申請明細表";
  250. string se = Main.Global.預設伺服器路徑;
  251. string pa = 編號.text;
  252. string pa1 = 年.options[年.value].text + "/" + 月.options[月.value].text;
  253. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  254. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  255. yield return request.SendWebRequest();
  256. if (request.result == UnityWebRequest.Result.ConnectionError)
  257. {
  258. //Debug.Log(request.error);
  259. yield break;
  260. }
  261. JSONNode json = JSON.Parse(request.downloadHandler.text);
  262. int sum = 5;
  263. for (int i = 0; i < json.Count; i++)
  264. {
  265. for (int j = 0; j < json[0].Count; j++)
  266. {
  267. if (json[i][j] == null)
  268. {
  269. json[i][j]="";
  270. }
  271. }
  272. }
  273. for (int i = 0; i < json.Count; i++)
  274. {
  275. GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
  276. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  277. buttonObj.transform.SetParent(buttonParent1, false);
  278. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  279. SetTextValue(text[0], json[i][0]);
  280. SetTextValue(text[1], json[i][1]);
  281. SetTextValue(text[2], json[i][2]);
  282. SetTextValue(text[3], json[i][3]);
  283. SetTextValue(text[4], json[i][4]);
  284. Image[] childImages = buttonObj.GetComponentsInChildren<Image>();
  285. string da = json[i][1].ToString().Trim('"');
  286. string da1 = json[i][2].ToString().Trim('"');
  287. if (da=="星期日")
  288. {
  289. foreach (Image childImage in childImages)
  290. {
  291. if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
  292. {
  293. childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
  294. }
  295. }
  296. }
  297. if (da=="星期六")
  298. {
  299. foreach (Image childImage in childImages)
  300. {
  301. if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
  302. {
  303. childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
  304. }
  305. }
  306. }
  307. if (da1=="國定假日")
  308. {
  309. foreach (Image childImage in childImages)
  310. {
  311. if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
  312. {
  313. childImage.color = new Color32(255, 160, 160, 255); // 改為紅色,你可以自己更改顏色
  314. }
  315. }
  316. }
  317. else if (da1 != "")
  318. {
  319. foreach (Image childImage in childImages)
  320. {
  321. if (childImage.transform.parent == buttonObj.transform) // 檢查是否是小圖像
  322. {
  323. childImage.color = new Color32(255, 255, 130, 255); // 改為紅色,你可以自己更改顏色
  324. }
  325. }
  326. }
  327. Button bt = buttonObj.GetComponentInChildren<Button>();
  328. Image im = bt.GetComponentInChildren<Image>();
  329. im.color = new Color32(255, 255, 255, 0);
  330. int index = i;
  331. bt.onClick.AddListener(() =>
  332. {
  333. if (json[index][1].ToString().Trim('"')=="星期六" || json[index][1].ToString().Trim('"')=="星期日" || json[index][2].ToString().Trim('"')=="國定假日")
  334. {
  335. 彈跳面板.SetActive(true);
  336. 彈跳文字.text = "星期六/星期日或國定假日不需要申請休假!!";
  337. }
  338. else
  339. {
  340. 日期.text =json[index][0].ToString().Trim('"');
  341. 生效 =json[index][4].ToString().Trim('"');
  342. 選擇資料庫=json[index][9].ToString().Trim('"');
  343. 選擇流水號=json[index][10].ToString().Trim('"');
  344. 存檔紐.interactable = true;
  345. 刪除紐.interactable = true;
  346. 切換紐.interactable = true;
  347. 回首紐.interactable = true;
  348. SetTextValue1(事由, json[index][3]);
  349. int currentIndex = 假別.options.FindIndex(option => option.text == json[index][2].ToString().Trim('"'));
  350. 假別.value = currentIndex;
  351. 縮圖.texture =Texture2D.blackTexture;
  352. if (選擇資料庫 !="" && 選擇流水號 !="")
  353. {
  354. 讀取圖片();
  355. }
  356. else
  357. {
  358. 放圖用.texture =Texture2D.blackTexture;
  359. }
  360. Debug.Log(生效);
  361. Debug.Log(選擇資料庫);
  362. Debug.Log(選擇流水號);
  363. }
  364. });
  365. sum+=75;
  366. copy1.Add(buttonObj);
  367. }
  368. buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
  369. 讀取面板.SetActive(false);
  370. }
  371. public void 讀取圖片()
  372. {
  373. string ip = "";
  374. if (Main.Global.預設伺服器路徑=="test")
  375. {
  376. ip="106.1.48.106,4567";
  377. }
  378. else
  379. {
  380. ip="mssql-147629-0.cloudclusters.net,12711";
  381. }
  382. string connectionString = "Data Source="+ ip +";Initial Catalog="+ 選擇資料庫 +";User ID=B70340;Password=Lee0911274990";
  383. Debug.Log(connectionString);
  384. using (SqlConnection connection = new SqlConnection(connectionString))
  385. {
  386. try
  387. {
  388. connection.Open();
  389. string query = "SELECT 圖片 FROM 加班圖片庫 WHERE 流水號 LIKE '" + 選擇流水號 + "'";
  390. using (SqlCommand command = new SqlCommand(query, connection))
  391. {
  392. using (SqlDataReader reader = command.ExecuteReader())
  393. {
  394. if (reader.Read())
  395. {
  396. // 讀取圖片的二進位資料
  397. byte[] imageData = (byte[])reader["圖片"];
  398. // 將二進位資料轉換為 Texture2D
  399. Texture2D texture = new Texture2D(1, 1);
  400. texture.LoadImage(imageData);
  401. // 將 Texture2D 設置為 RawImage 的 texture
  402. 放圖用.texture = texture;
  403. float aspectRatio = (float)texture.width / texture.height;
  404. float newWidth = Mathf.Min(720f, 放圖用.rectTransform.rect.width);
  405. float newHeight = newWidth / aspectRatio;
  406. 放圖用.rectTransform.sizeDelta = new Vector2(newWidth, newHeight);
  407. }
  408. }
  409. }
  410. }
  411. catch (Exception ex)
  412. {
  413. Debug.LogError("Error connecting to the database: " + ex.Message);
  414. 彈跳面板.SetActive(true);
  415. 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
  416. }
  417. finally
  418. {
  419. connection.Close();
  420. }
  421. }
  422. }
  423. private void SetTextValue1(TMP_InputField text, string value)
  424. {
  425. if (value == null)
  426. {
  427. text.text = "";
  428. }
  429. else
  430. {
  431. string jsonString = value.Trim('"');
  432. string unescapedString = Regex.Unescape(jsonString);
  433. text.text = unescapedString;
  434. }
  435. }
  436. private void SetTextValue(TextMeshProUGUI text, string value)
  437. {
  438. if (value == null)
  439. {
  440. text.text = "";
  441. }
  442. else
  443. {
  444. string jsonString = value.Trim('"');
  445. string unescapedString = Regex.Unescape(jsonString);
  446. text.text = unescapedString;
  447. }
  448. }
  449. public void 修改()
  450. {
  451. if (申請人.text == "" || 日期.text =="" )
  452. {
  453. 彈跳面板.SetActive(true);
  454. 彈跳文字.text = "人員、日期 不能為空白!!";
  455. }
  456. else
  457. {
  458. if (生效 == "已核准" || 生效 =="未核准")
  459. {
  460. 彈跳面板.SetActive(true);
  461. 彈跳文字.text = "已簽核的資料不能再做修改";
  462. }
  463. else
  464. {
  465. StartCoroutine(是否有加班資料());
  466. }
  467. }
  468. }
  469. public void 刪除()
  470. {
  471. if (申請人.text == "" || 日期.text =="")
  472. {
  473. 彈跳面板.SetActive(true);
  474. 彈跳文字.text = "人員、日期 不能為空白!!";
  475. }
  476. else
  477. {
  478. if (生效 == "已核准" || 生效 =="未核准")
  479. {
  480. 彈跳面板.SetActive(true);
  481. 彈跳文字.text = "已簽核的資料不能再做修改";
  482. }
  483. else
  484. {
  485. StartCoroutine(加班資料刪除());
  486. }
  487. }
  488. }
  489. IEnumerator 是否有加班資料()
  490. {
  491. 讀取面板.SetActive(true);
  492. string strcon = "是否有加班資料";
  493. string se = Main.Global.預設伺服器路徑;
  494. string pa = 日期.text;
  495. string pa1 = 編號.text;
  496. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  497. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  498. yield return request.SendWebRequest();
  499. if (request.result == UnityWebRequest.Result.ConnectionError)
  500. {
  501. //Debug.Log(request.error);
  502. yield break;
  503. }
  504. string str = request.downloadHandler.text.ToString();
  505. Debug.Log(str);
  506. if (str == "n")
  507. {
  508. yield return StartCoroutine(查詢最後一筆加班圖片編號("新增"));
  509. }
  510. else
  511. {
  512. if (選擇資料庫 !="" && 選擇流水號 !="")
  513. {
  514. yield return StartCoroutine(加班資料修改(""));
  515. }
  516. else
  517. {
  518. yield return StartCoroutine(查詢最後一筆加班圖片編號("修改"));
  519. }
  520. }
  521. }
  522. IEnumerator 加班資料新增(string 新流水)
  523. {
  524. string pa4 = "";
  525. string pa5 = "";
  526. if (縮圖.texture != null && 縮圖.texture != Texture2D.blackTexture)
  527. {
  528. 圖片上傳(新流水);
  529. pa4 = 圖片資料庫;
  530. pa5 = 新流水;
  531. }
  532. string strcon = "加班資料新增";
  533. string se = Main.Global.預設伺服器路徑;
  534. string pa = 編號.text;
  535. string pa1 = 日期.text;
  536. string pa2 = 假別.options[假別.value].text;
  537. string pa3 = 事由.text;
  538. 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);
  539. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  540. yield return request.SendWebRequest();
  541. if (request.result == UnityWebRequest.Result.ConnectionError)
  542. {
  543. //Debug.Log(request.error);
  544. yield break;
  545. }
  546. yield return StartCoroutine(加班申請明細表());
  547. 縮圖.texture = Texture2D.blackTexture;
  548. 彈跳面板.SetActive(true);
  549. 彈跳文字.text = "新增成功";
  550. }
  551. IEnumerator 查詢最後一筆加班圖片編號(string 狀態)
  552. {
  553. string strcon = "查詢最後一筆加班圖片編號";
  554. string se = Main.Global.預設伺服器路徑;
  555. string pa1 = 圖片資料庫;
  556. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se, pa1);
  557. Debug.Log(strUrl);
  558. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  559. yield return request.SendWebRequest();
  560. if (request.result == UnityWebRequest.Result.ConnectionError)
  561. {
  562. //Debug.Log(request.error);
  563. yield break;
  564. }
  565. string str = request.downloadHandler.text.ToString();
  566. if (str == "n")
  567. {
  568. str ="IR00000000";
  569. }
  570. string cnum = str.Substring(2);
  571. int inum = int.Parse(cnum);
  572. inum+=1;
  573. string 新流水 = "IR";
  574. if (inum<10)
  575. {
  576. 新流水+="0000000"+inum.ToString();
  577. }
  578. if (inum>9 && inum<100)
  579. {
  580. 新流水+="000000"+inum.ToString();
  581. }
  582. if (inum>99 && inum<1000)
  583. {
  584. 新流水+="00000"+inum.ToString();
  585. }
  586. if (inum>999 && inum<10000)
  587. {
  588. 新流水+="0000"+inum.ToString();
  589. }
  590. if (inum>9999 && inum<100000)
  591. {
  592. 新流水+="000"+inum.ToString();
  593. }
  594. if (inum>99999 && inum<10000000)
  595. {
  596. 新流水+="00"+inum.ToString();
  597. }
  598. if (inum>999999 && inum<10000000)
  599. {
  600. 新流水+="0"+inum.ToString();
  601. }
  602. if (inum>9999999 && inum<100000000)
  603. {
  604. 新流水+=inum.ToString();
  605. }
  606. if (狀態 == "修改")
  607. {
  608. yield return StartCoroutine(加班資料修改(新流水));
  609. }
  610. else
  611. {
  612. yield return StartCoroutine(加班資料新增(新流水));
  613. }
  614. }
  615. public void 圖片上傳(string 流水)
  616. {
  617. string ip = "";
  618. if (Main.Global.預設伺服器路徑=="test")
  619. {
  620. ip="106.1.48.106,4567";
  621. }
  622. else
  623. {
  624. ip="mssql-147629-0.cloudclusters.net,12711";
  625. }
  626. string connectionString = "Data Source="+ ip +";Initial Catalog="+ 圖片資料庫 +";User ID=B70340;Password=Lee0911274990";
  627. Debug.Log(connectionString);
  628. using (SqlConnection connection = new SqlConnection(connectionString))
  629. {
  630. try
  631. {
  632. connection.Open();
  633. Texture2D texture2D = new Texture2D((放圖用.texture as Texture2D).width, (放圖用.texture as Texture2D).height);
  634. Graphics.CopyTexture(放圖用.texture, texture2D);
  635. // 將 Texture2D 轉換為 PNG 格式的二進制數據
  636. byte[] imageBytes = texture2D.EncodeToPNG();
  637. string query = "INSERT INTO 加班圖片庫 (流水號, 圖片) VALUES (@流水號, @binary_file)";
  638. using (SqlCommand command = new SqlCommand(query, connection))
  639. {
  640. // 添加流水號參數
  641. command.Parameters.AddWithValue("@流水號", 流水);
  642. // 添加二進制圖片數據參數
  643. command.Parameters.AddWithValue("@binary_file", imageBytes);
  644. int rowsAffected = command.ExecuteNonQuery();
  645. Debug.Log("成功插入 " + rowsAffected + " 行數據");
  646. }
  647. }
  648. catch (Exception ex)
  649. {
  650. Debug.LogError("Error connecting to the database: " + ex.Message);
  651. 彈跳面板.SetActive(true);
  652. 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
  653. }
  654. finally
  655. {
  656. connection.Close();
  657. }
  658. }
  659. }
  660. public void 圖片修改()
  661. {
  662. string 流水 = 選擇流水號;
  663. string ip = "";
  664. if (Main.Global.預設伺服器路徑=="test")
  665. {
  666. ip="106.1.48.106,4567";
  667. }
  668. else
  669. {
  670. ip="mssql-147629-0.cloudclusters.net,12711";
  671. }
  672. string connectionString = "Data Source="+ ip +";Initial Catalog="+ 選擇資料庫 +";User ID=B70340;Password=Lee0911274990";
  673. Debug.Log(connectionString);
  674. using (SqlConnection connection = new SqlConnection(connectionString))
  675. {
  676. try
  677. {
  678. connection.Open();
  679. Texture2D texture2D = new Texture2D((放圖用.texture as Texture2D).width, (放圖用.texture as Texture2D).height);
  680. Graphics.CopyTexture(放圖用.texture, texture2D);
  681. // 將 Texture2D 轉換為 PNG 格式的二進制數據
  682. byte[] imageBytes = texture2D.EncodeToPNG();
  683. string query = "UPDATE 加班圖片庫 SET 圖片 = @binary_file WHERE 流水號 LIKE @流水號";
  684. using (SqlCommand command = new SqlCommand(query, connection))
  685. {
  686. // 添加流水號參數
  687. command.Parameters.AddWithValue("@流水號", 流水);
  688. // 添加二進制圖片數據參數
  689. command.Parameters.AddWithValue("@binary_file", imageBytes);
  690. int rowsAffected = command.ExecuteNonQuery();
  691. Debug.Log("成功修改 " + rowsAffected + " 行數據");
  692. }
  693. }
  694. catch (Exception ex)
  695. {
  696. Debug.LogError("Error connecting to the database: " + ex.Message);
  697. 彈跳面板.SetActive(true);
  698. 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
  699. }
  700. finally
  701. {
  702. connection.Close();
  703. }
  704. }
  705. }
  706. IEnumerator 加班資料修改(string 流水)
  707. {
  708. string strcon = "加班資料修改";
  709. string pa4 = 選擇資料庫;
  710. string pa5 = 選擇流水號;
  711. if (縮圖.texture != null && 縮圖.texture != Texture2D.blackTexture)
  712. {
  713. if (選擇資料庫 !="" && 選擇流水號 !="")
  714. {
  715. 圖片修改();
  716. }
  717. else
  718. {
  719. 圖片上傳(流水);
  720. pa4 = 圖片資料庫;
  721. pa5 = 流水;
  722. }
  723. }
  724. string se = Main.Global.預設伺服器路徑;
  725. string pa = 編號.text;
  726. string pa1 = 日期.text;
  727. string pa2 = 假別.options[假別.value].text;
  728. string pa3 = 事由.text;
  729. 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);
  730. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  731. Debug.Log(strUrl);
  732. yield return request.SendWebRequest();
  733. if (request.result == UnityWebRequest.Result.ConnectionError)
  734. {
  735. //Debug.Log(request.error);
  736. yield break;
  737. }
  738. 彈跳面板.SetActive(true);
  739. 彈跳文字.text = "修改成功";
  740. 縮圖.texture = Texture2D.blackTexture;
  741. yield return StartCoroutine(加班申請明細表());
  742. }
  743. IEnumerator 加班資料刪除()
  744. {
  745. 讀取面板.SetActive(true);
  746. string strcon = "加班資料刪除";
  747. string se = Main.Global.預設伺服器路徑;
  748. string pa = 日期.text;
  749. string pa1 = 編號.text;
  750. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  751. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  752. yield return request.SendWebRequest();
  753. if (request.result == UnityWebRequest.Result.ConnectionError)
  754. {
  755. //Debug.Log(request.error);
  756. yield break;
  757. }
  758. 事由.text = "";
  759. 生效="";
  760. yield return StartCoroutine(加班資料圖片刪除());
  761. }
  762. IEnumerator 加班資料圖片刪除()
  763. {
  764. string strcon = "加班資料圖片刪除";
  765. string se = Main.Global.預設伺服器路徑;
  766. string pa1 = 選擇資料庫;
  767. string pa = 選擇流水號;
  768. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA={2}&PA1={3}", strcon, se, pa, pa1);
  769. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  770. yield return request.SendWebRequest();
  771. if (request.result == UnityWebRequest.Result.ConnectionError)
  772. {
  773. //Debug.Log(request.error);
  774. yield break;
  775. }
  776. 選擇資料庫="";
  777. 選擇流水號="";
  778. 放圖用.texture =Texture2D.blackTexture;
  779. 縮圖.texture = Texture2D.blackTexture;
  780. 彈跳面板.SetActive(true);
  781. 彈跳文字.text = "刪除成功";
  782. yield return StartCoroutine(加班申請明細表());
  783. }
  784. public void 頁面切換()
  785. {
  786. if (主頁.activeSelf && !圖頁.activeSelf)
  787. {
  788. 主頁.SetActive(false);
  789. 圖頁.SetActive(true);
  790. 拍照用.gameObject.SetActive(false);
  791. 放圖用.gameObject.SetActive(true);
  792. 存檔紐.interactable = false;
  793. 刪除紐.interactable = false;
  794. 切換紐.interactable = true;
  795. 回首紐.interactable = true;
  796. }
  797. else if (圖頁.activeSelf && !主頁.activeSelf)
  798. {
  799. 圖頁.SetActive(false);
  800. 主頁.SetActive(true);
  801. if (myCam != null)
  802. {
  803. myCam.Stop();
  804. myCam = null;
  805. }
  806. 存檔紐.interactable = true;
  807. 刪除紐.interactable = true;
  808. 切換紐.interactable = true;
  809. 回首紐.interactable = true;
  810. }
  811. }
  812. public void 相機鈕()
  813. {
  814. if (拍照用.gameObject.activeSelf && !放圖用.gameObject.activeSelf)
  815. {
  816. Texture2D photoTexture = CapturePhoto();
  817. if (photoTexture != null)
  818. {
  819. 放圖用.rectTransform.sizeDelta = new Vector2(720f, 1280f);
  820. 放圖用.texture = photoTexture;
  821. 縮圖.texture = photoTexture;
  822. }
  823. 存檔紐.interactable = true;
  824. 刪除紐.interactable = true;
  825. 切換紐.interactable = true;
  826. 回首紐.interactable = true;
  827. myCam.Stop();
  828. myCam = null;
  829. 提示字.text ="";
  830. 拍照用.gameObject.SetActive(false);
  831. 放圖用.gameObject.SetActive(true);
  832. 圖頁.SetActive(false);
  833. 主頁.SetActive(true);
  834. }
  835. else if (放圖用.gameObject.activeSelf && !拍照用.gameObject.activeSelf)
  836. {
  837. StartCoroutine(open_Camera(60));
  838. 提示字.text ="拍照中";
  839. 存檔紐.interactable = false;
  840. 刪除紐.interactable = false;
  841. 切換紐.interactable = false;
  842. 回首紐.interactable = false;
  843. 拍照用.gameObject.SetActive(true);
  844. 放圖用.gameObject.SetActive(false);
  845. }
  846. }
  847. private IEnumerator open_Camera(int fps)
  848. {
  849. yield return Application.RequestUserAuthorization(UserAuthorization.WebCam); //授權開啟鏡頭
  850. if (Application.HasUserAuthorization(UserAuthorization.WebCam))
  851. {
  852. /* (攝影機名稱, 攝影機要拍到的寬度, 攝影機要拍到的高度, 攝影機的FPS) */
  853. myCam = new WebCamTexture(WebCamTexture.devices[0].name, 720, 1280, fps);
  854. 拍照用.texture = myCam;
  855. myCam.Play();//開啟攝影機
  856. }
  857. }
  858. private Texture2D CapturePhoto()
  859. {
  860. if (myCam != null)
  861. {
  862. int width = myCam.width;
  863. int height = myCam.height;
  864. // 创建一个新的 Texture2D,并读取当前帧的像素
  865. Texture2D photoTexture = new Texture2D(width, height);
  866. photoTexture.SetPixels(myCam.GetPixels());
  867. photoTexture.Apply();
  868. Texture2D rotatedTexture = RotateTexture(photoTexture, true);
  869. return rotatedTexture;
  870. }
  871. return null;
  872. }
  873. private Texture2D RotateTexture(Texture2D originalTexture, bool clockwise)
  874. {
  875. int width = originalTexture.width;
  876. int height = originalTexture.height;
  877. Texture2D rotatedTexture = new Texture2D(height, width);
  878. Color32[] originalPixels = originalTexture.GetPixels32();
  879. Color32[] rotatedPixels = new Color32[width * height];
  880. for (int y = 0; y < height; y++)
  881. {
  882. for (int x = 0; x < width; x++)
  883. {
  884. int newX = clockwise ? y : height - y - 1;
  885. int newY = clockwise ? width - x - 1 : x;
  886. rotatedPixels[newY * height + newX] = originalPixels[y * width + x];
  887. }
  888. }
  889. rotatedTexture.SetPixels32(rotatedPixels);
  890. rotatedTexture.Apply();
  891. return rotatedTexture;
  892. }
  893. public void 彈跳面板關閉()
  894. {
  895. 彈跳面板.SetActive(false);
  896. 彈跳文字.text = "";
  897. }
  898. public void 人員面板關閉()
  899. {
  900. 人員清單面板.SetActive(false);
  901. }
  902. public void 人員面板開啟()
  903. {
  904. 人員清單面板.SetActive(true);
  905. }
  906. private void DeleteCopies(List<GameObject> copyList)
  907. {
  908. foreach (GameObject copy in copyList)
  909. {
  910. Destroy(copy);
  911. }
  912. copyList.Clear();
  913. }
  914. public void back()
  915. {
  916. change_Secen(2);
  917. }
  918. public void change_Secen(int _screenNum)
  919. {
  920. SceneManager.LoadScene(_screenNum);
  921. }
  922. }