C# i=0;我有没有办法知道卡车经过读卡器时是来还是走?)你有没有办法知道卡车经过读卡器时是来还是走?) private void tmr_Tick(object sender, EventArgs e) { int maxTime =
C# i=0;我有没有办法知道卡车经过读卡器时是来还是走?)你有没有办法知道卡车经过读卡器时是来还是走?) private void tmr_Tick(object sender, EventArgs e) { int maxTime =,c#,C#,i=0;我有没有办法知道卡车经过读卡器时是来还是走?)你有没有办法知道卡车经过读卡器时是来还是走?) private void tmr_Tick(object sender, EventArgs e) { int maxTime = int.Parse(AppSettings.GetAppSetting("MaxTime")); List<string> _assets = new List<string>(); L
i=0;我有没有办法知道卡车经过读卡器时是来还是走?)你有没有办法知道卡车经过读卡器时是来还是走?)
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
//////////////////////////////
}
}
}
}
//Check if the route was correctly followed
if (currentRoute != null)
{
var gatesInOrder = 0;
for(var i=0; i<_assetReads.Length; i++)
{
if(_assetReads[i].ReadPointLocationId == currentRoute[gatesInOrder])
//gate crossed in order; increment to next gate
gatesInOrder++;
}
//if we didn't get to the end of the route, send a notification
if(gatesInOrder != currentRoute.Length)
{
///////////////////////
//Send notification
///////////////////////
}
}