2025-04-15 12:10:19 +02:00

981 lines
27 KiB
C#
Raw Blame History

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Security.Permissions;
[assembly: TagPrefix("CustomCompositeControl", "Custom2")]
[Serializable]
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal),
DefaultProperty("Text"),
ToolboxData("<{0}:TreeViewReport runat=\"server\"> </{0}:TreeViewReport>")]
public class TreeViewReport : System.Web.UI.WebControls.TreeView, INamingContainer
{
private TreeNode root;
private TreeNode child;
private int numeroNodi;
private int lastLevel;
private string radioName;
private string nodePreImage;
private CustomDataItem _treeviewitem;
public TreeViewReport()
{
numeroNodi = 0;
lastLevel = 0;
radioName = "";
nodePreImage = "";
_treeviewitem = null;
root = null;
child = null;
this.ExpandAll();
}
public TreeViewReport(string _id )
{
numeroNodi = 0;
lastLevel = 0;
radioName = "";
nodePreImage = "";
_treeviewitem = null;
root = null;
child = null;
this.ExpandAll();
this.ID = _id;
}
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
protected override TreeNode CreateNode()
{
return new MyTreeNodeCheck();
}
public void CreateTreeView(IEnumerable retrievedData)
{
foreach (object dataItem in retrievedData)
{
_treeviewitem = (CustomDataItem)dataItem;
if (_treeviewitem.Livello == 0)
{
root = getTreeNodeType(_treeviewitem, numeroNodi);
base.Nodes.Add(root);
}
else
{
if (_treeviewitem.Livello > lastLevel)
{
TreeNode child = getTreeNodeType(_treeviewitem, 0);
root.ChildNodes.Add(child);
root = child;
}
if (_treeviewitem.Livello <= lastLevel)
{
TreeNode parentNode = root;
while (parentNode.Depth > _treeviewitem.Livello)
{
parentNode = parentNode.Parent;
}
TreeNode child = getTreeNodeType(_treeviewitem, 0);
parentNode.Parent.ChildNodes.Add(child);
root = child;
}
}
lastLevel = _treeviewitem.Livello;
numeroNodi++;
}
}
private TreeNode getTreeNodeType(CustomDataItem _item, int nodo)
{
TreeNode _treenode = null;
switch (_item.TipoControllo)
{
case TipoControllo.MenuRoot:
_treenode = new MyTreeNodeRoot(this.ID, _item.Descrizione, nodo, _item.IsDefault, _item.IsMandatory, _item.SezionePersonalizzata, _item.IdSezione, _item.CSSClassName, _item.NoParentBehaviour, _item.IsSectionPrinting, _item.NoCheckedByParent);
break;
case TipoControllo.CheckBox:
_treenode = new MyTreeNodeCheck(this.ID, _item.Descrizione, _item.NomeControlloGruppo, _item.IsDefault, _item.IsMandatory, _item.SezionePersonalizzata, _item.IdSezione, _item.Image, _item.CSSClassName, _item.NoParentBehaviour, _item.IsSectionPrinting, _item.NoCheckedByParent); ;
break;
case TipoControllo.Label:
_treenode = new MyTreeNodeLabel(this.ID, _item.Descrizione, _item.CSSClassName, _item.NoParentBehaviour, _item.IsSectionPrinting, _item.NoCheckedByParent);
break;
case TipoControllo.RadioButton:
_treenode = new MyTreeNodeRadio(this.ID, _item.Descrizione, _item.NomeControlloGruppo, _item.IsDefault, _item.IsMandatory, _item.SezionePersonalizzata, _item.IdSezione, _item.CSSClassName, _item.NoParentBehaviour, _item.IsSectionPrinting, _item.NoCheckedByParent);
break;
default:
break;
}
return _treenode;
}
protected override object SaveViewState()
{
object[] arrState = new object[1];
arrState[0] = base.SaveViewState();
//arrState[1] = this.NodeText;
//arrState[2] = this.NodeURL;
return arrState;
}
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] arrState = savedState as object[];
//this.NodeText = (string)arrState[1];
//this.NodeURL = (string)arrState[2];
base.LoadViewState(arrState[0]);
}
}
//public void AddNode(TipoControllo tipo, string ID, int livello, string label, string preImage, string idSezione)
//{
// nodePreImage = preImage;
// this.AddNode(tipo, ID, livello, label, true, false, idSezione);
//}
protected override void Render(HtmlTextWriter output)
{
base.Render(output);
}
}
[Serializable]
public class MyTreeNodeCheck : System.Web.UI.WebControls.TreeNode, IDictionaryEnumerator
{
private DictionaryEntry nodeEntry;
private IEnumerator enumerator;
private bool stateEnabled = true;
private bool stateCheck = false;
private string _preImage;
private bool isMandatory = false;
private string _idtreeview;
string _css;
private bool noparentbehaviour = false;
private bool issectionprinting = false;
private int nocheckbyparent = 0;
private string Name = "";
public MyTreeNodeCheck()
{
enumerator = base.ChildNodes.GetEnumerator();
}
public MyTreeNodeCheck(string value, string idSezione)
: this()
{
base.Value = value;
base.SelectAction = TreeNodeSelectAction.None;
this.NodeKey = idSezione;
}
public MyTreeNodeCheck(string _id, string value, string _nomecontrollogruppo, bool enabled, bool _isMandatory, bool check, string idSezione, string image, string css, bool _noparentbehaviour, bool _issectionprinting, int _nocheckbyparent)
: this(value, idSezione)
{
isMandatory = _isMandatory;
stateEnabled = enabled;
stateCheck = check;
this.NodeKey = idSezione;
_idtreeview = _id;
this.preImage = image;
CssClassName = css;
noparentbehaviour = _noparentbehaviour;
issectionprinting = _issectionprinting;
nocheckbyparent = _nocheckbyparent;
if (_nomecontrollogruppo != null)
Name = _nomecontrollogruppo;
}
public string CssClassName
{
get { return _css; }
set { _css = value; }
}
public string IdTreeView
{
get { return _idtreeview; }
set { _idtreeview = value; }
}
private string _nodeStyle;
protected override void RenderPreText(System.Web.UI.HtmlTextWriter writer)
{
if (_preImage != "")
{
writer.AddAttribute("src", _preImage);
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
writer.AddAttribute("type", "checkbox");
writer.AddAttribute("id", this.NodeKey);
writer.AddAttribute("tipo", "SEZIONI");
if (noparentbehaviour)
writer.AddAttribute("noparentbehaviour", "true");
else
writer.AddAttribute("noparentbehaviour", "false");
writer.AddAttribute("nocheckbyparent", nocheckbyparent.ToString());
if (Name != null && Name != "")
writer.AddAttribute("name", Name);
if (issectionprinting)
writer.AddAttribute("issectionprinting", "true");
else
writer.AddAttribute("issectionprinting", "false");
writer.AddAttribute("class", "TreeViewItemClass");
writer.AddAttribute("onclick", "javascript:treeViewCheck(this);");
if (!stateEnabled || isMandatory)
writer.AddAttribute("disabled", "true");
if (stateCheck || isMandatory)
writer.AddAttribute("checked", "true");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
writer.AddAttribute("class", CssClassName);
}
protected override object SaveViewState()
{
object[] arrState = new object[1];
arrState[0] = base.SaveViewState();
//arrState[1] = this.NodeText;
//arrState[2] = this.NodeURL;
return arrState;
}
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] arrState = savedState as object[];
//this.NodeText = (string)arrState[1];
//this.NodeURL = (string)arrState[2];
base.LoadViewState(arrState[0]);
}
}
public string NodeStyle
{
set { this._nodeStyle = value; }
}
public string preImage
{
get
{
return _preImage;
}
set
{
_preImage = value;
}
}
public string NodeKey
{
get
{
return nodeEntry.Key.ToString();
}
set
{
nodeEntry.Key = value;
}
}
public object NodeValue
{
get
{
return nodeEntry.Value;
}
set
{
nodeEntry.Value = value;
}
}
public DictionaryEntry Entry
{
get
{
return nodeEntry;
}
}
public bool MoveNext()
{
bool Success;
Success = enumerator.MoveNext();
return Success;
}
public object Current
{
get
{
return enumerator.Current;
}
}
public object Key
{
get
{
return nodeEntry.Key;
}
}
public object Value
{
get
{
return nodeEntry.Value;
}
}
public void Reset()
{
enumerator.Reset();
}
}
[Serializable]
public class MyTreeNodeLabel : System.Web.UI.WebControls.TreeNode, IDictionaryEnumerator
{
private DictionaryEntry nodeEntry;
private IEnumerator enumerator;
private string _idtreeview;
private string _css;
private bool noparentbehaviour = false;
private bool issectionprinting = false;
private int nocheckbyparent = 0;
public MyTreeNodeLabel()
{
enumerator = base.ChildNodes.GetEnumerator();
}
public MyTreeNodeLabel(string _id, string value, string css, bool _noparentbehaviour, bool _issectionprinting, int _nocheckbyparent)
: this()
{
base.Value = value;
base.SelectAction = TreeNodeSelectAction.None;
_idtreeview = _id;
noparentbehaviour = _noparentbehaviour;
issectionprinting = _issectionprinting;
nocheckbyparent = _nocheckbyparent;
CssClassName = css;
}
public string IdTreeView
{
get { return _idtreeview; }
set { _idtreeview = value; }
}
private string _nodeStyle;
public string CssClassName
{
get { return _css; }
set { _css = value; }
}
protected override void RenderPreText(System.Web.UI.HtmlTextWriter writer)
{
writer.AddAttribute("type", "hidden");
writer.AddAttribute("tipo", "SEZIONI");
if (noparentbehaviour)
writer.AddAttribute("noparentbehaviour", "true");
else
writer.AddAttribute("noparentbehaviour", "false");
writer.AddAttribute("nocheckbyparent", nocheckbyparent.ToString());
if (issectionprinting)
writer.AddAttribute("issectionprinting", "true");
else
writer.AddAttribute("issectionprinting", "false");
writer.AddAttribute("class", "TreeViewItemClass");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
writer.AddAttribute("class", this.CssClassName);
writer.AddAttribute("style", this._nodeStyle);
}
protected override object SaveViewState()
{
object[] arrState = new object[1];
arrState[0] = base.SaveViewState();
//arrState[1] = this.NodeText;
//arrState[2] = this.NodeURL;
return arrState;
}
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] arrState = savedState as object[];
//this.NodeText = (string)arrState[1];
//this.NodeURL = (string)arrState[2];
base.LoadViewState(arrState[0]);
}
}
public string NodeStyle
{
set { this._nodeStyle = value; }
}
public string NodeKey
{
get
{
return nodeEntry.Key.ToString();
}
set
{
nodeEntry.Key = value;
}
}
public object NodeValue
{
get
{
return nodeEntry.Value;
}
set
{
nodeEntry.Value = value;
}
}
public DictionaryEntry Entry
{
get
{
return nodeEntry;
}
}
public bool MoveNext()
{
bool Success;
Success = enumerator.MoveNext();
return Success;
}
public object Current
{
get
{
return enumerator.Current;
}
}
public object Key
{
get
{
return nodeEntry.Key;
}
}
public object Value
{
get
{
return nodeEntry.Value;
}
}
public void Reset()
{
enumerator.Reset();
}
}
[Serializable]
public class MyTreeNodeRoot : System.Web.UI.WebControls.TreeNode, IDictionaryEnumerator
{
private DictionaryEntry nodeEntry;
private IEnumerator enumerator;
private int numeroNodo;
private bool stateEnabled = true;
private bool stateCheck = false;
private bool isMandatory = true;
private string _idtreeview;
private string _css;
private bool noparentbehaviour = false;
private bool issectionprinting = false;
private int nocheckbyparent = 0;
public MyTreeNodeRoot()
{
enumerator = base.ChildNodes.GetEnumerator();
}
public MyTreeNodeRoot(string value, int nodo, string idSezione): this()
{
numeroNodo = nodo;
base.Text = value;
base.SelectAction = TreeNodeSelectAction.None;
this._nodeStyle += "width: 550px;";
this.NodeKey = idSezione;
}
public string IdTreeView
{
get { return _idtreeview; }
set { _idtreeview = value; }
}
public string CssClassName
{
get { return _css; }
set { _css = value; }
}
public MyTreeNodeRoot(string _id, string value, int nodo, bool enabled, bool _isMandatory, bool check, string idSezione, string css, bool _noparentbehaviour, bool _issectionprinting, int _nocheckbyparent)
: this(value, nodo, idSezione)
{
isMandatory = _isMandatory;
stateEnabled = enabled;
stateCheck = check;
this.NodeKey = idSezione;
_idtreeview = _id;
this.CssClassName = css;
noparentbehaviour = _noparentbehaviour;
issectionprinting = _issectionprinting;
nocheckbyparent = _nocheckbyparent;
}
private string _nodeStyle;
protected override void RenderPreText(System.Web.UI.HtmlTextWriter writer)
{
writer.AddAttribute("type", "checkbox");
writer.AddAttribute("id", this.NodeKey);
writer.AddAttribute("tipo", "SEZIONI");
if (noparentbehaviour)
writer.AddAttribute("noparentbehaviour", "true");
else
writer.AddAttribute("noparentbehaviour", "false");
writer.AddAttribute("class", "TreeViewItemClass");
if (issectionprinting)
writer.AddAttribute("issectionprinting", "true");
else
writer.AddAttribute("issectionprinting", "false");
writer.AddAttribute("nocheckbyparent", nocheckbyparent.ToString());
writer.AddAttribute("onclick", "javascript:treeViewCheck(this);");
if (!stateEnabled || isMandatory)
writer.AddAttribute("disabled", "true");
if (stateCheck || isMandatory)
writer.AddAttribute("checked", "true");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
//setta lo stile del nodo
writer.AddAttribute("class", this.CssClassName);
}
protected override void RenderPostText(System.Web.UI.HtmlTextWriter writer)
{
//Mettere path relativa
writer.AddAttribute("src", "images/arrowDown.png");
//Indica lo stato di espansione del nodo (open/close)
writer.AddAttribute("state", "open");
//writer.AddAttribute("align", "bottom");
writer.AddAttribute("class", "image");
//Setta la funzione del TreeView che permette di espandere comprimere il nodo (si basa sull'id incrementale che gli viene assegnato nell'albero)
//<2F> la stessa funzione che il treeview utilizza quando si abilita ShowExpandeCollapse sull'oggetto +/-
writer.AddAttribute("onclick", " javascript:buttonExpandCollapse(this); javascript:TreeView_ToggleNode(" + _idtreeview + "_Data," + numeroNodo + "," + _idtreeview + "n" + numeroNodo + ",'%20'," + _idtreeview + "n" + numeroNodo + "Nodes);");
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
protected override object SaveViewState()
{
object[] arrState = new object[1];
arrState[0] = base.SaveViewState();
//arrState[1] = this.NodeText;
//arrState[2] = this.NodeURL;
return arrState;
}
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] arrState = savedState as object[];
//this.NodeText = (string)arrState[1];
//this.NodeURL = (string)arrState[2];
base.LoadViewState(arrState[0]);
}
}
public string NodeStyle
{
set { this._nodeStyle = value; }
}
public string NodeKey
{
get
{
return nodeEntry.Key.ToString();
}
set
{
nodeEntry.Key = value;
}
}
public object NodeValue
{
get
{
return nodeEntry.Value;
}
set
{
nodeEntry.Value = value;
}
}
public DictionaryEntry Entry
{
get
{
return nodeEntry;
}
}
public bool MoveNext()
{
bool Success;
Success = enumerator.MoveNext();
return Success;
}
public object Current
{
get
{
return enumerator.Current;
}
}
public object Key
{
get
{
return nodeEntry.Key;
}
}
public object Value
{
get
{
return nodeEntry.Value;
}
}
public void Reset()
{
enumerator.Reset();
}
}
[Serializable]
public class MyTreeNodeRadio : System.Web.UI.WebControls.TreeNode, IDictionaryEnumerator
{
private DictionaryEntry nodeEntry;
private IEnumerator enumerator;
private string Name;
private bool stateEnabled = true;
private bool stateCheck = false;
private bool isMandatory = false;
private string _idtreeview;
private string _css;
private bool noparentbehaviour = false;
private bool issectionprinting = false;
private int nocheckbyparent = 0;
public MyTreeNodeRadio()
{
enumerator = base.ChildNodes.GetEnumerator();
}
public MyTreeNodeRadio(string _id, string value, string gruppo, string idSezione): this()
{
Name = gruppo;
base.Value = value;
base.SelectAction = TreeNodeSelectAction.None;
this.NodeKey = idSezione;
_idtreeview = _id;
}
public MyTreeNodeRadio(string _id, string value, string gruppo, bool enabled, bool _isMandatory, bool check, string idSezione, string css, bool _noparentbehaviour, bool _issectionprinting, int _nocheckbyparent)
: this(_id,value, gruppo, idSezione)
{
_isMandatory = isMandatory;
stateEnabled = enabled;
stateCheck = check;
this.NodeKey = idSezione;
_idtreeview = _id;
CssClassName = css;
noparentbehaviour = _noparentbehaviour;
issectionprinting = _issectionprinting;
nocheckbyparent = _nocheckbyparent;
}
public string CssClassName
{
get { return _css; }
set { _css = value; }
}
private string _nodeStyle;
public string IdTreeView
{
get { return _idtreeview; }
set { _idtreeview = value; }
}
protected override void RenderPreText(System.Web.UI.HtmlTextWriter writer)
{
writer.AddAttribute("type", "radio");
writer.AddAttribute("onclick", "javascript:treeViewCheck(this);");
writer.AddAttribute("id", this.NodeKey);
writer.AddAttribute("tipo", "SEZIONI");
if (noparentbehaviour)
writer.AddAttribute("noparentbehaviour", "true");
else
writer.AddAttribute("noparentbehaviour", "false");
writer.AddAttribute("class", "TreeViewItemClass");
if (issectionprinting)
writer.AddAttribute("issectionprinting", "true");
else
writer.AddAttribute("issectionprinting", "false");
writer.AddAttribute("nocheckbyparent", nocheckbyparent.ToString());
if (!stateEnabled || isMandatory)
writer.AddAttribute("disabled", "true");
if (stateCheck || isMandatory)
writer.AddAttribute("checked", "true");
writer.AddAttribute("name", Name);
writer.AddAttribute("ShowCheckboxes", "true");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
writer.AddAttribute("class", CssClassName);
//writer.AddAttribute("style", this._nodeStyle);
}
protected override object SaveViewState()
{
object[] arrState = new object[1];
arrState[0] = base.SaveViewState();
//arrState[1] = this.NodeText;
//arrState[2] = this.NodeURL;
return arrState;
}
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] arrState = savedState as object[];
//this.NodeText = (string)arrState[1];
//this.NodeURL = (string)arrState[2];
base.LoadViewState(arrState[0]);
}
}
public string NodeStyle
{
set { this._nodeStyle = value; }
}
public string NodeKey
{
get
{
return nodeEntry.Key.ToString();
}
set
{
nodeEntry.Key = value;
}
}
public object NodeValue
{
get
{
return nodeEntry.Value;
}
set
{
nodeEntry.Value = value;
}
}
public DictionaryEntry Entry
{
get
{
return nodeEntry;
}
}
public bool MoveNext()
{
bool Success;
Success = enumerator.MoveNext();
return Success;
}
public object Current
{
get
{
return enumerator.Current;
}
}
public object Key
{
get
{
return nodeEntry.Key;
}
}
public object Value
{
get
{
return nodeEntry.Value;
}
}
public void Reset()
{
enumerator.Reset();
}
}
public enum TipoControllo
{
MenuRoot, CheckBox, RadioButton, Label, Image
}