using System; using System.Collections.Generic; namespace Shared.SimpleControl.Phone { public class SubaccountListView : FrameLayout { List subaccountList; VerticalScrolViewLayout subaccountListView; public SubaccountListView (List SubaccountList) { BackgroundColor = SkinStyle.Current.MainColor; subaccountList = SubaccountList; } public void ShowSubaccountListView () { #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 = "User 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 (640 - 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) => { modifySubaccount (null); }; 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); //#region ////当前住宅 //FrameLayout homeView = new FrameLayout () { // Height = Application.GetRealHeight (100), // BackgroundColor = SkinStyle.Current.Transparent //}; //contentView.AddChidren (homeView); //Button btnHomeText = new Button () { // X = Application.GetRealWidth (40), // Width = Application.GetRealWidth (600), // //TextID = R.MyInternationalizationString.Subaccount, // TextAlignment = TextAlignment.CenterLeft, // TextColor = SkinStyle.Current.TextColor1, //}; //homeView.AddChidren (btnHomeText); //if (UserConfig.Instance.CurrentRegion != null && !string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Name)) { // btnHomeText.Text = "Current residence: " + UserConfig.Instance.CurrentRegion.Name; //} //#endregion 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, 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); subaccountListView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight(660), }; contentView.AddChidren (subaccountListView); addSubaccountList (); addTipView (); } 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 = "Manage the member list of the current residence and share it to other accounts. \n Tips: You need to add the registered member account.", }; AddChidren (TipView); } void addSubaccountList () { subaccountListView.RemoveAll (); foreach (var subaccount in subaccountList) { //2020-01-07 带确认 if (subaccount.AccountType == 2) continue; RowLayout subaccountRowView = new RowLayout () { Height = Application.GetRealHeight(110), }; subaccountListView.AddChidren (subaccountRowView); //Button btnSubaccountReamrk = new Button () { // X = Application.GetRealWidth (40), // Height = Application.GetRealHeight(50), // TextAlignment = TextAlignment.CenterLeft, // TextColor = SkinStyle.Current.TextColor1, // Text = Language.StringByID(R.MyInternationalizationString.Remark) +": "+ subaccount.Account, //}; //subaccountRowView.AddChidren (btnSubaccountReamrk); Button btnDebugTitle = new Button () { X = Application.GetRealWidth (40), //Y = btnSubaccountReamrk.Bottom, //Height = Application.GetRealHeight(50), Text = subaccount.Account, TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, }; subaccountRowView.AddChidren (btnDebugTitle); Button rightButton = new Button () { X = Application.GetRealWidth (580), Width = Application.GetRealWidth (28), Height = Application.GetRealHeight (40), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Right.png", SelectedImagePath = "Item/RightSelected.png", }; subaccountRowView.AddChidren (rightButton); //EventHandler eHandler = (sender, e) => { // modifySubaccount (subaccount); //}; //subaccountRowView.MouseUpEventHandler += eHandler; //btnDebugTitle.MouseUpEventHandler += eHandler; //rightButton.MouseUpEventHandler += eHandler; 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) => { Alert delSubaccount = new Alert ("", Language.StringByID (R.MyInternationalizationString.DeleteSubaccount), Language.StringByID (R.MyInternationalizationString.cancel), Language.StringByID (R.MyInternationalizationString.confirm)); delSubaccount.Show (); delSubaccount.ResultEventHandler += (sender, e) => { if (e) { MainPage.Loading.Start ("Please wait..."); try { var requestObj = new DeletedSubAccountObj () { SubAccount = subaccount.SubAccountDistributedMark, HouseDistributedMark = UserConfig.Instance.CurrentRegion.Id, }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps (API.DeletedSubAccount, requestJson); if (revertObj.StateCode.ToUpper() == "SUCCESS") { Application.RunOnMainThread (() => { subaccountList.Remove (subaccount); addSubaccountList (); }); } else { //错误提示 ShowDeletedSubAccountErrorInfo (revertObj.StateCode); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } } }; }; } } void modifySubaccount (SubAccountRes subaccount) { bool isModify = true; if (subaccount == null) { subaccount = new SubAccountRes (); isModify = false; } Dialog dialog = new Dialog (); FrameLayout subaccountDialogView = new FrameLayout () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (650 - 100), 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, TextColor = SkinStyle.Current.DialogTextColor, }; subaccountDialogView.AddChidren (btnTitle); if (isModify) { btnTitle.TextID = R.MyInternationalizationString.Subaccount; } //Button btnSubaccountReamrk = new Button () { // X = Application.GetRealWidth (40), // Y = btnTitle.Bottom + Application.GetRealHeight (30), // Width = Application.GetRealWidth (420), // Height = Application.GetRealHeight (40), // TextID = R.MyInternationalizationString.Remark, // TextAlignment = TextAlignment.CenterLeft, // TextColor = SkinStyle.Current.TextColor, //}; //subaccountDialogView.AddChidren (btnSubaccountReamrk); //EditText etSubaccountReamrk = new EditText () { // X = Application.GetRealWidth (40), // Y = btnSubaccountReamrk.Bottom, // Width = Application.GetRealWidth (420), // Height = Application.GetRealHeight (80), // TextColor = SkinStyle.Current.TextColor, // Radius = 5, // BorderColor = SkinStyle.Current.DialogTitle, // BorderWidth = 2, // TextAlignment = TextAlignment.Center, // Text = subaccount.Remark, //}; //subaccountDialogView.AddChidren (etSubaccountReamrk); Button btnEmail = new Button () { X = Application.GetRealWidth (40), Y = btnTitle.Bottom + Application.GetRealHeight (30), Width = Application.GetRealWidth (420), Height = Application.GetRealHeight (40), Text = "SubAccount", 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, Text = subaccount.Account, }; subaccountDialogView.AddChidren (etEmail); //Button btnSubaccountPassword = new Button () { // X = Application.GetRealWidth (40), // Y = etEmail.Bottom + Application.GetRealHeight (20), // Width = Application.GetRealWidth (420), // Height = Application.GetRealHeight (40), // TextID = R.MyInternationalizationString.Password, // TextAlignment = TextAlignment.CenterLeft, // TextColor = SkinStyle.Current.TextColor, //}; //subaccountDialogView.AddChidren (btnSubaccountPassword); //EditText etSubaccountPassword = new EditText () { // X = Application.GetRealWidth (40), // Y = btnSubaccountPassword.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 (etSubaccountPassword); 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 (); //string addSubaccountPassword = etSubaccountPassword.Text.Trim (); //string addSubaccountReamrk = DateTime.Now.Ticks.ToString(); //string addSubaccountReamrk = etSubaccountReamrk.Text.Trim (); if (string.IsNullOrEmpty (addSubaccount)) { new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.TipEntrySubaccount), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show(etEmail); return; } //if (string.IsNullOrEmpty (addSubaccountPassword)) { // new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.PleaseEnterPassword), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show(etSubaccountPassword); // return; //} //if(string.IsNullOrEmpty (addSubaccountReamrk)){ // //new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.TipEntrySubaccountRemark), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show(etSubaccountReamrk); // //return; //} //if (addSubaccountPassword.Length < 6) { // new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show (etSubaccountPassword); // return; //} MainPage.Loading.Start ("Please wait..."); subaccount.Account = addSubaccount; //subaccount.Remark = addSubaccountReamrk; System.Threading.Tasks.Task.Run (() => { try { if (isModify) { //var requestObj = new EditSubAccountObj () { Id = subaccount.UserID, Email = addSubaccount, Password = addSubaccountPassword, Remark = addSubaccountReamrk }; //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); //var revertObj = MainPage.RequestHttps ("EditSubAccount", requestJson, true); //if (revertObj.StateCode.ToUpper() == "SUCCESS") { // Application.RunOnMainThread (() => { // addSubaccountList (); // dialog.Close (); // }); //} } else { //var requestObj = new SignSubAccountObj () { Email = addSubaccount, Password = addSubaccountPassword, Remark = addSubaccountReamrk }; var requestObj = new BindSubAccountObj () { HouseDistributedMark = UserConfig.Instance.CurrentRegion.Id, SubAccount = addSubaccount, }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps (API.BindSubAccount, requestJson); if (revertObj.StateCode.ToUpper () == "SUCCESS") { var requestObj2 = new GetSubAccountByDistributedMarkObj () { DistributedMark = UserConfig.Instance.CurrentRegion.Id, }; //var requestObj2 = new GetSubAccountListObj (); var requesetJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); var requesetRevertObj2 = MainPage.RequestHttps (API.GetSubAccountByDistributedMark, requesetJson2); if (requesetRevertObj2.StateCode.ToUpper () == "SUCCESS") { var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject> (requesetRevertObj2.ResponseData.ToString ()); subaccountList = responseDataObj; Application.RunOnMainThread (() => { new Alert ("", Language.StringByID (R.MyInternationalizationString.addsuccess), Language.StringByID (R.MyInternationalizationString.Close)).Show (); addSubaccountList (); dialog.Close (); }); } else { //错误提示 } } else { //BindSubAccount错误提示 ShowBindSubAccountErrorInfo (revertObj.StateCode); } } } 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 (); }); } }); }; //etSubaccountReamrk.EditorEnterAction += (obj) => { // etEmail.Foucs = true; //}; //etEmail.EditorEnterAction += (obj) => { // etSubaccountPassword.Foucs = true; //}; //etSubaccountPassword.EditorEnterAction += (obj) => { // Application.HideSoftInput (); //}; dialog.Show (); } /// /// /// /// void ShowDeletedSubAccountErrorInfo (string stateCodeStr) { string mes = ""; //2020-01-06 待补充 if (stateCodeStr == "NoExist") { mes = ErrorCode.FailedDelete; } else if (stateCodeStr == ErrorCode.NetworkError) { mes = ErrorCode.NetworkError; } else { mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr; } if (!string.IsNullOrEmpty (mes)) { Application.RunOnMainThread (() => { new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); } } /// ///(1)Success 则调用此接口成功 //(2)ParameterOrEmpty 提供的参数错误,详情见ErrorInfo字段 //(3)NoLogin,则响应字段中 [ErrorInfo] 为错误信息为 [无效登录Token!] //(4)AccountNoExists 子账号未注册,请绑定已注册的子账号! //(5)SameAccount,不能添加自己为子账号! (6)NoExist 用户不存在此住宅 //(7)Exist 账号已存在此住宅 //(8)Fail 操作失败 //(9)BeRestrict 权限不足 //(10)NoAddMainAccount 不能绑定主账号 // /// /// void ShowBindSubAccountErrorInfo (string stateCodeStr) { string mes = ""; //2020-01-06 待补充 if (stateCodeStr == "AccountNoExists") { mes = ErrorCode.SubAccountNoExists; } else if (stateCodeStr == "SameAccount") { mes = ErrorCode.SameAccount; } else if (stateCodeStr == "Exist") { mes = ErrorCode.SubAccountExist; } else if (stateCodeStr == "NoAddMainAccount") { mes = ErrorCode.NoAddMainAccount; } else if (stateCodeStr == ErrorCode.NetworkError) { mes = ErrorCode.NetworkError; } else { mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr; } if (!string.IsNullOrEmpty (mes)) { Application.RunOnMainThread (() => { new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); } } } }