using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using ICSharpCode.Core;
using Mesnac.Controls.Base;
using Mesnac.Action.Base;
using Mesnac.Codd.Session;
using Mesnac.Action.Default.Entity;
namespace Mesnac.Action.Default.Purview.BasUser
{
///
/// 生产管理-修改计划数业务
///
public class ModifyAction : DatabaseAction, IAction
{
#region 字段定义
private RuntimeParameter _runtime;
private DbMCControl _clientGridControl = null; //网格计划控件
public static event EventHandler OnModifyUser;
#endregion
#region 事件定义
///
/// 修改计划数事件定义
///
public static event EventHandler OnModifyPlanNum;
#endregion
#region 业务入口
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
this._runtime = runtime;
ICSharpCode.Core.LoggingService.Debug("用户管理-修改用户信息...");
try
{
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "BasUser").FirstOrDefault();
if (clientGridControl == null)
{
ICSharpCode.Core.LoggingService.Error("缺少用户信息列表控件...");
return;
}
this._runtime = runtime;
this._clientGridControl = clientGridControl;
DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView;
if (clientGridView.SelectedRows.Count != 1)
{
string msg1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_UserManage_ModifyUserAction_msg1")); //请选择一项要修改的用户!
MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
this._runtime.IsReturn = true;
return;
}
BasUserModel user = new BasUserModel
{
UID = clientGridView.SelectedRows[0].Cells["GUID"].Value as string, //获取选中的用户ID
UserName = clientGridView.SelectedRows[0].Cells["UserName"].Value as string,
UserPWD = clientGridView.SelectedRows[0].Cells["UserPWD"].Value as string,
RoleGUID = clientGridView.SelectedRows[0].Cells["RoleGUID"].Value as string,
RealName = clientGridView.SelectedRows[0].Cells["RealName"].Value as string,
RoleName = clientGridView.SelectedRows[0].Cells["RoleName"].Value as string,
};
frmInsert frmInsert = new frmInsert(ActionType.Modify,user);
DialogResult result = frmInsert.ShowDialog();
if (result == DialogResult.OK)
{
BasUserModel newUser = user;
newUser.UID = user.UID; //点击确认按钮后返回的user对象中未定义UID,因此要在此设定
newUser.UserName= frmInsert.UserName;
newUser.RealName = frmInsert.RealName;
newUser.RoleGUID = frmInsert.RoleGUID;
newUser.RoleName = frmInsert.RoleName;
frmInsert.Dispose();
string msg2 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_UserManage_ModifyUserAction_msg2")); //确认修改{0}用户信息?
msg2 = String.Format(msg2, newUser.UserName);
if (MessageBox.Show(msg2, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
//更新数据库中的用户信息
UserHelper.UpdateUser(newUser);
#region 触发刷新用户列表事件
if (OnModifyUser != null)
{
OnModifyUser(runtime, System.EventArgs.Empty);
}
#endregion
}
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("修改计划数失败:" + ex.Message, ex);
MessageBox.Show(ex.Message, Mesnac.Basic.LanguageHelper.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
#endregion
}
}