using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Mesnac.Action.Base;
namespace Mesnac.Action.Default.Purview.BasRole
{
///
/// 角色信息窗体初始化
///
public class InitFormAction : DatabaseAction, IAction
{
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
ICSharpCode.Core.LoggingService.Debug("角色信息-窗体初始化...");
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "BasRole").FirstOrDefault();
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);
}
}
}
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);
}
}
}
}
}