www.MasterCsharp.com Logo  AksTech Ad
 Welcome to MasterCSharp.com - Master C#, the easy way... - by Saurabh Nandu

 

 

Creating a Poll Application - Creating the Admin Pages - Part 1
   
 

 

[Rate this Article]
Download SDK Code Charge Studio
pollapp-part1.zip (105kb) v1.0.3705 v1.0.7

Introduction
In the last article I gave you a brief overview of CodeCharge Studio (CCS). In this article I will straight dive into the depths of this tool and we will build a Simple Poll Application using this tool. This tutorial will highlight how easily you can build a fairly complex database driven application. I will split this tutorial in to parts so that its easier for you to read ( and me to write ;) ).

Application Summary
Let's first summarize the functionality we are looking out for before we start creating the application. The application will be divided into two logical parts the first part will be the Poll User Control (Includable Page in CCS). This user control can be placed on any other page where you want to display the poll hence you reuse the user control code.
The second section contains of the administration section where only the administrator is allowed access. Through the admin section the administrator can easily add, update delete the poll items. The Poll application will be created in such a way that there can be multiple choices per poll. Also a user can only vote once per poll. And at a given time only one poll can be active.

In this article I will only cover the creating of the administration section. In the further parts I'll complete the next part.

Database Design
Before you start creating any application in CodeCharge Studio you need to first design the database. In this example I will be using MS Access database, you can actually use any database you like. The descriptions of the 4 tables are given below for our vote.mdb file :

1) Members - This table is used to keep the username and password of the administrators who will be allowed to access the admin section of the application.

Field Name Data Type Description
member_id AutoNumber Primary key field for the table.
member_name Text Username of the member that will be used while authentication.
member_pass Text Password of the member that will be used while authentication.

2) Vote_Details - This table stores the details of each poll. Also there it sets the active poll.

Field Name Data Type Description
vote_id AutoNumber Primary key field for the table.
vote_name Text Title of the poll.
vote_desc Memo Description of the poll. Usually this field will hold the question for the poll.
vote_active Yes/No Indicates which poll is active.

3) Vote_Items - This table stores the choices related to each poll. As I mentioned before each poll will support multiple choices, hence this table is used to store the choices for the poll.

Field Name Data Type Description
vote_item_id AutoNumber Primary key field for the table.
vote_id Number The vote_id from the vote_details table to which this item is related.
vote_item_name Text The description of the choice item.
vote_results Number The number of times this item has been voted.

4) User_Votes - This table stores the details of each users vote. Since we want a user to only vote once per poll we store his IP Address every time he votes.

Field Name Data Type Description
user_id AutoNumber Primary key field for this table.
vote_item_id Number The vote_item_id from the vote_items table, that the user has selected.
vote_id Number The vote_id from the vote_details table.
user_ip Text The IP Address of the user.
vote_date DateTime The DateTime when the user voted.

This completes the database design, the relationships between the tables is shown in figure 1 below.


Figure 1: Tables Relationships

Code Charge Studio Project

Creating a New Project
Once the database is ready its time to start you designing your application in CodeCharge Studio. Start up CCS and you will be shown the Project Dialog (see figure 2). Select New Project and click OK to start with a new CCS project.


Figure 2: Project Dialog

Using the Application Builder
The Add New Project dialog (figure 3) is displayed now, enter PollApp as the Name of the application and change the Language to ASP.NET 1.0 C#. At this point you have two choices, either you can start a blank project and then manually add each page to your project or you can use the Application Builder which rapidly builds the entire application with just a few clicks. To lessen our work, I choose Application Builder and click OK to start the Application Builder. 


Figure 3: Create new Project

In the first General project properties page, don't change any properties and click Next to come to the database setup page. Here click on the Create button to create a new connection to our vote.mdb database. The Add New Connection dialog is shown, set the Connection Name as VoteDB and Database as MS Access. Its very important to set up the database, since Code Charge Studio uses this information to construct SQL queries appropriately for the database.
Also in case you want to use another database connection on the production server or you want to use specific Managed Providers like SqlClient Managed Provider or the ODBC Managed Provider, switch to the Server tab in the Add New Connection dialog and setup the properties there.
For this example click the Build button and link to your vote.mdb database file. Once done click OK to add a connection to the project.


Figure 4: Add New Connection

Once you finish building the database connection click Next to come to the Builder Options screen. Here let the default properties of Enable smart naming, which helps to name the different pages and Autoincremented primary keys be checked. Proceed forward by clicking the Next button, now you are presented with a Access Authentication page. Set the setting the appropriate properties the page looks like below (figure 5). The User Table Field contains the table name in the database which stores the user details, the User ID Field contains the primary key field of the table, the Login Field contains the username field and the Password Field contains the password file from the table. The last Level/Group Field is set when you have Roles defined for your users. The Panel next to is also concerned with Roles. Since in this basic application we do not have any roles we leave them to their default values.


Figure 5: Authentication Settings

Once you finish the above settings click Next to move to the next page where you are given a list of tables from the database. Add all the tables to the Selected tables collection. This page helps you select the tables for which you want the builder to auto-generate the pages. Since in my case, I want to create a page to administer all the tables I select all of them. Click Next to arrive to the pages configuration step.


Figure 6: Page Configuration

This step is a very important step, and it gives you one place access to configure all your pages. Play around with this step as much as you can to better configure your pages. I will be outlining very few customization options, you will have to find others yourself ;).
First click on the All link since we want to update the properties for all the pages. Select both properties on this dialog (figure 7), the Search, Grid & Record on One Page option allows easy configuration and viewing of all the relevant options on one page. Remember the Grid form is used to list the contents of a table, the search form is used to search the table and show relevant records in the Grid form and the Record form is used to insert, update or delete a entry.
To collate all the forms on one page is good when you know the amount of data is less. The second option of Include in Menu allows the pages to be listed in a Menu , which is added on all pages for easy navigation. Click OK to close the dialog.


Figure 7: All Page details

Now, we will start configuring individual pages. Set the CheckBoxes to as shown below (figure 8). Basically I have removed Search option for all pages, since the data will be less. Also I have removed the Record and Updatable checkboxes for the user_votes page, since usually we don't rig poll's, do we ?? :)
Hence you will just be able to browse the list of users polling, but not directly add or update their details.


Figure 8: Updated page properties

Click the members link now to configure the properties for the members page. Switch directly to the Records tab and select the member_id field. Change the Control Type to Hidden (as shown in figure 9). We take this step since we do not want the admin to change the member_id field since its a primary key field.
Repeat the same steps for the vote_id field on the vote_details page and the vote_item_id on the vote_items field to convert them into Hidden controls on the Record form.


Figure 9: members Record form properties

Once you finish configuring the pages, click Next to come to the Select Page Layout section. Keep the default options and select Next to move to the Theme selection step. In this step you can select any of the Theme you want to apply throughout your application. I have selected InLine Theme (figure 10), you can select any theme you like and click Next. The final page in the Application Builder is shown, it summarizes the steps to be performed. This would be your last chance to go back and change any settings you might have left. If everything has been correctly setup click on Finish to generate the project.


Figure 10: Select Theme

Once the Application Builder completes CodeCharge Studio will automatically generate 7 pages for you depending upon the properties you have selected. 2 are User Controls used for the Header and Footer respectively while 1 handles the login, rest 4 pages are specific to your tables. You can view these pages from the Project Explorer window. I am sure you might have not seen a faster way of creating customized ASP.NET data-bound pages which can be created so easily! I mean if you switch to the Code View for each page, you will find that so much of code as been written for you, without you actually writing a single line of code by your hand!!

Publishing the Project
Now that you have come so far, you would be definitely waiting to check out how the code works, well we no further delay we publish our project so that the pages are uploaded to the server, and the code is compiled. Press F9 or select Project menu -> Publish Project to bring up the Project Settings dialog. If you have a local server use the default options, else select FTP from the Location dropdownlist and provide the appropriate credentials for your server. Click OK to compile and publish the project. If the project publishing directory does not exist on the local server you are prompted to create it.

Creating a Virtual Directory
All ASP.NET applications live within a Virtual Directory, so just publishing to a new directory is not enough, you need to convert this directory into a Virtual Directory. Use the IIS Manager from Administrative Tools to create a new Virtual Directory out of your publishing directory. You can also refer to the 2nd point of below linked article to learn to create a Virtual Directory.
[ www.mastercsharp.com/article.aspx?ArticleID=60&&TopicID=2 ]
Please do not skip this step or your application will give errors!!

Testing the pages
Once you have published your project, and created a Virtual Directory you are ready to test you pages. Navigate to the URL http://localhost/PollApp/members_list.aspx in your browser. Also add a new member with the Name admin and Pass admin. Some of you might be slightly worried at this point that the password textbox shows the password in clear text, well Code Charge Studio has no way of knowing from the database schema that you require a password textbox. So you can open the members_list page in CCS and change the Format->type property of the textbox to password.
There will be room for more such small adjustments, most of them can be fixed by adjusting the appropriate properties in CCS.

Live Page
Once you have published the project, you can shift to using Live Page tab for each page. This helps to have a quick look at the actual page that you have coded. When you shift to Live Page, CCS generates the current page and the necessary common files and compiles them. In order for the Live Page to show faster CCS does not generate all the pages, hence if you navigate (redirect) to another page from Live Page it will give an error!!

Adding a Index Page
Let's add a simple page that will contain a link to all the Admin pages, so its easier to navigate to them. Choose New -> Page from the File menu, in the New Page dialog choose Blank Page and set its name as admin and click OK.
Open the admin page in CCS Design view, and from the Toolbox window switch to the HTML controls. Select the Add HyperLink control and add the links to all the Admin pages (figure 11). Once you add the links to all pages, save the project.


Figure 11: Add Hyperlinks

Restricting Access to Pages
You might have noticed that even though the login page has been generated, you can freely access all the pages. But the admin pages should be restricted right ?? Well you have to manually set a property of the Pages in CCS you want only only authorized users to access. Select the members_list page in the Project Explorer and then from the Properties window set the Restricted property to Yes. Similarly set the other 4 pages admin, vote_detai_list, vote_items_list and user_votes_list Restricted property to Yes. Once done, save and publish your files. Now when you test your applications you will have to first enter your credentials ( admin/admin - remember we created this earlier) only then you will be able to access the pages.
CodeCharge Studio relies on Session based security, so once authenticated the user remains logged into the system for 20 minutes after which the session timeout occurs (default ASP.NET setting). You can although increase this timeout lime in the web.config file.


Figure 12: Restricted Property

Conclusion
In this part of the article we learnt how to create a quick admin section using CodeCharge Studio for our Poll application. You might have also noticed that we have accomplished all this in very little time and with virtually Zero lines of code. Also since all the code is auto-generated by CodeCharge Studio you don't have to sit and debug the application, it just works!!
Hopefully my rants in the previous article do seem true to you, we'll have lot to see further going. As an exercise go through the pages in CodeCharge Studio and rename all the column headers appropriately and arrange record forms appropriately, remember in most cases all you need to do is select the item in Design Editor and change its properties from the Properties explorer.

 

  
Saurabh Nandu - 26 July 2002


Your Ratings / Comments
     
 

[Go to Top]

How many cups of coffee is this article worth??

Rating (Bad)-(Excellent)

Your Name
Your E-mail  
Your Message (Optional)

Viewer Ratings/Comments
Rating Description
1 - 1 on 8/3/2002 11:35:00 AM
1 fsdfsdf - dfs on 10/16/2002 12:33:00 PM
1 - sss on 6/3/2004 12:23:00 AM
2 - David on 11/30/2004 12:54:00 PM
2 - arvind on 5/10/2005 2:41:00 AM
2 dfasdfa - sxfas on 6/9/2005 2:47:00 PM
5 - Elizabeth Azmoodeh on 11/20/2005 9:26:00 PM
1 fghfghfghfg - fghfg on 11/28/2005 10:37:00 AM
2 Good but improve - saadfsadfasf on 9/7/2006 4:57:00 AM
2 am i the only one to comment on this shit? - shadow on 10/12/2006 12:08:00 PM
3 hi , i am ved i have one query regarding Visualc# in which i want to select one item from list1 and want to get the value of same index from second list list2 like if i select one item from list1 which has index no 2 then i need to display the same index value of list2 thanks ved - ved on 11/28/2006 3:28:00 AM
Just Comments <h1>I like it</h1> - Adam on 6/4/2008 3:49:00 PM
5 testing - ixz on 6/5/2008 12:01:00 AM
4 testing2 - ixz on 6/5/2008 12:02:00 AM
5 testing - test on 6/5/2008 12:28:00 AM
1 sdfsfsfd - dsfsda on 5/17/2009 7:46:00 AM
1 aaaa - farhan on 3/15/2010 5:45:00 AM
1 - nasreen on 7/26/2010 9:39:00 AM
3 - ff on 8/20/2010 7:10:00 AM

[Go to Top]


 
 
  Copyright © 2002 - 2004 MasterCSharp.com. All rights are reserved.

  Presenting MasterCSharp.com in association with AksTech Solutions - .NET Solutions Development and Consulting. 

  Best Viewed in IE 4.0+ and 800x600 Resolution