using Mesnac.Action.Base;
using Mesnac.Action.Default.Entity;
using Mesnac.Action.Default.Purview;
using Mesnac.Action.Default.Purview.BasRole;
using Mesnac.Codd.Session;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.Default.Test
{
///
/// 查询用户业务
///
public class SelectAction : DatabaseAction, IAction
{
DbMCControl roleType = null;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
ICSharpCode.Core.LoggingService.Debug("用户信息-查询...");
FrmInsert frmInsert = new FrmInsert(ActionType.Query);
DialogResult result = frmInsert.ShowDialog();
if (result == DialogResult.OK)
{
//roleType = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[BasUser].[RoleGUID]").FirstOrDefault(); //获取用户类型combobox控件
//roleType.BaseControl.BindDataSource = GetUserListForSelect();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
dbHelper.ClearParameter();
StringBuilder sbSql = new StringBuilder("SELECT TA.*,TB.RoleName,TD.ItemName FROM BasUser TA LEFT JOIN BasRole TB ON TA.RoleGUID=TB.GUID LEFT JOIN SysCode TD ON TA.DeleteFlag=TD.ItemCode AND TD.TypeID='YesNo' WHERE 1=1 ");
if (!String.IsNullOrEmpty(frmInsert.UserName))
{
sbSql.Append(" and TA.UserName like @UserName");
dbHelper.AddParameter("@UserName", "%" + frmInsert.UserName + "%");
}
if (!String.IsNullOrEmpty(frmInsert.RoleGUID))
{
sbSql.Append(" and TA.RoleGUID = @RoleGUID");
dbHelper.AddParameter("@RoleGUID", frmInsert.RoleGUID);
}
//if (frmInsert.ClassID != 0)
//{
// sbSql.Append(" and TA.ClassID = @ClassID");
// dbHelper.AddParameter("@ClassID", frmInsert.ClassID);
//}
if (!String.IsNullOrEmpty(frmInsert.RealName))
{
sbSql.Append(" and TA.RealName like @RealName");
dbHelper.AddParameter("@RealName", "%" + frmInsert.RealName + "%");
}
sbSql.Append(" ORDER BY CAST(TA.SeqIndex AS INT)");
dbHelper.CommandText = sbSql.ToString();
dbHelper.CommandType = System.Data.CommandType.Text;
DataTable table = dbHelper.ToDataTable();
//刷新DataGridView数据
DbMCControl dgBasUser = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "BasUser").FirstOrDefault();
if (dgBasUser == null || !(dgBasUser.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService.Warn("{用户信息-查询} 缺少用户DataGridView控件...");
runtime.IsReturn = false;
return;
}
dgBasUser.BaseControl.BindDataSource = table;
}
}
public static DataTable GetUserListForSelect()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
StringBuilder sbSql = new StringBuilder("SELECT GUID,RoleName FROM BasRole WHERE DeleteFlag='0' ");
sbSql.Append(" ORDER BY SeqIndex ");
dbHelper.CommandText = sbSql.ToString();
dbHelper.CommandType = System.Data.CommandType.Text;
DataTable table = dbHelper.ToDataTable();
return table;
}
}
}