using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.GatewayManage
|
{
|
/// <summary>
|
/// 网关备份的列表界面
|
/// </summary>
|
public class GatewayBackUpListForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalListControl listView = null;
|
/// <summary>
|
/// 网关对象(这个是真实物理网关对象)
|
/// </summary>
|
private ZbGateway realGateway = null;
|
/// <summary>
|
/// 当前选择的备份ID
|
/// </summary>
|
private string nowSelectBackId = string.Empty;
|
/// <summary>
|
/// 当前选择的控件
|
/// </summary>
|
private MostRightIconControl nowbtnSelect = null;
|
/// <summary>
|
/// 下载按钮
|
/// </summary>
|
private BottomClickButton btnDownload = null;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_zbGateway"></param>
|
public void ShowForm(ZbGateway i_zbGateway)
|
{
|
this.realGateway = i_zbGateway;
|
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDwonloadData));
|
|
//初始化中部控件
|
this.InitMiddleFrame();
|
}
|
|
/// <summary>
|
/// 初始化中部控件
|
/// </summary>
|
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 ■ 从云端获取数据_____________________
|
|
/// <summary>
|
/// 从云端获取数据
|
/// </summary>
|
private void SetBackupInfoToForm()
|
{
|
this.nowSelectBackId = string.Empty;
|
this.nowbtnSelect = null;
|
|
//进度条
|
this.ShowProgressBar();
|
|
//获取自动备份的数据
|
var pageAuto = HdlBackupLogic.Current.GetBackupListNameFromDB(3, realGateway.GwId);
|
if (pageAuto == null)
|
{
|
//关闭进度条
|
this.CloseProgressBar(ShowReLoadMode.YES);
|
return;
|
}
|
|
//从云端获取数据
|
var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(2, realGateway.GwId);
|
if (pageData == null)
|
{
|
//关闭进度条
|
this.CloseProgressBar(ShowReLoadMode.YES);
|
return;
|
}
|
//关闭进度条
|
this.CloseProgressBar();
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
listView.RemoveAll();
|
listView.RecoverHeight();
|
|
//自动备份的ID
|
string autoID = string.Empty;
|
if (pageAuto.Count > 0)
|
{
|
autoID = pageAuto[0].Id;
|
//添加自动备份行
|
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);
|
}
|
|
this.btnDownload?.RemoveFromParent();
|
if (pageData.Count > 0 || pageAuto.Count > 0)
|
{
|
//下载
|
this.btnDownload = new BottomClickButton();
|
btnDownload.TextID = R.MyInternationalizationString.uDownLoad;
|
bodyFrameLayout.AddChidren(btnDownload);
|
btnDownload.ButtonClickEvent += (sender, e) =>
|
{
|
if (this.nowSelectBackId == string.Empty)
|
{
|
return;
|
}
|
//是否要下载并恢复数据?
|
string msg = Language.StringByID(R.MyInternationalizationString.uDownLoadAndRecoverMsg);
|
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
{
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//读取备份文档
|
bool result = HdlGatewayBackupLogic.Current.RecoverGateway(this.realGateway, this.nowSelectBackId, autoID == this.nowSelectBackId ? 1 : 0);
|
if (result == true)
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//关闭这个界面
|
this.CloseForm();
|
});
|
}
|
});
|
});
|
};
|
//调整真实高度
|
listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 添加备份行_________________________
|
|
/// <summary>
|
/// 添加备份行
|
/// </summary>
|
/// <param name="fileInfo"></param>
|
/// <param name="addLine"></param>
|
/// <param name="isAuto"></param>
|
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.nowSelectBackId = fileInfo.Id;
|
if (nowbtnSelect != null)
|
{
|
nowbtnSelect.IsSelected = false;
|
}
|
nowbtnSelect = btnSelect;
|
}
|
else
|
{
|
this.nowSelectBackId = string.Empty;
|
this.nowbtnSelect = null;
|
}
|
};
|
|
//自动备份不允许编辑
|
if (isAuto == false)
|
{
|
//编辑
|
var btnEditor = rowLayout.AddEditorControl();
|
btnEditor.ButtonClickEvent += (sender, e) =>
|
{
|
//显示编辑备考名画面
|
this.ShowEditorBackupForm(fileInfo);
|
};
|
|
//删除
|
var btnDelete = rowLayout.AddDeleteControl();
|
btnDelete.ButtonClickEvent += (sender, e) =>
|
{
|
//确认删除该备份数据?
|
string msg = Language.StringByID(R.MyInternationalizationString.uDoDeleteBackupMsg);
|
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
{
|
//删除备份文档
|
this.DeleteBackInfo(fileInfo.Id);
|
});
|
};
|
}
|
}
|
|
#endregion
|
|
#region ■ 编辑备份名称_______________________
|
|
/// <summary>
|
/// 编辑备份名称
|
/// </summary>
|
/// <param name="BackupClassId"></param>
|
/// <param name="backName"></param>
|
private void EditorBackInfo(string BackupClassId, string backName)
|
{
|
var Pra = new EditorBackUpNamePra();
|
Pra.BackupClassId = BackupClassId;
|
Pra.BackupName = backName;
|
//获取控制主人账号的Token
|
Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
|
bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/UpdateHomeAppGatewayName", true, Pra);
|
if (result == false)
|
{
|
return;
|
}
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//从云端获取数据
|
this.SetBackupInfoToForm();
|
});
|
}
|
|
#endregion
|
|
#region ■ 删除备份文档_______________________
|
|
/// <summary>
|
/// 删除备份文档
|
/// </summary>
|
/// <param name="BackupClassId"></param>
|
private void DeleteBackInfo(string BackupClassId)
|
{
|
bool success = HdlBackupLogic.Current.DeleteDbBackupData(BackupClassId);
|
if (success == false)
|
{
|
return;
|
}
|
if (this.nowSelectBackId == BackupClassId)
|
{
|
this.nowSelectBackId = string.Empty;
|
this.nowbtnSelect = null;
|
}
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//从云端获取数据
|
this.SetBackupInfoToForm();
|
});
|
}
|
|
#endregion
|
|
#region ■ 显示编辑备考名画面_________________
|
|
/// <summary>
|
/// 显示编辑备考名画面
|
/// </summary>
|
/// <param name="fileInfo"></param>
|
/// <returns></returns>
|
private void ShowEditorBackupForm(BackupListNameInfo fileInfo)
|
{
|
//生成一个弹窗画面
|
var dialogForm = new DialogInputControl();
|
|
//编辑备份
|
dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorBackup));
|
//请输入备份名称
|
dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInpuBackupName));
|
dialogForm.Text = fileInfo.BackupName;
|
|
//按下确认按钮
|
dialogForm.ComfirmClickEvent += ((txtvalue) =>
|
{
|
//画面关闭
|
dialogForm.CloseDialog();
|
//名字一样时,不处理
|
if (txtvalue != fileInfo.BackupName)
|
{
|
//编辑备份名称
|
this.EditorBackInfo(fileInfo.Id, txtvalue);
|
}
|
});
|
}
|
|
#endregion
|
}
|
}
|