| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 | 
							- using System;
 
- using System.Collections;
 
- using System.Collections.Generic;
 
- using System.Threading.Tasks;
 
- using Best.HTTP.JSON;
 
- using Bitsplash.DatePicker;
 
- using Newtonsoft.Json;
 
- using UnityEngine;
 
- using UnityEngine.UI;
 
- using XCharts.Runtime;
 
- public class WaterTrendPanel : MonoBehaviour
 
- {
 
-     public LineChart _LineChart;
 
-     public Text nameText;
 
-     public GameObject listItemOri;
 
-     public List<GameObject> listObj = new List<GameObject>();
 
-     public Button closeButton;
 
-     public string currentStcd;
 
-     public string currentName;
 
-     public Transform listRoot;
 
-     public DatePickerDropDownTextMeshPro DatePicker_Start;
 
-     public DatePickerDropDownTextMeshPro DatePicker_End;
 
-     public string startDateStr = "";
 
-     public string endDateStr = "";
 
-     public Button lineChartBtn;
 
-     public Button infoBtn;
 
-     public RectTransform lineChartPanel;
 
-     public RectTransform infoPanel;
 
-     public int currentType;
 
-     public Text typeTitle;
 
-     public Text idText;
 
-     public Text stnmText;
 
-     public Text stcdText;
 
-     public Text stlcText;
 
-     public Text sttpText;
 
-     public Text addvcdText;
 
-     public Text bsnmText;
 
-     public Text hnnmText;
 
-     public Text rvnmText;
 
-     public Text lgtdText;
 
-     public Text lttdText;
 
-     public Text dtmnmText;
 
-     public Text dtmelText;
 
-     public Text atcunitText;
 
-     public Text localityText;
 
-     public Text frgrdText;
 
-     public Text usflText;
 
-     public Button searchButton;
 
-     public GameObject threePanel;
 
-     public GameObject bythreePanel;
 
-     public GameObject taokouthreePanel;
 
-     public void Init()
 
-     {
 
-         _LineChart = this.transform.Find("linePanel/LineChart").GetComponent<LineChart>();
 
-         listRoot = this.transform.Find("linePanel/ScrollView/Viewport/Content").transform;
 
-         closeButton = this.transform.Find("CloseButton").GetComponent<Button>();
 
-         nameText = this.transform.Find("nameText").GetComponent<Text>();
 
-         closeButton.onClick.AddListener(() => {
 
-             print(111);
 
-             Hide(); 
 
-         });
 
-     }
 
-     private void Awake()
 
-     {
 
-         // // Get today's date
 
-         // DateTime today = DateTime.Today;
 
-         //
 
-         // // Get the date 3 months ago
 
-         // DateTime startDate = today.AddMonths(-3);
 
-         //
 
-         // // Format the dates to string
 
-         // startDateStr = startDate.ToString("yyyy-MM-dd");
 
-         // endDateStr = today.ToString("yyyy-MM-dd");
 
-         DatePicker_Start = this.transform.Find("linePanel/DatePicker_Start").GetComponent<DatePickerDropDownTextMeshPro>();
 
-         DatePicker_End = this.transform.Find("linePanel/DatePicker_End").GetComponent<DatePickerDropDownTextMeshPro>();
 
-         // DatePicker_Start.SetLabelText(startDateStr);
 
-         // DatePicker_End.SetLabelText(endDateStr);
 
-         lineChartBtn.onClick.AddListener(() =>
 
-         {
 
-             if (lineChartBtn.GetComponent<CanvasGroup>().alpha < 1)
 
-             {
 
-                 ChangePanel(0);
 
-                 ShowTrend(currentStcd, currentName,currentType);
 
-             }
 
-         });
 
-         infoBtn.onClick.AddListener(() =>
 
-         {
 
-             if (infoBtn.GetComponent<CanvasGroup>().alpha < 1)
 
-             {
 
-                 ChangePanel(1);
 
-                 ShowInfo();
 
-             }
 
-         });
 
-         searchButton.onClick.AddListener(() =>
 
-         {
 
-             ShowTrend(currentStcd, currentName, currentType);
 
-         });
 
-     }
 
-     private void Start()
 
-     {
 
-         DatePicker_Start.GetDateString += (string dateStr) =>
 
-         {
 
-             startDateStr = dateStr;
 
-             CheckDate();
 
-         };
 
-         DatePicker_End.GetDateString += (string dateStr) =>
 
-         {
 
-             endDateStr = dateStr;
 
-             CheckDate();
 
-         };
 
-     }
 
-     public void CheckDate()
 
-     {
 
-         if (!startDateStr.Equals("") && !endDateStr.Equals(""))
 
-         {
 
-             var startD = DateTime.ParseExact(startDateStr, "yyyy-MM-dd", null);
 
-             var endD = DateTime.ParseExact(endDateStr, "yyyy-MM-dd", null);
 
-             var disD = endD - startD;
 
-             Debug.Log(disD.TotalDays);
 
-             if (disD.TotalDays > 183)
 
-             {
 
-                 Debug.Log("时间间隔大于6个月");
 
-             }
 
-         }
 
-     }
 
-     /// <summary>
 
-     /// 获取时间范围内的趋势图
 
-     /// </summary>
 
-     /// <param name="type"></param>
 
-     /// <param name="gid"></param>
 
-     /// <param name="sid"></param>
 
-     /// <param name="startTime"></param>
 
-     /// <param name="endTime"></param>
 
-     public async Task GetTrend(int type, string gid, string sid)
 
-     {
 
-         string getJsonStr = await HttpHelper._Instance.GetDeviceTrend(type, gid, sid, startDateStr, endDateStr);
 
-         try
 
-         {
 
-             Debug.Log("GetTrend requestData:" + getJsonStr);
 
-             DeviceTrendRequest requestData = JsonConvert.DeserializeObject<DeviceTrendRequest>(getJsonStr);
 
-             XAxis tempXaxis = _LineChart.GetChartComponent<XAxis>();
 
-             tempXaxis.data.Clear();
 
-             for (int i = 0; i < requestData.data.Length; i++)
 
-             {
 
-                 tempXaxis.AddData(requestData.data[i].timeGroup);
 
-             }
 
-             var tempSeries = _LineChart.series;
 
-             SerieData[] tempDatas = new SerieData[requestData.data.Length];
 
-             for (int i = 0; i < tempDatas.Length; i++)
 
-             {
 
-                 tempDatas[i] = new SerieData();
 
-                 tempDatas[i].data = new List<double>();
 
-                 tempDatas[i].data.Add(i);
 
-                 tempDatas[i].data.Add(float.Parse(requestData.data[i].r1));
 
-             }
 
-             tempSeries[0].data.Clear();
 
-             tempSeries[0].data.AddRange(tempDatas);
 
-         }
 
-         catch (Exception e)
 
-         {
 
-             Debug.Log(e.ToString());
 
-             throw;
 
-         }
 
-     }
 
-     public void ChangePanel(int panelIndex = 0)
 
-     {
 
-         if (panelIndex == 0)
 
-         {
 
-             lineChartPanel.gameObject.SetActive(true);
 
-             infoPanel.gameObject.SetActive(false);
 
-             lineChartBtn.GetComponent<CanvasGroup>().alpha = 1;
 
-             infoBtn.GetComponent<CanvasGroup>().alpha = 0.5f;
 
-         }
 
-         else
 
-         {
 
-             lineChartPanel.gameObject.SetActive(false);
 
-             infoPanel.gameObject.SetActive(true);
 
-             lineChartBtn.GetComponent<CanvasGroup>().alpha = 0.5f;
 
-             infoBtn.GetComponent<CanvasGroup>().alpha = 1;
 
-         }
 
-     }
 
-     public async Task ShowTrend(string stcd, string name,int type)
 
-     {
 
-         var tempSeries = _LineChart.series;
 
-         tempSeries[0].data.Clear();
 
-         if (listObj.Count > 0)
 
-         {
 
-             GameObject[] deleteObjs = listObj.ToArray();
 
-             for (int i = 0; i < deleteObjs.Length; i++)
 
-             {
 
-                 Destroy(deleteObjs[i]);
 
-             }
 
-         }
 
-         listObj.Clear();
 
-         
 
-         string endTime = DateTime.Now.ToString("yyyy-MM-dd");
 
-         string startTime = DateTime.Now.AddMonths(-3).ToString("yyyy-MM-dd");
 
-         startDateStr = startTime;
 
-         endDateStr = endTime;
 
-         DatePicker_Start.SetLabelText(startTime);
 
-         DatePicker_End.SetLabelText(endTime);
 
-         
 
-         currentType = type;
 
-         if (type == 0)
 
-         {
 
-             threePanel.gameObject.SetActive(true);
 
-             typeTitle.text = "站点水位趋势";
 
-         }
 
-         else {
 
-             threePanel.gameObject.SetActive(false);
 
-             typeTitle.text = "站点降雨趋势";
 
-         }
 
-         currentStcd = stcd;
 
-         Debug.Log(stcd);
 
-         currentName = name;
 
-         ChangePanel(0);
 
-         name = name.Replace(" ", "");
 
-         nameText.text = $"站点:{name}";
 
-         this.gameObject.SetActive(true);
 
-         string chartJsonStr = "";
 
-         if (type == 0) {
 
-             _LineChart.GetChartComponent<YAxis>().axisName.name = "水位(m)";
 
-             chartJsonStr = await HttpHelper._Instance.GetWaterTrend_Chart(stcd, startDateStr, endDateStr);
 
-         }
 
-         else{
 
-             _LineChart.GetChartComponent<YAxis>().axisName.name = "降雨量(mm)";
 
-             chartJsonStr = await HttpHelper._Instance.GetDropTrend_Chart(stcd, startDateStr, endDateStr);
 
-         }
 
-         if (stcd == "61017810")
 
-         {
 
-             bythreePanel.gameObject.SetActive(true);
 
-             taokouthreePanel.gameObject.SetActive(false);
 
-         }
 
-         else {
 
-             bythreePanel.gameObject.SetActive(false);
 
-             taokouthreePanel.gameObject.SetActive(true);
 
-         }
 
-         SetChartLine(chartJsonStr);
 
-         StartCoroutine(CreatList(chartJsonStr));
 
-     }
 
-     public async Task ShowInfo()
 
-     {
 
-         idText.text = "-";
 
-         stnmText.text = "-";
 
-         stcdText.text = "-";
 
-         stlcText.text = "-";
 
-         sttpText.text = "-";
 
-         addvcdText.text = "-";
 
-         bsnmText.text = "-";
 
-         hnnmText.text = "-";
 
-         rvnmText.text = "-";
 
-         lgtdText.text = "-";
 
-         lttdText.text = "-";
 
-         dtmnmText.text = "-";
 
-         dtmelText.text = "-";
 
-         atcunitText.text = "-";
 
-         localityText.text = "-";
 
-         frgrdText.text = "-";
 
-         usflText.text = "-";
 
-         string infoJsonStr = await HttpHelper._Instance.GetWaterTrend_Info(currentStcd);
 
-         Debug.Log(infoJsonStr);
 
-         WaterTrendData_Info waterTrendData_Info = JsonConvert.DeserializeObject<WaterTrendData_Info>(infoJsonStr);
 
-         Debug.Log(waterTrendData_Info);
 
-         idText.text = waterTrendData_Info.data.id;
 
-         stnmText.text = waterTrendData_Info.data.stnm;
 
-         stcdText.text = waterTrendData_Info.data.stcd;
 
-         stlcText.text = waterTrendData_Info.data.stlc;
 
-         sttpText.text = waterTrendData_Info.data.sttp;
 
-         addvcdText.text = waterTrendData_Info.data.addvcd;
 
-         bsnmText.text = waterTrendData_Info.data.bsnm;
 
-         hnnmText.text = waterTrendData_Info.data.hnnm;
 
-         rvnmText.text = waterTrendData_Info.data.rvnm;
 
-         lgtdText.text = waterTrendData_Info.data.lgtd;
 
-         lttdText.text = waterTrendData_Info.data.lttd;
 
-         dtmnmText.text = waterTrendData_Info.data.dtmnm;
 
-         dtmelText.text = waterTrendData_Info.data.dtmel;
 
-         atcunitText.text = waterTrendData_Info.data.atcunit;
 
-         localityText.text = waterTrendData_Info.data.locality;
 
-         frgrdText.text = waterTrendData_Info.data.frgrd;
 
-         usflText.text = waterTrendData_Info.data.usfl;
 
-     }
 
-     public void Hide()
 
-     {
 
-         this.gameObject.SetActive(false);
 
-     }
 
-     public void SetChartLine(string jsonData)
 
-     {
 
-         WaterTrendData_Chart tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<WaterTrendData_Chart>(jsonData);
 
-         tempData.data.Reverse();
 
-         XAxis tempXaxis = _LineChart.GetChartComponent<XAxis>();
 
-         tempXaxis.data.Clear();
 
-         for (int i = 0; i < tempData.data.Count; i++)
 
-         {
 
-             tempXaxis.AddData(tempData.data[i].time);
 
-         }
 
-         var tempSeries = _LineChart.series;
 
-         tempSeries[0].serieName = "水位(m)";
 
-         SerieData[] tempDatas = new SerieData[tempData.data.Count];
 
-         for (int i = 0; i < tempDatas.Length; i++)
 
-         {
 
-             tempDatas[i] = new SerieData();
 
-             tempDatas[i].data = new List<double>();
 
-             tempDatas[i].data.Add(i);
 
-             string valueTex = tempData.data[i].value;
 
-             if (valueTex == "-") {
 
-                 valueTex = "-1";
 
-             }
 
-             double tempValue = double.Parse(float.Parse(valueTex).ToString("0.00"));
 
-             //if (tempValue < 0) {
 
-             //    tempValue = 24.99f;
 
-             //}
 
-             tempDatas[i].data.Add(tempValue);
 
-         }
 
-         tempSeries[0].data.Clear();
 
-         tempSeries[0].data.AddRange(tempDatas);
 
-     }
 
-     IEnumerator CreatList(string jsonData)
 
-     {
 
-         var wait = new WaitForEndOfFrame();
 
-         WaterTrendData_Chart tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<WaterTrendData_Chart>(jsonData);
 
-         int creatCount = 0;
 
-         for (int i = 0; i < tempData.data.Count; i++)
 
-         {
 
-             GameObject tempObj = Instantiate(listItemOri, listRoot);
 
-             tempObj.transform.Find("id").GetComponent<Text>().text = $"{i + 1}";
 
-             tempObj.transform.Find("time").GetComponent<Text>().text = $"{tempData.data[i].time}";
 
-             tempObj.transform.Find("value").GetComponent<Text>().text = $"{tempData.data[i].value}";
 
-             string dirStr = "-";
 
-             if (tempData.data[i].trend == 1)
 
-             {
 
-                 dirStr = "↑";
 
-                 tempObj.transform.Find("trend").GetComponent<Text>().color = Color.red;
 
-             }
 
-             else if (tempData.data[i].trend == 2)
 
-             {
 
-                 dirStr = "→";
 
-                 tempObj.transform.Find("trend").GetComponent<Text>().color = Color.blue;
 
-             }
 
-             else if (tempData.data[i].trend == 3)
 
-             {
 
-                 dirStr = "↓";
 
-                 tempObj.transform.Find("trend").GetComponent<Text>().color = Color.green;
 
-             }
 
-             else
 
-             {
 
-                 dirStr = "-";
 
-                 tempObj.transform.Find("trend").GetComponent<Text>().color = Color.white;
 
-             }
 
-             tempObj.transform.Find("trend").GetComponent<Text>().text = $"{dirStr}";
 
-             listObj.Add(tempObj);
 
-             creatCount++;
 
-             if (creatCount >= 10)
 
-             {
 
-                 creatCount = 0;
 
-                 yield return wait;
 
-             }
 
-         }
 
-     }
 
- }
 
- [Serializable]
 
- public class WaterTrendData_Chart
 
- {
 
-     public int code;
 
-     public string msg;
 
-     public List<WaterCharData> data;
 
- }
 
- [Serializable]
 
- public class WaterCharData
 
- {
 
-     public string time;
 
-     public int trend;
 
-     public string value;
 
- }
 
- [Serializable]
 
- public class WaterTrendData_Info
 
- {
 
-     public int code;
 
-     public string msg;
 
-     public WaterInfoData data;
 
- }
 
- [Serializable]
 
- public class WaterInfoData
 
- {
 
-     public string id { get; set; }
 
-     public string addvcd { get; set; }
 
-     public string atcunit { get; set; }
 
-     public string bsnm { get; set; }
 
-     public string dtmel { get; set; }
 
-     public string dtmnm { get; set; }
 
-     public string frgrd { get; set; }
 
-     public string hnnm { get; set; }
 
-     public string lgtd { get; set; }
 
-     public string locality { get; set; }
 
-     public string lttd { get; set; }
 
-     public string rvnm { get; set; }
 
-     public string stcd { get; set; }
 
-     public string stlc { get; set; }
 
-     public string stnm { get; set; }
 
-     public string sttp { get; set; }
 
-     public string usfl { get; set; }
 
- }
 
 
  |