陈嘉乐
2021-03-10 1d1cad99a27c9f644c84eb3d376c70bd30a55879
HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Matching.cs
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using HDL_ON.Entity;
using HDL_ON.UI.UI2.Intelligence.Automation.LogicView;
using Shared;
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
@@ -7,8 +9,9 @@
    {
        public Matching()
        {
            Tag = "PirView";
        }
        public void Show()
        public void Show(List<Library> libraryList,string spk)
        {
            #region 界面布局
            this.BackgroundColor = CSS.CSS_Color.viewMiddle;
@@ -79,7 +82,7 @@
                X = Application.GetRealWidth(136),
                Width = Application.GetRealWidth(104),
                Height = Application.GetRealHeight(44),
                Text = "电源",
                TextID=StringId.dianyuan,
                TextSize = TextSize.text16,
                TextColor = CSS.CSS_Color.textColor,
                TextAlignment = TextAlignment.Center,
@@ -96,7 +99,7 @@
                X = Application.GetRealWidth(170),
                Width = Application.GetRealWidth(36),
                Height = Application.GetRealHeight(17),
                Text = "(" + "1" + "/20)",
                Text = "(1/20)",
                TextSize = TextSize.text12,
                TextColor = CSS.CSS_Color.textCancelColor,
            };
@@ -137,15 +140,259 @@
            fLayout.AddChidren(succeedBtn);
            #endregion
            #region 点击事件
            int value = 1;
            //表示库列表索引值
            int index= 1;
            //表示测试码索引值
            int code = 1;
            //左
            leftIconBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (index>1) {
                    index--;
                    sumBtn.Text = "(" + index.ToString() + "/20)";
                }
                code = 1;
                GetBtnText(testBtn, code, spk);
            };
            //右
            rightIconBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (index < 20)
                {
                    index++;
                    sumBtn.Text = "(" + index.ToString() + "/20)";
                }
                code = 1;
                GetBtnText(testBtn, code, spk);
            };
            //测试Text
            testBtn.MouseUpEventHandler += (sender, e) =>
            {
                var library = libraryList[index];
                var control = GetControl(spk, testBtn.TextID, library);
                CodeTest(control);
            };
            //控制失败
            failedBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (index < 20)
                {
                    index++;
                    sumBtn.Text = "(" + index.ToString() + "/20)";
                }
                code = 1;
                GetBtnText(testBtn, code, spk);
            };
            //控制成功
            succeedBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (code < 3)
                {
                    code++;
                }
                GetBtnText(testBtn, code, spk);
                if (code == 3)
                {
                    var library = libraryList[index];
                    var control = GetControl(spk, testBtn.TextID, library);
                    Method method = new Method();
                    method.ThreadAddControl(control, this,(cont) => {
                        MainPage.BasePageView.RemoveViewByTag("PirView");
                        AddControlComplete addControlComplete = new AddControlComplete();
                        MainPage.BasePageView.AddChidren(addControlComplete);
                        addControlComplete.Show(cont,true);
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    });
                }
            };
            #endregion
        }
        /// <summary>
        /// 获取Control对象(存储发送数据的对象)
        /// </summary>
        /// <param name="spk"></param>
        /// <param name="textInt"></param>
        /// <param name="library"></param>
        /// <returns></returns>
        private Control GetControl(string spk, int textInt, Library library) {
            string key = "";
            string value = "";
            switch (spk)
            {
                case SPK.AcIr:
                    {
                        switch (textInt)
                        {
                            case StringId.dianyuan:
                                {
                                    key = "on_off";
                                    value = "on";
                                }
                                break;
                            case StringId.moshizhileng:
                                {
                                    key = "mode";
                                    value = "cool";
                                }
                                break;
                            case StringId.fengsuzhongfeng:
                                {
                                    key = "fan";
                                    value = "medium";
                                }
                                break;
                        }
                    }
                    break;
                case SPK.TvIr:
                    {
                        switch (textInt)
                        {
                            case StringId.dianyuan:
                                {
                                    key = "on_off";
                                    value = "on";
                                }
                                break;
                            case StringId.yinliangjia:
                                {
                                    key = "volume+";
                                    value = "50";
                                }
                                break;
                            case StringId.jingyin:
                                {
                                    key = "mute";
                                    value = "0";
                                }
                                break;
                        }
                    }
                    break;
            }
            AttributesStatus buttonObj = new AttributesStatus();
            buttonObj.key = key;
            buttonObj.value = value;
            Control control = new Control();
            control.spk = spk;
            control.name = spk;
            control.groupId = library.irIndex;
            control.type = "library";
            control.status.Add(buttonObj);
            control.deviceId = Pir.currPir.deviceId;
            control.sid = "";
            string[] strings = library.irCode.Split(',');
            for (int arrayStr = 0; arrayStr < strings.Length; arrayStr++)
            {
                //var intValue = Convert.ToInt32(strings[arrayStr],16);
                control.library.Add(strings[arrayStr].Replace("0x",""));
            }
            return control;
        }
        /// <summary>
        /// 发送库码测试命令
        /// </summary>
        /// <param name="control"></param>
        private void CodeTest(Control control)
        {
            //加载log
            Loading loading = new Loading();
            this.AddChidren(loading);
            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
            loading.Start();
            new System.Threading.Thread(() =>
            {
                try
                {
                    responsePackNew = PirSend.CodeTest(control);
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                        {
                        }
                        else
                        {
                            Method method = new Method();
                            method.ErrorShow(responsePackNew);
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 显示测试文本
        /// </summary>
        /// <param name="testBtn">显示控件</param>
        /// <param name="code">测试码文本索引值</param>
        /// <param name="spk">云雀上定义spk</param>
        private  void GetBtnText(Button testBtn,int code,string spk) {
            int textValue = 0;
            switch (spk)
            {
                case SPK.AcIr:
                    {
                        switch (code)
                        {
                            case 1:
                                {
                                    textValue = StringId.dianyuan;
                                }
                                break;
                            case 2:
                                {
                                    textValue = StringId.moshizhileng;
                                }
                                break;
                            case 3:
                                {
                                    textValue = StringId.fengsuzhongfeng;
                                }
                                break;
                        }
                    }
                    break;
                case SPK.TvIr:
                    {
                        switch (code)
                        {
                            case 1:
                                {
                                    textValue = StringId.dianyuan;
                                }
                                break;
                            case 2:
                                {
                                    textValue = StringId.yinliangjia;
                                }
                                break;
                            case 3:
                                {
                                    textValue = StringId.jingyin;
                                }
                                break;
                        }
                    }
                    break;
            }
            testBtn.TextID = textValue;
        }
    }
}