using Shared.Common;
using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter.Transfer
{
///
/// 执行过户操作的界面
///
public class TransferingResidenceForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 1:移交给用户 2:授权给调试人员
///
private int TransferDiv = 0;
///
/// 成员信息
///
private AccountInfoResult memberResult = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 账号信息
/// 1:移交给用户 2:授权给调试人员
public void ShowForm(AccountInfoResult i_memberResult, int i_TransferDiv)
{
this.ScrollEnabled = false;
this.TransferDiv = i_TransferDiv;
this.memberResult = i_memberResult;
//设置头部信息
base.SetTitleText(i_TransferDiv == 1
? Language.StringByID(R.MyInternationalizationString.HandoverToUser).Replace("{0}", string.Empty)
: Language.StringByID(R.MyInternationalizationString.AuthorizedToCommissioningPersonnel).Replace("{0}", string.Empty));
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化中部信息
///
private void InitMiddleFrame()
{
//清空bodyFrame
this.ClearBodyFrame();
//住宅的图标
var btnIcon1 = new PicViewControl(268, 268);
btnIcon1.Y = Application.GetRealHeight(366);
btnIcon1.X = Application.GetRealWidth(139);
btnIcon1.UnSelectedImagePath = "Item/TransferOfResidenceIcon.png";
bodyFrameLayout.AddChidren(btnIcon1);
//住宅名字 (以中间为基准,左右间距50)
var btnHouseName = new NormalViewControl(bodyFrameLayout.Width / 2 - Application.GetRealWidth(100), Application.GetRealHeight(110), false);
btnHouseName.X = Application.GetRealWidth(50);
btnHouseName.Y = btnIcon1.Bottom + Application.GetRealHeight(23);
btnHouseName.IsBold = true;
btnHouseName.IsMoreLines = true;
btnHouseName.TextAlignment = TextAlignment.Center;
btnHouseName.TextSize = 16;
btnHouseName.Text = Config.Instance.Home.Name;
bodyFrameLayout.AddChidren(btnHouseName);
//头像
var btnUserIcon = new ImageView();
btnUserIcon.Height = this.GetPictrueRealSize(268);
btnUserIcon.Width = this.GetPictrueRealSize(268);
btnUserIcon.Radius = (uint)this.GetPictrueRealSize(268) / 2;
if (memberResult.HeadImage != null)
{
btnUserIcon.ImageBytes = memberResult.HeadImage;
}
else
{
btnUserIcon.ImagePath = "Center/Admin.png";
}
btnUserIcon.Y = btnIcon1.Y;
btnUserIcon.X = bodyFrameLayout.Width - Application.GetRealWidth(139) - this.GetPictrueRealSize(268);
bodyFrameLayout.AddChidren(btnUserIcon);
//昵称 (以中间为基准,左右间距50)
var btnName = new NormalViewControl(btnHouseName.Width, btnHouseName.Height, false);
btnName.X = btnHouseName.Right + Application.GetRealWidth(100);
btnName.Y = btnHouseName.Y;
btnName.IsBold = true;
btnName.IsMoreLines = true;
btnName.TextAlignment = TextAlignment.Center;
btnName.TextSize = 16;
btnName.Text = memberResult.MemberName;
bodyFrameLayout.AddChidren(btnName);
//开启连接的假想动画效果线程
this.StartConcetionAnimeteThread(btnIcon1.Right + Application.GetRealWidth(49));
//终止
var btnCancel = new BottomClickButton();
btnCancel.TextID = R.MyInternationalizationString.uTermination;
bodyFrameLayout.AddChidren(btnCancel);
btnCancel.ButtonClickEvent += (sender, e) =>
{
this.CloseForm();
};
//初始化消息控件
this.InitMsgControl(btnCancel);
}
#endregion
#region ■ 假想动画___________________________
///
/// 开启连接的假想动画效果线程
///
private void StartConcetionAnimeteThread(int XX)
{
//生成点号图样
int pointXX = XX;
for (int i = 0; i < 7; i++)
{
var btnPoint = new NormalViewControl(14, 8, true);
btnPoint.Radius = (uint)Application.GetRealHeight(8) / 2;
btnPoint.BackgroundColor = 0xffd5d5d5;
btnPoint.Y = Application.GetRealHeight(498);
btnPoint.X = pointXX;
bodyFrameLayout.AddChidren(btnPoint);
pointXX = btnPoint.Right + Application.GetRealWidth(14);
}
int iconSize = this.GetPictrueRealSize(24);
var listPoint = new List();
//跳动的间距
int intSpace = Application.GetRealWidth(14 + 14);
for (int i = 0; i < 7; i++)
{
//X轴+Index*(图标大小+间距)
listPoint.Add(XX + i * intSpace);
}
var btnRound = new PicViewControl(iconSize, iconSize, false);
btnRound.Radius = (uint)iconSize / 2;
btnRound.BackgroundColor = UserCenterColor.Current.ConcetionRoundColor;
btnRound.X = listPoint[0];
btnRound.Y = Application.GetRealHeight(490);
bodyFrameLayout.AddChidren(btnRound);
HdlThreadLogic.Current.RunThread(() =>
{
int index = 1;
while (this.Parent != null)
{
System.Threading.Thread.Sleep(500);
HdlThreadLogic.Current.RunMain(() =>
{
if (btnRound != null)
{
btnRound.X = listPoint[index];
index++;
if (index == listPoint.Count)
{
index = 0;
}
}
});
}
});
}
#endregion
#region ■ 执行过户___________________________
///
/// 执行过户
///
private void DoTransferResidence()
{
this.ShowProgressBar();
System.Threading.Thread.Sleep(1500);
var pra2 = new
{
RequestVersion = CommonPage.RequestVersion,
RequestSource = 0,
LoginAccessToken = Config.Instance.Token,
HomeId = Config.Instance.Home.Id,
TargetAccount = this.memberResult.Account
};
//☆マーク☆
//var result = HdlUserCenterLogic.GetResultCodeByRequestHttps("App/SellHome", false, pra2, new List { "NotCheck" });
//bool success = result.ToLower() == "success";
bool success = false;
this.CloseProgressBar();
HdlThreadLogic.Current.RunMain(() =>
{
var form = new TransferResidenceResultForm();
form.AddForm(this.memberResult, success);
form.FinishEvent += () =>
{
if (success == false)
{
//重试
HdlThreadLogic.Current.RunThread(() =>
{
//执行过户
this.DoTransferResidence();
});
}
else
{
//成功过户 则切换住宅
var listLocalHouse = HdlResidenceLogic.Current.GetAllLocalResidenceListByDirectory();
if (listLocalHouse.Count == 1)
{
//如果只有一个住宅,则过户之后,直接退到登陆界面
HdlAccountLogic.Current.ReLoginAgain(Config.Instance.Account);
return;
}
else
{
HdlThreadLogic.Current.RunThread(() =>
{
this.ShowProgressBar();
//取一个住宅id
string houseId = string.Empty;
foreach (var myHouse in listLocalHouse)
{
houseId = myHouse.Id;
if (houseId != Config.Instance.Home.Id)
{
//随便取一个和当前住宅不相等的ID
break;
}
}
//当前住宅ID
string nowHouseId = Config.Instance.Home.Id;
//切换住宅
bool result2 = HdlResidenceLogic.Current.SwitchResidence(houseId);
//删掉这个文件夹
HdlResidenceLogic.Current.DeleteHouseMemmory(nowHouseId);
if (result2 == true)
{
HdlThreadLogic.Current.RunMain(() =>
{
//关闭全部的界面.直到住宅列表界面
HdlFormLogic.Current.CloseAllOpenForm("ResidenceListMainForm");
});
}
this.CloseProgressBar();
});
}
}
};
});
}
#endregion
#region ■ 一般方法___________________________
///
/// 初始化消息控件
///
private void InitMsgControl(BottomClickButton btnCancel)
{
string msg = this.TransferDiv == 1
? Language.StringByID(R.MyInternationalizationString.uHandoverToUserPleaseWaitting)
: Language.StringByID(R.MyInternationalizationString.uAuthorizingToDebuggingPersonnelPleaseWaitting);
//正在移交给用户,请稍后... 正在授权给调试人员,请稍后...
var btnMsg = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(60), false);
btnMsg.Y = Application.GetRealHeight(916);
btnMsg.TextAlignment = TextAlignment.Center;
btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
btnMsg.Text = msg;
bodyFrameLayout.AddChidren(btnMsg);
HdlThreadLogic.Current.RunThread(() =>
{
int timeOut = 15;
while (timeOut >= 0 && this.Parent != null)
{
HdlThreadLogic.Current.RunMain(() =>
{
btnMsg.Text = msg + timeOut + "s";
if (timeOut == 0)
{
btnMsg.Text = msg;
}
}, ShowErrorMode.NO);
System.Threading.Thread.Sleep(1000);
timeOut--;
}
if (timeOut <= 0)
{
//执行过户操作
this.DoTransferResidence();
}
});
}
#endregion
}
}