Administrator Recipe: Add Project


Beyond the ability to add new jobs, the administrator must also be able to add new projects. The Add Project page allows the creation of a new project and the assigning of a manager, an hours budget, and a method to track the timeline. The hours budget is an estimate of how long the project is expected to take. As the time cards related to the project are submitted, the time reported is subtracted from the hours budget. With these figures, the actual time spent on the project can be compared with the initial estimate. The final element on the Add Project page is a list that lets the administrator establish an estimated timeline for the project.

As with the Add Job Code recipe, the Insert Record server behavior is used to implement the server-side logic for this page.

Step 1: Implement Add Project Design

The Add Project layout is only slightly more complex than the preceding recipe. In addition to three text fields (one each for the project name, manager, and hours budget), it uses a drop-down list with static values displaying the number of weeks for a project. Our snippet example creates a list element from 1 to 20 weeks as well as an extra option for 1/2 week. You should, of course, create names and values that reflect your own project timelines.

1.

Create a dynamic page for your server model.

In the TimeCards folder, locate the folder for your server model and open the add_project page from there.

2.

Insert a table into the content region of your page to hold the needed form elements.

From the Snippets panel, drag the Recipes > TimeCards > Wireframes > Add Project - Wireframe snippet into the Content editable region.

3.

Insert the form and, within it, a two-column table. The table should include form text fields and labels for a project name, a project manager, and an hours budget. It should also include a select list displaying a number of week options. Finally, a form button is required to insert the new record.

Place your cursor in the row below the words ADD PROJECT and insert the Recipes > TimeCards > Forms > Add Project - Form snippet.

4.

Save the file [r5-2].

r5-2.


For PHP

MySQL doesn't have an easy way to automatically set the date when a new record is created. To work around this limitation, we'll use a brief bit of PHP code in a hidden form element to make a date stamp, which will later be inserted into the record.

1.

From the Form category of the Insert bar, drag a hidden field onto the page next to the Project Name label.

2.

With the hidden form element selected, enter curDate in the Name field of the Property inspector.

3.

In the Value field, enter the following code:

<?php echo Date("Y-m-d"); ?>


4.

Save your page.

Step 2: Insert RecordAdd Project

Because we're creating a new record, the Insert Record server behavior is the natural choice for our server-side code. To be consistent with the Add Job Code recipe, we'll set the server behavior to redirect the user to the same pagethe Project Summary pageafter the insert operation is complete.

For ASP

1.

From the Server Behaviors panel, choose Add (+) and select Insert Record from the list.

Note

To enhance this recipe, you might create a drop-down list that displays the names of all the managers in your company. To do this, you'll need to add a recordset of the Employee table filtered to show only the Manager position and attach that recordset to the values and labels of the list.

2.

In the Insert Record dialog, choose your data source.

Choose Recipes from the Connection list.

3.

Select the table you want to insert the record into.

From the Insert Into Table list, choose Projects.

4.

Set the page that you want to appear after the record is inserted.

Choose the report_projectsummary.asp file from your server model's folder for the After Inserting, Go To field.

5.

Select the form on the current page from which to gather the record values.

From the Get Values From list, make sure AddNewProject is selected.

6.

In the Form Elements area, match the form elements on the page to the fields in the data source table.

Set ProjectName to insert into the ProjectName column as Text type.

 

Set ProjectManager to insert into the ProjectManager column as Text type.

 

Set TaskHours to insert into the ProjectHours column as Numeric type.

 

Set ProjectWeek to insert into the Weeks column as Numeric type.


7.

When you're sure your choices are correct, click OK to close the dialog and add the behavior.

For ColdFusion and PHP

1.

From the Server Behaviors panel, choose Add (+) and select Insert Record.

2.

In the Insert Record dialog, choose the current form.

Select AddNewProject from the Submit Values From list.

3.

Select your data source from the list.

Choose Recipes from the Data Source list.

4.

Enter your username and password, if needed.

5.

Select the table in the data source to insert into from the list.

Choose Projects (projects in PHP) from the Insert Into Table list.

6.

Set the data source fields to their corresponding form elements.

Make sure the ProjectID data column is set to be an unused Primary Key.

 

Set ProjectName to the FORM.ProjectName form element and submit as Text type.

 

Set ProjectManager to the FORM.ProjectManager form element and submit as Text type.

 

Set TaskHours to the FORM.ProjectHours form element and submit as Numeric type (Double in PHP).

 

Set Weeks to the FORM.ProjectWeek form element and submit as Numerictype (Double in PHP).


Make sure the ProjectDate data column is set to Does Not Get a Value. The date will automatically be entered in the Access database when the record is created.

Set ProjectDate to the FORM.curDate form element and submit as Date type.

7.

In the After Inserting, Go To field, enter report_projectsummary.cfm or report_projectsummary.php as appropriate and click OK to close the dialog.

8.

Save your page.




Macromedia Dreamweaver 8 Recipes
Macromedia Dreamweaver 8 Recipes
ISBN: 0321393910
EAN: 2147483647
Year: 2003
Pages: 121

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net