using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone
|
{
|
/// <summary>
|
/// 设备选择的界面
|
/// </summary>
|
public class SelectDeviceForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 设备选择确定后的回调函数(此函数在点击确认后,会先关闭界面再执行回调方法,与ActionSelectDeviceEx不共存)
|
/// </summary>
|
public Action<List<CommonDevice>> ActionSelectDevice = null;
|
/// <summary>
|
/// 设备选择确定后的回调函数(此函数在点击确认后,不会关闭界面,与ActionSelectDevice不共存,关闭界面请调用CloseForm函数)
|
/// </summary>
|
public Action<List<CommonDevice>> ActionSelectDeviceEx = null;
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalListControl listView = null;
|
/// <summary>
|
/// 前回选择的行
|
/// </summary>
|
private DeviceSelectControl oldSelectRow = null;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_listShowDevice">需要显示设备列表(有些界面需要剔除一些不要的设备)</param>
|
/// <param name="i_listSelectDevice">指定哪些设备的初始状态为选中状态(设备的主键)</param>
|
/// <param name="SelcetCancel">初始选中状态的设备能否取消 true:可以 false:不允许</param>
|
/// <param name="SelectOnlyOne">是否只能选择一个 true:只能选择一个 false:可以多选</param>
|
public void ShowForm(List<CommonDevice> i_listShowDevice, List<string> i_listSelectDevice, bool SelcetCancel = true, bool SelectOnlyOne = false)
|
{
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uSelectDevice));
|
|
//初始化中部信息
|
this.InitMiddleFrame(i_listShowDevice, i_listSelectDevice, SelcetCancel, SelectOnlyOne);
|
}
|
|
/// <summary>
|
/// 初始化中部信息
|
/// </summary>
|
private void InitMiddleFrame(List<CommonDevice> i_listShowDevice, List<string> i_listSelectDevice, bool SelcetCancel, bool SelectOnlyOne)
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
if (i_listShowDevice.Count == 0)
|
{
|
//没有可添加的目标
|
this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotHadAddTarget));
|
return;
|
}
|
|
listView = new VerticalListControl(29);
|
listView.Y = Application.GetRealHeight(-6);
|
listView.Height = bodyFrameLayout.Height + Application.GetRealHeight(6);
|
listView.BackgroundColor = UserCenterColor.Current.White;
|
bodyFrameLayout.AddChidren(listView);
|
|
//添加所有设备行
|
HdlThreadLogic.Current.RunMainInThread(() =>
|
{
|
int count = i_listShowDevice.Count - 1;
|
for (int i = 0; i < i_listShowDevice.Count; i++)
|
{
|
//添加明细行
|
this.AddDeviceRow(i_listShowDevice[i], i_listSelectDevice, SelcetCancel, SelectOnlyOne, i != count);
|
}
|
//调整列表控件的高度
|
listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23), Application.GetRealHeight(6));
|
});
|
|
//完成
|
var btnfinish = new BottomClickButton();
|
btnfinish.TextID = R.MyInternationalizationString.uFinish;
|
bodyFrameLayout.AddChidren(btnfinish);
|
btnfinish.ButtonClickEvent += (sender, e) =>
|
{
|
List<CommonDevice> listDevice = this.GetListDeviceFromRow();
|
if (ActionSelectDeviceEx != null)
|
{
|
ActionSelectDeviceEx(listDevice);
|
return;
|
}
|
|
this.CloseForm();
|
if (ActionSelectDevice != null)
|
{
|
ActionSelectDevice(listDevice);
|
ActionSelectDevice = null;
|
}
|
};
|
}
|
|
#endregion
|
|
#region ■ 添加设备行_________________________
|
|
/// <summary>
|
/// 添加设备行
|
/// </summary>
|
/// <param name="device">设备</param>
|
/// <param name="i_listSelectDevice">指定哪些设备的初始状态为选中状态(设备的主键)</param>
|
/// <param name="SelcetCancel">初始选中状态的设备能否取消 true:可以 false:不允许</param>
|
/// <param name="SelectOnlyOne">是否只能选择一个 true:只能选择一个 false:可以多选</param>
|
/// <param name="addLine">是否添加底线</param>
|
private void AddDeviceRow(CommonDevice device, List<string> i_listSelectDevice, bool SelcetCancel, bool SelectOnlyOne, bool addLine)
|
{
|
string mainkeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
|
var row = new DeviceSelectControl(device, SelectOnlyOne == false, listView.rowSpace / 2);
|
row.MainKeys = mainkeys;
|
listView.AddChidren(row);
|
row.InitControl();
|
//底线
|
if (addLine == true)
|
{
|
row.AddBottomLine();
|
}
|
|
//设置选择状态
|
string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
|
if (i_listSelectDevice.Contains(mainKeys) == true)
|
{
|
row.SelectCancel = SelcetCancel;
|
row.IsSelected = true;
|
if (SelectOnlyOne == true)
|
{
|
oldSelectRow = row;
|
}
|
}
|
if (SelectOnlyOne == true)
|
{
|
row.ButtonClickEvent += (sender, e) =>
|
{
|
//取反
|
row.IsSelected = !row.IsSelected;
|
if (oldSelectRow != null && oldSelectRow.MainKeys != row.MainKeys)
|
{
|
oldSelectRow.IsSelected = false;
|
oldSelectRow = null;
|
}
|
if (row.IsSelected == true)
|
{
|
oldSelectRow = row;
|
}
|
};
|
}
|
}
|
|
#endregion
|
|
#region ■ 获取选中设备_______________________
|
|
/// <summary>
|
/// 获取选中的设备
|
/// </summary>
|
/// <returns></returns>
|
private List<CommonDevice> GetListDeviceFromRow()
|
{
|
List<CommonDevice> listDevice = new List<CommonDevice>();
|
for (int i = 0; i < this.listView.ChildrenCount; i++)
|
{
|
var myView = this.listView.GetChildren(i);
|
if (myView is DeviceSelectControl)
|
{
|
var row = (DeviceSelectControl)myView;
|
if (row.IsSelected == true)
|
{
|
listDevice.Add(row.device);
|
}
|
}
|
}
|
return listDevice;
|
}
|
|
#endregion
|
|
#region ■ 界面关闭___________________________
|
|
/// <summary>
|
/// 界面关闭
|
/// </summary>
|
public override void CloseFormBefore()
|
{
|
ActionSelectDeviceEx = null;
|
|
base.CloseFormBefore();
|
}
|
|
#endregion
|
}
|
}
|