Example #1
0
 /// <summary>
 /// Constructor - used when an IncidentInfo object HAS been created
 /// </summary>
 /// <param name="incidentNumber">The unique incident number of the incident</param>
 /// <param name="database">The connection to the database that provides functionality for retrieving/updating data</param>
 /// <param name="info">Container object that stores information about the incident</param>
 public Incident(int incidentNumber, IncidentInfo info)
 {
     IncidentNumber = incidentNumber;
     this.database  = Tools.IncidentDB;
     this.info      = info;
     this.view      = new IncidentDataView(incidentNumber, DateTime, Type.Name, Address.Building, Address.Number, Address.Street, Address.Town, Address.Postcode, Operator, StopTime, IncidentClosedTime);
 }
Example #2
0
        /// <summary>
        /// Records a new incident in the database.
        /// </summary>
        /// <param name="user">The logged in user that has created the incident</param>
        /// <param name="caller">The original caller for the incident</param>
        /// <param name="exchange">The exchange that passed the details of the caller</param>
        /// <param name="incidentType">The incident type of the emergency</param>
        /// <param name="address">The address of the emergency</param>
        /// <param name="details">Any other relevant details</param>
        /// <param name="infoId">The database ID of any relevant info.</param>
        /// <returns>An object representing the newly created incident.</returns>
        public Incident CreateIncident(int user, string caller, string exchange, IncidentType incidentType, Address address, string details, int infoId)
        {
            DateTime dateTime = DateTime.Now;

            ////insert the new incident
            string statement = "INSERT INTO Incident" + Environment.NewLine +
                               "VALUES (NULL, @userID, @building, @number, @street, @town, @postcode, @county, @longitude, @latitude, NULL, @type, @dateTime, @caller, @exchange, @details, NULL, NULL, NULL, NULL);";

            MySqlCommand incidentInsertCommand = new MySqlCommand(statement, connection);

            incidentInsertCommand.Parameters.AddWithValue("@userID", user);
            incidentInsertCommand.Parameters.AddWithValue("@building", address.Building);
            incidentInsertCommand.Parameters.AddWithValue("@number", address.Number);
            incidentInsertCommand.Parameters.AddWithValue("@street", address.Street);
            incidentInsertCommand.Parameters.AddWithValue("@town", address.Town);
            incidentInsertCommand.Parameters.AddWithValue("@postcode", address.Postcode);
            incidentInsertCommand.Parameters.AddWithValue("@county", address.County);
            incidentInsertCommand.Parameters.AddWithValue("@longitude", address.Longitude);
            incidentInsertCommand.Parameters.AddWithValue("@latitude", address.Latitude);
            incidentInsertCommand.Parameters.AddWithValue("@infoId", infoId);
            incidentInsertCommand.Parameters.AddWithValue("@type", incidentType.Name);
            incidentInsertCommand.Parameters.AddWithValue("@dateTime", dateTime);
            incidentInsertCommand.Parameters.AddWithValue("@caller", caller);
            incidentInsertCommand.Parameters.AddWithValue("@exchange", exchange);
            incidentInsertCommand.Parameters.AddWithValue("@details", details);

            bool result = executeNonQuery(incidentInsertCommand);

            //if the insert was successful, return a new Incident object for the newly created incident
            if (result)
            {
                int incidentId = -1;

                try
                {
                    string       statement2     = "SELECT MAX(IncidentNumber) FROM Incident WHERE OperatorID = @userId;";
                    MySqlCommand fetchIdCommand = new MySqlCommand(statement2, connection);
                    fetchIdCommand.Parameters.AddWithValue("@userId", user);

                    incidentId = executeIntSelectStatement(fetchIdCommand);

                    //create a new IncidentDataView object to add to the list - this ensures that new incidents are displayed immediately in the incidents window
                    IncidentDataView newView = new IncidentDataView(incidentId, dateTime, incidentType.Name, address.Building, address.Number, address.Street, address.Town,
                                                                    address.Postcode, Properties.Settings.Default.LoggedInUserName, DateTime.MinValue, DateTime.MinValue);
                    Tools.Incidents.Add(newView);

                    //finally, return the new incident
                    return(new Incident(incidentId));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to create incident:" + Environment.NewLine + ex.ToString() + Environment.NewLine + "incident number retrieved: " + incidentId);
                }
            }

            //if failed, return null
            return(null);
        }
Example #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="incidentNo">The unique incident number of the incident</param>
        /// <param name="database">The connection to the database that provides functionality for retrieving/updating data</param>
        public Incident(int incidentNo)
        {
            //assign parameters
            this.database  = Tools.IncidentDB;
            IncidentNumber = incidentNo;

            //retrieve Incident information from the database
            info = database.GetAllDetails(IncidentNumber);

            //find the related incidentDataView object
            this.view = Tools.Incidents.Single(x => x.IncidentNumber == incidentNo);
        }