1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174 |
- 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<GameObject> copy = new List<GameObject>();
-
- public GameObject buttonPrefab1;
- public Transform buttonParent1;
- public GameObject buttonceneter1;
- private List<GameObject> copy1 = new List<GameObject>();
- 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<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
- List<TMP_Dropdown.OptionData> options1 = new List<TMP_Dropdown.OptionData>();
- 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<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- buttonObj.transform.SetParent(buttonParent, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- Button bt = buttonObj.GetComponentInChildren<Button>();
- int index = i;
- bt.onClick.AddListener(() =>
- {
- 旋轉角度 = 0f;
- scrollbar.value=1f;
- scrollbar1.value=1f;
- rawImage1.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- rawImage.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- rawImage.transform.localScale = new Vector3(1f, 1f, 1f);
- rawImage1.transform.localScale = new Vector3(1f, 1f, 1f);
- 判斷 = false;
- 選擇書籍.SetActive(false);
- if (Main.Global.螢幕格式=="胖")
- {
- 寬板.SetActive(true);
- 細板.SetActive(false);
- 書編1.text =書籍清單[index][1].ToString().Trim('"');
- 書名s1.text=書籍清單[index][0].ToString().Trim('"');
- if (Main.Global.資料庫名稱=="流年")
- {
-
- 書頁名1.text=書籍清單[index][3].ToString().Trim('"')+"-"+書籍清單[index][4].ToString().Trim('"');
- }
- else
- {
- 書頁名1.text=書籍清單[index][3].ToString().Trim('"');
- }
-
- }
- else
- {
- 細板.SetActive(true);
- 寬板.SetActive(false);
- 書編.text =書籍清單[index][1].ToString().Trim('"');
- 書名s.text=書籍清單[index][0].ToString().Trim('"');
- if (Main.Global.資料庫名稱=="流年")
- {
-
- 書頁名.text=書籍清單[index][3].ToString().Trim('"')+"-"+書籍清單[index][4].ToString().Trim('"');
- }
- else
- {
- 書頁名.text=書籍清單[index][3].ToString().Trim('"');
- }
- }
- 選擇頁面.SetActive(false);
- 回主頁紐.SetActive(false);
- 回選擇書籍紐.SetActive(true);
- 選擇頁面紐.SetActive(true);
-
-
- 讀取書籍內容清單();
- 顯示圖片("1");
- });
- if (Main.Global.資料庫名稱=="流年")
- {
- text[0].text = 書籍清單[i][0].ToString().Trim('"');
- text[1].text = 書籍清單[i][3].ToString().Trim('"')+"-"+ 書籍清單[i][4].ToString().Trim('"');
-
- }
- else
- {
- text[0].text = 書籍清單[i][0].ToString().Trim('"');
- text[1].text = 書籍清單[i][3].ToString().Trim('"');
- }
-
- sum+=120;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- 讀取面板.SetActive(false);
- }
-
- public void 讀取書籍內容清單()
- {
- 讀取面板.SetActive(true);
- 書籍內容清單 = new JSONArray();
- string str = "";
- string str1 = "";
- string str2 = "";
- if (Main.Global.資料庫名稱=="流年")
- {
- if (Main.Global.螢幕格式=="胖")
- {
- str=書編1.text;
- string gg = 書頁名1.text;
- string[] 分割結果 = gg.Split('-');
- str1 = 分割結果[0];
- str2 = 分割結果[1];
-
- }
- else
- {
- str=書編.text;
- string gg = 書頁名.text;
- string[] 分割結果 = gg.Split('-');
- str1 = 分割結果[0];
- str2 = 分割結果[1];
- }
- }
- else
- {
- if (Main.Global.螢幕格式=="胖")
- {
- str=書編1.text;
- str1 = 書頁名1.text;
-
- }
- else
- {
- str=書編.text;
- str1 = 書頁名.text;
- }
- }
-
-
- using (SqlConnection connection = new SqlConnection(Main.Global.sql))
- {
- try
- {
- connection.Open();
-
- string query = "";
- if (Main.Global.資料庫名稱=="風水")
- {
- query = "SELECT 風水資料表.日期, 頁數, 備註 FROM 風水資料表 WHERE (客戶編號 LIKE '" + str + "' AND " +
- "風水資料表.日期 LIKE '" + str1 + "') ORDER BY 日期 DESC, 頁數";
- }
- else if (Main.Global.資料庫名稱=="擇日")
- {
- query = "SELECT 擇日資料表.日期, 頁數, 備註 FROM 擇日資料表 WHERE (客戶編號 LIKE '" + str + "' AND " +
- "擇日資料表.日期 LIKE '" + str1 + "') ORDER BY 日期 DESC, 頁數";
- }
- else if (Main.Global.資料庫名稱=="命名")
- {
- query = "SELECT 命名資料表.日期, 頁數, 備註 FROM 命名資料表 WHERE (客戶編號 LIKE '" + str + "' AND " +
- "命名資料表.日期 LIKE '" + str1 + "') ORDER BY 日期 DESC, 頁數";
- }
- else if (Main.Global.資料庫名稱=="流年")
- {
- query = "SELECT 西元, 頁數, 備註,年 FROM 流年資料表 WHERE (客戶編號 LIKE '" + str + "' AND " +
- "西元 LIKE '" + str1 + "' AND 年 LIKE '" + str2 + "') 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();
-
- }
- else
- {
- 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 (Main.Global.PA4 =="")
- {
- if (Main.Global.螢幕格式=="胖")
- {
- if (Main.Global.資料庫名稱=="流年")
- {
-
- 書頁名1.text=書籍內容清單[0][0]+"-"+書籍內容清單[0][3];
- 第幾頁1.text=書籍內容清單[0][1];
- }
- else
- {
- 書頁名1.text=書籍內容清單[0][0];
- 第幾頁1.text=書籍內容清單[0][1];
- }
-
- }
- else
- {
- if (Main.Global.資料庫名稱=="流年")
- {
-
- 書頁名.text=書籍內容清單[0][0]+"-"+書籍內容清單[0][3];
- 第幾頁.text=書籍內容清單[0][1];
- }
- else
- {
- 書頁名.text=書籍內容清單[0][0];
- 第幾頁.text=書籍內容清單[0][1];
- }
- }
- }
- 最大頁數 =書籍內容清單.Count;
- if (copy1 != null)
- {
- DeleteCopies(copy1);
- }
- if (Main.Global.資料庫名稱=="流年")
- {
-
- 選擇頁標題.text ="西元-年";
- }
- else
- {
- 選擇頁標題.text ="日期";
- }
- int sum = 5;
- for (int i = 0; i < 書籍內容清單.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- buttonObj.transform.SetParent(buttonParent1, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- Button bt = buttonObj.GetComponentInChildren<Button>();
- int index1 = i;
- bt.onClick.AddListener(() =>
- {
- 選擇頁面.SetActive(!選擇頁面.activeSelf);
- string str1 = 書籍內容清單[index1][1].ToString().Trim('"');
- if (Main.Global.螢幕格式=="胖")
- {
- 寬板.SetActive(!寬板.activeSelf);
- 第幾頁1.text=書籍內容清單[index1][1].ToString().Trim('"');
- 顯示圖片(str1);
- }
- else
- {
- 細板.SetActive(!細板.activeSelf);
- 第幾頁.text=書籍內容清單[index1][1].ToString().Trim('"');
- 顯示圖片(str1);
- }
-
- });
- text[0].text = 書籍內容清單[i][0].ToString().Trim('"');
- text[1].text = 書籍內容清單[i][1].ToString().Trim('"');
- sum+=120;
- copy1.Add(buttonObj);
- }
- buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
- 讀取面板.SetActive(false);
- }
- public void 顯示圖片(string 頁數)
- {
- rawImage.texture =Texture2D.blackTexture;
- 讀取面板.SetActive(true);
- string str = "";
- string str1 = "";
- string str2 = "";
- if (Main.Global.資料庫名稱=="流年")
- {
- if (Main.Global.螢幕格式=="胖")
- {
- str=書編1.text;
- string gg = 書頁名1.text;
- string[] 分割結果 = gg.Split('-');
- str1 = 分割結果[0];
- str2 = 分割結果[1];
- }
- else
- {
- str=書編.text;
- string gg = 書頁名.text;
- string[] 分割結果 = gg.Split('-');
- str1 = 分割結果[0];
- str2 = 分割結果[1];
- }
- }
- else
- {
- if (Main.Global.螢幕格式=="胖")
- {
- str=書編1.text;
- str1 = 書頁名1.text;
-
- }
- else
- {
- str=書編.text;
- str1 = 書頁名.text;
- }
- }
- using (SqlConnection connection = new SqlConnection(Main.Global.sql))
- {
- try
- {
- connection.Open();
-
- string query = "";
- if (Main.Global.資料庫名稱=="風水")
- {
- query = "SELECT 圖片 FROM 風水資料表 WHERE 客戶編號 LIKE N'" + str + "' AND +" +
- "日期 LIKE N'" + str1 + "' AND 頁數 LIKE N'" + 頁數 + "'";
- }
- else if (Main.Global.資料庫名稱=="擇日")
- {
- query = "SELECT 圖片 FROM 擇日資料表 WHERE 客戶編號 LIKE N'" + str + "' AND +" +
- "日期 LIKE N'" + str1 + "' AND 頁數 LIKE N'" + 頁數 + "'";
- }
- else if (Main.Global.資料庫名稱=="命名")
- {
- query = "SELECT 圖片 FROM 命名資料表 WHERE 客戶編號 LIKE N'" + str + "' AND +" +
- "日期 LIKE N'" + str1 + "' AND 頁數 LIKE N'" + 頁數 + "'";
- }
- else if (Main.Global.資料庫名稱=="流年")
- {
- query = "SELECT 圖片 FROM 流年資料表 WHERE 客戶編號 LIKE N'" + str + "' AND +" +
- "西元 LIKE N'" + str1 + "'AND 年 LIKE N'" + str2 + "' AND 頁數 LIKE N'" + 頁數 + "'";
- }
- Debug.Log(query);
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- while (reader.Read()) // 假設只取前兩筆資料
- {
- byte[] bytes = (byte[])reader["圖片"];
- texture = new Texture2D(2, 2);
- texture.LoadImage(bytes);
- 判斷 = false;
- 旋轉角度 = 0f;
- scrollbar.value=1f;
- scrollbar1.value=1f;
- rawImage1.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- rawImage.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- rawImage.transform.localScale = new Vector3(1f, 1f, 1f);
- rawImage1.transform.localScale = new Vector3(1f, 1f, 1f);
- if (Main.Global.螢幕方向 == "直")
- {
- if (Main.Global.螢幕格式 == "胖")
- {
- AdjustImageProperties(texture, rawImage1, 1000f, 1230f);
- }
- else
- {
- AdjustImageProperties(texture, rawImage, 900f, 1530f);
- }
- }
- else
- {
- if (Main.Global.螢幕格式 == "胖")
- {
- AdjustImageProperties(texture, rawImage1, 1600f, 850f);
- }
- else
- {
- AdjustImageProperties(texture, rawImage, 1900f, 750f);
- }
- }
-
-
-
- }
- }
- }
- }
- catch (Exception ex)
- {
- Debug.LogError("Error connecting to the database: " + ex.Message);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
- }
- finally
- {
- connection.Close();
-
- }
- }
- 讀取面板.SetActive(false);
- }
- public void AdjustImageProperties(Texture texture, RawImage rawImage, float maxWidth, float maxHeight)
- {
- rawImage.texture = texture;
- rawImage.rectTransform.sizeDelta = new Vector2(maxWidth, maxHeight);
- float aspectRatio = (float)texture.width / texture.height;
- if (判斷)
- {
- aspectRatio = 1 / aspectRatio;
- }
- float aspectRatio1 = maxWidth / maxHeight;
- float newWidth ;
- float newHeight ;
- if (aspectRatio > aspectRatio1)
- {
- if (判斷)
- {
- newWidth = Mathf.Min(maxWidth, rawImage.rectTransform.rect.height);
- }
- else
- {
- newWidth = Mathf.Min(maxWidth, rawImage.rectTransform.rect.width);
- }
-
- newHeight = newWidth / aspectRatio;
- }
- else
- {
- if (判斷)
- {
- newHeight = Mathf.Min(maxHeight, rawImage.rectTransform.rect.width);
- }
- else
- {
- newHeight = Mathf.Min(maxHeight, rawImage.rectTransform.rect.height);
- }
-
- newWidth = newHeight * aspectRatio;
- }
- if (判斷)
- {
- rawImage.rectTransform.sizeDelta = new Vector2(newHeight, newWidth);
- }
- else
- {
- rawImage.rectTransform.sizeDelta = new Vector2(newWidth, newHeight);
- }
- Debug.Log(旋轉角度);
- Debug.Log(判斷);
- Debug.Log(aspectRatio);
- Debug.Log(aspectRatio1);
- Debug.Log(texture.width);
- Debug.Log(texture.height);
- Debug.Log(newWidth);
- Debug.Log(newHeight);
- }
-
- public void 選單按鈕()
- {
- if (Main.Global.螢幕格式=="胖")
- {
- 寬板.SetActive(!寬板.activeSelf);
- }
- else
- {
- 細板.SetActive(!細板.activeSelf);
- }
- 選擇頁面.SetActive(!選擇頁面.activeSelf);
- }
-
- public void 倍率改變()
- {
- float scaleFactor = scrollbar.value;
- rawImage.transform.localScale = new Vector3(initialScale * scaleFactor, initialScale * scaleFactor, 1f);
- }
- public void 倍率改變1()
- {
- float scaleFactor = scrollbar1.value;
- rawImage1.transform.localScale = new Vector3(initialScale * scaleFactor, initialScale * scaleFactor, 1f);
- }
-
- public void 旋轉正()
- {
- 判斷 = !判斷;
- scrollbar.value=1f;
- scrollbar1.value=1f;
- rawImage.transform.localScale = new Vector3(1f, 1f, 1f);
- rawImage1.transform.localScale = new Vector3(1f, 1f, 1f);
-
- 旋轉角度 += 90f;
- if (旋轉角度 >= 360f)
- {
- 旋轉角度 -= 360f;
- }
- 圖片顯示();
- }
- public void 旋轉負()
- {
- 判斷 = !判斷;
- scrollbar.value=1f;
- scrollbar1.value=1f;
- rawImage.transform.localScale = new Vector3(1f, 1f, 1f);
- rawImage1.transform.localScale = new Vector3(1f, 1f, 1f);
- 旋轉角度 -= 90f;
- if (旋轉角度 < 0f)
- {
- 旋轉角度 += 360f;
- }
- 圖片顯示();
- }
- public void 圖片顯示()
- {
-
- if (Main.Global.螢幕方向 == "直")
- {
- if (Main.Global.螢幕格式 == "胖")
- {
-
- rawImage1.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- AdjustImageProperties(texture, rawImage1, 1000f, 1230f);
- }
- else
- {
- rawImage.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- AdjustImageProperties(texture, rawImage, 900f, 1530f);
- }
- }
- else
- {
- if (Main.Global.螢幕格式 == "胖")
- {
- rawImage1.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- AdjustImageProperties(texture, rawImage1, 1600f, 850f);
- }
- else
- {
- rawImage.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- AdjustImageProperties(texture, rawImage, 1900f, 750f);
- }
- }
- }
-
-
-
- public void 上頁()
- {
- int currentPage = 0;
- if (Main.Global.螢幕格式=="胖")
- {
- currentPage = int.Parse(第幾頁1.text);
- }
- else
- {
- currentPage = int.Parse(第幾頁.text);
- }
- if (currentPage < 1 || currentPage > 最大頁數)
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "超過最大頁數,或小於最小頁數";
- }
- else
- {
- 判斷 = false;
- 旋轉角度 = 0f;
- scrollbar.value=1f;
- scrollbar1.value=1f;
- rawImage1.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- rawImage.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- rawImage.transform.localScale = new Vector3(1f, 1f, 1f);
- rawImage1.transform.localScale = new Vector3(1f, 1f, 1f);
- int newPage = Mathf.Max(1, currentPage - 1); // 確保不會小於 1
- if (Main.Global.螢幕格式=="胖")
- {
- 第幾頁1.text = newPage.ToString();
- string str1 = 第幾頁1.text;
- 顯示圖片(str1);
- }
- else
- {
- 第幾頁.text = newPage.ToString();
- string str1 = 第幾頁.text;
- 顯示圖片(str1);
- }
-
- }
-
- }
- public void 下頁()
- {
- int currentPage = 0;
- if (Main.Global.螢幕格式=="胖")
- {
- currentPage = int.Parse(第幾頁1.text);
- }
- else
- {
- currentPage = int.Parse(第幾頁.text);
- }
- if (currentPage < 1 || currentPage > 最大頁數)
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "超過最大頁數,或小於最小頁數";
- }
- else
- {
- 判斷 = false;
- 旋轉角度 = 0f;
- scrollbar.value=1f;
- scrollbar1.value=1f;
- rawImage1.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- rawImage.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- rawImage.transform.localScale = new Vector3(1f, 1f, 1f);
- rawImage1.transform.localScale = new Vector3(1f, 1f, 1f);
- int newPage = Mathf.Min(最大頁數, currentPage + 1); // 確保不會超過最大頁數
- if (Main.Global.螢幕格式=="胖")
- {
- 第幾頁1.text = newPage.ToString();
- string str1 = 第幾頁1.text;
- 顯示圖片(str1);
- }
- else
- {
- 第幾頁.text = newPage.ToString();
- string str1 = 第幾頁.text;
- 顯示圖片(str1);
- }
-
- }
-
- }
- public void 指定()
- {
- int currentPage = 0;
- if (Main.Global.螢幕格式=="胖")
- {
- currentPage = int.Parse(第幾頁1.text);
- }
- else
- {
- currentPage = int.Parse(第幾頁.text);
- }
- if (currentPage < 1 || currentPage > 最大頁數)
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "超過最大頁數,或小於最小頁數";
- }
- else
- {
- 判斷 = false;
- 旋轉角度 = 0f;
- scrollbar.value=1f;
- scrollbar1.value=1f;
- rawImage1.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- rawImage.rectTransform.rotation = Quaternion.Euler(0f, 0f, 旋轉角度);
- rawImage.transform.localScale = new Vector3(1f, 1f, 1f);
- rawImage1.transform.localScale = new Vector3(1f, 1f, 1f);
- if (Main.Global.螢幕格式=="胖")
- {
- string str1 = 第幾頁1.text;
- 顯示圖片(str1);
- }
- else
- {
- string str1 = 第幾頁.text;
- 顯示圖片(str1);
- }
-
- }
-
- }
- public void 彈跳面板關閉()
- {
- 彈跳面板.SetActive(false);
- 彈跳文字.text = "";
- }
- public void 回選書()
- {
- 選擇書籍.SetActive(true);
- 細板.SetActive(false);
- 寬板.SetActive(false);
- 選擇頁面.SetActive(false);
- 回主頁紐.SetActive(true);
- 回選擇書籍紐.SetActive(false);
- 選擇頁面紐.SetActive(false);
- 書編1.text="";
- 書名s1.text="";
- 書頁名1.text="";
- 第幾頁1.text="";
- 書編.text="";
- 書名s.text="";
- 書頁名.text="";
- 第幾頁.text="";
- }
- public void 回主()
- {
- if (Main.Global.螢幕方向=="直")
- {
- change_Secen(1);
- }
- else
- {
- change_Secen(3);
- }
- }
- private void DeleteCopies(List<GameObject> copyList)
- {
- foreach (GameObject copy in copyList)
- {
- Destroy(copy);
- }
- copyList.Clear();
- }
- public void change_Secen(int _screenNum)
- {
-
- SceneManager.LoadScene(_screenNum);
- }
- }
|