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.
107 lines
4.0 KiB
C#
107 lines
4.0 KiB
C#
using ICSharpCode.Core;
|
|
using Mesnac.Action.Base;
|
|
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 DeleteUserAction : ChemicalWeighingAction, IAction
|
|
{
|
|
#region 事件定义
|
|
|
|
/// <summary>
|
|
/// 删除用户事件定义
|
|
/// </summary>
|
|
public static event EventHandler OnDeleteUser;
|
|
|
|
#endregion
|
|
|
|
#region 字段定义
|
|
|
|
private RuntimeParameter _runtime;
|
|
private DbMCControl _userNameControl = null; //用户名textbox控件
|
|
private DbMCControl _clientGridControl = null; //网格计划控件
|
|
#endregion
|
|
|
|
#region IAction接口实现
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
base.RunIni(runtime); //必须调用
|
|
this._runtime = runtime;
|
|
|
|
DbMCControl userName = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[Pst_user].[UName]").FirstOrDefault();
|
|
DbMCControl userDGV = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[Pst_user]").FirstOrDefault();
|
|
|
|
if (userName == null)
|
|
{
|
|
ICSharpCode.Core.LoggingService<DeleteUserAction>.Error("删除用户失败:未知用户");
|
|
return;
|
|
}
|
|
if (userDGV == null)
|
|
{
|
|
ICSharpCode.Core.LoggingService<DeleteUserAction>.Error("删除用户失败:未知列表项");
|
|
return;
|
|
}
|
|
this._userNameControl = userName;
|
|
this._clientGridControl = userDGV;
|
|
this.DoWork();
|
|
}
|
|
#endregion
|
|
|
|
#region 删除用户方法定义
|
|
/// <summary>
|
|
/// 根据用户名删除用户
|
|
/// </summary>
|
|
protected void DoWork()
|
|
{
|
|
this._runtime.BaseControl.MCEnabled = false;
|
|
//string str = _userNameControl.BaseControl.MCValue.ToString();
|
|
try
|
|
{
|
|
DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView;
|
|
if (clientGridView.SelectedRows.Count == 1)
|
|
{
|
|
string uName = clientGridView.SelectedRows[0].Cells["UName"].Value as string;
|
|
string msg1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_UserManage_DeleteUserAction_msg1")); //确认删除当前用户(用户名:{0})吗?
|
|
msg1 = String.Format(msg1, uName);
|
|
DialogResult result = MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
//删除本地数据库中的用户信息
|
|
UserHelper.deleteUser(uName);
|
|
|
|
#region 触发事件
|
|
|
|
if (OnDeleteUser != null)
|
|
{
|
|
OnDeleteUser(null, System.EventArgs.Empty);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string msg2 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_UserManage_DeleteUserAction_msg2")); //请选择一条要删除用户信息!
|
|
MessageBox.Show(msg2, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ICSharpCode.Core.LoggingService<DeleteUserAction>.Error("删除用户异常:" + ex.Message, ex);
|
|
MessageBox.Show(ex.Message, Mesnac.Basic.LanguageHelper.WarnCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
finally
|
|
{
|
|
this._runtime.BaseControl.MCEnabled = true;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|