You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.9 KiB
C#

1 year ago
using ICSharpCode.Core;
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.UserManage
{
class ModifyUserAction : ChemicalWeighingAction, IAction
{
#region 字段定义
private RuntimeParameter _runtime;
private DbMCControl _clientGridControl = null; //用户列表控件
#endregion
#region 事件定义
/// <summary>
/// 修改用户信息事件定义
/// </summary>
public static event EventHandler OnModifyUser;
#endregion
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用
this._runtime = runtime;
#region 获取界面控件
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pst_user").FirstOrDefault();
if (clientGridControl == null)
{
ICSharpCode.Core.LoggingService<ModifyUserAction>.Error("缺少用户信息列表控件...");
return;
}
this._runtime = runtime;
this._clientGridControl = clientGridControl;
DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView;
#endregion
//验证是否选中某用户
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;
}
//封装选中行对应的用户对象
SimplePstUser user = new SimplePstUser
{
UID = Convert.ToInt32(clientGridView.SelectedRows[0].Cells["UID"].Value), //获取选中的用户ID
UName = clientGridView.SelectedRows[0].Cells["UName"].Value as string,
UPwd = clientGridView.SelectedRows[0].Cells["UPwd"].Value as string,
URoleName = clientGridView.SelectedRows[0].Cells["RoleName"].Value as string,
URoleID = Convert.ToInt32(clientGridView.SelectedRows[0].Cells["URoleID"].Value)
};
#region 执行修改用户信息
FrmUser frmUser = new FrmUser(ActionType.Modify, user);
DialogResult result = frmUser.ShowDialog();
if (result == DialogResult.OK)
{
SimplePstUser newUser = frmUser.User;
newUser.UID = user.UID; //点击确认按钮后返回的user对象中未定义UID因此要在此设定
frmUser.Dispose();
string msg2 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_UserManage_ModifyUserAction_msg2")); //确认修改{0}用户信息?
msg2 = String.Format(msg2, newUser.UName);
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
}
}
else
{
frmUser.Dispose();
}
#endregion
}
}
}