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

ASP.NET TimeTracker Starter Kits Porting from Windows to Linux (Race to Linux)

Rate me:
Please Sign up or sign in to vote.
2.84/5 (9 votes)
5 Oct 20055 min read 70.6K   388   21  
ASP.NET TimeTracker Starter Kits Porting from Windows to Linux using Mainsoft's Grasshopper
<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.Data;
<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">    // UserDetail.aspx</font>
<font color= "green">    //</font>
<font color= "green">    // The UserDetail.aspx page is used to add new user or make changes to</font>
<font color= "green">    // existing users.</font>
<font color= "green">    // In addition, user Roles are added and changed on this page.</font>
<font color= "green">    // Only members of the Admin Role can access this page.</font>
<font color= "green">    //</font>
<font color= "green">    //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">    public class</font> UserDetail : System.Web.UI.Page
<font color= "blue">    </font>{
<font color= "blue">        protected </font>System.Web.UI.WebControls.Button Save;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Button Cancel;
<font color= "blue">        protected </font>System.Web.UI.WebControls.TextBox    UserName;
<font color= "blue">        protected </font>System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
<font color= "blue">        protected </font>System.Web.UI.WebControls.DropDownList Roles;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Label lblError;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Label ErrorLabel;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Label ErrorLabel2;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Label userNamelbl;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Label rolelbl;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Label displayNamelbl;
<font color= "blue">        protected </font>System.Web.UI.WebControls.TextBox DisplayName;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Label passwordlbl;
<font color= "blue">        protected </font>System.Web.UI.WebControls.TextBox Password;
<font color= "blue">        protected </font>System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
<font color= "blue">        protected </font>System.Web.UI.WebControls.Label confirmPasswordlbl;
<font color= "blue">        protected </font>System.Web.UI.WebControls.TextBox ConfirmPassword;
<font color= "blue">        protected </font>System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
<font color= "blue">        protected </font>System.Web.UI.WebControls.CompareValidator CompareValidator1;
<font color= "blue"></font>
<font color= "green">        //Use TTUser component to capture user's input during edit mode</font>
<font color= "blue">        private </font>TTUser user = new TTUser();
<font color= "blue">        </font>
<font color= "green">        //*********************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // UserDetail page of the Application</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************</font>
<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.UserRoleAdministrator) == 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>(!Page.IsPostBack)<font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>BindInfo();
<font color= "blue"></font>
<font color= "green">                //Hide fields for editing/adding windows authenticated users</font>
<font color= "blue"></font><font color= "blue">                if </font>((user.Password == "" && user.UserID != 0) || (Context.User.Identity.AuthenticationType != "Forms" && user.UserID==0))<font color= "blue"></font>
<font color= "blue">                </font>{
<font color= "blue">                    </font>displayNamelbl.Visible = false;
<font color= "blue">                    </font>DisplayName.Visible = false;
<font color= "blue">                    </font>passwordlbl.Visible = false;
<font color= "blue">                    </font>Password.Visible = false;
<font color= "blue">                    </font>confirmPasswordlbl.Visible = false;
<font color= "blue">                    </font>ConfirmPassword.Visible = false;
<font color= "blue">                    </font>RequiredFieldValidator3.Visible= false;
<font color= "blue">                    </font>RequiredFieldValidator4.Visible= false;
<font color= "blue">                    </font>userNamelbl.Text = @"Username (Use the format: DOMAIN or Computer Name\Username )";
<font color= "blue">                </font>}
<font color= "blue">               </font>}
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "green">        //*********************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The BindInfo method retrieves the list of roles </font>
<font color= "green">        // and Load User information if user exists</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> BindInfo()
<font color= "blue">        </font>{    
<font color= "green">            // Gets UserName from querystring</font>
<font color= "green">            // This value should by pass in by UserList.aspx</font>
<font color= "blue">            </font>string User = Request.QueryString["UserName"];
<font color= "blue"></font>
<font color= "blue">            </font>Roles.DataSource = BusinessLogicLayer.Roles.GetRoles();
<font color= "blue">            </font>Roles.DataTextField = "Name";
<font color= "blue">            </font>Roles.DataValueField = "RoleID";
<font color= "blue">            </font>Roles.DataBind();
<font color= "blue">            </font>
<font color= "blue"></font><font color= "blue">            if </font>(User != null)<font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>user.UserName = User;
<font color= "blue">                </font>user.Load();
<font color= "blue">                </font>UserName.Text = user.UserName;
<font color= "blue">                </font>UserName.ReadOnly = true;
<font color= "blue">                </font>Roles.Items.FindByValue(user.Role).Selected = true;
<font color= "blue">                </font>DisplayName.Text = user.DisplayName;
<font color= "blue">            </font>}
<font color= "blue"></font><font color= "blue">            else</font><font color= "blue"></font>
<font color= "blue">            </font>{
<font color= "blue">                </font>UserName.ReadOnly = false;
<font color= "blue">            </font>}
<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.Save.Click += new System.EventHandler(this.Save_Click);
<font color= "blue">            </font>this.Cancel.Click += new System.EventHandler(this.Cancel_Click);
<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 SaveButton_Click event handler saves the configuration of the user.</font>
<font color= "green">        // It updates if the current user id is not 0 and inserts if it is 0.</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> Save_Click(object sender, System.EventArgs e)
<font color= "blue">        </font>{
<font color= "blue">            </font>bool isUserFound = false;
<font color= "blue">            </font>bool isUserActiveManager = false;
<font color= "blue"></font>
<font color= "green">            // Save the user and ask the user object to make sure the username is</font>
<font color= "green">            // found in the user account source (NT SAM or Active Directory)</font>
<font color= "blue">            </font>user.UserName = TTSecurity.CleanStringRegex(UserName.Text);
<font color= "blue">            </font>user.Load();
<font color= "blue">            </font>user.Role = Roles.SelectedItem.Value;
<font color= "blue">            </font>user.DisplayName = TTSecurity.CleanStringRegex(DisplayName.Text);
<font color= "blue"></font><font color= "blue">            if </font>(Password.Text != string.Empty)<font color= "blue"></font>
<font color= "blue">                </font>user.Password = TTSecurity.Encrypt(Password.Text);
<font color= "blue">            </font>user.Save(true, ref isUserFound, ref isUserActiveManager);
<font color= "blue"></font>
<font color= "green">            // If we're adding a new user to the system and the username is not found in</font>
<font color= "green">            // the user account source (i.e. Active Directory or NT SAM), then we will</font>
<font color= "green">            // not allow the user to be added to our Time Tracker database.  Display an error</font>
<font color= "green">            // message so the user knows what happened.</font>
<font color= "blue"></font><font color= "blue">            if </font>(user.UserID == 0 && !isUserFound)<font color= "blue"></font>
<font color= "blue">                </font>ErrorLabel.Text = "The username was not found on your system or network.";
<font color= "blue"></font><font color= "blue">            else if </font>(isUserActiveManager)<font color= "blue"></font>
<font color= "blue">                </font>ErrorLabel.Text = "User Role can not be changed, user is a manager of one or more projects.";
<font color= "blue">                </font>
<font color= "blue"></font><font color= "blue">            else</font><font color= "blue"></font>
<font color= "blue">                </font>Response.Redirect("UserList.aspx?index=2&adminIndex=1", false);
<font color= "blue">        </font>}
<font color= "blue"></font>
<font color= "green">        //*********************************************************************</font>
<font color= "green">        //</font>
<font color= "green">        // The Cancel_Click event handler undo changes and redirect to UserList page</font>
<font color= "green">        //</font>
<font color= "green">        //*********************************************************************</font>
<font color= "blue"></font>
<font color= "blue">        private void</font> Cancel_Click(object sender, System.EventArgs e)
<font color= "blue">        </font>{
<font color= "blue">            </font>Response.Redirect("UserList.aspx?index=2&adminIndex=1", false);
<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
Architect
Australia Australia
"Impossible" + "'" + " " = "I'm Possible"

Started programming when i was a kid with 286 computers and Spectrum using BASIC from 1986. There was series of languages like pascal, c, c++, ada, algol, prolog, assembly, java, C#, VB.NET and so on. Then shifted my intrest in Architecture during past 5 years with Rational Suite and UML. Wrote some articles, i was member of month on some sites, top poster(i only answer) of week (actually weeks), won some books as prizes, rated 2nd in ASP.NET and ADO.NET in Australia.

There is simplicity in complexity

Comments and Discussions