From 2109463fab2eb1caed189e4f258e0e763c5cea7b Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期四, 07 十一月 2019 11:58:53 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev-tzy' into dev-wjc

---
 ZigbeeApp/Shared/Phone/Device/CommonForm/DeviceDetailInfo.cs |  273 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 229 insertions(+), 44 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/CommonForm/DeviceDetailInfo.cs b/ZigbeeApp/Shared/Phone/Device/CommonForm/DeviceDetailInfo.cs
index 61d8f23..6e89f8d 100755
--- a/ZigbeeApp/Shared/Phone/Device/CommonForm/DeviceDetailInfo.cs
+++ b/ZigbeeApp/Shared/Phone/Device/CommonForm/DeviceDetailInfo.cs
@@ -2,6 +2,8 @@
 using System.Collections.Generic;
 using System.Globalization;
 using Shared.Common;
+using Shared.Phone.UserCenter;
+using ZigBee.Device;
 
 namespace Shared.Phone.Device.CommonForm
 {
@@ -20,6 +22,22 @@
         /// action
         /// </summary>
         public Action action;
+        /// <summary>
+        /// curRoom
+        /// </summary>
+        private Common.Room curRoom;
+        /// <summary>
+        /// curRoom
+        /// </summary>
+        private Common.Room befRoom;
+        /// <summary>
+        /// sharedRow
+        /// </summary>
+        private DeviceInfoRow sharedRow;
+        /// <summary>
+        /// functionTypeRow
+        /// </summary>
+        private DeviceInfoRow functionTypeRow;
 
         #endregion
 
@@ -100,7 +118,7 @@
                 Height = Application.GetMinRealAverage(207),
                 Gravity = Gravity.CenterHorizontal,
                 BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
-                Radius=(uint)Application.GetMinRealAverage(207)
+                Radius = (uint)Application.GetMinRealAverage(207)
             };
             bodyFrameLayout.AddChidren(deviceBG);
 
@@ -174,14 +192,100 @@
             modelRow.Init();
             modelRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.BelongModel)} : ");
             modelRow.SetTitle(string.IsNullOrEmpty(device.CommonDevice.DeviceName) ? Language.StringByID(R.MyInternationalizationString.UNKnown) : device.CommonDevice.DeviceName);
+            modelRow.HideNext(true);
             infoFL.AddChidren(modelRow);
 
-            var sharedRow = new DeviceInfoRow(585);
-            sharedRow.Init();
-            sharedRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.Share)} : ");
-            sharedRow.SetTitle("2浜�");
-            infoFL.AddChidren(sharedRow);
+            if (device.CommonDevice.Type==ZigBee.Device.DeviceType.OnOffOutput)
+            {
+                functionTypeRow = new DeviceInfoRow(585);
+                functionTypeRow.Init();
+                functionTypeRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.FunctionType)} : ");
+                //functionTypeRow.SetTitle(device.CommonDevice.DfunctionType);
+                infoFL.AddChidren(functionTypeRow);
+                var dfunctionType = device.CommonDevice.DfunctionType;
 
+                //鍔熻兘绫诲瀷鐨勭炕璇戝悕瀛�
+                string strT = string.Empty;
+                if (dfunctionType == DeviceFunctionType.A鐏厜)
+                {
+                    strT = Language.StringByID(R.MyInternationalizationString.uLight);
+                }
+                else if (dfunctionType == DeviceFunctionType.A寮�鍏�)
+                {
+                    strT = Language.StringByID(R.MyInternationalizationString.uSwitch);
+                }
+                else if (dfunctionType == DeviceFunctionType.A鎻掑骇)
+                {
+                    strT = Language.StringByID(R.MyInternationalizationString.uSocket1);
+                }
+                functionTypeRow.SetTitle(strT);
+
+                functionTypeRow.ClickBtn.MouseUpEventHandler += (sender, e) =>
+                {
+                    var DfunctionType = device.CommonDevice.DfunctionType;
+                    
+                    //鍔熻兘绫诲瀷鐨勭炕璇戝悕瀛�
+                    int nowSelectNo = 1;
+                    string strType = string.Empty;
+                    if (DfunctionType == DeviceFunctionType.A鐏厜)
+                    {
+                        strType = Language.StringByID(R.MyInternationalizationString.uLight);
+                        nowSelectNo = 1;
+                    }
+                    else if (DfunctionType == DeviceFunctionType.A寮�鍏�)
+                    {
+                        strType = Language.StringByID(R.MyInternationalizationString.uSwitch);
+                        nowSelectNo = 0;
+                    }
+                    else if (DfunctionType == DeviceFunctionType.A鎻掑骇)
+                    {
+                        strType = Language.StringByID(R.MyInternationalizationString.uSocket1);
+                        nowSelectNo = 2;
+                    }
+                    //鏄剧ず鍒楄〃
+                    var listText = new List<string>();
+                    listText.Add(Language.StringByID(R.MyInternationalizationString.uSwitch));//寮�鍏�
+                    listText.Add(Language.StringByID(R.MyInternationalizationString.uLight));//鐏厜
+                    listText.Add(Language.StringByID(R.MyInternationalizationString.uSocket1));//鎻掑骇
+                                                                                               //鏍囬:閫夋嫨鍔熻兘绫诲瀷
+                    var title = Language.StringByID(R.MyInternationalizationString.uSelectFunctionType);
+
+                    var form = new BottomDialogSelectForm();
+                    form.AddForm(title, listText, nowSelectNo);
+                    form.FinishSelectEvent += (selectNo) =>
+                    {
+                        functionTypeRow.NameText.Text = listText[selectNo];
+                        nowSelectNo = selectNo;
+                        //璁板綍璧峰綋鍓嶉�夋嫨鐨勫姛鑳界被鍨�
+                        if (selectNo == 0)
+                        {
+                            device.CommonDevice.DfunctionType  = DeviceFunctionType.A寮�鍏�;
+                        }
+                        else if (selectNo == 1)
+                        {
+                            device.CommonDevice.DfunctionType = DeviceFunctionType.A鐏厜;
+                        }
+                        else
+                        {
+                            device.CommonDevice.DfunctionType = DeviceFunctionType.A鎻掑骇;
+                        }
+                    };
+                };
+
+                sharedRow = new DeviceInfoRow(723);
+                sharedRow.Init();
+                sharedRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.Share)} : ");
+                sharedRow.SetTitle("2浜�");
+                infoFL.AddChidren(sharedRow);
+            }
+            else
+            {
+                sharedRow = new DeviceInfoRow(585);
+                sharedRow.Init();
+                sharedRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.Share)} : ");
+                sharedRow.SetTitle("2浜�");
+                infoFL.AddChidren(sharedRow);
+            }
 
             var confirmBtn = new CommonForm.CompleteButton(962, 907, 127);
             confirmBtn.SetTitle(R.MyInternationalizationString.Confrim);
@@ -190,17 +294,54 @@
             #region event
             EventHandler<MouseEventArgs> selectZoneEvent = (sender, e) =>
             {
-                //UserCenter.SelectRoomForm selectedRoom = new UserCenter.SelectRoomForm();
-                //selectedRoom.AddForm(selectedRoom, roomNameList);
-                //selectedRoom.ActionSelectRoom += ((rList) =>
-                //{
-                //    roomNameList = rList;
-                //    zone.Text = Shared.Common.Room.CurrentRoom.GetRoomName(roomNameList);
-                //});
+                List<string> floorIds = new List<string> { };
+                List<string> floorNames = new List<string> { };
+                List<List<string>> roomNames = new List<List<string>> { };
+                List<List<Common.Room>> rooms = new List<List<Common.Room>> { };
+                List<Common.Room> rs = new List<Common.Room> { };
+                List<string> rNames = new List<string> { };
+                if (Config.Instance.Home.FloorDics.Count>0)
+                {
+                    foreach (var floor in Config.Instance.Home.FloorDics)
+                    {
+                        floorIds.Add(floor.Key);
+                        floorNames.Add(floor.Value);
+                        if (Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key).Count > 0)
+                        {
+                            roomNames.Add(Common.Room.CurrentRoom.GetRoomNamesByFloorId(floor.Key));
+                            rooms.Add(Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key));
+                        }
+                    }
+                    PickerView.ShowSecondary(floorNames, roomNames, (index1, index2) =>
+                    {
+                        curRoom = rooms[index1][index2];
+                        zoneRow.SetTitle($"{Config.Instance.Home.GetFloorNameById(floorIds[index1])} , {rooms[index1][index2].Name}");
+                    }, 0, 0, Language.StringByID(R.MyInternationalizationString.BelongFloor),
+                   Language.StringByID(R.MyInternationalizationString.Confrim),
+                   Language.StringByID(R.MyInternationalizationString.Cancel));
+                }
+                else
+                {
+                    for(int i=0;i<Common.Room.Lists.Count;i++)
+                    {
+                        var r = Common.Room.Lists[i];
+                        if (r.IsLove)
+                        {
+                            continue;
+                        }
+                        rs.Add(r);
+                        rNames.Add(r.Name);
+                    }
+                    PickerView.Show(rNames, (index1) =>
+                    {
+                        curRoom = rs[index1];
+                        zoneRow.SetTitle(rs[index1].Name);
+                    }, 0,Language.StringByID(R.MyInternationalizationString.BelongFloor),
+                   Language.StringByID(R.MyInternationalizationString.Confrim),
+                   Language.StringByID(R.MyInternationalizationString.Cancel));
+                }
             };
-            //zoneRight.MouseUpEventHandler += selectZoneEvent;
-            //zoneFL.MouseUpEventHandler += selectZoneEvent;
-            //zone.MouseUpEventHandler += selectZoneEvent;
+            zoneRow.ClickBtn.MouseUpEventHandler += selectZoneEvent;
 
             EventHandler<MouseEventArgs> selectDeviceIconEvent = (sender, e) =>
             {
@@ -212,38 +353,80 @@
                 {
                     deviceIMG.UnSelectedImagePath = unSelectedImagePath;
                     deviceIMG.SelectedImagePath = selectedImagePath;
+                    device.CommonDevice.IsCustomizeImage = true;
                 };
             };
             deviceIMG.MouseUpEventHandler += selectDeviceIconEvent;
 
-            confirmBtn.MouseUpEventHandler += async (sender, e) =>
+            confirmBtn.MouseUpEventHandler +=  (sender, e) =>
             {
-                //if (device.CommonDevice == null)
-                //{
-                //    CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
-                //    return;
-                //}
-                //var result = await Shared.Common.LocalDevice.Current.ReName(device.CommonDevice, deviceName.Text.Trim());
-                //if (result)
-                //{
-                //    var alertSuccess = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.Success), Language.StringByID(R.MyInternationalizationString.Confrim));
-                //    alertSuccess.Show();
-                //    alertSuccess.ResultEventHandler += (senderSuccess, eSuccess) =>
-                //    {
-                //        //鏀瑰浘鐗�
-                //        device.IconPath = deviceIMG.UnSelectedImagePath;
-                //        device.IsCustomizeImage = true;
-                //        device.ReSave();
-                //        //鏀规埧闂�
-                //        Shared.Common.Room.CurrentRoom.ChangedRoom(device.CommonDevice, roomNameList);
-                //        RemoveFromParent();
-                //    };
-                //}
-                //else
-                //{
-                //    return;
-                //    //CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
-                //}
+                try
+                {
+                    CommonPage.Loading.Start();
+                    if (device.CommonDevice == null)
+                    {
+                        CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
+                        return;
+                    }
+                    if (device.CommonDevice.Type == ZigBee.Device.DeviceType.OnOffOutput)
+                    {
+                        if (device.IsCustomizeImage == false)
+                        {
+                            if (device.CommonDevice.DfunctionType == DeviceFunctionType.A寮�鍏�)
+                            {
+                                device.CommonDevice.IconPath = "Device/Switch.png";
+                            }
+                            else if (device.CommonDevice.DfunctionType == DeviceFunctionType.A鎻掑骇)
+                            {
+                                device.CommonDevice.IconPath = "Device/Socket1.png";
+                            }
+                            else if (device.CommonDevice.DfunctionType == DeviceFunctionType.A鐏厜)
+                            {
+                                device.CommonDevice.IconPath = "Device/Light.png";
+                            }
+                        }
+                        else
+                        {
+                            //鏀瑰浘鐗�
+                            device.CommonDevice.IconPath = deviceIMG.UnSelectedImagePath;
+                        }
+                    }
+                    else
+                    {
+                        //鏀瑰浘鐗�
+                        device.CommonDevice.IconPath = deviceIMG.UnSelectedImagePath;
+                    }
+                    bool result;
+                    new System.Threading.Thread(async () =>
+                    {
+                        result = await LocalDevice.Current.ReName(device.CommonDevice, nameRow.NameText.Text.Trim());
+                        Application.RunOnMainThread(() =>
+                        {
+                            CommonPage.Loading.Hide();
+                            if (result)
+                            {
+                                var alertSuccess = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.Success), Language.StringByID(R.MyInternationalizationString.Confrim));
+                                alertSuccess.Show();
+                                alertSuccess.ResultEventHandler += (senderSuccess, eSuccess) =>
+                                {
+                                    //鏀规埧闂�
+                                    Shared.Common.Room.CurrentRoom.ChangedRoom(device.CommonDevice, curRoom.Id);
+                                    device.CommonDevice.ReSave();
+                                    RemoveFromParent();
+                                };
+                            }
+                            else
+                            {
+                                CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain);
+                            }
+                        });
+                    })
+                    { IsBackground = true }.Start();
+                }
+                catch
+                {
+                    CommonPage.Loading.Hide();
+                }
             };
 
             #endregion
@@ -255,7 +438,9 @@
         /// <param name="device"></param>
         public void Init(DeviceUI device)
         {
-            roomName = Common.Room.CurrentRoom.GetRoomNameByDevice(device.CommonDevice);
+            roomName = device.GetZone();
+            befRoom = Common.Room.CurrentRoom.GetRoomByDevice(device.CommonDevice);
+            curRoom = Common.Room.CurrentRoom.GetRoomByDevice(device.CommonDevice);
         }
         #endregion
     }

--
Gitblit v1.8.0