public static void CreateOccurrenceInfo(CrashDetails cd, int occ_id, int img_id)
        {
            try
            {
                BDConnect("CreateOccurrenceInfo");

                Command.Parameters.AddWithValue("@img", img_id);
                Command.Parameters.AddWithValue("@model", cd._Model != null ? cd._Model : Convert.DBNull);
                Command.Parameters.AddWithValue("@date", cd._Date);
                Command.Parameters.AddWithValue("@time", cd._Time != null ? cd._Time : Convert.DBNull);
                Command.Parameters.AddWithValue("@status", cd._Status);
                Command.Parameters.AddWithValue("@oper", cd._Operator != null ? cd._Operator : Convert.DBNull);
                Command.Parameters.AddWithValue("@reg", cd._Registration != null ? cd._Registration : Convert.DBNull);
                Command.Parameters.AddWithValue("@firstFlight", cd._FirstFlight != null ? cd._FirstFlight : Convert.DBNull);
                Command.Parameters.AddWithValue("@crew", cd._Crew != null ? cd._Crew : Convert.DBNull);
                Command.Parameters.AddWithValue("@pass", cd._Passengers != null ? cd._Passengers : Convert.DBNull);
                Command.Parameters.AddWithValue("@total", cd._Total != null ? cd._Total : Convert.DBNull);
                Command.Parameters.AddWithValue("@dmg", cd._Damage != null ? cd._Damage : Convert.DBNull);
                Command.Parameters.AddWithValue("@loc", cd._Location != null ? cd._Location : Convert.DBNull);
                Command.Parameters.AddWithValue("@phase", cd._Phase != null ? cd._Phase : Convert.DBNull);
                Command.Parameters.AddWithValue("@nature", cd._Nature != null ? cd._Nature : Convert.DBNull);
                Command.Parameters.AddWithValue("@dep", cd._Departure != null ? cd._Departure : Convert.DBNull);
                Command.Parameters.AddWithValue("@dest", cd._Destination != null ? cd._Destination : Convert.DBNull);
                Command.Parameters.AddWithValue("@number", cd._FlightNumber != null ? cd._FlightNumber : Convert.DBNull);
                Command.Parameters.AddWithValue("@summary", cd._Summary != null ? cd._Summary : Convert.DBNull);
                Command.Parameters.AddWithValue("@cycles", cd._Cycles != null ? cd._Cycles : Convert.DBNull);
                Command.Parameters.AddWithValue("@engines", cd._Engines != null ? cd._Engines : Convert.DBNull);
                Command.Parameters.AddWithValue("@airframe", cd._AirframeHours != null ? cd._AirframeHours : Convert.DBNull);
                Command.Parameters.AddWithValue("@fate", cd._AircraftFate != null ? cd._AircraftFate : Convert.DBNull);
                Command.Parameters.AddWithValue("@map", cd._MapURL != null ? cd._MapURL : Convert.DBNull);
                Command.Parameters.AddWithValue("@occurrence_id", occ_id);

                int value = Convert.ToInt32(Command.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                BDDisconnect();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fully create all the years of occurrences in the DB
        /// </summary>
        /// <returns></returns>
        public void FullDBSync(object sender, DoWorkEventArgs e)
        {
            btnLock.Enabled = false;
            btnSync.Enabled = false;

            int date  = 2018;
            int count = 0;

            while (date <= Convert.ToInt32(DateTime.Now.Year))
            {
                List <CrashInfo> values = CrashInfo.GetCrashes(date.ToString());

                foreach (CrashInfo cr in values)
                {
                    int id = DBSync.GetOccurrenceIDByLink(cr.Link);
                    int img_ID;
                    int countryID = 0;

                    if (id == 0)
                    {
                        countryID = DBSync.GetFlagByFlagName(cr.Flag_Name);

                        if (countryID <= 0)
                        {
                            countryID = DBSync.CreateFlagImage(cr.Flag_Name, DBSync.ImageToByteArray(cr.Img));
                        }

                        //Creates the occurrence, if it doesn't exist
                        id = DBSync.CreateOccurence(cr, countryID);

                        if (id != 0)
                        {
                            count++;
                        }

                        //Creates the page for the occurrence
                        img_ID = DBSync.GetPlaneImageIDByPlaneModel(cr.Plane);

                        if (img_ID <= 0)
                        {
                            img_ID = DBSync.CreatePlaneImage(cr.Plane, DBSync.ImageToByteArray(cr.Img));
                        }

                        DBSync.CreateOccurrenceInfo(CrashDetails.RetrieveInfoFromWebsite(Resources.MainPage + cr.Link), id, img_ID);
                    }
                    else
                    {
                        if (DBSync.GetOccurrenceInfoByID(id) <= 0) //If it does not exist
                        {
                            img_ID = DBSync.GetPlaneImageIDByPlaneModel(cr.Plane);

                            if (img_ID <= 0)
                            {
                                img_ID = DBSync.CreatePlaneImage(cr.Plane, DBSync.ImageToByteArray(cr.Img));
                            }

                            DBSync.CreateOccurrenceInfo(CrashDetails.RetrieveInfoFromWebsite(Resources.MainPage + cr.Link), id, img_ID);
                        }
                    }
                }

                CrashInfo.AllCrashes.Clear();
                date++;
            }

            Settings.Default.OccurrencesSync = DateTime.Now;
            Settings.Default.IndividualSync  = DateTime.Now;
            Settings.Default.Save();
            lblOcc.Text        = "Incidents: " + Settings.Default.OccurrencesSync.ToString();
            lblIndividual.Text = "Individual: " + Settings.Default.IndividualSync.ToString();
            btnLock.Enabled    = true;
            isLocked           = true;
        }
        static internal CrashDetails getCrashDetailsFromList(List <string> values)
        {
            CrashDetails crash               = new CrashDetails();
            Image        _planeImage         = null;
            string       _planeModel         = null;
            string       _crashDate          = null;
            string       _crashTime          = null;
            string       _currentStatus      = null;
            string       _operator           = null;
            string       _registration       = null;
            string       _firstFlight        = null;
            string       _crew               = null;
            string       _passengers         = null;
            string       _total              = null;
            string       _aircraftDamage     = null;
            string       _location           = null;
            string       _phase              = null;
            string       _nature             = null;
            string       _departureAirport   = null;
            string       _destinationAirport = null;
            string       _flightNumber       = null;
            string       _crashSummary       = null;
            string       _cycles             = null;
            string       _engines            = null;
            string       _airframeHours      = null;
            string       _aircraftFate       = null;
            string       _mapUrl             = null;
            List <Image> _imgList            = null;

            foreach (string item in values)
            {
                if (item.Contains("\r\n") && item.Length < 20 || item == "\n" || item == "")
                {
                    continue; //Do nothing
                }
                else
                {
                    if (item.Contains("Type:")) //Plane Model
                    {
                        string auxItem = getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0);
                        _planeModel = GetPlaneModel(auxItem);
                        if (item.Contains("<img src=")) //Plane Image
                        {
                            _planeImage = GetPlaneImage(auxItem);
                        }
                    }

                    if (item.Contains("Status:") && item.Contains("\"desc\">"))                               //Current Inspection Status
                    {
                        _currentStatus = GetStringValue(getStringBetweenTags(item, "\"desc\">", "</td>", 0)); //Site tag is wrong
                    }
                    if (item.Contains("Date:"))                                                               //Date of the Accident
                    {
                        _crashDate = GetStringValue(getStringBetweenTags(item, "<td class=\"caption\">", "</td>", 1));
                    }

                    if (item.Contains("Time:")) //Time of the Accident
                    {
                        _crashTime = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Operator:"))
                    {
                        _operator = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Registration:"))
                    {
                        _registration = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0).Trim());
                    }

                    if (item.Contains("First flight:"))
                    {
                        _firstFlight = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Total airframe:"))
                    {
                        _airframeHours = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Cycles:"))
                    {
                        _cycles = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Engines:"))
                    {
                        _engines  = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                        _engines += GetStringValue(getStringBetweenTags(item, ">", "<", 3));
                    }

                    if (item.Contains("Crew:") && item.Contains("Occupants:"))
                    {
                        _crew = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Passengers:") && item.Contains("Occupants:"))
                    {
                        _passengers = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Total:") && item.Contains("Occupants:"))
                    {
                        _total = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Aircraft damage:"))
                    {
                        _aircraftDamage = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Aircraft fate:"))
                    {
                        _aircraftFate = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Location:"))
                    {
                        _location  = GetStringValue(getStringBetweenTags(item, ">", "<", 2));
                        _location += GetStringValue(getStringBetweenTags(item, ">", "<", 4));

                        if (_location.Contains("United States of America"))
                        {
                            _location = _location.Replace("United States of America", "USA");
                        }
                    }

                    if (item.Contains("Phase:"))
                    {
                        _phase = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Nature:"))
                    {
                        _nature = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Departure airport:"))
                    {
                        if (item.Contains(">-<"))
                        {
                            _departureAirport = null;
                        }
                        else
                        {
                            if (item.Contains(">?<"))
                            {
                                _departureAirport = "Unknown";
                            }
                            else
                            {
                                _departureAirport  = GetStringValue(getStringBetweenTags(item, ">", "<", 3));
                                _departureAirport += GetStringValue(getStringBetweenTags(item, ">", "<", 4));
                            }
                        }
                    }

                    if (item.Contains("Destination airport:"))
                    {
                        if (item.Contains(">-<"))
                        {
                            _destinationAirport = null;
                        }
                        else
                        {
                            if (item.Contains(">?<"))
                            {
                                _destinationAirport = "Unknown";
                            }
                            else
                            {
                                _destinationAirport  = GetStringValue(getStringBetweenTags(item, ">", "<", 5));
                                _destinationAirport += GetStringValue(getStringBetweenTags(item, ">", "<", 6));
                            }
                        }
                    }

                    if (item.Contains("Flightnumber:"))
                    {
                        _flightNumber = GetStringValue(getStringBetweenTags(item, "<td class=\"desc\">", "</td>", 0));
                    }

                    if (item.Contains("Narrative:"))
                    {
                        _crashSummary = GetStringValue(getStringBetweenTags(item, "<span lang=\"en-US\">", "</span>", 0).Replace("<br />", "ççç"));
                        _crashSummary = _crashSummary.Replace("ççç", "\r\n");
                    }

                    if (item.Contains("Map") && item.Contains("infoboxtitle"))
                    {
                        _mapUrl = getMapUrlBetweenTags(item, "<iframe src=\"", "\" height");
                    }
                }
            }

            if (_currentStatus == null)
            {
                _currentStatus = "Unknown";
            }

            if (_crashTime == null)
            {
                _crashTime = "Unknown";
            }

            if (_crashDate == null)
            {
                _crashTime = "Unknown";
            }

            if (_planeImage == null)
            {
                _planeImage = Properties.Resources.stock_plane;
            }

            return(new CrashDetails(_planeImage, _planeModel, _crashDate, _crashTime, _currentStatus, _operator, _registration, _firstFlight, _crew, _passengers,
                                    _total, _aircraftDamage, _location, _phase, _nature, _departureAirport, _destinationAirport, _flightNumber, _crashSummary, _cycles, _engines,
                                    _airframeHours, _aircraftFate, _mapUrl, _imgList));
        }
        private void CrashSelection_Load(object sender, EventArgs e)
        {
            CrashDetails cs = CrashDetails.RetrieveInfoFromWebsite(link);

            pctPlane.Image    = cs._Image;
            this.Text         = "Current Status: " + cs._Status;
            this.lblDate.Text = "Date: " + cs._Date;
            this.lblTime.Text = "Time: " + cs._Time;

            if (cs._planeModel == null)
            {
                this.lblType.Visible = false;
            }
            else
            {
                this.lblType.Text = "Type: " + cs._planeModel;
            }

            if (cs._operator == null)
            {
                this.lblOperator.Visible = false;
            }
            else
            {
                this.lblOperator.Text = "Operator: " + cs._operator;
            }

            if (cs._registration == null)
            {
                this.lblRegistration.Visible = false;
            }
            else
            {
                this.lblRegistration.Text = "Registration: " + cs._registration;
            }

            if (cs._firstFlight == null)
            {
                this.lblFirstFlight.Visible = false;
            }
            else
            {
                this.lblFirstFlight.Text = "First Flight: " + cs._firstFlight;
            }

            if (cs._crew == null)
            {
                this.lblCrew.Visible = false;
            }
            else
            {
                this.lblCrew.Text = "Crew: " + cs._crew;
            }

            if (cs._passengers == null)
            {
                this.lblPassengers.Visible = false;
            }
            else
            {
                this.lblPassengers.Text = "Pass: "******"Total:  " + cs._total;
            }

            if (cs._aircraftDamage == null)
            {
                this.lblDamage.Visible = false;
            }
            else
            {
                this.lblDamage.Text = "Aircraft Damage: " + cs._aircraftDamage;
            }

            if (cs._location == null)
            {
                this.lblLocation.Visible = false;
            }
            else
            {
                this.lblLocation.Text = "Location: " + cs._location + ")";
            }

            if (cs._phase == null)
            {
                this.lblPhase.Visible = false;
            }
            else
            {
                this.lblPhase.Text = "Phase: " + cs._phase;
            }

            if (cs._nature == null)
            {
                this.lblNature.Visible = false;
            }
            else
            {
                this.lblNature.Text = "Nature: " + cs._nature;
            }

            if (cs._departureAirport == null)
            {
                this.lblDeparture.Visible = false;
            }
            else
            {
                this.lblDeparture.Text = "Departure Airport: " + cs._departureAirport;
            }

            if (cs._destinationAirport == null)
            {
                this.lblDestination.Visible = false;
            }
            else
            {
                this.lblDestination.Text = "Destination Airport: " + cs._destinationAirport;
            }

            if (cs._flightNumber == null)
            {
                this.lblFlightNumber.Visible = false;
            }
            else
            {
                this.lblFlightNumber.Text = "Flight Number: " + cs._flightNumber;
            }

            if (cs._crashSummary == null)
            {
                this.textBox1.Visible = false;
            }
            else
            {
                this.textBox1.Text = cs._crashSummary;
            } this.textBox1.SelectionStart = 0; this.textBox1.SelectionLength = 0;

            if (cs._cycles == null)
            {
                this.lblCycles.Visible = false;
            }
            else
            {
                this.lblCycles.Text = "Cycles: " + cs._cycles;
            }

            if (cs._engines == null)
            {
                this.lblEngines.Visible = false;
            }
            else
            {
                this.lblEngines.Text = "Engines: " + cs._engines;
            }

            if (cs._airframeHours == null)
            {
                this.lblAirframeHours.Visible = false;
            }
            else
            {
                this.lblAirframeHours.Text = "Total Airframe Hrs: " + cs._airframeHours;
            }

            if (cs._aircraftFate == null)
            {
                this.lblAircraftFate.Visible = false;
            }
            else
            {
                this.lblAircraftFate.Text = "Aircraft Fate: " + cs._aircraftFate;
            }

            if (cs._mapUrl == null)
            {
                DisableMap();
            }
            else
            {
                this.webBrowser1.Url = new Uri(Properties.Resources.MainPage + cs._MapURL);
            }

            //if (cs._imgList == null)
            //    DisableImgList();

            int x   = 12;
            int y   = 230;
            int idx = 0;

            for (int i = 0; i < this.Controls.Count; i++)
            {
                for (int i2 = this.Controls.Count - 1; i2 >= 0; i2--)
                {
                    if (this.Controls[i2] is Label && this.Controls[i2].TabIndex == i && this.Controls[i2].Visible == true)
                    {
                        if (idx >= 17)
                        {
                            idx = 0;
                            x   = 270;
                            y   = 40;
                        }
                        this.Controls[i2].Location = new Point(x, y + (25 * idx));
                        //item.Text = idx.ToString();
                        idx++;
                    }
                }
            }
        }