xm
2021-12-01 6d73bf6e816570291865674bef8bce8972e4de3f
HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/AddControlComplete.cs
@@ -4,30 +4,31 @@
using Shared;
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
{
    public class AddControlComplete:FrameLayout
    public class AddControlComplete : FrameLayout
    {
        public AddControlComplete()
        {
            Tag = "Pir";
            Tag = "PirView";
        }
        public void Show() {
        public void Show(Control control, bool bool_library)
        {
            #region 界面布局
            this.BackgroundColor = CSS.CSS_Color.viewMiddle;
            PirDevice.View.TopView topView = new View.TopView();
            topView.topNameBtn.TextID = StringId.tianjiayaokongqi;
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); };
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { RemoveFromParent(); };
            FrameLayout fLayout = new FrameLayout
            FrameLayout fLayout = new FrameLayout
            {
                Y =Application.GetRealHeight(64),
                Y = Application.GetRealHeight(64),
                BackgroundColor = CSS.CSS_Color.textWhiteColor,
                Height = Application.GetRealHeight(224),
                Width = Application.GetRealWidth(375),
            };
            this.AddChidren(fLayout);
            //
            Button iconBtn = new Button
            //成功图标
            Button iconBtn = new Button
            {
                Y = Application.GetRealHeight(28),
                X = Application.GetRealWidth(137),
@@ -40,7 +41,7 @@
            //添加成功
            Button text1Btn = new Button
            {
                Width = Application.GetRealWidth(375-32),
                Width = Application.GetRealWidth(375 - 32),
                Height = Application.GetRealHeight(22),
                Y = Application.GetRealHeight(158),
                X = Application.GetRealWidth(16),
@@ -50,7 +51,7 @@
                TextAlignment = TextAlignment.Center,
            };
            fLayout.AddChidren(text1Btn);
            //可到分类-功能-电器操作使用
            //可到分类-功能-操作使用
            Button text2Btn = new Button
            {
                Width = Application.GetRealWidth(375 - 32),
@@ -65,7 +66,7 @@
            fLayout.AddChidren(text2Btn);
            //所属分类
            View.PatchView fenlei = new View.PatchView();
            fenlei.frameLayout.Y = fLayout.Bottom+ Application.GetRealHeight(8);
            fenlei.frameLayout.Y = fLayout.Bottom + Application.GetRealHeight(8);
            this.AddChidren(fenlei.FLayoutView(false));
            fenlei.btnText1.TextID = StringId.suoshufenlei;
            fenlei.btnText2.TextID = StringId.dianqi;
@@ -74,20 +75,21 @@
            namePatchView.frameLayout.Y = fenlei.frameLayout.Bottom;
            this.AddChidren(namePatchView.FLayoutView());
            namePatchView.btnText1.TextID = StringId.yaokongqimingcheng;
            namePatchView.btnText2.TextID = StringId.dianqi;
            namePatchView.btnText2.Text = control.name;
            //所属区域
            View.PatchView quyuPatchView = new View.PatchView();
            quyuPatchView.frameLayout.Y = namePatchView.frameLayout.Bottom;
            this.AddChidren(quyuPatchView.FLayoutView());
            quyuPatchView.btnText1.TextID = StringId.suoshuquyu;
            quyuPatchView.btnText2.TextID = StringId.dianqi;
            quyuPatchView.btnText2.Text = Intelligence.Automation.LogicMethod.CurrLogicMethod.GetGetRoomName(GetFunction(control.deviceId));
            //继续添加
            Button addBtn = new Button
            {
                Y = quyuPatchView.frameLayout.Bottom + Application.GetRealHeight(125),
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(375-32),
                Width = Application.GetRealWidth(375 - 32),
                Height = Application.GetRealHeight(20),
                TextID = StringId.jixutianjia,
                TextSize = TextSize.text14,
@@ -102,30 +104,95 @@
            #endregion
            #region  界面点击事件
            //遥控器名称点击事件
            namePatchView.btnClick.MouseUpEventHandler += (sender,e) => { };
            //所属区域点击事件
            quyuPatchView.btnClick.MouseUpEventHandler += (sender, e) => { };
            //继续添加点击事件
            addBtn.MouseUpEventHandler += (sender, e) => {
                View.TipView tipView = new View.TipView();
                tipView.InputBox("", (s) =>
                {
                    if (!string.IsNullOrEmpty(s))
                    {
            namePatchView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
                        AddButton addButton = new AddButton();
                        MainPage.BasePageView.AddChidren(addButton);
                        addButton.Show();
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    }
                List<string> list = new List<string>();
                for (int i = 0; i < Pir.currPir.FunctioList.Count; i++)
                {
                    //添加所有遥控名称列表
                    list.Add(Pir.currPir.FunctioList[i].name);
                }
                PirMethod method = new PirMethod();
                method.EditControlName(StringId.editName, list, control.name, (name, dialog) =>
                {
                    //发送更新名称命令
                    PirMethod.ThreadSend(new Control { deviceId = control.deviceId, name = name }, (responsePackNew) =>
                    {
                        //关闭窗口
                        dialog.Close();
                        //更新备注
                        namePatchView.btnText2.Text = name;
                        //更新临时设备名称
                        control.name = name;
                        //更换内存设备名称
                        GetFunction(control.deviceId).name = name;
                    }, "修改名称", "dialog", null, dialog);
                }, () => { });
            };
            //所属区域点击事件
            quyuPatchView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
                PirMethod method = new PirMethod();
                method.ManagementPosition(GetFunction(control.deviceId), () =>
                {
                    //更新区域
                    quyuPatchView.btnText2.Text = Intelligence.Automation.LogicMethod.CurrLogicMethod.GetGetRoomName(GetFunction(control.deviceId));
                });
            };
            //继续添加点击事件
            addBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (bool_library)
                {//继续添加库的遥控器
                    PirMethod.RefreshView("PirMain");//刷新指点界面
                    this.RemoveFromParent();
                }
                else
                {//继续添加自定义的遥控器
                    PirMethod method = new PirMethod();
                    method.AddControl(this, (controlDevice) =>
                    {
                        AddButton addButton = new AddButton();
                        MainPage.BasePageView.AddChidren(addButton);
                        addButton.Show(controlDevice);
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    });
                }
            };
            //完成点击事件
            saveView.btnClick.MouseUpEventHandler += (sender, e) => {
                MainPage.BasePageView.RemoveViewByTag("AddControl");
                MainPage.BasePageView.RemoveViewByTag("Pir");
            saveView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
                //刷新指点界面
                PirMethod.RefreshView("PirMain");
                //移除所有界面
                MainPage.BasePageView.RemoveViewByTag("PirView");
            };
            #endregion
        }
        /// <summary>
        /// 查找设备对象
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <returns></returns>
        public Entity.Function GetFunction(string deviceId)
        {
            var fun = Pir.currPir.FunctioList.Find((c) => c.deviceId == deviceId);
            if (fun != null)
            {
                return fun;
            }
            return new Entity.Function();
        }
        /// <summary>
        /// 移除界面
        /// </summary>
        public override void RemoveFromParent()
        {
            //刷新指定界面
            PirMethod.RefreshView("PirMain");
            base.RemoveFromParent();
        }
    }
}