123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539 |
- 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 選擇頁面;
- [SerializeField] GameObject 主畫面;
-
- [SerializeField] GameObject p1;
- [SerializeField] GameObject p2;
- private bool isP1Active = true;
-
- [SerializeField] GameObject bar;
- [SerializeField] RectTransform panelRectTransform1;
-
- [SerializeField] GameObject bar1;
- [SerializeField] RectTransform panelRectTransform;
-
- private JSONArray newjson;
-
-
- [SerializeField] TextMeshProUGUI 標題;
- [SerializeField] TextMeshProUGUI 標題1;
- [SerializeField] TextMeshProUGUI 日期合計金額;
-
- private JSONNode 車種;
- private JSONNode 計算;
- [SerializeField] TextMeshProUGUI 車種合計數量;
- [SerializeField] TextMeshProUGUI 車種合計金額;
- public TMP_Dropdown 年;
- public TMP_Dropdown 月;
-
- public CanvasScaler canvasScaler;
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
-
- [SerializeField] GameObject 彈跳面板;
- [SerializeField] TextMeshProUGUI 彈跳文字;
-
- private string loadingText = "";
- private int dotCount = 0;
-
- 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>();
-
- // 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";
- //Main.Global.狀態="保養維修";
- //Main.Global.可選擇車廠型式=false;
-
- if (Main.Global.可選擇車廠型式==true)
- {
- 選擇頁面.SetActive(true);
- 主畫面.SetActive(false);
- }
- else
- {
- Main.Global.狀態="保養維修";
- 選擇頁面.SetActive(false);
- 主畫面.SetActive(true);
- p1.SetActive(true);
- p2.SetActive(false);
- StartCoroutine(年份清單());
- }
- }
- public void 買賣()
- {
- Main.Global.狀態="車輛買賣";
- 選擇頁面.SetActive(false);
- 主畫面.SetActive(true);
- p1.SetActive(true);
- p2.SetActive(false);
- StartCoroutine(年份清單());
-
- }
- public void 保養()
- {
- Main.Global.狀態="保養維修";
- 選擇頁面.SetActive(false);
- 主畫面.SetActive(true);
- p1.SetActive(true);
- p2.SetActive(false);
- StartCoroutine(年份清單());
-
- }
- public void 變換()
- {
- isP1Active = !isP1Active;
- p1.SetActive(isP1Active);
- p2.SetActive(!isP1Active);
-
- }
- 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;
- }
- }
- IEnumerator 年份清單()
- {
- 讀取面板.SetActive(true);
- 年.options.Clear();
- List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
- string strcon = "年份清單";
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
- 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);
- for (int i = 0; i < json.Count; i++)
- {
- string str = json[i].ToString().Trim('"');
-
- options.Add(new TMP_Dropdown.OptionData(str));
- }
- 年.AddOptions(options);
- DateTime currentDate = DateTime.Now;
- int index1 = 年.options.FindIndex(option => option.text == currentDate.Year.ToString());
- 年.value = index1;
- int index2 = 月.options.FindIndex(option => option.text == currentDate.Month.ToString());
- 月.value = index2;
- 年.onValueChanged.AddListener(delegate
- {
- StartCoroutine(銷售報表車種());
- });
- 月.onValueChanged.AddListener(delegate
- {
- StartCoroutine(銷售報表車種());
- });
- yield return StartCoroutine(銷售報表車種());
- }
-
- IEnumerator 銷售報表車種()
- {
- 讀取面板.SetActive(true);
- if (copy != null)
- {
- DeletetextCopy();
- }
- string strcon = "";
- if (Main.Global.狀態 == "車輛買賣")
- {
- strcon = "銷售報表車種1";
- }
- else
- {
- strcon = "銷售報表車種";
- }
- string pa= 年.options[年.value].text + 月.options[月.value].text;
- string pa1 = Main.Global.狀態;
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}", strcon, se,pa,pa1);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- yield break;
- }
- 車種 = JSON.Parse(request.downloadHandler.text);
- int sum = 2;
- double sum1 = 0;
- double sum2 = 0;
- 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>();
- sum1+=double.Parse(車種[i][1]);
- sum2+=double.Parse(車種[i][2]);
- if (Main.Global.狀態 == "車輛買賣")
- {
- 標題1.text="廠牌";
- }
- else
- {
- 標題1.text="車型";
- }
-
- if (車種[i][0].ToString().Trim('"') == "")
- {
- text[0].text ="未填入車型";
- 車種[i][0] = "未填入車型";
- }
- else
- {
- text[0].text =車種[i][0].ToString().Trim('"');
- }
-
- text[1].text =車種[i][1].ToString().Trim('"');
- text[2].text = double.Parse(車種[i][2]).ToString("#,##0");
- sum+=50;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- 車種合計數量.text =sum1.ToString("#,##0");
- 車種合計金額.text =sum2.ToString("#,##0");
-
- double sum3 = sum2 /sum1;
-
- int a = 車種.Count;
- panelRectTransform.anchoredPosition = new Vector2(0, 0);
- if (a<13)
- {
- panelRectTransform.sizeDelta= new Vector2(1000, 740);
- a=1000;
-
- }
- else
- {
- panelRectTransform.sizeDelta= new Vector2(a*84, 740);
- a*=84;
-
- }
- 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<int> yAxisValue = new List<int>();
- List<int> yAxisValue1 = new List<int>();
- for (int e = 0; e<車種.Count; e++)
- {
- xAxisValue.Add(車種[e][0].ToString().Trim('"'));
- double h1 = (double.Parse(車種[e][1])*sum3);
- int hh1 = (int)Math.Round(h1);
- yAxisValue.Add(hh1);
- double h2 = (double.Parse(車種[e][2]));
- int hh2 = (int)Math.Round(h2);
- yAxisValue1.Add(hh2);
- }
- barchart.RemoveData();
- barchart.AddSerie<Bar>("金額");
- foreach (int item in yAxisValue1)
- {
- barchart.AddData(0, item);
- }
- barchart.AddSerie<Line>("次數");
- foreach (int item in yAxisValue)
- {
- barchart.AddData(1, 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";
-
- yield return StartCoroutine(銷售報表日期());
- 讀取面板.SetActive(false);
- }
-
- IEnumerator 銷售報表日期()
- {
- string strcon = "";
- string pa = "";
- if (Main.Global.狀態 == "車輛買賣")
- {
- if (月.options[月.value].text == "")
- {
- strcon = "銷售報表年1";
- pa =年.options[年.value].text;
- 標題.text ="月份";
- }
- else
- {
- strcon = "銷售報表日期1";
- pa = 年.options[年.value].text + 月.options[月.value].text;
- 標題.text ="日期";
- }
- }
- else
- {
- if (月.options[月.value].text == "")
- {
- strcon = "銷售報表年";
- pa =年.options[年.value].text;
- 標題.text ="月份";
- }
- else
- {
- strcon = "銷售報表日期";
- pa = 年.options[年.value].text + 月.options[月.value].text;
- 標題.text ="日期";
- }
- }
- string pa1 = Main.Global.狀態;
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}", strcon, se, pa, pa1);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- yield break;
- }
- 計算 = JSON.Parse(request.downloadHandler.text);
- if (copy1 != null)
- {
- DeletetextCopy1();
- }
- int sum = 2;
- double sum1 = 0;
- newjson = new JSONArray();
- if (月.options[月.value].text == "")
- {
- for (int i = 0; i < 12; i++)
- {
- string dayString = (i+1).ToString().PadLeft(2, '0');
- string str = 年.options[年.value].text+dayString;
- JSONNode newValue = new JSONObject();
- newValue["date"] = dayString;
- newValue["value"] = 0;
- for (int j = 0; j < 計算.Count; j++)
- {
- string str1 = 計算[j][0].ToString().Trim('"');
- if (str == str1)
- {
- newValue["value"] = double.Parse(計算[j][1]).ToString("#,##0");
- }
- }
- newjson.Add(newValue);
- }
- }
- else
- {
- int 年份 = int.Parse(年.options[年.value].text);
- int 月份 = int.Parse(月.options[月.value].text);
- int daysInMonth = DateTime.DaysInMonth(年份, 月份);
- for (int i = 0; i < daysInMonth; i++)
- {
-
- string dayString = (i+1).ToString().PadLeft(2, '0');
- string str = 年.options[年.value].text+月.options[月.value].text+dayString;
-
- JSONNode newValue = new JSONObject();
- newValue["date"] = dayString;
- newValue["value"] = 0;
-
- for (int j = 0; j < 計算.Count; j++)
- {
- string str1 = 計算[j][0].ToString().Trim('"');
- if (str == str1)
- {
- newValue["value"] = double.Parse(計算[j][1]).ToString("#,##0");
- }
- }
- newjson.Add(newValue);
- }
- }
- for (int i = 0; i < newjson.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>();
- sum1+=double.Parse(newjson[i][1]);
- text[0].text =newjson[i][0].ToString().Trim('"');
- text[1].text = double.Parse(newjson[i][1]).ToString("#,##0");
- sum+=50;
- copy.Add(buttonObj);
- }
-
- 日期合計金額.text=sum1.ToString("#,##0");
- buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
-
-
-
-
- int a = newjson.Count;
- panelRectTransform1.anchoredPosition = new Vector2(0, 0);
- if (a<13)
- {
- panelRectTransform1.sizeDelta= new Vector2(1000, 740);
- a=1000;
-
- }
- else
- {
- panelRectTransform1.sizeDelta= new Vector2(a*84, 740);
- a*=84;
-
- }
- BarChart barchart = bar.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<int> yAxisValue = new List<int>();
- for (int e = 0; e<newjson.Count; e++)
- {
- xAxisValue.Add(newjson[e][0].ToString().Trim('"'));
- double h1 = (double.Parse(newjson[e][1]));
- int hh1 = (int)Math.Round(h1);
- yAxisValue.Add(hh1);
- }
- 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";
- }
-
-
- public void DeletetextCopy()
- {
- foreach (GameObject i in copy)
- {
- Destroy(i);
- }
- copy.Clear();
-
- }
- public void DeletetextCopy1()
- {
- foreach (GameObject i in copy1)
- {
- Destroy(i);
- }
- copy1.Clear();
-
- }
- public void exit()
- {
- change_Secen(1);
- }
- public void change_Secen(int _screenNum)
- {
- //Main.Global.判斷是否第一次=true;
- SceneManager.LoadScene(_screenNum);
- }
- }
-
|