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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. public class Main : MonoBehaviour
  18. {
  19. [SerializeField] GameObject 讀取面板;
  20. [SerializeField] TextMeshProUGUI 讀取;
  21. [SerializeField] GameObject 選單;
  22. [SerializeField] TextMeshProUGUI 伺服器;
  23. [SerializeField] Button 電子簽章_cb;
  24. [SerializeField] Button 個人照號管理_cb;
  25. [SerializeField] Button 點名_cb;
  26. [SerializeField] Button 庫存表_cb;
  27. [SerializeField] Button 生產排程表_cb;
  28. [SerializeField] Button 生產日報表_cb;
  29. [SerializeField] Button 出貨排程表_cb;
  30. [SerializeField] Button 出貨日報表_cb;
  31. [SerializeField] Button 庫存盤點_cb;
  32. [SerializeField] Button 庫存審查_cb;
  33. [SerializeField] Button 加班紀錄_cb;
  34. private List<Button> bts = new List<Button>();
  35. private string str;
  36. public CanvasScaler canvasScaler;
  37. public float idleTime = 300f; // 5分鐘的閒置時間
  38. private float timeSinceLastInteraction = 0f;
  39. private int buttonPressCount = 0;
  40. private float lastButtonPressTime = 0.0f;
  41. public float maxButtonPressInterval = 0.2f;
  42. public int requiredButtonPressCount = 5;
  43. private float timer = 0f;
  44. private float interval = 60f;
  45. private ScreenOrientation currentOrientation;
  46. float scale = 0;
  47. float xbar = 0;
  48. float ybar = 0;
  49. RectTransform panelRectTransform;
  50. float screenWidth;
  51. float screenHeight;
  52. private string loadingText = "";
  53. private int dotCount = 0;
  54. // Start is called before the first frame update
  55. void Start()
  56. {
  57. Screen.autorotateToPortrait = true;
  58. Screen.orientation = ScreenOrientation.AutoRotation;
  59. if (Screen.orientation == ScreenOrientation.LandscapeLeft)
  60. {
  61. float rate = 900.0f / 1900.0f;
  62. if (Main.Global.rate<rate)
  63. {
  64. canvasScaler.matchWidthOrHeight = 1f;
  65. }
  66. else
  67. {
  68. canvasScaler.matchWidthOrHeight = 0f;
  69. }
  70. }
  71. if (Screen.orientation == ScreenOrientation.Portrait)
  72. {
  73. float rate = 900.0f / 1900.0f;
  74. if (Main.Global.rate>rate)
  75. {
  76. canvasScaler.matchWidthOrHeight = 1f;
  77. }
  78. else
  79. {
  80. canvasScaler.matchWidthOrHeight = 0f;
  81. }
  82. }
  83. if (Main.Global.預設伺服器路徑=="official")
  84. {
  85. 伺服器.text="official";
  86. }
  87. else
  88. {
  89. 伺服器.text="test";
  90. }
  91. if (Main.Global.阿帕契路徑==Main.Global.PHP[0, 1] || Main.Global.阿帕契路徑==Main.Global.PHP[2, 1])
  92. {
  93. Main.Global.阿帕契路徑=Main.Global.PHP[2, 1];
  94. }
  95. else
  96. {
  97. Main.Global.阿帕契路徑=Main.Global.PHP[3, 1];
  98. }
  99. currentOrientation = Screen.orientation;
  100. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/ow_main.php?";
  101. StartCoroutine(AnimateText());
  102. 讀取面板.SetActive(true);
  103. //Main.Global.預設伺服器路徑="official";
  104. //Main.Global.系統語言="繁體中文";
  105. //Main.Global.PA="b70340";
  106. //Main.Global.PB="0911274990";
  107. StartCoroutine(讀取CC());
  108. }
  109. void Update()
  110. {
  111. if (Screen.orientation != currentOrientation)
  112. {
  113. if (Screen.orientation == ScreenOrientation.LandscapeLeft)
  114. {
  115. change_Secen(12);
  116. }
  117. if (Screen.orientation == ScreenOrientation.Portrait)
  118. {
  119. change_Secen(1);
  120. }
  121. }
  122. }
  123. IEnumerator AnimateText()
  124. {
  125. string qqq = 讀取.text.ToString();
  126. while (true)
  127. {
  128. yield return new WaitForSeconds(0.5f);
  129. if (dotCount < 3)
  130. {
  131. loadingText += ".";
  132. dotCount++;
  133. }
  134. else
  135. {
  136. loadingText = "";
  137. dotCount = 0;
  138. }
  139. 讀取.text = qqq+loadingText;
  140. }
  141. }
  142. public void OnButtonPress()
  143. {
  144. if (Time.time - lastButtonPressTime > maxButtonPressInterval)
  145. {
  146. buttonPressCount = 0;
  147. }
  148. else
  149. {
  150. buttonPressCount++;
  151. }
  152. lastButtonPressTime = Time.time;
  153. if (buttonPressCount >= requiredButtonPressCount)
  154. {
  155. // 觸發你想要的事件
  156. buttonPressCount = 0;
  157. 選單.SetActive(true);
  158. }
  159. }
  160. IEnumerator 讀取CC()
  161. {
  162. string strcon = "讀取";
  163. string name = Main.Global.PA;
  164. string ps = Main.Global.PB;
  165. string se = Main.Global.預設伺服器路徑;
  166. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&帳號={1}&密碼={2}&se={3}", strcon, name, ps, se);
  167. Debug.Log(strUrl);
  168. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  169. yield return request.SendWebRequest();
  170. if (request.result == UnityWebRequest.Result.ConnectionError)
  171. {
  172. //Debug.Log(request.error);
  173. }
  174. JSONNode json1 = JSON.Parse(request.downloadHandler.text);
  175. Debug.Log(json1);
  176. 讀取面板.SetActive(false);
  177. Main.Global.人員 = json1[0].ToString().Trim('"');
  178. Main.Global.級別 = json1[129].ToString().Trim('"');
  179. Main.Global.部門 = json1[130].ToString().Trim('"');
  180. Main.Global.職稱 = json1[131].ToString().Trim('"');
  181. Debug.Log(Main.Global.人員);
  182. 電子簽章_cb.gameObject.SetActive(false);
  183. //bts.Add(電子簽章_cb);
  184. bts.Add(個人照號管理_cb);
  185. bts.Add(庫存表_cb);
  186. if (json1[52].ToString()=="0")
  187. {
  188. 點名_cb.gameObject.SetActive(false);
  189. }
  190. else
  191. {
  192. bts.Add(點名_cb);
  193. }
  194. if (json1[53].ToString()=="0")
  195. {
  196. 生產排程表_cb.gameObject.SetActive(false);
  197. }
  198. else
  199. {
  200. bts.Add(生產排程表_cb);
  201. }
  202. if (json1[106].ToString()=="0")
  203. {
  204. 生產日報表_cb.gameObject.SetActive(false);
  205. }
  206. else
  207. {
  208. bts.Add(生產日報表_cb);
  209. }
  210. if (json1[109].ToString()=="0")
  211. {
  212. 出貨排程表_cb.gameObject.SetActive(false);
  213. }
  214. else
  215. {
  216. bts.Add(出貨排程表_cb);
  217. }
  218. if (json1[114].ToString()=="0")
  219. {
  220. 出貨日報表_cb.gameObject.SetActive(false);
  221. }
  222. else
  223. {
  224. bts.Add(出貨日報表_cb);
  225. }
  226. if (json1[85].ToString()=="0")
  227. {
  228. 庫存盤點_cb.gameObject.SetActive(false);
  229. }
  230. else
  231. {
  232. bts.Add(庫存盤點_cb);
  233. }
  234. if (json1[86].ToString()=="0")
  235. {
  236. 庫存審查_cb.gameObject.SetActive(false);
  237. }
  238. else
  239. {
  240. bts.Add(庫存審查_cb);
  241. }
  242. bts.Add(加班紀錄_cb);
  243. if (Screen.orientation == ScreenOrientation.LandscapeLeft)
  244. {
  245. for (int i = 0; i < bts.Count; i++)
  246. {
  247. float x, y;
  248. if (i % 2 == 0) // 偶數索引
  249. {
  250. x = 50f + (i / 2) * 250f;
  251. y = -50f;
  252. }
  253. else // 奇數索引
  254. {
  255. x = 50f + ((i - 1) / 2) * 250f;
  256. y = -400f;
  257. }
  258. RectTransform rt = bts[i].GetComponent<RectTransform>();
  259. rt.anchoredPosition = new Vector2(x, y);
  260. }
  261. }
  262. if (Screen.orientation == ScreenOrientation.Portrait)
  263. {
  264. for (int i = 0; i < bts.Count; i++)
  265. {
  266. // 設定按鈕的位置
  267. float x = 60 + (i % 4) * 210; // 在每一行的水平位置
  268. float y = -100 - (i / 4) * 300; // 在每一行的垂直位置
  269. RectTransform rt = bts[i].GetComponent<RectTransform>();
  270. rt.anchoredPosition = new Vector2(x, y);
  271. }
  272. }
  273. 讀取面板.SetActive(false);
  274. }
  275. public static class Global
  276. {
  277. public static string 登入人IP, 部門,年,日期, 職稱, 系統語言 ,使用者名稱, 密碼, 進入, 離開, 資料庫版本號, 執行檔版本號,版本號比對,預設伺服器路徑,版本號,選擇組別,阿帕契路徑,阿帕契,CC判別,合約內容,合約編號,級別,ID,查詢日期,人員,連動客戶;
  278. public static bool 判斷是否連線, 螢幕方向,啟動完畢,系統分區控制,登入位置,鏡頭啟動,有無清單 ,讀取完畢, 首次登入, 讀取年份, 快速登入, show1, show2, show3, show4, show5, show6, show7,展示帳號登入,qwe,印尼內網;
  279. public static int 部門編號,camfps;
  280. public static float rate, rate_;
  281. //public static TimeSpan 運行天數;
  282. public static string PA, PB, PC, PD, PE, PF, PG, PH, PI, PJ, PK, PA1, PA2, PA3, PA4, PA5, PA6, PA9, PA20;
  283. //public static bool[] 電表異常BL = new bool[999];
  284. // public static Sprite[] Wnum;
  285. // public static Sprite[] Bnum;
  286. public static string[] 系統語言資料;
  287. // public static string[] CC判斷=new string[999];
  288. public static Dictionary<string, string> 系統語言字典 = new Dictionary<string, string>() { };
  289. public static string[,] PHP = new string[5,2];
  290. }
  291. public void 回登入()
  292. {
  293. change_Secen(0);
  294. }
  295. public void 電簽()
  296. {
  297. change_Secen(2);
  298. }
  299. public void 個人帳號管理()
  300. {
  301. change_Secen(3);
  302. }
  303. public void 點名()
  304. {
  305. change_Secen(4);
  306. }
  307. public void 庫存()
  308. {
  309. change_Secen(5);
  310. }
  311. public void 生產排程()
  312. {
  313. change_Secen(6);
  314. }
  315. public void 出貨排程()
  316. {
  317. change_Secen(7);
  318. }
  319. public void 生產日報()
  320. {
  321. change_Secen(8);
  322. }
  323. public void 出貨日報()
  324. {
  325. change_Secen(9);
  326. }
  327. public void 盤點()
  328. {
  329. change_Secen(10);
  330. }
  331. public void 審查()
  332. {
  333. change_Secen(11);
  334. }
  335. public void 選單關閉()
  336. {
  337. 選單.SetActive(false);
  338. }
  339. public void 加班打卡()
  340. {
  341. change_Secen(13);
  342. }
  343. public void 正式()
  344. {
  345. Main.Global.預設伺服器路徑="official";
  346. 伺服器.text="official";
  347. //StartCoroutine(測驗());
  348. }
  349. public void 測試()
  350. {
  351. Main.Global.預設伺服器路徑="test";
  352. 伺服器.text="test";
  353. //StartCoroutine(測驗());
  354. }
  355. public void change_Secen(int _screenNum)
  356. {
  357. SceneManager.LoadScene(_screenNum);
  358. }
  359. public void 截圖()
  360. {
  361. string fileName = string.Format("{0}/screenshot_{1}.png", Application.persistentDataPath, System.DateTime.Now.ToString("yyyyMMdd_HHmmss"));
  362. ScreenCapture.CaptureScreenshot(fileName);
  363. }
  364. }