using System; using System.Collections.Generic; namespace Shared.SimpleControl.Phone { /// /// 调试人员管理页面 /// public class DebuggerManagementView : FrameLayout { /// /// /// VerticalScrolViewLayout bodyView; /// /// 当前住宅 /// RegionInfoResNew currentHome; /// /// /// /// public DebuggerManagementView (RegionInfoResNew home) { BackgroundColor = SkinStyle.Current.MainColor; this.currentHome = home; } /// /// /// public void ShowDebuggerManagementView () { #region ---TopView--- FrameLayout topView = new FrameLayout () { Height = Application.GetRealHeight (126), BackgroundColor = SkinStyle.Current.MainColor, }; AddChidren (topView); var back = new Button () { Y = Application.GetRealHeight (30), Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { (Parent as PageLayout).PageIndex -= 1; }; Button NameButton = new Button () { Width = Application.GetRealWidth (400), Height = Application.GetMinReal (90), Text = "Debugger Management", TextColor = SkinStyle.Current.TextColor1, Gravity = Gravity.CenterHorizontal, TextAlignment = TextAlignment.Center, Y = Application.GetRealHeight (30), TextSize = 20, }; topView.AddChidren (NameButton); Button ItemButton = new Button () { Width = Application.GetRealWidth (55), Height = Application.GetRealHeight (55), UnSelectedImagePath = "Item/+.png", SelectedImagePath = "Item/+.png", Y = Application.GetRealHeight (50), X = Application.GetRealWidth (Application.DesignWidth - 80), }; topView.AddChidren (ItemButton); #endregion //2020-07-01 if (UserConfig.Instance.CurrentRegion != null && !string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Name)) { NameButton.Text = UserConfig.Instance.CurrentRegion.Name; } EventHandler addSubaccountHandler = (sender, e) => { showAddDebugger (); }; ItemButton.MouseUpEventHandler += addSubaccountHandler; FrameLayout topUserMsgView = new FrameLayout () { Y = Application.GetRealHeight (126), Height = Application.GetRealHeight (175), BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (topUserMsgView); Button btnUserIcon = new Button () { X = Application.GetRealWidth (27), Width = Application.GetRealWidth (96), Height = Application.GetRealWidth (96), Gravity = Gravity.CenterVertical, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, UnSelectedImagePath = "AccountSettings/UserIcon.png", }; topUserMsgView.AddChidren (btnUserIcon); Button btnUserName = new Button () { X = btnUserIcon.Right + Application.GetRealWidth (20), Y = Application.GetRealHeight (40), Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (50), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, Text = MainPage.LoginUser.Name == "" ? Language.StringByID (R.MyInternationalizationString.Account) : MainPage.LoginUser.Name, }; topUserMsgView.AddChidren (btnUserName); Button btnUserAccount = new Button () { X = btnUserName.X, Y = btnUserName.Bottom, Width = btnUserName.Width, Height = btnUserName.Height, TextAlignment = TextAlignment.CenterLeft, Text = "", TextColor = SkinStyle.Current.TextColor1 }; topUserMsgView.AddChidren (btnUserAccount); if (MainPage.LoginUser != null) { btnUserAccount.Text += MainPage.LoginUser.AccountString; } VerticalScrolViewLayout contentView = new VerticalScrolViewLayout () { Y = topUserMsgView.Bottom, Height = Application.GetRealHeight (1136 - 80) - topUserMsgView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor, ScrollEnabled = false, }; AddChidren (contentView); FrameLayout subaccountView = new FrameLayout () { Height = Application.GetRealHeight (50), BackgroundColor = SkinStyle.Current.MainColor }; contentView.AddChidren (subaccountView); Button btnSubaccountText = new Button () { X = Application.GetRealWidth (40), Width = Application.GetRealWidth (600), //TextID = R.MyInternationalizationString.Subaccount, Text = "Debugger permissions", TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, }; subaccountView.AddChidren (btnSubaccountText); Button btnSubaccountLine = new Button () { Y = Application.GetRealHeight (105), Height = Application.GetRealHeight (10), BackgroundColor = SkinStyle.Current.MainColor, }; subaccountView.AddChidren (btnSubaccountLine); bodyView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (660), }; contentView.AddChidren (bodyView); //addTipView (); //刷新调试人员管理菜单 RefreshListView (); } void addTipView () { var TipView = new Button () { Width = LayoutParams.MatchParent, Y = Application.GetRealHeight (Application.DesignHeight - 80), Height = Application.GetRealHeight (80), BackgroundColor = 0xFFFFFFE0, TextSize = 11, TextColor = 0xFF1F1F1F, TextAlignment = TextAlignment.Center, IsMoreLines = true, Text = "Debugger permissions \n Tips: Management staff remotely access your gateway.", }; AddChidren (TipView); } /// /// 刷新调试人员管理菜单 /// void RefreshListView () { bodyView.RemoveAll (); if (!string.IsNullOrEmpty (currentHome.debugStaffUserId) && currentHome.debugStaffUserId != "-1") { RowLayout subaccountRowView = new RowLayout () { Height = Application.GetRealHeight (110), }; bodyView.AddChidren (subaccountRowView); Button btnDebugTitle = new Button () { X = Application.GetRealWidth (40), //Y = btnSubaccountReamrk.Bottom, //Height = Application.GetRealHeight(50), Text = "Debugger", TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, }; subaccountRowView.AddChidren (btnDebugTitle); Button tipBtn = new Button { X = Application.GetRealWidth (40), Y = Application.GetRealHeight (80), Height = Application.GetRealHeight (20), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, TextSize = 11, Text = "Allows debuggers remote access to your gateway" }; subaccountRowView.AddChidren (tipBtn); Button btnRowLine = new Button () { Y = Application.GetRealHeight (105), Height = Application.GetRealHeight (5), BackgroundColor = SkinStyle.Current.MainColor, }; subaccountRowView.AddChidren (btnRowLine); Button btnDel = new Button () { TextID = R.MyInternationalizationString.Del, BackgroundColor = SkinStyle.Current.DelColor }; subaccountRowView.AddRightView (btnDel); btnDel.MouseUpEventHandler += (sender2, e2) => { showDeleteDebuggerAlert (); }; var tempSwitch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), X = Application.GetRealWidth (Application.DesignWidth - 90 - 20), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/SwitchClose.png", SelectedImagePath = "Item/SwitchOpen.png", }; subaccountRowView.AddChidren (tempSwitch); tempSwitch.IsSelected = currentHome.debugPerm; tempSwitch.MouseUpEventHandler += (sender3, e3) => { updateDebugger (tempSwitch); }; } } /// /// 添加调试人员 /// void showAddDebugger () { Dialog dialog = new Dialog (); FrameLayout subaccountDialogView = new FrameLayout () { Width = Application.GetRealWidth (500), //Height = Application.GetRealHeight (650 - 100), Height = Application.GetRealHeight (390), BackgroundColor = SkinStyle.Current.DialogColor, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, Gravity = Gravity.Center, }; dialog.AddChidren (subaccountDialogView); Button btnTitle = new Button () { Height = Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.DialogTitle, TextAlignment = TextAlignment.Center, //TextID = R.MyInternationalizationString.AddSubaccount, Text = "Add debugger", TextColor = SkinStyle.Current.DialogTextColor, }; subaccountDialogView.AddChidren (btnTitle); bool isChange = false; if (!string.IsNullOrEmpty (currentHome.debugStaffUserId) && currentHome.debugStaffUserId != "-1") { isChange = true; btnTitle.Text = "Change debugger"; } Button btnEmail = new Button () { X = Application.GetRealWidth (40), Y = btnTitle.Bottom + Application.GetRealHeight (30), Width = Application.GetRealWidth (420), Height = Application.GetRealHeight (40), Text = "Account", TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor, }; subaccountDialogView.AddChidren (btnEmail); EditText etEmail = new EditText () { X = Application.GetRealWidth (40), Y = btnEmail.Bottom, Width = Application.GetRealWidth (420), Height = Application.GetRealHeight (80), TextColor = SkinStyle.Current.TextColor, Radius = 5, BorderColor = SkinStyle.Current.DialogTitle, BorderWidth = 2, TextAlignment = TextAlignment.Center, }; subaccountDialogView.AddChidren (etEmail); FrameLayout bottomView = new FrameLayout () { Y = subaccountDialogView.Height - Application.GetRealHeight (90), Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.DialogTitle, }; subaccountDialogView.AddChidren (bottomView); Button btnCancel = new Button () { Width = Application.GetRealWidth (249), TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.DialogTextColor, TextID = R.MyInternationalizationString.cancel, }; bottomView.AddChidren (btnCancel); btnCancel.MouseUpEventHandler += (sender3, e3) => { dialog.Close (); }; Button btnBottomLine = new Button () { X = btnCancel.Right, Width = Application.GetRealWidth (2), BackgroundColor = SkinStyle.Current.White20Transparent, }; bottomView.AddChidren (btnBottomLine); Button btnSaveSubaccount = new Button () { X = btnBottomLine.Right, Width = Application.GetRealWidth (248), TextID = R.MyInternationalizationString.SAVE, TextColor = SkinStyle.Current.DialogTextColor, TextAlignment = TextAlignment.Center, }; bottomView.AddChidren (btnSaveSubaccount); btnSaveSubaccount.MouseUpEventHandler += (sender3, e3) => { string addSubaccount = etEmail.Text.Trim (); if (string.IsNullOrEmpty (addSubaccount)) { new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.TipEntrySubaccount), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show (etEmail); return; } MainPage.Loading.Start ("Please wait..."); System.Threading.Tasks.Task.Run (() => { try { //添加调试人员 var revertObj = HttpServerRequest.Current.AddDebugStaff (addSubaccount); if (revertObj.Code == StateCode.SUCCESS) { currentHome.debugPerm = true; currentHome.debugStaffUserId = addSubaccount; Application.RunOnMainThread (() => { if (isChange) { new Alert ("", "Changed successfully", Language.StringByID (R.MyInternationalizationString.Close)).Show (); } else { new Alert ("", Language.StringByID (R.MyInternationalizationString.AddedSuccessfully), Language.StringByID (R.MyInternationalizationString.Close)).Show (); } dialog.Close (); RefreshListView (); }); } else { //BindSubAccount错误提示 IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); } } catch (Exception ex) { Application.RunOnMainThread (() => { new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); Utlis.WriteLine (ex.ToString ()); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; dialog.Show (); } /// /// 删除调试人员 /// void showDeleteDebuggerAlert () { Alert delSubaccount = new Alert ("", "Do you want to delete the debugger?", Language.StringByID (R.MyInternationalizationString.cancel), Language.StringByID (R.MyInternationalizationString.confirm)); delSubaccount.Show (); delSubaccount.ResultEventHandler += (sender, e) => { if (e) { MainPage.Loading.Start ("Please wait..."); System.Threading.Tasks.Task.Run (() => { try { var revertObj = HttpServerRequest.Current.DelDebugStaff (); if (revertObj.Code == StateCode.SUCCESS) { currentHome.debugPerm = false; currentHome.debugStaffUserId = "-1"; Application.RunOnMainThread (() => { bodyView.RemoveAll (); }); } else { //错误提示 IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); } }; } /// /// 更新调试人员调试权限 /// /// void updateDebugger (Button tempSwitch) { bool isSelected = !tempSwitch.IsSelected; MainPage.Loading.Start ("Please wait..."); System.Threading.Tasks.Task.Run (() => { try { var revertObj = HttpServerRequest.Current.UpdateDebugPerm (isSelected); if (revertObj.Code == StateCode.SUCCESS) { Application.RunOnMainThread (() => { tempSwitch.IsSelected = isSelected; currentHome.debugPerm = isSelected; }); } else { //错误提示 IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); } } }