Click here to Skip to main content
15,886,362 members
Articles / Web Development / HTML

A Really Vain "How are my articles doing" Web Spider

Rate me:
Please Sign up or sign in to vote.
4.56/5 (43 votes)
4 Feb 2013CPOL6 min read 91.8K   982   74  
A simple web spider to see fetch CodeProject articles.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace VainWebSpider
{
    #region frmLoader CLASS
    /// <summary>
    /// This form obtains the currently selected user from the registry
    /// (if there is a current user, if may be the 1st run, so there wont be)
    /// by using the <see cref="Program">Programs </see>readFromRegistry(..) 
    /// method. This class also allows the user to change the currently selected user
    /// via clicking a change user hyperlink. The user may also show the 
    /// <see cref="frmMain"> main interface</see> from this form using the hyperlink
    /// provided
    /// </summary>
    public partial class frmLoader : Form
    {
        #region Contructor
        /// <summary>
        /// Constructs a new frmLoader object
        /// </summary>
        public frmLoader()
        {
            InitializeComponent();
        }
        #endregion

        public frmMain frmMain
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }
        #region Private Methods
        /// <summary>
        /// Allows the user to specify a new UserId to fetch codeproject articles for by the
        /// use of a <see cref="InputBoxDialog">InputBoxDialog </see>
        /// The value entered must be a postive number
        /// </summary>
        /// <param name="sender">lnkChangeUser</param>
        /// <param name="e">LinkLabelLinkClickedEventArgs</param>
        private void lnkChangeUser_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //get the new userId
            string stringEntered = Program.InputBox("Enter a new user ID to examine", "Enter a new user ID", "");
            //check for empty
            if (stringEntered.Equals(string.Empty)) 
            {
                Program.ErrorBox("You must enter a value for the userId");
            }
            else 
            {
                try 
                {
                    //make sure its a positive number, then update the Program
                    //held property
                    long userId = long.Parse(stringEntered);
                    if (userId > 0)
                    {
                        Program.UserID = userId;
                        lblCurrentUser.Text = "Currently set-up to fetch articles for user ID : " + Program.UserID.ToString();

                    }
                    else
                    {
                        Program.ErrorBox("User ID must be a postive value");
                    }
                }
                //its not a number that was entered, tell them off
                catch(Exception) 
                {
                    Program.ErrorBox("The value you entered was not valid\r\n" +
                                    "The user ID must be a number");
                }
            }
        }

        /// <summary>
        /// Check to see if there is already a user within the registry (from last time)
        /// to fetch codeproject articles for, by using the <see cref="Program">Programs
        ///  </see>readFromRegistry(..) method. And update this forms GUI accordingly
        /// </summary>
        /// <param name="sender">frmLoader</param>
        /// <param name="e">EventArgs</param>
        private void frmLoader_Load(object sender, EventArgs e)
        {
            //check if there is a user in the registry, if there is a user
            //update the Program class and the GUI label
            long userId = Program.readFromRegistry();
            Program.UserID = userId;
            if (userId != -1)
            {
                lblCurrentUser.Text = "Currently set-up to fetch articles for user ID : " + userId.ToString();
            }
            else
            {
                lblCurrentUser.Text = "Not setup for any user as yet, use the link to pick a new user";
            }
        }

        /// <summary>
        /// Create and show a new <see cref="frmMain">frmMain</see> object, and hide this form
        /// </summary>
        /// <param name="sender">lnkLoadMainForm</param>
        /// <param name="e">LinkLabelLinkClickedEventArgs</param>
        private void lnkLoadMainForm_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frmMain fMain = new frmMain();
            this.Hide();
            fMain.ShowDialog(this);
        }
        #endregion
    }
    #endregion
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)

- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence

Both of these at Sussex University UK.

Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2016
  • Codeproject MVP 2016
  • Microsoft C# MVP 2015
  • Codeproject MVP 2015
  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Comments and Discussions