| | |
| | | using System; |
| | | using HDL_ON.UI.UI2.Intelligence.Automation.LogicView; |
| | | using Shared; |
| | | using System.Collections.Generic; |
| | | using Newtonsoft.Json.Linq; |
| | | |
| | | namespace HDL_ON.UI.UI2.Intelligence.Automation |
| | | { |
| | | public class MainView |
| | | { |
| | | //public MainView(FrameLayout layout) |
| | | //{ |
| | | // automationPage = layout; |
| | | //} |
| | | //public static FrameLayout automationPage; |
| | | |
| | | public static void MainShow(FrameLayout automationPage) |
| | | /// <summary> |
| | | /// 记录逻辑自动化父控件 |
| | | /// </summary> |
| | | public static FrameLayout automationPage; |
| | | /// <summary> |
| | | /// 加载逻辑列表显示界面 |
| | | /// </summary> |
| | | public static void MainShow() |
| | | { |
| | | automationPage.RemoveAll(); |
| | | VerticalScrolViewLayout vv = new VerticalScrolViewLayout(); |
| | | VerticalRefreshLayout vv = new VerticalRefreshLayout(); |
| | | vv.Height = Application.GetRealHeight(667 - 64 - 49);//模拟高度 |
| | | automationPage.AddChidren(vv); |
| | | |
| | | for (int i = 0; i < 2; i++) |
| | | vv.BeginHeaderRefreshingAction += () => |
| | | { |
| | | Logic.LogicList.Add(new Logic { name = "123456" }); |
| | | } |
| | | |
| | | //清除之前自动化列表; |
| | | Logic.LogicList.Clear(); |
| | | //获取自动列表 |
| | | GetLogicList(); |
| | | //刷新自动化界面 |
| | | MainShow(); |
| | | //关闭刷新View; |
| | | vv.EndHeaderRefreshing(); |
| | | }; |
| | | //获取自动化列表 |
| | | GetLogicList(); |
| | | // for (int i = Logic.LogicList.Count-1; i >= 0; i--)降序排列 |
| | | for (int i = 0; i < Logic.LogicList.Count; i++) |
| | | { |
| | | var currLogic = Logic.LogicList[i]; |
| | | ///上下间隔12像素 |
| | | vv.AddChidren(new FrameLayout { Height = Application.GetRealHeight(12) }); |
| | | LogicView.SingleLogicView logicView = new LogicView.SingleLogicView(); |
| | | vv.AddChidren(logicView.FLayoutView()); |
| | | logicView.btnLogicName.Text = i.ToString(); |
| | | logicView.btnWeekText.Text = "每天"; |
| | | logicView.btnLogicName.Text = currLogic.name; |
| | | logicView.btnWeekText.Text = GetWeekText(currLogic); |
| | | logicView.btnclick.MouseUpEventHandler += (sen, e) => |
| | | { |
| | | Logic.currlogic = currLogic; |
| | | var addLogic = new AddLogic(); |
| | | MainPage.BasePageView.AddChidren(addLogic); |
| | | addLogic.Show(); |
| | | MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; |
| | | }; |
| | | logicView.btnSwitchIcon.MouseUpEventHandler += (sender1, e1) => |
| | | { |
| | | logicView.btnSwitchIcon.IsSelected = !logicView.btnSwitchIcon.IsSelected; |
| | | if (logicView.btnSwitchIcon.IsSelected) |
| | | { |
| | | logicView.btnSwitchIcon.IsSelected = true; |
| | | currLogic.enable = "true"; |
| | | |
| | | |
| | | } |
| | | else |
| | | { |
| | | logicView.btnSwitchIcon.IsSelected = false; |
| | | currLogic.enable = "false"; |
| | | } |
| | | Send.switchLogic(currLogic); |
| | | |
| | | }; |
| | | //if (i==0)降序排列 |
| | | if (Logic.LogicList.Count - 1 == i) |
| | | { |
| | | ///最后一个距离最底部12,界面显示效果作用; |
| | | vv.AddChidren(new FrameLayout { Height = Application.GetRealHeight(12) }); |
| | | } |
| | | if (currLogic.enable == "true") |
| | | { |
| | | logicView.btnSwitchIcon.IsSelected = true; |
| | | } |
| | | else |
| | | { |
| | | logicView.btnSwitchIcon.IsSelected = false; |
| | | } |
| | | } |
| | | |
| | | if (Logic.LogicList.Count == 0) |
| | |
| | | automationPage.AddChidren(btnTipNotText); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 按+跳转到逻辑界面的方法 |
| | | /// </summary> |
| | | public static void SkipAddLogicPage() |
| | | { |
| | | Logic.currlogic = new Logic(); |
| | | var addLogic = new AddLogic(); |
| | | MainPage.BasePageView.AddChidren(addLogic); |
| | | addLogic.Show(); |
| | | MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; |
| | | } |
| | | /// <summary> |
| | | ///返回循环描述文本 |
| | | /// </summary> |
| | | /// <param name="logic"></param> |
| | | public static string GetWeekText(Logic logic) |
| | | { |
| | | |
| | | string weekName = ""; |
| | | /// (执行一次:once,每天:day,每月:mon,星期:week,日期段:date_to_date) |
| | | switch (logic.cycle.type) |
| | | { |
| | | case "once": |
| | | { |
| | | weekName = Language.StringByID(StringId.performA); |
| | | } |
| | | break; |
| | | case "day": |
| | | { |
| | | weekName = Language.StringByID(StringId.days); |
| | | } |
| | | break; |
| | | case "week": |
| | | { |
| | | |
| | | weekName = GetWeekString(logic.cycle.value); |
| | | |
| | | } |
| | | break; |
| | | case "mon": |
| | | { |
| | | weekName = GetMonString(logic.cycle.value); |
| | | } |
| | | break; |
| | | } |
| | | return weekName; |
| | | } |
| | | /// <summary> |
| | | /// 获取星期的字符串 |
| | | /// </summary> |
| | | /// <param name="weekList"></param> |
| | | /// <returns></returns> |
| | | public static string GetWeekString(List<string> weekList) |
| | | { |
| | | string weekTextName = ""; |
| | | |
| | | if (weekList.Contains("0")) |
| | | { |
| | | weekTextName += Language.StringByID(StringId.monday) + ","; |
| | | } |
| | | if (weekList.Contains("1")) |
| | | { |
| | | weekTextName += Language.StringByID(StringId.tuesday) + ","; |
| | | } |
| | | if (weekList.Contains("2")) |
| | | { |
| | | weekTextName += Language.StringByID(StringId.wednesday) + ","; |
| | | } |
| | | if (weekList.Contains("3")) |
| | | { |
| | | weekTextName += Language.StringByID(StringId.thursday) + ","; |
| | | } |
| | | if (weekList.Contains("4")) |
| | | { |
| | | weekTextName += Language.StringByID(StringId.friday) + ","; |
| | | } |
| | | if (weekList.Contains("5")) |
| | | { |
| | | weekTextName += Language.StringByID(StringId.saturday) + ","; |
| | | } |
| | | if (weekList.Contains("6")) |
| | | { |
| | | weekTextName += Language.StringByID(StringId.sunday) + ","; |
| | | } |
| | | if (weekTextName == "") |
| | | { |
| | | return ""; |
| | | } |
| | | return weekTextName.TrimEnd(','); |
| | | } |
| | | /// <summary> |
| | | /// 获取每月的字符串 |
| | | /// </summary> |
| | | /// <param name="monList"></param> |
| | | /// <returns></returns> |
| | | public static string GetMonString(List<string> monList) |
| | | { |
| | | string monTextName = Language.StringByID(StringId.monthly); |
| | | |
| | | for (int i = 1; i < 32; i++) |
| | | { |
| | | if (monList.Contains(i.ToString())) |
| | | { |
| | | monTextName += i.ToString() + ","; |
| | | } |
| | | } |
| | | return monTextName.TrimEnd(','); |
| | | } |
| | | /// <summary> |
| | | /// 获取逻辑列表 |
| | | /// </summary> |
| | | private static void GetLogicList() |
| | | { |
| | | |
| | | if (Logic.LogicList.Count != 0) |
| | | { |
| | | //自动化列表为0才去获取自动化列表; |
| | | return; |
| | | } |
| | | List<string> logicIdList = new List<string>(); |
| | | //获取逻辑ID列表 |
| | | var idStr = Send.getLogicIdList(); |
| | | if (idStr.Code == "0" && idStr.Data != null) |
| | | { |
| | | var date = Newtonsoft.Json.JsonConvert.SerializeObject(idStr.Data); |
| | | var dateList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Date>>(date); |
| | | for (int i = 0; i < dateList.Count; i++) |
| | | { |
| | | //添加逻辑ID |
| | | logicIdList.Add(dateList[i].userLogicId); |
| | | } |
| | | } |
| | | //获取自动化列表 |
| | | var logicStr = Send.getLogic(logicIdList); |
| | | if (logicStr.Code == "0" && logicStr.Data != null) |
| | | { |
| | | //获取逻辑详细返回是一个数组(object类型转换为数组); |
| | | var jArray = JArray.Parse(logicStr.Data.ToString()); |
| | | for (int a = 0; a < jArray.Count; a++) |
| | | { |
| | | var jay = jArray[a]; |
| | | //数据返序列化为Logic对象 |
| | | var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay); |
| | | var logic = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic>(str); |
| | | if (logic != null) |
| | | { |
| | | //查找是否已经存在该逻辑 |
| | | var if_logic = Logic.LogicList.Find((c) => c.userLogicId == logic.userLogicId); |
| | | if (if_logic == null) |
| | | { |
| | | //添加逻辑 |
| | | Logic.LogicList.Add(logic); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 判断JObject对象是存在健值 |
| | | /// </summary> |
| | | /// <param name="jObject"></param> |
| | | /// <param name="key"></param> |
| | | /// <returns></returns> |
| | | private bool Exist(JObject jObject, string key) |
| | | { |
| | | |
| | | if (jObject.Property(key) != null) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | class Date |
| | | { |
| | | /// <summary> |
| | | /// 云端唯一id |
| | | /// </summary> |
| | | public string userLogicId = ""; |
| | | public string gatewayId = ""; |
| | | /// <summary> |
| | | /// 逻辑唯一标识 |
| | | /// </summary> |
| | | public string sid = ""; |
| | | public string name = ""; |
| | | public string enable = ""; |
| | | //public CycleA cycle; |
| | | //public string modifyTime = ""; |
| | | } |
| | | |
| | | class CycleA |
| | | { |
| | | public string type = ""; |
| | | public string[] value; |
| | | } |
| | | } |