DeviceManager/TsSFCDeivceClient/pageDeivceView.cs

204 lines
7.1 KiB
C#
Raw Normal View History

2024-05-29 01:56:37 +00:00
using DevExpress.XtraBars.ToolbarForm;
2024-05-30 15:52:57 +00:00
using DeviceRepair.Models;
2024-05-29 01:56:37 +00:00
using System;
using System.Collections.Generic;
2024-06-03 17:21:11 +00:00
using System.Drawing;
2024-05-29 01:56:37 +00:00
using System.Windows.Forms;
using TsSFCDeivceClient.Common;
namespace TsSFCDeivceClient
{
public partial class pageDeivceView : ToolbarForm
{
int m_SelectedCurrentRowIndex = 0;
2024-05-30 15:52:57 +00:00
public DeviceInformationInfo CurrentDeviceInfo = null;
2024-06-03 17:21:11 +00:00
2024-05-29 01:56:37 +00:00
string FilterString
{
get { return txt_Filter.EditValue?.ToString()?.Trim(); }
}
public pageDeivceView()
{
InitializeComponent();
this.Load += PageDeivceView_Load;
}
private void PageDeivceView_Load(object sender, EventArgs e)
{
2024-06-02 16:38:52 +00:00
if (string.IsNullOrWhiteSpace(RunConfig.config.ServiceApiUrl))
2024-05-29 01:56:37 +00:00
{
XtraMessageBoxHelper.Error($"缺少配置字段设备管理软件接口地址【ServiceApiUrl】。");
this.Close();
}
InitializeGridViewStyle();
InitializeGridDatas();
}
void InitializeGridDatas()
{
try
{
splashScreenManager1.ShowWaitForm();
2024-07-08 02:44:57 +00:00
if (!string.IsNullOrWhiteSpace(FilterString) && FilterString.Length > 20)
{
2024-07-17 02:32:45 +00:00
txt_Filter.EditValue = "";
2024-07-08 02:44:57 +00:00
throw new Exception("输入的搜索关键字超长");
}
2024-06-02 16:38:52 +00:00
APIResponseData apiResponseData = Biz.HttpHelper.Instance.Get($"{RunConfig.config.ServiceApiUrl}{DeviceApiUrlConstValue.GetDeviceDatas}?FilterString={FilterString}");
2024-05-29 01:56:37 +00:00
if (!apiResponseData.IsSuccess)
throw new Exception(apiResponseData.Message);
2024-05-30 15:52:57 +00:00
List<DeviceInformationInfo> lst = apiResponseData.ToDeserializeObject<List<DeviceInformationInfo>>();
2024-05-29 01:56:37 +00:00
CloseWaitForm();
gridControl1.DataSource = lst;
gridView1.BestFitColumns();
if (lst.Count > 0)
2024-06-03 17:21:11 +00:00
{
CurrentDeviceInfo = lst[0]; gridView1.SelectRow(0);
SizeF size = this.CreateGraphics().MeasureString(lst.Count.ToString(), this.Font);
gridView1.IndicatorWidth = Convert.ToInt32(size.Width) + 20;
}
2024-05-29 01:56:37 +00:00
}
catch (Exception ex)
{
CloseWaitForm();
XtraMessageBoxHelper.Error(ex.Message);
}
}
/// <summary>
/// 初始化表格样式
/// </summary>
void InitializeGridViewStyle()
{
2024-07-08 02:44:57 +00:00
layoutControl1.AllowCustomization = false;
// 关闭列头右键菜单
gridView1.OptionsMenu.EnableColumnMenu = false;
2024-05-29 01:56:37 +00:00
/// 自增长行号
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) =>
{
2024-06-04 09:25:13 +00:00
(new Action<DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs>(BaseControlEx.GridControlExtend.CustomDrawColumnHeader)).Invoke(e);
2024-05-29 01:56:37 +00:00
};
/// 单元格点击
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;
2024-05-30 15:52:57 +00:00
CurrentDeviceInfo = gridView1.GetRow(e.FocusedRowHandle) as DeviceInformationInfo;
2024-05-29 01:56:37 +00:00
#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)
{
2024-07-08 02:44:57 +00:00
XtraMessageBoxHelper.Info("请选择设备!");
2024-05-29 01:56:37 +00:00
return;
}
this.DialogResult = DialogResult.OK;
}
private void btn_Search_Click(object sender, EventArgs e)
{
InitializeGridDatas();
}
}
}