115 lines
3.5 KiB
C#
115 lines
3.5 KiB
C#
using DevExpress.XtraBars.ToolbarForm;
|
||
using DevExpress.XtraTreeList.Nodes;
|
||
using DeviceRepair.Models;
|
||
using DeviceRepairAndOptimization.Biz;
|
||
using DeviceRepairAndOptimization.Common;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace DeviceRepairAndOptimization.Pages.DriveMaintenance
|
||
{
|
||
public partial class pageRouteAssign : ToolbarForm
|
||
{
|
||
public DeviceRouteInfo CurrentSelectModel = null;
|
||
List<DeviceRouteInfo> routes = null;
|
||
int CurrentRoute = 0;
|
||
|
||
public pageRouteAssign(int Route = 0)
|
||
{
|
||
InitializeComponent();
|
||
CurrentRoute = Route;
|
||
this.Load += PageRouteAssign_Load;
|
||
}
|
||
|
||
private void PageRouteAssign_Load(object sender, EventArgs e)
|
||
{
|
||
InitializeTreeDatas();
|
||
|
||
if (CurrentRoute != 0)
|
||
{
|
||
foreach (TreeListNode node in treeList1.Nodes)
|
||
{
|
||
SelectNodeByID(node, CurrentRoute);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void SelectNodeByID(TreeListNode node, int targetID)
|
||
{
|
||
// 假设ID存储在节点的第一个列(索引0)
|
||
if (node.GetValue("AutoID")?.ToString() == targetID.ToString())
|
||
{
|
||
node.Checked = true;
|
||
return;
|
||
}
|
||
|
||
// 递归处理子节点
|
||
foreach (TreeListNode childNode in node.Nodes)
|
||
{
|
||
SelectNodeByID(childNode, targetID);
|
||
}
|
||
}
|
||
|
||
void InitializeTreeDatas()
|
||
{
|
||
try
|
||
{
|
||
APIResponseData apiResponseData = DeviceManager.Instance.GetDeviceRoute();
|
||
if (apiResponseData.Code != 1)
|
||
{
|
||
splashScreenManager1.CloseWaitForm();
|
||
XtraMessageBoxHelper.Error(apiResponseData.Message);
|
||
return;
|
||
}
|
||
routes = apiResponseData.ToDeserializeObject<List<DeviceRouteInfo>>();
|
||
|
||
treeList1.DataSource = routes;
|
||
treeList1.KeyFieldName = "AutoID";
|
||
treeList1.ParentFieldName = "ParentID";
|
||
treeList1.ExpandAll();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBoxHelper.Error(ex.Message);
|
||
}
|
||
}
|
||
|
||
private void treeList1_CustomDrawNodeCheckBox(object sender, DevExpress.XtraTreeList.CustomDrawNodeCheckBoxEventArgs e)
|
||
{
|
||
if (e.Node.Level == 1)
|
||
{
|
||
e.Handled = true;
|
||
return;
|
||
}
|
||
}
|
||
|
||
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
||
{
|
||
List<TreeListNode> treeListNodes = treeList1.GetAllCheckedNodes();
|
||
if ((treeListNodes?.Count ?? 0) > 0)
|
||
{
|
||
TreeListNode node = treeListNodes.FirstOrDefault();
|
||
CurrentSelectModel = routes.FirstOrDefault(x => x.AutoID == node.Id);
|
||
this.DialogResult = DialogResult.OK;
|
||
}
|
||
else
|
||
{
|
||
XtraMessageBoxHelper.Warn("选中数据不能为空!");
|
||
}
|
||
}
|
||
|
||
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
||
{
|
||
treeList1.UncheckAll();
|
||
e.Node.Checked = true;
|
||
}
|
||
}
|
||
}
|