public DataTable GetDataforCache() { Console.WriteLine("Obtaining vehicle data for cache..."); if (!Database.IsAccessible()) { return((DataTable)null); } DataTable dataTable1 = new DataTable(); CVehicleInfo cvehicleInfo = new CVehicleInfo(); DataTable dataTable2 = new DataTable(); try { SqlConnection databaseConnection = Database.DatabaseConnection; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = databaseConnection; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandTimeout = 0; sqlCommand.CommandText = "selAllCarDetailsFromDateAndOnlyDisplayedForCache"; SqlParameter sqlParameter = new SqlParameter(); sqlParameter.ParameterName = "@DisplayTime"; sqlParameter.SqlDbType = SqlDbType.DateTime; sqlParameter.Value = (object)DateTime.Now; sqlParameter.Direction = ParameterDirection.Input; sqlCommand.Parameters.Add(sqlParameter); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(); sqlDataAdapter.SelectCommand = sqlCommand; if (databaseConnection.State != ConnectionState.Open) { databaseConnection.Open(); } sqlDataAdapter.Fill(dataTable2); databaseConnection.Close(); } catch (SqlException ex) { if (ex.Message.Contains("The server was not found or was not accessible.")) { Log.Write("The server was not found or was not accessible."); return((DataTable)null); } Log.Write((Exception)ex); } catch (Exception ex) { Log.Write(ex); } if (dataTable2 != null) { Log.Write("...returning {0} rows of Vehicle Data", new object[1] { (object)dataTable2.Rows.Count }); Console.WriteLine("...returning {0} rows of Vehicle Data", (object)dataTable2.Rows.Count); } return(dataTable2); }
internal static void DrawRegistrationMark(PictureBox pictureBox, CVehicleInfo carDataItem) { if (!Settings.Default.PaintVehicleRegistrationMarks) { return; } string vrm = carDataItem.VRM; Utilites.WriteToPictureBox(pictureBox, vrm); }
public List <CVehicleInfo> GetMatchingVRM(string partialPlate) { List <CVehicleInfo> cvehicleInfoList = new List <CVehicleInfo>(); if (!Database.IsAccessible()) { return(cvehicleInfoList); } CVehicleInfo cvehicleInfo = new CVehicleInfo(); try { SqlConnection databaseConnection = Database.DatabaseConnection; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = databaseConnection; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandTimeout = 0; sqlCommand.CommandText = "selAllCarDetailsPartVRM"; SqlParameter sqlParameter = new SqlParameter(); sqlParameter.ParameterName = "@VRM"; sqlParameter.SqlDbType = SqlDbType.VarChar; sqlParameter.Value = (object)partialPlate; sqlParameter.Direction = ParameterDirection.Input; sqlCommand.Parameters.Add(sqlParameter); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(); DataTable dataTable = new DataTable(); sqlDataAdapter.SelectCommand = sqlCommand; databaseConnection.Open(); sqlDataAdapter.Fill(dataTable); databaseConnection.Close(); for (int index = 0; index < dataTable.Rows.Count; ++index) { cvehicleInfoList.Add(new CVehicleInfo() { CarDataId = int.Parse(dataTable.Rows[index]["CarDataId"].ToString()), overviewImageLocation = dataTable.Rows[index]["OverviewImage"].ToString(), plateImageLocation = dataTable.Rows[index]["PlateImage"].ToString(), VRM = dataTable.Rows[index]["VRM"].ToString(), inwardTime = dataTable.Rows[index]["EventDateTime"].ToString() }); } } catch (Exception ex) { Log.Write(ex); } return(cvehicleInfoList); }
public List <CVehicleInfo> GetVehicleInfoListFromXmlDataTable( string timeparameter, string Direction) { List <CVehicleInfo> cvehicleInfoList = new List <CVehicleInfo>(); CVehicleInfo cvehicleInfo = new CVehicleInfo(); try { lock (CCacheData._GetVehicleInfoListFromXmlDataTableLocker) { DataTable dataTable = this.FillVehicleDataTableFromXML(); if (dataTable == null) { return(cvehicleInfoList); } switch (Direction) { case "HISTORY": for (int index = 0; index < dataTable.Rows.Count; ++index) { if (DateTime.Parse(dataTable.Rows[index]["EventDateTime"].ToString()) > DateTime.Parse(timeparameter)) { DataRow row = dataTable.Rows[index]; dataTable.Rows.Remove(row); } } dataTable.DefaultView.Sort = "EventDateTime DESC"; break; case "FUTURE": for (int index = 0; index < dataTable.Rows.Count; ++index) { if (DateTime.Parse(dataTable.Rows[index]["EventDateTime"].ToString()) < DateTime.Parse(timeparameter)) { DataRow row = dataTable.Rows[index]; dataTable.Rows.Remove(row); } } dataTable.DefaultView.Sort = "EventDateTime ASC"; break; } if (dataTable.Rows.Count == 0) { return(cvehicleInfoList); } int num = 16; if (dataTable.Rows.Count < 16) { num = dataTable.Rows.Count; } for (int index = 0; index < num; ++index) { cvehicleInfoList.Add(new CVehicleInfo() { CarDataId = int.Parse(dataTable.Rows[index]["CarDataID"].ToString()), overviewImageLocation = dataTable.Rows[index]["OverviewImage"].ToString(), plateImageLocation = dataTable.Rows[index]["PlateImage"].ToString(), VRM = dataTable.Rows[index]["VRM"].ToString(), inwardTime = dataTable.Rows[index]["EventDateTime"].ToString() }); } } } catch (Exception ex) { Log.Write(ex); } return(cvehicleInfoList); }
public List <CVehicleInfo> GetTopSixteen(string timeparameter, string direction) { List <CVehicleInfo> cvehicleInfoList = new List <CVehicleInfo>(); if (!Database.IsAccessible()) { return(cvehicleInfoList); } CVehicleInfo cvehicleInfo = new CVehicleInfo(); try { SqlConnection databaseConnection = Database.DatabaseConnection; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = databaseConnection; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandTimeout = 0; sqlCommand.CommandText = "selAllCarDetailsFromDateAndOnlyDisplayed"; SqlParameter sqlParameter1 = new SqlParameter(); sqlParameter1.ParameterName = "@DisplayTime"; sqlParameter1.SqlDbType = SqlDbType.DateTime; sqlParameter1.Value = (object)timeparameter; sqlParameter1.Direction = ParameterDirection.Input; sqlCommand.Parameters.Add(sqlParameter1); SqlParameter sqlParameter2 = new SqlParameter(); sqlParameter2.ParameterName = "@Direction"; sqlParameter2.SqlDbType = SqlDbType.VarChar; sqlParameter2.Value = (object)direction; sqlParameter2.Direction = ParameterDirection.Input; sqlCommand.Parameters.Add(sqlParameter2); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(); DataTable dataTable = new DataTable(); sqlDataAdapter.SelectCommand = sqlCommand; databaseConnection.Open(); sqlDataAdapter.Fill(dataTable); databaseConnection.Close(); for (int index = 0; index < dataTable.Rows.Count; ++index) { cvehicleInfoList.Add(new CVehicleInfo() { CarDataId = int.Parse(dataTable.Rows[index]["CarDataId"].ToString()), overviewImageLocation = dataTable.Rows[index]["OverviewImage"].ToString(), plateImageLocation = dataTable.Rows[index]["PlateImage"].ToString(), VRM = dataTable.Rows[index]["VRM"].ToString(), inwardTime = dataTable.Rows[index]["EventDateTime"].ToString() }); } } catch (SqlException ex) { if (ex.Message.Contains("The server was not found or was not accessible.")) { return(cvehicleInfoList); } Log.Write((Exception)ex); } catch (Exception ex) { Log.Write(ex); } return(cvehicleInfoList); }