wei
2020-12-23 271faaf6664166dc368639b9f2e577f63f901be5
HDL_ON/Entity/Function/Function.cs
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using HDL_ON.Common;
using HDL_ON.DAL.Server;
using HDL_ON.DriverLayer;
using Shared;
@@ -191,7 +193,7 @@
        /// <summary>
        /// 使用次数
        /// </summary>
        public double usageCount = 0;
        public double controlCounter = 0;
        /// <summary>
        /// 使用频率
        /// </summary>
@@ -199,13 +201,73 @@
        {
            get
            {
                return usageCount / 7;
                return controlCounter / 7;
            }
        }
        /// <summary>
        /// 固定的序号
        /// </summary>
        public int fixedSerialNumber = int.MaxValue;
        /// <summary>
        /// 收藏功能
        /// </summary>
        public void CollectFunction()
        {
            var result = "";
            //var waitPage = new Loading();
            new System.Threading.Thread(() =>
            {
                if (collect)
                {
                    result = ApiUtlis.Ins.HttpRequest.CollectDevice(deviceId).Code;
                }
                else
                {
                    result = ApiUtlis.Ins.HttpRequest.CancelCollectDevice(deviceId).Code;
                }
                //提示错误
                if (result != StateCode.SUCCESS)
                {
                    Application.RunOnMainThread(() =>
                    {
                        collect = !collect;
                        IMessageCommon.Current.ShowErrorInfoAlter(result);
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 编辑功能绑定房间信息
        /// </summary>
        public void EditBindRoomInfo(string roomId)
        {
            var result = "";
            new System.Threading.Thread(() =>
            {
                if (collect)
                {
                    result = ApiUtlis.Ins.HttpRequest.BindDeviceToRoom(new List<string>() { deviceId }, new List<string>() { roomId }).Code;
                }
                else
                {
                    result = ApiUtlis.Ins.HttpRequest.UnbindDeviceToRoom(deviceId,roomId);
                }
                //提示错误
                if (result != StateCode.SUCCESS)
                {
                    Application.RunOnMainThread(() =>
                    {
                        collect = !collect;
                        IMessageCommon.Current.ShowErrorInfoAlter(result);
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        public string GetBusId()
        {
@@ -254,31 +316,104 @@
                return "FunctionData_" + sid;
            }
        }
        /// <summary>
        /// 保存功能数据
        /// 保存功能文件
        /// </summary>
        public void SaveFunctionData(bool upSevser)
        public void SaveFunctionFile()
        {
            if (upSevser)
            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 pm = new DAL.Server.HttpServerRequest();
                var pack = pm.UpdataDevcieInfo(this);
                if (pack.Code == DAL.Server.StateCode.SUCCESS)
                var pack = ApiUtlis.Ins.HttpRequest.UpdataDevcieBindRoomInfo(this);
                //直接保存本地,
                SaveFunctionFile();
                if (pack.Code == StateCode.SUCCESS)
                {
                    var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
                    Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd);
                }
                else
                {
                    Utlis.ShowTip(Language.StringByID(StringId.EditFunctionInfoFail) + "\r\nCode:" + pack.Code);
                    IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                }
            }
            else
            {
                var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
                Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd);
            }
            })
            { 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
                {
                    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>