123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- using UnityEngine.EventSystems;
- using System.Text.RegularExpressions;
- using System.Data.SqlClient;
- using System.Runtime.InteropServices;
- using System.Text;
- using TMPro;
- using System;
- using System.IO;
- using ZXing;
- using ZXing.QrCode;
- using System.Net;
- using System.Data;
- using SimpleJSON;
- using System.Linq;
- using System.ComponentModel;
- using System.Runtime.InteropServices;
- using System.Globalization;
- using XCharts.Runtime;
-
- public class 物料使用 : MonoBehaviour
- {
- [SerializeField] GameObject bar;
- [SerializeField] RectTransform panelRectTransform1;
-
- [SerializeField] GameObject bar1;
- [SerializeField] RectTransform panelRectTransform;
-
- [SerializeField] TextMeshProUGUI startDateText;
- [SerializeField] TextMeshProUGUI endDateText;
-
- [SerializeField] GameObject p1;
- [SerializeField] GameObject p2;
- private bool isP1Active = true;
-
- private JSONNode 計算1;
- private JSONNode 計算2;
-
- 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>();
-
- public CanvasScaler canvasScaler;
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
-
- [SerializeField] GameObject 彈跳面板;
- [SerializeField] TextMeshProUGUI 彈跳文字;
-
- private string loadingText = "";
- private int dotCount = 0;
-
- // Start is called before the first frame update
- void Start()
- {
- Screen.autorotateToPortrait = false;
- Screen.orientation = ScreenOrientation.Portrait;
- float rate = 1000.0f / 1600.0f;
- if (canvasScaler == null)
- {
- canvasScaler = GetComponent<CanvasScaler>();
- }
- if (Main.Global.rate>rate)
- {
- canvasScaler.matchWidthOrHeight = 1f;
- }
- else
- {
- canvasScaler.matchWidthOrHeight = 0f;
- }
- StartCoroutine(AnimateText());
- //讀取面板.SetActive(true);
- //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/GF_main.php?";
- //Main.Global.預設伺服器路徑="GF01";
- DateTime today = DateTime.Today;
- DateTime startDate = new DateTime(today.Year, today.Month, 1);
- DateTime endDate = startDate.AddMonths(1).AddDays(-1);
- startDateText.text = startDate.ToString("yyyy/MM/dd");
- endDateText.text = endDate.ToString("yyyy/MM/dd");
- p1.SetActive(true);
- p2.SetActive(false);
-
- StartCoroutine(物料使用情況());
- }
- public void 變換()
- {
- isP1Active = !isP1Active;
- p1.SetActive(isP1Active);
- p2.SetActive(!isP1Active);
-
- }
- IEnumerator 物料使用情況()
- {
- 讀取面板.SetActive(true);
- if (copy1 != null)
- {
- DeletetextCopy1();
- }
- if (copy != null)
- {
- DeletetextCopy();
- }
- string strcon = "物料使用情況";
- string se = Main.Global.預設伺服器路徑;
- string pa1 = startDateText.text;
- string pa2 = endDateText.text;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}", strcon, se,pa1,pa2);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- yield break;
- }
- JSONNode json = JSON.Parse(request.downloadHandler.text);
- Debug.Log(json);
- int sum = 2;
- int sum1 = 2;
- 降冪(json, 1);
- Debug.Log(json);
- for (int i = 0; i < json.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum1);
- buttonObj.transform.SetParent(buttonParent1, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
-
- text[0].text =json[i][0].ToString().Trim('"').Replace("\\\\", "\\");
- text[1].text =json[i][1].ToString().Trim('"').Replace("\\\\", "\\");
- sum1+=75;
- copy1.Add(buttonObj);
- }
-
- int a = json.Count;
- panelRectTransform.anchoredPosition = new Vector2(0, 0);
- panelRectTransform1.anchoredPosition = new Vector2(0, 0);
- if (a<6)
- {
- panelRectTransform.sizeDelta= new Vector2(1000, 740);
- panelRectTransform1.sizeDelta= new Vector2(1000, 740);
- a=1000;
- }
- else
- {
- panelRectTransform.sizeDelta= new Vector2(a*167, 740);
- panelRectTransform1.sizeDelta= new Vector2(a*167, 740);
- a*=167;
- }
- BarChart barchart = bar1.GetComponent<BarChart>();
- var gc = barchart.EnsureChartComponent<GridCoord>();
- gc.left =100;
- gc.right =20;
- gc.top =120;
- gc.bottom =80;
- barchart.SetSize(a, 740);
- var title = barchart.EnsureChartComponent<Title>();
- title.text = "";
- List<string> xAxisValue = new List<string>();
- List<double> yAxisValue = new List<double>();
- for (int e = 0; e<json.Count; e++)
- {
- xAxisValue.Add(json[e][0].ToString().Trim('"').Replace("\\\\", "\\"));
- double h1 = (double.Parse(json[e][1]));
- yAxisValue.Add(h1);
- }
- barchart.RemoveData();
- barchart.AddSerie<Bar>("使用數量");
- foreach (int item in yAxisValue)
- {
- barchart.AddData(0, item);
- }
- foreach (var xValue in xAxisValue)
- {
- barchart.AddXAxisData(xValue);
- }
- Legend legend = barchart.EnsureChartComponent<Legend>();
- legend.show = true;
- legend.location =new Location() { align = Location.Align.TopLeft, top = 70, left =100 };
- Tooltip tooltip = barchart.EnsureChartComponent<Tooltip>();
- tooltip.show = true;
- tooltip.fixedY=-100;
- tooltip.numericFormatter="0,0";
- var yAxis = barchart.GetOrAddChartComponent<YAxis>();
- yAxis.axisLabel.numericFormatter="0,0";
-
-
- 降冪(json, 2);
- Debug.Log(json);
- for (int i = 0; i < json.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>();
-
- text[0].text =json[i][0].ToString().Trim('"').Replace("\\\\", "\\");
- text[1].text =json[i][2].ToString().Trim('"').Replace("\\\\", "\\");
- sum+=75;
- copy.Add(buttonObj);
- }
-
- BarChart barchart1 = bar.GetComponent<BarChart>();
- var gc1 = barchart1.EnsureChartComponent<GridCoord>();
- gc1.left =100;
- gc1.right =20;
- gc1.top =120;
- gc1.bottom =80;
- barchart1.SetSize(a, 740);
- var title1 = barchart1.EnsureChartComponent<Title>();
- title1.text = "";
- List<string> xAxisValue1 = new List<string>();
- List<int> yAxisValue1 = new List<int>();
- for (int e = 0; e<json.Count; e++)
- {
- xAxisValue1.Add(json[e][0].ToString().Trim('"').Replace("\\\\", "\\"));
- double h1 = (double.Parse(json[e][2]));
- int hh1 = (int)Math.Round(h1);
- yAxisValue1.Add(hh1);
- }
- barchart1.RemoveData();
- barchart1.AddSerie<Bar>("總金額");
- foreach (int item in yAxisValue1)
- {
- barchart1.AddData(0, item);
- }
- foreach (var xValue in xAxisValue1)
- {
- barchart1.AddXAxisData(xValue);
- }
- Legend legend1 = barchart1.EnsureChartComponent<Legend>();
- legend1.show = true;
- legend1.location =new Location() { align = Location.Align.TopLeft, top = 70, left =100 };
- Tooltip tooltip1 = barchart1.EnsureChartComponent<Tooltip>();
- tooltip1.show = true;
- tooltip1.fixedY=-100;
- tooltip1.numericFormatter="0,0";
- var yAxis1 = barchart1.GetOrAddChartComponent<YAxis>();
- yAxis1.axisLabel.numericFormatter="0,0";
-
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum1);
- 讀取面板.SetActive(false);
- }
- private void 降冪(JSONNode json, int a)
- {
- List<List<string>> tlist = new List<List<string>>();
- for (int i = 0; i<json.Count; i++)
- {
- List<string> list = new List<string>();
- for (int j = 0; j < json[i].Count; j++)
- {
- list.Add(json[i][j].ToString().Trim('"').Replace("\\\\", "\\"));
- }
- tlist.Add(list);
- }
- tlist = tlist.OrderByDescending(row => double.Parse(row[a])).ToList();
-
-
- for (int i = 0; i<json.Count; i++)
- {
-
- for (int j = 0; j < json[i].Count; j++)
- {
- json[i][j] = tlist[i][j];
- }
-
- }
-
- }
- public void DeletetextCopy()
- {
- foreach (GameObject i in copy)
- {
- Destroy(i);
- }
- copy.Clear();
-
- }
- public void DeletetextCopy1()
- {
- foreach (GameObject i in copy1)
- {
- Destroy(i);
- }
- copy1.Clear();
-
- }
- 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 本月()
- {
- DateTime today = DateTime.Today;
- DateTime startDate = new DateTime(today.Year, today.Month, 1);
- DateTime endDate = startDate.AddMonths(1).AddDays(-1);
- startDateText.text = startDate.ToString("yyyy/MM/dd");
- endDateText.text = endDate.ToString("yyyy/MM/dd");
- StartCoroutine(物料使用情況());
- }
- public void 本年()
- {
- DateTime today = DateTime.Today;
- DateTime startDate = new DateTime(today.Year, 1, 1);
- DateTime endDate = new DateTime(today.Year, 12, 31);
- startDateText.text = startDate.ToString("yyyy/MM/dd");
- endDateText.text = endDate.ToString("yyyy/MM/dd");
- StartCoroutine(物料使用情況());
- }
-
- public void 上一月()
- {
- DateTime startDate = DateTime.Parse(startDateText.text);
- DateTime endDate = DateTime.Parse(endDateText.text);
- startDate = startDate.AddMonths(-1);
- endDate = startDate.AddMonths(1).AddDays(-1);
- startDateText.text = startDate.ToString("yyyy/MM/dd");
- endDateText.text = endDate.ToString("yyyy/MM/dd");
- StartCoroutine(物料使用情況());
- }
- public void 上一年()
- {
- DateTime startDate = DateTime.Parse(startDateText.text);
- DateTime endDate = DateTime.Parse(endDateText.text);
- startDate = startDate.AddYears(-1);
- endDate = new DateTime(startDate.Year, 12, 31);
- startDateText.text = startDate.ToString("yyyy/MM/dd");
- endDateText.text = endDate.ToString("yyyy/MM/dd");
- StartCoroutine(物料使用情況());
- }
-
- public void exit()
- {
- change_Secen(1);
- }
- public void change_Secen(int _screenNum)
- {
- //Main.Global.判斷是否第一次=true;
- SceneManager.LoadScene(_screenNum);
- }
-
- }
|