using System;
|
using System.Collections.Generic;
|
using Newtonsoft.Json.Linq;
|
using Shared;
|
using Shared.Common;
|
using Shared.Phone;
|
using Shared.Phone.Device.Logic.LogicView;
|
using Shared.R;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.Device.Logic
|
{
|
public class OneLogic : FrameLayout
|
{
|
|
public OneLogic()
|
{
|
UserView.HomePage.Instance.RemoveViewByTag("Logic");
|
Tag = "Logic";
|
}
|
/// <summary>
|
/// S-one门锁特殊界面
|
/// </summary>
|
/// <param name="Yes"></param>
|
public void Show(bool Yes)
|
{
|
#region View布局代码
|
UserView.HomePage.Instance.ScrollEnabled = false;
|
TopView view = new TopView();
|
this.AddChidren(view.TopRowView());
|
|
if (Yes)
|
{
|
view.toptitleNameBtn.Text = Language.StringByID(MyInternationalizationString.look);
|
}
|
else
|
{
|
if (Common.Logic.CurrentLogic.LogicId != 0)
|
{
|
view.toptitleNameBtn.Text = Language.StringByID(MyInternationalizationString.editautomation);
|
}
|
else
|
{
|
view.toptitleNameBtn.Text = Language.StringByID(MyInternationalizationString.newautomation);
|
}
|
}
|
|
view.clickBtn.MouseDownEventHandler += (sender, e) =>
|
{
|
UserView.HomePage.Instance.ScrollEnabled = true;//恢复左滑
|
RemoveFromParent();
|
};
|
var middle = new VerticalScrolViewLayout
|
{
|
Y = view.topRowLayout.Bottom,
|
Height = Application.GetRealHeight(Method.H - 184 - 180),
|
BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
|
};
|
this.AddChidren(middle);
|
var saveBtn = new SaveView();
|
saveBtn.frameLayout.Y = middle.Bottom;
|
saveBtn.frameLayout.Height = Application.GetRealHeight(180);
|
this.AddChidren(saveBtn.Show());
|
#endregion
|
|
#region -----自动化名称 设置名称-----
|
var logicnamefl = new FrameLayout
|
{
|
Height = Application.GetRealHeight(130),
|
BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
|
};
|
middle.AddChidren(logicnamefl);
|
|
var text = new Button
|
{
|
Width = Application.GetRealWidth(300),
|
Height = Application.GetRealHeight(60),
|
X = Application.GetRealWidth(58),
|
TextAlignment = TextAlignment.CenterLeft,
|
//Text = "自动化名称",
|
TextID = MyInternationalizationString.automationname,
|
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
|
Y = Application.GetRealHeight(35),
|
TextSize = 15,
|
};
|
logicnamefl.AddChidren(text);
|
|
var logicTextBox = new EditText
|
{
|
Y = Application.GetRealHeight(35),
|
Width = Application.GetRealWidth(1080 - 58 - 300),
|
Height = Application.GetRealHeight(60),
|
X = text.Right,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = ZigbeeColor.Current.LogicBtnCancelColor,
|
TextSize = 14,
|
Text = Common.Logic.CurrentLogic.LogicName,
|
//TextID=MyInternationalizationString.automation1,
|
};
|
logicnamefl.AddChidren(logicTextBox);
|
if (Yes)
|
{
|
//S-one门锁特殊,不能再次编辑;
|
logicTextBox.Enable = false;
|
}
|
var fraline = new FrameLayout
|
{
|
Height = Application.GetRealHeight(30),
|
};
|
middle.AddChidren(fraline);
|
#endregion
|
|
#region -----显示逻辑条件-----
|
Addview addconditionview = new Addview();
|
addconditionview.iconBtn.Visible = false;
|
addconditionview.titleBtn.TextID = MyInternationalizationString.ifcondition;
|
middle.AddChidren(addconditionview.AddDeviceView());
|
|
///添加条件的点击事件
|
for (int i = 0; i < Common.Logic.CurrentLogic.Conditions.Count; i++)
|
{
|
SelectedDeviceView selecteddevice = new SelectedDeviceView();
|
selecteddevice.Show(middle);
|
if (!Yes)
|
{
|
//S-one门锁特殊,不能再次编辑;
|
selecteddevice.stateRow.AddRightView(selecteddevice.edit);
|
}
|
var Type = int.Parse(Common.Logic.CurrentLogic.Conditions[i]["Type"]);
|
var conditions = Common.Logic.CurrentLogic.Conditions[i];
|
switch (Type)
|
{
|
case 0:
|
{
|
|
//"0正常时间点","1日出时间","2日落时间","3正午时间"
|
switch (int.Parse(conditions["DateType"]))
|
{
|
case 0:
|
{
|
selecteddevice.ordinaryBtn.Text = Language.StringByID(MyInternationalizationString.immediateexecution);
|
selecteddevice.iconBtn.UnSelectedImagePath = "ZigeeLogic/timepoint.png";
|
string s = "";
|
s = conditions["StartMin"].Length < 2 ? "0" + conditions["StartMin"] : conditions["StartMin"];
|
selecteddevice.selecetddevicestateBtn.Text= conditions["StartHour"] + ":" + s;
|
}
|
break;
|
}
|
|
}
|
break;
|
}
|
if (Yes)
|
{
|
//改变字体颜色;
|
selecteddevice.ordinaryBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
|
selecteddevice.selecetddevicestateBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
|
}
|
///编辑
|
selecteddevice.edit.MouseUpEventHandler += (sender, e) =>
|
{
|
if (Type == 0)
|
{
|
var oneTimePoint = new OneTimePoint();
|
UserView.HomePage.Instance.AddChidren(oneTimePoint);
|
UserView.HomePage.Instance.PageIndex += 1;
|
oneTimePoint.Show((timeString) =>
|
{
|
if (!string.IsNullOrEmpty(timeString))
|
{
|
//编辑完回来先更新时间
|
selecteddevice.selecetddevicestateBtn.Text = timeString;
|
}
|
});
|
}
|
};
|
|
}
|
#endregion
|
|
#region ----显示执行目标----
|
Addview addactionview = new Addview();
|
addactionview.iconBtn.Visible = false;
|
addactionview.titleBtn.TextID = MyInternationalizationString.execute;
|
middle.AddChidren(addactionview.AddDeviceView());
|
|
for (int i = 0; i < Common.Logic.CurrentLogic.Actions.Count; i++)
|
{
|
SelectedDeviceView actiondevice = new SelectedDeviceView();
|
actiondevice.Show(middle);
|
if (!Yes)
|
{
|
//S-one门锁特殊,不能再次编辑;
|
actiondevice.stateRow.AddRightView(actiondevice.edit);
|
}
|
var linkType = int.Parse(Common.Logic.CurrentLogic.Actions[i]["LinkType"].ToString());
|
var actions = Common.Logic.CurrentLogic.Actions[i];
|
switch (linkType)
|
{
|
case 8:
|
{
|
//S-one门锁特殊(Mac是唯一的识别)
|
///如果不这样查找,分类-自动化进来查看会存在问题
|
var deviceinof = Common.Logic.LogicDviceList.Find((obj) => { return obj.DeviceAddr == actions["DeviceAddr"].ToString(); });
|
if (deviceinof == null)
|
{
|
deviceinof = new CommonDevice();
|
}
|
actiondevice.deviceNameBtn.Text = HdlDeviceCommonLogic.Current.GetDeviceEpointName(deviceinof);
|
actiondevice.deviceNameBtn.Visible = true;
|
actiondevice.regionNameBtn.Visible = true;
|
Method.RoomNmae(actiondevice.regionNameBtn, deviceinof);
|
|
if (Yes) {
|
//改变字体颜色;
|
actiondevice.deviceNameBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
|
actiondevice.regionNameBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
|
actiondevice.selecetddevicestateBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
|
}
|
switch (deviceinof.Type)
|
{
|
case DeviceType.DoorLock:
|
{
|
//门锁特殊
|
actiondevice.iconBtn.UnSelectedImagePath = "ZigeeLogic/doorlock.png";
|
if (actions["PassData"].ToString() == "055704010112")
|
{
|
actiondevice.selecetddevicestateBtn.Text = Language.StringByID(MyInternationalizationString.logicopen);
|
}
|
else
|
{
|
actiondevice.selecetddevicestateBtn.Text = Language.StringByID(MyInternationalizationString.logicclose);
|
}
|
}
|
break;
|
}
|
|
}
|
break;
|
|
}
|
///编辑
|
actiondevice.edit.MouseUpEventHandler += (sender, e) =>
|
{
|
switch (linkType)
|
{
|
case 8:
|
{
|
//S-one门锁特殊(Mac是唯一的识别)
|
///如果不这样查找,分类-自动化进来查看会存在问题
|
var deviceinof = Common.Logic.LogicDviceList.Find((obj) => { return obj.DeviceAddr == actions["DeviceAddr"].ToString(); });
|
if (deviceinof == null)
|
{
|
deviceinof = new CommonDevice();
|
}
|
DevcieView(deviceinof, actiondevice.selecetddevicestateBtn);
|
};
|
break;
|
|
|
}
|
};
|
|
}
|
#endregion
|
|
#region -----每天 设置周期-----
|
|
var fraline1 = new FrameLayout
|
{
|
Height = Application.GetRealHeight(30),
|
};
|
middle.AddChidren(fraline1);
|
|
Addview weekview = new Addview();
|
weekview.iconBtn.Visible = true;
|
weekview.iconBtn.UnSelectedImagePath = "ZigeeLogic/next.png";
|
weekview.titleBtn.TextID = MyInternationalizationString.setupcycle;
|
middle.AddChidren(weekview.AddDeviceView());
|
var weekBtn = new Button
|
{
|
Width = Application.GetRealWidth(595),
|
Height = Application.GetRealHeight(60),
|
TextAlignment = TextAlignment.CenterRight,
|
//Text = "每天",
|
TextColor = ZigbeeColor.Current.LogicBtnCancelColor,
|
TextID = MyInternationalizationString.everyday,
|
Y = Application.GetRealHeight(35 + 30),
|
X = weekview.titleBtn.Right,
|
TextSize = 14,
|
};
|
weekview.frameLayout.AddChidren(weekBtn);
|
Method.UpdateWeek(weekBtn, Common.Logic.CurrentLogic);
|
EventHandler<MouseEventArgs> cycleclick = (sender, e) =>
|
{
|
if (Yes) {
|
//S-one门锁特殊,不能再次编辑;
|
return;
|
}
|
var cycle = new Cycle(() => { Method.UpdateWeek(weekBtn, Common.Logic.CurrentLogic); });
|
UserView.HomePage.Instance.AddChidren(cycle);
|
UserView.HomePage.Instance.PageIndex += 1;
|
cycle.Show();
|
};
|
weekBtn.MouseUpEventHandler += cycleclick;
|
weekview.clickBtn.MouseUpEventHandler += cycleclick;
|
if (Yes)
|
{
|
//改变字体颜色;
|
weekBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
|
logicTextBox.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
|
}
|
#endregion
|
|
#region ----推送设置----
|
Method.Push(middle);
|
#endregion
|
|
saveBtn.clickviewBtn.MouseUpEventHandler += (sender, e) =>
|
{
|
if (Yes)
|
{
|
//S-one门锁特殊,不能再次编辑;
|
RemoveFromParent();
|
return;
|
}
|
var name = logicTextBox.Text.Trim();
|
Method.SaveLogic(IfString._SoneLogic, name, IfString.Tag, Common.Logic.CurrentLogic);
|
};
|
|
}
|
/// <summary>
|
/// 选中该作为条件或者目标的视图方法
|
/// </summary>
|
/// <param name="common">Common.</param>
|
void DevcieView( CommonDevice common,Button button)
|
{
|
#region -------界面布局部分
|
//不让当前界面滑动
|
UserView.HomePage.Instance.ScrollEnabled = false;
|
var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicViewBackgroundColor };
|
this.AddChidren(flMain);
|
CompleteView completeView = new CompleteView();
|
flMain.AddChidren(completeView.Show(1));
|
// completeView.Btntitle.Text =HdlDeviceCommonLogic.Current.GetDeviceEpointName(common);
|
completeView.Btntitle.TextID = MyInternationalizationString.openmode;
|
EventHandler<MouseEventArgs> clickcancel = (sender, e) =>
|
{
|
flMain.RemoveFromParent();
|
};
|
flMain.MouseUpEventHandler += clickcancel;
|
completeView.Btncancel.MouseUpEventHandler += clickcancel;
|
|
mFunView openView = new mFunView();
|
openView.frameLayout.Y = Application.GetRealHeight(140 + 20);
|
completeView.Show(2).AddChidren(openView.Show());
|
openView.titleBtn.TextID = MyInternationalizationString.logicopen;
|
|
mFunView closeView = new mFunView();
|
closeView.frameLayout.Y = Application.GetRealHeight(140 + 20 + 160);
|
closeView.frameLayout.Y = openView.frameLayout.Bottom;
|
completeView.Show(2).AddChidren(closeView.Show());
|
closeView.titleBtn.TextID = MyInternationalizationString.logicclose;
|
closeView.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor;
|
#endregion
|
|
|
Dictionary<string, object> actionsInfo = new Dictionary<string, object>();
|
actionsInfo.Add("LinkType", 8);
|
actionsInfo.Add("DeviceAddr", common.DeviceAddr);
|
actionsInfo.Add("Epoint","200");
|
string SelectedDeviceStatus = "";
|
switch (common.Type)
|
{
|
case DeviceType.DoorLock:
|
{
|
openView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
|
{
|
openView.selectedIconBtn.Visible = true;
|
closeView.selectedIconBtn.Visible = false;
|
openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
|
closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
|
SelectedDeviceStatus = Language.StringByID(MyInternationalizationString.logicopen);
|
if (actionsInfo.ContainsKey("PassData"))
|
{
|
actionsInfo.Remove("PassData");
|
}
|
actionsInfo.Add("PassData", "055704010112");//门锁常开
|
};
|
///点击取消事件
|
closeView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
|
{
|
openView.selectedIconBtn.Visible = false;
|
closeView.selectedIconBtn.Visible = true;
|
openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
|
closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
|
SelectedDeviceStatus = Language.StringByID(MyInternationalizationString.logicclose);
|
if (actionsInfo.ContainsKey("PassData"))
|
{
|
actionsInfo.Remove("PassData");
|
}
|
actionsInfo.Add("PassData", "055704010113");//门锁常关
|
|
};
|
|
if (button.Text == Language.StringByID(MyInternationalizationString.logicopen))
|
{
|
//开启
|
SelectedDeviceStatus = Language.StringByID(MyInternationalizationString.logicopen);
|
openView.selectedIconBtn.Visible = true;
|
closeView.selectedIconBtn.Visible = false;
|
openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
|
closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
|
|
}
|
else {
|
//关闭
|
SelectedDeviceStatus = Language.StringByID(MyInternationalizationString.logicclose);
|
openView.selectedIconBtn.Visible = false;
|
closeView.selectedIconBtn.Visible = true;
|
openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
|
closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
|
}
|
|
}
|
break;
|
|
}
|
|
|
completeView.Btncomplete.MouseUpEventHandler += (sender, e) =>
|
{
|
if (!string.IsNullOrEmpty(SelectedDeviceStatus))
|
{
|
LogicIfon.AddDoorLockActions(common, actionsInfo);
|
button.Text = SelectedDeviceStatus;
|
}
|
|
flMain.RemoveFromParent();
|
|
};
|
}
|
}
|
}
|