陈嘉乐
2021-01-11 1026814d931de92f0da5f15a58870565a94100e0
HDL_ON/Entity/Function/Function.cs
@@ -70,39 +70,82 @@
        /// 设备spk
        /// </summary>
        public string spk = "";
        /// <summary>
        /// 功能类别
        /// 如:空调类、灯光类、窗帘类
        /// </summary>
        public FunctionCategory functionCategory
        {
            get
            {
                try
                {
                    var _functionCategoryString = sid.Substring(16, 2);
                    var _functionCategory = Convert.ToInt32(_functionCategoryString, 16);
                    return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory);
                }
                catch (Exception ex)
                {
                    MainPage.Log($"get FunctionCategory error : {ex.Message}");
                    return FunctionCategory.UnKown;
                }
            }
        }
        ///// <summary>
        ///// 功能类别
        ///// 如:空调类、灯光类、窗帘类
        ///// </summary>
        //public FunctionCategory Spk_Prefix
        //{
        //    get
        //    {
        //        try
        //        {
        //            var _functionCategoryString = sid.Substring(16, 2);
        //            var _functionCategory = Convert.ToInt32(_functionCategoryString, 16);
        //            return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory);
        //        }
        //        catch (Exception ex)
        //        {
        //            MainPage.Log($"get FunctionCategory error : {ex.Message}");
        //            return FunctionCategory.UnKown;
        //        }
        //    }
        //}
        ///// <summary>
        ///// 功能类型
        ///// </summary>
        public FunctionType functionType
        //public FunctionType spk
        //{
        //    get
        //    {
        //        var _functionTypeString = sid.Substring(16, 4);
        //        return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16));
        //    }
        //}
        string spk_Prefix;
        /// <summary>
        /// spk前缀
        /// 大类
        /// 功能类别
        /// 如:空调类、灯光类、窗帘类
        /// </summary>
        public string Spk_Prefix
        {
            get
            {
                var _functionTypeString = sid.Substring(16, 4);
                return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16));
                if (string.IsNullOrEmpty(spk_Prefix))
                {
                    spk_Prefix = spk.Split(".")[0];
                }
                return spk_Prefix;
            }
        }
        string spk_Suffix;
        ///// <summary>
        ///// spk后缀
        ///// 小类
        ///// 功能类型
        ///// </summary>
        //public string spk
        //{
        //    get
        //    {
        //        if (string.IsNullOrEmpty(spk_Suffix))
        //        {
        //            try
        //            {
        //                spk_Suffix = spk.Split(".")[1];
        //            }
        //            catch
        //            {
        //                spk_Suffix = "";
        //            }
        //        }
        //        return spk_Suffix;
        //    }
        //}
        /// <summary>
        /// A协议功能的特性
@@ -299,7 +342,7 @@
                }
                roomNameList += findRoom.floorName +"-"+ findRoom.roomName;
            }
            if (roomNameList == "" && functionType == FunctionType.Scene)
            if (roomNameList == "" )
            {
                roomNameList = Language.StringByID(StringId.WholeZone);
            }
@@ -316,31 +359,104 @@
                return "FunctionData_" + sid;
            }
        }
        /// <summary>
        /// 保存功能数据
        /// 保存功能文件
        /// </summary>
        public void SaveFunctionData(bool upSevser)
        {
            if (upSevser)
            {
                var pm = new HttpServerRequest();
                var pack = pm.UpdataDevcieInfo(this);
                if (pack.Code == StateCode.SUCCESS)
        public void SaveFunctionFile()
                {
                    var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
                    FileUtlis.Files.WriteFileByBytes(savePath, ssd);
        }
        /// <summary>
        /// 保存房间绑定信息
        /// </summary>
        public void UpdataRoomIds()
        {
            new System.Threading.Thread(() =>
            {
                var pack = ApiUtlis.Ins.HttpRequest.UpdataDevcieBindRoomInfo(this);
                //直接保存本地,
                SaveFunctionFile();
                if (pack.Code == StateCode.SUCCESS)
                {
                }
                else
                {
                    IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 更新功能信息
        /// </summary>
        public void UpdataFuncitonInfo()
        {
            new System.Threading.Thread(() =>
            {
                var pm = new HttpServerRequest();
                var pack = pm.UpdataDevcieInfo(this);
                SaveFunctionFile();
                if (pack.Code == StateCode.SUCCESS)
                {
            }
            else
            {
                var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
                FileUtlis.Files.WriteFileByBytes(savePath, ssd);
                    IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
            }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 更新功能名称
        /// </summary>
        public void UpdataFunctionName()
        {
            new System.Threading.Thread(() =>
            {
                var pm = new HttpServerRequest();
                var pack = pm.UpdataDevcieInfo(this);
                SaveFunctionFile();
                if (pack.Code == StateCode.SUCCESS)
                {
                }
                else
                {
                    IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 保存功能数据
        /// </summary>
        //public void SaveFunctionData(bool upSevser)
        //{
        //    if (upSevser)
        //    {
        //        new System.Threading.Thread(() =>
        //        {
        //            var pm = new HttpServerRequest();
        //            var pack = pm.UpdataDevcieInfo(this);
        //            if (pack.Code == StateCode.SUCCESS)
        //            {
        //                var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
        //                FileUtlis.Files.WriteFileByBytes(savePath, ssd);
        //            }
        //            else
        //            {
        //                IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
        //            }
        //        })
        //        { IsBackground = true }.Start();
        //    }
        //    else
        //    {
        //        var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
        //        FileUtlis.Files.WriteFileByBytes(savePath, ssd);
        //    }
        //}
        /// <summary>
@@ -741,6 +857,54 @@
        /// 家电、风扇
        /// </summary>
        public const string ElectricFan = "electrical.fan";
    }
    /// <summary>
    /// 功能类别
    /// </summary>
    public static class FunctionCategory
    {
        /// <summary>
        ///(灯)
        /// </summary>
        public const string Light = "light";
        /// <summary>
        /// (窗帘)
        /// </summary>
        public const string Curtain = "curtain";
        /// <summary>
        /// (空调)
        /// </summary>
        public const string AC = "ac";
        /// <summary>
        /// (地热)
        /// </summary>
        public const string FloorHeat = "floorHeat";
        /// <summary>
        /// (新风)
        /// </summary>
        public const string AirFresh = "airFresh";
        /// <summary>
        /// (音乐)
        /// </summary>
        public const string Music = "music";
        /// <summary>
        /// (传感器)
        /// </summary>
        public const string Sensor = "sensor";
        /// <summary>
        /// (干接点)
        /// </summary>
        public const string DryContact = "dryContact";
        /// <summary>
        /// 家电
        /// </summary>
        public const string Electric = "electrical";
        //Music = 0x09,
    }
}