No Description
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.

Main.cs 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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] TextMeshProUGUI 下載進度;
  22. [SerializeField] Slider 進度條;
  23. public CanvasScaler canvasScaler;
  24. [SerializeField] GameObject 細板;
  25. [SerializeField] GameObject 寬板;
  26. [SerializeField] TextMeshProUGUI 資料庫;
  27. [SerializeField] TextMeshProUGUI 執行檔;
  28. [SerializeField] GameObject 讀取面板;
  29. [SerializeField] TextMeshProUGUI 讀取;
  30. [SerializeField] GameObject 彈跳面板;
  31. [SerializeField] TextMeshProUGUI 彈跳文字;
  32. private string loadingText = "";
  33. private int dotCount = 0;
  34. [SerializeField] Image backgroundImage;
  35. [SerializeField] Sprite[] backgroundSprites;
  36. string 資料庫版本號 = "";
  37. string 執行檔版本號 = "";
  38. private ScreenOrientation currentOrientation;
  39. string 更新路徑;
  40. string 更新;
  41. void Start()
  42. {
  43. Screen.autorotateToPortrait = true;
  44. Screen.orientation = ScreenOrientation.AutoRotation;
  45. if (Main.Global.螢幕方向=="直")
  46. {
  47. canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高);
  48. canvasScaler.matchWidthOrHeight=Main.Global.固比;
  49. }
  50. else
  51. {
  52. canvasScaler.referenceResolution = new Vector2(Main.Global.固高, Main.Global.固寬);
  53. canvasScaler.matchWidthOrHeight=Main.Global.固比1;
  54. }
  55. if (Main.Global.螢幕格式=="胖")
  56. {
  57. 寬板.SetActive(true);
  58. 細板.SetActive(false);
  59. }
  60. else
  61. {
  62. 細板.SetActive(true);
  63. 寬板.SetActive(false);
  64. }
  65. currentOrientation = Screen.orientation;
  66. if (backgroundSprites != null && backgroundSprites.Length > 0)
  67. {
  68. // 隨機選擇一張圖片
  69. int randomIndex = UnityEngine.Random.Range(0, backgroundSprites.Length);
  70. Sprite selectedSprite = backgroundSprites[randomIndex];
  71. // 將選擇的圖片設定為背景
  72. backgroundImage.sprite = selectedSprite;
  73. }
  74. StartCoroutine(AnimateText());
  75. 更新路徑="";
  76. 更新="";
  77. 讀取面板.SetActive(true);
  78. 讀取版本號();
  79. 判斷版本號();
  80. }
  81. void Update()
  82. {
  83. if (Main.Global.版本號比對=="ture")
  84. {
  85. if (Screen.orientation != currentOrientation)
  86. {
  87. if (Screen.orientation == ScreenOrientation.LandscapeLeft)
  88. {
  89. Main.Global.螢幕方向="橫";
  90. change_Secen(3);
  91. }
  92. if (Screen.orientation == ScreenOrientation.Portrait)
  93. {
  94. Main.Global.螢幕方向="直";
  95. change_Secen(1);
  96. }
  97. }
  98. }
  99. }
  100. public void 讀取版本號()
  101. {
  102. using (SqlConnection connection = new SqlConnection(Main.Global.sql))
  103. {
  104. try
  105. {
  106. connection.Open();
  107. string query = "SELECT 手機認證版本號 FROM 版本號管理 ";
  108. using (SqlCommand command = new SqlCommand(query, connection))
  109. {
  110. using (SqlDataReader reader = command.ExecuteReader())
  111. {
  112. if (reader.Read()) // 檢查是否有資料
  113. {
  114. 資料庫版本號 = reader.GetString(0); // 假設版本號在結果集中的第一列
  115. }
  116. }
  117. }
  118. }
  119. catch (Exception ex)
  120. {
  121. Debug.LogError("Error connecting to the database: " + ex.Message);
  122. 彈跳面板.SetActive(true);
  123. 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
  124. }
  125. finally
  126. {
  127. connection.Close();
  128. }
  129. }
  130. }
  131. public void 判斷版本號()
  132. {
  133. 執行檔版本號=Application.version;
  134. if (資料庫版本號 != "")
  135. {
  136. if (資料庫版本號 == 執行檔版本號)
  137. {
  138. 讀取面板.SetActive(false);
  139. Main.Global.版本號比對="ture";
  140. }
  141. else
  142. {
  143. 讀取面板.SetActive(false);
  144. 下載面板.SetActive(true);
  145. 下載文字.text="版本不符合,檔案下載中";
  146. WebClient client = new WebClient();
  147. string url = "http://106.1.48.106:8080/HX_APP/BIFENG.apk";
  148. string path = Application.persistentDataPath+"/BIFENG.apk";
  149. if (File.Exists(path))
  150. {
  151. File.Delete(path);
  152. }
  153. StartCoroutine(DownloadFile(url, path));
  154. }
  155. }
  156. 資料庫.text+=資料庫版本號;
  157. 執行檔.text+=執行檔版本號;
  158. }
  159. IEnumerator AnimateText()
  160. {
  161. string qqq = 讀取.text.ToString();
  162. while (true)
  163. {
  164. yield return new WaitForSeconds(0.5f);
  165. if (dotCount < 3)
  166. {
  167. loadingText += ".";
  168. dotCount++;
  169. }
  170. else
  171. {
  172. loadingText = "";
  173. dotCount = 0;
  174. }
  175. 讀取.text = qqq+loadingText;
  176. }
  177. }
  178. IEnumerator DownloadFile(string url, string path)
  179. {
  180. using (WWW www = new WWW(url))
  181. {
  182. while (!www.isDone)
  183. {
  184. float progress = Mathf.Clamp01(www.progress / 0.9f);
  185. 進度條.value = progress;
  186. int bar = (int)(progress*100);
  187. 下載進度.text=bar.ToString()+"%";
  188. yield return null;
  189. }
  190. if (string.IsNullOrEmpty(www.error))
  191. {
  192. System.IO.File.WriteAllBytes(path, www.bytes);
  193. //Debug.Log("Download complete!");
  194. 進度條.value = 1f;
  195. yield return new WaitForSeconds(1f);
  196. InstallApk(path);
  197. }
  198. else
  199. {
  200. Debug.LogError("Download error: " + www.error);
  201. }
  202. }
  203. }
  204. public void 書架()
  205. {
  206. Main.Global.PA1="";
  207. Main.Global.PA2="";
  208. Main.Global.PA3="";
  209. Main.Global.PA4="";
  210. if (Main.Global.螢幕方向=="直")
  211. {
  212. change_Secen(2);
  213. }
  214. else
  215. {
  216. change_Secen(4);
  217. }
  218. }
  219. public void 風水()
  220. {
  221. Main.Global.資料庫名稱="風水";
  222. Main.Global.PA1="";
  223. Main.Global.PA2="";
  224. Main.Global.PA3="";
  225. Main.Global.PA4="";
  226. if (Main.Global.螢幕方向=="直")
  227. {
  228. change_Secen(5);
  229. }
  230. else
  231. {
  232. change_Secen(6);
  233. }
  234. }
  235. public void 擇日()
  236. {
  237. Main.Global.資料庫名稱="擇日";
  238. Main.Global.PA1="";
  239. Main.Global.PA2="";
  240. Main.Global.PA3="";
  241. Main.Global.PA4="";
  242. if (Main.Global.螢幕方向=="直")
  243. {
  244. change_Secen(5);
  245. }
  246. else
  247. {
  248. change_Secen(6);
  249. }
  250. }
  251. public void 命名()
  252. {
  253. Main.Global.資料庫名稱="命名";
  254. Main.Global.PA1="";
  255. Main.Global.PA2="";
  256. Main.Global.PA3="";
  257. Main.Global.PA4="";
  258. if (Main.Global.螢幕方向=="直")
  259. {
  260. change_Secen(5);
  261. }
  262. else
  263. {
  264. change_Secen(6);
  265. }
  266. }
  267. public void 流年()
  268. {
  269. Main.Global.資料庫名稱="流年";
  270. Main.Global.PA1="";
  271. Main.Global.PA2="";
  272. Main.Global.PA3="";
  273. Main.Global.PA4="";
  274. if (Main.Global.螢幕方向=="直")
  275. {
  276. change_Secen(5);
  277. }
  278. else
  279. {
  280. change_Secen(6);
  281. }
  282. }
  283. public void 日誌()
  284. {
  285. change_Secen(7);
  286. }
  287. public void 彈跳面板關閉()
  288. {
  289. 彈跳面板.SetActive(false);
  290. 彈跳文字.text = "";
  291. }
  292. public static bool InstallApk(string apkPath)
  293. {
  294. AndroidJavaClass javaClass = new AndroidJavaClass("com.test.install.Install");
  295. return javaClass.CallStatic<bool>("InstallApk", apkPath);
  296. }
  297. public static class Global
  298. {
  299. public static string 資料庫名稱,螢幕方向, sql,螢幕格式,登入人IP, 年,日期, 職稱, 系統語言 ,使用者名稱, 密碼, 進入, 離開, 資料庫版本號, 執行檔版本號,版本號比對,預設伺服器路徑,版本號,選擇組別,阿帕契路徑,阿帕契,CC判別,合約內容,合約編號,級別,ID,查詢日期,人員,連動客戶;
  300. public static bool 判斷是否連線, 啟動完畢,系統分區控制,登入位置,鏡頭啟動,有無清單 ,讀取完畢, 首次登入, 讀取年份, 快速登入, show1, show2, show3, show4, show5, show6, show7,展示帳號登入,qwe,印尼內網;
  301. public static int 部門編號,camfps;
  302. public static float rate, rate_ , 固比, 固比1, 固寬,固高;
  303. //public static TimeSpan 運行天數;
  304. public static string PA, PB, PC, PD, PE, PF, PG, PH, PI, PJ, PK, PA1, PA2, PA3, PA4, PA5, PA6, PA9, PA20;
  305. //public static bool[] 電表異常BL = new bool[999];
  306. // public static Sprite[] Wnum;
  307. // public static Sprite[] Bnum;
  308. public static string[] 系統語言資料;
  309. // public static string[] CC判斷=new string[999];
  310. public static Dictionary<string, string> 系統語言字典 = new Dictionary<string, string>() { };
  311. public static string[,] PHP = new string[5,2];
  312. }
  313. public void change_Secen(int _screenNum)
  314. {
  315. SceneManager.LoadScene(_screenNum);
  316. }
  317. public void 截圖()
  318. {
  319. string fileName = string.Format("{0}/screenshot_{1}.png", Application.persistentDataPath, System.DateTime.Now.ToString("yyyyMMdd_HHmmss"));
  320. ScreenCapture.CaptureScreenshot(fileName);
  321. }
  322. }