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 async void SetBackupInfoToForm()
|
{
|
//进度条
|
this.ShowProgressBar();
|
|
//从云端获取数据
|
var pageData = await HdlBackupLogic.Current.GetBackupListNameFromDB(2, HdlGatewayLogic.Current.GetGatewayId(realGateway));
|
if (pageData == null)
|
{
|
//关闭进度条
|
this.CloseProgressBar(ShowReLoadMode.YES);
|
return;
|
}
|
//关闭进度条
|
this.CloseProgressBar();
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
listView.RemoveAll();
|
listView.RecoverHeight();
|
for (int i = 0; i < pageData.Count; i++)
|
{
|
//添加备份行
|
this.AddRowlayout(pageData[i], i != pageData.Count - 1);
|
}
|
|
this.btnDownload?.RemoveFromParent();
|
if (pageData.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, () =>
|
{
|
this.LoadBackupInfo(this.nowSelectBackId);
|
});
|
};
|
//调整真实高度
|
listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
|
}
|
|
});
|
}
|
|
#endregion
|
|
#region ■ 添加备份行_________________________
|
|
/// <summary>
|
/// 添加备份行
|
/// </summary>
|
/// <param name="fileInfo"></param>
|
/// <param name="addLine"></param>
|
private void AddRowlayout(BackupListNameInfo fileInfo, bool addLine)
|
{
|
var rowLayout = new RowLayoutControl(listView.rowSpace / 2);
|
listView.AddChidren(rowLayout);
|
|
//备份名字
|
var txtText = rowLayout.frameTable.AddLeftCaption(fileInfo.BackupName, 700, 60);
|
txtText.TextSize = 15;
|
txtText.Y = Application.GetRealHeight(12) + rowLayout.chidrenYaxis;
|
rowLayout.frameTable.AddChidren(txtText, ChidrenBindMode.BindEventOnly);
|
//时间 2019-11-11T11:31:01
|
var btnTime = rowLayout.frameTable.AddLeftCaption("", 600, 50, true);
|
btnTime.Y = Application.GetRealHeight(72) + rowLayout.chidrenYaxis;
|
btnTime.TextSize = 12;
|
btnTime.TextColor = UserCenterColor.Current.TextGrayColor1;
|
rowLayout.frameTable.AddChidren(btnTime, ChidrenBindMode.BindEventOnly);
|
if (fileInfo.CreatedOnUtc.Length >= 19)
|
{
|
btnTime.Text = fileInfo.CreatedOnUtc.Replace("-", ".").Replace("T", " ");
|
}
|
//底线
|
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;
|
}
|
};
|
|
//编辑
|
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>
|
private void LoadBackupInfo(string BackupClassId)
|
{
|
HdlThreadLogic.Current.RunThread(async () =>
|
{
|
//获取网关上面存在的全部文件
|
var listFile = await this.GetGatewayFileFromGateway();
|
if (listFile == null)
|
{
|
return;
|
}
|
//从云端获取备份的文件
|
bool result = await HdlBackupLogic.Current.LoadGatewayBackupInfo(BackupClassId, realGateway, listFile);
|
if (result == false)
|
{
|
//网关恢复失败
|
string msg2 = Language.StringByID(R.MyInternationalizationString.uGatewayFileRecoverFail);
|
this.ShowMassage(ShowMsgType.Error, msg2);
|
return;
|
}
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//关闭自身
|
this.CloseForm();
|
});
|
|
//网关恢复成功
|
string msg = Language.StringByID(R.MyInternationalizationString.uGatewayFileRecoverSuccess);
|
this.ShowMassage(ShowMsgType.Normal, msg);
|
});
|
}
|
|
#endregion
|
|
#region ■ 编辑备份名称_______________________
|
|
/// <summary>
|
/// 编辑备份名称
|
/// </summary>
|
/// <param name="BackupClassId"></param>
|
/// <param name="backName"></param>
|
private async void EditorBackInfo(string BackupClassId, string backName)
|
{
|
var Pra = new EditorBackUpNamePra();
|
Pra.BackupClassId = BackupClassId;
|
Pra.BackupName = backName;
|
//获取控制主人账号的Token
|
Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
|
bool result = await UserCenterLogic.GetResultStatuByRequestHttps("App/UpdateHomeAppGatewayName", true, Pra);
|
if (result == false)
|
{
|
return;
|
}
|
|
this.SetBackupInfoToForm();
|
}
|
|
#endregion
|
|
#region ■ 删除备份文档_______________________
|
|
/// <summary>
|
/// 删除备份文档
|
/// </summary>
|
/// <param name="BackupClassId"></param>
|
private async void DeleteBackInfo(string BackupClassId)
|
{
|
bool success = await HdlBackupLogic.Current.DeleteDbBackupData(BackupClassId);
|
if (success == false)
|
{
|
return;
|
}
|
if (this.nowSelectBackId == BackupClassId)
|
{
|
this.nowSelectBackId = string.Empty;
|
this.nowbtnSelect = null;
|
}
|
this.SetBackupInfoToForm();
|
}
|
|
#endregion
|
|
#region ■ 显示编辑备考名画面_________________
|
|
/// <summary>
|
/// 显示编辑备考名画面
|
/// </summary>
|
/// <param name="fileInfo"></param>
|
/// <returns></returns>
|
private void ShowEditorBackupForm(BackupListNameInfo fileInfo)
|
{
|
//生成一个弹窗画面
|
var dialogForm = new DialogInputForm();
|
dialogForm.AddForm(DialogFrameMode.OnlyInput);
|
|
//编辑备份
|
dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorBackup));
|
//请输入备注名称
|
dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInpuBackup));
|
dialogForm.Text = fileInfo.BackupName;
|
|
//按下确认按钮
|
dialogForm.ComfirmClickEvent += ((txtvalue) =>
|
{
|
//画面关闭
|
dialogForm.CloseForm();
|
//名字一样时,不处理
|
if (txtvalue != fileInfo.BackupName)
|
{
|
//编辑备份名称
|
this.EditorBackInfo(fileInfo.Id, txtvalue);
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 获取网关文件_______________________
|
|
/// <summary>
|
/// 从网关获取它的文件
|
/// </summary>
|
/// <returns></returns>
|
private async System.Threading.Tasks.Task<List<string>> GetGatewayFileFromGateway()
|
{
|
var fileData = await realGateway.FileTransferLsDirAsync();
|
//检测网关返回的共通错误状态码
|
string error = HdlCheckLogic.Current.CheckCommonErrorCode(fileData);
|
if (error != null)
|
{
|
this.ShowMassage(ShowMsgType.Error, error);
|
return null;
|
}
|
|
if (fileData == null || fileData.fileTransferLsDiResponseData == null || fileData.fileTransferLsDiResponseData.Result != 0)
|
{
|
//获取网关文件失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayFileFail);
|
this.ShowMassage(ShowMsgType.Error, msg);
|
return null;
|
}
|
var listFile = new List<string>();
|
foreach (var filedata in fileData.fileTransferLsDiResponseData.Dir)
|
{
|
listFile.Add(filedata.File);
|
}
|
return listFile;
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
#endregion
|
}
|
}
|