GridControlClass公用方法

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;
            }
        }
    }
}

 

         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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值