using Lskj.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Lskj.Control.SiftColControl
{
public partial class FrmGridSiftProjectManager : BaseForm
{
public FrmGridSiftProjectManager()
{
InitializeComponent();
this.Load += new EventHandler(OnFrmGridSiftProjectManager_Load);
}
///
/// 初始化时
///
///
///
private void OnFrmGridSiftProjectManager_Load(object sender, EventArgs e)
{
InitGrid();
BindCustomDrawRowIndicator(this.mainGridView);
InitGridData();
}
///
/// 初始化表格
///
private void InitGrid()
{
string sqlStr = "select employeeid,employeename from p_employeetab";
DataTable sourceTab = SqlHelper.ExecuteDataTable(sqlStr);
this.operatorGridLookUpEdit.DisplayMember = "employeename";
this.operatorGridLookUpEdit.ValueMember = "employeeid";
this.operatorGridLookUpEdit.ShowFooter = false;
this.operatorGridLookUpEdit.DataSource = sourceTab;
this.mainGridView.OptionsView.ColumnAutoWidth = true;
}
private void InitGridData()
{
string sqlStr = @"select name from p_SysModuleSchemeTab where moduleId = '{0}' and operatorid = '{1}' and isPub = '0'
union all select name from p_SysModuleSchemeTab where moduleId = '{0}' and isPub = '1'";
DataTable sourceTab = SqlHelper.ExecuteDataTable(string.Format(sqlStr, "", ""));
this.mainGridControl.DataSource = sourceTab;
}
///
/// 新增方案
///
///
///
private void addBtn_Click(object sender, EventArgs e)
{
}
///
/// 删除方案
///
///
///
private void deleteBtn_Click(object sender, EventArgs e)
{
}
///
/// 保存方案
///
///
///
private void saveBtn_Click(object sender, EventArgs e)
{
}
#region 显示行号
///
/// 说明:显示行号
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
public static void BindCustomDrawRowIndicator(DevExpress.XtraGrid.Views.Grid.GridView view)
{
view.IndicatorWidth = CalcIndicatorDefaultWidth(view);
view.CustomDrawRowIndicator += (s, e) =>
{
if (e.RowHandle >= 0)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
};
view.TopRowChanged += (s, e) =>
{
int width = CalcIndicatorBestWidth(view);
if ((view.IndicatorWidth - 4 < width || view.IndicatorWidth + 4 > width) && view.IndicatorWidth != width)
{
view.IndicatorWidth = width;
}
};
}
///
/// 计算行头宽度
///
///
///
static int CalcIndicatorBestWidth(DevExpress.XtraGrid.Views.Grid.GridView view)
{
Graphics graphics = new System.Windows.Forms.Control().CreateGraphics();
SizeF sizeF = new SizeF();
int count = view.TopRowIndex + ((DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo)view.GetViewInfo()).RowsInfo.Count;
if (count == 0)
{
count = 30;
}
sizeF = graphics.MeasureString(count.ToString(), view.Appearance.Row.Font);
return Convert.ToInt32(sizeF.Width) + 20;
}
///
/// 计算默认的宽度
///
///
///
static int CalcIndicatorDefaultWidth(DevExpress.XtraGrid.Views.Grid.GridView view)
{
var grid = view.GridControl;
Graphics graphics = new System.Windows.Forms.Control().CreateGraphics();
SizeF sizeF = new SizeF();
int rowHeight = 22;//22是Row的估计高度
if (view.RowHeight > 0)
{
rowHeight = view.RowHeight;
}
int count = grid != null ? grid.Height / rowHeight : 30;
sizeF = graphics.MeasureString(count.ToString(), view.Appearance.Row.Font);
return Convert.ToInt32(sizeF.Width) + 20;
}
#endregion
}
}