Split VAR.WebForms.Common to a class library.
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using VAR.Focus.Web.Controls;
|
||||
|
||||
namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
public class FormUtils
|
||||
{
|
||||
public static Control CreatePanel(string cssClass, Control ctrl)
|
||||
{
|
||||
Panel pnl = new Panel();
|
||||
if (ctrl != null)
|
||||
{
|
||||
pnl.Controls.Add(ctrl);
|
||||
}
|
||||
if (string.IsNullOrEmpty(cssClass) == false)
|
||||
{
|
||||
pnl.CssClass = cssClass;
|
||||
}
|
||||
return pnl;
|
||||
}
|
||||
|
||||
public static Control CreatePanel(string cssClass)
|
||||
{
|
||||
return CreatePanel(cssClass, null);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ using VAR.Focus.BusinessLogic;
|
||||
using VAR.Focus.BusinessLogic.Entities;
|
||||
using VAR.Focus.Web.Code;
|
||||
using VAR.Focus.Web.Controls;
|
||||
using VAR.WebForms.Common.Code;
|
||||
using VAR.WebForms.Common.Controls;
|
||||
using VAR.WebForms.Common.Pages;
|
||||
|
||||
namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
@@ -52,7 +55,8 @@ namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
if (FormUtils.Controls_AreValid(Controls) == false) { return; }
|
||||
|
||||
Board board = Boards.Current.Boards_SetBoard(0, _txtTitle.Text, _txtDescription.Text, null, CurrentUser.Name);
|
||||
User user = WebSessions.Current.Session_GetCurrentUser(Context);
|
||||
Board board = Boards.Current.Boards_SetBoard(0, _txtTitle.Text, _txtDescription.Text, null, user.Name);
|
||||
_idBoard = board.IDBoard;
|
||||
|
||||
Response.Redirect(GetUrl(_idBoard));
|
||||
@@ -77,7 +81,8 @@ namespace VAR.Focus.Web.Pages
|
||||
CButton btnEdit = (CButton)sender;
|
||||
int idBoard = Convert.ToInt32(btnEdit.CommandArgument);
|
||||
|
||||
if (Boards.Current.Boards_DelBoard(idBoard, CurrentUser.Name))
|
||||
User user = WebSessions.Current.Session_GetCurrentUser(Context);
|
||||
if (Boards.Current.Boards_DelBoard(idBoard, user.Name))
|
||||
{
|
||||
Controls.Clear();
|
||||
FrmBoard_InitIndex();
|
||||
@@ -146,7 +151,8 @@ namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
Title = "Boards";
|
||||
|
||||
List<Board> boards = Boards.Current.Boards_GetListForUser(CurrentUser.Name);
|
||||
User user = WebSessions.Current.Session_GetCurrentUser(Context);
|
||||
List<Board> boards = Boards.Current.Boards_GetListForUser(user?.Name);
|
||||
foreach (Board board in boards)
|
||||
{
|
||||
Panel pnlBoardSelector = BoardSelector_Create(board);
|
||||
@@ -167,6 +173,7 @@ namespace VAR.Focus.Web.Pages
|
||||
|
||||
private void FrmBoard_InitBoard()
|
||||
{
|
||||
User user = WebSessions.Current.Session_GetCurrentUser(Context);
|
||||
Board board = Boards.Current.Board_GetByIDBoard(_idBoard);
|
||||
|
||||
Title = board.Title;
|
||||
@@ -175,7 +182,7 @@ namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
ID = "ctrCardBoard",
|
||||
IDBoard = board.IDBoard,
|
||||
UserName = CurrentUser.Name,
|
||||
UserName = user.Name,
|
||||
};
|
||||
Controls.Add(cardBoardControl);
|
||||
|
||||
@@ -183,7 +190,7 @@ namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
ID = "ctrChat",
|
||||
IDMessageBoard = string.Format("CardBoard_{0}", board.IDBoard),
|
||||
UserName = CurrentUser.Name,
|
||||
UserName = user.Name,
|
||||
};
|
||||
Controls.Add(chatControl);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ using System.Web.UI.WebControls;
|
||||
using VAR.Focus.BusinessLogic;
|
||||
using VAR.Focus.BusinessLogic.Entities;
|
||||
using VAR.Focus.Web.Code;
|
||||
using VAR.Focus.Web.Controls;
|
||||
using VAR.WebForms.Common.Code;
|
||||
using VAR.WebForms.Common.Controls;
|
||||
using VAR.WebForms.Common.Pages;
|
||||
|
||||
namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
@@ -59,12 +61,13 @@ namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
if (FormUtils.Controls_AreValid(Controls) == false) { return; }
|
||||
|
||||
User user = WebSessions.Current.Session_GetCurrentUser(Context);
|
||||
Board board = Boards.Current.Boards_SetBoard(
|
||||
_idBoard,
|
||||
_txtTitle.Text,
|
||||
_txtDescription.Text,
|
||||
_txtDescription.GetClientsideHeight(),
|
||||
CurrentUser.Name);
|
||||
user.Name);
|
||||
|
||||
// FIXME: Notify User of "Save Succesfully"
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Web;
|
||||
using VAR.Json;
|
||||
|
||||
namespace VAR.Focus.Web.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 IHttpHandler
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using VAR.Focus.Web.Controls;
|
||||
|
||||
namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
public class FrmError : PageCommon
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private Exception _ex = null;
|
||||
|
||||
#endregion Declarations
|
||||
|
||||
#region Page life cycle
|
||||
|
||||
public FrmError(Exception ex)
|
||||
{
|
||||
_ex = ex;
|
||||
Init += FrmError_Init;
|
||||
}
|
||||
|
||||
private void FrmError_Init(object sender, EventArgs e)
|
||||
{
|
||||
InitializeControls();
|
||||
}
|
||||
|
||||
#endregion Page life cycle
|
||||
|
||||
#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 Private methods
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
using System.Web.UI.WebControls;
|
||||
using VAR.Focus.BusinessLogic;
|
||||
using VAR.Focus.Web.Code;
|
||||
using VAR.Focus.Web.Controls;
|
||||
using VAR.WebForms.Common.Code;
|
||||
using VAR.WebForms.Common.Controls;
|
||||
using VAR.WebForms.Common.Pages;
|
||||
|
||||
namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
@@ -44,7 +46,7 @@ namespace VAR.Focus.Web.Pages
|
||||
}
|
||||
|
||||
WebSessions.Current.Session_Init(Context, _txtNameEmail.Text);
|
||||
Response.Redirect(Globals.DefaultHandler);
|
||||
Response.Redirect(GlobalConfig.Get().DefaultHandler);
|
||||
}
|
||||
|
||||
#endregion UI Events
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
using System.Web.UI.WebControls;
|
||||
using VAR.Focus.BusinessLogic;
|
||||
using VAR.Focus.BusinessLogic.Entities;
|
||||
using VAR.Focus.Web.Code;
|
||||
using VAR.Focus.Web.Controls;
|
||||
using VAR.WebForms.Common.Code;
|
||||
using VAR.WebForms.Common.Controls;
|
||||
using VAR.WebForms.Common.Pages;
|
||||
|
||||
namespace VAR.Focus.Web.Pages
|
||||
{
|
||||
@@ -66,7 +67,7 @@ namespace VAR.Focus.Web.Pages
|
||||
|
||||
private void btnExit_Click(object sender, EventArgs e)
|
||||
{
|
||||
Response.Redirect(Globals.DefaultHandler);
|
||||
Response.Redirect(GlobalConfig.Get().DefaultHandler);
|
||||
}
|
||||
|
||||
#endregion UI Events
|
||||
|
||||
@@ -1,165 +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 VAR.Focus.BusinessLogic;
|
||||
using VAR.Focus.BusinessLogic.Entities;
|
||||
using VAR.Focus.Web.Code;
|
||||
using VAR.Focus.Web.Controls;
|
||||
|
||||
namespace VAR.Focus.Web.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 Declarations
|
||||
|
||||
#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 Properties
|
||||
|
||||
#region Life cycle
|
||||
|
||||
public PageCommon()
|
||||
{
|
||||
PreInit += PageCommon_PreInit;
|
||||
Init += PageCommon_Init;
|
||||
PreRender += PageCommon_PreRender;
|
||||
}
|
||||
|
||||
private void PageCommon_PreInit(object sender, EventArgs e)
|
||||
{
|
||||
Context.Response.PrepareUncacheableResponse();
|
||||
|
||||
Session session = WebSessions.Current.Session_GetCurrent(Context);
|
||||
if (session != null)
|
||||
{
|
||||
_currentUser = Users.Current.User_GetByName(session.UserName);
|
||||
if (_mustBeAutenticated)
|
||||
{
|
||||
WebSessions.Current.Session_SetCookie(Context, session);
|
||||
}
|
||||
}
|
||||
if (_currentUser == null && _mustBeAutenticated)
|
||||
{
|
||||
Response.Redirect(nameof(FrmLogin));
|
||||
}
|
||||
}
|
||||
|
||||
private void PageCommon_Init(object sender, EventArgs e)
|
||||
{
|
||||
CreateControls();
|
||||
}
|
||||
|
||||
private void PageCommon_PreRender(object sender, EventArgs e)
|
||||
{
|
||||
_head.Title = string.IsNullOrEmpty(Title) ? Globals.Title : string.Format("{0}{1}{2}", Title, Globals.TitleSeparator, Globals.Title);
|
||||
_btnLogout.Visible = (_currentUser != null);
|
||||
}
|
||||
|
||||
#endregion Life cycle
|
||||
|
||||
#region UI Events
|
||||
|
||||
private void btnLogout_Click(object sender, EventArgs e)
|
||||
{
|
||||
WebSessions.Current.Session_FinalizeCurrent(Context);
|
||||
_currentUser = null;
|
||||
if (_mustBeAutenticated)
|
||||
{
|
||||
Response.Redirect(nameof(FrmLogin));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion UI Events
|
||||
|
||||
#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 = "X-UA-Compatible", Content = "IE=Edge" });
|
||||
_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 });
|
||||
_head.Controls.Add(new HtmlMeta { Name = "viewport", Content = "width=device-width, initial-scale=1, maximum-scale=4, user-scalable=1" });
|
||||
|
||||
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
_head.Controls.Add(new LiteralControl(string.Format("<script type=\"text/javascript\" src=\"ScriptsBundler?v={0}\"></script>\n", version)));
|
||||
_head.Controls.Add(new LiteralControl(string.Format("<link href=\"StylesBundler?v={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 = MultiLang.GetLiteral("Logout");
|
||||
_btnLogout.Click += btnLogout_Click;
|
||||
_btnLogout.Attributes.Add("onclick", string.Format("return confirm('{0}');", MultiLang.GetLiteral("ConfirmExit")));
|
||||
pnlUserInfo.Controls.Add(_btnLogout);
|
||||
|
||||
_pnlContainer.CssClass = "divContent";
|
||||
_form.Controls.Add(_pnlContainer);
|
||||
}
|
||||
|
||||
#endregion Private methods
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user