示例#1
0
        private void YearSearch_Load(object sender, EventArgs e)
        {
            this.Text = "Occurrences reported in " + selectedYear;

            olvFlag.AspectToStringConverter = delegate(object x) {
                return(String.Empty);
            };

            olvFlag.ImageGetter = delegate(object rowObject) {
                CrashInfo s = (CrashInfo)rowObject;
                return(s.Img);
            };

            olvCrashes.SetObjects(CrashInfo.GetCrashes(selectedYear));

            //Deletes the Crashes List
            CrashInfo.AllCrashes.Clear();

            lblResults.Text = "Showing " + olvCrashes.Items.Count + " results";

            this.Show();
            SplashScreen.CloseSplashScreen();
            this.Activate();

            lblResults.Visible = true;
        }
        //static internal CrashDetails GetCrashInfo(string link)
        //{
        //    Crash = RetrieveInfoFromWebsite(link);
        //    return CrashDetails.Crash;
        //}
        //static public CrashDetails Crash = new CrashDetails();

        static internal CrashDetails RetrieveInfoFromWebsite(string link)
        {
            string        pageContent = "";
            List <string> values      = new List <string>();
            CrashDetails  details;

            WebClient web = new WebClient();
            Stream    stream;

            stream = web.OpenRead(link);
            using (StreamReader reader = new StreamReader(stream))
            {
                pageContent = reader.ReadToEnd();
            }
            stream.Close();

            pageContent = DeleteComments(pageContent);

            //Limits the page to the table tags (What we want to show)
            pageContent = CrashInfo.getStringBetweenTags(pageContent, "<body>", "</body>");
            //Grabs each individual set of data into a list
            values = CrashInfo.getListFromString(pageContent, "<tr>", "</tr>");
            //Distributes the concatenated string into the actual data
            details = getCrashDetailsFromList(values);

            return(details);
        }
        public static int CreateOccurence(CrashInfo crash, int flag_id)
        {
            try
            {
                BDConnect("CreateOccurrence");

                Command.Parameters.AddWithValue("@date", crash.Date);
                Command.Parameters.AddWithValue("@model", crash.Plane);
                Command.Parameters.AddWithValue("@reg", crash.Reg);
                Command.Parameters.AddWithValue("@oper", crash.Operator);
                Command.Parameters.AddWithValue("@fat", crash.Fat);
                Command.Parameters.AddWithValue("@loc", crash.Loc);
                Command.Parameters.AddWithValue("@flag_id", flag_id);
                Command.Parameters.AddWithValue("@category", crash.Cat);
                Command.Parameters.AddWithValue("@link", crash.Link);

                int value = Convert.ToInt32(Command.ExecuteScalar());

                return(value);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                BDDisconnect();
            }
        }
 public CrashSelection(CrashInfo info)
 {
     InitializeComponent();
     link           = Properties.Resources.MainPage + info._link;
     mapDefaultPos  = this.webBrowser1.Location;
     mapDefaultSize = this.webBrowser1.Size;
 }
示例#5
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;
        }