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);
RefreshSubaccountList ();
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);
}
///
/// 刷新成员列表View
///
void RefreshSubaccountList ()
{
subaccountListView.RemoveAll ();
if(subaccountList == null) {
subaccountList = new List ();
}
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 revertObj = HttpServerRequest.Current.DeleteResidenceMemberAccount (subaccount);
if (revertObj.Code == StateCode.SUCCESS) {
Application.RunOnMainThread (() => {
subaccountList.Remove (subaccount);
RefreshSubaccountList ();
});
} else {
//错误提示
IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
}
} catch {
MainPage.FailureToServer ();
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
}
};
};
}
}
///
/// 添加或者修改成员信息,目前修改功能已去掉
///
///
void modifySubaccount (ResidenceMemberInfo subaccount)
{
bool isModify = true;
if (subaccount == null) {
subaccount = new ResidenceMemberInfo ();
isModify = false;
}
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,
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.nickName,
//};
//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() == StateCode.SUCCESS) {
// Application.RunOnMainThread (() => {
// addSubaccountList ();
// dialog.Close ();
// });
//}
} else {
//添加子账号
var revertObj = HttpServerRequest.Current.BindResidenceMemberAccount (addSubaccount, addSubaccount);
if (revertObj.Code == StateCode.SUCCESS) {
var revertObj2 = HttpServerRequest.Current.GetResidenceMemberAccount ();
if (revertObj2.Code == StateCode.SUCCESS) {
var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject> (revertObj2.Data.ToString ());
subaccountList = responseDataObj;
Application.RunOnMainThread (() => {
new Alert ("", Language.StringByID (R.MyInternationalizationString.AddedSuccessfully),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
RefreshSubaccountList ();
dialog.Close ();
});
} else {
//错误提示
IMessageCommon.Current.ShowErrorInfoAlter (revertObj2.Code);
}
} 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 ();
});
}
});
};
//etSubaccountReamrk.EditorEnterAction += (obj) => {
// etEmail.Foucs = true;
//};
//etEmail.EditorEnterAction += (obj) => {
// etSubaccountPassword.Foucs = true;
//};
//etSubaccountPassword.EditorEnterAction += (obj) => {
// Application.HideSoftInput ();
//};
dialog.Show ();
}
/////
///// 获取子账号列表
/////
//void GetSubaccountList ()
//{
// subaccountListView.RemoveAll ();
// subaccountList = new List ();
// MainPage.Loading.Start ("Please wait...");
// System.Threading.Tasks.Task.Run (() => {
// try {
// var revertObj = HttpServerRequest.Current.GetResidenceMemberAccount ();
// if (revertObj.Code == StateCode.SUCCESS) {
// var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject> (revertObj.Data.ToString ());
// subaccountList = responseDataObj;
// } else {
// IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
// }
// } catch (Exception ex) {
// //MainPage.FailureToServer ();
// Utlis.WriteLine (ex.Message);
// } finally {
// Application.RunOnMainThread (() => {
// RefreshSubaccountList ();
// MainPage.Loading.Hide ();
// });
// }
// });
//}
}
}