代码清理

This commit is contained in:
liyaobang 2025-03-24 19:24:16 +08:00
parent fb1ae0bb08
commit fabc7606e7
14 changed files with 425 additions and 547 deletions

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DHSoftware.Languages
namespace DHSoftware.Languages
{
public class Localizer_enus : AntdUI.ILocalization
{
@ -14,125 +8,182 @@ namespace DHSoftware.Languages
{
case "search":
return "Search";
case "welcome":
return "Welcome to the AntdUI Demo";
case "home":
return "Home";
case "closeall":
return "Close all tabs";
#region systemset
case "systemset":
return "System Settings";
case "baseset":
return "Basic Settings";
case "messageconfig":
return "Message configuration";
case "animationon":
return "Turn on animation";
case "shadowon":
return "Enable shadow";
case "scrollbarhide":
return "Hide scrollbar";
case "showinwindow":
return "Show in window";
case "windowOffsetXY":
return "WindowOffsetXY";
case "tip":
return "Tip";
case "switchsuccess":
return "Switch successful.";
#endregion
#endregion systemset
#region Button
case "Button.Text":
return "Button";
case "Button.Description":
return "To trigger an operation.";
case "type":
return "Type";
case "wave":
return "Wave";
case "loading":
return "Loading";
case "ghost":
return "Ghost";
case "border":
return "Border";
case "icon":
return "Icon";
case "arrow":
return "Arrow";
case "join":
return "Join";
case "gradient":
return "Gradient";
case "toggle":
return "Toggle";
#endregion
#endregion Button
#region FloatButton
case "FloatButton.Text":
return "FloatButton";
case "FloatButton.Description":
return "A button that floats at the top of the page.";
case "FloatButton.Tip":
return "FloatButton does not have a toolbox control and is called code.";
case "control_option":
return "Control Options";
case "button_option":
return "Button Options";
case "open":
return "Open";
case "close":
return "Close";
case "reset":
return "Reset";
#endregion
#endregion FloatButton
#region Icon
case "Icon.Text":
return "Icon";
case "Icon.Description":
return "Semantic vector graphics.";
case "Icon.Tip":
return "Icon does not have a toolbox control and is used for Svg property assignments.";
case "outlined":
return "Outlined";
case "filled":
return "Filled";
case "directionalicon":
return "Directional icons";
case "suggestionicon":
return "Suggestion Icon";
case "editingicon":
return "Editing Icons";
case "dataicon":
return "Data icons";
case "brand":
return "Brand and logo";
case "universal":
return "Universal Icons for Websites";
case "copysuccess":
return "Copy successful!";
case "copyfail":
return "Copy failed!";
#endregion
#endregion Icon
#region Divider
case "Divider.Text":
return "Divider";
case "Divider.Description":
return "A divider line separates different content.";
case "basicusage":
return "Basic Usage";
case "vertical":
return "Vertical";
case "horizontal":
return "Horizontal";
#endregion
#endregion Divider
default:
return null;
}
}
}

View File

@ -1,26 +1,23 @@
using AntdUI;
using DHSoftware.Models;
using DHSoftware.Services;
namespace DHSoftware
{
public partial class LoginWindow : AntdUI.Window
{
public LoginWindow()
{
InitializeComponent();
button_ok.Click += Button_ok_Click;
button_cancel.Click += Button_cancel_Click;
}
/// <summary>
/// 窗体对象实例
/// </summary>
private static LoginWindow _instance;
internal static LoginWindow Instance
{
get
@ -30,6 +27,7 @@ namespace DHSoftware
return _instance;
}
}
private void Button_cancel_Click(object? sender, EventArgs e)
{
this.Dispose();
@ -47,9 +45,8 @@ namespace DHSoftware
AntdUI.Message.warn(this, "密码不能为空!", autoClose: 3);
return;
}
if(AuthService.Login(iptName.Text, iptPwd.Text))
if (AuthService.Login(iptName.Text, iptPwd.Text))
{
if (this.Owner is MainWindow parent)
{
List<string> UserPermissions = AuthService.GetUserPermissions();
@ -87,8 +84,7 @@ namespace DHSoftware
parent.Deleteschememe = false;
}
parent.LoginName=iptName.Text;
parent.LoginName = iptName.Text;
}
this.Dispose();
}
@ -100,7 +96,6 @@ namespace DHSoftware
private void LoginWindow_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -36,16 +36,12 @@ using ResultState = DH.Commons.Base.ResultState;
namespace DHSoftware
{
public partial class MainWindow : AntdUI.Window
{
Dictionary<string, List<string>> _cameraRelatedDetectionDict = null;
private Dictionary<string, List<string>> _cameraRelatedDetectionDict = null;
private string _loginName;
public string LoginName
{
get { return _loginName; }
@ -55,7 +51,9 @@ namespace DHSoftware
UpdateLabel();
}
}
private bool _ShowConfig;
public bool ShowConfig
{
get { return _ShowConfig; }
@ -66,8 +64,8 @@ namespace DHSoftware
}
}
private bool _addscheme;
public bool Addscheme
{
get { return _addscheme; }
@ -77,7 +75,9 @@ namespace DHSoftware
UpdateScheme();
}
}
private bool _deletescheme;
public bool Deleteschememe
{
get { return _deletescheme; }
@ -87,7 +87,9 @@ namespace DHSoftware
UpdateScheme();
}
}
private bool _loadscheme;
public bool Loadscheme
{
get { return _loadscheme; }
@ -100,7 +102,6 @@ namespace DHSoftware
private void UpdateScheme()
{
if (this.InvokeRequired)
{
this.Invoke(new Action(UpdateScheme));
@ -142,6 +143,7 @@ namespace DHSoftware
}
lbName.Text = _loginName;
}
private void UpdateConfig()
{
if (ShowConfig)
@ -163,8 +165,8 @@ namespace DHSoftware
}
segmented1.Items.Remove(itemToHide);
}
}
public MainWindow()
{
InitializeComponent();
@ -179,13 +181,13 @@ namespace DHSoftware
userControlFrm.Window = this;
userControlFrm.Dock = DockStyle.Fill;
tabPage2.Controls.Add(userControlFrm);
}
/// <summary>
/// 窗体对象实例
/// </summary>
private static MainWindow _instance;
internal static MainWindow Instance
{
get
@ -195,12 +197,13 @@ namespace DHSoftware
return _instance;
}
}
SegmentedItem itemToHide;
private SegmentedItem itemToHide;
private void InitData()
{
itemToHide = segmented1.Items[4];
segmented1.Items.Remove(itemToHide);
}
public void LoadScheme()
@ -277,7 +280,6 @@ namespace DHSoftware
// cam.CameraConnect();
cam.OnHImageOutput += OnCameraHImageOutput;
}
}
}
}
@ -291,7 +293,6 @@ namespace DHSoftware
var plcBase = ConfigModel.PLCBaseList[i];
if (plcBase.PLCType == EnumPLCType.XC网口)
{
PLC.IP = plcBase.IP;
PLC.Enable = plcBase.Enable;
PLC.PLCName = plcBase.PLCName;
@ -300,7 +301,6 @@ namespace DHSoftware
PLC.PLCConnect();
}
}
}
}
@ -311,7 +311,6 @@ namespace DHSoftware
if (ConfigModel.DetectionList.Count > 0)
{
for (int i = 0; i < ConfigModel.DetectionList.Count; i++)
{
DetectionConfig detectionConfig = ConfigModel.DetectionList[i];
@ -329,7 +328,6 @@ namespace DHSoftware
}
DetectionConfigs.ForEach(detection =>
{
detection.CameraCollects.ForEach(cam =>
{
List<string> Dets = new List<string>
@ -344,14 +342,11 @@ namespace DHSoftware
{
_cameraRelatedDetectionDict[cam.CameraSourceId].Add(detection.Id);
}
}
);
});
string inferenceDevice = "CPU";
//
_visionEngine = new SimboVisionDriver();
_visionEngine.DetectionConfigs = DetectionConfigs;
@ -360,16 +355,13 @@ namespace DHSoftware
_visionEngine.Init();
CtrlVisionRunBase ctrlVisionRun = new CtrlVisionRunBase(_visionEngine);
tabImgDisplay.Controls.Add(ctrlVisionRun);
}
private void BindEventHandler()
{
btnAddProject.Click += BtnAddProject_Click;
btnDeleteProject.Click += BtnDeleteProject_Click;
btnLoadProject.Click += BtnLoadProject_Click;
}
private void BtnDeleteProject_Click(object? sender, EventArgs e)
@ -400,16 +392,12 @@ namespace DHSoftware
SchemeHelper.SetCurrentScheme(SystemModel.CurrentScheme);
//加载当前方案配置
ConfigHelper.LoadConfig();
}
else
{
sltProjects.SelectedIndex = -1; // 清空选择
AntdUI.Modal.open(this, "空方案警告!", "当前方案全部删除,需重启程序!", TType.Warn);
}
}
}
catch (Exception ex)
@ -436,7 +424,8 @@ namespace DHSoftware
ConfigHelper.LoadConfig();
AntdUI.Message.success(this, $"载入方案{SystemModel.CurrentScheme}成功!", autoClose: 3);
}
catch (Exception ex) {
catch (Exception ex)
{
AntdUI.Message.error(this, ex.Message, autoClose: 3);
}
}
@ -481,23 +470,20 @@ namespace DHSoftware
{
AntdUI.Message.error(this, ex.Message, autoClose: 3);
}
}
public List<HikVisionCamera> HKCameras { get; } = new List<HikVisionCamera>();
public List<Do3ThinkCamera> Cameras { get; } = new List<Do3ThinkCamera>();
public Dictionary<string, SimboObjectDetection> Dectection { get; } = new Dictionary<string, SimboObjectDetection>();
public XinJEPLCTcpNet PLC { get; } = XinJEPLCTcpNet.Instance;
SLDMotion sLDMotion = new SLDMotion();
private SLDMotion sLDMotion = new SLDMotion();
private void MainWindow_Load(object sender, EventArgs e)
{
}
private bool _isClosing = false; // 状态标志
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
{
if (_isClosing) return;
@ -526,17 +512,13 @@ namespace DHSoftware
CloseWindow.Instance.Close();// 关闭提示窗口
//Application.Exit();
System.Environment.Exit(0);
}
catch (Exception ex)
{
CloseWindow.Instance.Close();
System.Environment.Exit(0);
}
}
private void segmented1_SelectIndexChanged(object sender, EventArgs e)
@ -550,23 +532,29 @@ namespace DHSoftware
case 0: // "启动" (Start)
HandleStartButton();
break;
case 1: // "停止" (Stop)
HandleStopButton();
break;
case 2: // "复位" (Reset)
HandleResetButton();
break;
case 3: // "设置" (Settings)
HandleLoginButton();
break;
case 4: // "登录" (Login)
HandleSettingsButton();
break;
default:
break;
}
segmented1.SelectIndex = -1;
}
public bool CurrentMachine = false;
public volatile int ProductNum_Total = 0;
public volatile int ProductNum_OK = 0;
@ -574,16 +562,19 @@ namespace DHSoftware
public SimboVisionDriver? _visionEngine = null;
public PLCBase? _PLCConfig = null;
List<DetectionConfig> DetectionConfigs = new List<DetectionConfig>();
List<SimboStationMLEngineSet> SimboStationMLEngineList = new List<SimboStationMLEngineSet>();
Dictionary<string, HDevEngineTool> HalconToolDict = new Dictionary<string, HDevEngineTool>();
private List<DetectionConfig> DetectionConfigs = new List<DetectionConfig>();
private List<SimboStationMLEngineSet> SimboStationMLEngineList = new List<SimboStationMLEngineSet>();
private Dictionary<string, HDevEngineTool> HalconToolDict = new Dictionary<string, HDevEngineTool>();
public List<RecongnitionLabel> RecongnitionLabelList { get; set; } = new List<RecongnitionLabel>();
public DateTime startTime;
private void HandleStartButton()
{
StartProcess();
}
private static int currentRegister = 411; // 初始为 D411
private void StartProcess()
{
//计数清零
@ -591,7 +582,6 @@ namespace DHSoftware
//吹气点位归置
currentRegister = 411;
if (_PLCConfig?.Enable == true)
{
PLC.CountToZero();
@ -632,13 +622,11 @@ namespace DHSoftware
// return new ProcessResponse(false);
//}
// _diskInfoListInOrder = XKRSPLCConfig.DiskInfoList.OrderBy(u => u.DiskSequence).ToList();
// var axisNumList = _diskInfoListInOrder.Select(u => u.DiskAxisNum).ToList();
/// PrepareMLEngine();
// if (_PLCConfig?.Enable == true)
//挡料电机操作
// _PLC.FeedingMotor(_PLCConfig.CunToZeroSpeed, _PLCConfig.CunPos, _PLCConfig.CunSpeed, _PLCConfig.CunDirection);
@ -659,15 +647,18 @@ namespace DHSoftware
// }
//});
_productLists.Clear();
#region
//mOfflineImageTimer = new System.Timers.Timer();
//mOfflineImageTimer.Elapsed += OnEmitSerialPortAsync;
//mOfflineImageTimer.Interval = 1000;
//mOfflineImageTimer.Start();
#endregion
var settings = _visionEngine.DetectionConfigs.Where(u => u.IsEnabled && u.IsAddStation ).ToList();
#endregion
var settings = _visionEngine.DetectionConfigs.Where(u => u.IsEnabled && u.IsAddStation).ToList();
if (settings != null)
{
settings = settings.Where(s => s.IsEnabled).ToList();
@ -680,7 +671,6 @@ namespace DHSoftware
}
}
// _MGSCameraList = DeviceCollection
//.OfType<MGSCameraDriver>() // 直接筛选出 MGSCameraDriver 类型的元素
//.Where(camera => camera.IConfig != null && camera.IConfig.IsEnabled) // 进一步筛选 IConfig 不为 null 且 IsEnabled 为 true
@ -694,7 +684,6 @@ namespace DHSoftware
_productLists.Add(products);
}
// 转盘操作
// if (_PLC?.IIConfig?.IsEnabled == true)
@ -703,7 +692,6 @@ namespace DHSoftware
if (itemSpeed != null)
{
PLC.TurntableOpen(Convert.ToInt32(itemSpeed.Value), true);
}
Thread.Sleep(500);
@ -715,12 +703,11 @@ namespace DHSoftware
// _PLC.Vibratory(true);
//}
//InitialOEEStatistic();
// MachineState = MachineState.Running;
}
private void PrepareMLEngine()
{
//if (_visionEngine == null)
@ -733,9 +720,6 @@ namespace DHSoftware
// throw new ProcessException($"未能获取检测设备");
//}
//相机模组
//_cameraRelatedDetectionDict = new();
@ -756,7 +740,6 @@ namespace DHSoftware
// _cameraRelatedDetectionDict[cam.CameraSourceId].Add(detection.Id);
// }
// });
//});
@ -766,8 +749,6 @@ namespace DHSoftware
#if false
private void HandleStartButton2()
{
CurrentMachine = true;
//_visionEngine.Start();
@ -798,8 +779,6 @@ namespace DHSoftware
RecongnitionLabelList.Add(recongnition2);
RecongnitionLabelList.Add(recongnition3);
var det1 = new DetectionConfig("相机1", ModelType., @"D:\PROJECTS\X015\Vision\Cam1.onnx", false, "Cam1");
var det2 = new DetectionConfig("相机2", ModelType., @"D:\PROJECTS\X015\Vision\Cam2.onnx", false, "Cam2");
var det3 = new DetectionConfig("相机3", ModelType., @"D:\PROJECTS\X015\Vision\Cam3.onnx", false, "Cam3");
@ -827,7 +806,6 @@ namespace DHSoftware
float Conf = 0.5f;
det1.CameraCollects = CameraCollects;
det1.ModelconfThreshold = Conf;
det1.ModelWidth = 640;
@ -864,8 +842,6 @@ namespace DHSoftware
det4.ShowLocation.X = 4;
det4.ShowLocation.Y = 1;
det5.CameraCollects = CameraCollects5;
det5.ModelconfThreshold = Conf;
det5.ModelWidth = 640;
@ -926,8 +902,6 @@ namespace DHSoftware
camera.CameraConnect();
camera.OnHImageOutput += OnCameraHImageOutput;
HKCameras.Add(camera);
}
#else
//Do3ThinkCamera do3ThinkCamera1 = new Do3ThinkCamera();
@ -939,7 +913,6 @@ namespace DHSoftware
// Cameras.Add(do3ThinkCamera1);
for (int i = 1; i <= 8; i++)
{
Do3ThinkCamera cam = new Do3ThinkCamera();
if (i == 1)
{
@ -956,13 +929,10 @@ namespace DHSoftware
cam.OnHImageOutput += OnCameraHImageOutput;
}
#endif
DetectionConfigs.ForEach(detection =>
{
detection.CameraCollects.ForEach(cam =>
{
List<string> Dets = new List<string>
@ -977,15 +947,11 @@ namespace DHSoftware
{
_cameraRelatedDetectionDict[cam.CameraSourceId].Add(detection.Id);
}
}
);
});
string inferenceDevice = "CPU";
_visionEngine = new SimboVisionDriver();
_visionEngine.DetectionConfigs = DetectionConfigs;
@ -1016,12 +982,9 @@ namespace DHSoftware
sLDMotion.IODefinitionCollection = new List<IODefinition>();
Motion(sLDMotion.IODefinitionCollection);
sLDMotion.SnapshotSettings = new List<SnapshotSetting>();
int[] cameraPositions = { 24161, 33608, 39702, 45701 };
sLDMotion.SnapshotSettings.Add(new SnapshotSetting
{
IsEnabled = true,
@ -1040,8 +1003,6 @@ namespace DHSoftware
});
}
sLDMotion.BlowSettings = new List<BlowSetting>();
int[] BlowPositions = { 61353, 68566 };
sLDMotion.BlowSettings.Add(new BlowSetting
@ -1065,8 +1026,6 @@ namespace DHSoftware
//sna1.CameraPosition = 17000;
//sna1.StationNumber = 0;
// sLDMotion.SnapshotSettings.Add(sna1);
sLDMotion.AxisSettings.Add(axis1);
sLDMotion.Init();
@ -1114,11 +1073,11 @@ namespace DHSoftware
}
#endif
private uint PieceCount = 0;
private List<ConcurrentDictionary<uint, ProductData>> _productLists = new List<ConcurrentDictionary<uint, ProductData>>();
private int ProductListMulti = 2;
private int ProductBaseCount = 0;
private int PieceNumberToIndex(uint pn)
{
// 物料编号,取余 集合数量
@ -1126,7 +1085,9 @@ namespace DHSoftware
int ret = (int)(pn % (ProductBaseCount * ProductListMulti));
return ret;
}
DateTime _ctTime = DateTime.Now;
private DateTime _ctTime = DateTime.Now;
public async void MainMotion_NewPieces(int axisIndex, uint pieceNumber)
{
//if (MachineState != MachineState.Running && MachineState != MachineState.Warning)
@ -1134,10 +1095,8 @@ namespace DHSoftware
// return;
//}
PieceCount++;
int index = PieceNumberToIndex(pieceNumber);
// productDatas.Add(pData);
//转盘2 的物料是不是重新覆盖之前的pDta
@ -1150,14 +1109,12 @@ namespace DHSoftware
Task.Run(() =>
{
//this.BeginInvoke(new MethodInvoker(delegate () { richTextBox1.AppendText(logStr); }));
});
DateTime dtNow = DateTime.Now;
UpdateCT(null, (float)(dtNow - _ctTime).TotalSeconds);
_ctTime = dtNow;
}
public async Task UpdateCT(object objData, float ctTime)
{
await Task.Run(() =>
@ -1165,6 +1122,7 @@ namespace DHSoftware
//OnUpdateCT?.Invoke(objData, ctTime);
});
}
/// <summary>
/// 相机回调
/// </summary>
@ -1173,7 +1131,6 @@ namespace DHSoftware
/// <param name="imageSet"></param>
private void OnCameraHImageOutput(DateTime dt, CameraBase camera, Mat imageSet)
{
//if (camera.CameraName.Equals("cam1", StringComparison.OrdinalIgnoreCase))
//{
// Console.WriteLine();
@ -1230,7 +1187,6 @@ namespace DHSoftware
localImageSet.Dispose();
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText(productNumber + "提前推出" + camera.CameraName);
@ -1252,11 +1208,9 @@ namespace DHSoftware
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
{
localImageSet.Dispose();
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText(productNumber + "提前推出" + camera.CameraName);
@ -1276,33 +1230,23 @@ namespace DHSoftware
return;
}
double totalTime = 0.0;
List<ResultState> resultStates = new List<ResultState>();
List<string>? detectionDict = _cameraRelatedDetectionDict[camera.CameraName];
for (int i = 0; i < detectionDict.Count; i++)
{
string detectionId = detectionDict[i];
// 1. 预处理
using (Mat inferenceImage = localImageSet.Clone()) // 仅在此处克隆,确保推理过程中 Mat 有独立副本
{
DetectStationResult temp1=_visionEngine.RunInference(inferenceImage, detectionId);
DetectStationResult temp1 = _visionEngine.RunInference(inferenceImage, detectionId);
resultStates.Add(temp1.ResultState);
product.ResultCollection.Add(temp1);
}
}
product.InferenceOne();
@ -1311,14 +1255,12 @@ namespace DHSoftware
if (!product.InferenceFinished())
{
return;
}
ProductNum_Total++;
CalculateOEE();
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText($"统计结果成功,{productNumber} 吹气!\n");
@ -1327,20 +1269,16 @@ namespace DHSoftware
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
#region 6.
product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
? ResultState.B_NG
: ResultState.OK;
product.ProductLabelCategory = product.ProductResult.GetEnumDescription();
product.ProductLabel = product.ProductResult.GetEnumDescription();
#endregion
#region 7.
#endregion
#endregion 6.
// 出列
ProductData temp = null;
@ -1362,7 +1300,6 @@ namespace DHSoftware
$"当前队列产品数量:{tmpDic.Count}";
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText(logStr);
@ -1381,7 +1318,6 @@ namespace DHSoftware
$"当前队列产品数量:{tmpDic.Count}";
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText(logStr);
@ -1396,7 +1332,6 @@ namespace DHSoftware
{
sw.WriteLine(logStr);
}
}
catch (Exception) { }
finally
@ -1409,8 +1344,6 @@ namespace DHSoftware
// UpdateCT((float)(dtNow - _ctTime).TotalSeconds);
//_ctTime = dtNow;
// });
}
catch (Exception ex)
{
@ -1418,18 +1351,11 @@ namespace DHSoftware
product?.Dispose();
}
}
});
}
public void SetResult()
{
//// detectResult.IsPreTreatDone = detectResult.VisionImageSet.PreTreatedFlag
////2024-02-29 目标检测不能全是NG
//if (IsPreTreatNG || IsObjectDetectNG)
@ -1437,15 +1363,13 @@ namespace DHSoftware
// return;
//}
//if (IsPreTreatDone && IsMLDetectDone && IsAfterTreatDone)
//{
// ResultState = ResultState.OK;
// ResultLabel = ResultState.OK.GetEnumDescription();
//}
}
private void HandleStopButton()
{
Cameras.Clear();
@ -1455,7 +1379,9 @@ namespace DHSoftware
CurrentMachine = true;
sLDMotion.Stop();
}
public int UPH = 0;
public void CalculateOEE()
{
TimeSpan timeSpan = DateTime.Now - startTime;
@ -1466,10 +1392,8 @@ namespace DHSoftware
{
label1.Text = UPH.ToString();
}));
}
private void HandleResetButton()
{
// Add the code for the "复位" button click here
@ -1481,7 +1405,6 @@ namespace DHSoftware
// Add the code for the "设置" button click here
SettingWindow.Instance.Show();
}
private void HandleLoginButton()
@ -1493,7 +1416,6 @@ namespace DHSoftware
private void splitter1_SplitterMoved(object sender, SplitterEventArgs e)
{
}
}
}

View File

@ -1,16 +1,12 @@
using AntdUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DHSoftware.Models
{
public class DataModel
{
}
public class DefectRow:NotifyProperty
public class DefectRow : NotifyProperty
{
private bool selected = false;
public string LabelId { get; set; }

View File

@ -1,6 +1,4 @@
using System.Collections.Generic;
namespace AntdUIDemo.Models
namespace AntdUIDemo.Models
{
public class DataUtil
{
@ -220,9 +218,5 @@ namespace AntdUIDemo.Models
{ "Chat", "MessageOutlined" },
{ "Other", "SettingOutlined" }
};
}
}

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
using SqlSugar;
namespace DHSoftware.Models
{

View File

@ -1,12 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DHSoftware.Models
namespace DHSoftware.Models
{
public class Camera
{
@ -14,7 +6,4 @@ namespace DHSoftware.Models
public string Alias { get; set; }
public string ImagePath { get; set; }
}
}
}

View File

@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHSoftware.Models;
using DHSoftware.Models;
using DHSoftware.Utils;
using SqlSugar;
namespace DHSoftware.Services
{
public static class AuthService
{
public static User CurrentUser { get; private set; }

View File

@ -1,18 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AntdUI;
namespace DHSoftware.Utils
namespace DHSoftware.Utils
{
public static class AdaptiveHelper
{
#region
public static void setTag(Control cons)
{
foreach (Control con in cons.Controls)
@ -42,8 +33,6 @@ namespace DHSoftware.Utils
}
}
#endregion
#endregion
}
}

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHSoftware.Models;
using DHSoftware.Models;
using SqlSugar;
namespace DHSoftware.Utils

View File

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace DHSoftware.Utils
{

View File

@ -1,5 +1,4 @@
using Microsoft.Win32;
using System.Drawing;
namespace DHSoftware.Utils
{

View File

@ -4,25 +4,26 @@ using DH.Commons.Helper;
using DH.Commons.Models;
using DHSoftware.Utils;
using DH.Commons.Base;
namespace DHSoftware.Views
{
public partial class SettingWindow : Window
{
private UserControl currControl;
public SettingWindow()
{
InitializeComponent();
BindEventHandler();
InitData();
}
/// <summary>
/// 窗体对象实例
/// </summary>
private static SettingWindow _instance;
internal static SettingWindow Instance
{
get
@ -32,18 +33,17 @@ namespace DHSoftware.Views
return _instance;
}
}
private void BindEventHandler()
{
Resize += SettingWindow1_Resize;
btnAdd.SelectedValueChanged += btnAdd_SelectedValueChanged;
btnSave.Click += BtnSave_Click;
menu1.SelectChanged += Menu1_SelectChanged;
}
private void Menu1_SelectChanged(object sender, MenuSelectEventArgs e)
{
MenuItem clickedItem = e.Value;
if (clickedItem != null)
@ -85,7 +85,6 @@ namespace DHSoftware.Views
{
Text = $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}",
ReadOnly = false,
};
tabPage.Controls.Add(control);
tabs1.Pages.Add(tabPage);
@ -95,6 +94,7 @@ namespace DHSoftware.Views
currControl = control;
}
break;
case "工位设置":
// 检查是否已存在同名 TabPage
foreach (var tab in tabs1.Pages)
@ -124,7 +124,6 @@ namespace DHSoftware.Views
{
Text = $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}",
ReadOnly = false,
};
tabPage.Controls.Add(control1);
tabs1.Pages.Add(tabPage);
@ -165,7 +164,6 @@ namespace DHSoftware.Views
{
Text = $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}",
ReadOnly = false,
};
tabPage.Controls.Add(control);
tabs1.Pages.Add(tabPage);
@ -175,16 +173,13 @@ namespace DHSoftware.Views
currControl = control;
}
break;
}
}
}
private float x; //定义当前窗体的宽度
private float y; //定义当前窗体的高度
private void InitData()
{
btnAdd.Items.Clear();
@ -196,7 +191,6 @@ namespace DHSoftware.Views
y = Height;
AdaptiveHelper.setTag(this);
if (ConfigModel.CameraBaseList.Count > 0)
{
var workstationItem = FindMenuItem(menu1.Items, "相机设置");
@ -209,7 +203,6 @@ namespace DHSoftware.Views
newItem.Text = item.CameraName;
newItem.IconSvg = "VideoCameraOutlined";
workstationItem.Sub.Add(newItem);
}
}
}
@ -225,7 +218,6 @@ namespace DHSoftware.Views
newItem.Text = item.Name;
newItem.IconSvg = "AppstoreOutlined";
workstationItem.Sub.Add(newItem);
}
}
}
@ -242,22 +234,17 @@ namespace DHSoftware.Views
newItem.Text = item.PLCName;
newItem.IconSvg = "ControlOutlined";
workstationItem.Sub.Add(newItem);
}
}
}
}
private void BtnSave_Click(object? sender, EventArgs e)
{
ConfigHelper.SaveConfig();
AntdUI.Message.success(this, "保存成功!", autoClose: 3);
}
private void SettingWindow1_Resize(object? sender, EventArgs e)
{
var newx = Width / x;
@ -265,13 +252,6 @@ namespace DHSoftware.Views
AdaptiveHelper.setControls(newx, newy, this);
}
// 递归查找菜单项
private MenuItem FindMenuItem(MenuItemCollection items, string targetText)
{
@ -287,17 +267,12 @@ namespace DHSoftware.Views
return null;
}
bool isUpdatingTabs = false;
private bool isUpdatingTabs = false;
private void menu1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
// 转换坐标到控件内部坐标系(考虑滚动条)
Point clickPoint = new Point(e.X, e.Y + menu1.ScrollBar.Value);
@ -324,7 +299,6 @@ namespace DHSoftware.Views
{
IconSvg = "DeleteOutlined"
}
};
AntdUI.ContextMenuStrip.open(menu1, it =>
{
@ -346,6 +320,7 @@ namespace DHSoftware.Views
}
ConfigModel.CameraBaseList.RemoveAll(c => c.CameraName == clickedItem.Text);
break;
case "重命名":
// 保存原始名称用于查找
string originalName = clickedItem.Text;
@ -374,7 +349,7 @@ namespace DHSoftware.Views
return;
}
clickedItem.Text= newName;
clickedItem.Text = newName;
var camera = ConfigModel.CameraBaseList.FirstOrDefault(c =>
c.CameraName.Equals(originalName, StringComparison.OrdinalIgnoreCase));
camera.CameraName = newName;
@ -393,9 +368,9 @@ namespace DHSoftware.Views
}
break;
}
}, menulist);
break;
case "工位设置":
var menulist1 = new AntdUI.IContextMenuStripItem[]
{ new AntdUI.ContextMenuStripItem("重命名", "")
@ -406,7 +381,6 @@ namespace DHSoftware.Views
{
IconSvg = "DeleteOutlined"
}
};
AntdUI.ContextMenuStrip.open(menu1, it =>
{
@ -427,6 +401,7 @@ namespace DHSoftware.Views
}
ConfigModel.DetectionList.RemoveAll(c => c.Name == clickedItem.Text);
break;
case "重命名":
// 保存原始名称用于查找
string originalName = clickedItem.Text;
@ -488,7 +463,6 @@ namespace DHSoftware.Views
{
IconSvg = "DeleteOutlined"
}
};
AntdUI.ContextMenuStrip.open(menu1, it =>
{
@ -512,6 +486,7 @@ namespace DHSoftware.Views
ConfigModel.PLCBaseList.RemoveAll(c => c.PLCName == clickedItem.Text);
break;
case "重命名":
var form = new AddMotionControl(this, "重命名运动控制操作") { Size = new Size(300, 200) };
@ -553,23 +528,15 @@ namespace DHSoftware.Views
}
}
break;
}
}, menulist2);
break;
}
}
}
}
private MenuItem FindClickedItem(MenuItemCollection items, Point clickPoint)
{
foreach (MenuItem item in items)
@ -590,8 +557,6 @@ namespace DHSoftware.Views
return null;
}
private void btnAdd_SelectedValueChanged(object sender, ObjectNEventArgs e)
{
string selectedValue = e.Value.ToString();
@ -602,8 +567,7 @@ namespace DHSoftware.Views
if (workstationItem != null)
{
var form = new AddCameraControl(this,"新增相机操作") { Size = new Size(300, 200) };
var form = new AddCameraControl(this, "新增相机操作") { Size = new Size(300, 200) };
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "", form, TType.None)
{
BtnHeight = 0,
@ -627,14 +591,14 @@ namespace DHSoftware.Views
}
}
break;
case "工位设置":
// 查找工位设置项
var workstationItem1= FindMenuItem(menu1.Items, "工位设置");
var workstationItem1 = FindMenuItem(menu1.Items, "工位设置");
if (workstationItem1 != null)
{
var form = new AddCubicleControl(this,"新增工位操作") { Size = new Size(300, 200) };
var form = new AddCubicleControl(this, "新增工位操作") { Size = new Size(300, 200) };
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "", form, TType.None)
{
BtnHeight = 0,
@ -658,13 +622,13 @@ namespace DHSoftware.Views
}
}
break;
case "运控设置":
var workstationItem2 = FindMenuItem(menu1.Items, "运控设置");
if (workstationItem2 != null)
{
var form = new AddMotionControl(this,"新增运动控制操作") { Size = new Size(300, 200) };
var form = new AddMotionControl(this, "新增运动控制操作") { Size = new Size(300, 200) };
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "", form, TType.None)
{
BtnHeight = 0,
@ -692,4 +656,3 @@ namespace DHSoftware.Views
}
}
}