using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using ICSharpCode.Core; using Mesnac.Action.Base; using Mesnac.Controls.Base; namespace Mesnac.Action.Default.Test { public class InitFormAction : DatabaseAction, IAction { private string caption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_Caption")); //提示 public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须调用 ICSharpCode.Core.LoggingService.Debug("用户信息-窗体初始化..."); DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "BasUser").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); //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); } } } } }