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.

105 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using Mesnac.Action.Base;
using Mesnac.Codd.Session;
namespace Mesnac.Action.Default.Purview.BasUser
{
/// <summary>
/// 添加用户业务
/// </summary>
public class InsertAction : DefaultAction, IAction
{
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
ICSharpCode.Core.LoggingService<InsertAction>.Debug("用户信息-添加...");
frmInsert frmInsert = new frmInsert();
DialogResult result = frmInsert.ShowDialog();
if (result == DialogResult.OK)
{
string guid = Guid.NewGuid().ToString().ToUpper();
int seqIndex = this.GetNextSeqIndex();
string userName = frmInsert.UserName;
string userPWD = frmInsert.UserPWD;
string roleGUID = frmInsert.RoleGUID;
//int classID = frmInsert.ClassID;
string realName = frmInsert.RealName;
string strSql = @"insert into BasUser(GUID, SeqIndex, UserName, UserPWD, RealName, RoleGUID, DeleteFlag)
values(@GUID, @SeqIndex, @UserName, @UserPWD, @RealName, @RoleGUID, @DeleteFlag)";
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
dbHelper.ClearParameter();
dbHelper.CommandType = System.Data.CommandType.Text;
dbHelper.CommandText = strSql;
dbHelper.AddParameter("@GUID", guid);
dbHelper.AddParameter("@SeqIndex", seqIndex);
dbHelper.AddParameter("@UserName", userName);
dbHelper.AddParameter("@UserPWD", userPWD);
dbHelper.AddParameter("@RealName", realName);
dbHelper.AddParameter("@RoleGUID", roleGUID);
//dbHelper.AddParameter("@ClassID", classID);
dbHelper.AddParameter("@DeleteFlag", "0");
dbHelper.ExecuteNonQuery();
//刷新DataGridView数据
DbMCControl dgBasUser = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "BasUser").FirstOrDefault();
if (dgBasUser == null || !(dgBasUser.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<InsertAction>.Warn("{用户信息-添加} 缺少用户DataGridView控件...");
runtime.IsReturn = false;
return;
}
DataTable table = dbHelper.GetDataTableBySql(dgBasUser.BaseControl.ActionDataSource);
dgBasUser.BaseControl.BindDataSource = table;
#region 记录操作日志
string logContent = String.Format("SeqIndex={0}, UserName={1}, RealName={2}", seqIndex, userName, realName);
base.DBLog(logContent);
#endregion
}
}
/// <summary>
/// 获取下一个可用的用户序号
/// </summary>
/// <returns>返回可用的用户序号</returns>
public int GetNextSeqIndex()
{
string strSql = "select MAX(SeqIndex) from BasUser";
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
dbHelper.ClearParameter();
dbHelper.CommandText = strSql;
dbHelper.CommandType = System.Data.CommandType.Text;
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
string SeqIndex = result.ToString();
int intSeqIndex = 1;
if (int.TryParse(SeqIndex, out intSeqIndex))
{
intSeqIndex++;
return intSeqIndex;
}
else
{
return 1;
}
}
else
{
return 1;
}
}
}
}