|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Security.Permissions;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Specialized;
using System.IO;
/// <summary>
/// Summary description for CustomWebZone
/// </summary>
///
namespace Samples.CustomWebZone.CS.Controls
{
public class CustomZone : WebPartZone
{
public CustomZone()
{
//
// TODO: Add constructor logic here
//
}
#region Add Custom Verbs to List
protected override void OnCreateVerbs(WebPartVerbsEventArgs e)
{
string CustomZone_Id = this.ID;
List<WebPartVerb> newVerbs = new List<WebPartVerb>();
if (CustomZone_Id == "CustomZone3")
{ newVerbs.Add(new DisableMoveRight(OnMoveRight)); }
else
{ newVerbs.Add(new MoveToRight(OnMoveRight)); }
if (CustomZone_Id == "CustomZone1")
{ newVerbs.Add(new DisableMoveLeft(OnMoveLeft)); }
else
{ newVerbs.Add(new MoveToLeft(OnMoveLeft)); }
newVerbs.Add(new MoveToDown(OnMoveDown));
newVerbs.Add(new MoveToUp(OnMoveUp));
e.Verbs = new WebPartVerbCollection(e.Verbs, newVerbs);
base.OnCreateVerbs(e);
}
#endregion
#region MoveRight Event Handler
void OnMoveRight(object sender, WebPartEventArgs e)
{
int wpcount = (int)e.WebPart.Zone.WebParts.Count;//gets the total number of webparts that is present in a particular zone
int wpindex = (int)e.WebPart.ZoneIndex;//get the webpart index within the zone
string zname = (string)e.WebPart.Zone.ID; //gets the zone name
string del = "e";
string[] temp = zname.Split(del.ToCharArray());//splits the name to get the last numeric value
int zid = int.Parse(temp[1].ToString());// get the numeric value of a zone
WebPartManager wpm1 = WebPartManager.GetCurrentWebPartManager(Page);//gets the available webpartmanager on the page
if (zid < 3)
{
GenericWebPart part = (GenericWebPart)wpm1.Zones[zid - 1].WebParts[wpindex]; //get the current control being move within the zone
wpm1.MoveWebPart(part, wpm1.Zones[zid], wpindex);//move the webpart to another or within a zone * e.WebPart.Zone.WebParts.Count
}
}
#endregion
#region MoveLeft Event Handler
void OnMoveLeft(object sender, WebPartEventArgs e)
{
HttpContext.Current.Session["CustomZone.Count"] = 0;//reset session to zero
int wpcount = (int)e.WebPart.Zone.WebParts.Count;//gets the total number of webparts that is present in a particular zone
int wpindex = (int)e.WebPart.ZoneIndex;//get the webpart index location within the zone
string zname = (string)e.WebPart.Zone.ID; //gets the zone name
string del = "e";
string[] temp = zname.Split(del.ToCharArray());//splits the name to get the last numeric value
int zid = int.Parse(temp[1].ToString());// get the numeric value of a zone
HttpContext.Current.Session["CustomZone.Count"] = zid - 1;
WebPartManager wpm1 = WebPartManager.GetCurrentWebPartManager(Page);//gets the available webpartmanager on the page
if (zid != 1)
{
GenericWebPart part = (GenericWebPart)wpm1.Zones[zid - 1].WebParts[wpindex]; //get the current control being move within the zone
wpm1.MoveWebPart(part, wpm1.Zones[zid - 2], wpindex);//move the webpart to another or within a zone
}
}
#endregion
#region GoDown Event Handler
void OnMoveDown(object sender, WebPartEventArgs e)
{
int wpcount = (int)e.WebPart.Zone.WebParts.Count;//gets the total number of webparts that is present in a particular zone
int wpindex = (int)e.WebPart.ZoneIndex;//get the webpart index location within the zone
string zname = (string)e.WebPart.Zone.ID; //gets the zone name
string del = "e";
string[] temp = zname.Split(del.ToCharArray());//splits the name to get the last numeric value
int zid = int.Parse(temp[1].ToString());// get the numeric value of a zone
WebPartManager wpm1 = WebPartManager.GetCurrentWebPartManager(Page);//gets the available webpartmanager on the page
if (wpindex < wpcount - 1)
{
GenericWebPart part = (GenericWebPart)wpm1.Zones[zid - 1].WebParts[wpindex]; //get the current control being move within the zone
wpm1.MoveWebPart(part, wpm1.Zones[zid - 1], wpindex + 1);//move the webpart to another or within a zone
}
else
{
//some code here for vaildation
}
}
#endregion
#region GoUp Event Handler
void OnMoveUp(object sender, WebPartEventArgs e)
{
int wpcount = (int)e.WebPart.Zone.WebParts.Count;//gets the total number of webparts that is present in a particular zone
int wpindex = (int)e.WebPart.ZoneIndex;//get the webpart index location within the zone
string zname = (string)e.WebPart.Zone.ID; //gets the zone name
string del = "e";
string[] temp = zname.Split(del.ToCharArray());//splits the name to get the last numeric value
int zid = int.Parse(temp[1].ToString());// get the numeric value of a zone
WebPartManager wpm1 = WebPartManager.GetCurrentWebPartManager(Page);//gets the available webpartmanager on the page
if (wpindex != 0)
{
HttpContext.Current.Session["zoneindex"] = null;
GenericWebPart part = (GenericWebPart)wpm1.Zones[zid - 1].WebParts[wpindex]; //get the current control being move within the zone
wpm1.MoveWebPart(part, wpm1.Zones[zid - 1], wpindex - 1);//move the webpart to another or within a zone
}
else
{
//some code here for vaildation
}
}
#endregion
}
//Internal Classes
#region Create Move Right Verb
internal class MoveToRight : WebPartVerb
{
private const String _copyWebPartImageUrl = "~/Images/right_arrow.png";
internal MoveToRight(WebPartEventHandler serverClickHandler)
:
base("MyVerbRight", serverClickHandler)
{ }
public override string Text
{
get { return "Move Right"; }
set { ;}
}
public override string Description
{
get
{
return "Allows you to move webparts to the right zone ";
}
set { ; }
}
public override bool Enabled
{
get
{
return base.Enabled;
}
set { base.Enabled = value; }
}
public override string ImageUrl
{
get
{
return _copyWebPartImageUrl;
}
set { ; }
}
}
internal class DisableMoveRight : WebPartVerb
{
private const String _copyWebPartImageUrl = "~/Images/disabled_right_arrow.png";
internal DisableMoveRight(WebPartEventHandler serverClickHandler)
:
base("Right", serverClickHandler)
{ }
public override string Text
{
get { return "Move Right"; }
set { ;}
}
public override string Description
{
get
{
return "Unable to move ";
}
set { ; }
}
public override bool Enabled
{
get { return base.Enabled = false; }
set { base.Enabled = value; }
}
public override string ImageUrl
{
get { return _copyWebPartImageUrl; }
set { ; }
}
}
#endregion
#region Create Move Left Verb
internal class MoveToLeft : WebPartVerb
{
private const String _copyWebPartImageUrl = "~/Images/left_arrow.png";
internal MoveToLeft(WebPartEventHandler serverClickHandler)
:
base("MyVerbLeft", serverClickHandler)
{ }
public override string Text
{
get { return "Move Left"; }
set { ;}
}
public override string Description
{
get
{
return "Allows you to move webparts to the left zone ";
}
set { ; }
}
public override bool Enabled
{
get { return base.Enabled; }
set { base.Enabled = value; }
}
public override string ImageUrl
{
get { return _copyWebPartImageUrl; }
set { ; }
}
}
internal class DisableMoveLeft : WebPartVerb
{
private const String _copyWebPartImageUrl = "~/Images/disabled_left_arrow.png";
internal DisableMoveLeft(WebPartEventHandler serverClickHandler)
:
base("Left", serverClickHandler)
{ }
public override string Text
{
get { return "Move Left"; }
set { ;}
}
public override string Description
{
get
{
return "Unable to move ";
}
set { ; }
}
public override bool Enabled
{
get { return base.Enabled = false; }
set { base.Enabled = value; }
}
public override string ImageUrl
{
get { return _copyWebPartImageUrl; }
set { ; }
}
}
#endregion
#region Create Move Down Ver
internal class MoveToDown : WebPartVerb
{
private const String _copyWebPartImageUrl = "~/Images/down_arrow.png";
internal MoveToDown(WebPartEventHandler serverClickHandler)
:
base("MyVerbDown", serverClickHandler)
{ }
public override string Text
{
get { return "Move Down"; }
set { ;}
}
public override string Description
{
get
{
return "Allows you to move webparts downward";
}
set { ; }
}
public override bool Enabled
{
get { return base.Enabled; }
set { base.Enabled = value; }
}
public override string ImageUrl
{
get { return _copyWebPartImageUrl; }
set { ; }
}
}
internal class Disable_Down : WebPartVerb
{
private const String _copyWebPartImageUrl = "~/Images/disabled_down_arrow.png";
internal Disable_Down(WebPartEventHandler serverClickHandler)
:
base("DownVerbDisabled", serverClickHandler)
{ }
public override string Text
{
get { return "Move Down"; }
set { ;}
}
public override string Description
{
get
{
return "Unable to move";
}
set { ; }
}
public override bool Enabled
{
get { return base.Enabled = false; }
set { base.Enabled = value; }
}
public override string ImageUrl
{
get { return _copyWebPartImageUrl; }
set { ; }
}
}
#endregion
#region Create Move Up Verb
internal class MoveToUp : WebPartVerb
{
private const String _copyWebPartImageUrl = "~/Images/up_arrow.png";
internal MoveToUp(WebPartEventHandler serverClickHandler)
:
base("MyVerbUp", serverClickHandler)
{ }
public override string Text
{
get { return "Move Up"; }
set { ;}
}
public override string Description
{
get
{
return "Allows you to move webparts upward";
}
set { ; }
}
public override bool Enabled
{
get { return base.Enabled; }
set { base.Enabled = value; }
}
public override string ImageUrl
{
get { return _copyWebPartImageUrl; }
set { ; }
}
}
#endregion
}
|