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 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.GetRealHeight (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) - 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, 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 (); } void addSubaccountList () { subaccountListView.RemoveAll (); foreach (var subaccount in subaccountList) { if (subaccount.UserType == 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 RemoveSubAccountObj () { Email = subaccount.Account }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps ("RemoveSubAccount", requestJson); if (revertObj.StateCode == "SUCCESS") { Application.RunOnMainThread (() => { subaccountList.Remove (subaccount); addSubaccountList (); }); } } 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="User name", 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); if (revertObj.StateCode == "SUCCESS") { Application.RunOnMainThread (() => { addSubaccountList (); dialog.Close (); }); } } else { var requestObj = new SignSubAccountObj () { Email = addSubaccount, Password = addSubaccountPassword, Remark = addSubaccountReamrk }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); var revertObj = MainPage.RequestHttps ("SignSubAccount", requestJson); if (revertObj.StateCode == "SUCCESS") { var requestObj2 = new GetSubAccountListObj (); var requesetJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); var requesetRevertObj2 = MainPage.RequestHttps ("GetSubAccountList", requesetJson2); if (requesetRevertObj2.StateCode == "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 (); }); } } } } catch (Exception ex) { Application.RunOnMainThread (() => { new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); Console.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 (); } } }