GridControlClass公用方法

来源:互联网 发布:nero9刻录软件免费下载 编辑:程序博客网 时间:2024/05/22 02:42
using System;using System.Collections.Generic;using System.Linq;using System.Text;using ForeStar.CoreUI.Control;using ForeStar.CoreUI.Win.Control;using DevExpress.XtraGrid.Views.Grid;using System.Drawing;using ForeStar.Data.General;using ForeStar.CoreUI.Message;using ForeStar.GIS.SpatialDatabase;using MapZone.SpatialDatabase;namespace Forestar.GZ.YZL.Utils{    /// <summary>    /// 定义GridContrl控件通用方法类    /// </summary>    public class GridCommonMethod    {        public GridCommonMethod()        {        }        /// <summary>        /// 设置GridControl焦点行的背景颜色        /// </summary>        /// <param name="form"></param>        /// <param name="strGridControlName"></param>        public void SetFocusRowBackColor(IDataForm form, string strGridControlName)        {            if (form == null || string.IsNullOrEmpty(strGridControlName)) return;            GridControlClass gc = form.GetControl(strGridControlName) as GridControlClass;            if (gc == null) return;            GridView gv = gc.MainView as GridView;            if (gv == null) return;            gv.Appearance.FocusedRow.BackColor = Color.GreenYellow;        }        public static void SetFocusRow(IDataForm form, string strGridControlName)        {            if (form == null || string.IsNullOrEmpty(strGridControlName)) return;            GridControlClass gc = form.GetControl(strGridControlName) as GridControlClass;            if (gc == null || gc.DataSource == null) return;            //List<IRow> lstIRow = null;            //lstIRow = gc.DataSource as List<IRow>;            //if (lstIRow == null)            //{            //    List<RowBase> lstRows = gc.DataSource as List<RowBase>;            //    if (lstRows != null && lstRows.Count != 0)            //        lstIRow = lstRows.ToList<IRow>();            //}            //if (lstIRow == null) return;            GridView gv = gc.MainView as GridView;            if (gv == null) return;            if (gv.DataRowCount == 0) return;            gv.FocusedRowHandle = -1;            gv.FocusedRowHandle = 0;        }        public int GetGridRowCount(IDataForm form, string strGridControlName)        {            int iCount = 0;            if (form == null || string.IsNullOrEmpty(strGridControlName)) return iCount;            GridControlClass gc = form.GetControl(strGridControlName) as GridControlClass;            if (gc == null) return iCount;            GridView gv = gc.MainView as GridView;            if (gv == null) return iCount;            iCount = gv.DataRowCount;            return iCount;        }        /// <summary>        /// 验证是否有数据源        /// </summary>        /// <param name="gc"></param>        /// <returns></returns>        public static bool DataCheck(GridControlClass gc)        {            if (gc == null) return false;            List<RowBase> lstRows = gc.DataSource as List<RowBase>;            if (lstRows == null || lstRows.Count == 0)            {                MessageManager.Show("数据源不能为空!", "系统提示");                return false;            }            int SelectRows = 0;            foreach (RowBase item in lstRows)            {                string strCheckBox = item.GetValue<string>("SHOWCHECKBOX");                if (string.IsNullOrEmpty(strCheckBox) || strCheckBox.ToUpper() != "TRUE")                    continue;                SelectRows++;            }            if (SelectRows > 0)                return true;            else            {                MessageManager.Show("请选择一条记录!", "系统提示");                return false;            }        }        /// <summary>        /// 设计成果删除的公共方法        /// </summary>        /// <param name="lstRow"></param>        /// <param name="strTableName"></param>        /// <param name="strUniFieldName"></param>        public static bool DelFeatures(List<IRow> lstRow, string strTableName, string strUniFieldName)        {            if (lstRow == null || lstRow.Count == 0)            {                MessageManager.Show("请选择一条记录!", "系统提示");                return false;            }            if (string.IsNullOrEmpty(strTableName) || string.IsNullOrEmpty(strUniFieldName))            {                LogManage.WriteLog("删除设计成果时,参数不能为空!");                return false;            }            ITable table_RG = ForeStar.Data.Metadata.MetadataWorkspaceClass.GetMetadataWorkspace.OpenTable(strTableName).Table;            if (table_RG == null)            {                LogManage.WriteLog("设计成果删除时不能打开表【" + strTableName + "】");                return false;            }            try            {                foreach (IRow item in lstRow)                {                    Int32 I_Pk_UID = item.GetValue<Int32>(strUniFieldName);                    IFeatureClass pFeaCls = table_RG as IFeatureClass;                    IMZDatasetVector dv = pFeaCls.InnerObject as IMZDatasetVector;                    if (dv != null)                        dv.DeleteFeature(I_Pk_UID);                }                return true;            }            catch (Exception ex)            {                LogManage.WriteLog(ex.ToString());                return false;            }        }    }}



<pre name="code" class="csharp">        //设置GridControl行的背景颜色    
        GridControlClass pGrid = null;
        private void SetRowBackColor(IDataForm form, string strGridControlName)        {            if (form == null || string.IsNullOrEmpty(strGridControlName)) return;            pGrid = form.GetControl(strGridControlName) as GridControlClass;            DevExpress.XtraGrid.Views.Grid.GridView focusView = pGrid.FocusedView as DevExpress.XtraGrid.Views.Grid.GridView;            if (focusView == null) return;            focusView.CustomDrawCell += new DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventHandler(focusView_CustomDrawCell);        }        void focusView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)        {            if (pGrid == null)            {                return;            }            List<RowBase> rows = pGrid.DataSource as List<RowBase>;            if (rows == null || rows.Count <= 0) return;            if (e.RowHandle >= rows.Count)                return;            RowBase row = rows[e.RowHandle];            if (row.GetValue<string>("SFBG").ToString() == "3")            {                e.Appearance.BackColor = System.Drawing.Color.Cyan;            }        } 


0 0
原创粉丝点击