void IPlugIn.ProcessPageRequest(PageRequest request, ViewPage page) { if (page.Rows.Count == 0) { page.Icons = new string[0]; return; } if (!(_requireProcessing)) { List<string> icons = new List<string>(); for (int i = 0; (i < page.Rows.Count); i++) { string rowDir = AnnotationPlugIn.GenerateDataRecordPath(request.Controller, page, null, i); if (Directory.Exists(rowDir)) icons.Add("Attachment"); else icons.Add(null); } page.Icons = icons.ToArray(); return; } List<DynamicExpression> expressions = new List<DynamicExpression>(page.Expressions); DynamicExpression de = new DynamicExpression(); de.Target = "Annotations"; de.Scope = DynamicExpressionScope.CategoryVisibility; de.Type = DynamicExpressionType.ClientScript; de.Test = "!this.get_isInserting()"; de.ViewId = page.View; expressions.Add(de); page.Expressions = expressions.ToArray(); if (!(_retrieveAnnotations)) return; DataField field = page.FindField("_Annotation_AttachmentNew"); if (field != null) { int fieldIndex = page.Fields.IndexOf(field); string newValue = String.Format("{0},{1}|{2}", request.Controller, field.Name, Regex.Replace(((string)(page.Rows[0][fieldIndex])), "^\\w+\\|(.+)$", "$1")); if (field.Name == "_Annotation_AttachmentNew") newValue = ("null|" + newValue); page.Rows[0][fieldIndex] = newValue; } string p = AnnotationPlugIn.GenerateDataRecordPath(request.Controller, page, null, 0); if (Directory.Exists(p)) { string[] files = Directory.GetFiles(p, "*.xml"); List<object> values = new List<object>(page.Rows[0]); int i = (files.Length - 1); while (i >= 0) { string filename = files[i]; XPathDocument doc = new XPathDocument(filename); XPathNavigator nav = doc.CreateNavigator().SelectSingleNode("/*"); DataField f = null; if (nav.Name == "note") { f = new DataField(); f.Name = "_Annotation_Note"; f.Type = "String"; f.HeaderText = String.Format(Localizer.Replace("AnnotationNoteDynamicFieldHeaderText", "{0} written at {1}"), ReadNameAndEmail(nav), Convert.ToDateTime(nav.GetAttribute("timestamp", String.Empty))); f.Columns = 50; f.Rows = 7; f.TextMode = TextInputMode.Note; values.Add(nav.Value); } else if (nav.Name == "attachment") { f = new DataField(); f.Name = "_Annotation_Attachment"; f.Type = "Byte[]"; f.HeaderText = String.Format(Localizer.Replace("AnnotationAttachmentDynamicFieldHeaderText", "{0} attached <b>{1}</b> at {2}"), ReadNameAndEmail(nav), nav.GetAttribute("fileName", String.Empty), Convert.ToDateTime(nav.GetAttribute("timestamp", String.Empty))); f.OnDemand = true; f.OnDemandHandler = "AnnotationPlugIn"; f.OnDemandStyle = OnDemandDisplayStyle.Link; if (nav.GetAttribute("contentType", String.Empty).StartsWith("image/")) f.OnDemandStyle = OnDemandDisplayStyle.Thumbnail; f.CategoryIndex = (page.Categories.Count - 1); values.Add(nav.GetAttribute("value", String.Empty)); } if (f != null) { f.Name = (f.Name + Path.GetFileNameWithoutExtension(filename)); f.AllowNulls = true; f.CategoryIndex = (page.Categories.Count - 1); if (!(Controller.UserIsInRole("Administrators"))) f.ReadOnly = true; page.Fields.Add(f); } i = (i - 1); } page.Rows[0] = values.ToArray(); if (files.Length > 0) { page.Categories[(page.Categories.Count - 1)].Tab = Localizer.Replace("AnnotationTab", "Notes & Attachments"); expressions.RemoveAt((expressions.Count - 1)); page.Expressions = expressions.ToArray(); } } else { de.Test = "this.get_isEditing() && this.get_view()._displayAnnotations"; ActionGroup g = new ActionGroup(); page.ActionGroups.Add(g); g.Scope = "ActionBar"; g.Flat = true; Action a = new Action(); g.Actions.Add(a); a.WhenLastCommandName = "Edit"; a.WhenView = page.View; a.CommandName = "ClientScript"; a.CommandArgument = "this.get_view()._displayAnnotations=true;this._focusedFieldName = \'_Annotation_No" + "teNew\';this._raiseSelectedDelayed=false;"; a.HeaderText = Localizer.Replace("AnnotationActionHeaderText", "Annotate"); a.CssClass = "AttachIcon"; a.WhenClientScript = "this.get_view()._displayAnnotations!=true;"; } }
public static object StringToValue(DataField field, string s) { if (!(String.IsNullOrEmpty(s)) && s.StartsWith("%js%")) { #pragma warning disable 0618 System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); #pragma warning restore 0618 object v = serializer.Deserialize<object>(s.Substring(4)); if (!((v is string)) || ((field == null) || (field.Type == "String"))) return v; s = ((string)(v)); } if (field != null) return TypeDescriptor.GetConverter(Controller.TypeMap[field.Type]).ConvertFromString(s); return s; }
protected virtual void EnsureSystemPageFields(PageRequest request, ViewPage page, DbCommand command) { if (!(RequiresHierarchy(page))) return; bool requiresHierarchyOrganization = false; foreach (DataField field in page.Fields) if (field.IsTagged("hierarchy-parent")) requiresHierarchyOrganization = true; else if (field.IsTagged("hierarchy-organization")) { requiresHierarchyOrganization = false; break; } if (requiresHierarchyOrganization) { DataField field = new DataField(); field.Name = HierarchyOrganizationFieldName; field.Type = "String"; field.Tag = "hierarchy-organization"; field.Len = 255; field.Columns = 20; field.Hidden = true; field.ReadOnly = true; page.Fields.Add(field); } }
protected string CreateValueFromSourceFields(DataField field, DbDataReader reader) { string v = String.Empty; if (DBNull.Value.Equals(reader[field.Name])) v = "null"; Match m = Regex.Match(field.SourceFields, "(\\w+)\\s*(,|$)"); while (m.Success) { if (v.Length > 0) v = (v + "|"); object rawValue = reader[m.Groups[1].Value]; if ((rawValue != null) && (rawValue.GetType() == typeof(byte[]))) rawValue = new Guid(((byte[])(rawValue))); v = (v + Convert.ToString(rawValue)); m = m.NextMatch(); } return v; }
protected void PopulatePageFields(ViewPage page) { if (page.Fields.Count > 0) return; XPathNodeIterator dataFieldIterator = _view.Select(".//c:dataFields/c:dataField", Resolver); while (dataFieldIterator.MoveNext()) { XPathNodeIterator fieldIterator = _config.Select("/c:dataController/c:fields/c:field[@name=\'{0}\']", dataFieldIterator.Current.GetAttribute("fieldName", String.Empty)); if (fieldIterator.MoveNext()) { DataField field = new DataField(fieldIterator.Current, Resolver); field.Hidden = (dataFieldIterator.Current.GetAttribute("hidden", String.Empty) == "true"); field.DataFormatString = fieldIterator.Current.GetAttribute("dataFormatString", String.Empty); string formatOnClient = dataFieldIterator.Current.GetAttribute("formatOnClient", String.Empty); if (!(String.IsNullOrEmpty(formatOnClient))) field.FormatOnClient = formatOnClient != "false"; if (String.IsNullOrEmpty(field.DataFormatString)) field.DataFormatString = dataFieldIterator.Current.GetAttribute("dataFormatString", String.Empty); field.HeaderText = ((string)(dataFieldIterator.Current.Evaluate("string(c:headerText)", Resolver))); field.FooterText = ((string)(dataFieldIterator.Current.Evaluate("string(c:footerText)", Resolver))); field.ToolTip = dataFieldIterator.Current.GetAttribute("toolTip", String.Empty); field.Watermark = dataFieldIterator.Current.GetAttribute("watermark", String.Empty); field.HyperlinkFormatString = dataFieldIterator.Current.GetAttribute("hyperlinkFormatString", String.Empty); field.AliasName = dataFieldIterator.Current.GetAttribute("aliasFieldName", String.Empty); field.Tag = dataFieldIterator.Current.GetAttribute("tag", String.Empty); if (!(String.IsNullOrEmpty(dataFieldIterator.Current.GetAttribute("allowQBE", String.Empty)))) field.AllowQBE = (dataFieldIterator.Current.GetAttribute("allowQBE", String.Empty) == "true"); if (!(String.IsNullOrEmpty(dataFieldIterator.Current.GetAttribute("allowSorting", String.Empty)))) field.AllowSorting = (dataFieldIterator.Current.GetAttribute("allowSorting", String.Empty) == "true"); field.CategoryIndex = Convert.ToInt32(dataFieldIterator.Current.Evaluate("count(parent::c:dataFields/parent::c:category/preceding-sibling::c:category)", Resolver)); string columns = dataFieldIterator.Current.GetAttribute("columns", String.Empty); if (!(String.IsNullOrEmpty(columns))) field.Columns = Convert.ToInt32(columns); string rows = dataFieldIterator.Current.GetAttribute("rows", String.Empty); if (!(String.IsNullOrEmpty(rows))) field.Rows = Convert.ToInt32(rows); string textMode = dataFieldIterator.Current.GetAttribute("textMode", String.Empty); if (!(String.IsNullOrEmpty(textMode))) field.TextMode = ((TextInputMode)(TypeDescriptor.GetConverter(typeof(TextInputMode)).ConvertFromString(textMode))); string maskType = fieldIterator.Current.GetAttribute("maskType", String.Empty); if (!(String.IsNullOrEmpty(maskType))) field.MaskType = ((DataFieldMaskType)(TypeDescriptor.GetConverter(typeof(DataFieldMaskType)).ConvertFromString(maskType))); field.Mask = fieldIterator.Current.GetAttribute("mask", String.Empty); string readOnly = dataFieldIterator.Current.GetAttribute("readOnly", String.Empty); if (!(String.IsNullOrEmpty(readOnly))) field.ReadOnly = (readOnly == "true"); string aggregate = dataFieldIterator.Current.GetAttribute("aggregate", String.Empty); if (!(String.IsNullOrEmpty(aggregate))) field.Aggregate = ((DataFieldAggregate)(TypeDescriptor.GetConverter(typeof(DataFieldAggregate)).ConvertFromString(aggregate))); string search = dataFieldIterator.Current.GetAttribute("search", String.Empty); if (!(String.IsNullOrEmpty(search))) field.Search = ((FieldSearchMode)(TypeDescriptor.GetConverter(typeof(FieldSearchMode)).ConvertFromString(search))); field.SearchOptions = dataFieldIterator.Current.GetAttribute("searchOptions", String.Empty); string prefixLength = dataFieldIterator.Current.GetAttribute("autoCompletePrefixLength", String.Empty); if (!(String.IsNullOrEmpty(prefixLength))) field.AutoCompletePrefixLength = Convert.ToInt32(prefixLength); XPathNodeIterator itemsIterator = dataFieldIterator.Current.Select("c:items[c:item]", Resolver); if (!(itemsIterator.MoveNext())) { itemsIterator = fieldIterator.Current.Select("c:items", Resolver); if (!(itemsIterator.MoveNext())) itemsIterator = null; } if (itemsIterator != null) { field.ItemsDataController = itemsIterator.Current.GetAttribute("dataController", String.Empty); field.ItemsDataView = itemsIterator.Current.GetAttribute("dataView", String.Empty); field.ItemsDataValueField = itemsIterator.Current.GetAttribute("dataValueField", String.Empty); field.ItemsDataTextField = itemsIterator.Current.GetAttribute("dataTextField", String.Empty); field.ItemsStyle = itemsIterator.Current.GetAttribute("style", String.Empty); field.ItemsNewDataView = itemsIterator.Current.GetAttribute("newDataView", String.Empty); field.Copy = itemsIterator.Current.GetAttribute("copy", String.Empty); string pageSize = itemsIterator.Current.GetAttribute("pageSize", String.Empty); if (!(String.IsNullOrEmpty(pageSize))) field.ItemsPageSize = Convert.ToInt32(pageSize); field.ItemsLetters = (itemsIterator.Current.GetAttribute("letters", String.Empty) == "true"); XPathNodeIterator itemIterator = itemsIterator.Current.Select("c:item", Resolver); while (itemIterator.MoveNext()) { string itemValue = itemIterator.Current.GetAttribute("value", String.Empty); if (itemValue == "NULL") itemValue = String.Empty; string itemText = itemIterator.Current.GetAttribute("text", String.Empty); field.Items.Add(new object[] { itemValue, itemText}); } if (!(String.IsNullOrEmpty(field.ItemsNewDataView)) && (((ActionArgs.Current == null) || (ActionArgs.Current.Controller == field.ItemsDataController)) && ((PageRequest.Current == null) || (PageRequest.Current.Controller == field.ItemsDataController)))) { Controller itemsController = ((Controller)(this.GetType().Assembly.CreateInstance(this.GetType().FullName))); itemsController.SelectView(field.ItemsDataController, field.ItemsNewDataView); string roles = ((string)(itemsController._config.Evaluate("string(//c:action[@commandName=\'New\' and @commandArgument=\'{0}\'][1]/@roles)", field.ItemsNewDataView))); if (!(Controller.UserIsInRole(roles))) field.ItemsNewDataView = null; } field.AutoSelect = (itemsIterator.Current.GetAttribute("autoSelect", String.Empty) == "true"); field.SearchOnStart = (itemsIterator.Current.GetAttribute("searchOnStart", String.Empty) == "true"); field.ItemsDescription = itemsIterator.Current.GetAttribute("description", String.Empty); } if (!(Controller.UserIsInRole(fieldIterator.Current.GetAttribute("writeRoles", String.Empty)))) field.ReadOnly = true; if (!(Controller.UserIsInRole(fieldIterator.Current.GetAttribute("roles", String.Empty)))) { field.ReadOnly = true; field.Hidden = true; } page.Fields.Add(field); // populate pivot info if (page.RequiresPivot) { if ((page.PivotDefinitions != null) && page.PivotDefinitions.ContainsKey(field.Name)) field.Tag = (field.Tag + (" " + page.PivotDefinitions[field.Name])); foreach (string tag in field.Tag.Split(' ')) if (tag.StartsWith("pivot")) { page.AddPivotField(field); break; } } } } }
private void ExportDataAsCsv(ViewPage page, DbDataReader reader, StreamWriter writer) { bool firstField = true; for (int i = 0; (i < page.Fields.Count); i++) { DataField field = page.Fields[i]; if (!(field.Hidden)) { if (firstField) { firstField = false; } else { writer.Write(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator); } if (!(String.IsNullOrEmpty(field.AliasName))) { field = page.FindField(field.AliasName); } writer.Write("\"{0}\"", field.Label.Replace("\"", "\"\"")); } field.NormalizeDataFormatString(); } writer.WriteLine(); while (reader.Read()) { firstField = true; for (int j = 0; (j < page.Fields.Count); j++) { DataField field = page.Fields[j]; if (!(field.Hidden)) { if (firstField) { firstField = false; } else { writer.Write(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator); } if (!(String.IsNullOrEmpty(field.AliasName))) { field = page.FindField(field.AliasName); } string text = String.Empty; object v = reader[field.Name]; if (!(DBNull.Value.Equals(v))) { if (!(String.IsNullOrEmpty(field.DataFormatString))) { text = String.Format(field.DataFormatString, v); } else { text = Convert.ToString(v); } writer.Write("\"{0}\"", text.Replace("\"", "\"\"")); } else { writer.Write("\"\""); } } } writer.WriteLine(); } }
protected virtual void ConfigureDataField(ViewPage page, DataField field) { }
private void ExportDataAsRowset(ViewPage page, DbDataReader reader, StreamWriter writer) { string s = "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"; string dt = "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"; string rs = "urn:schemas-microsoft-com:rowset"; string z = "#RowsetSchema"; XmlWriterSettings settings = new XmlWriterSettings(); settings.CloseOutput = false; XmlWriter output = XmlWriter.Create(writer, settings); output.WriteStartDocument(); output.WriteStartElement("xml"); output.WriteAttributeString("xmlns", "s", null, s); output.WriteAttributeString("xmlns", "dt", null, dt); output.WriteAttributeString("xmlns", "rs", null, rs); output.WriteAttributeString("xmlns", "z", null, z); // declare rowset schema output.WriteStartElement("Schema", s); output.WriteAttributeString("id", "RowsetSchema"); output.WriteStartElement("ElementType", s); output.WriteAttributeString("name", "row"); output.WriteAttributeString("content", "eltOnly"); output.WriteAttributeString("CommandTimeout", rs, "60"); List <DataField> fields = new List <DataField>(); foreach (DataField field in page.Fields) { if (!((field.Hidden || field.OnDemand)) && !(fields.Contains(field))) { DataField aliasField = field; if (!(String.IsNullOrEmpty(field.AliasName))) { aliasField = page.FindField(field.AliasName); } fields.Add(aliasField); } } int number = 1; foreach (DataField field in fields) { field.NormalizeDataFormatString(); output.WriteStartElement("AttributeType", s); output.WriteAttributeString("name", field.Name); output.WriteAttributeString("number", rs, number.ToString()); output.WriteAttributeString("nullable", rs, "true"); output.WriteAttributeString("name", rs, field.Label); output.WriteStartElement("datatype", s); string type = RowsetTypeMap[field.Type]; string dbType = null; if ("{0:c}".Equals(field.DataFormatString, StringComparison.CurrentCultureIgnoreCase)) { dbType = "currency"; } else if (!(String.IsNullOrEmpty(field.DataFormatString)) && field.Type != "DateTime") { type = "string"; } output.WriteAttributeString("type", dt, type); output.WriteAttributeString("dbtype", rs, dbType); output.WriteEndElement(); output.WriteEndElement(); number++; } output.WriteStartElement("extends", s); output.WriteAttributeString("type", "rs:rowbase"); output.WriteEndElement(); output.WriteEndElement(); output.WriteEndElement(); // output rowset data output.WriteStartElement("data", rs); while (reader.Read()) { output.WriteStartElement("row", z); foreach (DataField field in fields) { object v = reader[field.Name]; if (!(DBNull.Value.Equals(v))) { if (!(String.IsNullOrEmpty(field.DataFormatString)) && !(((field.DataFormatString == "{0:d}") || (field.DataFormatString == "{0:c}")))) { output.WriteAttributeString(field.Name, String.Format(field.DataFormatString, v)); } else if (field.Type == "DateTime") { output.WriteAttributeString(field.Name, ((DateTime)(v)).ToString("s")); } else { output.WriteAttributeString(field.Name, v.ToString()); } } } output.WriteEndElement(); } output.WriteEndElement(); output.WriteEndElement(); output.WriteEndDocument(); output.Close(); }
private void ExportDataAsRss(ViewPage page, DbDataReader reader, StreamWriter writer) { string appPath = Regex.Replace(HttpContext.Current.Request.Url.AbsoluteUri, "^(.+)Export.ashx.+$", "$1", RegexOptions.IgnoreCase); XmlWriterSettings settings = new XmlWriterSettings(); settings.CloseOutput = false; XmlWriter output = XmlWriter.Create(writer, settings); output.WriteStartDocument(); output.WriteStartElement("rss"); output.WriteAttributeString("version", "2.0"); output.WriteStartElement("channel"); output.WriteElementString("title", ((string)(_view.Evaluate("string(concat(/c:dataController/@label, \' | \', @label))", Resolver)))); output.WriteElementString("lastBuildDate", DateTime.Now.ToString("r")); output.WriteElementString("language", System.Threading.Thread.CurrentThread.CurrentCulture.Name.ToLower()); int rowCount = 0; while ((rowCount < MaximumRssItems) && reader.Read()) { output.WriteStartElement("item"); bool hasTitle = false; bool hasPubDate = false; StringBuilder desc = new StringBuilder(); for (int i = 0; (i < page.Fields.Count); i++) { DataField field = page.Fields[i]; if (!(field.Hidden)) { if (rowCount == 0) { field.NormalizeDataFormatString(); } if (!(String.IsNullOrEmpty(field.AliasName))) { field = page.FindField(field.AliasName); } string text = String.Empty; object v = reader[field.Name]; if (!(DBNull.Value.Equals(v))) { if (!(String.IsNullOrEmpty(field.DataFormatString))) { text = String.Format(field.DataFormatString, v); } else { text = Convert.ToString(v); } } if (!(hasPubDate) && (field.Type == "DateTime")) { hasPubDate = true; if (!(String.IsNullOrEmpty(text))) { output.WriteElementString("pubDate", ((DateTime)(reader[field.Name])).ToString("r")); } } if (!(hasTitle)) { hasTitle = true; output.WriteElementString("title", text); StringBuilder link = new StringBuilder(); link.Append(_config.Evaluate("string(/c:dataController/@name)")); foreach (DataField pkf in page.Fields) { if (pkf.IsPrimaryKey) { link.Append(String.Format("&{0}={1}", pkf.Name, reader[pkf.Name])); } } string itemGuid = String.Format("{0}Details.aspx?l={1}", appPath, HttpUtility.UrlEncode(Convert.ToBase64String(Encoding.Default.GetBytes(link.ToString())))); output.WriteElementString("link", itemGuid); output.WriteElementString("guid", itemGuid); } else if (!(String.IsNullOrEmpty(field.OnDemandHandler)) && (field.OnDemandStyle == OnDemandDisplayStyle.Thumbnail)) { if (text.Equals("1")) { desc.AppendFormat("{0}:<br /><img src=\"{1}Blob.ashx?{2}=t", HttpUtility.HtmlEncode(field.Label), appPath, field.OnDemandHandler); foreach (DataField f in page.Fields) { if (f.IsPrimaryKey) { desc.Append("|"); desc.Append(reader[f.Name]); } } desc.Append("\" style=\"width:92px;height:71px;\"/><br />"); } } else { desc.AppendFormat("{0}: {1}<br />", HttpUtility.HtmlEncode(field.Label), HttpUtility.HtmlEncode(text)); } } } output.WriteStartElement("description"); output.WriteCData(String.Format("<span style=\\\"font-size:small;\\\">{0}</span>", desc.ToString())); output.WriteEndElement(); output.WriteEndElement(); rowCount++; } output.WriteEndElement(); output.WriteEndElement(); output.WriteEndDocument(); output.Close(); }
void IPlugIn.ProcessPageRequest(PageRequest request, ViewPage page) { if (page.Rows.Count == 0) { page.Icons = new string[0]; return; } if (!_requireProcessing) { var icons = new List <string>(); for (var i = 0; (i < page.Rows.Count); i++) { var rowDir = AnnotationPlugIn.GenerateDataRecordPath(request.Controller, page, null, i); if (Directory.Exists(rowDir)) { icons.Add("Attachment"); } else { icons.Add(null); } } page.Icons = icons.ToArray(); return; } var expressions = new List <DynamicExpression>(page.Expressions); var de = new DynamicExpression(); de.Target = "Annotations"; de.Scope = DynamicExpressionScope.CategoryVisibility; de.Type = DynamicExpressionType.ClientScript; de.Test = "!this.get_isInserting()"; de.ViewId = page.View; expressions.Add(de); page.Expressions = expressions.ToArray(); if (!_retrieveAnnotations) { return; } var field = page.FindField("_Annotation_AttachmentNew"); if (field != null) { var fieldIndex = page.Fields.IndexOf(field); var newValue = string.Format("{0},{1}|{2}", request.Controller, field.Name, Regex.Replace(((string)(page.Rows[0][fieldIndex])), "^\\w+\\|(.+)$", "$1")); if (field.Name == "_Annotation_AttachmentNew") { newValue = ("null|" + newValue); } page.Rows[0][fieldIndex] = newValue; } var p = AnnotationPlugIn.GenerateDataRecordPath(request.Controller, page, null, 0); if (Directory.Exists(p)) { var files = Directory.GetFiles(p, "*.xml"); var values = new List <object>(page.Rows[0]); var i = (files.Length - 1); while (i >= 0) { var filename = files[i]; var doc = new XPathDocument(filename); var nav = doc.CreateNavigator().SelectSingleNode("/*"); DataField f = null; if (nav.Name == "note") { f = new DataField(); f.Name = "_Annotation_Note"; f.Type = "String"; f.HeaderText = string.Format(Localizer.Replace("AnnotationNoteDynamicFieldHeaderText", "{0} written at {1}"), ReadNameAndEmail(nav), Convert.ToDateTime(nav.GetAttribute("timestamp", string.Empty))); f.Columns = 50; f.Rows = 7; f.TextMode = TextInputMode.Note; values.Add(nav.Value); } else if (nav.Name == "attachment") { f = new DataField(); f.Name = "_Annotation_Attachment"; f.Type = "Byte[]"; f.HeaderText = string.Format(Localizer.Replace("AnnotationAttachmentDynamicFieldHeaderText", "{0} attached <b>{1}</b> at {2}"), ReadNameAndEmail(nav), nav.GetAttribute("fileName", string.Empty), Convert.ToDateTime(nav.GetAttribute("timestamp", string.Empty))); f.OnDemand = true; f.OnDemandHandler = "AnnotationPlugIn"; f.OnDemandStyle = OnDemandDisplayStyle.Link; if (nav.GetAttribute("contentType", string.Empty).StartsWith("image/")) { f.OnDemandStyle = OnDemandDisplayStyle.Thumbnail; } f.CategoryIndex = (page.Categories.Count - 1); values.Add(nav.GetAttribute("value", string.Empty)); } if (f != null) { f.Name = (f.Name + Path.GetFileNameWithoutExtension(filename)); f.AllowNulls = true; f.CategoryIndex = (page.Categories.Count - 1); if (!(Controller.UserIsInRole("Administrators"))) { f.ReadOnly = true; } page.Fields.Add(f); } i = (i - 1); } page.Rows[0] = values.ToArray(); if (files.Length > 0) { page.Categories[(page.Categories.Count - 1)].Tab = Localizer.Replace("AnnotationTab", "Notes & Attachments"); expressions.RemoveAt((expressions.Count - 1)); page.Expressions = expressions.ToArray(); } } else { de.Test = "this.get_isEditing() && this.get_view()._displayAnnotations"; var g = new ActionGroup(); page.ActionGroups.Add(g); g.Scope = "ActionBar"; g.Flat = true; var a = new Action(); g.Actions.Add(a); a.WhenLastCommandName = "Edit"; a.WhenView = page.View; a.CommandName = "ClientScript"; a.CommandArgument = "this.get_view()._displayAnnotations=true;this._focusedFieldName = \'_Annotation_No" + "teNew\';this._raiseSelectedDelayed=false;"; a.HeaderText = Localizer.Replace("AnnotationActionHeaderText", "Annotate"); a.CssClass = "AttachIcon"; a.WhenClientScript = "this.get_view()._displayAnnotations!=true;"; } }
public int ExecuteAction(ActionArgs args, ActionResult result, ViewPage page) { DataTable t = GetTable(args.Controller, null); if (args.CommandName == "Insert") { DataRow r = t.NewRow(); foreach (FieldValue v in args.Values) { DataField f = page.FindField(v.Name); if (f.IsPrimaryKey && f.ReadOnly) { object key = null; if (f.Type == "Guid") { key = Guid.NewGuid(); } else if (!(PrimaryKeys.TryGetValue(args.Controller, out key))) { key = -1; PrimaryKeys.Add(args.Controller, key); } else { key = (Convert.ToInt32(key) - 1); PrimaryKeys[args.Controller] = key; } r[v.Name] = key; result.Values.Add(new FieldValue(v.Name, key)); FieldValue fv = args.SelectFieldValueObject(v.Name); fv.NewValue = key; fv.Modified = true; } else if (v.Modified) { if (v.NewValue == null) { r[v.Name] = DBNull.Value; } else { r[v.Name] = v.NewValue; } } } t.Rows.Add(r); return(1); } else { DataRow targetRow = null; foreach (DataRow r in t.Rows) { bool matched = true; foreach (DataField f in page.Fields) { if (f.IsPrimaryKey) { object kv = r[f.Name]; object kv2 = args.SelectFieldValueObject(f.Name).OldValue; if (((kv == null) || (kv2 == null)) || !((kv.ToString() == kv2.ToString()))) { matched = false; break; } } } if (matched) { targetRow = r; break; } } if (targetRow == null) { return(0); } if (args.CommandName == "Delete") { t.Rows.Remove(targetRow); } else { foreach (FieldValue v in args.Values) { if (v.Modified) { if (v.NewValue == null) { targetRow[v.Name] = DBNull.Value; } else { targetRow[v.Name] = v.NewValue; } } } } return(1); } }
protected virtual void WriteJSONValue(StreamWriter writer, object v, DataField field) { string dataFormatString = null; if (field != null) dataFormatString = field.DataFormatString; if (v == null) writer.Write("null"); else if (v is string) writer.Write("\"{0}\"", BusinessRules.JavaScriptString(((string)(v)))); else if (v is DateTime) writer.Write("\"{0}\"", ConvertDateToJSON(((DateTime)(v)), dataFormatString)); else if (v is Guid) writer.Write("\"{0}\"", BusinessRules.JavaScriptString(v.ToString())); else if (v is bool) writer.Write(v.ToString().ToLower()); else if (!(String.IsNullOrEmpty(dataFormatString))) writer.Write("\"{0}\"", ConvertValueToJSON(v, dataFormatString)); else writer.Write(ConvertValueToJSON(v, null)); }
public DataField(DataField field) : this() { this._isMirror = true; this._name = (field.Name + "_Mirror"); this._type = field.Type; this._len = field.Len; this._label = field.Label; this._readOnly = true; this._allowNulls = field.AllowNulls; this._allowQBE = field.AllowQBE; this._allowSorting = field.AllowSorting; this._allowLEV = field.AllowLEV; this._dataFormatString = field.DataFormatString; this._aggregate = field.Aggregate; if (!(this._dataFormatString.Contains("{"))) this._dataFormatString = String.Format("{{0:{0}}}", this._dataFormatString); field._aliasName = this._name; this.FormatOnClient = false; field.FormatOnClient = true; field.DataFormatString = String.Empty; this._hidden = true; }
protected virtual void ProcessArguments(ControllerConfiguration config, ActionArgs args) { if (args.Values == null) { return; } FieldValueDictionary values = new FieldValueDictionary(args); _pk = null; // detect negative primary keys XPathNavigator pkNav = config.SelectSingleNode("/c:dataController/c:fields/c:field[@isPrimaryKey=\'true\']"); if (pkNav != null) { FieldValue fv = null; if (values.TryGetValue(pkNav.GetAttribute("name", String.Empty), out fv)) { int value = 0; if ((fv.NewValue != null) && int.TryParse(Convert.ToString(fv.NewValue), out value)) { if (value < 0) { if (args.CommandName == "Insert") { // request a new row from business rules PageRequest newRowRequest = new PageRequest(); newRowRequest.Controller = args.Controller; newRowRequest.View = args.View; newRowRequest.Inserting = true; newRowRequest.RequiresMetaData = true; newRowRequest.MetadataFilter = new string[] { "fields" }; ViewPage page = ControllerFactory.CreateDataController().GetPage(newRowRequest.Controller, newRowRequest.View, newRowRequest); if (page.NewRow != null) { for (int i = 0; (i < page.NewRow.Length); i++) { object newValue = page.NewRow[i]; if (newValue != null) { DataField field = page.Fields[i]; if (field.IsPrimaryKey) { // resolve the value of the primary key ResolvePrimaryKey(args.Controller, fv.Name, value, newValue); value = 0; fv.NewValue = newValue; } else { // inject a missing default value in the arguments FieldValue newFieldValue = null; if (values.TryGetValue(field.Name, out newFieldValue)) { if (!(newFieldValue.Modified)) { newFieldValue.NewValue = newValue; newFieldValue.Modified = true; } } else { List <FieldValue> newValues = new List <FieldValue>(args.Values); newFieldValue = new FieldValue(field.Name, newValue); newValues.Add(newFieldValue); args.Values = newValues.ToArray(); values[field.Name] = newFieldValue; } } } } } } // resolve the primary key after the command execution if (value < 0) { _pk = new FieldValue(fv.Name, value); fv.NewValue = null; fv.Modified = false; } } } } } // resolve negative foreign keys if (_resolvedKeys.Count > 0) { XPathNodeIterator fkIterator = config.Select("/c:dataController/c:fields/c:field[c:items/@dataController]"); while (fkIterator.MoveNext()) { FieldValue fv = null; if (values.TryGetValue(fkIterator.Current.GetAttribute("name", String.Empty), out fv)) { XPathNavigator itemsDataControllerNav = fkIterator.Current.SelectSingleNode("c:items/@dataController", config.Resolver); object resolvedKey = null; if (_resolvedKeys.TryGetValue(String.Format("{0}${1}", itemsDataControllerNav.Value, fv.NewValue), out resolvedKey)) { fv.NewValue = resolvedKey; } } } } }