using System; using System.Collections.Generic; using Shared.SimpleControl.Phone.Music; namespace Shared.SimpleControl.Phone { public class UserSchedule : FrameLayout { VerticalScrolViewLayout bodyView; List timers; public UserSchedule() { BackgroundColor = SkinStyle.Current.MainColor; timers = new List (); } public void ShowPage () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (640), }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, TextID = R.MyInternationalizationString.Schedule, TextColor = SkinStyle.Current.TextColor1, TextSize = 19, }; topView.AddChidren (title); var back = new Button () { Height = Application.GetRealHeight (100), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { (Parent as PageLayout).PageIndex -= 1; }; var ItemButton = new Button () { Width = Application.GetRealWidth (55), Height = Application.GetRealHeight (55), UnSelectedImagePath = "Item/+.png", SelectedImagePath = "Item/+.png", X = Application.GetRealWidth (640 - 80), Y = Application.GetRealHeight (17), }; topView.AddChidren (ItemButton); ItemButton.MouseUpEventHandler += (sender, e) => { if (UserConfig.Instance.internetStatus == 0) { new Alert ("", "Unable to save data, please check the network.", "Close").Show (); return; } MainPage.Loading.Start ("Please wait..."); System.Threading.Tasks.Task.Run (() => { try { System.Threading.Thread.Sleep (100); Application.RunOnMainThread (() => { var tt = new Timer () { TimeZone = Convert.ToInt32 (DateTime.Now.ToString ("%z")), RoomName = "ALL", Periodicity = ((int)DateTime.Now.DayOfWeek).ToString (), TimerType = TimerType.Week, TimerName = "Schedule " + timers.Count.ToString(), ExecutionTime = DateTime.Now.ToString ("HH:mm") }; Action refLoad = (obj) => { timers.Add (obj); initSchedule (obj); }; var scheduleShowView = new AddSchedule (refLoad); UserMiddle.SettingPageView.AddChidren (scheduleShowView); scheduleShowView.ShowPage (tt,timers,false); UserMiddle.SettingPageView.PageIndex = 2; }); }catch(Exception ex){ Console.WriteLine (ex.Message); } finally{ Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; #endregion bodyView = new VerticalScrolViewLayout () { Y= topView.Bottom, Height = Application.GetRealHeight(1136 - 126), BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (bodyView); InitScheduleView (); } void InitScheduleView () { MainPage.Loading.Start ("Please wait..."); System.Threading.Tasks.Task.Run (() => { try { var requestObj = new Timer () { RegionID = UserConfig.Instance.CurrentRegion.RegionID }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps ("GetTimerList", requestJson); if (revertObj.StateCode == "SUCCESS") { timers = Newtonsoft.Json.JsonConvert.DeserializeObject> (revertObj.ResponseData.ToString ()); foreach (var schedule in timers) { initSchedule (schedule); } } } catch (Exception ex) { Console.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); } void reinitSchedule(Timer schedule) { for (int i = 0;i< bodyView.ChildrenCount;i++){ var view = bodyView.GetChildren (i); if(view.GetType() == typeof(RowLayout)){ var rowView = view as RowLayout; if (rowView.GetTagByKey("guid").ToString () == schedule.Guid) { for (int j = 0; j < rowView.ChildrenCount; j++) { var viewChilren = rowView.GetChildren (j); if (viewChilren.GetType () == typeof (Button)) { var btn = viewChilren as Button; if(btn.Tag!= null){ switch (btn.Tag.ToString ()) { case "btnScheduleName": btn.Text = schedule.TimerName; break; case "btnScheduleRoomName": btn.Text = schedule.RoomName; break; case "btnScheduleTime": btn.Text = schedule.ExecutionTime; break; case "btnScheduleDay": btn.Text = ""; if (schedule.Periodicity.Contains ("0")) { btn.Text += "Sun "; } if (schedule.Periodicity.Contains ("1")) { btn.Text += "Mon "; } if (schedule.Periodicity.Contains ("2")) { btn.Text += "Tues "; } if (schedule.Periodicity.Contains ("3")) { btn.Text += "Wed "; } if (schedule.Periodicity.Contains ("4")) { btn.Text += "Thur "; } if (schedule.Periodicity.Contains ("5")) { btn.Text += "Fri "; } if (schedule.Periodicity.Contains ("6")) { btn.Text += "Sat "; } break; } } } } } } } } void initSchedule(Timer schedule) { Application.RunOnMainThread (() => { var rowView = new RowLayout () { Height = Application.GetRealHeight (180), }; bodyView.AddChidren (rowView); rowView.AddTag ("guid", schedule.Guid); var btnScheduleName = new Button () { X = Application.GetRealWidth (30), Height = Application.GetRealHeight (60), Width = Application.GetRealWidth (290), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, Text = schedule.TimerName, TextSize = 14, Tag = "btnScheduleName", }; rowView.AddChidren (btnScheduleName); btnScheduleName.AddTag ("guid", schedule.Guid); var btnScheduleRoomName = new Button () { X = btnScheduleName.Right, Height = Application.GetRealHeight (60), Width = Application.GetRealWidth (290), TextAlignment = TextAlignment.CenterRight, TextColor = SkinStyle.Current.TextColor1, Text = schedule.RoomName, Tag = "btnScheduleRoomName", }; rowView.AddChidren (btnScheduleRoomName); btnScheduleRoomName.AddTag ("guid", schedule.Guid); var btnScheduleTime = new Button () { X = Application.GetRealWidth (30), Y = Application.GetRealHeight (60), Height = Application.GetRealHeight (60), Width = Application.GetRealWidth (150), Text = schedule.ExecutionTime, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.CenterLeft, TextSize = 24, Tag = "btnScheduleTime", }; rowView.AddChidren (btnScheduleTime); btnScheduleTime.AddTag ("guid", schedule.Guid); var btnScheduleDay = new Button () { X = Application.GetRealWidth (33), Y = btnScheduleTime.Bottom, Height = Application.GetRealHeight (60), TextColor = SkinStyle.Current.TextColor1, Width = Application.GetRealWidth (400), TextAlignment = TextAlignment.CenterLeft, TextSize = 14, Tag = "btnScheduleDay", }; rowView.AddChidren (btnScheduleDay); btnScheduleDay.AddTag ("guid", schedule.Guid); if (schedule.Periodicity.Contains ("0")) { btnScheduleDay.Text += "Sun "; } if (schedule.Periodicity.Contains ("1")) { btnScheduleDay.Text += "Mon "; } if (schedule.Periodicity.Contains ("2")) { btnScheduleDay.Text += "Tues "; } if (schedule.Periodicity.Contains ("3")) { btnScheduleDay.Text += "Wed "; } if (schedule.Periodicity.Contains ("4")) { btnScheduleDay.Text += "Thur "; } if (schedule.Periodicity.Contains ("5")) { btnScheduleDay.Text += "Fri "; } if (schedule.Periodicity.Contains ("6")) { btnScheduleDay.Text += "Sat "; } var tempSiwtch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), X = Application.GetRealWidth (640 - 90 - 20), Y = Application.GetRealHeight (100), UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", IsSelected = schedule.IsStart, Tag = schedule.Guid }; rowView.AddChidren (tempSiwtch); tempSiwtch.MouseUpEventHandler += (sdd, ffd) => { tempSiwtch.IsSelected = !tempSiwtch.IsSelected; MainPage.Loading.Start ("Loading"); System.Threading.Tasks.Task.Run (() => { try { var switchObj = new Timer () { Guid = (sdd as Button).Tag.ToString () }; var switchRequestJson = Newtonsoft.Json.JsonConvert.SerializeObject (switchObj); var switchRevertObj = MainPage.RequestHttps ("IsEnableTimer", switchRequestJson); if (switchRevertObj.StateCode != "SUCCESS") { Application.RunOnMainThread (() => { tempSiwtch.IsSelected = !tempSiwtch.IsSelected; }); } } catch (Exception ex) { Console.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; Button btnDel = new Button () { TextID = R.MyInternationalizationString.Del, BackgroundColor = SkinStyle.Current.DelColor, Tag = schedule.Guid }; rowView.AddRightView (btnDel); btnDel.MouseUpEventHandler += (sender, er) => { var delObj = new Timer () { Guid = (sender as Button).Tag.ToString () }; var delRequestJson = Newtonsoft.Json.JsonConvert.SerializeObject (delObj); var delRevertObj = MainPage.RequestHttps ("DeleteTimer", delRequestJson); if (delRevertObj.StateCode == "SUCCESS") { rowView.RemoveFromParent (); timers.Remove (timers.Find((obj) => obj.Guid == delObj.Guid)); } }; #region goSchedule EventHandler eventHandler = (sender, er) => { Action refLoad = (obj) => { reinitSchedule (obj); }; var scheduleShowView = new AddSchedule (refLoad); UserMiddle.SettingPageView.AddChidren (scheduleShowView); scheduleShowView.ShowPage (schedule, timers, true); UserMiddle.SettingPageView.PageIndex = 2; }; rowView.MouseUpEventHandler += eventHandler; btnScheduleDay.MouseUpEventHandler += eventHandler; btnScheduleTime.MouseUpEventHandler += eventHandler; btnScheduleName.MouseUpEventHandler += eventHandler; #endregion #region delSchedule btnScheduleName.MouseLongEventHandler += (sender, e) => { var alert = new Alert ("",Language.StringByID (R.MyInternationalizationString.SureDelete), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { var delObj = new Timer () { Guid = (sender as Button).GetTagByKey ("guid").ToString () }; var delRequestJson = Newtonsoft.Json.JsonConvert.SerializeObject (delObj); var delRevertObj = MainPage.RequestHttps ("DeleteTimer", delRequestJson); if (delRevertObj.StateCode == "SUCCESS") { rowView.RemoveFromParent (); } } }; }; btnScheduleTime.MouseLongEventHandler += (sender, e) => { var alert = new Alert ("", Language.StringByID (R.MyInternationalizationString.SureDelete), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { var delObj = new Timer () { Guid = (sender as Button).GetTagByKey ("guid").ToString () }; var delRequestJson = Newtonsoft.Json.JsonConvert.SerializeObject (delObj); var delRevertObj = MainPage.RequestHttps ("DeleteTimer", delRequestJson); if (delRevertObj.StateCode == "SUCCESS") { rowView.RemoveFromParent (); } } }; }; btnScheduleDay.MouseLongEventHandler += (sender, e) => { var alert = new Alert ("", Language.StringByID (R.MyInternationalizationString.SureDelete), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { var delObj = new Timer () { Guid = (sender as Button).GetTagByKey ("guid").ToString () }; var delRequestJson = Newtonsoft.Json.JsonConvert.SerializeObject (delObj); var delRevertObj = MainPage.RequestHttps ("DeleteTimer", delRequestJson); if (delRevertObj.StateCode == "SUCCESS") { rowView.RemoveFromParent (); } } }; }; #endregion }); } } }