| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared.SimpleControl.Phone.Music; |
| | | |
| | | namespace Shared.SimpleControl.Phone |
| | | { |
| | | public class AddSchedule : FrameLayout |
| | | { |
| | | /// <summary> |
| | | /// 上下滑动VerticalScrolViewLayout |
| | | /// </summary> |
| | | VerticalScrolViewLayout bodyView; |
| | | /// <summary> |
| | | /// 设备对象父控件 |
| | | /// </summary> |
| | | FrameLayout devicesListView; |
| | | /// <summary> |
| | | /// 定义一个回调函数 |
| | | /// </summary> |
| | | Action<Timer> action; |
| | | List<Common> roomDeviceList = new List<Common>(); |
| | | List<string> roomNameList = new List<string> (); |
| | | List<DeviceInfo> timerControlDeviceList = new List<DeviceInfo> (); |
| | | |
| | | /// <summary> |
| | | /// 选中设备列表 |
| | | /// </summary> |
| | | List<Fun> selectedDeviceList = new List<Fun> (); |
| | | /// <summary> |
| | | /// 是否编辑(true=编辑) |
| | | /// </summary> |
| | | bool IsEdit = false; |
| | | /// <summary> |
| | | /// 对象构造函数 |
| | | /// </summary> |
| | | /// <param name="act">返回函数</param> |
| | | public AddSchedule (Action<Timer> act) |
| | | { |
| | | action = act; |
| | | } |
| | | /// <summary> |
| | | /// 重写方法 |
| | | /// </summary> |
| | | public override void RemoveFromParent () |
| | | { |
| | | UserMiddle.SettingPageView.ScrollEnabled = true; |
| | | base.RemoveFromParent (); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 对象主入口 |
| | | /// </summary> |
| | | /// <param name="timerTemp">当前对象</param> |
| | | /// <param name="listTimer">计时器列表</param> |
| | | /// <param name="isEdit">编辑状态</param> |
| | | public void ShowPage (Timer timerTemp, List<Timer> listTimer, bool isEdit = false) |
| | | { |
| | | IsEdit = isEdit; |
| | | selectedDeviceList.Clear (); |
| | | if (isEdit) { |
| | | for (int j = 0; j < timerTemp.controlData.actions.Count; j++) { |
| | | var fun = timerTemp.controlData.actions [j]; |
| | | var dev = selectedDeviceList.Find ((c) => c.deviceId == fun.deviceId); |
| | | if (dev == null) { |
| | | selectedDeviceList.Add (fun); |
| | | } |
| | | } |
| | | |
| | | } |
| | | UserMiddle.SettingPageView.ScrollEnabled = false; |
| | | timerTemp.RegionID = UserConfig.Instance.CurrentRegion.Id; |
| | | #region topview |
| | | var topView = new RowLayout () { |
| | | Y = Application.GetRealHeight (36), |
| | |
| | | BorderWidth = 1, |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | Text = timerTemp.TimerName |
| | | Text = timerTemp.timerName |
| | | }; |
| | | nameView.AddChidren (etName); |
| | | etName.EditorEnterAction += (obj) => { |
| | |
| | | var btnTimelbl = new Button () { |
| | | X = btnTimeIcon.Right, |
| | | Width = Application.GetRealWidth (110), |
| | | Text = timerTemp.ExecutionTime, |
| | | Text = timerTemp.executeUtcTime, |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | }; |
| | | timeView.AddChidren (btnTimelbl); |
| | | |
| | | btnTimelbl.MouseUpEventHandler += (timeSender, eee) => { |
| | | var dialog = new Dialog (); |
| | | var chooseTimeBodyView = new FrameLayout () { |
| | | }; |
| | | dialog.AddChidren (chooseTimeBodyView); |
| | | |
| | | var chooseTime = new TimeView () { |
| | | Y = Application.GetRealHeight (1136 - 420 - 90), |
| | | Height = Application.GetRealHeight (420), |
| | | BackgroundColor = 0xFFD7D7D7, |
| | | //BackgroundColor = SkinStyle.Current.ViewColor, |
| | | }; |
| | | chooseTimeBodyView.AddChidren (chooseTime); |
| | | ShowTimePickerView (btnTimelbl); |
| | | return; |
| | | |
| | | var bottomView = new FrameLayout () { |
| | | Y = chooseTime.Bottom, |
| | | Height = Application.GetRealHeight (90) + 1, |
| | | BackgroundColor = 0xFFD7D7D7, |
| | | }; |
| | | chooseTimeBodyView.AddChidren (bottomView); |
| | | //var dialog = new Dialog (); |
| | | //var chooseTimeBodyView = new FrameLayout () { |
| | | //}; |
| | | //dialog.AddChidren (chooseTimeBodyView); |
| | | |
| | | var btnCloseTime = new Button () { |
| | | Y = 1, |
| | | Width = Application.GetRealWidth (320), |
| | | BackgroundColor = SkinStyle.Current.ViewColor, |
| | | TextID = R.MyInternationalizationString.Close, |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | }; |
| | | bottomView.AddChidren (btnCloseTime); |
| | | btnCloseTime.MouseUpEventHandler += (ddf, dddf) => { |
| | | chooseTimeBodyView.RemoveAll (); |
| | | chooseTimeBodyView.RemoveFromParent (); |
| | | dialog.Close (); |
| | | }; |
| | | //var chooseTime = new TimeView () { |
| | | // Y = Application.GetRealHeight (1136 - 420 - 90), |
| | | // Height = Application.GetRealHeight (420), |
| | | // BackgroundColor = 0xFFD7D7D7, |
| | | // //BackgroundColor = SkinStyle.Current.ViewColor, |
| | | //}; |
| | | //chooseTimeBodyView.AddChidren (chooseTime); |
| | | |
| | | var btnSaveTime = new Button () { |
| | | X = btnCloseTime.Right + 1, |
| | | Y = 1, |
| | | Width = Application.GetRealWidth (320), |
| | | TextID = R.MyInternationalizationString.SAVE, |
| | | BackgroundColor = SkinStyle.Current.ViewColor, |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | }; |
| | | bottomView.AddChidren (btnSaveTime); |
| | | btnSaveTime.MouseUpEventHandler += (sender3, e3) => { |
| | | var chooseHour = chooseTime.Hour - timerTemp.TimeZone; |
| | | var chooseTimeString = chooseTime.Hour.ToString ().PadLeft (2, '0') + ":" + chooseTime.Minute.ToString ().PadLeft (2, '0'); |
| | | //if (chooseTime.Hour > 12) { |
| | | // chooseTimeString = (chooseTime.Hour -12) + ":" + chooseTime.Minute + " PM"; |
| | | //} else { |
| | | // chooseTimeString = chooseTime.Hour + ":" + chooseTime.Minute + " AM"; |
| | | //} |
| | | btnTimelbl.Text = chooseTimeString; |
| | | dialog.Close (); |
| | | }; |
| | | //var bottomView = new FrameLayout () { |
| | | // Y = chooseTime.Bottom, |
| | | // Height = Application.GetRealHeight (90) + 1, |
| | | // BackgroundColor = 0xFFD7D7D7, |
| | | //}; |
| | | //chooseTimeBodyView.AddChidren (bottomView); |
| | | |
| | | //var btnCloseTime = new Button () { |
| | | // Y = 1, |
| | | // Width = Application.GetRealWidth (320), |
| | | // BackgroundColor = SkinStyle.Current.ViewColor, |
| | | // TextID = R.MyInternationalizationString.Close, |
| | | // TextAlignment = TextAlignment.Center, |
| | | // TextColor = SkinStyle.Current.TextColor1, |
| | | //}; |
| | | //bottomView.AddChidren (btnCloseTime); |
| | | //btnCloseTime.MouseUpEventHandler += (ddf, dddf) => { |
| | | // chooseTimeBodyView.RemoveAll (); |
| | | // chooseTimeBodyView.RemoveFromParent (); |
| | | // dialog.Close (); |
| | | //}; |
| | | |
| | | //var btnSaveTime = new Button () { |
| | | // X = btnCloseTime.Right + 1, |
| | | // Y = 1, |
| | | // Width = Application.GetRealWidth (320), |
| | | // TextID = R.MyInternationalizationString.SAVE, |
| | | // BackgroundColor = SkinStyle.Current.ViewColor, |
| | | // TextAlignment = TextAlignment.Center, |
| | | // TextColor = SkinStyle.Current.TextColor1, |
| | | //}; |
| | | //bottomView.AddChidren (btnSaveTime); |
| | | //btnSaveTime.MouseUpEventHandler += (sender3, e3) => { |
| | | // // var chooseHour = chooseTime.Hour - timerTemp.TimeZone; |
| | | // var chooseTimeString = chooseTime.Hour.ToString ().PadLeft (2, '0') + ":" + chooseTime.Minute.ToString ().PadLeft (2, '0'); |
| | | // //if (chooseTime.Hour > 12) { |
| | | // // chooseTimeString = (chooseTime.Hour -12) + ":" + chooseTime.Minute + " PM"; |
| | | // //} else { |
| | | // // chooseTimeString = chooseTime.Hour + ":" + chooseTime.Minute + " AM"; |
| | | // //} |
| | | // btnTimelbl.Text = chooseTimeString; |
| | | // dialog.Close (); |
| | | //}; |
| | | |
| | | |
| | | dialog.Show (); |
| | | //dialog.Show (); |
| | | }; |
| | | #endregion |
| | | |
| | |
| | | Radius = (uint)Application.GetMinRealAverage (22), |
| | | BorderWidth = 1, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | IsSelected = timerTemp.Periodicity.Contains ("0"), |
| | | IsSelected = timerTemp.whichDay.Contains (0), |
| | | Tag = 0, |
| | | }; |
| | | repeatView.AddChidren (btnSunday); |
| | |
| | | Radius = (uint)Application.GetMinRealAverage (22), |
| | | BorderWidth = 1, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | IsSelected = timerTemp.Periodicity.Contains ("1"), |
| | | IsSelected = timerTemp.whichDay.Contains (1), |
| | | Tag = 1, |
| | | }; |
| | | repeatView.AddChidren (btnMonday); |
| | |
| | | Radius = (uint)Application.GetMinRealAverage (22), |
| | | BorderWidth = 1, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | IsSelected = timerTemp.Periodicity.Contains ("2"), |
| | | IsSelected = timerTemp.whichDay.Contains (2), |
| | | Tag = 2, |
| | | }; |
| | | repeatView.AddChidren (btnTuesday); |
| | |
| | | Radius = (uint)Application.GetMinRealAverage (22), |
| | | BorderWidth = 1, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | IsSelected = timerTemp.Periodicity.Contains ("3"), |
| | | IsSelected = timerTemp.whichDay.Contains (3), |
| | | Tag = 3, |
| | | }; |
| | | repeatView.AddChidren (btnWednesday); |
| | |
| | | Radius = (uint)Application.GetMinRealAverage (22), |
| | | BorderWidth = 1, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | IsSelected = timerTemp.Periodicity.Contains ("4"), |
| | | IsSelected = timerTemp.whichDay.Contains (4), |
| | | Tag = 4, |
| | | }; |
| | | repeatView.AddChidren (btnThursday); |
| | |
| | | Radius = (uint)Application.GetMinRealAverage (22), |
| | | BorderWidth = 1, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | IsSelected = timerTemp.Periodicity.Contains ("5"), |
| | | IsSelected = timerTemp.whichDay.Contains (5), |
| | | Tag = 5, |
| | | }; |
| | | repeatView.AddChidren (btnFriday); |
| | |
| | | Radius = (uint)Application.GetMinRealAverage (22), |
| | | BorderWidth = 1, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | IsSelected = timerTemp.Periodicity.Contains ("6"), |
| | | IsSelected = timerTemp.whichDay.Contains (6), |
| | | Tag = 6, |
| | | }; |
| | | repeatView.AddChidren (btnSaturday); |
| | |
| | | |
| | | var downSelectedButton = new Button () { |
| | | X = Application.GetRealWidth (310), |
| | | Height = Application.GetRealHeight (50), |
| | | Height = Application.GetRealWidth (50), |
| | | Width = Application.GetRealWidth (55), |
| | | UnSelectedImagePath = "Item/Down.png", |
| | | SelectedImagePath = "Item/DownSelected.png", |
| | |
| | | Height = Application.GetRealHeight (60), |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | Text = timerTemp.RoomName, |
| | | }; |
| | | roomContenView.AddChidren (btnRoomChoose); |
| | | |
| | | roomNameList.Add ("ALL"); |
| | | foreach (var room in Room.Lists) { |
| | | if (string.IsNullOrEmpty (room.Name)) { |
| | | continue; |
| | | } |
| | | roomNameList.Add (room.Name); |
| | | if (timerTemp.RoomName == "ALL") { |
| | | roomDeviceList.AddRange (room.DeviceList); |
| | | } else { |
| | | if(timerTemp.RoomName == room.Name) { |
| | | roomDeviceList.Clear (); |
| | | roomDeviceList.AddRange (room.DeviceList); |
| | | } |
| | | } |
| | | } |
| | | if (roomNameList.Count > 0 && !isEdit) { |
| | | timerTemp.RoomName = roomNameList [0]; |
| | | } |
| | | btnRoomChoose.Text = timerTemp.RoomName; |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region Devices |
| | | try { |
| | | timerControlDeviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DeviceInfo>> (timerTemp.ControlDeviceData);//devicesControlDataList |
| | | } catch { |
| | | timerControlDeviceList = null; |
| | | } |
| | | |
| | | if (timerControlDeviceList == null) |
| | | timerControlDeviceList = new List<DeviceInfo> (); |
| | | |
| | | var devicesView = new RowLayout () { |
| | | Height = Application.GetRealHeight (110), |
| | |
| | | }; |
| | | devicesView.AddChidren (btnDeviceTitle); |
| | | |
| | | devicesListView = new FrameLayout () { |
| | | Height = Application.GetRealHeight (130 * roomDeviceList.Count), |
| | | devicesListView = new FrameLayout () { |
| | | Height = Application.GetRealHeight (130), |
| | | }; |
| | | bodyView.AddChidren (devicesListView); |
| | | |
| | | MainPage.Loading.Start ("Please wait..."); |
| | | InitDeviceListView (roomDeviceList, timerControlDeviceList, devicesListView); |
| | | #endregion |
| | | |
| | | |
| | | #region -----Room |
| | | MainPage.Loading.Start ("Please wait..."); |
| | | SmartHome.Method mMthod = new SmartHome.Method (); |
| | | var devList = mMthod.GetRoomDeviceList (timerTemp.RoomName); |
| | | InitDeviceListView (devList); |
| | | #region -----Room 点击事件 |
| | | btnRoomChoose.MouseUpEventHandler += (sender, e) => { |
| | | Application.HideSoftInput (); |
| | | var roomDialog = new Dialog (); |
| | |
| | | BackgroundColor = SkinStyle.Current.ViewColor, |
| | | }; |
| | | chooseRoomView.AddChidren (roomListView); |
| | | |
| | | foreach (var roomName in roomNameList) { |
| | | //获取房间列表 |
| | | var roomList = mMthod.GetRoomList (); |
| | | for (int i = 0; i < roomList.Count; i++) { |
| | | var room = roomList [i]; |
| | | var btnRoomNameChoose = new Button () { |
| | | Height = Application.GetRealHeight (90), |
| | | Text = roomName, |
| | | Text = room.Name, |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | TextAlignment = TextAlignment.Center, |
| | | }; |
| | |
| | | roomListView.AddChidren (btnLine); |
| | | |
| | | btnRoomNameChoose.MouseUpEventHandler += (sd, ds) => { |
| | | //切换房间清空之前选择数据; |
| | | selectedDeviceList.Clear (); |
| | | btnRoomChoose.Text = (sd as Button).Text; |
| | | foreach (var room in Room.Lists) { |
| | | if (string.IsNullOrEmpty (room.Name)) { |
| | | continue; |
| | | } |
| | | if (btnRoomChoose.Text == "ALL") { |
| | | roomDeviceList.AddRange (room.DeviceList); |
| | | } else { |
| | | if (btnRoomChoose.Text == room.Name) { |
| | | roomDeviceList.Clear (); |
| | | roomDeviceList.AddRange (room.DeviceList); |
| | | } |
| | | } |
| | | } |
| | | timerControlDeviceList = new List<DeviceInfo> (); |
| | | InitDeviceListView (roomDeviceList, timerControlDeviceList, devicesListView); |
| | | //获取设备列表 |
| | | var deviceList = mMthod.GetRoomDeviceList (btnRoomChoose.Text); |
| | | InitDeviceListView (deviceList); |
| | | roomDialog.Close (); |
| | | }; |
| | | } |
| | |
| | | saveTimeBottomView.AddChidren (btnSaveTimerBottom); |
| | | |
| | | btnSaveTimerBottom.MouseUpEventHandler += (ll, kk) => { |
| | | //WorkingDay, //工作日 |
| | | //Weekend, //周末 |
| | | //Week, //指定星期几 |
| | | //Period, //指定时间段 |
| | | //AppointDay, //指定日 Periodicity |
| | | |
| | | |
| | | if (btnMonday.IsSelected == false && btnFriday.IsSelected == false && btnThursday.IsSelected == false && btnSunday.IsSelected == false && btnTuesday.IsSelected == false && btnSaturday.IsSelected == false && btnWednesday.IsSelected == false) { |
| | | //new Alert ("", "请选择日期!", "Close").Show (); |
| | |
| | | // return; |
| | | //} |
| | | |
| | | if (timerControlDeviceList.Count == 0) { |
| | | if (selectedDeviceList.Count == 0) { |
| | | new Alert ("", "Please choose at least one device!", "Close").Show (); |
| | | return; |
| | | } |
| | | |
| | | //名字重复判断限制 |
| | | var mTimer = listTimer.Find ((obj) => obj.TimerName == mTimerName); |
| | | var mTimer = listTimer.Find ((obj) => obj.timerName == mTimerName); |
| | | if (isEdit) { |
| | | if (mTimer != null && mTimer.Id != timerTemp.Id) { |
| | | if (mTimer != null && mTimer.id != timerTemp.id) { |
| | | new Alert ("", "The timer name already exists. Please change it before saving it.", "Close").Show (); |
| | | return; |
| | | } |
| | |
| | | //2020-02-10 时间重复判断限制 |
| | | string mExecutionTime = btnTimelbl.Text; |
| | | //timerTemp.ExecutionTime = btnTimelbl.Text; |
| | | var mTimerExecutionTime = listTimer.Find ((obj) => (obj.ExecutionTime == mExecutionTime)); |
| | | var mTimerExecutionTime = listTimer.Find ((obj) => (obj.executeUtcTime == mExecutionTime)); |
| | | if (isEdit) { |
| | | if (mTimerExecutionTime != null && mTimerExecutionTime.Id != timerTemp.Id) { |
| | | if (mTimerExecutionTime != null && mTimerExecutionTime.id != timerTemp.id) { |
| | | new Alert ("", "The timer time already exists. Please change it before saving it.", "Close").Show (); |
| | | return; |
| | | } |
| | |
| | | return; |
| | | } |
| | | } |
| | | // 2021-03-30 先清空,再重新统计 |
| | | timerTemp.whichDay = new List<int>(); |
| | | |
| | | timerTemp.Periodicity = ""; |
| | | if (btnMonday.IsSelected == true && btnFriday.IsSelected == true && btnThursday.IsSelected == true && btnSunday.IsSelected == true && btnTuesday.IsSelected == true && btnSaturday.IsSelected == true && btnWednesday.IsSelected == true) { |
| | | timerTemp.TimerType = TimerType.EveryDay; |
| | | timerTemp.timerType = TimerType.EveryDay; |
| | | } else if (btnSunday.IsSelected == true && btnSaturday.IsSelected == true && btnMonday.IsSelected == false && btnFriday.IsSelected == false && btnThursday.IsSelected == false && btnTuesday.IsSelected == false && btnWednesday.IsSelected == false) { |
| | | timerTemp.TimerType = TimerType.Weekend; |
| | | timerTemp.timerType = TimerType.Weekend; |
| | | } else if (btnSunday.IsSelected == false && btnSaturday.IsSelected == false && btnMonday.IsSelected == true && btnFriday.IsSelected == true && btnThursday.IsSelected == true && btnTuesday.IsSelected == true && btnWednesday.IsSelected) { |
| | | timerTemp.TimerType = TimerType.WorkingDay; |
| | | timerTemp.timerType = TimerType.WorkingDay; |
| | | } else { |
| | | timerTemp.TimerType = TimerType.Week; |
| | | timerTemp.Periodicity = ""; |
| | | timerTemp.timerType = TimerType.Week; |
| | | } |
| | | if (btnSunday.IsSelected) { |
| | | timerTemp.Periodicity += "0,"; |
| | | if (!timerTemp.whichDay.Contains (0)) { |
| | | timerTemp.whichDay.Add (0); |
| | | } |
| | | } |
| | | if (btnSaturday.IsSelected) { |
| | | timerTemp.Periodicity += "6,"; |
| | | if (!timerTemp.whichDay.Contains (6)) { |
| | | timerTemp.whichDay.Add (6); |
| | | } |
| | | } |
| | | if (btnMonday.IsSelected) { |
| | | timerTemp.Periodicity += "1,"; |
| | | } |
| | | if (btnFriday.IsSelected) { |
| | | timerTemp.Periodicity += "5,"; |
| | | } |
| | | if (btnThursday.IsSelected) { |
| | | timerTemp.Periodicity += "4,"; |
| | | if (!timerTemp.whichDay.Contains (1)) { |
| | | timerTemp.whichDay.Add (1); |
| | | } |
| | | } |
| | | if (btnTuesday.IsSelected) { |
| | | timerTemp.Periodicity += "2,"; |
| | | if (!timerTemp.whichDay.Contains (2)) { |
| | | timerTemp.whichDay.Add (2); |
| | | } |
| | | |
| | | } |
| | | if (btnWednesday.IsSelected) { |
| | | timerTemp.Periodicity += "3,"; |
| | | if (!timerTemp.whichDay.Contains (3)) { |
| | | timerTemp.whichDay.Add (3); |
| | | } |
| | | } |
| | | |
| | | if (timerTemp.Periodicity [timerTemp.Periodicity.Length - 1] == ',') { |
| | | timerTemp.Periodicity = timerTemp.Periodicity.Remove (timerTemp.Periodicity.Length - 1, 1); |
| | | if (btnThursday.IsSelected) { |
| | | if (!timerTemp.whichDay.Contains (4)) { |
| | | timerTemp.whichDay.Add (4); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | timerTemp.IsStart = true; |
| | | if (string.IsNullOrEmpty (timerTemp.Id)) { |
| | | timerTemp.Id = Guid.NewGuid ().ToString (); |
| | | if (btnFriday.IsSelected) { |
| | | if (!timerTemp.whichDay.Contains (5)) { |
| | | timerTemp.whichDay.Add (5); |
| | | } |
| | | } |
| | | timerTemp.ControlDeviceData = Newtonsoft.Json.JsonConvert.SerializeObject (timerControlDeviceList); |
| | | //if (string.IsNullOrEmpty (timerTemp.id)) { |
| | | // timerTemp.id = Guid.NewGuid ().ToString (); |
| | | //} |
| | | |
| | | DeviceDate deviceDate = new DeviceDate (); |
| | | deviceDate.gatewayId = SmartHome.Send.GatewayId; |
| | | deviceDate.homeId = SmartHome.Send.HomeId; |
| | | |
| | | |
| | | deviceDate.actions.AddRange (selectedDeviceList); |
| | | timerTemp.controlData = deviceDate; |
| | | |
| | | MainPage.Loading.Start ("Saving..."); |
| | | timerTemp.RoomName = btnRoomChoose.Text; |
| | | timerTemp.ExecutionTime = btnTimelbl.Text; |
| | | timerTemp.TimerName = etName.Text.Trim (); |
| | | timerTemp.executeUtcTime = btnTimelbl.Text; |
| | | timerTemp.timerName = etName.Text.Trim (); |
| | | System.Threading.Tasks.Task.Run (() => { |
| | | try { |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (timerTemp); |
| | | ResponsePack revertObj = null; |
| | | ResponsePackNew revertObj = null; |
| | | if (isEdit) { |
| | | revertObj = MainPage.RequestHttps (API.EditTimer, requestJson); |
| | | } else { |
| | | revertObj = MainPage.RequestHttps (API.AddTimer, requestJson); |
| | | revertObj = SmartHome.Send.UpdateTimer (timerTemp); |
| | | |
| | | } else { |
| | | |
| | | |
| | | revertObj = SmartHome.Send.AddTimer (timerTemp); |
| | | } |
| | | |
| | | Application.RunOnMainThread (() => { |
| | | if (revertObj == null) { |
| | | new Alert ("", "Unable to save data, please check the network.", "Close").Show (); |
| | | } else if (revertObj.StateCode.ToUpper() == StateCode.SUCCESS) { |
| | | } else if (revertObj.Code == StateCode.SUCCESS) { |
| | | string id = ""; |
| | | if (!isEdit) { |
| | | var jObject = JObject.Parse (revertObj.Data.ToString ()); |
| | | id = jObject ["id"].ToString (); |
| | | timerTemp.id = id; |
| | | } |
| | | this.RemoveFromParent (); |
| | | action (timerTemp); |
| | | |
| | | } else if (revertObj.Code == "10107") { |
| | | new Alert ("", "Timer name already exists.", "Close").Show (); |
| | | } else { |
| | | ShowErrorInfo (revertObj.StateCode); |
| | | //提示错误 |
| | | IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); |
| | | |
| | | } |
| | | }); |
| | | } catch (Exception ex) { |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | //(1)Success 则调用此接口成功 |
| | | //(2)NoRecord 住宅未绑定网关! |
| | | //(3)NoExist 住宅不存在! |
| | | //(4)Exist 生成的Guid已存在! |
| | | /// 自定义TimePickerView |
| | | /// 2021-03-24 |
| | | /// </summary> |
| | | void ShowErrorInfo (string stateCodeStr) |
| | | void ShowTimePickerView (Button btnTimelbl) |
| | | { |
| | | string mes = ""; |
| | | if (stateCodeStr == "NoRecord") { |
| | | // 住宅未绑定网关! |
| | | mes = ErrorCode.HomeNoRecord; |
| | | } else if (stateCodeStr == "NoExist") { |
| | | //住宅不存在! |
| | | mes = ErrorCode.HomeNoExist; |
| | | } else if (stateCodeStr == "Exist") { |
| | | //生成的Guid已存在! |
| | | mes = ErrorCode.GuidExist; |
| | | } else if (stateCodeStr == ErrorCode.NetworkError) { |
| | | mes = ErrorCode.NetworkError; |
| | | } else { |
| | | mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr; |
| | | var chooseTimeString = "00:00"; |
| | | var dialog = new Dialog (); |
| | | var chooseTimeBodyView = new FrameLayout () { |
| | | }; |
| | | dialog.AddChidren (chooseTimeBodyView); |
| | | |
| | | var timeView = new FrameLayout () { |
| | | Y = Application.GetRealHeight (1136 - 420 - 90), |
| | | Height = Application.GetRealHeight (420), |
| | | BackgroundColor = SkinStyle.Current.ViewColor, |
| | | }; |
| | | chooseTimeBodyView.AddChidren (timeView); |
| | | |
| | | var chooseTime = new UIPickerView () { |
| | | Height = Application.GetRealHeight (400), |
| | | BackgroundColor = SkinStyle.Current.Transparent, |
| | | Gravity = Gravity.CenterVertical |
| | | }; |
| | | timeView.AddChidren (chooseTime); |
| | | |
| | | var bottomView = new FrameLayout () { |
| | | Y = timeView.Bottom, |
| | | Height = Application.GetRealHeight (90) + 1, |
| | | BackgroundColor = 0xFFD7D7D7, |
| | | }; |
| | | chooseTimeBodyView.AddChidren (bottomView); |
| | | |
| | | var btnCloseTime = new Button () { |
| | | Y = 1, |
| | | Width = Application.GetRealWidth (320), |
| | | BackgroundColor = SkinStyle.Current.ViewColor, |
| | | TextID = R.MyInternationalizationString.Close, |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | }; |
| | | bottomView.AddChidren (btnCloseTime); |
| | | btnCloseTime.MouseUpEventHandler += (ddf, dddf) => { |
| | | chooseTimeBodyView.RemoveAll (); |
| | | chooseTimeBodyView.RemoveFromParent (); |
| | | dialog.Close (); |
| | | }; |
| | | |
| | | var btnSaveTime = new Button () { |
| | | X = btnCloseTime.Right + 1, |
| | | Y = 1, |
| | | Width = Application.GetRealWidth (320), |
| | | TextID = R.MyInternationalizationString.SAVE, |
| | | BackgroundColor = SkinStyle.Current.ViewColor, |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | }; |
| | | bottomView.AddChidren (btnSaveTime); |
| | | btnSaveTime.MouseUpEventHandler += (sender3, e3) => { |
| | | btnTimelbl.Text = chooseTimeString; |
| | | dialog.Close (); |
| | | }; |
| | | |
| | | var nowDateTime = DateTime.Now; |
| | | var hour = nowDateTime.Hour; |
| | | //hourStr |
| | | var hourStr = hour.ToString(); |
| | | if (hour < 10) { |
| | | hourStr = "0" + hour; |
| | | } |
| | | |
| | | var minute = nowDateTime.Minute; |
| | | //minuteStr |
| | | var minuteStr = minute.ToString (); |
| | | if (minute < 10) { |
| | | minuteStr = "0" + minute; |
| | | } |
| | | var hourList = new List<string> (); |
| | | for (int i = 0; i < 24; i++) { |
| | | if (i < 10) { |
| | | var a = "0" + i.ToString (); |
| | | hourList.Add (a); |
| | | } else { |
| | | hourList.Add (i.ToString ()); |
| | | } |
| | | |
| | | } |
| | | if (!string.IsNullOrEmpty (mes)) { |
| | | //Application.RunOnMainThread (() => { |
| | | new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | //}); |
| | | |
| | | var minuteList = new List<string> (); |
| | | for (int i = 0; i < 60; i++) { |
| | | if (i < 10) { |
| | | var a = "0" + i.ToString (); |
| | | minuteList.Add (a); |
| | | } else { |
| | | minuteList.Add (i.ToString ()); |
| | | } |
| | | |
| | | } |
| | | |
| | | chooseTime.setNPicker (hourList, minuteList, null); |
| | | chooseTime.setCurrentItems (hour, minute, 0); |
| | | chooseTimeString = hourStr + ":" + minuteStr; |
| | | |
| | | //string selectde = ""; |
| | | chooseTime.OnSelectChangeEvent += (s1, s2, s3) => { |
| | | var hourV = hourList [s1]; |
| | | var minuteV = minuteList [s2]; |
| | | chooseTimeString = hourV + ":" + minuteV; |
| | | |
| | | }; |
| | | |
| | | dialog.Show (); |
| | | |
| | | } |
| | | |
| | | private static void InitDeviceListView (List<Common> roomDeviceList, List<DeviceInfo> timerControlDeviceList, FrameLayout devicesListView) |
| | | /// <summary> |
| | | /// 加载房间设备列表界面 |
| | | /// </summary> |
| | | /// <param name="deviceList">房间设备列表</param> |
| | | private void InitDeviceListView (List<Function> deviceList) |
| | | { |
| | | devicesListView.RemoveAll (); |
| | | |
| | | //房间设备列表 |
| | | devicesListView.Height = Application.GetRealHeight (130 * deviceList.Count); |
| | | System.Threading.Tasks.Task.Run (() => { |
| | | try { |
| | | int iniIndex = 0; |
| | | for (int i = 0; i < timerControlDeviceList.Count;) { |
| | | if (timerControlDeviceList [i] == null) { |
| | | timerControlDeviceList.RemoveAt (i); |
| | | } else { |
| | | i++; |
| | | } |
| | | } |
| | | Application.RunOnMainThread (() => { |
| | | try { |
| | | string value = ""; |
| | | for (int i = 0; i < deviceList.Count; i++) { |
| | | var device = deviceList [i]; |
| | | var deviceRowView = new RowLayout () { |
| | | Y = Application.GetRealHeight (130 * i), |
| | | Radius = 1, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | BorderWidth = (uint)Application.GetMinRealAverage (5), |
| | | Height = Application.GetRealHeight (110), |
| | | Tag = device, |
| | | }; |
| | | devicesListView.AddChidren (deviceRowView); |
| | | |
| | | #if __IOS__ |
| | | var btnChoose = new Button () { |
| | | Width = Application.GetRealWidth (60), |
| | | Height = Application.GetRealWidth (60), |
| | | X = Application.GetRealWidth (40), |
| | | Gravity = Gravity.CenterVertical, |
| | | UnSelectedImagePath = "CrabtreeAdd/Choose.png", |
| | | SelectedImagePath = "CrabtreeAdd/ChooseOn.png", |
| | | Tag = device, |
| | | }; |
| | | deviceRowView.AddChidren (btnChoose); |
| | | |
| | | Button btnDeviceName = new Button () { |
| | | Width = Application.GetRealWidth (342), |
| | | Height = Application.GetRealHeight (70), |
| | | Text = device.name, |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | X = btnChoose.Right + Application.GetRealWidth (10), |
| | | Y = Application.GetRealHeight (20), |
| | | SelectedTextColor = SkinStyle.Current.TextColor1, |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | }; |
| | | deviceRowView.AddChidren (btnDeviceName); |
| | | Button tempSwitch = new Button { |
| | | Width = Application.GetRealWidth (90), |
| | | Height = Application.GetRealWidth (53), |
| | | X = Application.GetRealWidth (640 - 90 - 20), |
| | | Gravity = Gravity.CenterVertical, |
| | | UnSelectedImagePath = "Item/SwitchClose.png", |
| | | SelectedImagePath = "Item/SwitchOpen.png", |
| | | Tag = device, |
| | | }; |
| | | deviceRowView.AddChidren (tempSwitch); |
| | | |
| | | #else |
| | | //刷新devicesListView 高度 |
| | | devicesListView.Height = Application.GetRealHeight (130 * roomDeviceList.Count); |
| | | #endif |
| | | |
| | | foreach (var deviceCommon2 in roomDeviceList) { |
| | | if (deviceCommon2 == null) |
| | | continue; |
| | | var deviceCommon = new DeviceInfo () { |
| | | DevicePath = deviceCommon2.SavePath, DeviceType = (int)deviceCommon2.Type, SubnetID = deviceCommon2.SubnetID, |
| | | DeviceID = deviceCommon2.DeviceID, LoopID = deviceCommon2.LoopID, Command = (int)Command.SetSingleLight, |
| | | Type = deviceCommon2.Type,Name = deviceCommon2.Name,SavePath = deviceCommon2.SavePath, |
| | | }; |
| | | if (deviceCommon.Type == DeviceType.LightDimming || deviceCommon.Type == DeviceType.FanModule || |
| | | deviceCommon.Type == DeviceType.LightSwitch || deviceCommon.Type == DeviceType.LightEnergySwitch || deviceCommon.Type == DeviceType.LightEnergySocket || deviceCommon.Type == DeviceType.LightSwitchSocket || |
| | | deviceCommon.Type == DeviceType.CurtainModel || deviceCommon.Type == DeviceType.CurtainRoller || deviceCommon.Type == DeviceType.CurtainTrietex) { |
| | | Application.RunOnMainThread (() => { |
| | | try { |
| | | DeviceInfo timerControlDevice = null; |
| | | try { |
| | | timerControlDevice = timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath); |
| | | } catch { } |
| | | if (timerControlDevice != null) |
| | | deviceCommon.SendBytes = timerControlDevice.SendBytes; |
| | | var DeviceRowView = new RowLayout () { |
| | | Y = Application.GetRealHeight (130 * iniIndex), |
| | | Radius = 1, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | BorderWidth = (uint)Application.GetMinRealAverage (5), |
| | | Height = Application.GetRealHeight (110), |
| | | Tag = deviceCommon.Type + "_" + deviceCommon.CommonLoopID |
| | | }; |
| | | devicesListView.AddChidren (DeviceRowView); |
| | | iniIndex++; |
| | | |
| | | var btnChoose = new Button () { |
| | | Width = Application.GetRealHeight (60), |
| | | Height = Application.GetRealHeight (60), |
| | | X = Application.GetRealWidth (40), |
| | | Gravity = Gravity.CenterVertical, |
| | | UnSelectedImagePath = "CrabtreeAdd/Choose.png", |
| | | SelectedImagePath = "CrabtreeAdd/ChooseOn.png", |
| | | IsSelected = timerControlDevice != null, |
| | | //Tag = deviceFilePath |
| | | }; |
| | | DeviceRowView.AddChidren (btnChoose); |
| | | |
| | | Button btnDeviceName = new Button () { |
| | | Width = Application.GetRealWidth (342), |
| | | Height = Application.GetRealHeight (70), |
| | | Text = deviceCommon.Name, |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | X = btnChoose.Right + Application.GetRealWidth (10), |
| | | Y = Application.GetRealHeight (20), |
| | | SelectedTextColor = SkinStyle.Current.TextColor1, |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | }; |
| | | DeviceRowView.AddChidren (btnDeviceName); |
| | | Button tempSwitch = new Button () { |
| | | Width = Application.GetMinRealAverage (90), |
| | | Height = Application.GetMinRealAverage (53), |
| | | X = Application.GetRealWidth (640 - 90 - 20), |
| | | Gravity = Gravity.CenterVertical, |
| | | UnSelectedImagePath = "Item/SwitchClose.png", |
| | | SelectedImagePath = "Item/SwitchOpen.png", |
| | | Tag = deviceCommon.CommonLoopID, |
| | | }; |
| | | DeviceRowView.AddChidren (tempSwitch); |
| | | |
| | | |
| | | if (deviceCommon.Type == DeviceType.FanModule) { |
| | | #region 风扇 |
| | | tempSwitch.RemoveFromParent (); |
| | | //FanModule fanModule = deviceCommon as FanModule; |
| | | |
| | | DeviceRowView.Height = Application.GetRealHeight (130); |
| | | btnChoose.Y = Application.GetRealHeight (5); |
| | | btnDeviceName.Y = Application.GetRealHeight (0); |
| | | |
| | | var btnFanLevel = new Button () { |
| | | X = btnChoose.X + Application.GetRealWidth (10), |
| | | Y = btnChoose.Bottom, |
| | | Width = Application.GetRealWidth (75), |
| | | Height = Application.GetRealHeight (45), |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | SelectedTextColor = SkinStyle.Current.TextColor1, |
| | | Text = "OFF", |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | }; |
| | | DeviceRowView.AddChidren (btnFanLevel); |
| | | |
| | | var wi = Application.GetRealWidth (480 / 8); |
| | | for (int i = 0; i < 9; i++) { |
| | | var btnFanLevelTip = new Button () { |
| | | X = btnFanLevel.Right + wi * i - Application.GetRealWidth (0), |
| | | Y = btnFanLevel.Y - Application.GetRealHeight (5), |
| | | Width = wi, |
| | | Height = Application.GetRealHeight (27), |
| | | TextAlignment = TextAlignment.TopLeft, |
| | | Text = i.ToString (), |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | TextSize = 12, |
| | | }; |
| | | DeviceRowView.AddChidren (btnFanLevelTip); |
| | | if (i == 0) { |
| | | btnFanLevelTip.Text = "OFF"; |
| | | btnFanLevelTip.TextSize = 11; |
| | | } |
| | | } |
| | | |
| | | var fanLevel = new HorizontalSeekBar () { |
| | | X = btnFanLevel.Right, |
| | | Y = btnFanLevel.Y + Application.GetRealHeight (10), |
| | | Width = Application.GetRealWidth (492), |
| | | Height = Application.GetRealHeight (45), |
| | | ThumbColor = SkinStyle.Current.ThumbColor, |
| | | ProgressColor = SkinStyle.Current.SelectedColor, |
| | | ThumbRadius = Application.GetRealWidth (3), |
| | | Max = 8, |
| | | Progress = 2,// (int)(deviceCommon.SendBytes[1]), |
| | | |
| | | }; |
| | | DeviceRowView.AddChidren (fanLevel); |
| | | fanLevel.ProgressChanged += (sender, e) => { |
| | | try { |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | deviceCommon.SendBytes = new byte [] { deviceCommon.LoopID, (byte)(fanLevel.Progress) }; |
| | | if (timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath) == null) { |
| | | timerControlDeviceList.Add (deviceCommon); |
| | | } else { |
| | | timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath).SendBytes = new byte [] { deviceCommon.LoopID, (byte)fanLevel.Progress }; |
| | | } |
| | | if (e == 0) { |
| | | btnFanLevel.Text = "OFF"; |
| | | } else { |
| | | btnFanLevel.Text = "S" + e.ToString (); |
| | | } |
| | | } catch (Exception ex) { |
| | | Utlis.WriteLine ("ss1: " + ex.Message); |
| | | } |
| | | }; |
| | | |
| | | if (timerControlDevice != null) { |
| | | if (timerControlDevice.SendBytes [1] == 0) { |
| | | btnFanLevel.Text = "OFF"; |
| | | } else { |
| | | btnFanLevel.Text = "S" + timerControlDevice.SendBytes [1].ToString (); |
| | | } |
| | | fanLevel.Progress = timerControlDevice.SendBytes [1]; |
| | | } |
| | | |
| | | fanLevel.MouseDownEventHandler += (sss, ff) => { |
| | | try { |
| | | timerControlDevice = timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath); |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | if (timerControlDevice == null) { |
| | | deviceCommon.SendBytes = new byte [] { deviceCommon.LoopID, (byte)(fanLevel.Progress) }; |
| | | if (timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath) == null) { |
| | | timerControlDeviceList.Add (deviceCommon); |
| | | } else { |
| | | timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath).SendBytes = new byte [] { deviceCommon.LoopID, (byte)fanLevel.Progress }; |
| | | } |
| | | } |
| | | timerControlDevice.SendBytes [1] = (byte)fanLevel.Progress; |
| | | } catch { } |
| | | }; |
| | | |
| | | btnChoose.MouseUpEventHandler += (dds, ddss) => { |
| | | btnChoose.IsSelected = !btnChoose.IsSelected; |
| | | if (btnChoose.IsSelected) { |
| | | deviceCommon.SendBytes = new byte [] { deviceCommon.LoopID, (byte)(fanLevel.Progress) }; |
| | | if (timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath) == null) { |
| | | timerControlDeviceList.Add (deviceCommon); |
| | | } else { |
| | | timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath).SendBytes = new byte [] { deviceCommon.LoopID, (byte)fanLevel.Progress }; |
| | | } |
| | | } else { |
| | | timerControlDeviceList.Remove (timerControlDeviceList.Find ((obj) => obj.DeviceType == (int)deviceCommon.Type && |
| | | obj.SubnetID == deviceCommon.SubnetID && obj.DeviceID == deviceCommon.DeviceID && obj.LoopID == deviceCommon.LoopID)); |
| | | } |
| | | }; |
| | | |
| | | #endregion |
| | | } else if (deviceCommon.Type == DeviceType.LightDimming || deviceCommon.Type == DeviceType.LightDALI) { |
| | | switch (device.spk) { |
| | | //DeviceType.LightDALI |
| | | case SPK.LightDimming: { |
| | | #region 调光器A |
| | | tempSwitch.RemoveFromParent (); |
| | | |
| | | DeviceRowView.Height = Application.GetRealHeight (130); |
| | | deviceRowView.Height = Application.GetRealHeight (130); |
| | | btnChoose.Y = Application.GetRealHeight (20); |
| | | btnDeviceName.Y = Application.GetRealHeight (15); |
| | | |
| | |
| | | Text = "OFF", |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | }; |
| | | DeviceRowView.AddChidren (btnLevel); |
| | | deviceRowView.AddChidren (btnLevel); |
| | | |
| | | var levelBar = new HorizontalSeekBar () { |
| | | X = btnLevel.Right, |
| | |
| | | ThumbRadius = 6, |
| | | Max = 100, |
| | | }; |
| | | DeviceRowView.AddChidren (levelBar); |
| | | deviceRowView.AddChidren (levelBar); |
| | | |
| | | levelBar.ProgressChanged += (sender, e) => { |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | deviceCommon.SendBytes = new byte [] { deviceCommon.LoopID, (byte)levelBar.Progress }; |
| | | //timerControlDevice = deviceCommon; |
| | | if (timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath) == null) { |
| | | timerControlDeviceList.Add (deviceCommon); |
| | | } else { |
| | | timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath).SendBytes = new byte [] { deviceCommon.LoopID, (byte)levelBar.Progress }; |
| | | } |
| | | if (e == 0) { |
| | | btnLevel.Text = "OFF"; |
| | | } else { |
| | | btnLevel.Text = e.ToString () + "%"; |
| | | } |
| | | value = e.ToString (); |
| | | DeviceDateFun (btnChoose.Tag as Function, value, btnChoose.IsSelected); |
| | | }; |
| | | |
| | | btnChoose.MouseUpEventHandler += (dds, ddss) => { |
| | | btnChoose.IsSelected = !btnChoose.IsSelected; |
| | | DeviceDateFun (btnChoose.Tag as Function, "0", btnChoose.IsSelected); |
| | | }; |
| | | |
| | | if (timerControlDevice != null) { |
| | | if (timerControlDevice.SendBytes [1] == 0) { |
| | | btnLevel.Text = "OFF"; |
| | | } else { |
| | | btnLevel.Text = timerControlDevice.SendBytes [1].ToString () + "%"; |
| | | } |
| | | levelBar.Progress = timerControlDevice.SendBytes [1]; |
| | | } |
| | | |
| | | levelBar.MouseDownEventHandler += (sss, ff) => { |
| | | if (IsEdit) { |
| | | try { |
| | | timerControlDevice = timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath); |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | if (timerControlDevice == null) { |
| | | deviceCommon.SendBytes = new byte [] { deviceCommon.LoopID, (byte)(levelBar.Progress) }; |
| | | if (timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath) == null) { |
| | | timerControlDeviceList.Add (deviceCommon); |
| | | } else { |
| | | timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath).SendBytes = new byte [] { deviceCommon.LoopID, (byte)levelBar.Progress }; |
| | | var dev = selectedDeviceList.Find ((c) => c.deviceId == Int64.Parse (device.deviceId)); |
| | | if (dev != null) { |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | for (int a = 0; a < dev.attributes.Count; a++) { |
| | | var fundev = dev.attributes [a]; |
| | | if (fundev.key == "brightness") { |
| | | if (fundev.value == "0") { |
| | | btnLevel.Text = "OFF"; |
| | | } else { |
| | | btnLevel.Text = fundev.value + "%"; |
| | | } |
| | | levelBar.Progress = int.Parse (fundev.value); |
| | | } |
| | | } |
| | | } |
| | | } catch { } |
| | | }; |
| | | btnChoose.MouseUpEventHandler += (dds, ddss) => { |
| | | btnChoose.IsSelected = !btnChoose.IsSelected; |
| | | if (btnChoose.IsSelected) { |
| | | deviceCommon.SendBytes = new byte [] { deviceCommon.LoopID, (byte)(levelBar.Progress) }; |
| | | if (timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath) == null) { |
| | | timerControlDeviceList.Add (deviceCommon); |
| | | } else { |
| | | timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath).SendBytes = new byte [] { deviceCommon.LoopID, (byte)levelBar.Progress }; |
| | | } |
| | | } else { |
| | | timerControlDeviceList.Remove (timerControlDeviceList.Find ((obj) => obj.DeviceType == (int)deviceCommon.Type && |
| | | obj.SubnetID == deviceCommon.SubnetID && obj.DeviceID == deviceCommon.DeviceID && obj.LoopID == deviceCommon.LoopID)); |
| | | } |
| | | }; |
| | | } |
| | | #endregion |
| | | } else if (deviceCommon.Type == DeviceType.LightSwitch || deviceCommon.Type == DeviceType.LightEnergySwitch || deviceCommon.Type == DeviceType.LightEnergySocket || deviceCommon.Type == DeviceType.LightSwitchSocket) { |
| | | } |
| | | break; |
| | | //DeviceType.LightEnergySwitch |
| | | //DeviceType.LightEnergySocket |
| | | //DeviceType.LightSwitchSocket |
| | | case SPK.ElectricSocket: |
| | | case SPK.LightSwitch: { |
| | | #region 继电器 |
| | | //LightSwitch switchLight = deviceCommon as LightSwitch; |
| | | //tempSwitch.IsSelected = switchLight.CurrentBrightness == 100 ? true : false; |
| | | |
| | | tempSwitch.MouseUpEventHandler += (sender3, e3) => { |
| | | tempSwitch.IsSelected = !tempSwitch.IsSelected; |
| | | var CurrentBrightness = 0; |
| | | |
| | | if (tempSwitch.IsSelected) { |
| | | CurrentBrightness = 100; |
| | | value = "on"; |
| | | } else { |
| | | CurrentBrightness = 0; |
| | | value = "off"; |
| | | } |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | deviceCommon.SendBytes = new byte [] { deviceCommon.LoopID, (byte)CurrentBrightness }; |
| | | if (timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath) == null) { |
| | | timerControlDeviceList.Add (deviceCommon); |
| | | } else { |
| | | timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath).SendBytes = new byte [] { deviceCommon.LoopID, (byte)CurrentBrightness }; |
| | | } |
| | | DeviceDateFun (btnChoose.Tag as Function, value, btnChoose.IsSelected); |
| | | |
| | | }; |
| | | if (timerControlDevice != null) { |
| | | try { |
| | | tempSwitch.IsSelected = timerControlDevice.SendBytes [1] == 100; |
| | | } catch { } |
| | | } |
| | | |
| | | btnChoose.MouseUpEventHandler += (dds, ddss) => { |
| | | btnChoose.IsSelected = !btnChoose.IsSelected; |
| | | if (btnChoose.IsSelected) { |
| | | var CurrentBrightness = 0; |
| | | if (tempSwitch.IsSelected) { |
| | | CurrentBrightness = 100; |
| | | } else { |
| | | CurrentBrightness = 0; |
| | | } |
| | | deviceCommon.SendBytes = new byte [] { deviceCommon.LoopID, (byte)CurrentBrightness }; |
| | | if (timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath) == null) |
| | | timerControlDeviceList.Add (deviceCommon); |
| | | else { |
| | | timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath).SendBytes = new byte [] { deviceCommon.LoopID, (byte)CurrentBrightness }; |
| | | } |
| | | if (tempSwitch.IsSelected) { |
| | | value = "on"; |
| | | } else { |
| | | timerControlDeviceList.Remove (timerControlDeviceList.Find ((obj) => obj.DeviceType == (int)deviceCommon.Type && |
| | | obj.SubnetID == deviceCommon.SubnetID && obj.DeviceID == deviceCommon.DeviceID && obj.LoopID == deviceCommon.LoopID)); |
| | | value = "off"; |
| | | } |
| | | DeviceDateFun (btnChoose.Tag as Function, value, btnChoose.IsSelected); |
| | | |
| | | }; |
| | | |
| | | if (IsEdit) { |
| | | try { |
| | | var dev = selectedDeviceList.Find ((c) => c.deviceId == Int64.Parse (device.deviceId)); |
| | | if (dev != null) { |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | for (int a = 0; a < dev.attributes.Count; a++) { |
| | | var fundev = dev.attributes [a]; |
| | | if (fundev.value == "on") { |
| | | tempSwitch.IsSelected = true; |
| | | } else { |
| | | tempSwitch.IsSelected = false; |
| | | } |
| | | } |
| | | } |
| | | } catch { } |
| | | } |
| | | #endregion |
| | | } else if (deviceCommon.Type == DeviceType.CurtainModel || deviceCommon.Type == DeviceType.CurtainTrietex || deviceCommon.Type == DeviceType.CurtainRoller) { |
| | | } |
| | | break; |
| | | case SPK.CurtainRoller: |
| | | case SPK.CurtainTrietex: |
| | | case SPK.CurtainSwitch: { |
| | | #region 窗帘 |
| | | //2020-07-09 刷新控制操作码 |
| | | deviceCommon.Command = (int)Command.UpdataCurtainModelStutas; |
| | | tempSwitch.RemoveFromParent (); |
| | | var tempSwitch1 = new Button () { |
| | | Width = Application.GetMinRealAverage (90), |
| | | Height = Application.GetMinRealAverage (53), |
| | | Width = Application.GetRealWidth (90), |
| | | Height = Application.GetRealWidth (53), |
| | | X = Application.GetRealWidth (640 - 90 - 20), |
| | | Radius = 5, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | |
| | | BackgroundColor = SkinStyle.Current.ButtonColor, |
| | | SelectedBackgroundColor = SkinStyle.Current.SelectedColor, |
| | | Text = "CLOSE", |
| | | Tag = deviceCommon.CommonLoopID, |
| | | Tag = device, |
| | | }; |
| | | DeviceRowView.AddChidren (tempSwitch1); |
| | | |
| | | deviceRowView.AddChidren (tempSwitch1); |
| | | |
| | | tempSwitch1.MouseUpEventHandler += (sender3, e3) => { |
| | | tempSwitch1.IsSelected = !tempSwitch1.IsSelected; |
| | | |
| | | var CurrentBrightness = 0; |
| | | if (tempSwitch1.IsSelected) { |
| | | CurrentBrightness = 1; |
| | | value = "on"; |
| | | tempSwitch1.Text = "OPEN"; |
| | | tempSwitch1.BackgroundColor = SkinStyle.Current.SelectedColor; |
| | | } else { |
| | | CurrentBrightness = 2; |
| | | value = "off"; |
| | | tempSwitch1.Text = "CLOSE"; |
| | | tempSwitch1.BackgroundColor = SkinStyle.Current.ButtonColor; |
| | | } |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | deviceCommon.SendBytes = new byte [] { deviceCommon.LoopID, (byte)CurrentBrightness }; |
| | | //2020-07-09 |
| | | DeviceInfo mDeviceInfo = timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath); |
| | | if (mDeviceInfo == null) { |
| | | timerControlDeviceList.Add (deviceCommon); |
| | | } else { |
| | | mDeviceInfo.Command = (int)Command.UpdataCurtainModelStutas; |
| | | mDeviceInfo.SendBytes = new byte [] { deviceCommon.LoopID, (byte)CurrentBrightness }; |
| | | } |
| | | }; |
| | | DeviceDateFun (btnChoose.Tag as Function, value, btnChoose.IsSelected); |
| | | |
| | | if (timerControlDevice != null) { |
| | | try { |
| | | if (timerControlDevice.SendBytes [1] == 1) { |
| | | tempSwitch1.Text = "OPEN"; |
| | | tempSwitch1.IsSelected = true; |
| | | tempSwitch1.BackgroundColor = SkinStyle.Current.SelectedColor; |
| | | } else { |
| | | tempSwitch1.Text = "CLOSE"; |
| | | tempSwitch1.IsSelected = false; |
| | | tempSwitch1.BackgroundColor = SkinStyle.Current.ButtonColor; |
| | | } |
| | | } catch { } |
| | | } |
| | | |
| | | }; |
| | | |
| | | btnChoose.MouseUpEventHandler += (dds, ddss) => { |
| | | btnChoose.IsSelected = !btnChoose.IsSelected; |
| | | if (btnChoose.IsSelected) { |
| | | var CurrentBrightness = 0; |
| | | if (tempSwitch.IsSelected) { |
| | | CurrentBrightness = 1; |
| | | } else { |
| | | CurrentBrightness = 2; |
| | | } |
| | | deviceCommon.SendBytes = new byte [] { deviceCommon.LoopID, (byte)CurrentBrightness }; |
| | | |
| | | //if (timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath) == null) { |
| | | // timerControlDeviceList.Add (deviceCommon); |
| | | //} else { |
| | | // timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath).SendBytes = new byte [] { deviceCommon.LoopID, (byte)CurrentBrightness }; |
| | | //} |
| | | |
| | | //2020-07-09 |
| | | DeviceInfo mDeviceInfo = timerControlDeviceList.Find ((obj) => obj.DevicePath == deviceCommon.SavePath); |
| | | if (mDeviceInfo == null) { |
| | | timerControlDeviceList.Add (deviceCommon); |
| | | } else { |
| | | mDeviceInfo.Command = (int)Command.UpdataCurtainModelStutas; |
| | | mDeviceInfo.SendBytes = new byte [] { deviceCommon.LoopID, (byte)CurrentBrightness }; |
| | | } |
| | | if (tempSwitch1.IsSelected) { |
| | | value = "on"; |
| | | } else { |
| | | timerControlDeviceList.Remove (timerControlDeviceList.Find ((obj) => obj.DeviceType == (int)deviceCommon.Type && |
| | | obj.SubnetID == deviceCommon.SubnetID && obj.DeviceID == deviceCommon.DeviceID && obj.LoopID == deviceCommon.LoopID)); |
| | | value = "off"; |
| | | } |
| | | DeviceDateFun (btnChoose.Tag as Function, value, btnChoose.IsSelected); |
| | | }; |
| | | |
| | | if (IsEdit) { |
| | | try { |
| | | var dev = selectedDeviceList.Find ((c) => c.deviceId == Int64.Parse (device.deviceId)); |
| | | if (dev != null) { |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | for (int a = 0; a < dev.attributes.Count; a++) { |
| | | var fundev = dev.attributes [a]; |
| | | if (fundev.value == "on") { |
| | | tempSwitch1.IsSelected = true; |
| | | tempSwitch1.Text = "OPEN"; |
| | | } else { |
| | | tempSwitch1.IsSelected = false; |
| | | tempSwitch1.Text = "CLOSE"; |
| | | } |
| | | } |
| | | } |
| | | } catch { } |
| | | } |
| | | #endregion |
| | | } |
| | | }catch(Exception ex) { |
| | | Utlis.WriteLine ("AddSchedule error : "+ ex.Message); |
| | | break; |
| | | case SPK.ElectricFan: { |
| | | #region 风扇 |
| | | tempSwitch.RemoveFromParent (); |
| | | deviceRowView.Height = Application.GetRealHeight (130); |
| | | btnChoose.Y = Application.GetRealHeight (5); |
| | | btnDeviceName.Y = Application.GetRealHeight (0); |
| | | |
| | | var btnFanLevel = new Button () { |
| | | X = btnChoose.X + Application.GetRealWidth (10), |
| | | Y = btnChoose.Bottom, |
| | | Width = Application.GetRealWidth (75), |
| | | Height = Application.GetRealHeight (45), |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | SelectedTextColor = SkinStyle.Current.TextColor1, |
| | | Text = "OFF", |
| | | //Text = "", |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | }; |
| | | deviceRowView.AddChidren (btnFanLevel); |
| | | |
| | | var wi = Application.GetRealWidth (480 / 8); |
| | | for (int a = 0; a < 9; a++) { |
| | | var btnFanLevelTip = new Button () { |
| | | X = btnFanLevel.Right + wi * a - Application.GetRealWidth (0), |
| | | Y = btnFanLevel.Y - Application.GetRealHeight (5), |
| | | Width = wi, |
| | | Height = Application.GetRealHeight (27), |
| | | TextAlignment = TextAlignment.TopLeft, |
| | | Text = a.ToString (), |
| | | TextColor = SkinStyle.Current.TextColor1, |
| | | TextSize = 12, |
| | | }; |
| | | deviceRowView.AddChidren (btnFanLevelTip); |
| | | if (a == 0) { |
| | | btnFanLevelTip.Text = "OFF"; |
| | | btnFanLevelTip.TextSize = 11; |
| | | } |
| | | } |
| | | var fanLevel = new HorizontalSeekBar () { |
| | | X = btnFanLevel.Right, |
| | | Y = btnFanLevel.Y + Application.GetRealHeight (10), |
| | | Width = Application.GetRealWidth (492), |
| | | Height = Application.GetRealHeight (45), |
| | | ThumbColor = SkinStyle.Current.ThumbColor, |
| | | ProgressColor = SkinStyle.Current.SelectedColor, |
| | | ThumbRadius = Application.GetRealWidth (3), |
| | | Max = 8, |
| | | Progress = 2, |
| | | |
| | | }; |
| | | deviceRowView.AddChidren (fanLevel); |
| | | //刚开始默认显示1档 |
| | | value = "2"; |
| | | SetFanButtonState (btnFanLevel, value); |
| | | |
| | | fanLevel.ProgressChanged += (sender, e) => { |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | value = e.ToString (); |
| | | //if (value == "0") { |
| | | // btnFanLevel.Text = "OFF"; |
| | | //} else { |
| | | // btnFanLevel.Text = value; |
| | | //} |
| | | |
| | | SetFanButtonState (btnFanLevel, value); |
| | | |
| | | DeviceDateFun (btnChoose.Tag as Function, value, btnChoose.IsSelected); |
| | | }; |
| | | |
| | | btnChoose.MouseUpEventHandler += (dds, ddss) => { |
| | | btnChoose.IsSelected = !btnChoose.IsSelected; |
| | | DeviceDateFun (btnChoose.Tag as Function, value, btnChoose.IsSelected); |
| | | }; |
| | | if (IsEdit) { |
| | | try { |
| | | var dev = selectedDeviceList.Find ((c) => c.deviceId == Int64.Parse (device.deviceId)); |
| | | if (dev != null) { |
| | | if (!btnChoose.IsSelected) { |
| | | btnChoose.IsSelected = true; |
| | | } |
| | | for (int a = 0; a < dev.attributes.Count; a++) { |
| | | var fundev = dev.attributes [a]; |
| | | if (fundev.key == "fan_speed_percent") { |
| | | fanLevel.Progress = int.Parse (fundev.value); |
| | | //if (fundev.value == "0") { |
| | | // btnFanLevel.Text = "OFF"; |
| | | //} else { |
| | | // btnFanLevel.Text = fundev.value; |
| | | //} |
| | | SetFanButtonState (btnFanLevel, fundev.value); |
| | | } |
| | | } |
| | | } |
| | | } catch { } |
| | | } |
| | | #endregion |
| | | } |
| | | break; |
| | | } |
| | | }); |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } catch (Exception ex) { |
| | | Utlis.WriteLine ("AddSchedule error : " + ex.Message); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | } catch (Exception ex) { |
| | | Utlis.WriteLine (ex.Message); |
| | | } finally { |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="btnFanLevel"></param> |
| | | /// <param name="value"></param> |
| | | void SetFanButtonState (Button btnFanLevel, string value) |
| | | { |
| | | if (btnFanLevel == null) return; |
| | | |
| | | if (value == "0") { |
| | | btnFanLevel.Text = "OFF"; |
| | | } else { |
| | | btnFanLevel.Text = value; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设备数据转换 |
| | | /// </summary> |
| | | /// <param name="function"></param> |
| | | /// <param name="value">开关状态值</param> |
| | | /// <param name="isSelected">判断控件点击状态</param> |
| | | public void DeviceDateFun (Function function, string value, bool isSelected) |
| | | { |
| | | string keyValue = ""; |
| | | switch (function.spk) { |
| | | case SPK.CurtainTrietex: |
| | | case SPK.CurtainRoller: |
| | | case SPK.LightSwitch: |
| | | case SPK.CurtainSwitch: |
| | | case SPK.ElectricSocket: { |
| | | keyValue = "on_off"; |
| | | } |
| | | break; |
| | | case SPK.LightDimming: { |
| | | keyValue = "brightness"; |
| | | } |
| | | break; |
| | | case SPK.ElectricFan: { |
| | | keyValue = "fan_speed_percent"; |
| | | } |
| | | break; |
| | | |
| | | } |
| | | Fun fun = new Fun (); |
| | | fun.deviceId = Int64.Parse (function.deviceId); |
| | | fun.spk = function.spk; |
| | | fun.attributes.Add (new Attributes { key = keyValue, value = value }); |
| | | fun.bus.addresses = function.bus.addresses; |
| | | fun.bus.loopId = function.bus.loopId; |
| | | AddDeviceList (fun, isSelected); |
| | | } |
| | | /// <summary> |
| | | /// 添加设备数据到列表里 |
| | | /// </summary> |
| | | /// <param name="fun"></param> |
| | | /// <param name="isSelected">判断控件点击状态</param> |
| | | public void AddDeviceList (Fun fun, bool isSelected) |
| | | { |
| | | |
| | | switch (fun.spk) { |
| | | case SPK.LightDimming: { |
| | | //调光做了一个特殊处理; |
| | | if (fun.attributes.Count == 1) { |
| | | var dic = fun.attributes [0]; |
| | | if (dic.key == "brightness") { |
| | | Attributes attributes = new Attributes (); |
| | | attributes.key = "on_off"; |
| | | if (dic.value == "0") { |
| | | attributes.value = "off"; |
| | | } else { |
| | | attributes.value = "on"; |
| | | } |
| | | fun.attributes.Add (attributes); |
| | | } |
| | | |
| | | } |
| | | break; |
| | | } |
| | | case SPK.ElectricFan: { |
| | | if (fun.attributes.Count == 1) { |
| | | var dic = fun.attributes [0]; |
| | | if (dic.key == "fan_speed_percent") { |
| | | Attributes attributes = new Attributes (); |
| | | attributes.key = "on_off"; |
| | | if (dic.value == "0") { |
| | | attributes.value = "off"; |
| | | } else { |
| | | attributes.value = "on"; |
| | | } |
| | | fun.attributes.Add (attributes); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | var device = selectedDeviceList.Find ((dev) => dev.deviceId == fun.deviceId); |
| | | if (device != null) { |
| | | selectedDeviceList.Remove (device); |
| | | } |
| | | if (isSelected) { |
| | | selectedDeviceList.Add (fun); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |