Brak opisu
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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  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 UnityEngine.EventSystems;
  8. using System.Text.RegularExpressions;
  9. using System.Data.SqlClient;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using TMPro;
  13. using System;
  14. using System.IO;
  15. using System.Net;
  16. using System.Data;
  17. using SimpleJSON;
  18. using System.Linq;
  19. using System.ComponentModel;
  20. using System.Runtime.InteropServices;
  21. using System.Globalization;
  22. using static System.Net.WebRequestMethods;
  23. public class Main : MonoBehaviour
  24. {
  25. [SerializeField] GameObject 面板1;
  26. [SerializeField] GameObject 面板2;
  27. [SerializeField] GameObject 讀取面板;
  28. [SerializeField] TextMeshProUGUI 讀取;
  29. [SerializeField] GameObject 股東帳1;
  30. [SerializeField] Toggle 股東帳;
  31. [SerializeField] TextMeshProUGUI 天;
  32. [SerializeField] TextMeshProUGUI 周;
  33. [SerializeField] TextMeshProUGUI 月;
  34. [SerializeField] TextMeshProUGUI 天1;
  35. [SerializeField] TextMeshProUGUI 周1;
  36. [SerializeField] TextMeshProUGUI 月1;
  37. public GameObject buttonPrefab;
  38. public ScrollRect buttonscroll;
  39. private List<GameObject> copy = new List<GameObject>();
  40. public GameObject buttonPrefab1;
  41. public ScrollRect buttonscroll1;
  42. private List<GameObject> copy1 = new List<GameObject>();
  43. public CanvasScaler canvasScaler;
  44. private float timer = 0f;
  45. private float interval = 60f;
  46. float screenWidth;
  47. float screenHeight;
  48. private string loadingText = "";
  49. private int dotCount = 0;
  50. string 選擇日期;
  51. string 本周一;
  52. string 月初;
  53. string 年初;
  54. string 開始日期;
  55. string 結束日期;
  56. string PA2;
  57. JSONArray 彙總1;
  58. JSONNode 彙總2;
  59. JSONNode 彙總3;
  60. JSONNode 彙總4;
  61. JSONNode 彙總5;
  62. JSONNode 彙總6;
  63. JSONNode 彙總7;
  64. string 路徑1;
  65. // Start is called before the first frame update
  66. void Start()
  67. {
  68. Screen.autorotateToPortrait = false;
  69. Screen.orientation = ScreenOrientation.Portrait;
  70. screenWidth = Screen.width;
  71. screenHeight = Screen.height;
  72. float rate = 900.0f / 1900.0f;
  73. if (canvasScaler == null)
  74. {
  75. canvasScaler = GetComponent<CanvasScaler>();
  76. }
  77. Main.Global.rate = screenWidth/screenHeight;
  78. if (Main.Global.rate>rate)
  79. {
  80. canvasScaler.matchWidthOrHeight = 1f;
  81. }
  82. else
  83. {
  84. canvasScaler.matchWidthOrHeight = 0f;
  85. }
  86. StartCoroutine(AnimateText());
  87. 讀取面板.SetActive(true);
  88. 面板1.SetActive(true);
  89. 面板2.SetActive(false);
  90. if (Main.Global.股東)
  91. {
  92. 股東帳1.SetActive(true);
  93. }
  94. else
  95. {
  96. 股東帳1.SetActive(false);
  97. }
  98. AdManager.Instance.ShowInterstitialAd();
  99. StartCoroutine(讀取IP());
  100. }
  101. private void 輸入日期(string date)
  102. {
  103. DateTime today = DateTime.ParseExact(date, "yyyy/MM/dd", null);
  104. DateTime yearStart = new DateTime(today.Year, 1, 1);
  105. DateTime monthStart = new DateTime(today.Year, today.Month, 1);
  106. int daysUntilMonday = ((int)DayOfWeek.Monday - (int)today.DayOfWeek + 7) % 7;
  107. if (daysUntilMonday == 0)
  108. {
  109. daysUntilMonday = 7; // 如果差距為 0,則禮拜一仍在本周
  110. }
  111. DateTime monday = today.AddDays(daysUntilMonday-7);
  112. 選擇日期 = today.ToString("yyyy/MM/dd");
  113. 年初 = yearStart.ToString("yyyy/MM/dd");
  114. 月初 = monthStart.ToString("yyyy/MM/dd");
  115. 本周一= monday.ToString("yyyy/MM/dd");
  116. }
  117. IEnumerator AnimateText()
  118. {
  119. string qqq = 讀取.text.ToString();
  120. while (true)
  121. {
  122. yield return new WaitForSeconds(0.5f);
  123. if (dotCount < 3)
  124. {
  125. loadingText += ".";
  126. dotCount++;
  127. }
  128. else
  129. {
  130. loadingText = "";
  131. dotCount = 0;
  132. }
  133. 讀取.text = qqq+loadingText;
  134. }
  135. }
  136. IEnumerator 讀取IP()
  137. {
  138. string strcon = "讀取IP";
  139. string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}", strcon);
  140. Debug.Log(strUrl);
  141. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  142. yield return request.SendWebRequest();
  143. if (request.result == UnityWebRequest.Result.ConnectionError)
  144. {
  145. //Debug.Log(request.error);
  146. }
  147. string query = request.downloadHandler.text.ToString();
  148. using (SqlConnection connection = new SqlConnection(Main.Global.路徑))
  149. {
  150. try
  151. {
  152. connection.Open();
  153. using (SqlCommand command = new SqlCommand(query, connection))
  154. {
  155. using (SqlDataReader reader = command.ExecuteReader())
  156. {
  157. if (reader.Read())
  158. {
  159. string pa = reader.GetString("資料庫");
  160. string pa1 = reader.GetString("IP位置");
  161. string pa2 = reader.GetString("帳號");
  162. string pa3 = reader.GetString("密碼");
  163. 路徑1 = string.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3}", pa1, pa, pa2, pa3);
  164. Debug.Log(路徑1);
  165. StartCoroutine(日期清單());
  166. }
  167. }
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. Debug.LogError("Error connecting to the database: " + ex.Message);
  173. }
  174. finally
  175. {
  176. connection.Close();
  177. }
  178. }
  179. }
  180. IEnumerator 日期清單()
  181. {
  182. string strcon = "日期清單";
  183. string strUrl = string.Format(Main.Global.阿帕契路徑+ "comm={0}", strcon);
  184. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  185. yield return request.SendWebRequest();
  186. if (request.result == UnityWebRequest.Result.ConnectionError)
  187. {
  188. //Debug.Log(request.error);
  189. }
  190. string query = request.downloadHandler.text.ToString();
  191. Debug.Log(query);
  192. Debug.Log(路徑1);
  193. JSONArray json = new JSONArray();
  194. using (SqlConnection connection = new SqlConnection(路徑1))
  195. {
  196. try
  197. {
  198. connection.Open();
  199. using (SqlCommand command = new SqlCommand(query, connection))
  200. {
  201. using (SqlDataReader reader = command.ExecuteReader())
  202. {
  203. while (reader.Read()) // 逐行讀取資料
  204. {
  205. JSONNode jsona = new JSONObject(); // 創建 JSON 物件來存放每一行的資料
  206. for (int i = 0; i < reader.FieldCount; i++)
  207. {
  208. string columnName = reader.GetName(i); // 取得欄位名稱
  209. string value = reader.GetValue(i).ToString(); // 取得欄位值,並轉換成字串形式
  210. jsona[columnName] = value; // 將欄位名稱和值加入 JSON 物件中
  211. }
  212. json.Add(jsona); // 將整個 JSON 物件加入 JSON Array 中
  213. }
  214. }
  215. int sum = 0;
  216. for (int i = 0; i < json.Count; i++)
  217. {
  218. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  219. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(3, -sum);
  220. Transform tran = buttonscroll.content;
  221. buttonObj.transform.SetParent(tran, false);
  222. TextMeshProUGUI[] texts = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  223. texts[0].text = json[i][1].ToString().Trim('"');
  224. texts[1].text = json[i][2].ToString().Trim('"');
  225. Button bt = buttonObj.GetComponentInChildren<Button>();
  226. int index = i;
  227. bt.onClick.AddListener(() =>
  228. {
  229. if (股東帳.isOn == true)
  230. {
  231. PA2 = "And (後台商客基本資料表.自訂 = 1)";
  232. }
  233. else
  234. {
  235. PA2 = "";
  236. }
  237. 開始日期 = json[index][1].ToString().Trim('"');
  238. 結束日期 = json[index][2].ToString().Trim('"');
  239. DateTime parsedDate = DateTime.ParseExact(開始日期, "yyyy-MM-dd", null);
  240. string formattedDate = parsedDate.ToString("yyyy/MM/dd");
  241. 輸入日期(formattedDate);
  242. 面板1.SetActive(false);
  243. 面板2.SetActive(true);
  244. 天.text = 選擇日期;
  245. 周.text = 本周一;
  246. 月.text = 月初;
  247. 讀取面板.SetActive(true);
  248. StartCoroutine(後台彙總讀取2());
  249. });
  250. sum += 100;
  251. copy.Add(buttonObj);
  252. }
  253. RectTransform contentTransform = buttonscroll.content;
  254. contentTransform.anchoredPosition = new Vector2(contentTransform.anchoredPosition.x, 0);
  255. contentTransform.sizeDelta = new Vector2(contentTransform.sizeDelta.x, sum);
  256. if (sum > 1652)
  257. {
  258. buttonscroll.vertical = true;
  259. }
  260. else
  261. {
  262. buttonscroll.vertical = false;
  263. }
  264. 讀取面板.SetActive(false);
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. Debug.LogError("Error connecting to the database: " + ex.Message);
  270. 讀取面板.SetActive(false);
  271. yield break;
  272. }
  273. finally
  274. {
  275. connection.Close();
  276. }
  277. }
  278. }
  279. IEnumerator 後台彙總讀取2()
  280. {
  281. string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}", "後台彙總讀取2");
  282. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  283. yield return request.SendWebRequest();
  284. if (request.result == UnityWebRequest.Result.ConnectionError)
  285. {
  286. //Debug.Log(request.error);
  287. }
  288. string query = string.Format(request.downloadHandler.text.ToString(), 開始日期, 結束日期, PA2);
  289. Debug.Log(query);
  290. 彙總1 = new JSONArray();
  291. using (SqlConnection connection = new SqlConnection(路徑1))
  292. {
  293. try
  294. {
  295. connection.Open();
  296. using (SqlCommand command = new SqlCommand(query, connection))
  297. {
  298. using (SqlDataReader reader = command.ExecuteReader())
  299. {
  300. while (reader.Read()) // 逐行讀取資料
  301. {
  302. JSONNode jsona = new JSONObject(); // 創建 JSON 物件來存放每一行的資料
  303. for (int i = 0; i < reader.FieldCount; i++)
  304. {
  305. string columnName = reader.GetName(i); // 取得欄位名稱
  306. string value = reader.GetValue(i).ToString(); // 取得欄位值,並轉換成字串形式
  307. jsona[columnName] = value; // 將欄位名稱和值加入 JSON 物件中
  308. }
  309. 彙總1.Add(jsona); // 將整個 JSON 物件加入 JSON Array 中
  310. }
  311. }
  312. for (int i = 0; i < 彙總1.Count; i++)
  313. {
  314. if (彙總1[i][14] == null || 彙總1[i][14].ToString() == "")
  315. {
  316. 彙總1[i][14] = "0";
  317. }
  318. 彙總1[i][11] = 彙總1[i][13].ToString().Trim('"');
  319. }
  320. StartCoroutine(後台彙總讀取2_1());
  321. }
  322. }
  323. catch (Exception ex)
  324. {
  325. Debug.LogError("Error connecting to the database: " + ex.Message);
  326. 讀取面板.SetActive(false);
  327. yield break;
  328. }
  329. finally
  330. {
  331. connection.Close();
  332. }
  333. }
  334. }
  335. IEnumerator 後台彙總讀取2_1()
  336. {
  337. string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}", "後台彙總讀取2");
  338. DateTime parsedDate = DateTime.ParseExact(本周一, "yyyy/MM/dd", null);
  339. string formattedDate = parsedDate.ToString("yyyy-MM-dd");
  340. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  341. yield return request.SendWebRequest();
  342. if (request.result == UnityWebRequest.Result.ConnectionError)
  343. {
  344. //Debug.Log(request.error);
  345. }
  346. string query = string.Format(request.downloadHandler.text.ToString(), formattedDate, 結束日期, PA2);
  347. Debug.Log(query);
  348. 彙總2 = new JSONArray();
  349. using (SqlConnection connection = new SqlConnection(路徑1))
  350. {
  351. try
  352. {
  353. connection.Open();
  354. using (SqlCommand command = new SqlCommand(query, connection))
  355. {
  356. using (SqlDataReader reader = command.ExecuteReader())
  357. {
  358. while (reader.Read()) // 逐行讀取資料
  359. {
  360. JSONNode jsona = new JSONObject(); // 創建 JSON 物件來存放每一行的資料
  361. for (int i = 0; i < reader.FieldCount; i++)
  362. {
  363. string columnName = reader.GetName(i); // 取得欄位名稱
  364. string value = reader.GetValue(i).ToString(); // 取得欄位值,並轉換成字串形式
  365. jsona[columnName] = value; // 將欄位名稱和值加入 JSON 物件中
  366. }
  367. 彙總2.Add(jsona); // 將整個 JSON 物件加入 JSON Array 中
  368. }
  369. }
  370. for (int i = 0; i < 彙總2.Count; i++)
  371. {
  372. if (彙總2[i][14] == null || 彙總2[i][14].ToString() == "")
  373. {
  374. 彙總2[i][14] = "0";
  375. }
  376. 彙總2[i][11] = 彙總2[i][13].ToString().Trim('"');
  377. }
  378. StartCoroutine(後台彙總讀取2_2());
  379. }
  380. }
  381. catch (Exception ex)
  382. {
  383. Debug.LogError("Error connecting to the database: " + ex.Message);
  384. 讀取面板.SetActive(false);
  385. yield break;
  386. }
  387. finally
  388. {
  389. connection.Close();
  390. }
  391. }
  392. }
  393. IEnumerator 後台彙總讀取2_2()
  394. {
  395. string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}", "後台彙總讀取2");
  396. DateTime parsedDate = DateTime.ParseExact(月初, "yyyy/MM/dd", null);
  397. string formattedDate = parsedDate.ToString("yyyy-MM-dd");
  398. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  399. yield return request.SendWebRequest();
  400. if (request.result == UnityWebRequest.Result.ConnectionError)
  401. {
  402. //Debug.Log(request.error);
  403. }
  404. string query = string.Format(request.downloadHandler.text.ToString(), formattedDate, 結束日期, PA2);
  405. Debug.Log(query);
  406. 彙總6 = new JSONArray();
  407. using (SqlConnection connection = new SqlConnection(路徑1))
  408. {
  409. try
  410. {
  411. connection.Open();
  412. using (SqlCommand command = new SqlCommand(query, connection))
  413. {
  414. using (SqlDataReader reader = command.ExecuteReader())
  415. {
  416. while (reader.Read()) // 逐行讀取資料
  417. {
  418. JSONNode jsona = new JSONObject(); // 創建 JSON 物件來存放每一行的資料
  419. for (int i = 0; i < reader.FieldCount; i++)
  420. {
  421. string columnName = reader.GetName(i); // 取得欄位名稱
  422. string value = reader.GetValue(i).ToString(); // 取得欄位值,並轉換成字串形式
  423. jsona[columnName] = value; // 將欄位名稱和值加入 JSON 物件中
  424. }
  425. 彙總6.Add(jsona); // 將整個 JSON 物件加入 JSON Array 中
  426. }
  427. }
  428. for (int i = 0; i < 彙總6.Count; i++)
  429. {
  430. if (彙總6[i][14] == null || 彙總6[i][14].ToString() == "")
  431. {
  432. 彙總6[i][14] = "0";
  433. }
  434. 彙總6[i][11] = 彙總6[i][13].ToString().Trim('"');
  435. }
  436. StartCoroutine(後台彙總讀取1());
  437. }
  438. }
  439. catch (Exception ex)
  440. {
  441. Debug.LogError("Error connecting to the database: " + ex.Message);
  442. 讀取面板.SetActive(false);
  443. yield break;
  444. }
  445. finally
  446. {
  447. connection.Close();
  448. }
  449. }
  450. }
  451. IEnumerator 後台彙總讀取1()
  452. {
  453. string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}", "後台彙總讀取1");
  454. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  455. yield return request.SendWebRequest();
  456. if (request.result == UnityWebRequest.Result.ConnectionError)
  457. {
  458. //Debug.Log(request.error);
  459. }
  460. string query = string.Format(request.downloadHandler.text.ToString(), 開始日期, 結束日期, PA2);
  461. Debug.Log(query);
  462. 彙總3 = new JSONArray();
  463. using (SqlConnection connection = new SqlConnection(路徑1))
  464. {
  465. try
  466. {
  467. connection.Open();
  468. using (SqlCommand command = new SqlCommand(query, connection))
  469. {
  470. using (SqlDataReader reader = command.ExecuteReader())
  471. {
  472. while (reader.Read()) // 逐行讀取資料
  473. {
  474. JSONNode jsona = new JSONObject(); // 創建 JSON 物件來存放每一行的資料
  475. for (int i = 0; i < reader.FieldCount; i++)
  476. {
  477. string columnName = reader.GetName(i); // 取得欄位名稱
  478. string value = reader.GetValue(i).ToString(); // 取得欄位值,並轉換成字串形式
  479. jsona[columnName] = value; // 將欄位名稱和值加入 JSON 物件中
  480. }
  481. 彙總3.Add(jsona); // 將整個 JSON 物件加入 JSON Array 中
  482. }
  483. }
  484. int sum = 0;
  485. for (int i = 0; i < 彙總3.Count; i++)
  486. {
  487. 彙總3[i][5] = "0";
  488. 彙總3[i][6] = "0";
  489. 彙總3[i][7] = "0";
  490. 彙總3[i][8] = "0";
  491. 彙總3[i][9] = "0";
  492. 彙總3[i][10] = "0";
  493. for (int j = 0; j < 彙總1.Count; j++)
  494. {
  495. string n1 = 彙總3[i][2].ToString().Trim('"');
  496. string n2 = 彙總1[j][2].ToString().Trim('"');
  497. string n3 = 彙總1[j][15].ToString().Trim('"');
  498. if ((n1 == n2) && n3 == "全")
  499. {
  500. 彙總3[i][5] = 彙總1[j][10].ToString().Trim('"');
  501. 彙總3[i][6] = 彙總1[j][11].ToString().Trim('"');
  502. }
  503. }
  504. double num = double.Parse(彙總3[i][6]);
  505. int roundedValue = (int)Math.Round(num / 10000);
  506. sum = sum + roundedValue;
  507. }
  508. 天1.text = sum.ToString("#,##0");
  509. if (sum >= 0)
  510. {
  511. 天1.color = Color.blue;
  512. }
  513. else
  514. {
  515. 天1.color = Color.red;
  516. }
  517. //Debug.Log(sum);
  518. StartCoroutine(後台彙總讀取3());
  519. }
  520. }
  521. catch (Exception ex)
  522. {
  523. Debug.LogError("Error connecting to the database: " + ex.Message);
  524. 讀取面板.SetActive(false);
  525. yield break;
  526. }
  527. finally
  528. {
  529. connection.Close();
  530. }
  531. }
  532. }
  533. IEnumerator 後台彙總讀取3()
  534. {
  535. string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}", "後台彙總讀取3");
  536. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  537. yield return request.SendWebRequest();
  538. if (request.result == UnityWebRequest.Result.ConnectionError)
  539. {
  540. //Debug.Log(request.error);
  541. }
  542. DateTime parsedDate = DateTime.ParseExact(本周一, "yyyy/MM/dd", null);
  543. string formattedDate = parsedDate.ToString("yyyy-MM-dd");
  544. string query = string.Format(request.downloadHandler.text.ToString(), formattedDate, 結束日期, PA2);
  545. Debug.Log(query);
  546. 彙總4 = new JSONArray();
  547. using (SqlConnection connection = new SqlConnection(路徑1))
  548. {
  549. try
  550. {
  551. connection.Open();
  552. using (SqlCommand command = new SqlCommand(query, connection))
  553. {
  554. using (SqlDataReader reader = command.ExecuteReader())
  555. {
  556. while (reader.Read()) // 逐行讀取資料
  557. {
  558. JSONNode jsona = new JSONObject(); // 創建 JSON 物件來存放每一行的資料
  559. for (int i = 0; i < reader.FieldCount; i++)
  560. {
  561. string columnName = reader.GetName(i); // 取得欄位名稱
  562. string value = reader.GetValue(i).ToString(); // 取得欄位值,並轉換成字串形式
  563. jsona[columnName] = value; // 將欄位名稱和值加入 JSON 物件中
  564. }
  565. 彙總4.Add(jsona); // 將整個 JSON 物件加入 JSON Array 中
  566. }
  567. }
  568. int sum = 0;
  569. for (int i = 0; i < 彙總4.Count; i++)
  570. {
  571. 彙總4[i][3] = "0";
  572. 彙總4[i][4] = "0";
  573. 彙總4[i][5] = "0";
  574. 彙總4[i][6] = "0";
  575. 彙總4[i][7] = "0";
  576. 彙總4[i][8] = "0";
  577. for (int j = 0; j < 彙總2.Count; j++)
  578. {
  579. string n1 = 彙總4[i][1].ToString().Trim('"');
  580. string n2 = 彙總2[j][2].ToString().Trim('"');
  581. string n3 = 彙總2[j][15].ToString().Trim('"');
  582. if ((n1 == n2) && n3 == "全")
  583. {
  584. 彙總4[i][3] = 彙總2[j][10].ToString().Trim('"');
  585. 彙總4[i][4] = 彙總2[j][11].ToString().Trim('"');
  586. }
  587. }
  588. double num = double.Parse(彙總4[i][4]);
  589. int roundedValue = (int)Math.Round(num / 10000);
  590. sum = sum + roundedValue;
  591. }
  592. 周1.text = sum.ToString("#,##0");
  593. if (sum >= 0)
  594. {
  595. 周1.color = Color.blue;
  596. }
  597. else
  598. {
  599. 周1.color = Color.red;
  600. }
  601. // Debug.Log(sum);
  602. StartCoroutine(後台彙總讀取4());
  603. }
  604. }
  605. catch (Exception ex)
  606. {
  607. Debug.LogError("Error connecting to the database: " + ex.Message);
  608. 讀取面板.SetActive(false);
  609. yield break;
  610. }
  611. finally
  612. {
  613. connection.Close();
  614. }
  615. }
  616. }
  617. IEnumerator 後台彙總讀取4()
  618. {
  619. string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}", "後台彙總讀取4");
  620. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  621. yield return request.SendWebRequest();
  622. if (request.result == UnityWebRequest.Result.ConnectionError)
  623. {
  624. //Debug.Log(request.error);
  625. }
  626. DateTime parsedDate = DateTime.ParseExact(月初, "yyyy/MM/dd", null);
  627. string formattedDate = parsedDate.ToString("yyyy-MM-dd");
  628. string query = string.Format(request.downloadHandler.text.ToString(), formattedDate, 結束日期, PA2);
  629. Debug.Log(query);
  630. 彙總7 = new JSONArray();
  631. using (SqlConnection connection = new SqlConnection(路徑1))
  632. {
  633. try
  634. {
  635. connection.Open();
  636. using (SqlCommand command = new SqlCommand(query, connection))
  637. {
  638. using (SqlDataReader reader = command.ExecuteReader())
  639. {
  640. while (reader.Read()) // 逐行讀取資料
  641. {
  642. JSONNode jsona = new JSONObject(); // 創建 JSON 物件來存放每一行的資料
  643. for (int i = 0; i < reader.FieldCount; i++)
  644. {
  645. string columnName = reader.GetName(i); // 取得欄位名稱
  646. string value = reader.GetValue(i).ToString(); // 取得欄位值,並轉換成字串形式
  647. jsona[columnName] = value; // 將欄位名稱和值加入 JSON 物件中
  648. }
  649. 彙總7.Add(jsona); // 將整個 JSON 物件加入 JSON Array 中
  650. }
  651. }
  652. int sum = 0;
  653. for (int i = 0; i < 彙總7.Count; i++)
  654. {
  655. 彙總7[i][3] = "0";
  656. 彙總7[i][4] = "0";
  657. 彙總7[i][5] = "0";
  658. 彙總7[i][6] = "0";
  659. 彙總7[i][7] = "0";
  660. 彙總7[i][8] = "0";
  661. for (int j = 0; j < 彙總6.Count; j++)
  662. {
  663. string n1 = 彙總7[i][1].ToString().Trim('"');
  664. string n2 = 彙總6[j][2].ToString().Trim('"');
  665. string n3 = 彙總6[j][15].ToString().Trim('"');
  666. if ((n1 == n2) && n3 == "全")
  667. {
  668. 彙總7[i][3] = 彙總6[j][10].ToString().Trim('"');
  669. 彙總7[i][4] = 彙總6[j][11].ToString().Trim('"');
  670. }
  671. }
  672. double num = double.Parse(彙總7[i][4]);
  673. int roundedValue = (int)Math.Round(num / 10000);
  674. sum = sum + roundedValue;
  675. }
  676. 月1.text = sum.ToString("#,##0");
  677. if (sum >= 0)
  678. {
  679. 月1.color = Color.blue;
  680. }
  681. else
  682. {
  683. 月1.color = Color.red;
  684. }
  685. // Debug.Log(sum);
  686. StartCoroutine(後台彙總讀取5());
  687. }
  688. }
  689. catch (Exception ex)
  690. {
  691. Debug.LogError("Error connecting to the database: " + ex.Message);
  692. 讀取面板.SetActive(false);
  693. yield break;
  694. }
  695. finally
  696. {
  697. connection.Close();
  698. }
  699. }
  700. }
  701. IEnumerator 後台彙總讀取5()
  702. {
  703. string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}", "後台彙總讀取5");
  704. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  705. yield return request.SendWebRequest();
  706. if (request.result == UnityWebRequest.Result.ConnectionError)
  707. {
  708. //Debug.Log(request.error);
  709. }
  710. DateTime parsedDate = DateTime.ParseExact(年初, "yyyy/MM/dd", null);
  711. string formattedDate = parsedDate.ToString("yyyy-MM-dd");
  712. string query = string.Format(request.downloadHandler.text.ToString(), formattedDate, 結束日期, PA2);
  713. Debug.Log(query);
  714. 彙總5 = new JSONArray();
  715. using (SqlConnection connection = new SqlConnection(路徑1))
  716. {
  717. try
  718. {
  719. connection.Open();
  720. using (SqlCommand command = new SqlCommand(query, connection))
  721. {
  722. using (SqlDataReader reader = command.ExecuteReader())
  723. {
  724. while (reader.Read()) // 逐行讀取資料
  725. {
  726. JSONNode jsona = new JSONObject(); // 創建 JSON 物件來存放每一行的資料
  727. for (int i = 0; i < reader.FieldCount; i++)
  728. {
  729. string columnName = reader.GetName(i); // 取得欄位名稱
  730. string value = reader.GetValue(i).ToString(); // 取得欄位值,並轉換成字串形式
  731. jsona[columnName] = value; // 將欄位名稱和值加入 JSON 物件中
  732. }
  733. 彙總5.Add(jsona); // 將整個 JSON 物件加入 JSON Array 中
  734. }
  735. }
  736. for (int i = 0; i < 彙總5.Count; i++)
  737. {
  738. 彙總5[i][3] = "0";
  739. 彙總5[i][4] = "0";
  740. 彙總5[i][5] = "0";
  741. 彙總5[i][6] = "0";
  742. 彙總5[i][7] = "0";
  743. 彙總5[i][8] = "0";
  744. 彙總5[i][11] = "0";
  745. 彙總5[i][12] = "0";
  746. 彙總5[i][13] = "0";
  747. 彙總5[i][14] = "0";
  748. 彙總5[i][15] = "0";
  749. 彙總5[i][16] = "0";
  750. for (int j1 = 0; j1 < 彙總3.Count; j1++)
  751. {
  752. string n1 = 彙總5[i][1].ToString().Trim('"');
  753. string n2 = 彙總3[j1][2].ToString().Trim('"');
  754. if (n1 == n2)
  755. {
  756. double num = double.Parse(彙總3[j1][5]);
  757. int roundedValue = (int)Math.Round(num / 10000);
  758. double num1 = double.Parse(彙總3[j1][6]);
  759. int roundedValue1 = (int)Math.Round(num1 / 10000);
  760. 彙總5[i][3] = roundedValue.ToString("#,##0");
  761. 彙總5[i][4] = roundedValue1.ToString("#,##0");
  762. }
  763. }
  764. for (int j2 = 0; j2 < 彙總4.Count; j2++)
  765. {
  766. string n1 = 彙總5[i][1].ToString().Trim('"');
  767. string n2 = 彙總4[j2][1].ToString().Trim('"');
  768. if (n1 == n2)
  769. {
  770. double num = double.Parse(彙總4[j2][3]);
  771. int roundedValue = (int)Math.Round(num / 10000);
  772. double num1 = double.Parse(彙總4[j2][4]);
  773. int roundedValue1 = (int)Math.Round(num1 / 10000);
  774. 彙總5[i][5] = roundedValue.ToString("#,##0");
  775. 彙總5[i][6] = roundedValue1.ToString("#,##0");
  776. }
  777. }
  778. for (int j3 = 0; j3 < 彙總7.Count; j3++)
  779. {
  780. string n1 = 彙總5[i][1].ToString().Trim('"');
  781. string n2 = 彙總7[j3][1].ToString().Trim('"');
  782. if (n1 == n2)
  783. {
  784. double num = double.Parse(彙總7[j3][3]);
  785. int roundedValue = (int)Math.Round(num / 10000);
  786. double num1 = double.Parse(彙總7[j3][4]);
  787. int roundedValue1 = (int)Math.Round(num1 / 10000);
  788. 彙總5[i][7] = roundedValue.ToString("#,##0");
  789. 彙總5[i][8] = roundedValue1.ToString("#,##0");
  790. }
  791. }
  792. }
  793. 降冪(彙總5, 4);
  794. int sum = 0;
  795. if (copy1 != null)
  796. {
  797. DeletetextCopy1();
  798. }
  799. for (int ii = 0; ii < 彙總5.Count; ii++)
  800. {
  801. GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
  802. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(3, -sum);
  803. Transform tran = buttonscroll1.content;
  804. buttonObj.transform.SetParent(tran, false);
  805. TextMeshProUGUI[] texts = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  806. texts[0].text = 彙總5[ii][1].ToString().Trim('"');
  807. texts[1].text = 彙總5[ii][2].ToString().Trim('"');
  808. texts[2].text = 彙總5[ii][3].ToString().Trim('"');
  809. texts[3].text = 彙總5[ii][4].ToString().Trim('"');
  810. if (double.Parse(彙總5[ii][4]) >= 0)
  811. {
  812. texts[3].color = Color.blue;
  813. }
  814. else
  815. {
  816. texts[3].color = Color.red;
  817. }
  818. texts[4].text = 彙總5[ii][5].ToString().Trim('"');
  819. texts[5].text = 彙總5[ii][6].ToString().Trim('"');
  820. if (double.Parse(彙總5[ii][6]) >= 0)
  821. {
  822. texts[5].color = Color.blue;
  823. }
  824. else
  825. {
  826. texts[5].color = Color.red;
  827. }
  828. texts[6].text = 彙總5[ii][7].ToString().Trim('"');
  829. texts[7].text = 彙總5[ii][8].ToString().Trim('"');
  830. if (double.Parse(彙總5[ii][8]) >= 0)
  831. {
  832. texts[7].color = Color.blue;
  833. }
  834. else
  835. {
  836. texts[7].color = Color.red;
  837. }
  838. sum += 50;
  839. copy1.Add(buttonObj);
  840. }
  841. RectTransform contentTransform = buttonscroll1.content;
  842. contentTransform.anchoredPosition = new Vector2(contentTransform.anchoredPosition.x, 0);
  843. contentTransform.sizeDelta = new Vector2(contentTransform.sizeDelta.x, sum);
  844. if (sum > 1602)
  845. {
  846. buttonscroll1.vertical = true;
  847. }
  848. else
  849. {
  850. buttonscroll1.vertical = false;
  851. }
  852. 讀取面板.SetActive(false);
  853. }
  854. }
  855. catch (Exception ex)
  856. {
  857. Debug.LogError("Error connecting to the database: " + ex.Message);
  858. 讀取面板.SetActive(false);
  859. yield break;
  860. }
  861. finally
  862. {
  863. connection.Close();
  864. }
  865. }
  866. }
  867. private void 降冪(JSONNode json, int a)
  868. {
  869. List<List<string>> tlist = new List<List<string>>();
  870. for (int i = 0; i<json.Count; i++)
  871. {
  872. List<string> list = new List<string>();
  873. for (int j = 0; j < json[i].Count; j++)
  874. {
  875. list.Add(json[i][j].ToString().Trim('"'));
  876. }
  877. tlist.Add(list);
  878. }
  879. tlist = tlist.OrderByDescending(row => double.Parse(row[a])).ToList();
  880. for (int i = 0; i<json.Count; i++)
  881. {
  882. for (int j = 0; j < json[i].Count; j++)
  883. {
  884. json[i][j] = tlist[i][j];
  885. }
  886. }
  887. }
  888. public class Global
  889. {
  890. public static string 登入人IP, 年,日期, 職稱, 系統語言, 使用者名稱, 密碼, 進入, 離開, 資料庫版本號, 執行檔版本號,版本號比對,預設伺服器路徑,版本號,選擇組別,阿帕契路徑,阿帕契,CC判別,合約內容,合約編號,級別,ID,查詢日期,人員,連動客戶;
  891. public static bool 判斷是否連線, 股東,國外,啟動完畢,系統分區控制,登入位置,鏡頭啟動,有無清單 ,讀取完畢, 首次登入, 讀取年份, 快速登入, show1, show2, show3, show4, show5, show6, show7,展示帳號登入,qwe,印尼內網;
  892. public static int 部門編號,camfps;
  893. public static float rate, rate_;
  894. //public static TimeSpan 運行天數;
  895. public static string PA, PB, PC, PD, PE, PF, PG, PH, PI, PJ, PK, PA1, PA2, PA3, PA4, PA5, PA6, PA9, PA20;
  896. //public static bool[] 電表異常BL = new bool[999];
  897. // public static Sprite[] Wnum;
  898. // public static Sprite[] Bnum;
  899. public static string[] 系統語言資料;
  900. // public static string[] CC判斷=new string[999];
  901. public static Dictionary<string, string> 系統語言字典 = new Dictionary<string, string>() { };
  902. public static string[,] PHP = new string[99, 2];
  903. public static string 資料庫名稱, 資料庫IP, 資料庫帳, 資料庫密,路徑;
  904. }
  905. public static IEnumerator 路徑()
  906. {
  907. string strcon = "取得路徑";
  908. string strUrl = string.Format(Main.Global.阿帕契路徑 + "comm={0}", strcon);
  909. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  910. yield return request.SendWebRequest();
  911. if (request.result == UnityWebRequest.Result.ConnectionError)
  912. {
  913. Debug.Log(request.error);
  914. yield break;
  915. }
  916. Main.Global.路徑 = request.downloadHandler.text.ToString();
  917. }
  918. public static void 讀取sql()
  919. {
  920. string connectionString = "Data Source=mssql-147629-0.cloudclusters.net,12711;Initial Catalog=GCM-IP-DATE01;User ID=GCMIP01;Password=Df85deS52w";
  921. using (SqlConnection connection = new SqlConnection(connectionString))
  922. {
  923. try
  924. {
  925. connection.Open();
  926. string query = "SELECT 類別,位址 FROM PHP連線 Where 名稱=N'GA'";
  927. using (SqlCommand command = new SqlCommand(query, connection))
  928. {
  929. using (SqlDataReader reader = command.ExecuteReader())
  930. {
  931. int row = 0;
  932. while (reader.Read()) // 假設只取前兩筆資料
  933. {
  934. // 取得類別和位址資料
  935. Main.Global.PHP[row, 0] = reader["類別"].ToString();
  936. Main.Global.PHP[row, 1] = reader["位址"].ToString();
  937. row++;
  938. }
  939. Main.Global.國外 = true;
  940. }
  941. }
  942. }
  943. catch (Exception ex)
  944. {
  945. Debug.LogError("Error connecting to the database: " + ex.Message);
  946. Main.Global.國外 = false;
  947. }
  948. finally
  949. {
  950. connection.Close();
  951. }
  952. }
  953. }
  954. public static string GetAddressByCategory(string category)
  955. {
  956. for (int i = 0; i < Main.Global.PHP.GetLength(0); i++)
  957. {
  958. if (Main.Global.PHP[i, 0] == category)
  959. {
  960. return Main.Global.PHP[i, 1];
  961. }
  962. }
  963. return ""; // 或者返回一個默認值
  964. }
  965. void Update()
  966. {
  967. }
  968. public void DeletetextCopy1()
  969. {
  970. // 刪除複製出來的物件
  971. foreach (GameObject i in copy1)
  972. {
  973. Destroy(i);
  974. }
  975. copy1.Clear();
  976. }
  977. public void 回上頁 ()
  978. {
  979. 面板1.SetActive(true);
  980. 面板2.SetActive(false);
  981. 天.text ="";
  982. 周.text ="";
  983. 月.text ="";
  984. 天1.text ="";
  985. 周1.text ="";
  986. 月1.text ="";
  987. DeletetextCopy1();
  988. }
  989. public void 回登入()
  990. {
  991. change_Secen(0);
  992. }
  993. public void 個人帳號管理()
  994. {
  995. change_Secen(2);
  996. }
  997. public void change_Secen(int _screenNum)
  998. {
  999. SceneManager.LoadScene(_screenNum);
  1000. }
  1001. public void 截圖()
  1002. {
  1003. string fileName = string.Format("{0}/screenshot_{1}.png", Application.persistentDataPath, System.DateTime.Now.ToString("yyyyMMdd_HHmmss"));
  1004. ScreenCapture.CaptureScreenshot(fileName);
  1005. }
  1006. }