using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using Lskj.Control.Model; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraEditors; using DevExpress.XtraGrid; using DevExpress.Utils; using Lskj.Business.Impl; using Lskj.Control; namespace Lskj.MesGumDip.Control { /// /// 自动搜索框弹出框 /// public partial class AutoGridPopup : UserControl { /// /// 是否显示添加按钮 /// /// true if [add visible]; otherwise, false. public bool AddVisible { get { return this.btnAdd.Visible; } set { this.btnAdd.Visible = value; this.pl_bottom.Visible = value; } } /// /// 输入框 /// public ButtonEdit LookUp; /// /// Gets the grid control object. /// /// The grid control object. public GridControl GridControlObj { get { return this.gridControl; } } /// /// Gets the grid view object. /// /// The grid view object. public GridView GridViewObj { get { return this.gridView; } } /// /// 提示文本 /// /// The label object. public LabelControl LabelObj { get { return this.lbl_title; } } /// /// Gets the top panel object. /// /// The top panel object. public PanelControl BottomPanelObj { get { return this.pl_bottom; } } /// /// 缓存列对象 /// public List ColumnList = new List(); /// /// 弹出框回车事件 /// public event KeyEventHandler OnGridViewEnter; /// /// 添加按钮点击事件 /// public event EventHandler OnAddMouseClick; /// /// 弹出框鼠标点击 /// public event EventHandler OnGridViewMouseClick; /// /// The reset colum primary key /// public string CustomColumKey; public ControlModel Model; public AutoGridPopup() { InitializeComponent(); this.GotFocus += new EventHandler(OnAutoGridPopupGotFocus); this.gridView.CustomDrawRowIndicator += new RowIndicatorCustomDrawEventHandler(OnGridViewCustomDrawRowIndicator); this.gridView.CustomDrawCell += new DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventHandler(OnGridViewCustomDrawCell); gridControl.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat; gridControl.LookAndFeel.UseDefaultLookAndFeel = false; gridView.Appearance.HeaderPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); gridView.Appearance.HeaderPanel.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); gridView.Appearance.HeaderPanel.ForeColor = System.Drawing.Color.Black; gridView.ColumnPanelRowHeight = 30; gridView.RowHeight = 32; gridView.Appearance.Row.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F); gridView.Appearance.Row.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(136)))), ((int)(((byte)(136)))), ((int)(((byte)(136))))); } /// /// 说明:GridView获取焦点 /// 创建人:龚宇超 /// 创建日期:2018-03-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnAutoGridPopupGotFocus(object sender, EventArgs e) { try { if (this.gridView.DataSource != null) { this.gridView.FocusedRowHandle = 0; this.gridView.SelectRow(0); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } /// /// 说明:生成序号 /// 创建人:龚宇超 /// 创建日期:2018-03-15 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnGridViewCustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) { try { e.Appearance.TextOptions.HAlignment = HorzAlignment.Center; if (e.Info.IsRowIndicator) { if (e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } } } catch (Exception) { } } /// /// 说明:设置颜色 /// 创建人:龚宇超 /// 创建日期:2018-03-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnGridViewCustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { try { if (e.RowHandle == gridView.FocusedRowHandle) e.Appearance.BackColor = ColorTranslator.FromHtml("#9feb6a"); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } /// /// 说明:键盘弹起 /// 创建人:龚宇超 /// 创建日期:2018-03-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnGridViewKeyUp(object sender, KeyEventArgs e) { try { if (this.OnGridViewEnter != null) this.OnGridViewEnter(this.gridView, e); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } /// /// 说明:点击GridView /// 创建人:龚宇超 /// 创建日期:2018-03-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnGridViewMouseDown(object sender, MouseEventArgs e) { try { int rowHandle = this.gridView.CalcHitInfo(e.X, e.Y).RowHandle; this.gridView.FocusedRowHandle = rowHandle; this.gridView.SelectRow(rowHandle); if (rowHandle > -1 && this.OnGridViewMouseClick != null) this.OnGridViewMouseClick(this.gridView, null); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } /// /// 说明:添加操作 /// 创建人:龚宇超 /// 创建日期:2018-04-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnAddButtonClick(object sender, EventArgs e) { try { if (this.OnAddMouseClick != null) this.OnAddMouseClick(sender, e); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } } }