![]() |
|||||
| :: Home |
| :: Solutions |
| :: Contact Us |
| :: About Us |
This document describes the iGrants programming methodology.
iGrants is written in c#, and is separated into multiple projects so programmers can work independently:
Code Overview
The following page load event for the screen which presents the seven steps in the selections. A simplified walk through would be:
standard page start code:
For new page entry, look up additional information and store it in session variables
If we are posting back, then:
private void Page_Load(object sender, System.EventArgs e)
#region functionCode
{
#region standard page start code
lib.sessionChecker();
lib.NoPageCaching();
#endregion
if (!IsPostBack)
{
#region show profile page unless another was selected
Session[ses.lastFormPackageName]=lib.DBGetItem("select name from formPackageLookup where formPackageID=" + Session[ses.formPackageID]);
if (Session[ses.selectionStepsSelection].ToString() == "")
{
Session[ses.selectionStepsSelection] = itab.selectionSteps.s1profile;
}
#endregion
}
else
{
#region parseActionVerbThenSaveChangesAndNavigate
lib.parseActionVerb();
#region saveChangesIfSaveButtonClicked
string savedStepsSelection = Session[ses.selectionStepsSelection].ToString();
if (Session[ses.actionVerb].ToString() == cns.actionVerbs.save.ToString())
{
if (savedStepsSelection == itab.selectionSteps.s1profile.ToString())
{
pageDoStep1(cns.actionVerbs.save); //profile
}
if (savedStepsSelection == itab.selectionSteps.s2contact.ToString())
{
pageDoStep2(cns.actionVerbs.save); //contact
}
if (savedStepsSelection == itab.selectionSteps.s3declare.ToString())
{
pageDoStep3(cns.actionVerbs.save); //declare
}
if (savedStepsSelection == itab.selectionSteps.s4parts.ToString())
{
pageDoStep4(cns.actionVerbs.save); //pages
}
if (savedStepsSelection == itab.selectionSteps.s5budget.ToString())
{
pageDoStep5(cns.actionVerbs.save); //budget items
}
if (savedStepsSelection == itab.selectionSteps.s6finish.ToString())
{
pageDoStep6(cns.actionVerbs.save); //budget items
}
if (savedStepsSelection == itab.selectionSteps.s7notify.ToString())
{
pageDoStep7(cns.actionVerbs.save); //budget items
}
if (savedStepsSelection == itab.selectionSteps.notes.ToString())
{
pageDoNotes(cns.actionVerbs.save); //notes
}
}
#endregion
#region if leaving the page go now
if (Session[ses.actionVerb].ToString()==cns.actionVerbs.redirect.ToString())
{
nav.NavTransfer(int.Parse(Session[ses.actionPage].ToString()));
}
#endregion
#region set the step selection to whatever was clicked
//could turn this into a function
if (Session[ses.actionVerb].ToString() == cns.navModes.subNavModes.step1.ToString())
{
Session[ses.selectionStepsSelection] = itab.selectionSteps.s1profile;
//initialize budget creation step to 0 since the person selected another tab
Session[ses.subStepForSelectedTab] = "0";
Session[ses.createBudgetStep] = 0;
}
if (Session[ses.actionVerb].ToString() == cns.navModes.subNavModes.step2.ToString())
{
Session[ses.selectionStepsSelection] = itab.selectionSteps.s2contact;
//initialize budget creation step to 0 since the person selected another tab
Session[ses.subStepForSelectedTab] = "0";
Session[ses.createBudgetStep] = 0;
}
if (Session[ses.actionVerb].ToString() == cns.navModes.subNavModes.step3.ToString())
{
Session[ses.selectionStepsSelection] = itab.selectionSteps.s3declare;
//initialize budget creation step to 0 since the person selected another tab
Session[ses.subStepForSelectedTab] = "0";
Session[ses.createBudgetStep] = 0;
}
if (Session[ses.actionVerb].ToString() == cns.navModes.subNavModes.step4.ToString())
{
Session[ses.selectionStepsSelection] = itab.selectionSteps.s4parts;
//initialize budget creation step to 0 since the person selected another tab
Session[ses.subStepForSelectedTab] = "0";
Session[ses.createBudgetStep] = 0;
}
if (Session[ses.actionVerb].ToString() == cns.navModes.subNavModes.step5.ToString())
{
Session[ses.selectionStepsSelection] = itab.selectionSteps.s5budget;
//initialize budget creation step to 0 since the person selected another tab
Session[ses.subStepForSelectedTab] = "0";
Session[ses.createBudgetStep] = 0;
}
if (Session[ses.actionVerb].ToString() == itab.step5BudgetSteps.createBudget.ToString())
{
Session[ses.subStepForSelectedTab] = "0";
Session[ses.budgetTabsSelection] = itab.step5BudgetSteps.createBudget;
}
if (Session[ses.actionVerb].ToString() == itab.step5BudgetSteps.inprocessBudgets.ToString())
{
Session[ses.subStepForSelectedTab] = "0";
Session[ses.budgetTabsSelection] = itab.step5BudgetSteps.inprocessBudgets;
}
if (Session[ses.actionVerb].ToString() == cns.navModes.subNavModes.step6.ToString())
{
Session[ses.selectionStepsSelection] = itab.selectionSteps.s6finish;
//initialize budget creation step to 0 since the person selected another tab
Session[ses.createBudgetStep] = 0;
Session[ses.subStepForSelectedTab] = "0";
}
if (Session[ses.actionVerb].ToString() == cns.navModes.subNavModes.step7.ToString())
{
Session[ses.selectionStepsSelection] = itab.selectionSteps.s7notify;
//initialize budget creation step to 0 since the person selected another tab
Session[ses.createBudgetStep] = 0;
Session[ses.subStepForSelectedTab] = "0";
}
if (Session[ses.actionVerb].ToString() == cns.navModes.subNavModes.notes.ToString())
{
Session[ses.selectionStepsSelection] = itab.selectionSteps.notes;
//initialize budget creation step to 0 since the person selected another tab
Session[ses.createBudgetStep] = 0;
Session[ses.subStepForSelectedTab] = "0";
}
#endregion
#endregion
}
refreshPage();
}
#endregion
As you can see, session variables are used to a great extent to store values. A repeated theme in this code is the creation of 'unselected collections' to minimize database interactions. For example, a set of tabs is defined in a database, and the database is queried once for the tab information and a long HTML string is built to define those tabs. At the time the HTML is built, no tab is selected, and the HTML is stored in a session variable. When it is time to display the tabs, the word 'selected' is inserted after the name of the image of the currently-selected tab.
This same concept is used for drop-down lists so that the database is queried only once, and the HTML for the list is stored in session or cache memory and shown later.
Since a single .aspx file is used to show and save countless possible pages, most page content does not use the ViewState feature of .net. Placeholders are used so that the form or dynamic area of the page can have any type of content.
Here is an example of the code used to save or present a page which uses .net objects on the page:
protected void pageDoStep1(string whichAction)
#region profile page
{
string formPackageID = Session[ses.formPackageID].ToString();
if (whichAction == cns.actionVerbs.save)
{
lib.dbexec("update formPackageLookup set profile=" + lib.sq(Request["profile"]) + " where formPackageID=" + formPackageID);
}
else
{
if (Session[ses.savedMessage].ToString() != "")
{
plcNav.Controls.Add(new LiteralControl(Session[ses.savedMessage].ToString()));
Session[ses.savedMessage] = "";
}
plcNav.Controls.Add(new LiteralControl("<center>"));
TextBox txtProfile = new TextBox();
txtProfile.ID = "profile";
txtProfile.EnableViewState = false;
txtProfile.Text = lib.DBGetItem("select profile from formPackageLookup where formPackageID=" + formPackageID);
txtProfile.TextMode = TextBoxMode.MultiLine;
txtProfile.MaxLength = 5000;
txtProfile.Rows = 40;
txtProfile.Columns = 80;
plcNav.Controls.Add(new LiteralControl("<br>" + txtProfile.Text));
plcNav.Controls.Add(new LiteralControl("<hr>The following section will be shown for site admins only:<br>"));
plcNav.Controls.Add(txtProfile);
plcNav.Controls.Add(new LiteralControl("<br>" + lib.HTMLSaveChangesButton()+ @"</center>"));
}
}
#endregion
NavProgramEdit.aspx contains examples of every code method used in this project.
This document does not present the use of the FormBase functions which will be used extensively to present and store pages.
| © Copyright 2004 Kuwago Inc. All Rights Reserved. |