Reorder namespaces of pages and controls
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace Scrummer.Code.Controls
|
||||
{
|
||||
public class CButton : Button
|
||||
{
|
||||
public CButton()
|
||||
{
|
||||
CssClass = "button";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace Scrummer.Code.Controls
|
||||
{
|
||||
public class CLabel : Label
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private string _tagName = "span";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public string Tag
|
||||
{
|
||||
get { return _tagName; }
|
||||
set { _tagName = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Life cycle
|
||||
|
||||
public override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_tagName) == false)
|
||||
{
|
||||
this.AddAttributesToRender(writer);
|
||||
writer.RenderBeginTag(_tagName);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace Scrummer.Code.Controls
|
||||
{
|
||||
public class CTextBox : TextBox, IValidableControl
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private const string CssClassBase = "textbox";
|
||||
private string _cssClassExtra = "";
|
||||
|
||||
private bool _allowEmpty = true;
|
||||
|
||||
private string _placeHolder = string.Empty;
|
||||
|
||||
private bool _markedInvalid = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public string CssClassExtra
|
||||
{
|
||||
get { return _cssClassExtra; }
|
||||
set { _cssClassExtra = value; }
|
||||
}
|
||||
|
||||
public bool AllowEmpty
|
||||
{
|
||||
get { return _allowEmpty; }
|
||||
set { _allowEmpty = value; }
|
||||
}
|
||||
|
||||
public string PlaceHolder
|
||||
{
|
||||
get { return _placeHolder; }
|
||||
set { _placeHolder = value; }
|
||||
}
|
||||
|
||||
public bool MarkedInvalid
|
||||
{
|
||||
get { return _markedInvalid; }
|
||||
set { _markedInvalid = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Control life cycle
|
||||
|
||||
public CTextBox()
|
||||
{
|
||||
PreRender += CTextbox_PreRender;
|
||||
}
|
||||
|
||||
void CTextbox_PreRender(object sender, EventArgs e)
|
||||
{
|
||||
CssClass = CssClassBase;
|
||||
if (string.IsNullOrEmpty(_cssClassExtra) == false)
|
||||
{
|
||||
CssClass = String.Format("{0} {1}", CssClassBase, _cssClassExtra);
|
||||
}
|
||||
if (Page.IsPostBack && (_allowEmpty == false && IsEmpty()) || _markedInvalid)
|
||||
{
|
||||
CssClass += " textboxInvalid";
|
||||
}
|
||||
Attributes.Add("onchange", "ElementRemoveClass(this, 'textboxInvalid');");
|
||||
|
||||
if (string.IsNullOrEmpty(_placeHolder) == false)
|
||||
{
|
||||
Attributes.Add("placeholder", _placeHolder);
|
||||
}
|
||||
|
||||
// FIX: The framework deletes textbox values on password mode
|
||||
if (TextMode == TextBoxMode.Password)
|
||||
{
|
||||
Attributes["value"] = Text;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return string.IsNullOrEmpty(Text);
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
return _allowEmpty || (string.IsNullOrEmpty(Text) == false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace Scrummer.Code.Controls
|
||||
{
|
||||
public class ChatControl : Control, INamingContainer
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private string _serviceUrl = "ChatHandler";
|
||||
|
||||
private int _idBoard = 0;
|
||||
|
||||
private string _userName = string.Empty;
|
||||
|
||||
private int _timePoolData = 10000;
|
||||
|
||||
private Unit _width = new Unit(500, UnitType.Pixel);
|
||||
private Unit _height = new Unit(300, UnitType.Pixel);
|
||||
|
||||
private Panel _divChatWindow = null;
|
||||
private Panel _divChatContainer = null;
|
||||
private Panel _divChatTitleBar = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public string ServiceUrl
|
||||
{
|
||||
get { return _serviceUrl; }
|
||||
set { _serviceUrl = value; }
|
||||
}
|
||||
|
||||
public int IDBoard
|
||||
{
|
||||
get { return _idBoard; }
|
||||
set { _idBoard = value; }
|
||||
}
|
||||
|
||||
public string UserName
|
||||
{
|
||||
get { return _userName; }
|
||||
set { _userName = value; }
|
||||
}
|
||||
|
||||
public int TimePoolData
|
||||
{
|
||||
get { return _timePoolData; }
|
||||
set { _timePoolData = value; }
|
||||
}
|
||||
|
||||
public Unit Width
|
||||
{
|
||||
get { return _width; }
|
||||
set
|
||||
{
|
||||
_width = value;
|
||||
if (_divChatContainer != null)
|
||||
{
|
||||
_divChatContainer.Width = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Unit Height
|
||||
{
|
||||
get { return _height; }
|
||||
set
|
||||
{
|
||||
_height = value;
|
||||
if (_divChatContainer != null)
|
||||
{
|
||||
_divChatContainer.Height = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Control Life cycle
|
||||
|
||||
public ChatControl()
|
||||
{
|
||||
Init += ChatControl_Init;
|
||||
}
|
||||
|
||||
void ChatControl_Init(object sender, EventArgs e)
|
||||
{
|
||||
InitializeControls();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void InitializeControls()
|
||||
{
|
||||
string strCfgName = string.Format("{0}_cfg", this.ClientID);
|
||||
|
||||
_divChatWindow = new Panel { ID = "divChatWindow", CssClass = "divChatWindow" };
|
||||
Controls.Add(_divChatWindow);
|
||||
|
||||
_divChatTitleBar = new Panel { ID = "divChatTitleBar", CssClass = "divChatTitleBar" };
|
||||
_divChatWindow.Controls.Add(_divChatTitleBar);
|
||||
|
||||
CLabel lblTitle = new CLabel();
|
||||
lblTitle.ID = "lblTitle";
|
||||
_divChatTitleBar.Controls.Add(lblTitle);
|
||||
|
||||
_divChatContainer = new Panel { ID = "divChatContainer", CssClass = "divChatContainer" };
|
||||
_divChatWindow.Controls.Add(_divChatContainer);
|
||||
_divChatContainer.Width = _width;
|
||||
_divChatContainer.Height = _height;
|
||||
|
||||
var divChat = new Panel { ID = "divChat", CssClass = "divChat" };
|
||||
_divChatContainer.Controls.Add(divChat);
|
||||
|
||||
var divChatControls = new Panel { ID = "divChatControls", CssClass = "divChatControls" };
|
||||
_divChatContainer.Controls.Add(divChatControls);
|
||||
|
||||
var txtText = new TextBox { ID = "txtText", CssClass = "chatTextBox" };
|
||||
txtText.Attributes.Add("autocomplete", "off");
|
||||
txtText.Attributes.Add("onkeydown", String.Format("if(event.keyCode==13){{SendChat({0}); return false;}}", strCfgName));
|
||||
divChatControls.Controls.Add(txtText);
|
||||
|
||||
var btnSend = new Button { ID = "btnSend", Text = "Send", CssClass = "chatButton" };
|
||||
divChatControls.Controls.Add(btnSend);
|
||||
btnSend.Attributes.Add("onclick", String.Format("SendChat({0}); return false;", strCfgName));
|
||||
|
||||
StringBuilder sbCfg = new StringBuilder();
|
||||
sbCfg.AppendFormat("<script>\n");
|
||||
sbCfg.AppendFormat("var {0} = {{\n", strCfgName);
|
||||
sbCfg.AppendFormat(" divChatWindow: \"{0}\",\n", _divChatWindow.ClientID);
|
||||
sbCfg.AppendFormat(" divChatTitleBar: \"{0}\",\n", _divChatTitleBar.ClientID);
|
||||
sbCfg.AppendFormat(" lblTitle: \"{0}\",\n", lblTitle.ClientID);
|
||||
sbCfg.AppendFormat(" divChatContainer: \"{0}\",\n", _divChatContainer.ClientID);
|
||||
sbCfg.AppendFormat(" divChat: \"{0}\",\n", divChat.ClientID);
|
||||
sbCfg.AppendFormat(" txtText: \"{0}\",\n", txtText.ClientID);
|
||||
sbCfg.AppendFormat(" btnSend: \"{0}\",\n", btnSend.ClientID);
|
||||
sbCfg.AppendFormat(" IDBoard: {0},\n", _idBoard);
|
||||
sbCfg.AppendFormat(" UserName: \"{0}\",\n", _userName);
|
||||
sbCfg.AppendFormat(" IDMessage: {0},\n", 0);
|
||||
sbCfg.AppendFormat(" ServiceUrl: \"{0}\",\n", _serviceUrl);
|
||||
sbCfg.AppendFormat(" TimePoolData: {0},\n", _timePoolData);
|
||||
sbCfg.AppendFormat(" Texts: {{\n", _serviceUrl);
|
||||
sbCfg.AppendFormat(" Chat: \"{0}\",\n", "Chat");
|
||||
sbCfg.AppendFormat(" Close: \"{0}\",\n", "Close X");
|
||||
sbCfg.AppendFormat(" NewMessages: \"{0}\",\n", "New messages");
|
||||
sbCfg.AppendFormat(" Disconnected: \"{0}\",\n", "Disconnected");
|
||||
sbCfg.AppendFormat(" StringEmpty: \"\"\n");
|
||||
sbCfg.AppendFormat(" }}\n");
|
||||
sbCfg.AppendFormat("}};\n");
|
||||
sbCfg.AppendFormat("RunChat({0});\n", strCfgName);
|
||||
sbCfg.AppendFormat("</script>\n");
|
||||
LiteralControl liScript = new LiteralControl(sbCfg.ToString());
|
||||
Controls.Add(liScript);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using Scrummer.Code.BusinessLogic;
|
||||
using Scrummer.Code.Entities;
|
||||
using Scrummer.Code.JSON;
|
||||
|
||||
namespace Scrummer.Code
|
||||
{
|
||||
public class ChatHandler : IHttpHandler
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private static object _monitor = new object();
|
||||
private static Dictionary<int, MessageBoard> _chatBoards = new Dictionary<int, MessageBoard>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region IHttpHandler
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
if (context.Request.RequestType == "GET")
|
||||
{
|
||||
ProcessReciver(context);
|
||||
}
|
||||
if (context.Request.RequestType == "POST")
|
||||
{
|
||||
ProcessSender(context);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void ProcessReciver(HttpContext context)
|
||||
{
|
||||
int idBoard = Convert.ToInt32(GetRequestParm(context, "IDBoard"));
|
||||
int idMessage = Convert.ToInt32(GetRequestParm(context, "IDMessage"));
|
||||
string strTimePoolData = GetRequestParm(context, "TimePoolData");
|
||||
int timePoolData = Convert.ToInt32(string.IsNullOrEmpty(strTimePoolData) ? "0" : strTimePoolData);
|
||||
|
||||
MessageBoard messageBoard;
|
||||
bool mustWait = (timePoolData > 0);
|
||||
do
|
||||
{
|
||||
if (_chatBoards.ContainsKey(idBoard) == false)
|
||||
{
|
||||
lock (_chatBoards)
|
||||
{
|
||||
if (_chatBoards.ContainsKey(idBoard) == false)
|
||||
{
|
||||
messageBoard = new MessageBoard(idBoard);
|
||||
_chatBoards[idBoard] = messageBoard;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_chatBoards.ContainsKey(idBoard))
|
||||
{
|
||||
messageBoard = _chatBoards[idBoard];
|
||||
List<Message> listMessages = messageBoard.Messages_GetList(idMessage);
|
||||
if (listMessages.Count > 0)
|
||||
{
|
||||
mustWait = false;
|
||||
ResponseObject(context, listMessages);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mustWait)
|
||||
{
|
||||
lock (_monitor) { Monitor.Wait(_monitor, timePoolData); }
|
||||
}
|
||||
} while (mustWait);
|
||||
ResponseObject(context, new List<Message>());
|
||||
}
|
||||
|
||||
private void ProcessSender(HttpContext context)
|
||||
{
|
||||
string text = Convert.ToString(GetRequestParm(context, "Text"));
|
||||
string strIDBoard = GetRequestParm(context, "IDBoard");
|
||||
int idBoard = Convert.ToInt32(string.IsNullOrEmpty(strIDBoard) ? "0" : strIDBoard);
|
||||
string userName = Convert.ToString(GetRequestParm(context, "UserName"));
|
||||
Session session = Sessions.Current.Session_GetCurrent(context);
|
||||
if (session.UserName.ToLower() != userName.ToLower())
|
||||
{
|
||||
ResponseObject(context, new OperationStatus { IsOK = false, Message = "User mismatch" });
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_chatBoards)
|
||||
{
|
||||
MessageBoard messageBoard;
|
||||
if (_chatBoards.ContainsKey(idBoard))
|
||||
{
|
||||
messageBoard = _chatBoards[idBoard];
|
||||
}
|
||||
else
|
||||
{
|
||||
messageBoard = new MessageBoard(idBoard);
|
||||
_chatBoards[idBoard] = messageBoard;
|
||||
}
|
||||
messageBoard.Message_Add(userName, text);
|
||||
lock (_monitor) { Monitor.PulseAll(_monitor); }
|
||||
}
|
||||
ResponseObject(context, new OperationStatus { IsOK = true, Message = "Message sent" });
|
||||
}
|
||||
|
||||
private string GetRequestParm(HttpContext context, string parm)
|
||||
{
|
||||
foreach (string key in context.Request.Params.AllKeys)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key) == false && key.EndsWith(parm))
|
||||
{
|
||||
return context.Request.Params[key];
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private void ResponseObject(HttpContext context, object obj)
|
||||
{
|
||||
var jsonWritter = new JSONWriter(true);
|
||||
context.Response.ContentType = "text/json";
|
||||
string strObject = jsonWritter.Write(obj);
|
||||
context.Response.Write(strObject);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Scrummer.Code.Controls
|
||||
{
|
||||
public interface IValidableControl
|
||||
{
|
||||
bool IsValid();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Scrummer.Code.Pages;
|
||||
using Scrummer.Pages;
|
||||
|
||||
namespace Scrummer.Code
|
||||
{
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Code.Controls;
|
||||
|
||||
namespace Scrummer.Code.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using Scrummer.Code.Controls;
|
||||
|
||||
namespace Scrummer.Code.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Web;
|
||||
using Scrummer.Code.JSON;
|
||||
|
||||
namespace Scrummer.Code.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
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Code.Controls;
|
||||
|
||||
namespace Scrummer.Code.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
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
using System;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Code.BusinessLogic;
|
||||
using Scrummer.Code.Controls;
|
||||
|
||||
namespace Scrummer.Code.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
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
using System;
|
||||
using System.Web.UI.WebControls;
|
||||
using Scrummer.Code.BusinessLogic;
|
||||
using Scrummer.Code.Controls;
|
||||
using Scrummer.Code.Entities;
|
||||
|
||||
namespace Scrummer.Code.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
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
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.Controls;
|
||||
using Scrummer.Code.Entities;
|
||||
|
||||
namespace Scrummer.Code.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