From 351bdda734832d821a9764b0cde8be5d83c4ec50 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期四, 01 十二月 2022 09:56:25 +0800
Subject: [PATCH] 2022年12月01日09:56:23

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Form/AreaCodeSelectForm.cs |  599 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 599 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Form/AreaCodeSelectForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Form/AreaCodeSelectForm.cs
new file mode 100644
index 0000000..af7a278
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Form/AreaCodeSelectForm.cs
@@ -0,0 +1,599 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shared.Phone.UserCenter
+{
+    public class AreaCodeSelectForm : DialogCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 瀹屾垚閫夋嫨鐨勪簨浠�(鍦板尯鐮�)
+        /// </summary>
+        public Action<string> FinishSelectEvent = null;
+        /// <summary>
+        /// 鍒楄〃鎺т欢
+        /// </summary>
+        private VerticalListControl listView = null;
+        /// <summary>
+        /// 鍓嶅洖閫夋嫨鐨勬帶浠�
+        /// </summary>
+        private FrameRowControl oldFrameRowControl = null;
+        /// <summary>
+        /// 閿�
+        /// </summary>
+        private object objLock = new object();
+        /// <summary>
+        /// 杩欎釜涓滆タ鏄釜闈欐��(瀹冩槸涓壒娈婄殑)
+        /// </summary>
+        private static List<AreaCodeInfo> listAreaCode = null;
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        public void ShowForm()
+        {
+            //鍒濆鍖栦腑閮ㄤ俊鎭�
+            this.InitMiddleFrame();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+        /// </summary>
+        private void InitMiddleFrame()
+        {
+            var frameBack = new FrameLayout();
+            frameBack.Width = Application.GetRealWidth(850);
+            frameBack.Height = Application.GetRealHeight(1342);
+            frameBack.Radius = (uint)Application.GetRealHeight(17);
+            frameBack.BackgroundColor = UserCenterColor.Current.White;
+            frameBack.Gravity = Gravity.CenterHorizontal;
+            frameBack.Y = Application.GetRealHeight(328);
+            bodyFrameLayout.AddChidren(frameBack);
+
+            this.listView = new VerticalListControl(3);
+            listView.Y = Application.GetRealHeight(164 - 11);
+            listView.Height = frameBack.Height - Application.GetRealHeight(164 - 11);
+            listView.Radius = (uint)Application.GetRealHeight(17);
+            frameBack.AddChidren(listView);
+
+            //璇烽�夋嫨鍖哄彿
+            var btnTitle = new NormalViewControl(270, 60, true);
+            btnTitle.X = ControlCommonResourse.XXLeft;
+            btnTitle.Y = Application.GetRealHeight(69);
+            btnTitle.TextID = R.MyInternationalizationString.uPleaseSelectAreaCode;
+            btnTitle.TextSize = 15;
+            btnTitle.TextColor = UserCenterColor.Current.TextColor2;
+            frameBack.AddChidren(btnTitle);
+
+            //鎼滅储
+            var btnSearch = new MySearchControl(Language.StringByID(R.MyInternationalizationString.uSearch));
+            btnSearch.X = Application.GetRealWidth(334);
+            btnSearch.Y = Application.GetRealHeight(46);
+            frameBack.AddChidren(btnSearch);
+            btnSearch.BindEvent(this.SearchEvent);
+
+            //璁╄繖涓寜閽繖涓尯鍩熶笉鑳界偣鍑昏彍鍗�
+            var frameTemp = new FrameLayout();
+            frameTemp.Y = Application.GetRealHeight(1146);
+            frameTemp.Height = frameBack.Height - Application.GetRealHeight(1146);
+            frameBack.AddChidren(frameTemp);
+
+            var btnOk = new BottomClickButton(688);
+            btnOk.Y = Application.GetRealHeight(1146);
+            btnOk.TextID = R.MyInternationalizationString.uConfirm1;
+            frameBack.AddChidren(btnOk);
+            btnOk.ButtonClickEvent += (sender, e) =>
+            {
+                if (oldFrameRowControl != null)
+                {
+                    this.FinishSelectEvent?.Invoke(oldFrameRowControl.MainKeys);
+                }
+                this.CloseForm();
+            };
+
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //鍒濆鍖栧湴鍖哄垪琛�
+                this.InitAreaList();
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖栧湴鍖哄垪琛╛____________________
+
+        /// <summary>
+        /// 鍒濆鍖栧湴鍖哄垪琛�
+        /// </summary>
+        private void InitAreaList()
+        {
+            if (listAreaCode == null)
+            {
+                //绗竴娆¤幏鍙�
+                //寮�鍚繘搴︽潯
+                ProgressBar.Show();
+
+                //鑾峰彇鍏ㄩ儴鐨勫湴鍖轰唬鐮佸垪琛�
+                var Pra = new { Common.CommonPage.RequestVersion };
+                string result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetAreaCode", false, Pra);
+                //鍏抽棴杩涘害鏉�
+                ProgressBar.Close();
+                if (string.IsNullOrEmpty(result) == true)
+                {
+                    return;
+                }
+                listAreaCode = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AreaCodeInfo>>(result);
+                for (int i = 0; i < listAreaCode.Count; i++)
+                {
+                    //鑾峰彇棣栧瓧姣�
+                    listAreaCode[i].First = this.GetCharSpellCode(listAreaCode[i].Name.Substring(0, 1));
+                }
+                //鎺掑簭
+                listAreaCode.Sort((obj1, obj2) =>
+                {
+                    return obj1.First.CompareTo(obj2.First);
+                });
+            }
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                //娣诲姞鍏ㄩ儴鏄庣粏琛�
+                this.AddAllDetailRow(listAreaCode);
+            });   
+        }
+
+        /// <summary>
+        /// 娣诲姞鍏ㄩ儴鏄庣粏琛�
+        /// </summary>
+        /// <param name="listData"></param>
+        private void AddAllDetailRow(List<AreaCodeInfo> listData)
+        {
+            listView.RemoveAll();
+            string oldFirst = string.Empty;
+            int realHeight = 0;
+            for (int i = 0; i < listData.Count; i++)
+            {
+                if (oldFirst != listData[i].First)
+                {
+                    oldFirst = listData[i].First;
+                    //娣诲姞瀛楁瘝鏍囬
+                    var frame1 = new FrameRowControl(listView.rowSpace / 2);
+                    frame1.UseClickStatu = false;
+                    //鍒楄〃鎺т欢鍙府鎵╁ぇ3锛岃�屽畠鐨勯棿璺濋渶瑕�11
+                    frame1.Height = Application.GetRealHeight(58 + 8);
+                    frame1.Width = Application.GetRealWidth(850);
+                    listView.AddChidren(frame1);
+                    realHeight += frame1.Height;
+
+                    var btnView1 = frame1.AddLeftCaption(listData[i].First, 300);
+                    btnView1.TextColor = UserCenterColor.Current.TextGrayColor2;
+                    if (listData[i].First == "ZZ")
+                    {
+                        //鍏朵粬
+                        btnView1.TextID = R.MyInternationalizationString.uOther;
+                    }
+                }
+                //娣诲姞鏄庣粏琛�
+                var frameDetail = new FrameRowControl(listView.rowSpace / 2);
+                frameDetail.MainKeys = listData[i].Code;
+                frameDetail.UseClickStatu = false;
+                frameDetail.Width = Application.GetRealWidth(850);
+                frameDetail.Height = Application.GetRealHeight(118);
+                listView.AddChidren(frameDetail);
+                realHeight += frameDetail.Height;
+                //鍦板尯鍚�
+                var btnName = frameDetail.AddLeftCaption(listData[i].Name, 600);
+                btnName.TextColor = UserCenterColor.Current.TextGrayColor3;
+                //鍦板尯鐮�
+                var btnCode = frameDetail.AddMostRightView("+" + listData[i].Code, 300);
+                btnCode.TextColor = UserCenterColor.Current.TextGrayColor3;
+                frameDetail.ButtonClickEvent += (sender, e) =>
+                {
+                    if (oldFrameRowControl != null)
+                    {
+                        if (oldFrameRowControl.MainKeys == frameDetail.MainKeys)
+                        {
+                            //鍚屼竴涓笢瑗�
+                            return;
+                        }
+                        //鍙栨秷涓婁竴娆$殑閫夋嫨
+                        oldFrameRowControl.BackgroundColor = UserCenterColor.Current.Transparent;
+                        ((NormalViewControl)oldFrameRowControl.GetChildren(0)).TextColor = UserCenterColor.Current.TextGrayColor3;
+                        ((NormalViewControl)oldFrameRowControl.GetChildren(1)).TextColor = UserCenterColor.Current.TextGrayColor3;
+                    }
+
+                    //閫変腑鐘舵��
+                    frameDetail.BackgroundColor = 0x0ffc744b;
+                    btnName.TextColor = UserCenterColor.Current.TextColor1;
+                    btnCode.TextColor = UserCenterColor.Current.TextColor1;
+                    oldFrameRowControl = frameDetail;
+                };
+            }
+
+            if (realHeight > listView.Height - Application.GetRealHeight(196))
+            {
+                //淇冧娇琚尅浣忕殑鑿滃崟鑳藉鍚戜笂婊戝姩
+                var frameTemp = new FrameLayout();
+                frameTemp.Height = Application.GetRealHeight(196 + 34);//闂磋窛34
+                listView.AddChidren(frameTemp);
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鎼滅储浜嬩欢___________________________
+
+        /// <summary>
+        /// 鎼滅储浜嬩欢
+        /// </summary>
+        /// <param name="changdValue"></param>
+        private void SearchEvent(string changdValue)
+        {
+            lock (objLock)
+            {
+                //濡傛灉鍙緭鍏ヤ竴浣嶇殑璇�,鍙互鍒ゆ柇棣栧瓧姣�
+                string first = changdValue.Length == 1 ? changdValue.ToUpper() : string.Empty;
+
+                var listData = new List<AreaCodeInfo>();
+                for (int i = 0; i < listAreaCode.Count; i++)
+                {
+                    //濡傛灉鍙緭鍏ヤ竴浣嶇殑璇�,鍙互鍒ゆ柇棣栧瓧姣�
+                    if (listAreaCode[i].First == first)
+                    {
+                        listData.Add(listAreaCode[i]);
+                    }
+                    //鍒ゆ柇鍚嶅瓧鍜屽湴鍖虹爜
+                    else if (listAreaCode[i].Code.Contains(changdValue) == true || listAreaCode[i].Name.Contains(changdValue) == true)
+                    {
+                        listData.Add(listAreaCode[i]);
+                    }
+                }
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    //娣诲姞鍏ㄩ儴鏄庣粏琛�
+                    this.AddAllDetailRow(listData);
+                });
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鎼滅储鎺т欢___________________________
+
+        /// <summary>
+        /// 鍒朵綔涓�涓牴鎹敭鍊艰繘琛屾悳绱㈢殑鎺т欢
+        /// 娣诲姞鎺т欢鍚庯紝璇疯皟鐢↙oadEvent()鍑芥暟杩涜鍥炶皟鍑芥暟鐨勭粦瀹�
+        /// </summary>
+        public class MySearchControl : FrameLayout
+        {
+            #region 鈻� 鍙橀噺澹版槑__________________________
+            
+            /// <summary>
+            /// 鎼滅储鎺т欢
+            /// </summary>
+            private TextInputControl txtSearch = null;
+            /// <summary>
+            /// 鍥炶皟鍑芥暟
+            /// </summary>
+            private Action<string> actionMethod = null;
+            /// <summary>
+            /// 娌℃湁杈撳叆閿�肩殑鏄剧ず鏂囨湰
+            /// </summary>
+            private string tipText = string.Empty;
+
+            #endregion
+
+            #region 鈻� 鍒濆鍖朹___________________________
+            /// <summary>
+            /// 鍒朵綔涓�涓牴鎹敭鍊艰繘琛屾悳绱㈢殑鎺т欢
+            /// 娣诲姞鎺т欢鍒扮埗鎺т欢鍚庯紝璇疯皟鐢˙indEvent()鍑芥暟杩涜鍥炶皟鍑芥暟鐨勭粦瀹�
+            /// </summary>
+            /// <param name="i_tipText">娌℃湁杈撳叆閿�肩殑鏄剧ず鏂囨湰</param>
+            public MySearchControl(string i_tipText)
+            {
+                this.tipText = i_tipText;
+                //妗屽竷鎺т欢
+                this.Width = Application.GetRealWidth(458);
+                this.Height = Application.GetRealHeight(104);
+                this.Radius = (uint)Application.GetRealHeight(17);
+                this.BorderColor = 0xffbfc1c2;
+                this.BorderWidth = 1;
+            }
+
+            /// <summary>
+            /// 鎺т欢鍒濆鍖�
+            /// </summary>
+            private void InitControl()
+            {
+                //杈撳叆鏂囨湰
+                int textWidth = this.Width - Application.GetRealWidth(35 * 2);
+                txtSearch = new TextInputControl(textWidth, Application.GetRealHeight(58), false);
+                txtSearch.X = Application.GetRealWidth(35);
+                txtSearch.PlaceholderText = this.tipText;
+                txtSearch.Gravity = Gravity.CenterVertical;
+                this.AddChidren(txtSearch);
+
+                string oldText = string.Empty;
+                //鍊兼敼鍙樹簨浠�
+                txtSearch.TextChangeEventHandler += (sender, e) =>
+                {
+                    this.nextSearchKeys = txtSearch.Text.Trim();
+                    if (oldText == this.nextSearchKeys)
+                    {
+                        //杈撳叆鐨勫�间竴鏍�
+                        return;
+                    }
+                    oldText = this.nextSearchKeys;
+                    //鍏佽鎵ц鍥炶皟鍑芥暟
+                    this.isCanSearch = true;
+                };
+            }
+            #endregion
+
+            #region 鈻� 缁戝畾浜嬩欢__________________________
+
+            /// <summary>
+            /// 缁戝畾浜嬩欢
+            /// </summary>
+            /// <param name="action">鍥炶皟鍑芥暟锛氬�兼槸杈撳叆鐨勫叧閿瓧</param>
+            public void BindEvent(Action<string> action)
+            {
+                this.actionMethod = action;
+
+                //鎺т欢鍒濆鍖�
+                this.InitControl();
+
+                //鎵撳紑鎼滅储閿�肩殑绾跨▼
+                this.StartSearchKeysThead();
+            }
+
+            #endregion
+
+            #region 鈻� 寮�鍚嚎绋媉_________________________
+
+            /// <summary>
+            /// 鑳藉惁鎵ц鎼滅储
+            /// </summary>
+            private bool isCanSearch = false;
+            /// <summary>
+            /// 涓嬩竴涓悳绱㈤敭鍊�
+            /// </summary>
+            private string nextSearchKeys = string.Empty;
+            /// <summary>
+            /// 鎵撳紑鎼滅储閿�肩殑绾跨▼
+            /// </summary>
+            private void StartSearchKeysThead()
+            {
+                HdlThreadLogic.Current.RunThread(() =>
+                {
+                    while (this.Parent != null)
+                    {
+                        //鏍规嵁閫昏緫锛屼笉鑳藉鎼滅储鐨勮瘽锛岀瓑寰�
+                        if (this.isCanSearch == false)
+                        {
+                            System.Threading.Thread.Sleep(1000);
+                            continue;
+                        }
+                        //鑾峰彇褰撳墠鐬棿鐨勯敭鍊�
+                        string nowSearchKeys = nextSearchKeys;
+
+                        //鏍规嵁鎼滅储閿�硷紝璋冪敤鍥炶皟鍑芥暟
+                        this.actionMethod(nowSearchKeys);
+
+                        //澶勭悊瀹屾瘯鍚庯紝濡傛灉褰撳墠鐨勬绱㈤敭鍊间笌涓嬩竴涓绱㈤敭鍊间竴鏍风殑璇�
+                        //璇存槑鐢ㄦ埛宸茬粡涓嶅啀杈撳叆閿�间簡锛岃繖涓椂鍊欙紝鍋滄鎼滅储
+                        if (nowSearchKeys == nextSearchKeys)
+                        {
+                            this.isCanSearch = false;
+                        }
+
+                        //濡傛灉褰撳墠鐨勬绱㈤敭鍊间笌涓嬩竴涓绱㈤敭鍊间笉涓�鏍风殑璇�
+                        //閭e氨璇存槑锛岀敤鎴峰啀娆¤緭鍏ヤ簡閿�硷紝杩欎釜鏃跺�欙紝璁╃嚎绋嬬户缁窇涓嬪幓
+                    }
+                });
+            }
+            #endregion
+
+            #region 鈻� 鎺т欢鎽ф瘉__________________________
+
+            /// <summary>
+            /// 鎺т欢鎽ф瘉
+            /// </summary>
+            public override void RemoveFromParent()
+            {
+                actionMethod = null;
+                base.RemoveFromParent();
+            }
+
+            #endregion
+        }
+
+        #endregion
+
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 鑾峰彇姹夊瓧棣栧瓧姣�
+        /// </summary>
+        /// <param name="textValue"></param>
+        /// <returns></returns>
+        private string GetCharSpellCode(string textValue)
+        {
+            long iCnChar;
+
+            byte[] ZW = Encoding.GetEncoding("gb2312").GetBytes(textValue);
+
+            //濡傛灉鏄瓧姣嶏紝鍒欑洿鎺ヨ繑鍥� 
+            if (ZW.Length == 1)
+            {
+                return textValue.ToUpper();
+            }
+            else
+            {
+                // get the array of byte from the single char 
+                int i1 = (short)(ZW[0]);
+                int i2 = (short)(ZW[1]);
+                iCnChar = i1 * 256 + i2;
+            }
+
+            //expresstion 
+            //table of the constant list 
+            // 'A'; //45217..45252 
+            // 'B'; //45253..45760 
+            // 'C'; //45761..46317 
+            // 'D'; //46318..46825 
+            // 'E'; //46826..47009 
+            // 'F'; //47010..47296 
+            // 'G'; //47297..47613 
+
+            // 'H'; //47614..48118 
+            // 'J'; //48119..49061 
+            // 'K'; //49062..49323 
+            // 'L'; //49324..49895 
+            // 'M'; //49896..50370 
+            // 'N'; //50371..50613 
+            // 'O'; //50614..50621 
+            // 'P'; //50622..50905 
+            // 'Q'; //50906..51386 
+
+            // 'R'; //51387..51445 
+            // 'S'; //51446..52217 
+            // 'T'; //52218..52697 
+            //娌℃湁U,V 
+            // 'W'; //52698..52979 
+            // 'X'; //52980..53640 
+            // 'Y'; //53689..54480 
+            // 'Z'; //54481..55289 
+
+            // iCnChar match the constant 
+            if ((iCnChar >= 45217) && (iCnChar <= 45252))
+            {
+                return "A";
+            }
+            else if ((iCnChar >= 45253) && (iCnChar <= 45760))
+            {
+                return "B";
+            }
+            else if ((iCnChar >= 45761) && (iCnChar <= 46317))
+            {
+                return "C";
+            }
+            else if ((iCnChar >= 46318) && (iCnChar <= 46825))
+            {
+                return "D";
+            }
+            else if ((iCnChar >= 46826) && (iCnChar <= 47009))
+            {
+                return "E";
+            }
+            else if ((iCnChar >= 47010) && (iCnChar <= 47296))
+            {
+                return "F";
+            }
+            else if ((iCnChar >= 47297) && (iCnChar <= 47613))
+            {
+                return "G";
+            }
+            else if ((iCnChar >= 47614) && (iCnChar <= 48118))
+            {
+                return "H";
+            }
+            else if ((iCnChar >= 48119) && (iCnChar <= 49061))
+            {
+                return "J";
+            }
+            else if ((iCnChar >= 49062) && (iCnChar <= 49323))
+            {
+                return "K";
+            }
+            else if ((iCnChar >= 49324) && (iCnChar <= 49895))
+            {
+                return "L";
+            }
+            else if ((iCnChar >= 49896) && (iCnChar <= 50370))
+            {
+                return "M";
+            }
+
+            else if ((iCnChar >= 50371) && (iCnChar <= 50613))
+            {
+                return "N";
+            }
+            else if ((iCnChar >= 50614) && (iCnChar <= 50621))
+            {
+                return "O";
+            }
+            else if ((iCnChar >= 50622) && (iCnChar <= 50905))
+            {
+                return "P";
+            }
+            else if ((iCnChar >= 50906) && (iCnChar <= 51386))
+            {
+                return "Q";
+            }
+            else if ((iCnChar >= 51387) && (iCnChar <= 51445))
+            {
+                return "R";
+            }
+            else if ((iCnChar >= 51446) && (iCnChar <= 52217))
+            {
+                return "S";
+            }
+            else if ((iCnChar >= 52218) && (iCnChar <= 52697))
+            {
+                return "T";
+            }
+            else if ((iCnChar >= 52698) && (iCnChar <= 52979))
+            {
+                return "W";
+            }
+            else if ((iCnChar >= 52980) && (iCnChar <= 53640))
+            {
+                return "X";
+            }
+            else if ((iCnChar >= 53689) && (iCnChar <= 54480))
+            {
+                return "Y";
+            }
+            else if ((iCnChar >= 54481) && (iCnChar <= 55289))
+            {
+                return "Z";
+            }
+            else return ("ZZ");
+        }
+
+        #endregion
+
+        #region 鈻� 缁撴瀯浣揰____________________________
+
+        /// <summary>
+        /// 鍦板尯鐮�
+        /// </summary>
+        private class AreaCodeInfo
+        {
+            /// <summary>
+            /// 棣栧瓧姣�
+            /// </summary>
+            public string First = string.Empty;
+            /// <summary>
+            /// 鍚嶅瓧
+            /// </summary>
+            public string Name = string.Empty;
+            /// <summary>
+            /// 鍦板尯鐮�
+            /// </summary>
+            public string Code = string.Empty;
+            /// <summary>
+            /// Id
+            /// </summary>
+            public string Id = string.Empty;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0