DeviceManager/TsSFCDevice.Client.Launch/Common/pageDeivceView.cs
2024-11-09 12:25:57 +08:00

203 lines
6.9 KiB
C#

using DevExpress.XtraBars.ToolbarForm;
using DeviceRepair.Models;
using DeviceRepair.Utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using TsSFCDevice.Client.Biz.Base.Utils;
namespace TsSFCDevice.Client.Launch.Common
{
public partial class pageDeivceView : ToolbarForm
{
int m_SelectedCurrentRowIndex = 0;
public DeviceInformationInfo CurrentDeviceInfo = null;
string FilterString
{
get { return txt_Filter.EditValue?.ToString()?.Trim(); }
}
public pageDeivceView()
{
InitializeComponent();
this.Load += PageDeivceView_Load;
}
private void PageDeivceView_Load(object sender, EventArgs e)
{
InitializeGridViewStyle();
InitializeGridDatas();
}
void InitializeGridDatas()
{
try
{
splashScreenManager1.ShowWaitForm();
gridView1.ClearSelection();
if (!string.IsNullOrWhiteSpace(FilterString) && FilterString.Length > 20)
{
txt_Filter.EditValue = "";
throw new Exception("输入的搜索关键字超长");
}
IList<DeviceInformationInfo> lst = Utility.SystemRuntimeInfo.CurrentDeviceCaches;
if (!FilterString.IsNull())
lst = lst.Where(x => x.EquipmentID == FilterString).ToList();
CloseWaitForm();
gridControl1.DataSource = lst;
gridView1.BestFitColumns();
if (lst.Count > 0)
{
CurrentDeviceInfo = lst[0]; gridView1.SelectRow(0);
SizeF size = this.CreateGraphics().MeasureString(lst.Count.ToString(), this.Font);
gridView1.IndicatorWidth = Convert.ToInt32(size.Width) + 20;
}
}
catch (Exception ex)
{
CloseWaitForm();
XtraMessageBoxHelper.Error(ex.Message);
}
}
/// <summary>
/// 初始化表格样式
/// </summary>
void InitializeGridViewStyle()
{
layoutControl1.AllowCustomization = false;
// 关闭列头右键菜单
gridView1.OptionsMenu.EnableColumnMenu = false;
/// 自增长行号
gridView1.CustomDrawRowIndicator += (s, e) =>
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
e.Appearance.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;
}
};
/// 修改字段标题
gridView1.CustomDrawColumnHeader += (s, e) =>
{
if (e.Column != null && (e.Column.Caption == "Selection" || e.Column.FieldName == "DX$CheckboxSelectorColumn"))
{
e.Info.Caption = "选择";
e.Appearance.Font = new System.Drawing.Font("Tahoma", 12F);
}
};
/// 单元格点击
gridView1.RowCellClick += (s, e) =>
{
if (e.Button == MouseButtons.Right)
{
e.Handled = true;
return;
}
if (e.Column.Caption == "Selection")
{
if (this.m_SelectedCurrentRowIndex == e.RowHandle && this.gridView1.IsRowSelected(e.RowHandle))
this.gridView1.UnselectRow(e.RowHandle);
}
};
/// 表格选中行更改
gridView1.FocusedRowChanged += (s, e) =>
{
try
{
if (e.FocusedRowHandle >= 0)
{
m_SelectedCurrentRowIndex = e.FocusedRowHandle;
CurrentDeviceInfo = gridView1.GetRow(e.FocusedRowHandle) as DeviceInformationInfo;
#region
if (gridView1.SelectedRowsCount > 0)
{
for (int i = 0; i < this.gridView1.RowCount; i++)
{
if (this.gridView1.IsRowSelected(i) && this.gridView1.FocusedRowHandle.ToString().Equals(i.ToString()) == false)
{
this.gridView1.UnselectRow(i);
}
}
}
this.gridView1.SelectRow(e.FocusedRowHandle);
#endregion
}
else
{
CurrentDeviceInfo = null;
}
}
catch (Exception ex)
{
XtraMessageBoxHelper.Error(ex.Message);
}
};
gridView1.OptionsBehavior.Editable = false;
gridView1.OptionsBehavior.ReadOnly = true;
gridView1.OptionsSelection.MultiSelect = true;
gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
gridView1.OptionsScrollAnnotations.ShowSelectedRows = DevExpress.Utils.DefaultBoolean.False;
foreach (DevExpress.XtraGrid.Columns.GridColumn item in gridView1.Columns)
{
item.OptionsColumn.AllowEdit = false;
item.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.True;
item.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False;
item.OptionsColumn.AllowShowHide = false;
}
}
private void CloseWaitForm()
{
try
{
if (splashScreenManager1.IsSplashFormVisible)
{
splashScreenManager1.CloseWaitForm();
}
Cursor.Current = Cursors.Default;
}
catch (Exception ex)
{
//m_log.Error(ex.Message, ex);
}
}
private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (CurrentDeviceInfo == null)
{
XtraMessageBoxHelper.Info("请选择设备!");
return;
}
this.DialogResult = DialogResult.OK;
}
private void btn_Search_Click(object sender, EventArgs e)
{
InitializeGridDatas();
}
}
}