陈嘉乐
2021-03-01 a469a96ee8c38f7d98366dcd633e3a15f92fec65
HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/BrandList.cs
@@ -17,17 +17,9 @@
        /// </summary>
        /// <param name="list">表示该列表元素A-Z字母筛选显示出来</param>
        /// <param name="list6">表示该列表元素显示在list前面(该列表元素不做A-Z字母筛选),没有可以为list6=null</param>
        public void Show(List<string> list, List<string> list6)
        public void Show(List<Brand>brandList,List<string> list, List<string> list6)
        {
            //string text = "30";
            //byte[] bytes = new byte[text.Length / 2];
            //for (int i = 0, j = 0; i < bytes.Length; j += 2, i++)
            //{
            //    //把16进度转换成byte
            //    bytes[i] = Convert.ToByte(text.Substring(j, 2), 16);
            //}
            ////把byte数组转换成文字
            //string str = System.Text.Encoding.UTF8.GetString(bytes);
            var frameLayout = new FrameLayout
            {
                BackgroundColor = CSS.CSS_Color.viewTop,
@@ -119,7 +111,7 @@
                        listStr.Add(s);
                    }
                }
                RefreshLayout(vv, listStr);
                RefreshLayout(vv, brandList, listStr);
            };
            #region A-Z
@@ -176,7 +168,7 @@
            }
            #endregion
            RefreshLayout(vv, list1);
            RefreshLayout(vv, brandList, list1);
        }
        /// <summary>
@@ -184,7 +176,7 @@
        /// </summary>
        /// <param name="vv">父控件</param>
        /// <param name="list">显示列表</param>
        private void RefreshLayout(VerticalScrolViewLayout vv, List<string> list)
        private void RefreshLayout(VerticalScrolViewLayout vv, List<Brand> brandList, List<string> list)
        {
            vv.RemoveAll();
            foreach (var str in list)
@@ -224,14 +216,60 @@
                vv.AddChidren(rowLayout);
                clickBtn.MouseUpEventHandler += (sen, e) =>
                {
                    ////找到索引值
                    //var index = list.IndexOf(clickBtn.Tag.ToString());
                    //this.RemoveFromParent();
                    var name = clickBtn.Tag.ToString();
                    var brandObj = brandList.Find((c) => c.brandName == name);
                    if (brandObj==null) {
                        return;
                    }
                    GetLibraryList(brandObj.id, (libraryList) =>
                     {
                         Matching matching = new Matching();
                         MainPage.BasePageView.AddChidren(matching);
                         matching.Show();
                         MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                     });
                };
            }
        }
        /// <summary>
        /// 读取品牌红外码库列表
        /// </summary>
        private void GetLibraryList(string id, Action<List<Library>> actionBrand)
        {
            List<Library> libraryList = new List<Library>();
            PirSend.GetDeviceTypesList(this, (responsePackNew) =>
            {
                if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                {
                    //清空之前数据
                    libraryList.Clear();
                    var jArray = Newtonsoft.Json.Linq.JArray.Parse(responsePackNew.Data.ToString());
                    for (int a = 0; a < jArray.Count; a++)
                    {
                        var jay = jArray[a];
                        var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
                        var library = Newtonsoft.Json.JsonConvert.DeserializeObject<Library>(str);
                        if (library != null)
                        {
                            if (null == libraryList.Find((c) => c.brandId == library.brandId))
                            {
                                libraryList.Add(library);
                            }
                        }
                    }
                    actionBrand(libraryList);
                }
                else
                {
                    Method method = new Method();
                    method.ErrorShow(responsePackNew);
                }
            }, id, "品牌红外码库列表");
        }
        /// <summary>
        /// 列表是否包含该值(true=包含,false=不包含)
@@ -431,5 +469,22 @@
            else return ("ZZ");
        }
    }
    public class Library
    {
        /// <summary>
        /// 红外码
        /// </summary>
        public string irCode = string.Empty;
        /// <summary>
        /// 品牌主键Id
        /// </summary>
        public string brandId = string.Empty;
        /// <summary>
        /// 红外码索引序号
        /// </summary>
        public string irIndex = string.Empty;
    }
}