using System;
|
using Shared;
|
using System.Collections.Generic;
|
namespace HDL_ON.UI.UI2.Intelligence.Automation
|
{
|
public class DeviceFunList : FrameLayout
|
{
|
public DeviceFunList()
|
{
|
Tag = "Logic";
|
}
|
|
public void Show(Entity.Function device, int index, bool edit)
|
{
|
#region 界面布局
|
this.BackgroundColor = CSS.CSS_Color.viewMiddle;
|
LogicView.TopView topView = new LogicView.TopView();
|
this.AddChidren(topView.FLayoutView());
|
topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
|
{
|
RemoveFromParent();
|
};
|
topView.topNameBtn.Text = device.name;
|
|
FrameLayout fLayout = new FrameLayout
|
{
|
Y = Application.GetRealHeight(64),
|
Height = Application.GetRealHeight(667 - 64),
|
};
|
this.AddChidren(fLayout);
|
#endregion
|
|
//定义一个变量,记录选中状态
|
string selectedState = "unknown";
|
|
Input inputdevice = new Input();
|
inputdevice.condition_type = "3";
|
inputdevice.sid = device.sid;
|
|
|
switch (device.functionType)
|
{
|
//开关灯光
|
case FunctionType.Relay:
|
{
|
|
|
|
//for (int i = 0; i < device.function.Count; i++)
|
//{
|
//}
|
LogicView.SelectTypeView relayView = new LogicView.SelectTypeView();
|
relayView.btnIcon.Visible = false;
|
relayView.btnState.Visible = true;
|
relayView.btnText.TextSize = LogicView.TextSize.text16;
|
relayView.btnText.Height = Application.GetRealHeight(22);
|
relayView.btnText.TextID = StringId.switchLogic;
|
relayView.btnText.X = Application.GetRealWidth(16);
|
relayView.btnText.Width = Application.GetRealWidth(130);
|
relayView.btnLine.X = Application.GetRealWidth(16);
|
relayView.btnLine.Width = Application.GetRealWidth(343);
|
fLayout.AddChidren(relayView.FLayoutView());
|
relayView.btnClick.MouseUpEventHandler += (sender, e) =>
|
{
|
FrameLayout relayFunView = new FrameLayout
|
{
|
BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
|
};
|
this.AddChidren(relayFunView);
|
LogicView.SwitchView switchView = new LogicView.SwitchView();
|
switchView.FLayoutView(relayFunView, 2);
|
|
Button btnOn = new Button
|
{
|
TextAlignment = TextAlignment.Center,
|
TextSize = LogicView.TextSize.text16,
|
TextColor = CSS.CSS_Color.textCancelColor,
|
TextID = StringId.onLogic,
|
Height = Application.GetRealHeight(44),
|
Width = Application.GetRealWidth(343),
|
};
|
switchView.frameLayout.AddChidren(btnOn);
|
Button btnLine = new Button
|
{
|
Height = 1,
|
BackgroundColor = CSS.CSS_Color.viewLine,
|
Y = btnOn.Bottom,
|
};
|
switchView.frameLayout.AddChidren(btnLine);
|
Button btnOff = new Button
|
{
|
Y = btnLine.Bottom,
|
TextAlignment = TextAlignment.Center,
|
TextSize = LogicView.TextSize.text16,
|
TextColor = CSS.CSS_Color.textCancelColor,
|
TextID = StringId.offLogic,
|
Height = Application.GetRealHeight(44),
|
Width = Application.GetRealWidth(343),
|
};
|
switchView.frameLayout.AddChidren(btnOff);
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
LogicMethod.dictionary(dic, "key", "on_off");
|
LogicMethod.dictionary(dic, "comparator", "=");
|
LogicMethod.dictionary(dic, "data_type", "string");
|
inputdevice.condition.Add(dic);
|
btnOn.MouseUpEventHandler += (sender2, e2) =>
|
{
|
LogicMethod.dictionary(dic, "value", "on");
|
RemView(relayFunView);
|
relayView.btnState.TextID = StringId.onLogic;
|
selectedState = device.functionType + "_on";
|
};
|
btnOff.MouseUpEventHandler += (sender3, e3) =>
|
{
|
LogicMethod.dictionary(dic, "value", "off");
|
RemView(relayFunView);
|
relayView.btnState.TextID = StringId.offLogic;
|
selectedState = device.functionType + "_off";
|
};
|
|
};
|
if (edit)
|
{
|
Input inputs = Logic.currlogic.input[index];
|
if (inputs.condition_type == "3")
|
{
|
List<Dictionary<string, string>> dicList = inputs.condition as List<Dictionary<string, string>>;
|
foreach (var dic in dicList)
|
{
|
string value = dic["value"];
|
if (value == "on")
|
{
|
relayView.btnState.Text = Language.StringByID(StringId.onLogic);
|
|
}
|
else
|
{
|
relayView.btnState.Text = Language.StringByID(StringId.offLogic);
|
}
|
}
|
}
|
}
|
|
}
|
break;
|
|
}
|
|
|
|
#region 保存
|
///保存View
|
LogicView.SaveView saveView = new LogicView.SaveView();
|
saveView.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(24), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
|
saveView.btnSave.TextID = StringId.completeLogic;
|
this.AddChidren(saveView.FLayoutView());
|
saveView.btnClick.MouseUpEventHandler += (sen, e) =>
|
{
|
if (selectedState != "unknown")
|
{
|
if (edit)
|
{
|
//移除旧数据
|
Logic.currlogic.input.RemoveAt(index);
|
//新数据插入旧数据的位置;
|
Logic.currlogic.input.Insert(index, inputdevice);
|
}
|
else
|
{
|
//添加一个新的时间点条件
|
Logic.currlogic.input.Add(inputdevice);
|
}
|
}
|
else
|
{
|
if (!edit)
|
{
|
//提示用户
|
return;
|
}
|
this.RemoveFromParent();
|
return;
|
}
|
RemoveViewByTag("Logic");
|
AddLogic addLogic = new AddLogic();
|
MainPage.BasePageView.AddChidren(addLogic);
|
addLogic.Show();
|
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
|
};
|
|
#endregion
|
|
}
|
/// <summary>
|
/// 移除控件
|
/// </summary>
|
/// <param name="frame"></param>
|
public void RemView(FrameLayout frame)
|
{
|
frame.RemoveFromParent();
|
}
|
|
public void GetState(Entity.Function device, bool edit, int index,Button button1,Button button2,Button button3,Button button4)
|
{
|
if (edit)
|
{
|
Input inputs = Logic.currlogic.input[index];
|
var dicList = inputs.condition as List<Dictionary<string, string>>;
|
switch (device.functionType)
|
{
|
//开关灯光
|
case FunctionType.Relay:
|
{
|
foreach (var dic in dicList)
|
{
|
string value = dic["value"];
|
//if (value == "on")
|
//{
|
// relayView.btnState.Text = Language.StringByID(StringId.onLogic);
|
|
//}
|
//else
|
//{
|
// relayView.btnState.Text = Language.StringByID(StringId.offLogic);
|
//}
|
}
|
}
|
break;
|
|
}
|
}
|
}
|
}
|
}
|