From 23fb45dd846ed8b62304c408c6bbe64265d4ac8b Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期五, 20 十二月 2019 18:57:16 +0800
Subject: [PATCH] 代码合并

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/ACZbGatewayModuleUpdateForm.cs |  221 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 205 insertions(+), 16 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/ACZbGatewayModuleUpdateForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/ACZbGatewayModuleUpdateForm.cs
index 9396272..335f45b 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/ACZbGatewayModuleUpdateForm.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/ACZbGatewayModuleUpdateForm.cs
@@ -13,9 +13,17 @@
         #region 鈻� 鍙橀噺澹版槑___________________________
 
         /// <summary>
-        /// 璁惧mac鍦板潃
+        /// 璁惧Ota
         /// </summary>
-        private string deviceMac = null;
+        private OTADevice otaDevice = null;
+        /// <summary>
+        /// 璁惧
+        /// </summary>
+        private AC deviceAc = null;
+        /// <summary>
+        /// 鍓嶅洖閫夋嫨鐨勬帶浠�
+        /// </summary>
+        private NormalSelectControl oldSelectContr = null;
 
         #endregion
 
@@ -24,10 +32,11 @@
         /// <summary>
         /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
         /// </summary>
-        /// <param name="i_deviceMac">璁惧mac鍦板潃</param>
-        public void ShowForm(string i_deviceMac)
+        /// <param name="i_deviceAc">璁惧</param>
+        public void ShowForm(AC i_deviceAc)
         {
-            this.deviceMac = i_deviceMac;
+            this.deviceAc = i_deviceAc;
+            this.otaDevice = Common.LocalDevice.Current.GetOTADevice(i_deviceAc.DeviceAddr);
 
             //璁剧疆澶撮儴淇℃伅
             base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAirConditioningModule));
@@ -55,29 +64,209 @@
             listView.BackgroundColor = UserCenterColor.Current.White;
             bodyFrameLayout.AddChidren(listView);
 
-            //鍗囩骇
-            var btnUpdate = new BottomClickButton();
-            btnUpdate.TextID = R.MyInternationalizationString.uLevelUp;
-            bodyFrameLayout.AddChidren(btnUpdate);
-            btnUpdate.ButtonClickEvent += (sender, e) =>
-            {
-            };
+            //鍒濆鍖栫┖璋冩ā鍧楀垪琛�
+            this.InitAirConditioningModuleList(listView);
         }
 
         #endregion
 
-        private async void DoDeviceUpdate()
+        #region 鈻� 鍒濆鍖栫┖璋冩ā鍧楀垪琛╛________________
+
+        /// <summary>
+        /// 鍒濆鍖栫┖璋冩ā鍧楀垪琛�
+        /// </summary>
+        private void InitAirConditioningModuleList(VerticalListControl listView)
         {
-            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(this.deviceMac);
-            if (listDevice.Count == 0)
+            var list = HdlFirmwareUpdateLogic.GetFirmwareVersionListInfo(FirmwareLevelType.ZigbeeDevice, otaDevice.HwVersion.ToString(), otaDevice.ImgTypeId.ToString());
+            if (list.Count == 0)
             {
+                //娌℃湁鍙崌绾х殑绌鸿皟妯″潡
+                this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotHadAirConditioningUpdateModule));
                 return;
             }
-            
+            HdlThreadLogic.Current.RunMainInThread(() =>
+            {
+                for (int i = 0; i < list.Count; i++)
+                {
+                    //娣诲姞妯″潡琛�
+                    this.AddModuleRow(listView, list[i], i.ToString(), i != list.Count - 1);
+                }
+                //璋冩暣楂樺害
+                listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
+
+                //鍗囩骇
+                var btnUpdate = new BottomClickButton();
+                btnUpdate.TextID = R.MyInternationalizationString.uLevelUp;
+                bodyFrameLayout.AddChidren(btnUpdate);
+                btnUpdate.ButtonClickEvent += (sender, e) =>
+                {
+                    var selectInfo = this.GetSelectFirmware(listView, list);
+                    if (selectInfo == null)
+                    {
+                        //娌℃湁閫夋嫨鍥轰欢
+                        return;
+                    }
+                    //璁惧鍗囩骇
+                    HdlThreadLogic.Current.RunThread(() =>
+                    {
+                        this.DoDeviceUpdate(selectInfo);
+                    });
+                };
+            });
         }
 
+        /// <summary>
+        /// 娣诲姞妯″潡琛�
+        /// </summary>
+        /// <param name="listView"></param>
+        /// <param name="info"></param>
+        /// <param name="mainkeys"></param>
+        private void AddModuleRow(VerticalListControl listView, FirmwareVersionInfo info, string mainkeys,bool addLine)
+        {
+            //鑾峰彇绌鸿皟妯″潡鐨勫悕瀛�
+            string textView = this.GetAirConditioningModuleName(info);
+            var row = new NormalSelectControl(textView, listView.rowSpace / 2);
+            row.MainKeys = mainkeys;
+            listView.AddChidren(row);
+            row.InitControl("Device/AirConditionerEpoint.png");
+            if (addLine == true)
+            {
+                row.AddBottomLine();
+            }
+            row.ButtonClickEvent += (sender, e) =>
+            {
+                //鍙栨秷
+                if (row.IsSelected == true)
+                {
+                    row.IsSelected = false;
+                    oldSelectContr = null;
+                    return;
+                }
+                //閫夋嫨
+                row.IsSelected = true;
+                if (oldSelectContr != null)
+                {
+                    oldSelectContr.IsSelected = false;
+                }
+                oldSelectContr = row;
+            };
+        }
+
+        /// <summary>
+        /// 鑾峰彇绌鸿皟妯″潡鐨勫悕瀛�
+        /// </summary>
+        /// <param name="info"></param>
+        /// <returns></returns>
+        private string GetAirConditioningModuleName(FirmwareVersionInfo info)
+        {
+            string textView = string.Empty;
+            if (info.Name.Contains("IRACC_DAK") == true)
+            {
+                //澶ч噾绌鸿皟妯″潡
+                textView = Language.StringByID(R.MyInternationalizationString.uDakAirConditioningModule);
+            }
+            else if (info.Name.Contains("IRACC_HIC") == true)
+            {
+                //閲嶅伐绌鸿皟妯″潡
+                textView = Language.StringByID(R.MyInternationalizationString.uHicAirConditioningModule);
+            }
+            else
+            {
+                //绌鸿皟鍗囩骇妯″潡
+                textView = Language.StringByID(R.MyInternationalizationString.uAirConditioningUpdateModule);
+            }
+            return textView;
+        }
+
+        #endregion
+
         #region 鈻� 涓�鑸柟娉昣__________________________
 
+        /// <summary>
+        /// 鑾峰彇閫夋嫨鐨勫崌绾у浐浠�
+        /// </summary>
+        /// <param name="listView"></param>
+        /// <param name=""></param>
+        /// <returns></returns>
+        private FirmwareVersionInfo GetSelectFirmware(VerticalListControl listView, List<FirmwareVersionInfo> listInfo)
+        {
+            int contrCount = listView.ChildrenCount;
+            for (int i = 0; i < contrCount; i++)
+            {
+                var myView = listView.GetChildren(i) as NormalSelectControl;
+                if (myView == null || myView.IsSelected == false)
+                {
+                    continue;
+                }
+                return listInfo[i];
+            }
+            return null;
+        }
+
+        #endregion
+
+        #region 鈻� 璁惧鍗囩骇___________________________
+
+        /// <summary>
+        /// 璁惧鍗囩骇
+        /// </summary>
+        private void DoDeviceUpdate(FirmwareVersionInfo updateInfo)
+        {
+            //鎵撳紑杩涘害鏉�
+            ProgressFormBar.Current.Start();
+            //璁惧鍗囩骇
+            var updateLogic = new HdlACZbGatewayUpdateLogic(deviceAc, updateInfo);
+            //鏇存柊鐘舵�佸彉鍖栫殑浜嬩欢
+            updateLogic.UpdateStatuChangedEvent += (div, msg) =>
+            {
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    if (div == -1)
+                    {
+                        //寮傚父
+                        this.ShowMassage(ShowMsgType.Tip, msg);
+                        ProgressFormBar.Current.Close();
+                    }
+                    else if (div == 0)
+                    {
+                        //涓�鑸俊鎭�
+                        ProgressFormBar.Current.SetMsg(msg);
+                    }
+                    else if (div == 1)
+                    {
+                        //鍗囩骇瀹屾垚
+                        ProgressFormBar.Current.Close();
+                        this.ShowMassage(ShowMsgType.Tip, msg);
+
+                        HdlThreadLogic.Current.RunMain(() =>
+                        {
+                            //鍏抽棴鐣岄潰
+                            this.CloseForm();
+                        });
+                    }
+                });
+            };
+            //杩涘害鍊兼敼鍙樹簨浠�
+            updateLogic.ProgressEvent += (value) =>
+            {
+                ProgressFormBar.Current.SetValue(value);
+            };
+            //璁惧鍗囩骇寮�濮�
+            updateLogic.StartUpdateReady();
+            //鍏抽棴浜嬩欢
+            ProgressFormBar.Current.CloseEvent += () =>
+            {
+                //鍗囩骇瀵硅薄
+                if (FirmwareUpdateResourse.dicUpdateList.ContainsKey(deviceAc.DeviceAddr) == true
+                    && FirmwareUpdateResourse.dicUpdateList[deviceAc.DeviceAddr].IsFinishUpdate == true)
+                {
+                    //濡傛灉璁惧宸茬粡鍗囩骇瀹屾垚锛岀晫闈㈠叧闂椂锛屽垯绉婚櫎鍐呭瓨
+                    FirmwareUpdateResourse.dicUpdateList[deviceAc.DeviceAddr].Dispose();
+                    FirmwareUpdateResourse.dicUpdateList.Remove(deviceAc.DeviceAddr);
+                }
+            };
+        }
+
         #endregion
     }
 }

--
Gitblit v1.8.0