xm
2021-12-01 6d73bf6e816570291865674bef8bce8972e4de3f
HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/AddControl.cs
@@ -9,7 +9,7 @@
    {
        public AddControl()
        {
            Tag = "Pir";
            Tag = "PirView";
        }
        public void Show(Control control)
        {
@@ -24,7 +24,7 @@
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
@@ -56,7 +56,7 @@
            FrameLayout frameLayout = new FrameLayout
            {
                Y = Application.GetRealHeight(64 + 84),
                Height = Application.GetRealHeight(667 - 64 - 84),
                Height = Application.GetRealHeight(667 - 64 - 84-104),
                Width = Application.GetRealWidth(TextSize.view375),
            };
            this.AddChidren(frameLayout);
@@ -71,7 +71,7 @@
            };
            this.AddChidren(saveLayout);
            saveLayout.SetCornerWithSameRadius(Application.GetRealHeight(24), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            //暂时隐藏排序功能
            Button paixuBtn = new Button
            {
                Width = Application.GetRealWidth(375 - 16 * 2),
@@ -82,7 +82,7 @@
                TextSize = TextSize.text14,
                TextColor = CSS.CSS_Color.textTipColor,
            };
            saveLayout.AddChidren(paixuBtn);
            //saveLayout.AddChidren(paixuBtn);
            Button saveBtn = new Button
            {
@@ -103,7 +103,7 @@
            VerticalScrolViewLayout vv = new VerticalScrolViewLayout();
            frameLayout.AddChidren(vv);
            RefreshView(vv, false);
            RefreshView(vv, false, control);
            #endregion
            #region  界面点击事件
@@ -117,13 +117,13 @@
                    topView.topIconBtn.Text = Language.StringByID(StringId.wancheng);
                    topView.topIconBtn.TextSize = TextSize.text14;
                    topView.topIconBtn.TextColor = CSS.CSS_Color.textColor;
                    RefreshView(vv, true);
                    RefreshView(vv, true, control);
                }
                else
                {
                    topView.topIconBtn.UnSelectedImagePath = "PirIcon/del.png";
                    topView.topIconBtn.Text = "";
                    RefreshView(vv, false);
                    RefreshView(vv, false, control);
                }
@@ -140,21 +140,13 @@
            //保存点击事件
            saveBtn.MouseUpEventHandler += (sender, e) =>
            {
               //移除当前界面
                //移除当前界面
                this.RemoveFromParent();
                //可能之前已经存在该界面
                for (int i = MainPage.BasePageView.ChildrenCount - 1; 0 <= i; i--)
                {
                    var view = MainPage.BasePageView.GetChildren(i);
                    if (view.GetType() == typeof(AddControlComplete))
                    {
                        view.RemoveFromParent();
                    }
                }
                //MainPage.BasePageView.RemoveViewByTag("Pir");
                PirMethod.RemoveView("AddControlComplete");
                AddControlComplete addControlComplete = new AddControlComplete();
                MainPage.BasePageView.AddChidren(addControlComplete);
                addControlComplete.Show(control);
                addControlComplete.Show(control, false);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            #endregion
@@ -164,116 +156,22 @@
        /// </summary>
        /// <param name="vv">上下滑动控件</param>
        /// <param name="if_bool">表示是否显示删除图标</param>
        void RefreshView(VerticalScrolViewLayout vv, bool if_bool)
        void RefreshView(VerticalScrolViewLayout vv, bool if_bool, Control control)
        {
            vv.RemoveAll();
            //定义一个变量记录行数
            int sum = 0;
            if (Pir.BuottonList.Count % 3 == 0)
            View.Buttons buttons = new View.Buttons();
            buttons.AddButton2(vv, control.status, (obj) =>
            {
                sum = Pir.BuottonList.Count / 3;
            }
            else
            {
                sum = Pir.BuottonList.Count / 3 + 1;
            }
            //计算加载出来的数据需要的高度
            int h = 16 + sum * (16 + 44) + 104 + 76;
            int line = 0;
            //按钮的父控件
            var FLayout = new FrameLayout
            {
                Height = Application.GetRealWidth(h),
            };
            vv.AddChidren(FLayout);
            for (int i = 1, j = 0; i <= Pir.BuottonList.Count; i++, j++)
            {
                var nameObj = Pir.BuottonList[i - 1];
                //按钮
                var buttonNameBtn = new Button
                PirMethod.ThreadSend(control, (responsePackNew) =>
                {
                    Y = Application.GetRealHeight(16 + line * (16 + 44)),
                    X = Application.GetRealWidth(16 + (16 + 104) * j),
                    Width = Application.GetRealWidth(104),
                    Height = Application.GetRealHeight(44),
                    Text = nameObj.value,
                    TextSize = TextSize.text16,
                    TextColor = CSS.CSS_Color.textColor,
                    TextAlignment = TextAlignment.Center,
                    Radius = (uint)Application.GetRealHeight(18),
                    BorderWidth = 1,
                    BorderColor = CSS.CSS_Color.textCancelColor,
                };
                FLayout.AddChidren(buttonNameBtn);
                //删除图标
                var delIconBtn = new Button
                {
                    UnSelectedImagePath = "PirIcon/delbuton.png",
                    Y = Application.GetRealHeight(12 + line * (16 + 44)),
                    X = Application.GetRealWidth((16 + 92) + (104 + 16) * j),
                    Width = Application.GetRealWidth(16),
                    Height = Application.GetRealWidth(16),
                    Tag = nameObj,
                };
                if (if_bool)
                {
                    FLayout.AddChidren(delIconBtn);
                }
                //删除图标的点击事件
                delIconBtn.MouseUpEventHandler += (sender, e) =>
                {
                    var obj = delIconBtn.Tag as ButtonObj;
                    //加载log
                    Loading loading = new Loading();
                    this.AddChidren(loading);
                    HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
                    loading.Start();
                    new System.Threading.Thread(() =>
                    var buttonObj = control.status.Find((c) => c.value == obj.value);
                    if (buttonObj != null)
                    {
                        try
                        {
                            //发送按键删除;
                            responsePackNew = PirSend.CodeRemove(obj);
                        }
                        catch { }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                loading.Hide();
                                if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                                {
                                    ///这里:监听MTTP推送下来主题,才知道是否添加成功
                                    var buttonObj = Pir.BuottonList.Find((c) => c.value == obj.value);
                                    if (buttonObj != null)
                                    {
                                        Pir.BuottonList.Remove(buttonObj);
                                    }
                                    RefreshView(vv, true);
                                }
                                else {
                                    Method method = new Method();
                                    method.ErrorShow(responsePackNew);
                                }
                            });
                        }
                    })
                    { IsBackground = true }.Start();
                };
                if (i % 3 == 0)
                {
                    //满一行重置j=0值;
                    j = -1;
                    line += 1;
                }
            }
                        control.status.Remove(buttonObj);
                    }
                    RefreshView(vv, true, control);
                }, "删除按键", "fram", this, null, obj);
            }, if_bool);
        }
    }
}