Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

銷售報表.cs 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. using UnityEngine.Networking;
  7. using UnityEngine.EventSystems;
  8. using System.Text.RegularExpressions;
  9. using System.Data.SqlClient;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using TMPro;
  13. using System;
  14. using System.IO;
  15. using ZXing;
  16. using ZXing.QrCode;
  17. using System.Net;
  18. using System.Data;
  19. using SimpleJSON;
  20. using System.Linq;
  21. using System.ComponentModel;
  22. using System.Runtime.InteropServices;
  23. using System.Globalization;
  24. using XCharts.Runtime;
  25. public class 銷售報表 : MonoBehaviour
  26. {
  27. [SerializeField] GameObject 選擇頁面;
  28. [SerializeField] GameObject 主畫面;
  29. [SerializeField] GameObject p1;
  30. [SerializeField] GameObject p2;
  31. private bool isP1Active = true;
  32. [SerializeField] GameObject bar;
  33. [SerializeField] RectTransform panelRectTransform1;
  34. [SerializeField] GameObject bar1;
  35. [SerializeField] RectTransform panelRectTransform;
  36. private JSONArray newjson;
  37. [SerializeField] TextMeshProUGUI 標題;
  38. [SerializeField] TextMeshProUGUI 標題1;
  39. [SerializeField] TextMeshProUGUI 日期合計金額;
  40. private JSONNode 車種;
  41. private JSONNode 計算;
  42. [SerializeField] TextMeshProUGUI 車種合計數量;
  43. [SerializeField] TextMeshProUGUI 車種合計金額;
  44. public TMP_Dropdown 年;
  45. public TMP_Dropdown 月;
  46. public CanvasScaler canvasScaler;
  47. [SerializeField] GameObject 讀取面板;
  48. [SerializeField] TextMeshProUGUI 讀取;
  49. [SerializeField] GameObject 彈跳面板;
  50. [SerializeField] TextMeshProUGUI 彈跳文字;
  51. private string loadingText = "";
  52. private int dotCount = 0;
  53. public GameObject buttonPrefab;
  54. public Transform buttonParent;
  55. public GameObject buttonceneter;
  56. private List<GameObject> copy = new List<GameObject>();
  57. public GameObject buttonPrefab1;
  58. public Transform buttonParent1;
  59. public GameObject buttonceneter1;
  60. private List<GameObject> copy1 = new List<GameObject>();
  61. // Start is called before the first frame update
  62. void Start()
  63. {
  64. Screen.autorotateToPortrait = false;
  65. Screen.orientation = ScreenOrientation.Portrait;
  66. float rate = 1000.0f / 1600.0f;
  67. if (canvasScaler == null)
  68. {
  69. canvasScaler = GetComponent<CanvasScaler>();
  70. }
  71. if (Main.Global.rate>rate)
  72. {
  73. canvasScaler.matchWidthOrHeight = 1f;
  74. }
  75. else
  76. {
  77. canvasScaler.matchWidthOrHeight = 0f;
  78. }
  79. StartCoroutine(AnimateText());
  80. //讀取面板.SetActive(true);
  81. //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/GF_main.php?";
  82. //Main.Global.預設伺服器路徑="GF01";
  83. //Main.Global.狀態="保養維修";
  84. //Main.Global.可選擇車廠型式=false;
  85. if (Main.Global.可選擇車廠型式==true)
  86. {
  87. 選擇頁面.SetActive(true);
  88. 主畫面.SetActive(false);
  89. }
  90. else
  91. {
  92. Main.Global.狀態="保養維修";
  93. 選擇頁面.SetActive(false);
  94. 主畫面.SetActive(true);
  95. p1.SetActive(true);
  96. p2.SetActive(false);
  97. StartCoroutine(年份清單());
  98. }
  99. }
  100. public void 買賣()
  101. {
  102. Main.Global.狀態="車輛買賣";
  103. 選擇頁面.SetActive(false);
  104. 主畫面.SetActive(true);
  105. p1.SetActive(true);
  106. p2.SetActive(false);
  107. StartCoroutine(年份清單());
  108. }
  109. public void 保養()
  110. {
  111. Main.Global.狀態="保養維修";
  112. 選擇頁面.SetActive(false);
  113. 主畫面.SetActive(true);
  114. p1.SetActive(true);
  115. p2.SetActive(false);
  116. StartCoroutine(年份清單());
  117. }
  118. public void 變換()
  119. {
  120. isP1Active = !isP1Active;
  121. p1.SetActive(isP1Active);
  122. p2.SetActive(!isP1Active);
  123. }
  124. IEnumerator AnimateText()
  125. {
  126. string qqq = 讀取.text.ToString();
  127. while (true)
  128. {
  129. yield return new WaitForSeconds(0.5f);
  130. if (dotCount < 3)
  131. {
  132. loadingText += ".";
  133. dotCount++;
  134. }
  135. else
  136. {
  137. loadingText = "";
  138. dotCount = 0;
  139. }
  140. 讀取.text = qqq+loadingText;
  141. }
  142. }
  143. IEnumerator 年份清單()
  144. {
  145. 讀取面板.SetActive(true);
  146. 年.options.Clear();
  147. List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
  148. string strcon = "年份清單";
  149. string se = Main.Global.預設伺服器路徑;
  150. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
  151. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  152. yield return request.SendWebRequest();
  153. if (request.result == UnityWebRequest.Result.ConnectionError)
  154. {
  155. Debug.Log(request.error);
  156. yield break;
  157. }
  158. JSONNode json = JSON.Parse(request.downloadHandler.text);
  159. for (int i = 0; i < json.Count; i++)
  160. {
  161. string str = json[i].ToString().Trim('"');
  162. options.Add(new TMP_Dropdown.OptionData(str));
  163. }
  164. 年.AddOptions(options);
  165. DateTime currentDate = DateTime.Now;
  166. int index1 = 年.options.FindIndex(option => option.text == currentDate.Year.ToString());
  167. 年.value = index1;
  168. int index2 = 月.options.FindIndex(option => option.text == currentDate.Month.ToString());
  169. 月.value = index2;
  170. 年.onValueChanged.AddListener(delegate
  171. {
  172. StartCoroutine(銷售報表車種());
  173. });
  174. 月.onValueChanged.AddListener(delegate
  175. {
  176. StartCoroutine(銷售報表車種());
  177. });
  178. yield return StartCoroutine(銷售報表車種());
  179. }
  180. IEnumerator 銷售報表車種()
  181. {
  182. 讀取面板.SetActive(true);
  183. if (copy != null)
  184. {
  185. DeletetextCopy();
  186. }
  187. string strcon = "";
  188. if (Main.Global.狀態 == "車輛買賣")
  189. {
  190. strcon = "銷售報表車種1";
  191. }
  192. else
  193. {
  194. strcon = "銷售報表車種";
  195. }
  196. string pa= 年.options[年.value].text + 月.options[月.value].text;
  197. string pa1 = Main.Global.狀態;
  198. string se = Main.Global.預設伺服器路徑;
  199. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}", strcon, se,pa,pa1);
  200. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  201. yield return request.SendWebRequest();
  202. if (request.result == UnityWebRequest.Result.ConnectionError)
  203. {
  204. Debug.Log(request.error);
  205. yield break;
  206. }
  207. 車種 = JSON.Parse(request.downloadHandler.text);
  208. int sum = 2;
  209. double sum1 = 0;
  210. double sum2 = 0;
  211. for (int i = 0; i < 車種.Count; i++)
  212. {
  213. GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
  214. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  215. buttonObj.transform.SetParent(buttonParent, false);
  216. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  217. sum1+=double.Parse(車種[i][1]);
  218. sum2+=double.Parse(車種[i][2]);
  219. if (Main.Global.狀態 == "車輛買賣")
  220. {
  221. 標題1.text="廠牌";
  222. }
  223. else
  224. {
  225. 標題1.text="車型";
  226. }
  227. if (車種[i][0].ToString().Trim('"') == "")
  228. {
  229. text[0].text ="未填入車型";
  230. 車種[i][0] = "未填入車型";
  231. }
  232. else
  233. {
  234. text[0].text =車種[i][0].ToString().Trim('"');
  235. }
  236. text[1].text =車種[i][1].ToString().Trim('"');
  237. text[2].text = double.Parse(車種[i][2]).ToString("#,##0");
  238. sum+=50;
  239. copy.Add(buttonObj);
  240. }
  241. buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
  242. 車種合計數量.text =sum1.ToString("#,##0");
  243. 車種合計金額.text =sum2.ToString("#,##0");
  244. double sum3 = sum2 /sum1;
  245. int a = 車種.Count;
  246. panelRectTransform.anchoredPosition = new Vector2(0, 0);
  247. if (a<13)
  248. {
  249. panelRectTransform.sizeDelta= new Vector2(1000, 740);
  250. a=1000;
  251. }
  252. else
  253. {
  254. panelRectTransform.sizeDelta= new Vector2(a*84, 740);
  255. a*=84;
  256. }
  257. BarChart barchart = bar1.GetComponent<BarChart>();
  258. var gc = barchart.EnsureChartComponent<GridCoord>();
  259. gc.left =100;
  260. gc.right =20;
  261. gc.top =120;
  262. gc.bottom =80;
  263. barchart.SetSize(a, 740);
  264. var title = barchart.EnsureChartComponent<Title>();
  265. title.text = "";
  266. List<string> xAxisValue = new List<string>();
  267. List<int> yAxisValue = new List<int>();
  268. List<int> yAxisValue1 = new List<int>();
  269. for (int e = 0; e<車種.Count; e++)
  270. {
  271. xAxisValue.Add(車種[e][0].ToString().Trim('"'));
  272. double h1 = (double.Parse(車種[e][1])*sum3);
  273. int hh1 = (int)Math.Round(h1);
  274. yAxisValue.Add(hh1);
  275. double h2 = (double.Parse(車種[e][2]));
  276. int hh2 = (int)Math.Round(h2);
  277. yAxisValue1.Add(hh2);
  278. }
  279. barchart.RemoveData();
  280. barchart.AddSerie<Bar>("金額");
  281. foreach (int item in yAxisValue1)
  282. {
  283. barchart.AddData(0, item);
  284. }
  285. barchart.AddSerie<Line>("次數");
  286. foreach (int item in yAxisValue)
  287. {
  288. barchart.AddData(1, item);
  289. }
  290. foreach (var xValue in xAxisValue)
  291. {
  292. barchart.AddXAxisData(xValue);
  293. }
  294. Legend legend = barchart.EnsureChartComponent<Legend>();
  295. legend.show = true;
  296. legend.location =new Location() { align = Location.Align.TopLeft, top = 70, left =100 };
  297. //Tooltip tooltip = barchart.EnsureChartComponent<Tooltip>();
  298. //tooltip.show = true;
  299. //tooltip.fixedY=-100;
  300. //tooltip.numericFormatter="0,0";
  301. var yAxis = barchart.GetOrAddChartComponent<YAxis>();
  302. yAxis.axisLabel.numericFormatter="0,0";
  303. yield return StartCoroutine(銷售報表日期());
  304. 讀取面板.SetActive(false);
  305. }
  306. IEnumerator 銷售報表日期()
  307. {
  308. string strcon = "";
  309. string pa = "";
  310. if (Main.Global.狀態 == "車輛買賣")
  311. {
  312. if (月.options[月.value].text == "")
  313. {
  314. strcon = "銷售報表年1";
  315. pa =年.options[年.value].text;
  316. 標題.text ="月份";
  317. }
  318. else
  319. {
  320. strcon = "銷售報表日期1";
  321. pa = 年.options[年.value].text + 月.options[月.value].text;
  322. 標題.text ="日期";
  323. }
  324. }
  325. else
  326. {
  327. if (月.options[月.value].text == "")
  328. {
  329. strcon = "銷售報表年";
  330. pa =年.options[年.value].text;
  331. 標題.text ="月份";
  332. }
  333. else
  334. {
  335. strcon = "銷售報表日期";
  336. pa = 年.options[年.value].text + 月.options[月.value].text;
  337. 標題.text ="日期";
  338. }
  339. }
  340. string pa1 = Main.Global.狀態;
  341. string se = Main.Global.預設伺服器路徑;
  342. string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}", strcon, se, pa, pa1);
  343. UnityWebRequest request = UnityWebRequest.Get(strUrl);
  344. yield return request.SendWebRequest();
  345. if (request.result == UnityWebRequest.Result.ConnectionError)
  346. {
  347. Debug.Log(request.error);
  348. yield break;
  349. }
  350. 計算 = JSON.Parse(request.downloadHandler.text);
  351. if (copy1 != null)
  352. {
  353. DeletetextCopy1();
  354. }
  355. int sum = 2;
  356. double sum1 = 0;
  357. newjson = new JSONArray();
  358. if (月.options[月.value].text == "")
  359. {
  360. for (int i = 0; i < 12; i++)
  361. {
  362. string dayString = (i+1).ToString().PadLeft(2, '0');
  363. string str = 年.options[年.value].text+dayString;
  364. JSONNode newValue = new JSONObject();
  365. newValue["date"] = dayString;
  366. newValue["value"] = 0;
  367. for (int j = 0; j < 計算.Count; j++)
  368. {
  369. string str1 = 計算[j][0].ToString().Trim('"');
  370. if (str == str1)
  371. {
  372. newValue["value"] = double.Parse(計算[j][1]).ToString("#,##0");
  373. }
  374. }
  375. newjson.Add(newValue);
  376. }
  377. }
  378. else
  379. {
  380. int 年份 = int.Parse(年.options[年.value].text);
  381. int 月份 = int.Parse(月.options[月.value].text);
  382. int daysInMonth = DateTime.DaysInMonth(年份, 月份);
  383. for (int i = 0; i < daysInMonth; i++)
  384. {
  385. string dayString = (i+1).ToString().PadLeft(2, '0');
  386. string str = 年.options[年.value].text+月.options[月.value].text+dayString;
  387. JSONNode newValue = new JSONObject();
  388. newValue["date"] = dayString;
  389. newValue["value"] = 0;
  390. for (int j = 0; j < 計算.Count; j++)
  391. {
  392. string str1 = 計算[j][0].ToString().Trim('"');
  393. if (str == str1)
  394. {
  395. newValue["value"] = double.Parse(計算[j][1]).ToString("#,##0");
  396. }
  397. }
  398. newjson.Add(newValue);
  399. }
  400. }
  401. for (int i = 0; i < newjson.Count; i++)
  402. {
  403. GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
  404. buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
  405. buttonObj.transform.SetParent(buttonParent1, false);
  406. TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
  407. sum1+=double.Parse(newjson[i][1]);
  408. text[0].text =newjson[i][0].ToString().Trim('"');
  409. text[1].text = double.Parse(newjson[i][1]).ToString("#,##0");
  410. sum+=50;
  411. copy.Add(buttonObj);
  412. }
  413. 日期合計金額.text=sum1.ToString("#,##0");
  414. buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
  415. int a = newjson.Count;
  416. panelRectTransform1.anchoredPosition = new Vector2(0, 0);
  417. if (a<13)
  418. {
  419. panelRectTransform1.sizeDelta= new Vector2(1000, 740);
  420. a=1000;
  421. }
  422. else
  423. {
  424. panelRectTransform1.sizeDelta= new Vector2(a*84, 740);
  425. a*=84;
  426. }
  427. BarChart barchart = bar.GetComponent<BarChart>();
  428. var gc = barchart.EnsureChartComponent<GridCoord>();
  429. gc.left =100;
  430. gc.right =20;
  431. gc.top =120;
  432. gc.bottom =80;
  433. barchart.SetSize(a, 740);
  434. var title = barchart.EnsureChartComponent<Title>();
  435. title.text = "";
  436. List<string> xAxisValue = new List<string>();
  437. List<int> yAxisValue = new List<int>();
  438. for (int e = 0; e<newjson.Count; e++)
  439. {
  440. xAxisValue.Add(newjson[e][0].ToString().Trim('"'));
  441. double h1 = (double.Parse(newjson[e][1]));
  442. int hh1 = (int)Math.Round(h1);
  443. yAxisValue.Add(hh1);
  444. }
  445. barchart.RemoveData();
  446. barchart.AddSerie<Bar>("金額");
  447. foreach (int item in yAxisValue)
  448. {
  449. barchart.AddData(0, item);
  450. }
  451. foreach (var xValue in xAxisValue)
  452. {
  453. barchart.AddXAxisData(xValue);
  454. }
  455. Legend legend = barchart.EnsureChartComponent<Legend>();
  456. legend.show = true;
  457. legend.location =new Location() { align = Location.Align.TopLeft, top = 70, left =100 };
  458. Tooltip tooltip = barchart.EnsureChartComponent<Tooltip>();
  459. tooltip.show = true;
  460. tooltip.fixedY=-100;
  461. tooltip.numericFormatter="0,0";
  462. var yAxis = barchart.GetOrAddChartComponent<YAxis>();
  463. yAxis.axisLabel.numericFormatter="0,0";
  464. }
  465. public void DeletetextCopy()
  466. {
  467. foreach (GameObject i in copy)
  468. {
  469. Destroy(i);
  470. }
  471. copy.Clear();
  472. }
  473. public void DeletetextCopy1()
  474. {
  475. foreach (GameObject i in copy1)
  476. {
  477. Destroy(i);
  478. }
  479. copy1.Clear();
  480. }
  481. public void exit()
  482. {
  483. change_Secen(1);
  484. }
  485. public void change_Secen(int _screenNum)
  486. {
  487. //Main.Global.判斷是否第一次=true;
  488. SceneManager.LoadScene(_screenNum);
  489. }
  490. }