using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mesnac.Action.Base;
using System.Windows.Forms;
using System.Data;
using Mesnac.Codd.Session;
namespace Mesnac.Action.ChemicalWeighing.UserManage
{
public class initUserFormAction : ChemicalWeighingAction, IAction
{
#region 事件定义
///
/// 刷新用户信息事件
///
public static event EventHandler OnRefreshUser;
#endregion
private RuntimeParameter _runtime;
private DbMCControl _userName = null; //用户名
private DbMCControl _userPwd = null; //密码
private DbMCControl _userType = null; //用户类型
private DbMCControl _clientGridControl = null; //用户列表控件
#region IAction接口实现
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
this._runtime = runtime;
#region 事件订阅
if (true)
{
//新增用户后,要刷新用户页面
insertUserAction.OnInsertUser -= Process_Event;
insertUserAction.OnInsertUser += Process_Event;
//删除用户后,触发刷新页面事件
DeleteUserAction.OnDeleteUser -= Process_Event;
DeleteUserAction.OnDeleteUser += Process_Event;
//修改用户信息后,触发刷新页面事件
ModifyUserAction.OnModifyUser -= Process_Event;
ModifyUserAction.OnModifyUser += Process_Event;
}
#endregion
DbMCControl userName = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[Pst_user].[UName]").FirstOrDefault(); //获取用户名textbox控件
DbMCControl userPwd = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[Pst_user].[UPwd]").FirstOrDefault(); ////获取密码textbox控件
DbMCControl userType = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[Pst_user].[URoleID]").FirstOrDefault(); //获取用户类型combobox控件
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pst_user").FirstOrDefault(); //获取用户数据控件
this._userName = userName;
this._userPwd = userPwd;
this._userType = userType;
this._clientGridControl = clientGridControl;
//调用刷新用户信息的操作
this.requestUserInfo();
}
#endregion
///
/// 刷新用户信息
///
protected void requestUserInfo()
{
//获取用户信息表
DataTable userTable = UserHelper.getUsers();
lock (String.Empty)
{
if (this._clientGridControl != null && this._clientGridControl.BaseControl != null)
{
this._clientGridControl.BaseControl.BindDataSource = null;
this._clientGridControl.BaseControl.BindDataSource = userTable;
}
else
{
ICSharpCode.Core.LoggingService.Warn("刷新用户信息失败:数据控件为Null...");
}
}
#region 触发事件, 刷新用户信息
if (OnRefreshUser != null)
{
OnRefreshUser(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
}
#endregion
}
#region 事件处理方法
private void Process_Event(object sender, EventArgs e)
{
if (sender is RuntimeParameter)
{
this.Run(sender as RuntimeParameter);
}
else
{
this.Run(this._runtime);
}
}
#endregion
}
}