using System;
|
using System.Collections.Generic;
|
using Shared.SimpleControl.Phone.Music;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class UserSchedule : FrameLayout
|
{
|
VerticalScrolViewLayout bodyView;
|
|
public UserSchedule()
|
{
|
BackgroundColor = SkinStyle.Current.MainColor;
|
}
|
|
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) => {
|
MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load));
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
System.Threading.Thread.Sleep (100);
|
Application.RunOnMainThread (() => {
|
var tt = new Timer () { TimeZone = Convert.ToInt32 (DateTime.Now.ToString ("%z")), RegionID = UserConfig.Instance.CurrentRegion.RegionID, Periodicity = ((int)DateTime.Now.DayOfWeek).ToString (), TimerType = TimerType.Week, TimerName = "Schedule " + DateTime.Now.ToString ("yy-MM-dd"), ExecutionTime = DateTime.Now.ToString ("HH:mm") };
|
Action<Timer> refLoad = (obj) => {
|
initSchedule (obj);
|
};
|
var scheduleShowView = new AddSchedule (refLoad);
|
UserMiddle.SettingPageView.AddChidren (scheduleShowView);
|
scheduleShowView.ShowPage (tt);
|
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 (Application.DesignHeight - 126),
|
BackgroundColor = SkinStyle.Current.ViewColor
|
};
|
AddChidren (bodyView);
|
InitScheduleView ();
|
}
|
|
void InitScheduleView ()
|
{
|
MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load));
|
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") {
|
var timers = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Timer>> (revertObj.ResponseData.ToString ());
|
foreach (var schedule in timers) {
|
initSchedule (schedule);
|
}
|
}
|
} catch (Exception ex) {
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
}
|
|
|
void initSchedule(Timer schedule)
|
{
|
|
Application.RunOnMainThread (() => {
|
var rowView = new RowLayout () {
|
Height = Application.GetRealHeight (180),
|
};
|
bodyView.AddChidren (rowView);
|
|
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,
|
};
|
rowView.AddChidren (btnScheduleName);
|
|
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,
|
};
|
rowView.AddChidren (btnScheduleRoomName);
|
|
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,
|
};
|
rowView.AddChidren (btnScheduleTime);
|
//if (chooseTime.Hour > 12) {
|
// chooseTimeString = (chooseTime.Hour -12) + ":" + chooseTime.Minute + " PM";
|
//} else {
|
// chooseTimeString = chooseTime.Hour + ":" + chooseTime.Minute + " AM";
|
//}
|
|
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,
|
};
|
rowView.AddChidren (btnScheduleDay);
|
|
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);
|
//var timers = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Timer>> (revertObj.ResponseData.ToString ());
|
if (delRevertObj.StateCode == "SUCCESS") {
|
rowView.RemoveFromParent ();
|
}
|
};
|
});
|
|
}
|
}
|
}
|