Reorder namespaces of pages and controls
This commit is contained in:
67
Scrummer/Pages/FormUtils.cs
Normal file
67
Scrummer/Pages/FormUtils.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Controls;
|
||||
|
||||
namespace Scrummer.Pages
|
||||
{
|
||||
public class FormUtils
|
||||
{
|
||||
public static Control CreateField(string label, Control fieldControl)
|
||||
{
|
||||
Panel pnlRow = new Panel();
|
||||
pnlRow.CssClass = "formRow";
|
||||
|
||||
Panel pnlLabelContainer = new Panel();
|
||||
pnlLabelContainer.CssClass = "formLabel width25pc";
|
||||
pnlRow.Controls.Add(pnlLabelContainer);
|
||||
|
||||
if (string.IsNullOrEmpty(label) == false)
|
||||
{
|
||||
CLabel lblField = new CLabel();
|
||||
lblField.Text = label;
|
||||
pnlLabelContainer.Controls.Add(lblField);
|
||||
}
|
||||
|
||||
Panel pnlFieldContainer = new Panel();
|
||||
pnlFieldContainer.CssClass = "formField width75pc";
|
||||
pnlRow.Controls.Add(pnlFieldContainer);
|
||||
|
||||
pnlFieldContainer.Controls.Add(fieldControl);
|
||||
|
||||
return pnlRow;
|
||||
}
|
||||
|
||||
public static bool Control_IsValid(Control control)
|
||||
{
|
||||
if (control is IValidableControl)
|
||||
{
|
||||
if (((IValidableControl)control).IsValid() == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Controls_AreValid(ControlCollection controls) {
|
||||
bool valid = true;
|
||||
foreach (Control control in controls)
|
||||
{
|
||||
if (Control_IsValid(control))
|
||||
{
|
||||
if (Controls_AreValid(control.Controls) == false)
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Scrummer/Pages/FrmBoard.cs
Normal file
28
Scrummer/Pages/FrmBoard.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using Scrummer.Controls;
|
||||
|
||||
namespace Scrummer.Pages
|
||||
{
|
||||
public class FrmBoard : PageCommon
|
||||
{
|
||||
private int _idBoard = 0;
|
||||
|
||||
public FrmBoard()
|
||||
{
|
||||
Init += FrmBoard_Init;
|
||||
}
|
||||
|
||||
void FrmBoard_Init(object sender, EventArgs e)
|
||||
{
|
||||
Title = "Board";
|
||||
var lblTest = new CLabel { Text = "Hello World", Tag = "h2" };
|
||||
Controls.Add(lblTest);
|
||||
|
||||
ChatControl chatControl = new ChatControl();
|
||||
chatControl.ID = "ctrChat";
|
||||
chatControl.IDBoard = _idBoard;
|
||||
chatControl.UserName = CurrentUser.Name;
|
||||
Controls.Add(chatControl);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Scrummer/Pages/FrmEcho.cs
Normal file
25
Scrummer/Pages/FrmEcho.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Web;
|
||||
using Scrummer.Code.JSON;
|
||||
|
||||
namespace Scrummer.Pages
|
||||
{
|
||||
public class FrmEcho : IHttpHandler
|
||||
{
|
||||
#region IHttpHandler
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
var jsonWritter = new JSONWriter(true);
|
||||
context.Response.Write("<pre><code>");
|
||||
context.Response.Write(jsonWritter.Write(context.Request));
|
||||
context.Response.Write("</code></pre>");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
65
Scrummer/Pages/FrmError.cs
Normal file
65
Scrummer/Pages/FrmError.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Controls;
|
||||
|
||||
namespace Scrummer.Pages
|
||||
{
|
||||
public class FrmError : PageCommon
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
Exception _ex = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Page life cycle
|
||||
|
||||
public FrmError(Exception ex)
|
||||
{
|
||||
_ex = ex;
|
||||
Init += FrmError_Init;
|
||||
}
|
||||
|
||||
void FrmError_Init(object sender, EventArgs e)
|
||||
{
|
||||
InitializeControls();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void InitializeControls()
|
||||
{
|
||||
Title = "Application Error";
|
||||
|
||||
CLabel lblErrorTitle = new CLabel { Text = Title, Tag = "h2" };
|
||||
Controls.Add(lblErrorTitle);
|
||||
|
||||
Exception exAux = _ex;
|
||||
if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; }
|
||||
while (exAux != null)
|
||||
{
|
||||
CLabel lblMessage = new CLabel { Tag = "P" };
|
||||
lblMessage.Text = String.Format("<b>{0}:</b> {1}", "Message", HttpUtility.HtmlEncode(exAux.Message));
|
||||
Controls.Add(lblMessage);
|
||||
|
||||
CLabel lblStacktraceTitle = new CLabel { Tag = "p" };
|
||||
lblStacktraceTitle.Text = String.Format("<b>{0}:</b>", "Stacktrace");
|
||||
Controls.Add(lblStacktraceTitle);
|
||||
Panel pnlStacktrace = new Panel();
|
||||
pnlStacktrace.CssClass = "divCode";
|
||||
Controls.Add(pnlStacktrace);
|
||||
LiteralControl litStackTrace = new LiteralControl(
|
||||
String.Format("<pre><code>{0}</code></pre>", HttpUtility.HtmlEncode(exAux.StackTrace)));
|
||||
pnlStacktrace.Controls.Add(litStackTrace);
|
||||
|
||||
exAux = exAux.InnerException;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
79
Scrummer/Pages/FrmLogin.cs
Normal file
79
Scrummer/Pages/FrmLogin.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Code.BusinessLogic;
|
||||
using Scrummer.Controls;
|
||||
|
||||
namespace Scrummer.Pages
|
||||
{
|
||||
public class FrmLogin : PageCommon
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private CTextBox _txtNameEmail = new CTextBox { ID = "txtNameEmail", CssClassExtra = "width150px", AllowEmpty = false };
|
||||
private CTextBox _txtPassword = new CTextBox { ID = "txtPassword", CssClassExtra = "width150px", AllowEmpty = false, TextMode = TextBoxMode.Password };
|
||||
private CButton _btnLogin = new CButton { ID = "btnLogin"};
|
||||
|
||||
#endregion
|
||||
|
||||
#region Page life cycle
|
||||
|
||||
public FrmLogin()
|
||||
{
|
||||
MustBeAutenticated = false;
|
||||
Init += FrmLogin_Init;
|
||||
}
|
||||
|
||||
private void FrmLogin_Init(object sender, EventArgs e)
|
||||
{
|
||||
InitializeControls();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI Events
|
||||
|
||||
private void btnLogin_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (FormUtils.Controls_AreValid(Controls) == false) { return; }
|
||||
|
||||
if (Users.Current.User_Authenticate(_txtNameEmail.Text, _txtPassword.Text) == false)
|
||||
{
|
||||
_txtPassword.Text = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
Sessions.Current.Session_Init(Context, _txtNameEmail.Text);
|
||||
Response.Redirect(".");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void InitializeControls()
|
||||
{
|
||||
Title = "Login";
|
||||
var lblTitle = new CLabel { Text = "Login", Tag = "h2" };
|
||||
Controls.Add(lblTitle);
|
||||
|
||||
Controls.Add(FormUtils.CreateField("Name/Mail", _txtNameEmail));
|
||||
_txtNameEmail.PlaceHolder = "Name/Mail";
|
||||
|
||||
Controls.Add(FormUtils.CreateField("Password", _txtPassword));
|
||||
_txtPassword.PlaceHolder = "Password";
|
||||
|
||||
Controls.Add(FormUtils.CreateField(String.Empty, _btnLogin));
|
||||
_btnLogin.Text = "Login";
|
||||
_btnLogin.Click += btnLogin_Click;
|
||||
|
||||
Controls.Add(FormUtils.CreateField(String.Empty, new HyperLink { Text = "Register user", NavigateUrl = "FrmRegister" }));
|
||||
|
||||
_txtNameEmail.Attributes.Add("onkeydown", String.Format(
|
||||
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _txtPassword.ClientID));
|
||||
_txtPassword.Attributes.Add("onkeydown", String.Format(
|
||||
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _btnLogin.ClientID));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
130
Scrummer/Pages/FrmRegister.cs
Normal file
130
Scrummer/Pages/FrmRegister.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Code.BusinessLogic;
|
||||
using Scrummer.Code.Entities;
|
||||
using Scrummer.Controls;
|
||||
|
||||
namespace Scrummer.Pages
|
||||
{
|
||||
public class FrmRegister : PageCommon
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private Panel _pnlRegister = new Panel { ID = "pnlRegister" };
|
||||
private CTextBox _txtName = new CTextBox { ID = "txtName", CssClassExtra = "width150px", AllowEmpty = false };
|
||||
private CTextBox _txtEmail = new CTextBox { ID = "txtEmail", CssClassExtra = "width150px", AllowEmpty = false };
|
||||
private CTextBox _txtPassword1 = new CTextBox { ID = "txtPassword1", CssClass = "width150px", AllowEmpty = false, TextMode = TextBoxMode.Password };
|
||||
private CTextBox _txtPassword2 = new CTextBox { ID = "txtPassword2", CssClass = "width150px", AllowEmpty = false, TextMode = TextBoxMode.Password };
|
||||
private CButton _btnRegister = new CButton { ID = "btnRegister" };
|
||||
private CButton _btnExit = new CButton { ID = "btnExit" };
|
||||
private Panel _pnlSuccess = new Panel { ID = "pnlSuccess" };
|
||||
private CLabel _lblSuccess = new CLabel { ID = "lblSuccess" };
|
||||
private CButton _btnExitSuccess = new CButton { ID = "btnExitSuccess" };
|
||||
|
||||
#endregion
|
||||
|
||||
#region Page life cycle
|
||||
|
||||
public FrmRegister()
|
||||
{
|
||||
MustBeAutenticated = false;
|
||||
Init += FrmRegister_Init;
|
||||
}
|
||||
|
||||
void FrmRegister_Init(object sender, EventArgs e)
|
||||
{
|
||||
InitializeComponents();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI Events
|
||||
|
||||
void btnRegister_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (FormUtils.Controls_AreValid(Controls) == false) { return; }
|
||||
|
||||
// FIXME: Check Email
|
||||
|
||||
// Check password
|
||||
if (_txtPassword1.Text != _txtPassword2.Text)
|
||||
{
|
||||
_txtPassword1.MarkedInvalid = true;
|
||||
_txtPassword2.MarkedInvalid = true;
|
||||
_txtPassword1.Text = String.Empty;
|
||||
_txtPassword2.Text = String.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
User user = Users.Current.User_Set(_txtName.Text, _txtEmail.Text, _txtPassword1.Text);
|
||||
|
||||
_pnlRegister.Visible = false;
|
||||
_pnlSuccess.Visible = true;
|
||||
_lblSuccess.Text = String.Format("User {0} created sucessfully", user.Name);
|
||||
}
|
||||
|
||||
void btnExit_Click(object sender, EventArgs e)
|
||||
{
|
||||
Response.Redirect(".");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void InitializeComponents()
|
||||
{
|
||||
Title = "Register";
|
||||
var lblTitle = new CLabel { Text = "Register", Tag = "h2" };
|
||||
Controls.Add(lblTitle);
|
||||
|
||||
Controls.Add(_pnlRegister);
|
||||
|
||||
_pnlRegister.Controls.Add(FormUtils.CreateField("Name", _txtName));
|
||||
_txtName.PlaceHolder = "Name";
|
||||
|
||||
_pnlRegister.Controls.Add(FormUtils.CreateField("Email", _txtEmail));
|
||||
_txtEmail.PlaceHolder = "Email";
|
||||
|
||||
_pnlRegister.Controls.Add(FormUtils.CreateField("Password", _txtPassword1));
|
||||
_txtPassword1.PlaceHolder = "Password";
|
||||
|
||||
_pnlRegister.Controls.Add(FormUtils.CreateField(String.Empty, _txtPassword2));
|
||||
_txtPassword2.PlaceHolder = "Password";
|
||||
|
||||
_btnRegister.Text = "Register";
|
||||
_btnRegister.Click += btnRegister_Click;
|
||||
|
||||
_btnExit.Text = "Exit";
|
||||
_btnExit.Click += btnExit_Click;
|
||||
|
||||
Panel pnlButtons=new Panel();
|
||||
pnlButtons.Controls.Add(_btnRegister);
|
||||
pnlButtons.Controls.Add(_btnExit);
|
||||
_pnlRegister.Controls.Add(FormUtils.CreateField(String.Empty, pnlButtons));
|
||||
|
||||
_txtName.Attributes.Add("onkeydown", String.Format(
|
||||
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _txtEmail.ClientID));
|
||||
_txtEmail.Attributes.Add("onkeydown", String.Format(
|
||||
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _txtPassword1.ClientID));
|
||||
_txtPassword1.Attributes.Add("onkeydown", String.Format(
|
||||
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _txtPassword2.ClientID));
|
||||
_txtPassword2.Attributes.Add("onkeydown", String.Format(
|
||||
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _btnRegister.ClientID));
|
||||
|
||||
|
||||
Controls.Add(_pnlSuccess);
|
||||
_pnlSuccess.Visible = false;
|
||||
|
||||
_pnlSuccess.Controls.Add(_lblSuccess);
|
||||
|
||||
_btnExitSuccess.Text = "Exit";
|
||||
_btnExitSuccess.Click += btnExit_Click;
|
||||
_pnlSuccess.Controls.Add(FormUtils.CreateField(String.Empty, _btnExitSuccess));
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
161
Scrummer/Pages/PageCommon.cs
Normal file
161
Scrummer/Pages/PageCommon.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Code.BusinessLogic;
|
||||
using Scrummer.Code.Entities;
|
||||
using Scrummer.Controls;
|
||||
|
||||
namespace Scrummer.Pages
|
||||
{
|
||||
public class PageCommon : Page
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private HtmlHead _head;
|
||||
private HtmlGenericControl _body;
|
||||
private HtmlForm _form;
|
||||
private Panel _pnlContainer = new Panel();
|
||||
private CButton _btnPostback = new CButton();
|
||||
private CButton _btnLogout = new CButton();
|
||||
|
||||
private bool _mustBeAutenticated = true;
|
||||
private User _currentUser = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public new ControlCollection Controls
|
||||
{
|
||||
get { return _pnlContainer.Controls; }
|
||||
}
|
||||
|
||||
public bool MustBeAutenticated
|
||||
{
|
||||
get { return _mustBeAutenticated; }
|
||||
set { _mustBeAutenticated = value; }
|
||||
}
|
||||
|
||||
public User CurrentUser
|
||||
{
|
||||
get { return _currentUser; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Life cycle
|
||||
|
||||
public PageCommon()
|
||||
{
|
||||
PreInit += PageCommon_PreInit;
|
||||
Init += PageCommon_Init;
|
||||
PreRender += PageCommon_PreRender;
|
||||
}
|
||||
|
||||
void PageCommon_PreInit(object sender, EventArgs e)
|
||||
{
|
||||
Session session = Sessions.Current.Session_GetCurrent(Context);
|
||||
if (session != null)
|
||||
{
|
||||
_currentUser = Users.Current.User_GetByName(session.UserName);
|
||||
if (_mustBeAutenticated)
|
||||
{
|
||||
Sessions.Current.Session_SetCookie(Context, session);
|
||||
}
|
||||
}
|
||||
if (_currentUser == null && _mustBeAutenticated)
|
||||
{
|
||||
Response.Redirect("FrmLogin");
|
||||
}
|
||||
}
|
||||
|
||||
void PageCommon_Init(object sender, EventArgs e)
|
||||
{
|
||||
CreateControls();
|
||||
}
|
||||
|
||||
void PageCommon_PreRender(object sender, EventArgs e)
|
||||
{
|
||||
_head.Title = string.IsNullOrEmpty(Title) ? Globals.Title : String.Format("{0}{1}{2}", Globals.Title, Globals.TitleSeparator, Title);
|
||||
_btnLogout.Visible = (_currentUser != null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UI Events
|
||||
|
||||
void btnLogout_Click(object sender, EventArgs e)
|
||||
{
|
||||
Sessions.Current.Session_FinalizeCurrent(Context);
|
||||
_currentUser = null;
|
||||
if (_mustBeAutenticated)
|
||||
{
|
||||
Response.Redirect("FrmLogin");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void CreateControls()
|
||||
{
|
||||
Context.Response.Charset = Encoding.UTF8.WebName;
|
||||
|
||||
var doctype = new LiteralControl("<!DOCTYPE html>\n");
|
||||
base.Controls.Add(doctype);
|
||||
|
||||
var html = new HtmlGenericControl("html");
|
||||
base.Controls.Add(html);
|
||||
|
||||
_head = new HtmlHead();
|
||||
html.Controls.Add(_head);
|
||||
|
||||
_head.Controls.Add(new HtmlMeta { HttpEquiv = "content-type", Content = "text/html; charset=utf-8" });
|
||||
_head.Controls.Add(new HtmlMeta { Name = "author", Content = Globals.Author });
|
||||
_head.Controls.Add(new HtmlMeta { Name = "Copyright", Content = Globals.Copyright });
|
||||
Assembly asm = Assembly.GetExecutingAssembly();
|
||||
string version = asm.GetName().Version.ToString();
|
||||
_head.Controls.Add(new LiteralControl(String.Format("<script type=\"text/javascript\" src=\"ScriptsBundler?t={0}\"></script>\n", version)));
|
||||
_head.Controls.Add(new LiteralControl(String.Format("<link href=\"StylesBundler?t={0}\" type=\"text/css\" rel=\"stylesheet\"/>\n", version)));
|
||||
|
||||
|
||||
_body = new HtmlGenericControl("body");
|
||||
html.Controls.Add(_body);
|
||||
_form = new HtmlForm { ID = "formMain" };
|
||||
_body.Controls.Add(_form);
|
||||
|
||||
var pnlHeader = new Panel { CssClass = "divHeader" };
|
||||
_form.Controls.Add(pnlHeader);
|
||||
|
||||
HyperLink lnkTitle = new HyperLink();
|
||||
lnkTitle.NavigateUrl = ".";
|
||||
pnlHeader.Controls.Add(lnkTitle);
|
||||
|
||||
var lblTitle = new CLabel { Text = Globals.Title, Tag = "h1" };
|
||||
lnkTitle.Controls.Add(lblTitle);
|
||||
|
||||
_btnPostback.ID = "btnPostback";
|
||||
_btnPostback.Text = "Postback";
|
||||
pnlHeader.Controls.Add(_btnPostback);
|
||||
_btnPostback.Style.Add("display", "none");
|
||||
|
||||
var pnlUserInfo = new Panel { CssClass = "divUserInfo" };
|
||||
pnlHeader.Controls.Add(pnlUserInfo);
|
||||
|
||||
_btnLogout.ID = "btnLogout";
|
||||
_btnLogout.Text = "Logout";
|
||||
_btnLogout.Click += btnLogout_Click;
|
||||
_btnLogout.Attributes.Add("onclick", String.Format("return confirm('{0}');", "¿Are you sure to exit?"));
|
||||
pnlUserInfo.Controls.Add(_btnLogout);
|
||||
|
||||
_pnlContainer.CssClass = "divContent";
|
||||
_form.Controls.Add(_pnlContainer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user