protected virtual string GenerateOutputFileName(ActionArgs args, string outputFileName)
        {
            args.CommandArgument = args.CommandName;
            args.CommandName     = "FileName";
            List <FieldValue> values = new List <FieldValue>();

            values.Add(new FieldValue("FileName", outputFileName));
            args.Values = values.ToArray();
            ActionResult result = ControllerFactory.CreateDataController().Execute(args.Controller, args.View, args);

            foreach (FieldValue v in result.Values)
            {
                if (v.Name == "FileName")
                {
                    outputFileName = Convert.ToString(v.Value);
                    break;
                }
            }
            return(outputFileName);
        }
        string[] IAutoCompleteManager.GetCompletionList(string prefixText, int count, string contextKey)
        {
            if (contextKey == null)
            {
                return(null);
            }
            string[] arguments = contextKey.Split(',');
            if (arguments.Length != 3)
            {
                return(null);
            }
            DistinctValueRequest request = new DistinctValueRequest();

            request.FieldName = arguments[2];
            string filter = (request.FieldName + ":");

            foreach (string s in prefixText.Split(',', ';'))
            {
                string query = Controller.ConvertSampleToQuery(s);
                if (!(String.IsNullOrEmpty(query)))
                {
                    filter = (filter + query);
                }
            }
            request.Filter = new string[] {
                filter
            };
            request.AllowFieldInFilter = true;
            request.MaximumValueCount  = count;
            request.Controller         = arguments[0];
            request.View = arguments[1];
            object[]      list   = ControllerFactory.CreateDataController().GetListOfValues(arguments[0], arguments[1], request);
            List <string> result = new List <string>();

            foreach (object o in list)
            {
                result.Add(Convert.ToString(o));
            }
            return(result.ToArray());
        }
Exemplo n.º 3
0
 public bool PopulateStaticItems(DataField field, FieldValue[] contextValues)
 {
     if (field.SupportsStaticItems() && (String.IsNullOrEmpty(field.ContextFields) || ((contextValues != null) || (field.ItemsStyle == "CheckBoxList"))))
     {
         if (PopulatingStaticItems)
         {
             return(true);
         }
         PopulatingStaticItems = true;
         try
         {
             string[] filter = null;
             if (!(String.IsNullOrEmpty(field.ContextFields)))
             {
                 List <string> contextFilter = new List <string>();
                 Match         m             = Regex.Match(field.ContextFields, "(\\w+)=(.+?)($|,)");
                 while (m.Success)
                 {
                     Match vm = Regex.Match(m.Groups[2].Value, "^\'(.+?)\'$");
                     if (vm.Success)
                     {
                         contextFilter.Add(String.Format("{0}:={1}", m.Groups[1].Value, vm.Groups[1].Value));
                     }
                     else
                     if (contextValues != null)
                     {
                         foreach (FieldValue cv in contextValues)
                         {
                             if (cv.Name == m.Groups[2].Value)
                             {
                                 contextFilter.Add(String.Format("{0}:={1}", m.Groups[1].Value, cv.NewValue));
                                 break;
                             }
                         }
                     }
                     m = m.NextMatch();
                 }
                 filter = contextFilter.ToArray();
             }
             PageRequest request = new PageRequest(-1, 1000, field.ItemsDataTextField, filter);
             if (ActionArgs.Current != null)
             {
                 request.ExternalFilter = ActionArgs.Current.ExternalFilter;
             }
             ViewPage page = ControllerFactory.CreateDataController().GetPage(field.ItemsDataController, field.ItemsDataView, request);
             int      dataValueFieldIndex = page.Fields.IndexOf(page.FindField(field.ItemsDataValueField));
             if (dataValueFieldIndex == -1)
             {
                 foreach (DataField aField in page.Fields)
                 {
                     if (aField.IsPrimaryKey)
                     {
                         dataValueFieldIndex = page.Fields.IndexOf(aField);
                         break;
                     }
                 }
             }
             int dataTextFieldIndex = page.Fields.IndexOf(page.FindField(field.ItemsDataTextField));
             if (dataTextFieldIndex == -1)
             {
                 int i = 0;
                 while ((dataTextFieldIndex == -1) && (i < page.Fields.Count))
                 {
                     DataField f = page.Fields[i];
                     if (!(f.Hidden) && (f.Type == "String"))
                     {
                         dataTextFieldIndex = i;
                     }
                     i++;
                 }
                 if (dataTextFieldIndex == -1)
                 {
                     dataTextFieldIndex = 0;
                 }
             }
             List <int> fieldIndexes = new List <int>();
             fieldIndexes.Add(dataValueFieldIndex);
             fieldIndexes.Add(dataTextFieldIndex);
             if (!(String.IsNullOrEmpty(field.Copy)))
             {
                 Match m = Regex.Match(field.Copy, "(\\w+)=(\\w+)");
                 while (m.Success)
                 {
                     int copyFieldIndex = page.Fields.IndexOf(page.FindField(m.Groups[2].Value));
                     if (copyFieldIndex >= 0)
                     {
                         fieldIndexes.Add(copyFieldIndex);
                     }
                     m = m.NextMatch();
                 }
             }
             foreach (object[] row in page.Rows)
             {
                 object[] values = new object[fieldIndexes.Count];
                 for (int i = 0; (i < fieldIndexes.Count); i++)
                 {
                     int copyFieldIndex = fieldIndexes[i];
                     if (copyFieldIndex >= 0)
                     {
                         values[i] = row[copyFieldIndex];
                     }
                 }
                 field.Items.Add(values);
             }
             return(true);
         }
         finally
         {
             PopulatingStaticItems = false;
         }
     }
     return(false);
 }