using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace Shared.Phone.UserCenter.HdlBackup
|
{
|
/// <summary>
|
/// 备份列表界面
|
/// </summary>
|
public class HdlBackupListForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalListControl listView = null;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
public void ShowForm()
|
{
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDataBackup));
|
|
//右上添加按钮
|
var btnTopIcon = new MostRightIconControl(69, 69);
|
btnTopIcon.UnSelectedImagePath = "Item/Add.png";
|
topFrameLayout.AddChidren(btnTopIcon);
|
btnTopIcon.InitControl();
|
btnTopIcon.ButtonClickEvent += (sender, e) =>
|
{
|
//显示添加备考名画面
|
this.ShowAddBackupForm();
|
};
|
|
//初始化中部控件
|
this.InitMiddleFrame();
|
}
|
|
/// <summary>
|
/// 初始化中部控件
|
/// </summary>
|
private void InitMiddleFrame()
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
listView = new VerticalListControl(29);
|
listView.BackgroundColor = UserCenterColor.Current.White;
|
listView.Height = bodyFrameLayout.Height;
|
bodyFrameLayout.AddChidren(listView);
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//从云端获取数据
|
this.SetBackupInfoToForm();
|
});
|
}
|
|
#endregion
|
|
#region ■ 从云端获取数据_____________________
|
|
/// <summary>
|
/// 从云端获取数据
|
/// </summary>
|
private void SetBackupInfoToForm()
|
{
|
//进度条
|
this.ShowProgressBar();
|
|
//获取app的自动备份
|
var autoData = HdlBackupLogic.Current.GetBackupListNameFromDB(BackUpMode.A自动备份);
|
if (autoData == null)
|
{
|
//关闭进度条
|
this.CloseProgressBar(ShowReLoadMode.YES);
|
return;
|
}
|
//从云端获取数据
|
var pageData = HdlBackupLogic.Current.GetBackupListNameFromDB(BackUpMode.A手动备份);
|
if (pageData == null)
|
{
|
//关闭进度条
|
this.CloseProgressBar(ShowReLoadMode.YES);
|
return;
|
}
|
//关闭
|
this.CloseProgressBar();
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
if (this.Parent == null)
|
{
|
return;
|
|
}
|
listView.RemoveAll();
|
listView.RecoverHeight();
|
//添加自动备份行
|
if (autoData.Count == 0)
|
{
|
this.AddNotAutoBackupRow(pageData.Count > 0);
|
}
|
else
|
{
|
this.AddRowlayout(autoData[0], pageData.Count > 0, true);
|
}
|
|
//排序
|
var dic = new Dictionary<string, BackupListNameInfo>();
|
var listSort = new List<string>();
|
for (int i = 0; i < pageData.Count; i++)
|
{
|
listSort.Add(pageData[i].ModifyTime);
|
dic[pageData[i].ModifyTime] = pageData[i];
|
}
|
listSort.Sort();
|
|
for (int i = listSort.Count - 1; i >= 0; i--)
|
{
|
//添加备份行
|
this.AddRowlayout(dic[listSort[i]], i != 0, false);
|
}
|
listView.AdjustRealHeight(Application.GetRealHeight(23));
|
});
|
}
|
|
#endregion
|
|
#region ■ 添加备份行_________________________
|
|
/// <summary>
|
/// 添加备份行
|
/// </summary>
|
/// <param name="fileInfo"></param>
|
private void AddRowlayout(BackupListNameInfo fileInfo, bool addLine, bool autoBack)
|
{
|
//行
|
var rowLayout = new RowLayoutControl(listView.rowSpace / 2);
|
listView.AddChidren(rowLayout);
|
if (autoBack == true)
|
{
|
rowLayout.frameTable.UseClickStatu = false;
|
}
|
|
//图标
|
var btnPoint = rowLayout.frameTable.AddLeftIcon();
|
btnPoint.UnSelectedImagePath = "Item/DownLoad.png";
|
|
//备份名字
|
var txtText = rowLayout.frameTable.AddTopView("", 700);
|
if (autoBack == true)
|
{
|
//自动备份
|
txtText.Text = Language.StringByID(R.MyInternationalizationString.uAutoBackup);
|
}
|
else
|
{
|
txtText.Text = fileInfo.FolderName;
|
}
|
//时间
|
var btnTime = rowLayout.frameTable.AddBottomView("", 600);
|
if (fileInfo.ModifyTime.Length >= 13)
|
{
|
btnTime.Text = HdlCommonLogic.Current.ConvertUtcTimeToLocalTime2(fileInfo.ModifyTime).ToString("yyyy.MM.dd HH:mm:ss");
|
}
|
if (addLine == true)
|
{
|
//底线
|
rowLayout.frameTable.AddBottomLine();
|
}
|
|
//立即下载
|
var btnLoad = new NormalViewControl(Application.GetRealWidth(200), rowLayout.frameTable.Height, false);
|
btnLoad.X = rowLayout.frameTable.Width - Application.GetRealWidth(200 + 127);
|
btnLoad.TextID = R.MyInternationalizationString.uDownLoadNow;
|
btnLoad.TextAlignment = TextAlignment.CenterRight;
|
btnLoad.TextSize = 12;
|
btnLoad.TextColor = UserCenterColor.Current.TextOrangeColor;
|
rowLayout.frameTable.AddChidren(btnLoad, ChidrenBindMode.NotBind);
|
btnLoad.ButtonClickEvent += (sender, e) =>
|
{
|
//是否要下载并恢复数据?
|
string msg = Language.StringByID(R.MyInternationalizationString.uDownLoadAndRecoverMsg);
|
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
{
|
//读取备份文档
|
this.LoadBackupInfo(fileInfo.Id);
|
});
|
};
|
|
if (autoBack == true)
|
{
|
//上传
|
var btnUpLoad = rowLayout.AddEditorControl();
|
btnUpLoad.TextID = R.MyInternationalizationString.uUpload;
|
btnUpLoad.ButtonClickEvent += (sender, e) =>
|
{
|
//确认是否上传数据到服务器?
|
this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uSynchronizeDataToServiceMsg), () =>
|
{
|
//上传自动备份数据
|
this.UpLoadAutoBackupInfo();
|
});
|
};
|
}
|
else
|
{
|
//编辑备注名
|
rowLayout.frameTable.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, ShowErrorMode.YES);
|
});
|
};
|
}
|
}
|
|
/// <summary>
|
/// 添加没有自动备份数据的行
|
/// </summary>
|
/// <param name="addLine"></param>
|
private void AddNotAutoBackupRow(bool addLine)
|
{
|
//行
|
var rowLayout = new RowLayoutControl(listView.rowSpace / 2);
|
listView.AddChidren(rowLayout);
|
rowLayout.frameTable.UseClickStatu = false;
|
|
//图标
|
var btnPoint = rowLayout.frameTable.AddLeftIcon();
|
btnPoint.UnSelectedImagePath = "Item/DownLoad.png";
|
|
//备份名字
|
var txtText = rowLayout.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAutoBackup), 700);
|
txtText.TextSize = 15;
|
|
if (addLine == true)
|
{
|
//底线
|
rowLayout.frameTable.AddBottomLine();
|
}
|
//上传
|
var btnUpLoad = rowLayout.AddEditorControl();
|
btnUpLoad.TextID = R.MyInternationalizationString.uUpload;
|
btnUpLoad.ButtonClickEvent += (sender, e) =>
|
{
|
//确认是否上传数据到服务器?
|
this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uSynchronizeDataToServiceMsg), () =>
|
{
|
//上传自动备份数据
|
this.UpLoadAutoBackupInfo();
|
});
|
};
|
}
|
|
#endregion
|
|
#region ■ 读取备份文档_______________________
|
|
/// <summary>
|
/// 读取备份文档
|
/// </summary>
|
/// <param name="BackupClassId"></param>
|
private void LoadBackupInfo(string BackupClassId)
|
{
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//从云端获取备份的文件
|
bool result = HdlBackupLogic.Current.LoadAppBackupInfo(BackupClassId);
|
if (result == false)
|
{
|
//文件恢复失败
|
string msg2 = Language.StringByID(R.MyInternationalizationString.uFileRecoverFail);
|
this.ShowMassage(ShowMsgType.Error, msg2);
|
return;
|
}
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//关闭所有界面
|
HdlFormLogic.Current.CloseAllOpenForm(null, false);
|
//切换到主页
|
UserView.UserPage.Instance.ReFreshControl();
|
});
|
|
//文件恢复成功
|
string msg = Language.StringByID(R.MyInternationalizationString.uFileRecoverSuccess);
|
this.ShowMassage(ShowMsgType.Normal, msg);
|
});
|
}
|
|
#endregion
|
|
#region ■ 上传手动备份数据___________________
|
|
/// <summary>
|
/// 上传数据
|
/// </summary>
|
/// <param name="backName"></param>
|
private void UpLoadBackInfo(string backName)
|
{
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//绑定还没有成功的网关
|
var result2 = HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
|
if (result2 == false)
|
{
|
//绑定网关失败,请重新上传
|
this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uBindGatewayFailPleaseUploadAgain));
|
return;
|
}
|
//创建一个备份名字
|
string backupClassId = HdlBackupLogic.Current.CreatNewBackupNameToDB(backName, BackUpMode.A手动备份);
|
if (backupClassId == null)
|
{
|
//创建备份名字失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uCreatBackupNameFail);
|
this.ShowMassage(ShowMsgType.Error, msg);
|
|
return;
|
}
|
|
//上传数据到云端
|
bool result = HdlBackupLogic.Current.UpLoadBackupFileToDB(backupClassId);
|
if (result == false)
|
{
|
//文件上传失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uFileUpLoadFail);
|
this.ShowMassage(ShowMsgType.Error, msg);
|
|
//如果上传失败的话,就把它删除
|
this.DeleteBackInfo(backupClassId, ShowErrorMode.NO);
|
|
return;
|
}
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//从云端获取数据
|
this.SetBackupInfoToForm();
|
});
|
});
|
}
|
|
#endregion
|
|
#region ■ 上传自动备份数据___________________
|
|
/// <summary>
|
/// 上传自动备份数据
|
/// </summary>
|
private void UpLoadAutoBackupInfo()
|
{
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//绑定还没有成功的网关
|
var result2 = HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
|
if (result2 == false)
|
{
|
//绑定网关失败,请重新上传
|
this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uBindGatewayFailPleaseUploadAgain));
|
return;
|
}
|
int result = HdlBackupLogic.Current.DoUpLoadAutoBackupDataByHand();
|
if (result == -1)
|
{
|
//文件上传失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uFileUpLoadFail);
|
this.ShowMassage(ShowMsgType.Error, msg);
|
|
return;
|
}
|
//数据成功同步到服务器
|
string msg2 = Language.StringByID(R.MyInternationalizationString.uSynchronizeDataToServiceSuccessMsg);
|
this.ShowMassage(ShowMsgType.Normal, msg2);
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//从云端获取数据
|
this.SetBackupInfoToForm();
|
});
|
});
|
}
|
#endregion
|
|
#region ■ 编辑备份名称_______________________
|
|
/// <summary>
|
/// 编辑备份名称
|
/// </summary>
|
/// <param name="BackupClassId"></param>
|
/// <param name="backName"></param>
|
private void EditorBackInfo(string BackupClassId, string backName)
|
{
|
//开启进度条
|
this.ShowProgressBar();
|
|
bool result = HdlBackupLogic.Current.EditorBackupName(BackupClassId, backName);
|
this.CloseProgressBar();
|
|
if (result == true)
|
{
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//从云端获取数据
|
this.SetBackupInfoToForm();
|
});
|
}
|
}
|
|
#endregion
|
|
#region ■ 删除备份文档_______________________
|
|
/// <summary>
|
/// 删除备份文档
|
/// </summary>
|
/// <param name="BackupClassId"></param>
|
/// <param name="showMode"></param>
|
public void DeleteBackInfo(string BackupClassId, ShowErrorMode showMode = ShowErrorMode.YES)
|
{
|
bool success = HdlBackupLogic.Current.DeleteDbBackupData(BackupClassId);
|
if (success == false)
|
{
|
if (showMode == ShowErrorMode.YES)
|
{
|
//删除备份失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBackupFail);
|
this.ShowMassage(ShowMsgType.Error, msg);
|
}
|
return;
|
}
|
|
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.FolderName;
|
|
//按下确认按钮
|
dialogForm.ComfirmClickEvent += ((textValue) =>
|
{
|
//检测备考名称
|
if (this.CheckBackupName(textValue) == false)
|
{
|
return;
|
}
|
|
//画面关闭
|
dialogForm.CloseDialog();
|
|
//名字一样时,不处理
|
if (textValue != fileInfo.FolderName)
|
{
|
//编辑备份名称
|
this.EditorBackInfo(fileInfo.Id, textValue);
|
}
|
});
|
}
|
|
/// <summary>
|
/// 显示添加备考名画面
|
/// </summary>
|
/// <returns></returns>
|
private void ShowAddBackupForm()
|
{
|
//生成一个弹窗画面
|
var dialogForm = new DialogInputControl();
|
//添加备份
|
dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddBackup));
|
//请输入备份名称
|
dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInpuBackupName));
|
|
//按下确认按钮
|
dialogForm.ComfirmClickEvent += ((textValue) =>
|
{
|
//检测备考名称
|
if (this.CheckBackupName(textValue) == false)
|
{
|
return;
|
}
|
|
//画面关闭
|
dialogForm.CloseDialog();
|
|
//上传备份
|
this.UpLoadBackInfo(textValue);
|
});
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 检测备考名称
|
/// </summary>
|
/// <param name="backName"></param>
|
/// <returns></returns>
|
private bool CheckBackupName(string backName)
|
{
|
if (backName == string.Empty)
|
{
|
//请输入备份名称
|
string msg = Language.StringByID(R.MyInternationalizationString.uPleaseInpuBackupName);
|
this.ShowMassage(ShowMsgType.Error, msg);
|
return false;
|
}
|
if (backName.Contains("##") == true)
|
{
|
//存在非法字符「##」
|
string msg = Language.StringByID(R.MyInternationalizationString.uErrorFieldIsEsixt);
|
if (msg.Contains("{0}") == true)
|
{
|
msg = string.Format(msg, "##");
|
}
|
this.ShowMassage(ShowMsgType.Error, msg);
|
return false;
|
}
|
|
return true;
|
}
|
#endregion
|
}
|
}
|