我正在开发一个 C# Winforms 应用程序,我需要确定卡车是否采用指定的路线,并以正确的顺序通过这些点。有效路线的示例如下:
ROUTE 1
入口门 1
秤门入口侧
秤门出口侧
出口门 1
ROUTE 2
入口 2
栅门入口侧
栅门出口侧
出口 2
两条路线的比例门相同,但入口和出口是我需要担心的。如果一辆卡车从 1 号门进入并从 1 号门离开,那么所走的路线是正确的。但是,如果卡车进入 2 号门并通过 1 号门离开,那么我需要发送通知。
每个门都有配置为读取点的硬件。当卡车经过读取点时,会在数据库中创建带有时间戳的记录。我设置了一个计时器,以便在指定的时间间隔内检索有效卡车 ID 的列表。然后,它检索每辆卡车在指定时间段内经过的读取点,并将这些读取点也存储在列表中。我不确定如何将“正确路线”列表与卡车通过的读取点列表进行比较。现在我的出发点是每辆卡车每天只开一次旅行,并且在我得到这个覆盖后会调整额外的旅行。
这是我的计时器代码
private void tmr_Tick(object sender, EventArgs e)
{
int maxTime = int.Parse(AppSettings.GetAppSetting("MaxTime"));
List<string> _assets = new List<string>();
List<ReadPoint> _assetReads = new List<ReadPoint>();
//Get the list of assets to process
DataSet ds = du.ExecuteTextCommand("SELECT DISTINCT AssetId FROM " +
"(SELECT a.TagId, a.AssetId, a.Description, rp.Comments, DateScanned " +
"FROM AssetsReads ar JOIN Assets a on ar.AssetTagID = a.AssetTagID " +
"JOIN ReadPointLocations rp on " +
"ar.ReadPointLocationsID = rp.ReadPointLocationsID) AS AssetResult " +
"ORDER BY AssetId");
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
_assets.Add(dr["AssetId"].ToString());
}
}
//Loop through and process the assets
foreach (string asset in _assets)
{
ds = du.ExecuteTextCommand("SELECT a.TagId, a.AssetId, a.Description, " +
"rp.ReadPointLocationId, rp.Comments, DateScanned " +
"FROM AssetsReads ar JOIN Assets a on ar.AssetTagID = a.AssetTagID " +
"JOIN ReadPointLocations rp on " +
"ar.ReadPointLocationsID = rp.ReadPointLocationsID " +
"WHERE a.AssetID = '" + asset + "' ORDER BY DateScanned");
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
_assetReads.Clear();
foreach (DataRow dr in ds.Tables[0].Rows)
{
ReadPoint ar = new ReadPoint();
ar.ReadPointLocationId = int.Parse(dr["ReadPointLocationId"].ToString());
ar.ReadpointName = dr["Comments"].ToString();
ar.DateScanned = DateTime.Parse(dr["DateScanned"].ToString());
_assetReads.Add(ar);
}
//Check to see if the asset has been seen in the last (MaxTime) minutes
if (DateTime.Parse(_assetReads[0].DateScanned.ToString()) < DateTime.Now)
{
///////////////////////
//Send notification
///////////////////////
continue;
}
//Determine the correct route to follow
Route currentRoute = null;
foreach (Route rt in _routes)
{
foreach (ReadPoint rp in rt.ReadPoints)
{
if (_assetReads[0].ReadPointLocationId == rp.ReadPointLocationId)
{
currentRoute = rt;
break;
}
}
if (currentRoute != null)
break;
}
//Check if the route was correctly followed
if (currentRoute != null)
{
//////////////////////////////
//This is where I'm stuck
//////////////////////////////
}
}
}
}