Creating a Custom Human Resources Application with ASP.NET | 2 | WebReference

Creating a Custom Human Resources Application with ASP.NET | 2


[prev]

Creating a Custom Human Resources Application with ASP.NET [con't]

Run the Project

Save your project and press F5 to run the project. You'll have to append the URL as follows: https://localhost{portNumber}/admin/addjob.aspx. As you can see, when the browser opens, it will open to local host and a port number. Simply append on the admin folder, as well as your add job file. Give the form a try and make sure everything works as intended. After you hit the add job button a few times, you should have the same number of records in your database table.

Open default.aspx from Inside the Admin Folder

From inside the admin folder, double click default.aspx and add the markup as shown in the default.aspx file from the project downloads file. As you can see from the code archive, you have two repeater controls: one is for displaying active jobs, the other is for displaying inactive jobs.

Let's add the functionality to associate data to the repeater. From the solution explorer, left click the plus sign (+), double click default.aspx.cs and then add the code from the default.aspx.cs file in the project downloads file.

As you can see from the code archive within your page load event, you:

  • Create two list objects, and call the appropriate methods from your code behind file (added next)
  • Set the data source of both your controls to the appropriate list object and data bind

Open HumanResources.cs and add the ViewAllJobs and ViewInactiveJobs methods as shown from the project downloads file. As you can see from the code archive, you create:

  • A static method
  • A connection object and pass in your configuration key
  • A command object and call your stored procedure
  • A list object casted as your human resources class

If for any reason you can't connect to the database or you can't read records, you wrap the methods inside a try/catch to handle exceptions as follows:

  1. Call the open method of your connection object.
  2. Create a data reader object and set the command object's execute reader method to it.
  3. Inside your while loop, create a new instance of your human resources class and add it to your list object.
  4. Call the dispose method of your connection object and the close method of your connection object.

Save your file and preview the results.

Open default.aspx from the Root of the Solution

From the root of the solution, double click default.aspx and add the markup from the default.aspx file in project downloads file. As you can see from the code archive, you create a repeater control and for each active job, you'll display a link (with a guid) and the job title. Open HumanResources.cs and add ViewAllJobs from the project downloads file.

Save your file. From the solution explorer, left click the plus sign (+) next to default.aspx, double click default.aspx.cs and add the code from the project downloads file.

Save your file.

Next, create the viewjob.aspx file from the solution explorer as follows:

  1. Right click and select Add→New Item.
  2. In the Add New Item window, select WebForm.
  3. In Name, type viewjob.aspx and click Add.
  4. Replace the markup with the code from the viewjob.aspx file in project downloads file.

As you can see from the code archive, you display all appropriate information about the job on the page.

Save your file. At this point, you should have a functioning system. Run the project, give it a test run and make sure all parts are working as intended.

What About Authentication?

Due to the scope of the article, I left out authentication. However, you have set up the solution to the point where wiring in authentication wouldn't be terribly challenging, specifically if you use ASP.NET's built-in model. In other words, your admin folder is the part of the solution that would be restricted, whereas the root default.aspx would be accessible to anyone. Spend some time looking at ASP.NET's built-in security model, and see if it would meet your needs. Depending on requirements, it often does 90% of the time.

Summary

In this article you learned how to create a relatively simple job-listing HR system with ASP.NET. Furthermore, you learned the following:

  • Restoring a database from a backup
  • What stored procedures are and why you use them

Take the knowledge gained in this article and expand your HR system to meet any needs you may have. If you have questions, please contact me.

Code Download

  • ASP.NET Job-listing HR system source code
  • About the Author

    Ryan Butler is the founder of Midwest Web Design. His skill sets include HTML, CSS, Flash, JavaScript, ASP.NET, PHP and database technologies.

    Original: Nov. 30, 2010


    [prev]