init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,240 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DevExpress.XtraGrid.Views.Grid;
|
||||
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using DevExpress.Utils;
|
||||
using System.Data;
|
||||
using DevExpress.XtraGrid;
|
||||
|
||||
namespace Lskj.PubPower
|
||||
{
|
||||
/// <summary>
|
||||
/// 表格拖拽到表格
|
||||
/// </summary>
|
||||
public class GridDragGrid
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否正在拖拽
|
||||
/// </summary>
|
||||
private bool _draging = false;
|
||||
/// <summary>
|
||||
/// 拖动位置
|
||||
/// </summary>
|
||||
private GridHitInfo _hitInfo;
|
||||
/// <summary>
|
||||
/// 当前操作的GridView
|
||||
/// </summary>
|
||||
private GridView _sourceGridView;
|
||||
/// <summary>
|
||||
/// 目标GridView
|
||||
/// </summary>
|
||||
private GridView _targetGridView;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 拖动完成后调用
|
||||
/// </summary>
|
||||
public event GridFragGridCompleteEventHandler OnDragComplete;
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GridDragGrid"/> class.
|
||||
/// </summary>
|
||||
/// <param name="curGridView">当前GridView</param>
|
||||
/// <param name="tarGridView">目标GridView.</param>
|
||||
public GridDragGrid(GridView sourceView, GridView targetView)
|
||||
{
|
||||
this._sourceGridView = sourceView;
|
||||
this._targetGridView = targetView;
|
||||
|
||||
if (this._sourceGridView == null || this._targetGridView == null) return;
|
||||
|
||||
this._sourceGridView.MouseDown += new System.Windows.Forms.MouseEventHandler(sourceGridView_MouseDown);
|
||||
this._sourceGridView.MouseMove += new System.Windows.Forms.MouseEventHandler(sourceGridView_MouseMove);
|
||||
this._sourceGridView.MouseUp += new System.Windows.Forms.MouseEventHandler(sourceGridView_MouseUp);
|
||||
|
||||
this._targetGridView.GridControl.AllowDrop = true;
|
||||
this._targetGridView.GridControl.DragOver += new DragEventHandler(gridControl_DragOver);
|
||||
this._targetGridView.GridControl.DragEnter += new System.Windows.Forms.DragEventHandler(gridControl_DragEnter);
|
||||
this._targetGridView.GridControl.DragDrop += new System.Windows.Forms.DragEventHandler(gridControl_DragDrop);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:获取表格选中行数据</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-13 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="rowHandles">The row handles.</param>
|
||||
/// <returns>DataRow[].</returns>
|
||||
private DataRow[] GetGridSelectRows(int[] rowHandles)
|
||||
{
|
||||
List<DataRow> rows = new List<DataRow>();
|
||||
|
||||
foreach (int handle in rowHandles)
|
||||
{
|
||||
DataRow row = this._sourceGridView.GetDataRow(handle);
|
||||
rows.Add(row);
|
||||
}
|
||||
|
||||
return rows.ToArray();
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:源表格鼠标按下</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-13 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
|
||||
protected void sourceGridView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
|
||||
{
|
||||
this._hitInfo = null;
|
||||
if (System.Windows.Forms.Control.ModifierKeys != Keys.None) return;
|
||||
|
||||
GridView gridView = sender as GridView;
|
||||
GridHitInfo hitInfo = gridView.CalcHitInfo(new Point(e.X, e.Y));
|
||||
|
||||
if (e.Button == MouseButtons.Left && hitInfo.RowHandle >= 0)
|
||||
{
|
||||
this._draging = true;
|
||||
this._hitInfo = hitInfo;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:源表格鼠标移动</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-13 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
|
||||
protected void sourceGridView_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
|
||||
{
|
||||
GridView gridView = sender as GridView;
|
||||
if (e.Button == MouseButtons.Left && this._hitInfo != null)
|
||||
{
|
||||
Size dragSize = SystemInformation.DragSize;
|
||||
Rectangle dragRect = new Rectangle(new Point(this._hitInfo.HitPoint.X - dragSize.Width / 2,
|
||||
this._hitInfo.HitPoint.Y - dragSize.Height / 2), dragSize);
|
||||
|
||||
if (!dragRect.Contains(new Point(e.X, e.Y)))
|
||||
{
|
||||
object row = gridView.GetRow(this._hitInfo.RowHandle >= 0 ? this._hitInfo.RowHandle : 0);
|
||||
gridView.GridControl.DoDragDrop(row, DragDropEffects.Move);
|
||||
this._hitInfo = null;
|
||||
DXMouseEventArgs.GetMouseArgs(e).Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:源表格鼠标放开</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-13 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
|
||||
protected void sourceGridView_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
|
||||
{
|
||||
this._draging = false;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:移动到目标表格上</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-13 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="System.Windows.Forms.DragEventArgs"/> instance containing the event data.</param>
|
||||
private void gridControl_DragOver(object sender, DragEventArgs e)
|
||||
{
|
||||
GridControl targetControl = (sender as GridControl);
|
||||
GridView targetGrid = targetControl.FocusedView as GridView;
|
||||
Point gcPoint = targetControl.PointToScreen((sender as GridControl).Location);
|
||||
Point pt = new Point(e.X - gcPoint.X, e.Y - gcPoint.Y);
|
||||
_hitInfo = targetGrid.CalcHitInfo(pt);
|
||||
if (_hitInfo == null || _hitInfo.RowHandle < 0) return;
|
||||
targetGrid.SelectRow(_hitInfo.RowHandle);
|
||||
targetGrid.FocusedRowHandle = _hitInfo.RowHandle;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:移动到目标表格</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-13 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="System.Windows.Forms.DragEventArgs"/> instance containing the event data.</param>
|
||||
protected void gridControl_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
|
||||
{
|
||||
e.Effect = DragDropEffects.Move;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:拖动完成时</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-11-13 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="System.Windows.Forms.DragEventArgs"/> instance containing the event data.</param>
|
||||
protected void gridControl_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
|
||||
{
|
||||
if (this.OnDragComplete != null && this._draging)
|
||||
{
|
||||
this._draging = false;
|
||||
|
||||
GridDragGridArgs args = new GridDragGridArgs();
|
||||
args.SourceGridViewObj = this._sourceGridView;
|
||||
args.TargetGridViewObj = this._targetGridView;
|
||||
args.GridViewSelectRows = GetGridSelectRows(this._sourceGridView.GetSelectedRows());
|
||||
args.SelectGridRow = this._targetGridView.GetDataRow(this._targetGridView.FocusedRowHandle);
|
||||
this.OnDragComplete(sender, args);
|
||||
}
|
||||
}
|
||||
#region 表格第一列添加复选框
|
||||
/// <summary>
|
||||
/// <para>说明:表格第一列添加复选框</para>
|
||||
/// <para>创建人:唐德馨</para>
|
||||
/// <para>创建日期:2021-07-08 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="gridColumn">The grid columnFilterPopupChecke.</param>
|
||||
public static void GridAddCheckBox(GridView gridview)
|
||||
{
|
||||
gridview.OptionsSelection.MultiSelect = true;
|
||||
gridview.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect;
|
||||
gridview.OptionsSelection.EnableAppearanceFocusedCell = false;
|
||||
gridview.OptionsBehavior.EditorShowMode = EditorShowMode.MouseDown;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user