479 lines
14 KiB
C#
479 lines
14 KiB
C#
using BaseFunction;
|
||
using DAL;
|
||
using System;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Windows.Forms;
|
||
using UserControlClass;
|
||
|
||
namespace NSAnalysis
|
||
{
|
||
public partial class FEH3RightCarData : Telerik.WinControls.UI.ShapedForm
|
||
{
|
||
#region 全局变量
|
||
|
||
private TMeasureMSSQLDAL tmdal = new TMeasureMSSQLDAL();
|
||
private DataTable dtVINData = new DataTable();
|
||
private string strLastVIN = "";
|
||
private CenterControl gCC = null;
|
||
private BackgroundWorker m_bgwRefreshCar = new BackgroundWorker();
|
||
|
||
#endregion 全局变量
|
||
|
||
public FEH3RightCarData(CenterControl cc)
|
||
{
|
||
InitializeComponent();
|
||
gCC = cc;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 指定屏幕显示
|
||
/// </summary>
|
||
public void SpecifyScreenDisplay1()
|
||
{
|
||
try
|
||
{
|
||
Screen[] screens = Screen.AllScreens;
|
||
// 指定显示在第二个显示器
|
||
Screen secondScreen = screens[1]; //1
|
||
|
||
// 设置窗体位置和大小
|
||
this.StartPosition = FormStartPosition.Manual;
|
||
this.Left = secondScreen.Bounds.Left;
|
||
this.Top = secondScreen.Bounds.Top;
|
||
this.Width = secondScreen.Bounds.Width;
|
||
this.Height = secondScreen.Bounds.Height;
|
||
this.Show();
|
||
}
|
||
catch { }
|
||
}
|
||
|
||
#region 初始化控件
|
||
|
||
private void InitNextSenseControl()
|
||
{
|
||
string strNSName = "";
|
||
UCVWNextSense ucns = null;
|
||
for (int i = 1; i <= 25; i++)
|
||
{
|
||
strNSName = "";//L0" + i.ToString();
|
||
if (i <= 9)
|
||
strNSName = "R0" + i.ToString();
|
||
else
|
||
{
|
||
strNSName = "R" + i.ToString();
|
||
}
|
||
ucns = ((UCVWNextSense)MyBase.GetChildControl(this, strNSName));
|
||
if (ucns != null)
|
||
{
|
||
ucns.tlpBackColor = Color.White;
|
||
ucns.tlpFBackColor = Color.White;
|
||
ucns.tlpGBackColor = Color.White;
|
||
ucns.labFVal = "";
|
||
ucns.labFLowerUpper = "";
|
||
ucns.labGVal = "";
|
||
ucns.labGLowerUpper = "";
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion 初始化控件
|
||
|
||
private void FEH3RightCarData_Load(object sender, EventArgs e)
|
||
{
|
||
MyBase.TraceWriteLine("[FEH3RightCarData] 窗体开始加载");
|
||
//InitNextSenseOneItemControl();
|
||
InitNextSenseControl();
|
||
labVIN.Text = "";
|
||
tmrRefreshData.Interval = 1100;
|
||
//tmrRefreshData.Start();
|
||
m_bgwRefreshCar.WorkerSupportsCancellation = true;
|
||
m_bgwRefreshCar.DoWork += new DoWorkEventHandler(m_bgwRefreshCar_DoWork);
|
||
m_bgwRefreshCar.RunWorkerAsync();
|
||
SpecifyScreenDisplay1();
|
||
MyBase.TraceWriteLine("[FEH3RightCarData] 窗体加载完成,后台刷新线程已启动");
|
||
}
|
||
|
||
private void m_bgwRefreshCar_DoWork(object sender, DoWorkEventArgs e)
|
||
{
|
||
while (!m_bgwRefreshCar.CancellationPending)
|
||
{
|
||
try
|
||
{
|
||
string strVIN = tmdal.SelectMaintenanceStation7VIN();
|
||
RefreshMonitor.LogRefreshActivity("FEH3RightCarData", strVIN, true);
|
||
RefreshMonitor.LogDatabaseQuery("FEH3RightCarData", "SelectMaintenanceStation7VIN", strVIN);
|
||
|
||
if (strLastVIN != strVIN)
|
||
{
|
||
MyBase.TraceWriteLine($"[FEH3RightCarData] VIN码变更: {strLastVIN} -> {strVIN}");
|
||
|
||
if (strVIN.ToLower().Contains("empty"))
|
||
{
|
||
Invoke((MethodInvoker)(() =>
|
||
{
|
||
labVIN.Text = "VIN码为空";
|
||
}));
|
||
InitNextSenseControl();
|
||
RefreshMonitor.LogUIUpdate("FEH3RightCarData", "初始化控件(VIN为空)", 25);
|
||
MyBase.TraceWriteLine("[FEH3RightCarData] VIN码为空,初始化控件");
|
||
}
|
||
else
|
||
{
|
||
if (strVIN.Length == 17)
|
||
{
|
||
string strSubVIN = strVIN;//.Substring(0, strVIN.Length - 2);
|
||
dtVINData.Clear();
|
||
Invoke((MethodInvoker)(() =>
|
||
{
|
||
labVIN.Text = strSubVIN;
|
||
}));
|
||
|
||
string strCarType = tmdal.SelectCarTypeByVIN(strSubVIN);
|
||
RefreshMonitor.LogDatabaseQuery("FEH3RightCarData", "SelectCarTypeByVIN", strCarType);
|
||
//记录到日志
|
||
MyBase.TraceWriteLine($"[FEH3RightCarData] 查询到车型: {strCarType} (VIN长度17)");
|
||
|
||
if (strCarType.ToUpper().Contains("EH3"))
|
||
{
|
||
MyBase.TraceWriteLine("Right EH3 UI Refresh m_bgwRefreshCar_DoWork (strVIN.Length==17):strLastVIN:" + strLastVIN + " ;VIN: " + strSubVIN);
|
||
SpecifyScreenDisplay1();
|
||
|
||
dtVINData = tmdal.SelectTMeasureDataByCarIDAndMPN(strSubVIN, "R");
|
||
RefreshMonitor.LogDatabaseQuery("FEH3RightCarData", "SelectTMeasureDataByCarIDAndMPN", "查询测量数据", dtVINData.Rows.Count);
|
||
MyBase.TraceWriteLine($"[FEH3RightCarData] 获取测量数据: {dtVINData.Rows.Count} 行");
|
||
|
||
if (dtVINData.Rows.Count > 0)
|
||
{
|
||
refreshCarUIData(dtVINData);
|
||
analysisTitleColor();
|
||
RefreshMonitor.LogUIUpdate("FEH3RightCarData", "刷新测量数据", dtVINData.Rows.Count);
|
||
MyBase.TraceWriteLine($"[FEH3RightCarData] UI数据刷新完成,更新了 {dtVINData.Rows.Count} 个测量点");
|
||
}
|
||
else
|
||
{
|
||
InitNextSenseControl();
|
||
RefreshMonitor.LogUIUpdate("FEH3RightCarData", "初始化控件(无测量数据)", 25);
|
||
MyBase.TraceWriteLine("[FEH3RightCarData] 无测量数据,初始化控件");
|
||
}
|
||
gCC.ShowCarMeasureDataByCarType(1);
|
||
}
|
||
else
|
||
{
|
||
MyBase.TraceWriteLine($"[FEH3RightCarData] 车型不匹配EH3: {strCarType}");
|
||
}
|
||
}
|
||
if (strVIN.Length == 21)
|
||
{
|
||
string strSubVIN = strVIN.Substring(0, 17);
|
||
dtVINData.Clear();
|
||
Invoke((MethodInvoker)(() =>
|
||
{
|
||
labVIN.Text = strSubVIN;
|
||
}));
|
||
string strCarType = strVIN.Substring(18, 3);
|
||
RefreshMonitor.LogDatabaseQuery("FEH3RightCarData", "ExtractCarTypeFromVIN", strCarType);
|
||
MyBase.TraceWriteLine($"[FEH3RightCarData] 从VIN提取车型: {strCarType} (VIN长度21)");
|
||
|
||
if (strCarType.ToUpper().Contains("EH3"))
|
||
{
|
||
MyBase.TraceWriteLine("Right EH3 UI Refresh m_bgwRefreshCar_DoWork (strVIN.Length==21):strLastVIN:" + strLastVIN + " ;VIN: " + strSubVIN);
|
||
SpecifyScreenDisplay1();
|
||
|
||
dtVINData = tmdal.SelectTMeasureDataByCarIDAndMPN(strSubVIN, "R");
|
||
RefreshMonitor.LogDatabaseQuery("FEH3RightCarData", "SelectTMeasureDataByCarIDAndMPN", "查询测量数据", dtVINData.Rows.Count);
|
||
MyBase.TraceWriteLine($"[FEH3RightCarData] 获取测量数据: {dtVINData.Rows.Count} 行");
|
||
|
||
if (dtVINData.Rows.Count > 0)
|
||
{
|
||
refreshCarUIData(dtVINData);
|
||
analysisTitleColor();
|
||
RefreshMonitor.LogUIUpdate("FEH3RightCarData", "刷新测量数据", dtVINData.Rows.Count);
|
||
MyBase.TraceWriteLine($"[FEH3RightCarData] UI数据刷新完成,更新了 {dtVINData.Rows.Count} 个测量点");
|
||
}
|
||
else
|
||
{
|
||
InitNextSenseControl();
|
||
RefreshMonitor.LogUIUpdate("FEH3RightCarData", "初始化控件(无测量数据)", 25);
|
||
MyBase.TraceWriteLine("[FEH3RightCarData] 无测量数据,初始化控件");
|
||
}
|
||
gCC.ShowCarMeasureDataByCarType(1);
|
||
}
|
||
else
|
||
{
|
||
MyBase.TraceWriteLine($"[FEH3RightCarData] 车型不匹配EH3: {strCarType}");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
strLastVIN = strVIN;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
RefreshMonitor.LogRefreshActivity("FEH3RightCarData", "ERROR", false);
|
||
MyBase.TraceWriteLine("Right EH3 UI Refresh m_bgwRefreshCar_DoWork Error:" + ex.Message);
|
||
// 异常后等待更长时间再重试
|
||
System.Threading.Thread.Sleep(5000);
|
||
}
|
||
|
||
// 添加延时,避免CPU占用过高,同时检查取消请求
|
||
for (int i = 0; i < 11; i++) // 总共1100ms延时,分成11次检查
|
||
{
|
||
if (m_bgwRefreshCar.CancellationPending)
|
||
break;
|
||
System.Threading.Thread.Sleep(100);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnRefresh_Click(object sender, EventArgs e)
|
||
{
|
||
SpecifyScreenDisplay1();
|
||
string strVIN = tmdal.SelectMaintenanceStation7VIN();
|
||
if (strVIN.ToLower().Contains("empty"))
|
||
{
|
||
labVIN.Text = "VIN码为空";
|
||
InitNextSenseControl();
|
||
}
|
||
else
|
||
{
|
||
if (strVIN.Length == 17)
|
||
{
|
||
string strSubVIN = strVIN;// strVIN.Substring(0, strVIN.Length - 2);
|
||
dtVINData.Clear();
|
||
labVIN.Text = strSubVIN;
|
||
string strCarType = tmdal.SelectCarTypeByVIN(strSubVIN);
|
||
|
||
if (strCarType.ToUpper().Contains("EH3"))
|
||
{
|
||
MyBase.TraceWriteLine("Right EH3 UI Refresh Button (strVIN.Length==17):CarType:" + strCarType + " ;VIN: " + strSubVIN);
|
||
dtVINData = tmdal.SelectTMeasureDataByCarIDAndMPN(strSubVIN, "R");
|
||
if (dtVINData.Rows.Count > 0)
|
||
{
|
||
refreshCarUIData(dtVINData);
|
||
analysisTitleColor();
|
||
}
|
||
else
|
||
{
|
||
InitNextSenseControl();
|
||
}
|
||
}
|
||
}
|
||
if (strVIN.Length == 21)
|
||
{
|
||
string strSubVIN = strVIN.Substring(0, strVIN.Length - 4);
|
||
dtVINData.Clear();
|
||
labVIN.Text = strSubVIN;
|
||
string strCarType = strVIN.Substring(strVIN.Length - 3, 3);
|
||
|
||
if (strCarType.ToUpper().Contains("EH3"))
|
||
{
|
||
MyBase.TraceWriteLine("Right EH3 UI Refresh Button (strVIN.Length==21):CarType:" + strCarType + " ;VIN: " + strSubVIN);
|
||
dtVINData = tmdal.SelectTMeasureDataByCarIDAndMPN(strSubVIN, "R");
|
||
if (dtVINData.Rows.Count > 0)
|
||
{
|
||
refreshCarUIData(dtVINData);
|
||
analysisTitleColor();
|
||
}
|
||
else
|
||
{
|
||
InitNextSenseControl();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void tmrRefreshData_Tick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
tmrRefreshData.Stop();
|
||
string strVIN = tmdal.SelectMaintenanceStation7VIN();
|
||
if (strLastVIN != strVIN)
|
||
{
|
||
if (strVIN.ToLower().Contains("empty"))
|
||
{
|
||
labVIN.Text = "VIN码为空";
|
||
//InitNextSenseOneItemControl();
|
||
InitNextSenseControl();
|
||
}
|
||
else
|
||
{
|
||
if (strVIN.Length == 17)
|
||
{
|
||
string strSubVIN = strVIN;//.Substring(0, strVIN.Length - 2);
|
||
dtVINData.Clear();
|
||
labVIN.Text = strSubVIN;
|
||
string strCarType = tmdal.SelectCarTypeByVIN(strSubVIN);
|
||
|
||
if (strCarType.ToUpper().Contains("EH3"))
|
||
{
|
||
MyBase.TraceWriteLine("Right EH3 UI Refresh tmrRefreshData (strVIN.Length==17):strLastVIN:" + strLastVIN + " ;VIN: " + strSubVIN);
|
||
SpecifyScreenDisplay1();
|
||
dtVINData = tmdal.SelectTMeasureDataByCarIDAndMPN(strSubVIN, "R");
|
||
if (dtVINData.Rows.Count > 0)
|
||
{
|
||
refreshCarUIData(dtVINData);
|
||
analysisTitleColor();
|
||
}
|
||
else
|
||
{
|
||
InitNextSenseControl();
|
||
}
|
||
gCC.ShowCarMeasureDataByCarType(1);
|
||
}
|
||
}
|
||
if (strVIN.Length == 21)
|
||
{
|
||
string strSubVIN = strVIN.Substring(0, 17);
|
||
dtVINData.Clear();
|
||
labVIN.Text = strSubVIN;
|
||
string strCarType = strVIN.Substring(18, 3);
|
||
|
||
if (strCarType.ToUpper().Contains("EH3"))
|
||
{
|
||
MyBase.TraceWriteLine("Right EH3 UI Refresh tmrRefreshData (strVIN.Length==21):strLastVIN:" + strLastVIN + " ;VIN: " + strSubVIN);
|
||
SpecifyScreenDisplay1();
|
||
dtVINData = tmdal.SelectTMeasureDataByCarIDAndMPN(strSubVIN, "R");
|
||
if (dtVINData.Rows.Count > 0)
|
||
{
|
||
refreshCarUIData(dtVINData);
|
||
analysisTitleColor();
|
||
}
|
||
else
|
||
{
|
||
InitNextSenseControl();
|
||
}
|
||
gCC.ShowCarMeasureDataByCarType(1);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
strLastVIN = strVIN;
|
||
tmrRefreshData.Start();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MyBase.TraceWriteLine("Left EHY UI Refresh tmrRefreshData Error:" + ex.Message);
|
||
}
|
||
}
|
||
|
||
private Color analysisColorbyStatus(string strStatus)
|
||
{
|
||
Color colStatus = new Color();
|
||
switch (strStatus.ToLower())
|
||
{
|
||
case "best":
|
||
colStatus = Color.Lime;
|
||
break;
|
||
|
||
case "good":
|
||
colStatus = Color.Lime;
|
||
break;
|
||
|
||
case "ng1":
|
||
colStatus = Color.Yellow;
|
||
break;
|
||
|
||
case "ng2":
|
||
colStatus = Color.Red;
|
||
break;
|
||
|
||
default:
|
||
colStatus = Color.LightGray;
|
||
break;
|
||
}
|
||
return colStatus;
|
||
}
|
||
|
||
private void analysisTitleColor()
|
||
{
|
||
string strNSName = "";
|
||
UCVWNextSense ucns = null;
|
||
for (int i = 1; i <= 25; i++)
|
||
{
|
||
if (i <= 9)
|
||
strNSName = "R0" + i.ToString();
|
||
else
|
||
{
|
||
strNSName = "R" + i.ToString();
|
||
}
|
||
ucns = ((UCVWNextSense)MyBase.GetChildControl(this, strNSName));
|
||
Invoke((MethodInvoker)(() =>
|
||
{
|
||
if (ucns != null)
|
||
{
|
||
if (ucns.tlpFBackColor == Color.Red || ucns.tlpGBackColor == Color.Red)
|
||
{
|
||
ucns.tlpBackColor = Color.Red;
|
||
}
|
||
else if (ucns.tlpFBackColor == Color.LightGray && ucns.tlpGBackColor == Color.LightGray)
|
||
{
|
||
ucns.tlpBackColor = Color.LightGray;
|
||
}
|
||
else if (ucns.tlpFBackColor == Color.Yellow && ucns.tlpGBackColor == Color.Yellow)
|
||
{
|
||
ucns.tlpBackColor = Color.Yellow;
|
||
}
|
||
else
|
||
{
|
||
ucns.tlpBackColor = Color.Lime;
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
|
||
private void refreshCarUIData(DataTable dtData)
|
||
{
|
||
string strNSName = "";
|
||
string strFGName = "";
|
||
UCVWNextSense ucns = null;
|
||
for (int i = 0; i < dtData.Rows.Count; i++)
|
||
{
|
||
strNSName = dtData.Rows[i]["MeasPointName"].ToString().Replace("-", "");
|
||
strFGName = dtData.Rows[i]["DimensionName"].ToString();
|
||
ucns = ((UCVWNextSense)MyBase.GetChildControl(this, strNSName));
|
||
Invoke((MethodInvoker)(() =>
|
||
{
|
||
if (ucns != null)
|
||
{
|
||
if (strFGName == "F")
|
||
{
|
||
ucns.labFVal = dtData.Rows[i]["MeasureValue"].ToString();
|
||
ucns.labFLowerUpper = dtData.Rows[i]["LowerTolVal"].ToString() + "/" + dtData.Rows[i]["UpperTolVal"].ToString();
|
||
ucns.tlpFBackColor = analysisColorbyStatus(dtData.Rows[i]["MeasureItemResult"].ToString());
|
||
}
|
||
else
|
||
{
|
||
ucns.labGVal = dtData.Rows[i]["MeasureValue"].ToString();
|
||
ucns.labGLowerUpper = dtData.Rows[i]["LowerTolVal"].ToString() + "/" + dtData.Rows[i]["UpperTolVal"].ToString();
|
||
ucns.tlpGBackColor = analysisColorbyStatus(dtData.Rows[i]["MeasureItemResult"].ToString());
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
|
||
private void FEH3RightCarData_FormClosing(object sender, FormClosingEventArgs e)
|
||
{
|
||
// 停止后台工作线程
|
||
if (m_bgwRefreshCar.IsBusy)
|
||
{
|
||
m_bgwRefreshCar.CancelAsync();
|
||
// 等待线程结束,最多等待3秒
|
||
int waitCount = 0;
|
||
while (m_bgwRefreshCar.IsBusy && waitCount < 30)
|
||
{
|
||
System.Threading.Thread.Sleep(100);
|
||
waitCount++;
|
||
}
|
||
}
|
||
|
||
e.Cancel = true;
|
||
this.Hide();
|
||
}
|
||
}
|
||
} |