Leave a comment

A Year in Review: 2013


The year 2013 saw The Happy Coder publish 15 posts after taking some time off. The blog was somewhat re-tooled from something that was strictly code-based, this is how you do it, to something that is designed to give insight to the world of programming (at least MY part of it) and maybe give you a few ideas for projects. I have taken you into how I think and what I feel the role of the programmer is, as well as this is how you do it.

I have done a few multi-part posts about certain projects – Invoice Approval System – Part I, Invoice Approval System – Part II: The Web and Invoice Approval System – Part III: Multiple Approvers being the longest and most popular – but most consisted of a single post. I tried to let you in on my thought process (Creativity and Proactive Customer Service) and hopefully inspired you to look at projects in a different light. I think it is important to set aside personal feelings and ego in order to satisfy the customer. It is equally important to make sure the customer gets what they need even if it isn’t necessarily what they think they want. The hard part is to do this and still make them happy.

I intend to bring more projects and instruction your way in the upcoming year. I hope you find them, not only informational and inspirational, but also entertaining.

Thank you for a great 2013 and I look forward to a great 2014!

Leave a comment

HTML to PHP to ASP.NET: Part II


Http://Welcome back! In the first part of this series I covered my initial involvement in a client’s website development; it was strictly HTML and a little CSS. Then the “Contact Us” page was written in PHP, followed by a PHP product specification sheet that got it’s data from a PostgreSQL database. The final step in the evolution was a total migration to ASP.NET and SQL Server. I had just finished the main product pages, database tables and stored procedures when I ended Part I. You can refresh your memory (or read it for the first time) here – HTML to PHP to ASP.NET: Part I. In Part II I will cover the “Contact Us”, “Careers” and “Login” pages along with pages that handle site and data administration.

Let’s start with the all-important “Contact Us” page. As I mentioned earlier, this page was written in PHP and later had CAPTCHA added. When a potential customer submitted the request they received a confirmation email and an email was sent to the client’s sales department for follow-up. The system worked well but there was no record other than an email and there was nowhere for the sales department to keep notes about the request. I built a table in the database and added code to write the data to the table prior to sending the email. There was then a page created that queried this data and wrote it to the screen. When I moved to ASP.NET I also added the ability to send email to the requestor directly from the web page and for the person sending the email to add comments to the database. They now had somewhere they could go to and see what people are inquiring about and maintain records of follow-up correspondence. This data could ultimately be tied into a customer database or order database with relative ease.

At this point I have completely migrated the existing website over to ASP.NET and SQL Server and it is time to add the back-end administrative functionality. One of the prime reasons for the site migration was to give the client the ability to maintain the data and add products without having to come to me to update the HTML code. With that goal in mind I set out to create the “admin” pages. The first consideration was security; we didn’t want just anyone to be able to change the data. The easiest form of security, and also the least secure, is to put up a page that doesn’t have a link to it anywhere. The thought is that you can’t get there if you don’t know where “there” is or that it even exists. This isn’t a very good choice. The site already had a “Login” page that contained links to internal sites that required user authentication so I decided to use that page and add a couple textboxes for the user to input a loginID and password. These would be the same as their email id and password; you’ll learn why later. I wanted to give the client the ability to restrict functionality to users based upon “access levels” and started with four basic levels – “sales”, “hr”, “admin” and “executive”. Sales would have access restricted to the contact request functions and hr would be restricted to the “Careers” page. Admin level would give access to the product data tables and executive would grant access to everything. I had a table, tLogin, that stored the userID, password, access level, date created and date deleted. If date deleted is NULL, then the access rights were active, otherwise the user either had their access rights changed or they no longer had rights. The reason I wanted to use the email password for the user is that this then allowed me to use their email account for sending the correspondence to the custom in response to a contact request.

The “Careers” page is something that I am sure everyone reading this post has seen; it is a page for advertising job openings within the company. I decided to have this page work for both internal and external job postings. If the user had a login id and password, they were allowed to view the internal postings otherwise they got only the external posts. There was a link to send and email to the person posting the job. I created everything with the intent of having the ability to track applicants and store resumes but that is beyond the scope of this project. I do envision adding this functionality in the future.

That is the project, in a nutshell. I hope you enjoyed reading about it and maybe getting some ideas for your next website.

If you would like to know more about this project or have one you would like to discuss, please write to me at joevalencia32@gmail.com.

1 Comment

HTML to PHP to ASP.NET: Part I


Http://Since 2008 I have been doing miscellaneous work for a client on an as-needed basis. My first job for him was a simple spreadsheet fix and it grew into other projects, the biggest of which was the company website. The site was originally just a plain white background with the company logo and a little background information along with contact information. I expanded the site to include pages for the individual product lines and added graphics. They wanted to make it more attractive but their design needs were beyond my expertise so they hired a company to build it, under my guidance and specifications. The resulting site is quite attractive but a little cumbersome to work with because the layout is based on tables and the menus are placed on each page making changes far more labor intensive than necessary. The host is a LINUX server and the site was purely HTML and CSS with no server-side coding at all.

In 2010 they wanted to add a feature that allows the user to click on an icon on a product page and have a new page open with a full specification sheet that they could then print. The sheet was to include a photo of the product, description and full specifications along with the companies contact information and logo. There were a couple ways to attack this request – one way would be to create a specification page for each of the items and hard-code a link which would have made a lot of money for me or we could do it the smart way and create one page using PHP and bind it to a database on the backend. This page would be built dynamically based upon the item the user clicked on. I suggested the latter and the client agreed so I went about learning PHP. I then discovered that the database available to me was PostgreSQL which I had never worked with. I was expecting MySQL, a database that I was familiar with. It didn’t take long for me to learn the necessary technologies, build the database and write the code; within a week of the initial request I had the work done. The company has added products since then and the update couldn’t be easier – or could it?

That brings me to the next step in the evolution of the site – ASP.NET. I have been wanting to bring the site over to .NET and SQL Server for a while but the clients host didn’t offer the service with the package they had and the advantages weren’t enough to warrant a move. It wasn’t until I added the ability to save customer contact requests to the database that we finally reached a point where the change was worthwhile. I added a couple tables to the database to store the contact request and comments from the sales department and created a PHP admin page where they could view all the requests and send e-mail to the customer. It is functional but it isn’t what I wanted to do. I spoke with my contact at the client, outlined my vision for what the site could be like and got the green light to migrate to .NET and SQL Server. They found a new host and had the existing site moved, all I had to do was build the database on the new server, add the data and update the connection strings. The host was capable of running both PHP and ASP.NET. The goal was to re-build the site so that it was completely data-driven and new items could be added simply by adding the information to the database. This means that when they add an 11×14 inch spiral bound notebook to the rest of the spiral bound notebooks (note: the client is not a stationary supply company, this product is for illustration purposes only) they only need to add one record to the database and the site will update automatically. If they want to add a completely new product line, I would still need to do some HTML work on the front-end. The new design would also allow them to sort the data on the contact request admin page, view all of the comments entered by the sales department and perform other routine maintenance of the data.

My first step, after deciding on C# as my development language, was to create a “master page” which will have all of the header, navigation and footer information on it. This will dramatically reduce the time required to add/remove a page, re-arrange the menu and update the copyright information. I now have one place to keep this information instead of more than a dozen. Once I had the master page it was just a matter of creating the home page, individual product pages, information request and administrative pages. I started by creating a template for the product pages to make the process more efficient. I was able to copy most of the content and much of the structure for each product and paste it into the new template with only minor adjustments. What I didn’t have to do was include the product specification tables under each product, those were now driven by the database. I simply had to set up an empty <asp:Table>, give it a name and it was done. I created a stored procedure to retrieve the product data from the database and a class module to handle the data. Each product line is different and not all of the fields in the database table with have data so the code looks for fields in the returned recordset and only puts that data in the product table to present to the user. This allows me to use a single stored procedure and the same code for every product, current and future. By using a stored procedure to query the database I can make changes without having to update the source code in the pages. I have found that it is (almost) always best to run the queries from stored procedures within the database rather than in your source code. There are exceptions, of course, but it is a good rule to live by.

I think this is a good place to stop. In Part II I will cover the “Contact Us” page along with pages that handle site and data administration.

If you would like to know more about this project or have one you would like to discuss, please write to me at joe@joevalencia.site90.com.

Leave a comment

Customer Call Listening Program


customer_support_1In my last post (Employee Recognition Program) I wrote about an application I built for the Corporate Communications Department. This article is about another job I did for them, this one was for a project requested by our CEO.

At one time, new employees in certain departments were required to spend time with customer support representatives and listen to calls. A company’s success depends upon happy customers and by hearing directly from the customer we were better prepared to give them a better experience. I don’t know why but the program was stopped for new hires shortly after I started with the company. Now he wanted the program restored, but with a twist. Everyone in the company had to spend time monitoring calls at least once per quarter. My job was to create a web-based scheduling application. I was told that the program had to be “live” in three months – “Can you do it?” “Sure!” I only had two other projects that I was working on and one of them had the same deadline as this one. Why would that be a problem? One of the projects was the second generation of the Invoice Distribution program and since I already had something in place I could put that on a side burner. The other application was for Human Resources.

You have heard the phrase “the devil is in the details”; little did I know the devil in this case was 8 feet tall and had just sharpened his pitchfork! It wasn’t as simple as letting someone sign up for a day and be done. The user had to select 3 sessions of 4 hours but there were a limited number of seats available each day and the program only ran 3 days a week. I needed to track attendance, generate reports and give the participants a section where they could record their observances and suggest improvements. The project also required two (2) admin screens – one for the Customer Support and one for HR. (I know I said this project was for Corporate Communications and it was. They requested the project and provided all of the specifications – the HR department was charged with administering the program and tracking compliance.)

My first task was to build the front-end for the user to request their sessions. The obvious choice here was to use the ASP.NET Calendar control. If the obvious choice was the best choice, I wouldn’t be writing this article…. The problem with the calendar control is that I couldn’t customize it to make it what I wanted. I needed to be able to show which days were available but I also wanted to use color-coding to indicate if the spots were filling up. I decided to use buttons and show 3 months on the screen at a time. The user would select the quarter they wanted to register for and the calendars would be generated and color-coded. I wanted each calendar to actually look like a calendar so I needed to calculate the day of the week the month started and fill in the rest behind it. I needed to have 42 buttons for each month, the button would have a number in it (1 thru 28, 29, 30 or 31) and a color representing it’s availability. I needed to loop through the buttons for each calendar and put the day on the button face and then color code the button. To do this I needed to know how many days were in the month. I could have had a lookup table but that would have been too much work, especially when you take into account leap year. The best answer was a function that returned the last day – that function is GetLastDayInMonth and is shown below.


Private Function GetLastDayInMonth(ByVal dDate As Date) As Date
	dDate = DateAdd(DateInterval.Month, 1, dDate)
	dDate = Convert.ToDateTime(Month(dDate).ToString() & "/" & "1/" & Year(dDate).ToString())
	dDate = DateAdd(DateInterval.Day, -1, dDate)
	Return dDate
End Function

I think I am going to leave it at that for now. This project is a bit too large to cover in one article if I am going to include code samples with it. Stay tuned for upcoming articles where I will cover the color-coding, administration functions and the user input.

If you would like to know more about this project or have one you would like to discuss, please write to me at joe@joevalencia.site90.com.

1 Comment

Have you ever worked with….?


questionMarkIt is the question we have all heard – “Have you ever worked with C#?” or was it “Have you ever worked with VB.NET?” or any of the other languages and technologies that exist in today’s world. I understand why the questions are asked but I don’t understand why many people hold such high regard for the answer. I know that each language has it’s own syntax and a unique way of doing certain things but those are easy things to learn for experienced programmers. Don’t get me wrong, I’m not trying to say that a Visual Basic developer with 15 years’ experience is going to be a crackerjack C# developer in a day – that would be an unreasonable expectation. What I am saying is that, to me, the difficulty with programming is learning the logic behind what you’re coding. How to think in code and how to write good code. You need to know when to write a function and when to just include that code in you current procedure. When should you break code out of a procedure and create a new one? Do you need a class or do you just want to create one? Is the code too fragmented? Unreadable? The list goes on….. Does it really matter if I am writing a protected sub or a protected void? If I import a namespace or I am using it? If I forget a “;” at the end of my C# code, Visual Studio will let me know immediately but it doesn’t care if I create an infinite loop that does absolutely nothing.

It would be easy to stop at programming languages but let me ask you – is it terribly important that you have extensive experience with the most recent version of SQL Server or is it enough to have a solid understanding of databases? Should you care if someone has 10 years experience with virtually every aspect of database design and implementation or is it important that they have 3 years of MySQL work? I have worked with Access, SQL Server, Oracle, MySQL and PostgreSQL over the years. Was I a rock star developer with any of them as soon as I sat down? Of course not! Do I know everything there is to know about all of them? No! I did, however, quickly learn what I needed to know to get the job done.

When did it become more important to know the most recent “greatest thing” than to have a solid background in getting things done. Is it more important to have all the answers or the wisdom to know how to find the answers and put them to work? Don’t get me started with “tools”. I know what you’re thinking – everything is a “tool” and, by the way didn’t you mention that you use Visual Studio? You’re right but that isn’t what I mean by tools. I am talking about applications that allow you to build a website without knowing that it uses HTML and other applications that require little to no knowledge to use. Call me old-fashioned but I like to know what is going on “behind the scenes”. If you read We Need a Website you’ll remember that I had to learn HTML and I actually created my first page (yes, it was HELLO, WORLD! as a heading on a plain page) using NotePad. I moved to a free HTML editor called HomeSite and now use CoffeeCup HTML editor. I was forced to use FrontPage for publishing my initial websites but always used HomeSite for editing. I have worked with people who have intimate knowledge of the tool but little or no knowledge of what it actually does. If the tool doesn’t work or they need to do something beyond the scope of the tool, they are lost.

So there you have it; my first editorial written by The Happy Coder. I know that I am not the only one who is concerned about the changing attitude in today’s technology field but I don’t know how many of us remain. That concerns me. Am I over-reacting? I don’t know and I may never know for sure. What do you think? Leave your thoughts in the comments section below or shoot me an e-mail at joe@joevalencia.site90.com.

Leave a comment

Pick Your Favorite Pumpkin!


gif_1004halloween001I know, it is June and I am writing about pumpkins but I like this project and wanted to share it with you. I used to get calls from various departments with quick projects they had and the “Annual Pumpkin Contest” was one of my favorites. It was fun, it was easy and it gave me an opportunity to be a bit more creative in the page design. Each year at Halloween the company would sponsor a pumpkin decorating contest that was judged by the employees. There were four categories – Funniest, Most Creative, Most Original and Most Company-themed. The winner in each category received a gift card and the undying adoration of their fans.

Each year I would get a call from HR asking if I had time to do the voting page and each year I would put together a page with a Halloween-themed banner, some text, a table with a cell for each pumpkin and finally four sets of radio buttons for the voting. There was also a reporting page where the results could be seen -access to this page was restricted. The only thing difficult about this project each year was getting the graphics approved and the copy they wanted on the page.

We discovered the first year that many people were voting many times, even though they were asked to vote only once. I began tracking the users as they voted, but not their votes, in the database and if someone tried voting more than once subsequent votes were not recorded. I never spent much time building the database or trying to create some type of template because it was such a small project and it was always a welcomed diversion from other projects.

One year I got the call and I didn’t have a lot going on so I decided to build this project for the very last time. I was going to make it “smart” and data-driven so that next time, the person running the contest only had to do a couple things and the job was done. The other thing different with this year is that I was going to do it in C# instead of VB. I had been reading and watching video tutorials over the preceding couple months in an effort to learn the language but never had an appropriate project to put my new skills to the test.

I decided to give the administrator a more robust page and have them upload the pumpkin photos to the server themselves. They would also set the start and end dates along with the copy for the page. When the user opened the page, the application would get a list of the photos, lay out a table three (3) columns wide and load the table with pictures and captions. It would then generate the four sets of radio buttons at the bottom of the page for voting.

Let’s take a look at some of the code. The first thing I want to do is query the directory holding the pumpkin photos and put the list into an array, fi. To do this I need to load the System.IO namespace.

using System.IO;
FileInfo[] fi = new DirectoryInfo(Server.MapPath("pumpkins")).GetFiles("*.jpg");

Once I have the list of pumpkins, I am ready to put them on the page. To do this I will use a “Do…While” loop.


do
  {
    TableRow row = new TableRow();
    TableCell cell = new TableCell();

    string strP1 = fi[i].Name.ToString();
    cell = new TableCell();
    cell.Text = "<img src='pumpkins/" + strP1 + "' width='194px'>
                 <br />Pumpkin " + (i + 1) + "";
    row.Cells.Add(cell);

    try
    {
      string strP2 = fi[i + 1].Name.ToString();
      cell = new TableCell();
      cell.Text = "<img src='pumpkins/" + strP2 + "' width='194px'>
                 <br />Pumpkin " + (i + 2) + "";
      row.Cells.Add(cell);
    }
    catch
    {
    //empty cell
      cell = new TableCell();
      cell.Text = "";
      row.Cells.Add(cell);
    }

    try
    {
      string strP3 = fi[i + 2].Name.ToString();
      cell = new TableCell();
      cell.Text = "<img src='pumpkins/" + strP3 + "' width='194px'>
                 <br />Pumpkin " + (i + 3) + "";
      row.Cells.Add(cell);
    }
    catch
    {
    //empty cell
      cell = new TableCell();
      cell.Text = "";
      row.Cells.Add(cell);
    }
    tblPumpkins.Rows.Add(row);
    i = i + 3;
  }
  while (i <= fi.Length - 1);

All that we have left are the voting buttons at the bottom of the page.


for (int orig = 0; orig < fi.Length; orig++)
        {
            rdoMostOriginal.Items.Add("Pumpkin " + (orig + 1));
            rdoCreative.Items.Add("Pumpkin " + (orig + 1));
            rdoFunniest.Items.Add("Pumpkin " + (orig + 1));
            rdoTheme.Items.Add("Pumpkin " + (orig + 1));
        }

That covers most of the user page, with the exception of the “Submit vote” button. I will cover the administrative and reporting code in an upcoming article.

If you would like to know more about this project or have one you would like to discuss, please write to me at joe@joevalencia.site90.com.

1 Comment

Employee Recognition Program


awardOrangeOne of the first, if not the very first, ASP.NET applications I built was for an employee recognition program that was run by the Corporate Communications Department. I didn’t know it at the time but it was the beginning of a long-lasting relationship with that department and some valued friendships.

The program was designed for employees to reward co-workers who impressed them with their accomplishments and dedication to making the company the best it could be. The only rules were that you could not nominate yourself and the act should truly be noteworthy – you weren’t going to be recognized for giving someone a piece of gum…. The program had already been in place when I was asked to build the web application for them. The requirements were fairly simple – validate the nominator, validate the nominee, get the reason for the nomination, store the nomination, nomination approval and print the certificate. The back-end was Microsoft Access and the certificates were done using Microsoft Word and mail merge. When a nomination was made the Program Administrator was notified and she reviewed the nomination. If it was legitimate, a certificate was printed and delivered through company mail. The employee’s manager was also notified of the award.

I added an “Admin” page so that nominations could easily be reviewed, approved or edited. There was also another component that had to be added – a monthly contest. This was different in that it was only open to managers and they could only choose from employees who were nominated for awards that month. The winner received the “Outstanding Employee of the Month” award. This part required another web page for the nominations, another section of the admin page and the ability to verify that the user was a manager.

The application was in production for about 7 months before the program was discontinued but it was a big success and it gave me the foundation upon which to build everything that came after it. I also got quite a bit of recognition for my efforts (I got a couple awards myself!) and I soon found myself with a lot of requests for applications from many different areas of the company. I even got a request for a project that came from the CEO but that’s for another article.

If you would like to know more about this project or have one you would like to discuss, please write to me at joe@joevalencia.site90.com.

Follow

Get every new post delivered to your Inbox.

Join 333 other followers

%d bloggers like this: