public bool AddIncident(Incident incident) { try { using (ModemController mc = new ModemController()) using (IncidentTypeController itc = new IncidentTypeController()) using (AreaController ac = new AreaController()) using (SqlConnection conn = new SqlConnection(connString)) { // Query to insert incident information into database String query = "INSERT INTO Incidents(PostalCode,UnitNo,AddInfo,IncidentTypeId,AreaId,ReportName,ReportMobile,ReportDateTime,LocLat,LocLon) VALUES(@PostalCode,@UnitNo,@AddInfo,@IncidentTypeId,@AreaId,@ReportName,@ReportMobile,GETDATE(),@LocLat,@LocLon)"; using (SqlCommand cmd = new SqlCommand(query, conn)) { // Add location of where the incident has occurred GeoCoordinate location = ac.GetCoordinate(incident.PostalCode); cmd.Parameters.AddWithValue("@PostalCode", incident.PostalCode); cmd.Parameters.AddWithValue("@UnitNo", incident.UnitNo); cmd.Parameters.AddWithValue("@AddInfo", incident.AddInfo); cmd.Parameters.AddWithValue("@IncidentTypeId", incident.IncidentType.IncidentTypeId); cmd.Parameters.AddWithValue("@AreaId", ac.GetAreaOfLocation(location).AreaId); cmd.Parameters.AddWithValue("@ReportName", incident.ReportName); cmd.Parameters.AddWithValue("@ReportMobile", incident.ReportMobile); cmd.Parameters.AddWithValue("@LocLat", location.Latitude); cmd.Parameters.AddWithValue("@LocLon", location.Longitude); conn.Open(); cmd.ExecuteNonQuery(); } // Get incident type of the incident with GetIncidentType method IncidentType type = itc.GetIncidentType(incident.IncidentType.IncidentTypeId); // If incident type has an agency, form message and send sms to the agency if (type.Agency != null) { string message = "CrisisCore: " + type.Agency.AgencyId + ", " + type.IncidentTypeName + " assistance required at " + incident.PostalCode + ", " + incident.UnitNo + " (" + incident.AddInfo + ")"; return(mc.SendSms(type.Agency.AgencyContact, message)); } // Return true if there is no error return(true); } } catch (Exception ex) { // Return false if there is an error return(false); } }
public string GenerateReport() { // Header to show date and time for the report string content = "<font face=\"Myriad Pro\"><h1>Report for " + DateTime.Now + "</h1>"; using (AreaController ac = new AreaController()) using (IncidentTypeController itc = new IncidentTypeController()) { // Method to get a a list of area in Singapore from the AreaController and initialize to the list areas object //("Central", "North East", "North West", "South East" and "South West") List <Area> areas = ac.GetAllAreas(); // Loop through the list area object foreach (Area area in areas) { // Method to get a a list of incident types from the incidentTypeController and initialize to the list incidentTypes object List <IncidentType> incidentTypes = itc.GetIncidentTypesInArea(area.AreaId); // Method to get a list of recent incident types from the incidentTypeController and initialize to the list recentIncidentTypes object List <IncidentType> recentIncidentTypes = itc.GetRecentIncidentTypesInArea(area.AreaId); // Display area name and "New Incidents" content += "<h2>" + area.AreaName + "</h2>"; content += "<h3>New Incidents</h3><p>"; // Loop through the list recentIncidentTypes object foreach (IncidentType type in recentIncidentTypes) { // Display recent incident and severity content content += "<strong>" + type.IncidentTypeName + ":</strong> " + type.Severity + "<br />"; } // Display "Total Incidents" content += "</p><h3>Total Incidents</h3>"; // Loop through the list incidentTypes object foreach (IncidentType type in incidentTypes) { // Display total incident and severity content content += "<strong>" + type.IncidentTypeName + ":</strong> " + type.Severity + "<br />"; } content += "</p>"; } } content += "</font>"; return(content); }
public List <Incident> GetUnresolvedIncidents() { // Initialize a list of Incident objects List <Incident> incidents = new List <Incident>(); try { using (IncidentTypeController itc = new IncidentTypeController()) using (AreaController ac = new AreaController()) using (SqlConnection conn = new SqlConnection(connString)) { // Query the databse for all incidents that are unresolved String query = "SELECT * FROM Incidents WHERE ResolveDateTime IS NULL"; using (SqlCommand cmd = new SqlCommand(query, conn)) { conn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { // If a row is returned, create new Incident object with relevant values Incident incident = new Incident(); incident.IncidentId = Convert.ToInt32(dr["IncidentId"]); incident.IncidentType = new IncidentType(dr["IncidentTypeId"].ToString(), null, null); incident.PostalCode = dr["PostalCode"].ToString(); incident.ReportDateTime = Convert.ToDateTime(dr["ReportDateTime"]); incident.ReportMobile = dr["ReportMobile"].ToString(); incident.ReportName = dr["ReportName"].ToString(); incident.UnitNo = dr["UnitNo"].ToString(); incident.AddInfo = dr["AddInfo"].ToString(); incident.Area = new Area(dr["AreaId"].ToString(), null, null); incident.Location = new GeoCoordinate(Convert.ToDouble(dr["LocLat"]), Convert.ToDouble(dr["LocLon"])); // Add Incident object into the list of incidents incidents.Add(incident); } } } } } catch (Exception ex) { } // Return the list of Incident objects return(incidents); }
public List <IncidentType> GetIncidentTypesInArea(string areaId) { // Initialize a list of IncidentType objects List <IncidentType> incidentTypes = new List <IncidentType>(); try { using (AreaController ac = new AreaController()) using (SqlConnection conn = new SqlConnection(connString)) { // Query the database for all incident types with matching area id String query = "SELECT IncidentTypes.IncidentTypeId, COUNT(Incidents.IncidentId) AS IncidentCount FROM IncidentTypes LEFT JOIN Incidents ON IncidentTypes.IncidentTypeId = Incidents.IncidentTypeId AND Incidents.AreaId=@AreaId AND Incidents.ResolveDateTime IS NULL GROUP BY IncidentTypes.IncidentTypeId"; using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.AddWithValue("@AreaId", areaId); conn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { // If a row is returned, create new IncidentType object with relevant values IncidentType incidentType = GetIncidentType(dr["IncidentTypeId"].ToString()); incidentType.Severity = Convert.ToInt32(dr["IncidentCount"]); // Add IncidentType object into the list of incident types incidentTypes.Add(incidentType); } } } } } catch (Exception ex) { } using (NeaController nc = new NeaController()) // Add haze incident type in the particular area into the list of incident types incidentTypes.Add(nc.GetPsiInArea(areaId)); // Return the list of IncidentType objects return(incidentTypes); }