using System; using System.Collections.Generic; namespace Shared.SimpleControl.Phone { public class UserSensorHistoryPage :FrameLayout { public UserSensorHistoryPage () { } public void ShowPage(Common sensor) { #if DEBUG //UserConfig.Instance.GatewayMAC = "00005AF30A845F00"; #endif string unitText = "PM2.5"; string titleText = ""; switch (sensor.Type) { case DeviceType.SensorPM25: titleText = "PM2.5"; unitText = @"μg/m³"; break; case DeviceType.SensorCO2: titleText = "CO2"; unitText = "ppm"; break; case DeviceType.SensorTVOC: titleText = "TVOC"; unitText = "ppm"; break; case DeviceType.SensorTemperature: titleText = Language.StringByID (R.MyInternationalizationString.Temp); unitText = "°"; break; case DeviceType.SensorHumidity: titleText = Language.StringByID (R.MyInternationalizationString.Humidity); unitText = "%"; break; } List revertData = new List (); this.BackgroundColor = SkinStyle.Current.MainColor; #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.MainColor }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = titleText +" " + Language.StringByID(R.MyInternationalizationString.DataHistory), //TextID = R.MyInternationalizationString.SetPush, TextColor = SkinStyle.Current.TextColor1, TextSize = 19, }; topView.AddChidren (title); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (logo); var back = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { (Parent as PageLayout).PageIndex -= 1; }; #endregion FrameLayout bodyView = new FrameLayout () { Y = topView.Bottom, Height = Application.GetRealHeight (Application.DesignHeight -126), BackgroundColor = SkinStyle.Current.ViewColor, }; AddChidren (bodyView); FrameLayout timeView = new FrameLayout () { X = Application.GetRealWidth(20), Height = Application.GetRealHeight (200), Width = Application.GetRealWidth (600), }; bodyView.AddChidren (timeView); Button btnYear = new Button () { Y = Application.GetRealHeight (50), Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (80), BorderColor = SkinStyle.Current.BorderColor, BorderWidth = 1, Radius = 1, TextID = R.MyInternationalizationString.Year, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.SelectedColor, }; timeView.AddChidren (btnYear); Button btnMonth = new Button () { X = btnYear.Right, Y = Application.GetRealHeight (50), Width = Application.GetRealWidth(150), Height = Application.GetRealHeight (80), BorderColor = SkinStyle.Current.BorderColor, BorderWidth = 1, Radius = 1, Text = GetMonthText(DateTime.Now.Month), TextAlignment = TextAlignment.Center, TextColor= SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.SelectedColor, }; timeView.AddChidren (btnMonth); Button btnDay = new Button () { X = btnMonth.Right, Y = Application.GetRealHeight (50), Width = Application.GetRealWidth (150), Height = Application.GetRealHeight(80), BorderColor = SkinStyle.Current.BorderColor, BorderWidth = 1, Radius = 1, TextID = R.MyInternationalizationString.CurDay, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.SelectedColor, }; timeView.AddChidren (btnDay); Button btnTime = new Button () { X = btnDay.Right, Y = Application.GetRealHeight (50), Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (80), BorderColor = SkinStyle.Current.BorderColor, BorderWidth = 1, Radius = 1, TextID = R.MyInternationalizationString.Days7, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.SelectedColor, }; timeView.AddChidren (btnTime); FrameLayout chartView = new FrameLayout () { Y = Application.GetRealHeight(200), Height = Application.GetRealHeight(600), }; bodyView.AddChidren (chartView); MyEchartsView myEchartsView = new MyEchartsView (); chartView.AddChidren (myEchartsView); Random random = new Random (); List xstrings = new List (); List ystrings = new List (); btnMonth.BorderColor = SkinStyle.Current.SelectedColor; btnMonth.IsSelected = true; btnDay.BorderColor = btnTime.BorderColor = SkinStyle.Current.BorderColor; btnDay.IsSelected = btnDay.IsSelected = false; btnYear.MouseUpEventHandler += (df, fd) => { xstrings.Clear (); ystrings.Clear (); btnYear.BorderColor = SkinStyle.Current.SelectedColor; btnYear.IsSelected = true; btnMonth.BorderColor = btnDay.BorderColor = btnTime.BorderColor = SkinStyle.Current.BorderColor; btnMonth.IsSelected = btnDay.IsSelected = btnTime.IsSelected = false; MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var requestObj = new SensorPushHistory () { SubnetID = sensor.SubnetID, DeviceID = sensor.DeviceID, LargeType = sensor.BigClass, SmallType = sensor.MinClass, QueryType = QueryType.NowYear, LoopID = 1, NowMonth = 0, MAC = UserConfig.Instance.GatewayMAC }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps ("GetSensorPushHistory", requestJson); if (revertObj != null) { Application.RunOnMainThread (() => { if (revertObj.StateCode == "SUCCESS") { revertData = Newtonsoft.Json.JsonConvert.DeserializeObject> (revertObj.ResponseData.ToString ()); if (revertData.Count == 0) { ystrings.AddRange (new List () { "0" }); xstrings.AddRange (new List () { "无数据" }); } int ass = 0; for (int i = 0; i < revertData.Count; i++) { if (revertData [i].TargetValue.ToString () == "NaN") { ass = 0; } else { ass = Convert.ToInt32 (revertData [i].TargetValue); } xstrings.Add (revertData [i].CreatedOnUtc.ToLocalTime ().Month.ToString ()); ystrings.Add (ass.ToString ()); //xstrings.AddRange (new List () { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }); //ystrings.AddRange (new List () { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }); } myEchartsView.Show (unitText, xstrings.ToArray (), ystrings.ToArray ()); } }); } else { ystrings.AddRange (new List () { "0" }); xstrings.AddRange (new List () { "无数据" }); myEchartsView.Show (unitText, xstrings.ToArray (), ystrings.ToArray ()); } } catch (Exception ex) { Console.WriteLine (ex.ToString ()); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; btnMonth.MouseUpEventHandler += (df, fd) => { xstrings.Clear (); ystrings.Clear (); btnMonth.BorderColor = SkinStyle.Current.SelectedColor; btnMonth.IsSelected = true; btnYear.IsSelected = btnDay.IsSelected = btnDay.IsSelected = false; btnYear.BorderColor = btnDay.BorderColor = btnTime.BorderColor = SkinStyle.Current.BorderColor; Dialog dialogChooseMonth = new Dialog (); var chooseMonthView = new FrameLayout () { BackgroundColor = SkinStyle.Current.Black50Transparent, }; dialogChooseMonth.AddChidren (chooseMonthView); chooseMonthView.MouseUpEventHandler += (ddfd, fdfd) => { dialogChooseMonth.Close (); }; VerticalScrolViewLayout chooseMothView = new VerticalScrolViewLayout () { Y = Application.GetRealHeight (636), Height = Application.GetRealHeight(500), BackgroundColor = SkinStyle.Current.DialogColor, }; chooseMonthView.AddChidren (chooseMothView); for (int ii = 1; ii < DateTime.Now.Month+1; ii++) { Button btn = new Button () { Height = Application.GetRealHeight (100), TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor, Tag = ii }; btn.Text = GetMonthText (ii); chooseMothView.AddChidren (btn); btn.MouseUpEventHandler += (dff, ffd) => { chooseMothView.RemoveAll (); chooseMothView.RemoveFromParent (); dialogChooseMonth.Close (); btnMonth.Text = ((Button)dff).Text; MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var requestObj = new SensorPushHistory () { SubnetID = sensor.SubnetID, DeviceID = sensor.DeviceID, LargeType = sensor.BigClass, SmallType = sensor.MinClass, QueryType = QueryType.NowMonth, LoopID = 1, NowMonth = Convert.ToInt32 (((Button)dff).Tag), MAC = UserConfig.Instance.GatewayMAC }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps ("GetSensorPushHistory", requestJson); if (revertObj != null) { Application.RunOnMainThread (() => { if (revertObj.StateCode == "SUCCESS") { revertData = Newtonsoft.Json.JsonConvert.DeserializeObject> (revertObj.ResponseData.ToString ()); if (revertData.Count == 0) { ystrings.AddRange (new List () { "0" }); xstrings.AddRange (new List () { "无数据" }); } int ass = 0; for (int i = 0; i < revertData.Count; i++) { if (revertData [i].TargetValue.ToString () == "NaN") { ass = 0; } else { ass = Convert.ToInt32 (revertData [i].TargetValue); } xstrings.Add (revertData [i].CreatedOnUtc.ToLocalTime ().Day.ToString ()); ystrings.Add (ass.ToString ()); } myEchartsView.Show (unitText, xstrings.ToArray (), ystrings.ToArray ()); } }); } else { ystrings.AddRange (new List () { "0" }); xstrings.AddRange (new List () { "无数据" }); myEchartsView.Show (unitText, xstrings.ToArray (), ystrings.ToArray ()); } } catch (Exception ex) { Console.WriteLine (ex.ToString ()); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; Button btnLine = new Button (){ BackgroundColor = SkinStyle.Current.Black50Transparent, Height = 1 }; chooseMothView.AddChidren (btnLine); } dialogChooseMonth.Show (); }; btnDay.MouseUpEventHandler += (df, fd) => { xstrings.Clear (); ystrings.Clear (); btnDay.BorderColor = SkinStyle.Current.SelectedColor; btnDay.IsSelected = true; btnYear.BorderColor = btnMonth.BorderColor = btnTime.BorderColor = SkinStyle.Current.BorderColor; btnYear.IsSelected = btnMonth.IsSelected = btnTime.IsSelected = false; MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var requestObj = new SensorPushHistory () { SubnetID = sensor.SubnetID, DeviceID = sensor.DeviceID, LargeType = sensor.BigClass, SmallType = sensor.MinClass, QueryType = QueryType.NowDay, LoopID = 1, NowMonth = 0, MAC = UserConfig.Instance.GatewayMAC }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps ("GetSensorPushHistory", requestJson); if (revertObj != null) { Application.RunOnMainThread (() => { if (revertObj.StateCode == "SUCCESS") { revertData = Newtonsoft.Json.JsonConvert.DeserializeObject> (revertObj.ResponseData.ToString ()); if (revertData.Count == 0) { ystrings.AddRange (new List () { "0" }); xstrings.AddRange (new List () { "无数据" }); } int ass = 0; for (int i = 0; i < revertData.Count; i++) { if (revertData [i].TargetValue.ToString () == "NaN") { ass = 0; } else { ass = Convert.ToInt32 (revertData [i].TargetValue); } xstrings.Add (revertData [i].CreatedOnUtc.Hour.ToString ()); ystrings.Add (ass.ToString ()); } myEchartsView.Show (unitText, xstrings.ToArray (), ystrings.ToArray ()); } }); } else { ystrings.AddRange (new List () { "0" }); xstrings.AddRange (new List () { "无数据" }); myEchartsView.Show (unitText, xstrings.ToArray (), ystrings.ToArray ()); } } catch (Exception ex) { Console.WriteLine (ex.ToString ()); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; Action action = () => { xstrings.Clear (); ystrings.Clear (); btnTime.BorderColor = SkinStyle.Current.SelectedColor; btnTime.IsSelected = true; btnYear.BorderColor = btnMonth.BorderColor = btnDay.BorderColor = SkinStyle.Current.BorderColor; btnYear.IsSelected = btnMonth.IsSelected = btnDay.IsSelected = false; MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var requestObj = new SensorPushHistory () { SubnetID = sensor.SubnetID, DeviceID = sensor.DeviceID, LargeType = sensor.BigClass, SmallType = sensor.MinClass, QueryType = QueryType.LatelySevenDay, LoopID = 1, NowMonth = 0, MAC = UserConfig.Instance.GatewayMAC }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps ("GetSensorPushHistory", requestJson); if (revertObj != null) { Application.RunOnMainThread (() => { if (revertObj.StateCode == "SUCCESS") { revertData = Newtonsoft.Json.JsonConvert.DeserializeObject> (revertObj.ResponseData.ToString ()); if (revertData.Count == 0) { ystrings.AddRange (new List () { "0" }); xstrings.AddRange (new List () { "无数据" }); } int ass = 0; for (int i = 0; i < revertData.Count; i++) { if (revertData [i].TargetValue.ToString () == "NaN") { ass = 0; } else { ass = Convert.ToInt32 (revertData [i].TargetValue); } xstrings.Add (revertData [i].CreatedOnUtc.ToLocalTime ().ToString ("MM/dd"));//.ToString ("ddd", new System.Globalization.CultureInfo ("zh-cn"))); ystrings.Add (ass.ToString ()); } myEchartsView.Show (unitText, xstrings.ToArray (), ystrings.ToArray ()); } }); } else { ystrings.AddRange (new List () { "0" }); xstrings.AddRange (new List () { "无数据" }); myEchartsView.Show (unitText, xstrings.ToArray (), ystrings.ToArray ()); } } catch (Exception ex) { Console.WriteLine (ex.ToString ()); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; btnTime.MouseUpEventHandler += (df, fd) => { action (); }; action (); } string GetMonthText (int InMonth) { string strReturn = ""; if (Language.CurrentLanguage == "English") { string strParaMonthn = "Jan._Feb._Mar._Apr._May_Jun._Jul._Aug._Sep._Oct._Nov._Dec."; string [] strSubMonth = strParaMonthn.Split ("_".ToCharArray ()); strReturn = strSubMonth [InMonth - 1]; } else { strReturn = InMonth + " 月"; } return strReturn; } } }