BaoKai_202508-Wms-Jingwang..../WMS.Common/DevControlHelper.cs

101 lines
4.0 KiB
C#
Raw Normal View History

2025-08-24 09:35:55 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraEditors.Repository;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
namespace WMS.Common
{
public class DevControlHelper
{
#region CheckBox
public static void DrawCheckBox(DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e, bool chk)
{
RepositoryItemCheckEdit repositoryCheck = e.Column.ColumnEdit as RepositoryItemCheckEdit;
if (repositoryCheck != null)
{
Graphics g = e.Graphics;
Rectangle r = e.Bounds;
DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo info;
DevExpress.XtraEditors.Drawing.CheckEditPainter painter;
DevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs args;
info = repositoryCheck.CreateViewInfo() as DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo;
painter = repositoryCheck.CreatePainter() as DevExpress.XtraEditors.Drawing.CheckEditPainter;
info.EditValue = chk;
info.Bounds = r;
info.CalcViewInfo(g);
args = new DevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs(info, new DevExpress.Utils.Drawing.GraphicsCache(g), r);
painter.Draw(args);
args.Cache.Dispose();
}
}
#endregion
#region
public static bool ClickGridCheckBox(DevExpress.XtraGrid.Views.Grid.GridView gridView, string fieldName, bool currentStatus)
{
bool result = false;
if (gridView != null)
{
gridView.ClearSorting();//禁止排序
gridView.PostEditor();
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo info;
Point pt = gridView.GridControl.PointToClient(Control.MousePosition);
info = gridView.CalcHitInfo(pt);//鼠标位置(点) 表格热区
//info.InColumn && info.Column != null &&
if (info.InColumn && info.Column != null && info.Column.FieldName == fieldName)//判断是不是Check列
{
for (int i = 0; i < gridView.RowCount; i++)
{
gridView.SetRowCellValue(i, fieldName, !currentStatus);//对check列进行复制操作
}
return true;
}
}
return result;
}
public static void ClickCheckBox(DevExpress.XtraGrid.Views.Grid.GridView gridView, string fieldName, bool currentStatus)
{
if (gridView != null)
{
int rowIndex = gridView.FocusedRowHandle;
gridView.SetRowCellValue(rowIndex, fieldName, !currentStatus);//对check列进行复制操作
}
}
#endregion
#region
public static void ClickGridRadioCheck(DevExpress.XtraGrid.Views.Grid.GridView gridView, string fieldName)
{
Boolean result = false;
if (gridView != null)
{
gridView.ClearSorting();//禁止排序
gridView.PostEditor();
int curRowID = gridView.FocusedRowHandle;
DataRow dr = gridView.GetFocusedDataRow();
object isChecked = dr[fieldName];
if (isChecked != DBNull.Value)//数据中的空
{
result = Convert.ToBoolean(isChecked);
}
gridView.SetRowCellValue(curRowID, fieldName, !result);//对check列进行赋值操作
for (int i = 0; i < gridView.RowCount; i++)
{
//对check列进行赋值操作 false
if (i != curRowID)
{
gridView.SetRowCellValue(i, fieldName, false);
}
}
}
}
#endregion
}
}