public override void CreateControlBinding(CodeWriter output, ReferenceField c) { WebEditorReferenceFieldExtension extension = (WebEditorReferenceFieldExtension) c.GetExtension(typeof(WebEditorReferenceFieldExtension)); if (c.IsClientEditEnabled) { if (c.ReferenceType.IsTableCoded) { if (!output.ReferenceUsed(c)) { output.WriteLine("{0}Manager {1}Manager = new {0}Manager();", c.ReferenceType.Name, c.ReferenceType.ParentClassEntry.PrivateName, c.Name); output.WriteLine("{0}Collection {1}Collection = " + "{1}Manager.GetCollection(string.Empty, string.Empty);", c.ReferenceType.Name, c.ReferenceType.ParentClassEntry.PrivateName); // Save Reference For Later :)~ Take that! output.SaveReference(c, c.ReferenceType.ParentClassEntry.PrivateName + "Collection"); } } else { if (!output.ReferenceUsed(c)) { // BLECH! A Custom Manager, Blah BLAH! output.WriteLine("{0}Manager {1}Manager = new {0}Manager(\"{2}\");", c.ReferenceType.Name, c.PrivateName, c.TableName); output.WriteLine("{0}Collection {1}Collection = " + "{1}Manager.GetCollection(string.Empty, string.Empty);", c.ReferenceType.Name, c.PrivateName); // Save another pesky reference for later! // Don't worry so much bud, it keeps track of tables! output.SaveReference(c, c.PrivateName + "Collection"); } } output.WriteLine("foreach({0} itemObject in {1})", c.ReferenceType.Name, output.GetReference(c)); output.WriteLine("{"); output.Indent++; output.WriteLine("ComponentArt.Web.UI.ComboBoxItem item = " + "new ComponentArt.Web.UI.ComboBoxItem();"); output.WriteLine("item.Text = itemObject." + extension.ListText + ";"); output.WriteLine("item.Value = itemObject.ID.ToString();"); output.WriteLine("combo{0}.Items.Add(item);", c.Name); output.Indent--; output.WriteLine("}"); output.WriteLine(); } }
public override void SetControlValue(CodeWriter output, string className, ReferenceField c) { WebEditorReferenceFieldExtension e = (WebEditorReferenceFieldExtension) c.GetExtension(typeof(WebEditorReferenceFieldExtension)); if (c.IsClientEditEnabled) { if (c.ReferenceMode == ReferenceMode.Normal) { output.WriteLine("if({0}.{1} != null)", className, c.Name); output.WriteLine("{"); output.Indent++; if (e.ListText.Length > 0) { output.WriteLine("combo{0}.Text = {1}.{0}.{2};", c.Name, className, e.ListText); } else { output.WriteLine("combo{0}.Text = {1}.{0}.ToString()", c.Name, className); } output.WriteLine("foreach(ComponentArt.Web.UI.ComboBoxItem item in combo{0}.Items)", c.Name); output.WriteLine("{"); output.Indent++; output.WriteLine("if(item.Value == {0}.{1}.ID.ToString())", className, c.Name); output.WriteLine("{"); output.Indent++; output.WriteLine("combo{0}.SelectedItem = item;", c.Name); output.WriteLine("break;"); output.Indent--; output.WriteLine("}"); output.Indent--; output.WriteLine("}"); output.Indent--; output.WriteLine("}"); output.WriteLine("else"); output.WriteLine("{"); output.Indent++; output.WriteLine("// Necissary to clear prior ViewState - if only we don't need it."); output.WriteLine("combo{0}.Text = string.Empty;", c.Name); output.WriteLine("combo{0}.SelectedItem = null;", c.Name); output.Indent--; output.WriteLine("}"); } else if (c.ReferenceMode == ReferenceMode.Collection) { output.WriteLine("tb{0}.Text = {1}.{0}.ToEncodedString(\"<br>\");", c.Name, className); } } else { output.WriteLine("lt{0}.Text = {1}.{0}.ToString();", c.Name, className); } }
public static ComponentArtReferenceFieldExtension Find(ReferenceField f) { return((ComponentArtReferenceFieldExtension) f.GetExtension(typeof(ComponentArtReferenceFieldExtension))); }
public static WebEditorReferenceFieldExtension Find(ReferenceField f) { return((WebEditorReferenceFieldExtension) f.GetExtension(typeof(WebEditorReferenceFieldExtension))); }
public override void CreateControlProperties(CodeWriter output, ReferenceField f, bool instantiate, bool enableViewState, string addControlFormat) { ComponentArtReferenceFieldExtension extension = (ComponentArtReferenceFieldExtension) f.GetExtension(typeof(ComponentArtReferenceFieldExtension)); WebEditorReferenceFieldExtension editExtension = (WebEditorReferenceFieldExtension) f.GetExtension(typeof(WebEditorReferenceFieldExtension)); if (f.IsClientEditEnabled) { if (f.ReferenceMode == ReferenceMode.Normal) { // TODO - MAKE THE CSS CLASSES EXTENSIONS ON REFERENCES output.WriteLine("combo{0} = new ComponentArt.Web.UI.ComboBox();", f.Name); output.WriteLine("combo{0}.ID = \"combo{0}\";", f.Name); output.WriteLine("combo{0}.CssClass = \"{1}\";", f.Name, extension.CssClass); output.WriteLine("combo{0}.HoverCssClass = \"{1}\";", f.Name, extension.HoverCssClass); output.WriteLine("combo{0}.FocusedCssClass = \"{1}\";", f.Name, extension.FocusedCssClass); output.WriteLine("combo{0}.TextBoxCssClass = \"{1}\";", f.Name, extension.TextBoxCssClass); output.WriteLine("combo{0}.DropDownCssClass = \"{1}\";", f.Name, extension.DropDownCssClass); output.WriteLine("combo{0}.ItemCssClass = \"{1}\";", f.Name, extension.ItemCssClass); output.WriteLine("combo{0}.ItemHoverCssClass = \"{1}\";", f.Name, extension.ItemHoverCssClass); output.WriteLine("combo{0}.SelectedItemCssClass = \"{1}\";", f.Name, extension.SelectedItemCssClass); output.WriteLine("combo{0}.DropHoverImageUrl = \"{1}\";", f.Name, extension.DropHoverImageUrl); output.WriteLine("combo{0}.DropImageUrl = \"{1}\";", f.Name, extension.DropImageUrl); if (!f.AllowNull) { output.Write("combo{0}.TextBoxEnabled = false;", f.Name); } if (extension.Width.Type == System.Web.UI.WebControls.UnitType.Pixel) { output.WriteLine("combo{0}.Width = Unit.Pixel(" + extension.Width.Value.ToString() + ");", f.Name); } else if (extension.Width.Type == System.Web.UI.WebControls.UnitType.Percentage) { output.WriteLine("combo{0}.Width = Unit.Percentage(" + extension.Width.Value.ToString() + ");", f.Name); } if (!enableViewState) { output.WriteLine("// combo{0}.EnableViewState = false; // This is not " + " yet possible, ComponentArt's ComboBox Requires ViewState!!!", f.Name); } output.WriteLine(addControlFormat, string.Format("combo{0}", f.Name), f.Caption != string.Empty ? f.Caption : f.Name); } else if (f.ReferenceMode == ReferenceMode.Collection) { output.WriteLine("tb{0} = new TextBox();", f.Name); output.WriteLine("tb{0}.ID = this.ID + \"_ref\";", f.Name); output.WriteLine("tb{0}.EnableViewState = false;", f.Name); output.WriteLine("tb{0}.Rows = 10;", f.Name); output.WriteLine("tb{0}.MaxLength = 1500;", f.Name); output.WriteLine("tb{0}.TextMode = TextBoxMode.MultiLine;", f.Name); output.WriteLine("tb{0}.Width = Unit.Pixel(350);", f.Name); output.WriteLine(addControlFormat, string.Format("tb{0}", f.Name), f.Caption != string.Empty ? f.Caption : f.Name); output.WriteLine("Panel {0}Panel = new Panel();", f.Name); output.WriteLine("{0}Panel.Controls.Add(new LiteralControl(\"<div style=\\\"float:left\\\">\"));", f.Name); output.WriteLine("combo{0} = new ComponentArt.Web.UI.ComboBox();", f.Name); output.WriteLine("combo{0}.CssClass = \"{1}\";", f.Name, extension.CssClass); output.WriteLine("combo{0}.HoverCssClass = \"{1}\";", f.Name, extension.HoverCssClass); output.WriteLine("combo{0}.FocusedCssClass = \"{1}\";", f.Name, extension.FocusedCssClass); output.WriteLine("combo{0}.TextBoxCssClass = \"{1}\";", f.Name, extension.TextBoxCssClass); output.WriteLine("combo{0}.DropDownCssClass = \"{1}\";", f.Name, extension.DropDownCssClass); output.WriteLine("combo{0}.ItemCssClass = \"{1}\";", f.Name, extension.ItemCssClass); output.WriteLine("combo{0}.ItemHoverCssClass = \"{1}\";", f.Name, extension.ItemHoverCssClass); output.WriteLine("combo{0}.SelectedItemCssClass = \"{1}\";", f.Name, extension.SelectedItemCssClass); output.WriteLine("combo{0}.DropHoverImageUrl = \"{1}\";", f.Name, extension.DropHoverImageUrl); output.WriteLine("combo{0}.DropImageUrl = \"{1}\";", f.Name, extension.DropImageUrl); output.WriteLine("combo{0}.Width = Unit.Pixel(300);", f.Name); if (!enableViewState) { output.WriteLine("// combo{0}.EnableViewState = false; // This is not " + " yet possible, ComponentArt's ComboBox Requires ViewState!!!", f.Name); } output.WriteLine("{0}Panel.Controls.Add({0}Panel);", f.Name); output.WriteLine("{0}Panel.Controls.Add(new LiteralControl(\"</div><div><input type=\\\"button\\\" value=\\\"Add\\\" \" +", f.Name); output.WriteLine("\t\"align=\\\"right\\\" onClick=\\\"\" +"); output.WriteLine("\ttb{0}.ClientID + \".value += (\" + tb{0}.ClientID + \".value != '' ? '\\\\r\\\\n' : '') + \" +", f.Name); output.WriteLine("\tcombo{0}.ClientObjectId + \".getSelectedItem().Text;\\\"></div>\"));", f.Name); output.WriteLine(addControlFormat, string.Format("{0}Panel", f.ParentFolder), " "); } if (editExtension.EditorNote.Length > 0) { output.WriteLine(addControlFormat, string.Format("new LiteralControl(\"{0}\")", editExtension.EditorNote), " "); } } else if (f.IsClientViewEnabled) { output.WriteLine("lt{0} = new Literal();", f.Name); output.WriteLine("lt{0}.EnableViewState = false;", f.Name); output.WriteLine(addControlFormat, string.Format("lt{0}", f.Name), f.Caption != string.Empty ? f.Caption : f.Name); } }
public override string Render() { CodeWriter output = new CodeWriter(); output.WriteLine("/* ********************************************************** *"); output.WriteLine(" * AMNS NitroCast v1.0 Web Grid Generator - GreyFox *"); output.WriteLine(" * Autogenerated by NitroCast © 2004 Roy A.E Hodges *"); output.WriteLine(" * All Rights Reserved *"); output.WriteLine(" * ---------------------------------------------------------- *"); output.WriteLine(" * Source code may not be reproduced or redistributed without *"); output.WriteLine(" * written expressed permission from the author. *"); output.WriteLine(" * Permission is granted to modify source code by licencee. *"); output.WriteLine(" * These permissions do not extend to third parties. *"); output.WriteLine(" * ********************************************************** */"); output.WriteLine(); output.WriteLine("using System;"); output.WriteLine("using System.ComponentModel;"); output.WriteLine("using System.Web;"); output.WriteLine("using System.Web.UI;"); output.WriteLine("using Amns.GreyFox.Web.UI.WebControls;"); // // Add imported namespaces // int importCount = -1; bool addImport = true; string[] namespacelist = new string[_modelClass.ReferenceFields.Count]; foreach (ReferenceField c in _modelClass.ReferenceFields) { addImport = true; foreach (string name in namespacelist) { if (c.ReferenceType.NameSpace == name | c.ReferenceType.NameSpace == _modelClass.Namespace) { addImport = false; break; } } if (addImport) { importCount++; namespacelist[importCount] = c.ReferenceType.NameSpace; } } for (int x = 0; x <= importCount; x++) { output.WriteLine("using {0};", namespacelist[x]); } output.WriteLine(); output.WriteLine("namespace {0}.Web.UI.WebControls", _modelClass.Namespace); output.WriteLine("{"); output.Indent++; output.WriteLine("/// <summary>"); output.WriteXmlSummary(string.Format("A custom grid for {0}.", _modelClass.Name)); output.WriteLine("/// </summary>"); output.Write("[ToolboxData(\"<{0}:"); output.Write("{0}Grid runat=server>", _modelClass.Name); output.Write("</{0}:"); output.WriteLine("{0}Grid>\")]", _modelClass.Name); // // Class Start // output.WriteLine("public class {0}Grid : TableGrid", _modelClass.Name); output.WriteLine("{"); output.Indent++; // // Private Fields // if (!_modelClass.IsTableCoded) { if (_modelClass.DefaultTableName != string.Empty) { output.WriteLine("private string tableName = \"{0}\";", _modelClass.DefaultTableName); } else { output.WriteLine("private string tableName;"); } } output.WriteLine(); output.WriteLine("#region Public Properties"); if (!_modelClass.IsTableCoded) { output.WriteLine("[Bindable(false),"); output.Indent++; output.WriteLine("Category(\"Data\"),"); output.WriteLine("DefaultValue(\"{0}\")]", _modelClass.DefaultTableName); output.Indent--; output.WriteProperty("string", "tableName", "TableName"); output.WriteLine(); } output.WriteLine("#endregion"); output.WriteLine(); output.WriteLine("protected override void OnInit(EventArgs e)"); output.WriteLine("{"); output.Indent++; output.WriteLine("base.OnInit(e);"); output.WriteLine("features = TableWindowFeatures.ClipboardCopier | "); output.Indent++; output.WriteLine("TableWindowFeatures.Scroller |"); output.WriteLine("TableWindowFeatures.WindowPrinter |"); output.WriteLine("TableWindowFeatures.ClientSideSelector;"); output.Indent--; //output.WriteLine("components = TableWindowComponents.Toolbar |"); //output.Indent++; //output.WriteLine("TableWindowComponents.ViewPane;"); //output.Indent--; output.Indent--; output.WriteLine("}"); output.WriteLine(); output.WriteLine("#region Rendering"); output.WriteLine(); output.WriteLine("/// <summary> "); output.WriteLine("/// Render this control to the output parameter specified."); output.WriteLine("/// </summary>"); output.WriteLine("/// <param name=\"output\"> The HTML writer to write out to </param>"); output.WriteLine("protected override void RenderContent(HtmlTextWriter output)"); output.WriteLine("{"); output.Indent++; if (_modelClass.IsTableCoded) { output.WriteLine("{0}Manager m = new {0}Manager();", _modelClass.Name); } else { output.WriteLine("{0}Manager m = new {0}Manager(tableName);", _modelClass.Name); } if (_modelClass.ReferenceFields.Count > 0) { output.WriteLine("{0}Collection {1}Collection = m.GetCollection(string.Empty, string.Empty, null);", _modelClass.Name, _modelClass.PrivateName); } else { output.WriteLine("{0}Collection {1}Collection = m.GetCollection(string.Empty, string.Empty);", _modelClass.Name, _modelClass.PrivateName); } #region Header Locked Row bool commaEnabled = false; string headerRow = ""; // <<----- REPLACE WITH STRINGBUILDER foreach (ClassFolder folder in _modelClass.Folders) { foreach (object i in folder.Items) { if (i is ValueField) { ValueField f = (ValueField)i; WebGridValueFieldExtension e = (WebGridValueFieldExtension) f.GetExtension(typeof(WebGridValueFieldExtension)); if (e.GridEnabled) { if (commaEnabled) { headerRow += ", "; } headerRow += "\"" + (f.Caption.Length > 0 ? f.Caption : f.Name) + "\""; commaEnabled = true; } } else if (i is ReferenceField) { ReferenceField f = (ReferenceField)i; WebGridReferenceFieldExtension e = (WebGridReferenceFieldExtension) f.GetExtension(typeof(WebGridReferenceFieldExtension)); if (e.GridEnabled) { if (commaEnabled) { headerRow += ", "; } headerRow += "\"" + (f.Caption.Length > 0 ? f.Caption : f.Name) + "\""; commaEnabled = true; } } else if (i is EnumField) { EnumField f = (EnumField)i; WebGridEnumFieldExtension e = (WebGridEnumFieldExtension) f.GetExtension(typeof(WebGridEnumFieldExtension)); if (e.GridEnabled) { if (commaEnabled) { headerRow += ", "; } headerRow += "\"" + (f.Caption.Length > 0 ? f.Caption : f.Name) + "\""; commaEnabled = true; } } } } if (headerRow.Length > 0) { output.WriteLine("// Render Header Row"); output.WriteLine("this.headerLockEnabled = true;"); output.Write("RenderRow(this.HeaderRowCssClass, "); output.Write(headerRow); output.WriteLine(");"); output.WriteLine(); } #endregion output.WriteLine("bool rowflag = false;"); output.WriteLine("string rowCssClass;"); output.WriteLine("//"); output.WriteLine("// Render Records"); output.WriteLine("//"); output.WriteLine("foreach({0} {1} in {1}Collection)", _modelClass.Name, _modelClass.PrivateName); output.WriteLine("{"); output.Indent++; output.WriteLine("if(rowflag) rowCssClass = defaultRowCssClass;"); output.WriteLine("else rowCssClass = alternateRowCssClass;"); output.WriteLine("rowflag = !rowflag;"); output.WriteLine("output.WriteBeginTag(\"tr\");"); output.WriteLine("output.WriteAttribute(\"i\", {0}.ID.ToString());", _modelClass.PrivateName); output.WriteLine("output.WriteLine(HtmlTextWriter.TagRightChar);"); output.WriteLine("output.Indent++;"); output.WriteLine(); foreach (ClassFolder folder in _modelClass.Folders) { foreach (object i in folder.Items) { if (i is ValueField) { ValueField f = (ValueField)i; WebGridValueFieldExtension e = (WebGridValueFieldExtension) f.GetExtension(typeof(WebGridValueFieldExtension)); if (e.GridEnabled) { output.WriteLine("//"); output.WriteLine("// Render Main Representation of Record"); output.WriteLine("//"); output.WriteLine("output.WriteBeginTag(\"td\");"); output.WriteLine("output.WriteAttribute(\"valign\", \"top\");"); output.WriteLine("output.WriteAttribute(\"class\", rowCssClass);"); output.WriteLine("output.Write(HtmlTextWriter.TagRightChar);"); if (e.GridFormat.Length > 0) { output.WriteLine("output.Write({0}.{1}.ToString(\"{2}\"));", _modelClass.PrivateName, f.Name, e.GridFormat); } else { output.WriteLine("output.Write({0}.{1});", _modelClass.PrivateName, f.Name); } output.WriteLine("output.WriteEndTag(\"td\");"); output.WriteLine("output.WriteLine();"); output.WriteLine(); } } else if (i is ReferenceField) { ReferenceField c = (ReferenceField)i; WebGridReferenceFieldExtension e = (WebGridReferenceFieldExtension) c.GetExtension(typeof(WebGridReferenceFieldExtension)); if (e.GridEnabled) { output.WriteLine("//"); output.WriteLine("// Render Main Representation of Record"); output.WriteLine("//"); output.WriteLine("output.WriteBeginTag(\"td\");"); output.WriteLine("output.WriteAttribute(\"valign\", \"top\");"); output.WriteLine("output.WriteAttribute(\"class\", rowCssClass);"); output.WriteLine("output.Write(HtmlTextWriter.TagRightChar);"); output.WriteLine("if({0}.{1} != null)", _modelClass.PrivateName, c.Name); output.WriteLine("{"); output.Indent++; if (e.GridFormat.Length > 0) { output.WriteLine("output.Write({0}.{1}.ToString(\"{2}\"));", _modelClass.PrivateName, c.Name, e.GridFormat); } else { output.WriteLine("output.Write({0}.{1});", _modelClass.PrivateName, c.Name); } output.Indent--; output.WriteLine("}"); output.WriteLine("else"); output.WriteLine("{"); output.Indent++; output.WriteLine("output.Write(\"null\");"); output.Indent--; output.WriteLine("}"); output.WriteLine("output.WriteEndTag(\"td\");"); output.WriteLine("output.WriteLine();"); output.WriteLine(); } } else if (i is EnumField) { EnumField f = (EnumField)i; WebGridEnumFieldExtension e = (WebGridEnumFieldExtension) f.GetExtension(typeof(WebGridEnumFieldExtension)); if (e.GridEnabled) { output.WriteLine("//"); output.WriteLine("// Render Main Representation of Record"); output.WriteLine("//"); output.WriteLine("output.WriteBeginTag(\"td\");"); output.WriteLine("output.WriteAttribute(\"valign\", \"top\");"); output.WriteLine("output.WriteAttribute(\"class\", rowCssClass);"); output.WriteLine("output.Write(HtmlTextWriter.TagRightChar);"); output.WriteLine("output.Write({0}.{1}.ToString());", _modelClass.PrivateName, f.Name); output.WriteLine("output.WriteEndTag(\"td\");"); output.WriteLine("output.WriteLine();"); output.WriteLine(); } } } } output.WriteLine("output.Indent--;"); output.WriteLine("output.WriteEndTag(\"tr\");"); output.WriteLine("output.WriteLine();"); output.Indent--; output.WriteLine("}"); output.Indent--; output.WriteLine("}"); output.WriteLine(); output.WriteLine("#endregion"); output.WriteLine(); // // Class End // output.Indent--; output.WriteLine("}"); // // Namespace End // output.Indent--; output.WriteLine("}"); return(output.ToString()); }