using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
public class LogicMethod
{
///
/// 生成逻辑sid方法
///
public static string NewSid()
{
string logicId = "";
try
{
string sOidBeginsWith = "000101";//厂商 + 通讯方式
DateTime dt = DateTime.Now;
DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2020, 1, 1));
long m = (long)((dt - startTime).TotalMilliseconds / 10);
string sTimeSpan = "00000000";
byte[] arry = new byte[4];
arry[0] = (byte)(m & 0xFF);
arry[1] = (byte)((m & 0xFF00) >> 8);
arry[2] = (byte)((m & 0xFF0000) >> 16);
arry[3] = (byte)((m >> 24) & 0xFF);
sTimeSpan = arry[0].ToString("X2") + arry[1].ToString("X2") + arry[2].ToString("X2") + arry[3].ToString("X2");
if (sTimeSpan.Length > 8)
{
sTimeSpan = sTimeSpan.Substring(0, 8);
}
else
{
sTimeSpan = "00000000";
}
logicId = sOidBeginsWith + sTimeSpan;
logicId += "0A";
logicId += "0A01";
//0A01 物模型为逻辑, 0001 表示 1 号逻辑功能
int iTopLogicId = 1;
Random random = new Random();
iTopLogicId = random.Next(0, 255);
iTopLogicId += random.Next(0, 255);
logicId += iTopLogicId.ToString("X4");//逻辑号 两个byte
logicId += "1100";
}
catch
{
return logicId;
}
return logicId;
}
///
/// 封装Dictionary对象
///
/// Dictionary类
/// 健
/// 值
public static void dictionary(Dictionary dic, string key, string value)
{
if (dic.ContainsKey(key)) //判断是否存在键值
{
//键存在移除
dic.Remove(key);
}
//添加键值
dic.Add(key, value);
}
///
/// 获取房间列表
///
///
public static List GetRoomList()
{
return HDL_ON.Entity.DB_ResidenceData.rooms;
}
///
/// 获取设备列表
///
///
public static List GetDeviceList()
{
return HDL_ON.Entity.DB_ResidenceData.functionList.GetAllFunction();
}
///
/// 获取房间的设备列表
///
/// 当前房间
///
public static List GetRoomDevice(HDL_ON.Entity.Room room)
{
List deviceLists = new List();
List lists = GetDeviceList();
foreach (var dev in lists)
{
if (dev.roomIdList.Find((id) => id == room.sid) != null)
{
deviceLists.Add(dev);
}
}
return deviceLists;
}
///
/// 获取设备
///
/// 设备唯一标识
///
public static HDL_ON.Entity.Function GetDevice(string sid)
{
HDL_ON.Entity.Function device = new Entity.Function();
List deviceLists = GetDeviceList();
foreach (var dev in deviceLists)
{
if (dev.sid == sid)
{
device = dev;
break;
}
}
return device;
}
///
/// 获取房间名(即是=区域名称)
///
/// 设备
///
public static string GetGetRoomName(HDL_ON.Entity.Function device)
{
string roomName = "";
List roomLists = GetRoomList();
foreach (var dev in device.roomIdList)
{
var room = roomLists.Find((c) => c.sid == dev);
if (room != null)
{
roomName += room.floorName + "." + room.name + ",";
}
}
return roomName.TrimEnd(',');
}
///
/// 获取房间名列表(即是=区域名称)
///
///
public static List GetGetRoomNameList()
{
List roomNameList = new List();
roomNameList.Add(Language.StringByID(StringId.allAreas));
List roomLists = GetRoomList();
foreach (var room in roomLists)
{
roomNameList.Add(room.name);
}
return roomNameList;
}
///
/// 获取图标
///
/// 设备类型
///
public static string GetIconPath(FunctionType functionType) {
string strPath = "";
switch (functionType) {
case FunctionType.Relay: {
strPath = "LogicIcon/lightloguc.png";
}
break;
}
return strPath;
}
}
}