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.

106 lines
3.6 KiB
C#

1 year ago
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;
using System.Web.UI.WebControls;
namespace Mesnac.Action.Default.Purview.BasUser
{
/// <summary>
/// 用户信息窗体初始化
/// </summary>
public class InitFormAction : DatabaseAction, IAction
{
private DbMCControl _roleType = null; //用户类型
private RuntimeParameter _runtime;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
this._runtime = runtime;
ICSharpCode.Core.LoggingService<InitFormAction>.Debug("用户信息-窗体初始化...");
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "BasUser").FirstOrDefault();
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<InitFormAction>.Warn("{用户信息-窗体初始化} 缺少datagridview控件...");
runtime.IsReturn = false;
return;
}
else
{
DataGridView clientGrid = (clientGridControl.BaseControl as DataGridView);
if (clientGrid != null)
{
clientGrid.DataSourceChanged += RefreshBackColor;
clientGrid.VisibleChanged += RefreshBackColor;
ModifyAction.OnModifyUser -= Process_Event;
ModifyAction.OnModifyUser += Process_Event;
SetBackColor(clientGrid, "DeleteFlag", "1", System.Drawing.Color.Gray);
clientGridControl.BaseControl.BindDataSource = null;
clientGridControl.BaseControl.BindDataSource = UserHelper.GetUserListForSelect();
}
}
}
private void RefreshBackColor(object sender, EventArgs e)
{
DataGridView clientGrid = sender as DataGridView;
SetBackColor(clientGrid, "DeleteFlag", "1", System.Drawing.Color.Gray);
}
public static void SetBackColor(DataGridView grid, string columnName, object filterValue, System.Drawing.Color c)
{
lock (String.Empty)
{
try
{
if (grid == null)
{
ICSharpCode.Core.LoggingService<InitFormAction>.Warn("设置GridViewRow背景色失败网格控件为null");
return;
}
foreach (DataGridViewRow row in grid.Rows)
{
if (filterValue.Equals(row.Cells[columnName].Value))
{
row.DefaultCellStyle.BackColor = c;
}
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<InitFormAction>.Error("设置GridViewRow背景色失败" + ex.Message);
}
}
}
#region 事件处理方法
private void Process_Event(object sender, EventArgs e)
{
if (sender is RuntimeParameter)
{
this.Run(sender as RuntimeParameter);
}
else
{
this.Run(this._runtime);
}
}
#endregion
}
}