using Shared;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace HDL_ON.Stan
{
///
/// 界面最基层的底层共通
///
public class CommonFormBase : FrameLayout
{
#region ■ 变量声明___________________________
///
/// 画面的ID(自动编号,唯一主键,和各页面并无任何逻辑关系,但是它的用处大着呢)
///
public string FormID = string.Empty;
#endregion
#region ■ 初始化_____________________________
///
/// 初始化界面框架
///
public virtual void InitForm()
{
//将当前的画面保存到内存当中
HdlFormLogic.Current.AddActionForm(this);
}
///
/// 执行ShowForm()方法
///
/// 启动参数
public virtual void LoadShowFormMethod(params object[] parameter)
{
this.LoadFormMethodByName(this, "ShowForm", parameter);
}
#endregion
#region ■ 添加界面___________________________
///
/// 添加画面,启动参数由指定画面的ShowForm函数所指定
///
/// 启动参数:参数由指定画面的ShowForm函数所指定
public virtual void AddForm(params object[] parameter)
{
return;
}
///
/// 添加指定画面,并移除当前画面,启动参数由指定画面的ShowForm函数所指定
///
/// 目标界面
/// 启动参数:参数由指定画面的ShowForm函数所指定
public void AddFormAndCloseNowForm(CommonFormBase form, params object[] parameter)
{
//移除当前画面
this.CloseForm();
//添加画面
form.AddForm(parameter);
}
#endregion
#region ■ 关闭界面___________________________
///
/// 画面关闭之前(底层变更,不能重载CloseForm方法了)
///
public virtual void CloseFormBefore()
{
}
///
/// 画面关闭之后(新增)
///
public virtual void CloseFormAfter()
{
}
///
/// 画面关闭
///
public void CloseForm()
{
try
{
//关闭进度条
this.CloseProgressBar();
//画面关闭之前
this.CloseFormBefore();
//调用的是Base的移除控件函数
//而不是调用this的移除控件函
base.RemoveFromParent();
//从列表中移除(防止画面二重添加)
HdlFormLogic.Current.RemoveActionForm(this);
//画面关闭之后
this.CloseFormAfter();
}
catch (Exception ex)
{
//出现未知错误
HdlMessageLogic.Current.ShowAppProgramIsError(ex);
}
}
///
/// 画面关闭(在画面里面,请不要调用此方法,请使用CloseForm()方法)
///
public override void RemoveFromParent()
{
//画面右滑时,关闭画面,调用自定义的CloseForm()方法
this.CloseForm();
}
#endregion
#region ■ 圆形进度条_________________________
///
/// 进度条启动
///
/// 初始文本
public void ShowProgressBar(string text = "")
{
if (this.FormID != HdlFormLogic.Current.NowActionFormID)
{
return;
}
ProgressBar.Show(text);
}
///
/// 设置进度条的信息值(会自动计算百分比,值累加模式)
///
/// 值
public void SetProgressValue(decimal value)
{
ProgressBar.SetValue(value);
}
///
/// 设置进度条的信息值
///
/// 值
public void SetProgressValue(string value)
{
ProgressBar.SetValue(value);
}
///
/// 设置进度条的信息值
///
/// 值
public void SetProgressMax(decimal value)
{
if (value == 0)
{
value = 100;
}
ProgressBar.SetMaxValue(value);
}
///
/// 关闭进度条
///
/// 是否显示重新加载的界面
public void CloseProgressBar(ShowReLoadMode mode = ShowReLoadMode.NO)
{
ProgressBar.Close();
if (mode == ShowReLoadMode.YES)
{
//显示重新加载的界面(主要是用在界面加载错误时,再次加载)
this.ShowReLoadView();
}
}
///
/// 显示重新加载的界面(主要是用在界面加载错误时,再次加载)
///
public virtual void ShowReLoadView()
{
}
#endregion
#region ■ 一般的方法_________________________
///
/// 显示信息框
///
/// 信息类型
/// 信息
/// 单击确认后执行的回调函数
/// 按钮的文本
/// 等待时间,单位为秒,设置确认按钮在多长时间后才能够点击
public void ShowMassage(ShowMsgType msgType, string msg, Action action = null, string buttonText = null, int i_waitTime = -1)
{
HdlMessageLogic.Current.ShowMassage(msgType, msg, action, buttonText, i_waitTime);
}
///
/// 判断当前正在活动的界面是否是当前这个界面
///
///
public bool NowFormIsAction()
{
return HdlFormLogic.Current.NowActionFormID == this.FormID;
}
///
/// 计算图片的真实高宽度
///
///
///
public int GetPictrueRealSize(int i_size)
{
return Application.GetRealWidth(i_size);
}
#endregion
#region ■ 反射方法___________________________
///
/// 执行指定画面的方法
///
/// 指定画面的英文名
/// 指定要加载的方法名
/// 启动参数
public object LoadFormMethodByName(string formName, string method, params object[] parameter)
{
var form = HdlFormLogic.Current.GetFormByName(formName);
if (form == null)
{
return null;
}
return this.LoadFormMethodByName(form, method, parameter);
}
///
/// 执行指定画面的方法(注意:这个是专门调用异步,并且等待异步完成的高科技函数,不调用异步的情况,别使用此函数)
///
/// 指定画面的英文名
/// 指定要加载的方法名
/// 启动参数
public async Task