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 { public TMP_Dropdown 年; public TMP_Dropdown 西元; public RawImage rawImage; public RawImage rawImage1; [SerializeField] TMP_InputField 關鍵字; [SerializeField] TextMeshProUGUI 選擇書籍標題; [SerializeField] TextMeshProUGUI 選擇頁標題; [SerializeField] TextMeshProUGUI 圖片頁標題; [SerializeField] TextMeshProUGUI 圖片頁標題1; public CanvasScaler canvasScaler; [SerializeField] GameObject 細板; [SerializeField] GameObject 寬板; [SerializeField] GameObject 回主頁紐; [SerializeField] GameObject 回選擇書籍紐; [SerializeField] GameObject 選擇頁面紐; [SerializeField] GameObject 選擇書籍; [SerializeField] GameObject 選擇頁面; [SerializeField] TextMeshProUGUI 書編; [SerializeField] TextMeshProUGUI 書名s; [SerializeField] TextMeshProUGUI 書頁名; [SerializeField] TMP_InputField 第幾頁; [SerializeField] TextMeshProUGUI 書編1; [SerializeField] TextMeshProUGUI 書名s1; [SerializeField] TextMeshProUGUI 書頁名1; [SerializeField] TMP_InputField 第幾頁1; [SerializeField] GameObject 讀取面板; [SerializeField] TextMeshProUGUI 讀取; [SerializeField] GameObject 彈跳面板; [SerializeField] TextMeshProUGUI 彈跳文字; private string loadingText = ""; private int dotCount = 0; JSONArray 書籍清單; JSONArray 書籍內容清單; public GameObject buttonPrefab; public Transform buttonParent; public GameObject buttonceneter; private List copy = new List(); public GameObject buttonPrefab1; public Transform buttonParent1; public GameObject buttonceneter1; private List copy1 = new List(); int 最大頁數; [SerializeField] Slider scrollbar; [SerializeField] Slider scrollbar1; private float initialScale; private ScreenOrientation currentOrientation; private float 旋轉角度 = 0f; Texture2D texture; bool 判斷; // Start is called before the first frame update void Start() { //Main.Global.固寬=1000f; //Main.Global.固高=1600f; //Main.Global.固比=1f; //Main.Global.螢幕格式="胖"; //Main.Global.螢幕方向="直"; //Main.Global.資料庫名稱="命名"; //Main.Global.sql="Data Source=180.177.181.162,5264;Initial Catalog=BIFENG-ERP-SYS;User ID=b70340;Password=0911274990"; Main.Global.PA1=""; Main.Global.PA2=""; Main.Global.PA3=""; Main.Global.PA4=""; Screen.autorotateToPortrait = true; Screen.orientation = ScreenOrientation.AutoRotation; if (Main.Global.螢幕方向=="直") { canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高); canvasScaler.matchWidthOrHeight=Main.Global.固比; } else { canvasScaler.referenceResolution = new Vector2(Main.Global.固高, Main.Global.固寬); canvasScaler.matchWidthOrHeight=Main.Global.固比1; } currentOrientation = Screen.orientation; if (Main.Global.資料庫名稱=="流年") { 圖片頁標題.text ="西元-年"; 圖片頁標題1.text ="西元-年"; } else { 圖片頁標題.text ="日期"; 圖片頁標題1.text ="日期"; } if (Main.Global.螢幕格式=="胖") { initialScale = rawImage1.transform.localScale.x; if (Main.Global.PA1 == "") { 選擇書籍.SetActive(true); 回主頁紐.SetActive(true); 回選擇書籍紐.SetActive(false); 選擇頁面紐.SetActive(false); } else if (Main.Global.PA1 != "" && Main.Global.PA4 !="") { 選擇書籍.SetActive(false); string str1 = Main.Global.PA4; 細板.SetActive(false); 寬板.SetActive(true); 書編1.text =Main.Global.PA1; 書名s1.text=Main.Global.PA2; 書頁名1.text=Main.Global.PA3; 第幾頁1.text=Main.Global.PA4; 選擇頁面.SetActive(false); 回主頁紐.SetActive(false); 回選擇書籍紐.SetActive(true); 選擇頁面紐.SetActive(true); 讀取書籍內容清單(); 顯示圖片(str1); } } else { initialScale = rawImage.transform.localScale.x; if (Main.Global.PA1 == "") { 選擇書籍.SetActive(true); 回主頁紐.SetActive(true); 回選擇書籍紐.SetActive(false); 選擇頁面紐.SetActive(false); } else if (Main.Global.PA1 != "" && Main.Global.PA4 !="") { 選擇書籍.SetActive(false); string str1 = Main.Global.PA4; 細板.SetActive(true); 寬板.SetActive(false); 書編.text =Main.Global.PA1; 書名s.text=Main.Global.PA2; 書頁名.text=Main.Global.PA3; 第幾頁.text=Main.Global.PA4; 選擇頁面.SetActive(false); 回主頁紐.SetActive(false); 回選擇書籍紐.SetActive(true); 選擇頁面紐.SetActive(true); 讀取書籍內容清單(); 顯示圖片(str1); } } StartCoroutine(AnimateText()); 讀取年份(); 讀取書籍清單(); } 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; } } void Update() { if (Screen.orientation != currentOrientation) { if (Screen.orientation == ScreenOrientation.LandscapeLeft) { Main.Global.螢幕方向="橫"; if (Main.Global.螢幕格式=="胖") { Main.Global.PA1=書編1.text; Main.Global.PA2=書名s1.text; Main.Global.PA3=書頁名1.text; Main.Global.PA4=第幾頁1.text; } else { Main.Global.PA1=書編.text; Main.Global.PA2=書名s.text; Main.Global.PA3=書頁名.text; Main.Global.PA4=第幾頁.text; } change_Secen(6); } if (Screen.orientation == ScreenOrientation.Portrait) { if (Main.Global.螢幕格式=="胖") { Main.Global.PA1=書編1.text; Main.Global.PA2=書名s1.text; Main.Global.PA3=書頁名1.text; Main.Global.PA4=第幾頁1.text; } else { Main.Global.PA1=書編.text; Main.Global.PA2=書名s.text; Main.Global.PA3=書頁名.text; Main.Global.PA4=第幾頁.text; } Main.Global.螢幕方向="直"; change_Secen(5); } } } public void 讀取年份() { 讀取面板.SetActive(true); 年.options.Clear(); 西元.options.Clear(); List options = new List(); List options1 = new List(); options.Add(new TMP_Dropdown.OptionData("")); options1.Add(new TMP_Dropdown.OptionData("")); using (SqlConnection connection = new SqlConnection(Main.Global.sql)) { try { connection.Open(); string query = "SELECT LEFT(西元, 4) AS 西元, 年 FROM 萬年曆 WHERE (RIGHT(西元, 5) LIKE '05/05') GROUP BY LEFT(西元, 4), 年 ORDER BY 西元, 年"; using (SqlCommand command = new SqlCommand(query, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) // 假設只取前兩筆資料 { options.Add(new TMP_Dropdown.OptionData(reader["年"].ToString())); options1.Add(new TMP_Dropdown.OptionData(reader["西元"].ToString())); } 年.AddOptions(options); 西元.AddOptions(options1); 年.value = 0; 西元.value = 0; 年.onValueChanged.AddListener(OnDropdown1ValueChanged); 西元.onValueChanged.AddListener(OnDropdown2ValueChanged); } } } catch (Exception ex) { Debug.LogError("Error connecting to the database: " + ex.Message); 彈跳面板.SetActive(true); 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員"; } finally { connection.Close(); } } 讀取面板.SetActive(false); } void OnDropdown1ValueChanged(int index) { 西元.value = index; 關鍵字.text = ""; 讀取書籍清單(); } // 當第二個下拉式清單的值改變時被呼叫 void OnDropdown2ValueChanged(int index) { 年.value = index; 關鍵字.text = ""; 讀取書籍清單(); } public void 讀取書籍清單() { 讀取面板.SetActive(true); 書籍清單 = new JSONArray(); using (SqlConnection connection = new SqlConnection(Main.Global.sql)) { try { connection.Open(); string query = ""; if (關鍵字.text =="") { if (Main.Global.資料庫名稱=="風水") { query = "SELECT 客戶資料庫.姓名, 風水資料表.日期, 風水資料表.客戶編號, 客戶資料庫.備註 " + "FROM 風水資料表 LEFT OUTER JOIN 客戶資料庫 ON 風水資料表.客戶編號 = 客戶資料庫.流水號 " + "WHERE LEFT(風水資料表.日期, 4) LIKE '%"+ 西元.options[西元.value].text +"%' " + "GROUP BY 客戶資料庫.姓名, 風水資料表.日期, 風水資料表.客戶編號, 客戶資料庫.備註 " + "ORDER BY 風水資料表.日期 DESC"; } else if (Main.Global.資料庫名稱=="擇日") { query = "SELECT 客戶資料庫.姓名, 擇日資料表.日期, 擇日資料表.客戶編號, 客戶資料庫.備註 " + "FROM 擇日資料表 LEFT OUTER JOIN 客戶資料庫 ON 擇日資料表.客戶編號 = 客戶資料庫.流水號 " + "WHERE LEFT(擇日資料表.日期, 4) LIKE '%"+ 西元.options[西元.value].text +"%' " + "GROUP BY 客戶資料庫.姓名, 擇日資料表.日期, 擇日資料表.客戶編號, 客戶資料庫.備註 " + "ORDER BY 擇日資料表.日期 DESC"; } else if (Main.Global.資料庫名稱=="命名") { query = "SELECT 客戶資料庫.姓名, 命名資料表.日期, 命名資料表.客戶編號, 客戶資料庫.備註 " + "FROM 命名資料表 LEFT OUTER JOIN 客戶資料庫 ON 命名資料表.客戶編號 = 客戶資料庫.流水號 " + "WHERE LEFT(命名資料表.日期, 4) LIKE '%"+ 西元.options[西元.value].text +"%' " + "GROUP BY 客戶資料庫.姓名, 命名資料表.日期, 命名資料表.客戶編號, 客戶資料庫.備註 " + "ORDER BY 命名資料表.日期 DESC"; } else if (Main.Global.資料庫名稱=="流年") { query = "SELECT 客戶資料庫.姓名, 流年資料表.西元, 流年資料表.年, 流年資料表.客戶編號, 客戶資料庫.備註 " + "FROM 流年資料表 LEFT OUTER JOIN 客戶資料庫 ON 流年資料表.客戶編號 = 客戶資料庫.流水號 " + "WHERE 流年資料表.西元 LIKE '%"+ 西元.options[西元.value].text +"%' AND 流年資料表.年 LIKE '%"+ 年.options[年.value].text +"%' " + "GROUP BY 客戶資料庫.姓名, 流年資料表.西元, 流年資料表.年, 流年資料表.客戶編號, 客戶資料庫.備註 " + "ORDER BY 流年資料表.西元 DESC, 流年資料表.年"; } } else { if (Main.Global.資料庫名稱=="風水") { query = "SELECT 客戶資料庫.姓名, 風水資料表.日期, 風水資料表.客戶編號, 客戶資料庫.備註 " + "FROM 風水資料表 LEFT OUTER JOIN 客戶資料庫 ON 風水資料表.客戶編號 = 客戶資料庫.流水號 " + "WHERE 客戶資料庫.區域 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.客戶群組 LIKE N'%" + 關鍵字.text + "%' " + "OR 客戶資料庫.姓名 LIKE N'%" + 關鍵字.text + "%' OR " + "客戶資料庫.性別 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.電話 LIKE N'%" + 關鍵字.text + "%' OR " + "客戶資料庫.地址 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.備註 LIKE N'%" + 關鍵字.text + "%' " + "GROUP BY 客戶資料庫.姓名, 風水資料表.日期, 風水資料表.客戶編號, 客戶資料庫.備註 " + "ORDER BY 風水資料表.日期 DESC"; } else if (Main.Global.資料庫名稱=="擇日") { query = "SELECT 客戶資料庫.姓名, 擇日資料表.日期, 擇日資料表.客戶編號, 客戶資料庫.備註 " + "FROM 擇日資料表 LEFT OUTER JOIN 客戶資料庫 ON 擇日資料表.客戶編號 = 客戶資料庫.流水號 " + "WHERE 客戶資料庫.區域 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.客戶群組 LIKE N'%" + 關鍵字.text + "%' " + "OR 客戶資料庫.姓名 LIKE N'%" + 關鍵字.text + "%' OR " + "客戶資料庫.性別 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.電話 LIKE N'%" + 關鍵字.text + "%' OR " + "客戶資料庫.地址 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.備註 LIKE N'%" + 關鍵字.text + "%' " + "GROUP BY 客戶資料庫.姓名, 擇日資料表.日期, 擇日資料表.客戶編號, 客戶資料庫.備註 " + "ORDER BY 擇日資料表.日期 DESC"; } else if (Main.Global.資料庫名稱=="命名") { query = "SELECT 客戶資料庫.姓名, 命名資料表.日期, 命名資料表.客戶編號, 客戶資料庫.備註 " + "FROM 命名資料表 LEFT OUTER JOIN 客戶資料庫 ON 命名資料表.客戶編號 = 客戶資料庫.流水號 " + "WHERE 客戶資料庫.區域 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.客戶群組 LIKE N'%" + 關鍵字.text + "%' " + "OR 客戶資料庫.姓名 LIKE N'%" + 關鍵字.text + "%' OR " + "客戶資料庫.性別 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.電話 LIKE N'%" + 關鍵字.text + "%' OR " + "客戶資料庫.地址 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.備註 LIKE N'%" + 關鍵字.text + "%' " + "GROUP BY 客戶資料庫.姓名, 命名資料表.日期, 命名資料表.客戶編號, 客戶資料庫.備註 " + "ORDER BY 命名資料表.日期 DESC"; } else if (Main.Global.資料庫名稱=="流年") { query = "SELECT 客戶資料庫.姓名, 流年資料表.西元, 流年資料表.年, 流年資料表.客戶編號, 客戶資料庫.備註 " + "FROM 流年資料表 LEFT OUTER JOIN 客戶資料庫 ON 流年資料表.客戶編號 = 客戶資料庫.流水號 " + "WHERE 客戶資料庫.區域 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.客戶群組 LIKE N'%" + 關鍵字.text + "%' " + "OR 客戶資料庫.姓名 LIKE N'%" + 關鍵字.text + "%' OR " + "客戶資料庫.性別 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.電話 LIKE N'%" + 關鍵字.text + "%' OR " + "客戶資料庫.地址 LIKE N'%" + 關鍵字.text + "%' OR 客戶資料庫.備註 LIKE N'%" + 關鍵字.text + "%' " + "GROUP BY 客戶資料庫.姓名, 流年資料表.西元, 流年資料表.年, 流年資料表.客戶編號, 客戶資料庫.備註 " + "ORDER BY 流年資料表.西元 DESC, 流年資料表.年"; } } using (SqlCommand command = new SqlCommand(query, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) // 假設只取前兩筆資料 { JSONNode newValue = new JSONObject(); if (Main.Global.資料庫名稱=="流年") { newValue["姓名"] = reader["姓名"].ToString(); newValue["客戶編號"] = reader["客戶編號"].ToString(); newValue["備註"] = reader["備註"].ToString(); newValue["西元"] = reader["西元"].ToString(); newValue["年"] = reader["年"].ToString(); } else { newValue["姓名"] = reader["姓名"].ToString(); newValue["客戶編號"] = reader["客戶編號"].ToString(); newValue["備註"] = reader["備註"].ToString(); newValue["日期"] = reader["日期"].ToString(); } 書籍清單.Add(newValue); } } } } catch (Exception ex) { Debug.LogError("Error connecting to the database: " + ex.Message); 彈跳面板.SetActive(true); 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員"; } finally { connection.Close(); } } if (copy != null) { DeleteCopies(copy); } int sum = 5; if (Main.Global.資料庫名稱=="流年") { 選擇書籍標題.text ="西元-年"; } else { 選擇書籍標題.text ="日期"; } for (int i = 0; i < 書籍清單.Count; i++) { GameObject buttonObj = Instantiate(buttonPrefab) as GameObject; buttonObj.GetComponent().anchoredPosition = new Vector2(2, -sum); buttonObj.transform.SetParent(buttonParent, false); TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren(); Button bt = buttonObj.GetComponentInChildren