using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.GatewayManage
{
///
/// 替换网关时,选择网关备份的列表界面
///
public class GatewayReplaceBackUpListForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 列表控件
///
private VerticalListControl listView = null;
///
/// 真实物理网关(新网关)
///
private ZbGateway realGateway = null;
///
/// 被替换的目标网关
///
private string targetGwId = string.Empty;
///
/// 当前选择的备份
///
private BackupListNameInfo nowSelectInfo = null;
///
/// 当前选择的控件
///
private MostRightIconControl nowbtnSelect = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 真实物理网关(新网关)
/// 被替换的目标网关
public void ShowForm(ZbGateway i_realGateway, string i_targetGwId)
{
this.realGateway = i_realGateway;
this.targetGwId = i_targetGwId;
//设置标题信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uSelectUseBackup));
//初始化中部控件
this.InitMiddleFrame();
}
///
/// 初始化中部控件
///
private void InitMiddleFrame()
{
//清空bodyFrame
this.ClearBodyFrame();
var frameBack = new FrameLayout();
frameBack.Height = Application.GetRealHeight(11);
frameBack.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(frameBack);
listView = new VerticalListControl(12);
listView.Y = frameBack.Bottom;
listView.Height = bodyFrameLayout.Height - frameBack.Height;
listView.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(listView);
HdlThreadLogic.Current.RunThread(() =>
{
//从云端获取数据
this.SetBackupInfoToForm();
});
}
#endregion
#region ■ 从云端获取数据_____________________
///
/// 从云端获取数据
///
private void SetBackupInfoToForm()
{
//进度条
this.ShowProgressBar();
//获取自动备份的数据
var pageAuto = HdlBackupLogic.Current.GetBackupListNameFromDB(3, this.targetGwId);
if (pageAuto == null)
{
//关闭进度条
this.CloseProgressBar(ShowReLoadMode.YES);
return;
}
//从云端获取数据
var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(2, this.targetGwId);
if (pageData == null)
{
//关闭进度条
this.CloseProgressBar(ShowReLoadMode.YES);
return;
}
//关闭进度条
this.CloseProgressBar();
if (pageAuto.Count == 0 && pageData.Count == 0)
{
//目标网关检测不到备份数据,无法执行替换操作
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uTaegetGatewayNotHadBackupAndDoNotReplace));
return;
}
HdlThreadLogic.Current.RunMain(() =>
{
listView.RemoveAll();
listView.RecoverHeight();
if (pageAuto.Count > 0)
{
pageAuto[0].IsAutoBack = 1;
//添加自动备份行
this.AddRowlayout(pageAuto[0], pageData.Count > 0, true);
}
for (int i = 0; i < pageData.Count; i++)
{
//添加备份行
this.AddRowlayout(pageData[i], i != pageData.Count - 1, false);
}
if (pageData.Count > 0 || pageAuto.Count > 0)
{
//替换
var btnDownload = new BottomClickButton();
btnDownload.TextID = R.MyInternationalizationString.uReplace;
bodyFrameLayout.AddChidren(btnDownload);
btnDownload.ButtonClickEvent += (sender, e) =>
{
if (this.nowSelectInfo == null)
{
return;
}
//是否使用备份:{0}?
string msg = Language.StringByID(R.MyInternationalizationString.uSelectUseBackupConfirmMsg).Replace("{0}", this.nowbtnSelect.MainKey);
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
{
//执行网关替换操作
this.DoReplaceGateway();
}, null, 3);
};
//调整真实高度
listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
}
});
}
#endregion
#region ■ 添加备份行_________________________
///
/// 添加备份行
///
///
///
///
private void AddRowlayout(BackupListNameInfo fileInfo, bool addLine, bool isAuto)
{
var rowLayout = new RowLayoutControl(listView.rowSpace / 2);
listView.AddChidren(rowLayout);
//备份名字
var txtText = rowLayout.frameTable.AddTopView(fileInfo.BackupName, 700);
if (isAuto == true)
{
txtText.TextID = R.MyInternationalizationString.uAutoBackup;
}
//时间 2019-11-11T11:31:01
var btnTime = rowLayout.frameTable.AddBottomView("", 600);
if (fileInfo.CreatedOnUtc.Length >= 19)
{
btnTime.Text = UserCenterLogic.ConvertUtcTimeToLocalTime(fileInfo.CreatedOnUtc).ToString("yyyy.MM.dd HH:mm:ss");
}
//底线
if (addLine == true)
{
rowLayout.frameTable.AddBottomLine();
}
//选择
var btnSelect = rowLayout.frameTable.AddMostRightEmptyIcon(58, 58);
btnSelect.UnSelectedImagePath = "Item/ItemUnSelected.png";
btnSelect.SelectedImagePath = "Item/ItemSelected.png";
rowLayout.frameTable.ButtonClickEvent += (sender, e) =>
{
btnSelect.IsSelected = !btnSelect.IsSelected;
if (btnSelect.IsSelected == true)
{
this.nowSelectInfo = fileInfo;
if (this.nowbtnSelect != null)
{
nowbtnSelect.IsSelected = false;
}
nowbtnSelect = btnSelect;
nowbtnSelect.MainKey = txtText.Text;
}
else
{
this.nowSelectInfo = null;
this.nowbtnSelect = null;
}
};
}
#endregion
#region ■ 执行网关替换操作___________________
///
/// 执行网关替换操作
///
private void DoReplaceGateway()
{
//执行更换网关
HdlGatewayLogic.Current.DoReplaceGateway(this.realGateway, this.targetGwId, this.nowSelectInfo, (div) =>
{
if (div == 1)
{
if (GatewayResourse.AppOldSelectGatewayId == this.targetGwId)
{
//如果被替换的网关是设备列表界面正在显示的网关的话,需要置空
GatewayResourse.AppOldSelectGatewayId = string.Empty;
}
HdlThreadLogic.Current.RunMain(() =>
{
//显示成功的界面
this.ShowSuccessMsg();
});
}
});
}
///
/// 显示成功的界面
///
private void ShowSuccessMsg()
{
var frameBack = new FrameLayout();
frameBack.BackgroundColor = 0x80000000;
this.AddChidren(frameBack);
var frameMsg = new FrameLayout();
frameMsg.BackgroundColor = UserCenterColor.Current.White;
frameMsg.Width = Application.GetRealWidth(622);
frameMsg.Height = Application.GetRealHeight(317);
frameMsg.Radius = (uint)Application.GetRealHeight(17);
frameMsg.Gravity = Gravity.CenterHorizontal;
frameMsg.Y = Application.GetRealHeight(792);
frameBack.AddChidren(frameMsg);
//提示
var btnTitle = new NormalViewControl(492, 65, true);
btnTitle.Y = Application.GetRealHeight(68);
btnTitle.Gravity = Gravity.CenterHorizontal;
btnTitle.TextID = R.MyInternationalizationString.NormalTip;
btnTitle.TextAlignment = TextAlignment.Center;
btnTitle.TextColor = 0xFF333443;
frameMsg.AddChidren(btnTitle);
//替换网关成功
var btnSuccess = new NormalViewControl(frameMsg.Width, Application.GetRealHeight(60), false);
btnSuccess.Y = Application.GetRealHeight(166);
btnSuccess.TextAlignment = TextAlignment.Center;
btnSuccess.TextColor = UserCenterColor.Current.TextGrayColor1;
btnSuccess.TextID = R.MyInternationalizationString.uReplacegatewaySuccess;
frameMsg.AddChidren(btnSuccess);
HdlThreadLogic.Current.RunThread(() =>
{
System.Threading.Thread.Sleep(2000);
HdlThreadLogic.Current.RunMain(() =>
{
this.CloseForm();
//把网关替换一览界面也关了
this.CloseFormByFormName("GatewayReplaceListForm");
});
});
}
#endregion
}
}