123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 |
- 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 TMP_Dropdown 日;
- public TMP_Dropdown 字體;
- public TMP_Dropdown 字體1;
- public Toggle 歷史;
- public Toggle 全部;
- public Toggle 編輯;
- public Toggle 編輯1;
- [SerializeField] GameObject 回主頁紐;
- [SerializeField] GameObject 回選擇書籍紐;
- [SerializeField] GameObject 新增紐;
- [SerializeField] GameObject 存檔紐;
- [SerializeField] GameObject 細板;
- [SerializeField] GameObject 寬板;
- [SerializeField] GameObject 選擇書籍;
- [SerializeField] TextMeshProUGUI 日期;
- [SerializeField] TMP_InputField 日誌s;
- [SerializeField] TextMeshProUGUI 日期1;
- [SerializeField] TMP_InputField 日誌s1;
- [SerializeField] TMP_InputField 輸入;
- [SerializeField] TMP_InputField 輸入1;
- public CanvasScaler canvasScaler;
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
- [SerializeField] GameObject 彈跳面板;
- [SerializeField] TextMeshProUGUI 彈跳文字;
- private string loadingText = "";
- private int dotCount = 0;
- JSONArray 書籍清單;
- public GameObject buttonPrefab;
- public Transform buttonParent;
- public GameObject buttonceneter;
- private List<GameObject> copy = new List<GameObject>();
- // Start is called before the first frame update
- void Start()
- {
- //Main.Global.固寬=900f;
- //Main.Global.固高=1900f;
- //Main.Global.固比=1f;
- //Main.Global.螢幕格式="瘦";
- //Main.Global.sql="Data Source=180.177.181.162,5264;Initial Catalog=BIFENG-ERP-SYS;User ID=b70340;Password=0911274990";
- Screen.autorotateToPortrait = false;
- Screen.orientation = ScreenOrientation.Portrait;
- canvasScaler.referenceResolution = new Vector2(Main.Global.固寬, Main.Global.固高);
- canvasScaler.matchWidthOrHeight=Main.Global.固比;
- StartCoroutine(AnimateText());
- 讀取年份();
- 讀取書籍清單();
- 選擇書籍.SetActive(true);
- 新增紐.SetActive(true);
- 存檔紐.SetActive(false);
- 細板.SetActive(false);
- 寬板.SetActive(false);
- 回主頁紐.SetActive(true);
- 回選擇書籍紐.SetActive(false);
- 字體.value = 1;
- 字體1.value = 1;
- 字體.onValueChanged.AddListener((value) => 改字());
- 字體1.onValueChanged.AddListener((value) => 改字1());
- 輸入.onSubmit.AddListener(OnSubmit);
- 輸入1.onSubmit.AddListener(OnSubmit1);
- }
-
-
- private void 改字()
- {
- int 字體大小值 = int.Parse(字體.options[字體.value].text);
- 日誌s.textComponent.fontSize = 字體大小值;
- }
- private void 改字1()
- {
- int 字體大小值 = int.Parse(字體1.options[字體1.value].text);
- 日誌s1.textComponent.fontSize = 字體大小值;
- }
- 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;
- }
- }
- public void 讀取年份()
- {
- 讀取面板.SetActive(true);
- 年.options.Clear();
- List<TMP_Dropdown.OptionData> options = new List<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()));
- }
- 年.AddOptions(options);
- DateTime currentDate = DateTime.Now;
- int currentIndex = 年.options.FindIndex(option => option.text == currentDate.Year.ToString());
- 年.value = currentIndex;
- string monStr = $"{currentDate.Month:00}";
- int currentIndex1 = 月.options.FindIndex(option => option.text == monStr);
- 月.value = currentIndex1;
- string yearStr=年.options[年.value].text;
- string monthStr= 月.options[月.value].text;
- if (int.TryParse(yearStr, out int year) && int.TryParse(monthStr, out int month))
- {
- 日期讀取(year, month);
- string dayStr = $"{currentDate.Day:00}";
- int currentIndex2 = 日.options.FindIndex(option => option.text == dayStr);
- 日.value = currentIndex2;
- }
- 年.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
- 月.onValueChanged.AddListener((value) => OnDropdown1ValueChanged());
- 日.onValueChanged.AddListener((value) => OnDropdown1ValueChanged1());
- }
- }
- }
- catch (Exception ex)
- {
- Debug.LogError("Error connecting to the database: " + ex.Message);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
- }
- finally
- {
- connection.Close();
-
- }
- }
- 讀取面板.SetActive(false);
- }
- private void OnDropdown1ValueChanged()
- {
- string yearStr = 年.options[年.value].text;
- string monthStr = 月.options[月.value].text;
- if (int.TryParse(yearStr, out int year) && int.TryParse(monthStr, out int month))
- {
- 日期讀取(year, month);
- if (歷史.isOn==true)
- {
- 讀取書籍清單();
- }
- }
- }
- private void OnDropdown1ValueChanged1()
- {
- if (歷史.isOn==true)
- {
- 讀取書籍清單();
- }
- }
- public void 日期讀取(int year , int month)
- {
- int daysInMonth = DateTime.DaysInMonth(year, month);
- 日.options.Clear();
- List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
- for (int i = 1; i <= daysInMonth; i++)
- {
- string dayStr = i < 10 ? "0" + i.ToString() : i.ToString();
- options.Add(new TMP_Dropdown.OptionData(dayStr));
- }
- 日.AddOptions(options);
- }
- public void 讀取書籍清單()
- {
- 讀取面板.SetActive(true);
- 書籍清單 = new JSONArray();
- using (SqlConnection connection = new SqlConnection(Main.Global.sql))
- {
- try
- {
- connection.Open();
- string query = "";
- if (歷史.isOn==true)
- {
- string str = 月.options[月.value].text + "/" + 日.options[日.value].text;
- query = "SELECT 日期, 日誌 FROM 日誌資料表 WHERE (日期 LIKE N'%" + str + "') ORDER BY 日期 DESC";
- }
- else
- {
- query = "SELECT 日期, 日誌 FROM 日誌資料表 ORDER BY 日期 DESC";
- }
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- while (reader.Read()) // 假設只取前兩筆資料
- {
- JSONNode newValue = new JSONObject();
- 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;
- 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.GetComponentInChildren<TextMeshProUGUI>();
- Button bt = buttonObj.GetComponentInChildren<Button>();
- int index = i;
- bt.onClick.AddListener(() =>
- {
- 回主頁紐.SetActive(false);
- 回選擇書籍紐.SetActive(true);
- 選擇書籍.SetActive(false);
- 新增紐.SetActive(false);
- 存檔紐.SetActive(true);
- string jsonString = 書籍清單[index][1].ToString().Trim('"');
- string unescapedString = Regex.Unescape(jsonString);
- if (Main.Global.螢幕格式=="胖")
- {
- 細板.SetActive(false);
- 寬板.SetActive(true);
- 日誌s1.text = unescapedString;
- 日期1.text = 書籍清單[index][0].ToString().Trim('"');
- 日誌s1.interactable = false;
- }
- else
- {
- 細板.SetActive(true);
- 寬板.SetActive(false);
- 日誌s.text = unescapedString;
- 日誌s.interactable = false;
- 日期.text =書籍清單[index][0].ToString().Trim('"');
- }
- });
- text.text = 書籍清單[i][0].ToString().Trim('"');
- sum+=120;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- 讀取面板.SetActive(false);
- }
- public void 存檔()
- {
- string str = "";
- 讀取面板.SetActive(true);
- using (SqlConnection connection = new SqlConnection(Main.Global.sql))
- {
- try
- {
- connection.Open();
- string query = "";
- if (Main.Global.螢幕格式=="胖")
- {
- query = "SELECT 日期 FROM 日誌資料表 WHERE 日期 LIKE N'" + 日期1.text.ToString() + "'";
- }
- else
- {
- query = "SELECT 日期 FROM 日誌資料表 WHERE 日期 LIKE N'" + 日期.text.ToString() + "'";
- }
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- while (reader.Read()) // 假設只取前兩筆資料
- {
- str = reader["日期"].ToString();
- }
- }
- }
- }
- catch (Exception ex)
- {
- Debug.LogError("Error connecting to the database: " + ex.Message);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
- }
- finally
- {
- connection.Close();
-
- }
- }
-
- if (str == "")
- {
- 存檔新增();
- }
- else
- {
- 存檔修改();
- }
- 讀取書籍清單();
- 選擇書籍.SetActive(true);
- 細板.SetActive(false);
- 寬板.SetActive(false);
- 讀取面板.SetActive(false);
- 彈跳面板.SetActive(true);
- 彈跳文字.text="儲存完成";
- }
- public void 存檔新增()
- {
- using (SqlConnection connection = new SqlConnection(Main.Global.sql))
- {
- try
- {
- connection.Open();
- string query = "";
- if (Main.Global.螢幕格式=="胖")
- {
- query = "INSERT INTO 日誌資料表 (日期, 日誌) SELECT N'" + 日期1.text.ToString() + "', N'" + 日誌s1.text.ToString() + "'";
- }
- else
- {
- query = "INSERT INTO 日誌資料表 (日期, 日誌) SELECT N'" + 日期.text.ToString() + "', N'" + 日誌s.text.ToString() + "'";
- }
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- while (reader.Read())
- {
-
- }
- }
- }
-
- }
- catch (Exception ex)
- {
- Debug.LogError("Error connecting to the database: " + ex.Message);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
- }
- finally
- {
- connection.Close();
- }
- }
-
- }
- public void 存檔修改()
- {
- using (SqlConnection connection = new SqlConnection(Main.Global.sql))
- {
- try
- {
- connection.Open();
- string query = "";
- if (Main.Global.螢幕格式=="胖")
- {
- query = "UPDATE 日誌資料表 SET 日誌 = N'" + 日誌s1.text.ToString() + "' WHERE 日期 LIKE N'" + 日期1.text.ToString() + "'";
- }
- else
- {
- query = "UPDATE 日誌資料表 SET 日誌 = N'" + 日誌s.text.ToString() + "' WHERE 日期 LIKE N'" + 日期.text.ToString() + "'";
- }
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- while (reader.Read())
- {
-
- }
- }
- }
- }
- catch (Exception ex)
- {
- Debug.LogError("Error connecting to the database: " + ex.Message);
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "目前無法連到伺服器,請通知系統管理員";
- }
- finally
- {
- connection.Close();
- }
- }
-
- }
- public void 彈跳面板關閉()
- {
- 彈跳面板.SetActive(false);
- 彈跳文字.text = "";
- }
-
- public void 輸入文字1()
- {
- if (編輯1.isOn == false)
- {
- string str = 輸入1.text;
- if (日誌s1.text=="")
- {
- 日誌s1.text+=str;
- }
- else
- {
- 日誌s1.text+= "\n" +str;
- }
- 輸入1.text = "";
- }
- }
- public void 編輯切換1()
- {
- if (編輯1.isOn == false)
- {
- 日誌s1.interactable = false;
- 輸入1.interactable = true;
-
- }
- else
- {
- 日誌s1.interactable = true;
- 輸入1.interactable = false;
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "如有排版需求,請至PC版,再手機上排版比較不方便";
- }
-
- }
- void OnSubmit(string inputText)
- {
- string str = 輸入.text;
- if (日誌s.text=="")
- {
- 日誌s.text+=str;
- }
- else
- {
- 日誌s.text+= "\n" +str;
- }
- 輸入.text = "";
- }
- void OnSubmit1(string inputText)
- {
- string str = 輸入1.text;
- if (日誌s1.text=="")
- {
- 日誌s1.text+=str;
- }
- else
- {
- 日誌s1.text+= "\n" +str;
- }
- 輸入1.text = "";
- }
- public void 輸入文字()
- {
- if (編輯.isOn == false)
- {
- string str = 輸入.text;
- if (日誌s.text=="")
- {
- 日誌s.text+=str;
- }
- else
- {
- 日誌s.text+= "\n" +str;
- }
- 輸入.text = "";
- }
- }
- public void 編輯切換()
- {
- if (編輯.isOn == false)
- {
- 日誌s.interactable = false;
- 輸入.interactable = true;
- }
- else
- {
- 日誌s.interactable = true;
- 輸入.interactable = false;
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "如有排版需求,請至PC版,再手機上排版比較不方便";
- }
-
- }
- public void t1_click()
- {
-
- if (歷史.isOn==false && 全部.isOn==false )
- {
- 歷史.isOn = true;
- 全部.isOn = false;
- }
- else if (歷史.isOn==true && 全部==true)
- {
- 歷史.isOn = true;
- 全部.isOn = false;
- 讀取書籍清單();
- }
- }
-
- public void t2_click()
- {
- if (歷史.isOn==false && 全部.isOn==false)
- {
- 歷史.isOn = false;
- 全部.isOn = true;
- }
- else if (歷史.isOn==true && 全部.isOn==true)
- {
- 歷史.isOn = false;
- 全部.isOn = true;
- 讀取書籍清單();
- }
- }
- public void 新增日()
- {
- string str = "";
- 讀取面板.SetActive(true);
- using (SqlConnection connection = new SqlConnection(Main.Global.sql))
- {
- try
- {
- connection.Open();
- string query = "";
- string str1 = 年.options[年.value].text + "/" + 月.options[月.value].text + "/" + 日.options[日.value].text;
- if (Main.Global.螢幕格式=="胖")
- {
- query = "SELECT 日期 FROM 日誌資料表 WHERE 日期 LIKE N'" + str1 + "'";
- }
- else
- {
- query = "SELECT 日期 FROM 日誌資料表 WHERE 日期 LIKE N'" + str1 + "'";
- }
- using (SqlCommand command = new SqlCommand(query, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- while (reader.Read()) // 假設只取前兩筆資料
- {
- str = reader["日期"].ToString();
- }
- }
- }
- }
- catch (Exception ex)
- {
- Debug.LogError("Error connecting to the database: " + ex.Message);
-
- }
- finally
- {
- connection.Close();
-
- }
- }
- 讀取面板.SetActive(false);
- if (str == "")
- {
- 回主頁紐.SetActive(false);
- 回選擇書籍紐.SetActive(true);
- 選擇書籍.SetActive(false);
- 新增紐.SetActive(false);
- 存檔紐.SetActive(true);
- if (Main.Global.螢幕格式=="胖")
- {
- 細板.SetActive(false);
- 寬板.SetActive(true);
- 日誌s1.text = "";
- 日誌s1.interactable = false;
- 日期1.text =年.options[年.value].text + "/" + 月.options[月.value].text + "/" + 日.options[日.value].text;
- }
- else
- {
- 細板.SetActive(true);
- 寬板.SetActive(false);
- 日誌s.text = "";
- 日誌s.interactable = false;
- 日期.text =年.options[年.value].text + "/" + 月.options[月.value].text + "/" + 日.options[日.value].text;
- }
- }
- else
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "已有該日日誌";
- }
-
- }
- public void 回選書()
- {
- 選擇書籍.SetActive(true);
- 細板.SetActive(false);
- 寬板.SetActive(false);
- 回主頁紐.SetActive(true);
- 回選擇書籍紐.SetActive(false);
- 新增紐.SetActive(true);
- 存檔紐.SetActive(false);
- 日誌s.text = "";
- 日期.text ="";
- 日誌s1.text = "";
- 日期1.text ="";
- 輸入.text ="";
- 輸入1.text ="";
- }
- public void 回主()
- {
- change_Secen(1);
- }
- private void DeleteCopies(List<GameObject> copyList)
- {
- foreach (GameObject copy in copyList)
- {
- Destroy(copy);
- }
- copyList.Clear();
- }
- public void change_Secen(int _screenNum)
- {
-
- SceneManager.LoadScene(_screenNum);
- }
- public void 截圖()
- {
- string fileName = string.Format("{0}/screenshot_{1}.png", Application.persistentDataPath, System.DateTime.Now.ToString("yyyyMMdd_HHmmss"));
- ScreenCapture.CaptureScreenshot(fileName);
- }
- }
|