Click here to Skip to main content
15,891,845 members
Articles / Web Development / ASP.NET

Race to Linux - Race 2: Time Tracker Starter Kit

Rate me:
Please Sign up or sign in to vote.
4.25/5 (5 votes)
26 Sep 20051 min read 40.4K   274   16  
Time Tracker Starter Kit port to Linux using Mono and FireBird
<html><head><link rel=stylesheet href=style.css></head><body><div class=SourcePanel style='font-size:12'><pre style='background-color:white'>
<font color= "blue">using</font> System;
<font color= "blue">using</font> System.Web.UI.WebControls;
<font color= "blue">using</font> ASPNET.StarterKit.TimeTracker.BusinessLogicLayer;
<font color= "blue"></font>
<font color= "blue">namespace</font> ASPNET.StarterKit.TimeTracker.Web
<font color= "blue"></font>{
<font color= "green">    //*********************************************************************</font>
<font color= "green">    //</font>
<font color= "green">    // ProjectList.aspx</font>
<font color= "green">    //</font>
<font color= "green">    // The ProjectList.aspx is used to display the list of projects available.</font>
<font color= "green">    // Only members of the Admin or Manager Role can access this page.</font>
<font color= "green">    // Members of the Admin group will see all projects and members of the</font>
<font color= "green">    // Managers group will see only the projects they are managing.</font>
<font color= "green">    //</font>
<font color= "green">    //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">    public class</font> ProjectList : System.Web.UI.Page
<font color= "blue">    </font>{
<font color= "blue">        protected </font>System.Web.UI.WebControls.LinkButton    LinkButton1;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Button        NewProjectButton;
<font color= "blue">        protected </font>System.Web.UI.WebControls.DataGrid    ProjectsGrid;
<font color= "blue"></font>
<font color= "blue">        private void</font> Page_Load(object sender, System.EventArgs e)
<font color= "blue">        </font>{
<font color= "green">            // Ensure that the visiting user has access to view the current page</font>
<font color= "blue"></font><font color= "blue">            if </font>(TTSecurity.IsInRole(TTUser.UserRoleAdminPMgr) == false) <font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>Response.Redirect("AccessDenied.aspx?Index=-1", true);
<font color= "blue">            </font>}
<font color= "blue"></font>
<font color= "blue"></font><font color= "blue">            if </font>(!IsPostBack)<font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>BindProjects();
<font color= "blue">            </font>}
<font color= "blue">        </font>}
<font color= "blue">        </font>
<font color= "green">        //*********************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The BindProjects method retrieves the list of projects the current user</font>
<font color= "green">        // can view based on their role and then databinds them to the ProjectsGrid</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> BindProjects()
<font color= "blue">        </font>{
<font color= "blue">            </font>ProjectsCollection projectList = Project.GetProjects(TTSecurity.GetUserID(), TTSecurity.GetUserRole());
<font color= "blue"></font>
<font color= "green">            // Call method to sort the data before databinding</font>
<font color= "blue">            </font>SortGridData(projectList, SortField, SortAscending);
<font color= "blue"></font>
<font color= "blue">            </font>ProjectsGrid.DataSource = projectList;
<font color= "blue">            </font>ProjectsGrid.DataBind();
<font color= "blue">        </font>}
<font color= "blue">        </font>
<font color= "green">        //*********************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The SortGridData method is a helper method called when databinding the Projects grid </font>
<font color= "green">        // to sort the columns of the grid.</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> SortGridData(ProjectsCollection list, string sortField, bool asc)
<font color= "blue">        </font>{
<font color= "blue">            </font>ProjectsCollection.ProjectFields sortCol = ProjectsCollection.ProjectFields.InitValue;
<font color= "blue"></font>
<font color= "blue">            </font>switch(sortField)
<font color= "blue">            </font>{
<font color= "blue">                case</font> "Name":
<font color= "blue">                    </font>sortCol = ProjectsCollection.ProjectFields.Name;
<font color= "blue">                    </font>break;
<font color= "blue">                case</font> "Manager":
<font color= "blue">                    </font>sortCol = ProjectsCollection.ProjectFields.ManagerUserName;
<font color= "blue">                    </font>break;
<font color= "blue">                case</font> "Completion":
<font color= "blue">                    </font>sortCol = ProjectsCollection.ProjectFields.CompletionDate;
<font color= "blue">                    </font>break;
<font color= "blue">                case</font> "Duration":
<font color= "blue">                    </font>sortCol = ProjectsCollection.ProjectFields.Duration;
<font color= "blue">                    </font>break;
<font color= "blue">                </font>default:
<font color= "blue">                    </font>break;
<font color= "blue">            </font>}
<font color= "blue"></font>
<font color= "blue">            </font>list.Sort(sortCol, asc);
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "blue">        </font>#region Web Form Designer generated code
<font color= "blue">        </font>override protected void OnInit(EventArgs e)
<font color= "blue">        </font>{
<font color= "green">            //</font>
<font color= "green">            // CODEGEN: This call is required by the ASP.NET Web Form Designer.</font>
<font color= "green">            //</font>
<font color= "blue">            </font>InitializeComponent();
<font color= "blue">            </font>base.OnInit(e);
<font color= "blue">        </font>}
<font color= "blue">        </font>
<font color= "green">        /// <summary></font>
<font color= "green">        /// Required method for Designer support - do not modify</font>
<font color= "green">        /// the contents of this method with the code editor.</font>
<font color= "green">        /// </summary></font>
<font color= "blue">        private void</font> InitializeComponent()
<font color= "blue">        </font>{    
<font color= "blue">            </font>this.NewProjectButton.Click += new System.EventHandler(this.NewProjectButton_Click);
<font color= "blue">            </font>this.ProjectsGrid.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.ProjectsGrid_Sort);
<font color= "blue">            </font>this.Load += new System.EventHandler(this.Page_Load);
<font color= "blue"></font>
<font color= "blue">        </font>}
<font color= "blue">        </font>#endregion
<font color= "blue"></font>
<font color= "green">        //*********************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The NewProjectButton_Click event handler redirects to the ProjectDetails.aspx </font>
<font color= "green">        // page so the user can create a new project.</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> NewProjectButton_Click(object sender, System.EventArgs e)
<font color= "blue">        </font>{
<font color= "blue">            </font>int mainIndex = (Request["index"]==null) ? 0 : Convert.ToInt32(Request["index"]);
<font color= "blue">            </font>int adminIndex = (Request["adminindex"]==null) ? 0 : Convert.ToInt32(Request["adminindex"]);
<font color= "blue">            </font>Response.Redirect(String.Format("ProjectDetails.aspx?index={0}&adminindex={1}", mainIndex, adminIndex), false);
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "green">        //*********************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The ProjectsGrid_Page event handler sets the index of the currently displayed </font>
<font color= "green">        // page for the Projects grid and re-binds it.</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        protected void</font> ProjectsGrid_Page(Object sender, DataGridPageChangedEventArgs e) 
<font color= "blue">        </font>{
<font color= "blue">            </font>ProjectsGrid.CurrentPageIndex = e.NewPageIndex;
<font color= "blue"></font>
<font color= "blue">            </font>BindProjects();
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "green">        //*********************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The ProjectGrid_Sort event handler changes the sortfield for the Projects grid </font>
<font color= "green">        // and re-binds it.</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> ProjectsGrid_Sort(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
<font color= "blue">        </font>{
<font color= "blue">            </font>SortField = e.SortExpression;
<font color= "blue"></font>
<font color= "blue">            </font>BindProjects();
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "blue">        </font>string SortField 
<font color= "blue">        </font>{
<font color= "blue">            get</font> 
<font color= "blue">            </font>{
<font color= "blue">                </font>object o = ViewState["SortField"];
<font color= "blue"></font><font color= "blue">                if </font>(o == null) <font color= "blue"></font>
<font color= "blue">                </font>{
<font color= "blue">                    return</font> String.Empty;
<font color= "blue">                </font>}
<font color= "blue">                return</font> (string)o;
<font color= "blue">            </font>}
<font color= "blue"></font>
<font color= "blue">            set</font> 
<font color= "blue">            </font>{
<font color= "blue"></font><font color= "blue">                if </font>(value == SortField) <font color= "blue"></font>
<font color= "blue">                </font>{
<font color= "green">                    // same as current sort file, toggle sort direction</font>
<font color= "blue">                    </font>SortAscending = !SortAscending;
<font color= "blue">                </font>}
<font color= "blue">                </font>ViewState["SortField"] = value;
<font color= "blue">            </font>}
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "green">        //*********************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // SortAscending property is tracked in ViewState</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        </font>bool SortAscending 
<font color= "blue">        </font>{
<font color= "blue">            get</font> 
<font color= "blue">            </font>{
<font color= "blue">                </font>object o = ViewState["SortAscending"];
<font color= "blue"></font><font color= "blue">                if </font>(o == null) <font color= "blue"></font>
<font color= "blue">                </font>{
<font color= "blue">                    return</font> true;
<font color= "blue">                </font>}
<font color= "blue">                return</font> (bool)o;
<font color= "blue">            </font>}
<font color= "blue"></font>
<font color= "blue">            set</font> 
<font color= "blue">            </font>{
<font color= "blue">                </font>ViewState["SortAscending"] = value;
<font color= "blue">            </font>}
<font color= "blue">        </font>}
<font color= "blue">    </font>}
<font color= "blue"></font>}
</pre>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Uruguay Uruguay
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions