|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Hosting;
using System.Threading;
using AspNetScopes.Framework;
/// <summary>
/// Summary description for PopupControl
/// </summary>
public class PopupControl : ScopeControl
{
public override void SetTemplate(ControlTemplate template)
{
template.Markup = File.ReadAllText(HostingEnvironment.MapPath("~/App_Data/Templates/Popup.htm"));
}
public override void SetupModel(ControlModel model)
{
model.Select("DialogWindow", "ContentView", "Pager").SetControl(new PagerControl());
model.SetDataBind(new DataBindHandler(ROOT_DataBind));
model.Select("DialogWindow", "ContentView").SetDataBind(new DataBindHandler(ContentView_DataBind));
model.Select("DialogWindow", "ContentView", "Profile").SetDataBind(new DataBindHandler(Profile_DataBind));
model.Select("DialogWindow", "ContentView", "CourseRepeater").SetDataBind(new DataBindHandler(CourseRepeater_DataBind));
model.Select("DialogWindow", "ContentView", "Summary").SetDataBind(new DataBindHandler(Summary_DataBind));
model.Select("DialogWindow", "ContentView", "Pager").HandleAction("NextPage", new ActionHandler(Pager_NextPage));
model.Select("DialogWindow", "ContentView", "Pager").HandleAction("PrevPage", new ActionHandler(Pager_PrevPage));
model.HandleAction("ClosePopup", new ActionHandler(Action_ClosePopup));
model.HandleAction("DelayedLoad", new ActionHandler(Action_DelayedLoad));
}
private void Pager_NextPage(ActionArgs args)
{
Scopes.ActionPath.Rew(1).Fwd("CourseRepeater").Context.Refresh();
Scopes.ActionPath.Rew(1).Fwd("Summary").Context.Refresh();
Scopes.ActionPath.Context.Refresh();
}
private void Pager_PrevPage(ActionArgs args)
{
Scopes.ActionPath.Rew(1).Fwd("CourseRepeater").Context.Refresh();
Scopes.ActionPath.Rew(1).Fwd("Summary").Context.Refresh();
Scopes.ActionPath.Context.Refresh();
}
private void Action_ClosePopup(ActionArgs args)
{
Context.Params["ShowDialog"] = "0";
Scopes.CurrentPath.Context.Refresh();
}
private void Action_DelayedLoad(ActionArgs args)
{
Context.Params["LoadedState"] = "1";
Scopes.CurrentPath.Context.Refresh();
}
private void ROOT_DataBind(DataBindArgs args)
{
string showDialog = Context.Params.Get("ShowDialog", "0");
string loadedState = Context.Params.Get("LoadedState", "0");
if (loadedState == "0") Scopes.CurrentPath.Fwd("DialogWindow", "ContentView").Context.IsVisible = false;
else
{
Context.Params["LoadedState"] = "0";
Scopes.CurrentPath.Fwd("DialogWindow", "LoaderView").Context.IsVisible = false;
}
if (showDialog == "0") Scopes.CurrentPath.Fwd("DialogWindow").Context.IsVisible = false;
else Scopes.CurrentPath.Fwd("DialogWindow").Context.IsVisible = true;
args.NewItemBinding();
args.CurrBinder.Replace("{CurrScopeID}", Scopes.CurrentPath.Context.ScopeClientID);
}
private void ContentView_DataBind(DataBindArgs args)
{
// load all data
Thread.Sleep(2000);
var student = DataFacade.GetStudent(Context.Params["StudentSSN"]);
int courseCount = DataFacade.GetCourseCount(Context.Params["StudentSSN"]);
Scopes.CurrentPath.Fwd("Profile").Context.Params.AddRange(student, "StudentName", "StudentSSN", "Major", "PhoneNumber");
Scopes.CurrentPath.Fwd("Profile").Context.Params["CourseCount"] = courseCount.ToString();
Scopes.CurrentPath.Fwd("Pager").Context.Params["StartItemIdx"] = "0";
Scopes.CurrentPath.Fwd("Pager").Context.Params["PageSize"] = "3";
Scopes.CurrentPath.Fwd("Pager").Context.Params["ItemTotalCount"] = courseCount.ToString();
}
private void Profile_DataBind(DataBindArgs args)
{
int courseCount = Scopes.CurrentPath.Context.Params.GetInt("CourseCount");
args.NewItemBinding();
args.CurrBinder.Replace(Scopes.CurrentPath.Context.Params, "StudentName", "StudentSSN", "Major", "PhoneNumber");
args.CurrBinder.Replace("{CourseCount}", courseCount);
}
private void CourseRepeater_DataBind(DataBindArgs args)
{
string studentSSN = Context.Params["StudentSSN"];
int startItemIdx = Scopes.CurrentPath.Rew(1).Fwd("Pager").Context.Params.GetInt("StartItemIdx");
int pageSize = Scopes.CurrentPath.Rew(1).Fwd("Pager").Context.Params.GetInt("PageSize");
int courseCount = Scopes.CurrentPath.Rew(1).Fwd("Pager").Context.Params.GetInt("ItemTotalCount");
object[] courses = DataFacade.GetCourses(studentSSN, startItemIdx, pageSize);
for (int i = 0; i < courses.Length; i++)
{
args.NewItemBinding();
args.CurrBinder.Replace(courses[i]);
}
}
private void Summary_DataBind(DataBindArgs args)
{
int startItemIdx = Scopes.CurrentPath.Rew(1).Fwd("Pager").Context.Params.GetInt("StartItemIdx");
int pageSize = Scopes.CurrentPath.Rew(1).Fwd("Pager").Context.Params.GetInt("PageSize");
args.NewItemBinding();
args.CurrBinder.Replace("{FromCourse}", (startItemIdx + 1).ToString());
args.CurrBinder.Replace("{ToCourse}", (startItemIdx + pageSize).ToString());
}
}
|
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.
Software Architect with over 15 years in IT field. Started with deep math and C++ Computer Vision software. Currently in .NET and PHP web development. Creator of DaST pattern, open-source frameworks, and plugins. Interested in cutting Edge IT, open-source, Web 2.0, .NET, MVC, C++, Java, jQuery, Mobile tech, and extreme sports.