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
{
///
/// 用户信息窗体初始化
///
public class InitFormAction : DatabaseAction, IAction
{
private DbMCControl _roleType = null; //用户类型
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
ICSharpCode.Core.LoggingService.Debug("用户信息-窗体初始化...");
//DbMCControl roleType = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[Pst_user].[RoleGUID]").FirstOrDefault(); //获取用户类型combobox控件
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "BasUser").FirstOrDefault();
//_roleType = roleType;
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService.Warn("{用户信息-窗体初始化} 缺少datagridview控件...");
runtime.IsReturn = false;
return;
}
else
{
DataGridView clientGrid = (clientGridControl.BaseControl as DataGridView);
if (clientGrid != null)
{
clientGrid.DataSourceChanged += RefreshBackColor;
clientGrid.VisibleChanged += RefreshBackColor;
SetBackColor(clientGrid, "DeleteFlag", "1", System.Drawing.Color.Gray);
//clientGrid.DataSource = 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.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.Error("设置GridViewRow背景色失败:" + ex.Message);
}
}
}
}
}