Beispiel #1
0
 private string GetControlHtml(Type fieldType, ColumnDetailAttribute attrField, EditFormFieldPropsAttribute attrEdit, ControlType ct)
 {
     StringBuilder sb = new StringBuilder();
     switch (ct)
     {
         case ControlType.TagEdit:
             if (attrField.References != null)
                 sb.AppendFormat(@"<select multiple="""" class=""width-80 chosen-select form-control"" id=""{0}"" name=""{0}"" data-placeholder=""Select tags"">
         $ foreach(var e in Provider.Database.ReadList(typeof({1}), ""select Id, Name from {1} order by Name"")) {{ $
             <option>$=e.Name$</option>
         $ }} $
     </select>", FieldName, attrField.References.Name);
             else
                 sb.AppendFormat(@"<select multiple="""" class=""width-80 chosen-select form-control"" id=""{0}"" name=""{0}"" data-placeholder=""Select tags"">
         <option>Tag1</option>
         <option>Tag2</option>
         <option>Tag3</option>
     </select>", FieldName);
             break;
         case ControlType.StringEdit:
             if (attrField.Length>100 || attrField.ColumnType== DbType.Text)
                 sb.AppendFormat("<textarea name=\"{0}\" id=\"{0}\" rows=\"3\" class=\"col-sm-8 form-control\"></textarea>", FieldName);
             else
                 sb.AppendFormat("<input type=\"text\" name=\"{0}\" id=\"{0}\" placeholder=\"\" class=\"col-sm-6 form-control\"/>", FieldName);
             break;
         case ControlType.IntegerEdit:
         case ControlType.DecimalEdit:
             sb.AppendFormat("<input class=\"input-mini bkspinner form-control\" type=\"text\" name=\"{0}\" id=\"{0}\"/>", FieldName);
             break;
         case ControlType.DateTimeEdit:
             sb.AppendFormat("<input class=\"date-picker form-control\" type=\"text\" name=\"{0}\" id=\"{0}\" data-date-format=\"dd-mm-yyyy\"/><span class=\"input-group-addon\"><i class=\"icon-calendar bigger-110\"></i></span>", FieldName);
             break;
         case ControlType.PictureEdit:
             sb.AppendFormat("<img name=\"{0}\" class=\"img-responsive\" src=\"/UserFiles/contact.png\" /><input class=\"form-control\" type=\"file\" name=\"{0}\" id=\"{0}\"/>", FieldName);
             break;
         case ControlType.ComboBox:
             if (fieldType == typeof(bool))
                 sb.AppendFormat("<input type=\"checkbox\" name=\"{0}\" id=\"{0}\" class=\"ace ace-switch ace-switch-5 form-control\" value=\"1\"/><span class=\"lbl\"></span>", FieldName);
             if(attrField.References!=null)
                 sb.AppendFormat(@"<select id=""{0}"" name=""{0}"" class=""form-control"">
         $ foreach(var e in Provider.Database.ReadList(typeof({1}), ""select Id, Name from {1} order by Name"")) {{ $
             <option value=""$=e.Id$"">$=e.Name$</option>
         $ }} $
     </select>", FieldName, attrField.References.Name);
             if(fieldType.IsEnum)
                 sb.AppendFormat(@"<select id=""{0}"" name=""{0}"" class=""form-control"">
         $ foreach(var ev in Enum.GetNames(typeof({1}))) {{ $
             <option>$=ev$</option>
         $ }} $
     </select>", FieldName, fieldType.Name);
             break;
         case ControlType.LookUp:
             sb.AppendFormat(@"<input type=""hidden"" name=""{0}"" id=""{0}""/><input type=""text"" placeholder=""Search..."" class=""cinarChooser form-control""
     entityName=""{1}"" id=""{0}Chooser""
     selectedCallback=""on{0}ChooserSelected""
     autocomplete=""off"" />
     <div id=""{0}ChooserTemplate"" style=""display:none""><img height=""40"" src=""{{Picture}}""/> {{Name}}</div>
     <script>
     function on{0}ChooserSelected(id, name){{
         \$('{0}').val(id);
     }}
     </script>", FieldName, attrField.References.Name);
             break;
         case ControlType.CSSEdit:
         case ControlType.MemoEdit:
             sb.AppendFormat("<textarea name=\"{0}\" id=\"{0}\" rows=\"3\" class=\"col-sm-8 form-control\"></textarea>", FieldName);
             break;
         case ControlType.Undefined:
         case ControlType.FilterEdit:
         default:
             throw new Exception(Provider.GetResource("This kind of form field is not supported: {0}", ct));
     }
     return sb.ToString();
 }
Beispiel #2
0
        public static ControlType GetDefaultControlType(Cinar.Database.DbType dbType, PropertyInfo pi, ColumnDetailAttribute columnProps)
        {
            ControlType ct = ControlType.Undefined;
            Type type = pi.PropertyType;

            switch (dbType)
            {
                case Cinar.Database.DbType.Boolean:
                    ct = ControlType.ComboBox;
                    break;
                case Cinar.Database.DbType.Byte:
                case Cinar.Database.DbType.Int16:
                case Cinar.Database.DbType.Int32:
                case Cinar.Database.DbType.Int64:
                    ct = ControlType.IntegerEdit;
                    if (columnProps.References != null)
                        ct = ControlType.LookUp;
                    break;
                case Cinar.Database.DbType.Real:
                case Cinar.Database.DbType.Float:
                case Cinar.Database.DbType.Decimal:
                case Cinar.Database.DbType.Double:
                case Cinar.Database.DbType.Numeric:
                case Cinar.Database.DbType.Currency:
                case Cinar.Database.DbType.CurrencySmall:
                    ct = ControlType.DecimalEdit;
                    break;
                case Cinar.Database.DbType.DateTimeSmall:
                case Cinar.Database.DbType.DateTime:
                case Cinar.Database.DbType.Date:
                    ct = ControlType.DateTimeEdit;
                    break;
                case Cinar.Database.DbType.Char:
                case Cinar.Database.DbType.VarChar:
                case Cinar.Database.DbType.NChar:
                case Cinar.Database.DbType.NVarChar:
                case Cinar.Database.DbType.Text:
                case Cinar.Database.DbType.NText:
                case Cinar.Database.DbType.TextTiny:
                case Cinar.Database.DbType.TextMedium:
                case Cinar.Database.DbType.TextLong:
                    if (type.IsEnum)
                        ct = ControlType.ComboBox;
                    else
                        ct = ControlType.StringEdit;
                    break;
                case Cinar.Database.DbType.Time:
                case Cinar.Database.DbType.Timetz:
                case Cinar.Database.DbType.Timestamp:
                case Cinar.Database.DbType.Timestamptz:
                case Cinar.Database.DbType.Binary:
                case Cinar.Database.DbType.VarBinary:
                case Cinar.Database.DbType.Image:
                case Cinar.Database.DbType.Blob:
                case Cinar.Database.DbType.BlobTiny:
                case Cinar.Database.DbType.BlobMedium:
                case Cinar.Database.DbType.BlobLong:
                case Cinar.Database.DbType.Variant:
                case Cinar.Database.DbType.Guid:
                case Cinar.Database.DbType.Xml:
                case Cinar.Database.DbType.Set:
                case Cinar.Database.DbType.Enum:
                case Cinar.Database.DbType.Undefined:
                default:
                    switch (type.Name)
                    {
                        case "String":
                            if (type.IsEnum)
                                ct = ControlType.ComboBox;
                            else
                                ct = ControlType.StringEdit;
                            break;
                        case "Int16":
                        case "Int32":
                        case "Int64":
                            if (type.IsEnum)
                                ct = ControlType.ComboBox;
                            else if (columnProps.References != null)
                                ct = ControlType.LookUp;
                            else
                                ct = ControlType.IntegerEdit;
                            break;
                        case "Decimal":
                        case "Double":
                        case "Single":
                            ct = ControlType.DecimalEdit;
                            break;
                        case "DateTime":
                            ct = ControlType.DateTimeEdit;
                            break;
                        case "Boolean":
                            ct = ControlType.ComboBox;
                            break;
                        default:
                            if (type.IsEnum)
                                ct = ControlType.ComboBox;
                            else
                                throw new Exception(Provider.GetResource("A control type cannot be acquired from the field type!"));
                            break;
                    }
                    break;
            }

            return ct;
        }