private IDataSourceFieldSchema[] GetFieldSchemas()
 {
     if (this._fieldSchemas == null)
     {
         IDataSourceViewSchema  schema       = null;
         DesignerDataSourceView designerView = this._controlDesigner.DesignerView;
         if (designerView != null)
         {
             try
             {
                 schema = designerView.Schema;
             }
             catch (Exception exception)
             {
                 IComponentDesignerDebugService service = (IComponentDesignerDebugService)base.ServiceProvider.GetService(typeof(IComponentDesignerDebugService));
                 if (service != null)
                 {
                     service.Fail(System.Design.SR.GetString("DataSource_DebugService_FailedCall", new object[] { "DesignerDataSourceView.Schema", exception.Message }));
                 }
             }
         }
         if (schema != null)
         {
             this._fieldSchemas = schema.GetFields();
         }
     }
     return(this._fieldSchemas);
 }
 public virtual TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context, Type typeFilter)
 {
     string[] destinationArray = null;
     if (context != null)
     {
         IDataSourceViewSchemaAccessor instance = context.Instance as IDataSourceViewSchemaAccessor;
         if (instance != null)
         {
             IDataSourceViewSchema dataSourceViewSchema = instance.DataSourceViewSchema as IDataSourceViewSchema;
             if (dataSourceViewSchema != null)
             {
                 IDataSourceFieldSchema[] fields = dataSourceViewSchema.GetFields();
                 string[] sourceArray            = new string[fields.Length];
                 int      index = 0;
                 for (int i = 0; i < fields.Length; i++)
                 {
                     if (((typeFilter != null) && (fields[i].DataType == typeFilter)) || (typeFilter == null))
                     {
                         sourceArray[index] = fields[i].Name;
                         index++;
                     }
                 }
                 destinationArray = new string[index];
                 Array.Copy(sourceArray, destinationArray, index);
             }
         }
         if (destinationArray == null)
         {
             destinationArray = new string[0];
         }
         Array.Sort(destinationArray, Comparer.Default);
     }
     return(new TypeConverter.StandardValuesCollection(destinationArray));
 }
        /// <summary>
        /// Returns a set of sample data used to populate
        /// controls at design time.
        /// </summary>
        /// <param name="minimumRows">Minimum number of sample rows
        /// to create.</param>
        /// <param name="isSampleData">Returns True if the data
        /// is sample data.</param>
        public override IEnumerable GetDesignTimeData(int minimumRows, out bool isSampleData)
        {
            IDataSourceViewSchema schema = this.Schema;
            DataTable             result = new DataTable();

            // create the columns
            foreach (IDataSourceFieldSchema item in schema.GetFields())
            {
                result.Columns.Add(item.Name, item.DataType);
            }

            // create sample data
            for (int index = 1; index <= minimumRows; index++)
            {
                object[] values   = new object[result.Columns.Count];
                int      colIndex = 0;
                foreach (DataColumn col in result.Columns)
                {
                    if (col.DataType.Equals(typeof(string)))
                    {
                        values[colIndex] = "abc";
                    }
                    else if (col.DataType.Equals(typeof(System.DateTime)))
                    {
                        values[colIndex] = System.DateTime.Today.ToShortDateString();
                    }
                    else if (col.DataType.Equals(typeof(System.DateTimeOffset)))
                    {
                        values[colIndex] = System.DateTime.Today.ToShortDateString();
                    }
                    else if (col.DataType.Equals(typeof(bool)))
                    {
                        values[colIndex] = false;
                    }
                    else if (col.DataType.IsPrimitive)
                    {
                        values[colIndex] = index;
                    }
                    else if (col.DataType.Equals(typeof(Guid)))
                    {
                        values[colIndex] = Guid.Empty;
                    }
                    else if (col.DataType.IsValueType)
                    {
                        values[colIndex] = Activator.CreateInstance(col.DataType);
                    }
                    else
                    {
                        values[colIndex] = null;
                    }
                    colIndex += 1;
                }
                result.LoadDataRow(values, LoadOption.OverwriteChanges);
            }

            isSampleData = true;
            return((IEnumerable)result.DefaultView);
        }
        private void CreateDefaultTemplate()
        {
            string                text             = string.Empty;
            StringBuilder         builder          = new StringBuilder();
            DataList              component        = (DataList)base.Component;
            IDataSourceViewSchema dataSourceSchema = this.GetDataSourceSchema();

            IDataSourceFieldSchema[] fields = null;
            if (dataSourceSchema != null)
            {
                fields = dataSourceSchema.GetFields();
            }
            if ((fields != null) && (fields.Length > 0))
            {
                foreach (IDataSourceFieldSchema schema2 in fields)
                {
                    string name    = schema2.Name;
                    char[] chArray = new char[name.Length];
                    for (int i = 0; i < name.Length; i++)
                    {
                        char c = name[i];
                        if (char.IsLetterOrDigit(c) || (c == '_'))
                        {
                            chArray[i] = c;
                        }
                        else
                        {
                            chArray[i] = '_';
                        }
                    }
                    string str3 = new string(chArray);
                    builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:Label Text='<%# {1} %>' runat=\"server\" id=\"{2}Label\"/><br />", new object[] { name, DesignTimeDataBinding.CreateEvalExpression(name, string.Empty), str3 }));
                    builder.Append(Environment.NewLine);
                    if (schema2.PrimaryKey && (component.DataKeyField.Length == 0))
                    {
                        component.DataKeyField = name;
                    }
                }
                builder.Append("<br />");
                builder.Append(Environment.NewLine);
                text = builder.ToString();
            }
            if ((text != null) && (text.Length > 0))
            {
                try
                {
                    component.ItemTemplate = base.GetTemplateFromText(text, component.ItemTemplate);
                }
                catch
                {
                }
            }
        }
Example #5
0
 private static DataTable[] ConvertSchemaToDataTables(TypeSchema schema)
 {
     if (schema == null)
     {
         return(null);
     }
     IDataSourceViewSchema[] views = schema.GetViews();
     if (views == null)
     {
         return(null);
     }
     DataTable[] tableArray = new DataTable[views.Length];
     for (int i = 0; i < views.Length; i++)
     {
         IDataSourceViewSchema schema2 = views[i];
         tableArray[i] = new DataTable(schema2.Name);
         IDataSourceFieldSchema[] fields = schema2.GetFields();
         if (fields != null)
         {
             List <DataColumn> list = new List <DataColumn>();
             for (int j = 0; j < fields.Length; j++)
             {
                 IDataSourceFieldSchema schema3 = fields[j];
                 DataColumn             column  = new DataColumn {
                     AllowDBNull   = schema3.Nullable,
                     AutoIncrement = schema3.Identity,
                     ColumnName    = schema3.Name,
                     DataType      = schema3.DataType
                 };
                 if (column.DataType == typeof(string))
                 {
                     column.MaxLength = schema3.Length;
                 }
                 column.ReadOnly = schema3.IsReadOnly;
                 column.Unique   = schema3.IsUnique;
                 tableArray[i].Columns.Add(column);
                 if (schema3.PrimaryKey)
                 {
                     list.Add(column);
                 }
             }
             if (list.Count > 0)
             {
                 tableArray[i].PrimaryKey = list.ToArray();
             }
         }
     }
     return(tableArray);
 }
 private void AddKeysAndBoundFields(IDataSourceViewSchema schema)
 {
     DataControlFieldCollection columns = ((GridView) base.Component).Columns;
     if (schema != null)
     {
         IDataSourceFieldSchema[] fields = schema.GetFields();
         if ((fields != null) && (fields.Length > 0))
         {
             ArrayList list = new ArrayList();
             foreach (IDataSourceFieldSchema schema2 in fields)
             {
                 if (((GridView) base.Component).IsBindableType(schema2.DataType))
                 {
                     BoundField field;
                     if ((schema2.DataType == typeof(bool)) || (schema2.DataType == typeof(bool?)))
                     {
                         field = new CheckBoxField();
                     }
                     else
                     {
                         field = new BoundField();
                     }
                     string name = schema2.Name;
                     if (schema2.PrimaryKey)
                     {
                         list.Add(name);
                     }
                     field.DataField = name;
                     field.HeaderText = name;
                     field.SortExpression = name;
                     field.ReadOnly = schema2.PrimaryKey || schema2.IsReadOnly;
                     field.InsertVisible = !schema2.Identity;
                     columns.Add(field);
                 }
             }
             ((GridView) base.Component).AutoGenerateColumns = false;
             int count = list.Count;
             if (count > 0)
             {
                 string[] array = new string[count];
                 list.CopyTo(array, 0);
                 ((GridView) base.Component).DataKeyNames = array;
             }
         }
     }
 }
 public static bool ViewSchemasEquivalent(IDataSourceViewSchema viewSchema1, IDataSourceViewSchema viewSchema2)
 {
     if ((viewSchema1 == null) ^ (viewSchema2 == null))
     {
         return(false);
     }
     if ((viewSchema1 != null) || (viewSchema2 != null))
     {
         IDataSourceFieldSchema[] fields       = viewSchema1.GetFields();
         IDataSourceFieldSchema[] schemaArray2 = viewSchema2.GetFields();
         if ((fields == null) ^ (schemaArray2 == null))
         {
             return(false);
         }
         if ((fields == null) && (schemaArray2 == null))
         {
             return(true);
         }
         int length = fields.Length;
         int num2   = schemaArray2.Length;
         if (length != num2)
         {
             return(false);
         }
         foreach (IDataSourceFieldSchema schema in fields)
         {
             bool   flag     = false;
             string name     = schema.Name;
             Type   dataType = schema.DataType;
             foreach (IDataSourceFieldSchema schema2 in schemaArray2)
             {
                 if ((name == schema2.Name) && (dataType == schema2.DataType))
                 {
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Example #8
0
        private void AddKeysAndBoundFields(IDataSourceViewSchema schema)
        {
            JQGridColumnCollection columns = ((JQGrid)base.Component).Columns;

            try
            {
                columns.Clear();
            }
            catch (Exception)
            {
            }
            if (schema != null)
            {
                IDataSourceFieldSchema[] fields = schema.GetFields();
                if (fields != null && fields.Length > 0)
                {
                    new ArrayList();
                    IDataSourceFieldSchema[] array = fields;
                    for (int i = 0; i < array.Length; i++)
                    {
                        IDataSourceFieldSchema dataSourceFieldSchema = array[i];
                        if (((JQGrid)base.Component).IsBindableType(dataSourceFieldSchema.DataType))
                        {
                            JQGridColumn jQGridColumn;
                            if (dataSourceFieldSchema.DataType == typeof(bool) || dataSourceFieldSchema.DataType == typeof(bool?))
                            {
                                jQGridColumn = new JQGridColumn();
                            }
                            else
                            {
                                jQGridColumn = new JQGridColumn();
                            }
                            string name = dataSourceFieldSchema.Name;
                            jQGridColumn.DataField  = name;
                            jQGridColumn.PrimaryKey = dataSourceFieldSchema.PrimaryKey;
                            columns.Add(jQGridColumn);
                        }
                    }
                }
            }
        }
Example #9
0
 private void AddKeysAndBoundFields(IDataSourceViewSchema schema)
 {
     JQGridColumnCollection columns = ((JQGrid)base.Component).Columns;
     try
     {
         columns.Clear();
     }
     catch (Exception)
     {
     }
     if (schema != null)
     {
         IDataSourceFieldSchema[] fields = schema.GetFields();
         if (fields != null && fields.Length > 0)
         {
             new ArrayList();
             IDataSourceFieldSchema[] array = fields;
             for (int i = 0; i < array.Length; i++)
             {
                 IDataSourceFieldSchema dataSourceFieldSchema = array[i];
                 if (((JQGrid)base.Component).IsBindableType(dataSourceFieldSchema.DataType))
                 {
                     JQGridColumn jQGridColumn;
                     if (dataSourceFieldSchema.DataType == typeof(bool) || dataSourceFieldSchema.DataType == typeof(bool?))
                     {
                         jQGridColumn = new JQGridColumn();
                     }
                     else
                     {
                         jQGridColumn = new JQGridColumn();
                     }
                     string name = dataSourceFieldSchema.Name;
                     jQGridColumn.DataField = name;
                     jQGridColumn.PrimaryKey = dataSourceFieldSchema.PrimaryKey;
                     columns.Add(jQGridColumn);
                 }
             }
         }
     }
 }
Example #10
0
        public override string GetDesignTimeHtml()
        {
            FormView viewControl = (FormView)base.ViewControl;
            bool     flag        = false;

            string[] dataKeyNames = null;
            if (this.CurrentModeTemplateExists)
            {
                bool flag2 = false;
                IDataSourceViewSchema dataSourceSchema = this.GetDataSourceSchema();
                if (dataSourceSchema != null)
                {
                    IDataSourceFieldSchema[] fields = dataSourceSchema.GetFields();
                    if ((fields != null) && (fields.Length > 0))
                    {
                        flag2 = true;
                    }
                }
                try
                {
                    if (!flag2)
                    {
                        dataKeyNames             = viewControl.DataKeyNames;
                        viewControl.DataKeyNames = new string[0];
                        flag = true;
                    }
                    TypeDescriptor.Refresh(base.Component);
                    return(base.GetDesignTimeHtml());
                }
                finally
                {
                    if (flag)
                    {
                        viewControl.DataKeyNames = dataKeyNames;
                    }
                }
            }
            return(this.GetEmptyDesignTimeHtml());
        }
 private void ExtractFields(IDataSourceViewSchema schema, ArrayList fields)
 {
     if (schema != null)
     {
         IDataSourceFieldSchema[] schemaArray = schema.GetFields();
         if (schemaArray != null)
         {
             for (int i = 0; i < schemaArray.Length; i++)
             {
                 fields.Add(new FieldItem(schemaArray[i].Name, schemaArray[i].DataType));
             }
         }
     }
 }
 public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     object[] objArray1 = null;
     if (context != null)
     {
         IComponent component1 = context.Instance as IComponent;
         if (component1 != null)
         {
             ISite site1 = component1.Site;
             if (site1 != null)
             {
                 IDesignerHost host1 = (IDesignerHost)site1.GetService(typeof(IDesignerHost));
                 if (host1 != null)
                 {
                     IDesigner designer1          = host1.GetDesigner(component1);
                     DesignerDataSourceView view1 = this.GetView(designer1);
                     if (view1 != null)
                     {
                         IDataSourceViewSchema schema1 = null;
                         try
                         {
                             schema1 = view1.Schema;
                         }
                         catch (Exception exception1)
                         {
                             IComponentDesignerDebugService service1 = (IComponentDesignerDebugService)site1.GetService(typeof(IComponentDesignerDebugService));
                             if (service1 != null)
                             {
                                 service1.Fail("DataSource DebugService FailedCall\r\n" + exception1.ToString());
                             }
                         }
                         if (schema1 != null)
                         {
                             IDataSourceFieldSchema[] schemaArray1 = schema1.GetFields();
                             if (schemaArray1 != null)
                             {
                                 objArray1 = new object[schemaArray1.Length];
                                 for (int num1 = 0; num1 < schemaArray1.Length; num1++)
                                 {
                                     objArray1[num1] = schemaArray1[num1].Name;
                                 }
                             }
                         }
                     }
                     if (((objArray1 == null) && (designer1 != null)) && (designer1 is IDataSourceProvider))
                     {
                         IDataSourceProvider provider1   = designer1 as IDataSourceProvider;
                         IEnumerable         enumerable1 = null;
                         if (provider1 != null)
                         {
                             enumerable1 = provider1.GetResolvedSelectedDataSource();
                         }
                         if (enumerable1 != null)
                         {
                             PropertyDescriptorCollection collection1 = DesignTimeData.GetDataFields(enumerable1);
                             if (collection1 != null)
                             {
                                 ArrayList list1 = new ArrayList();
                                 foreach (PropertyDescriptor descriptor1 in collection1)
                                 {
                                     list1.Add(descriptor1.Name);
                                 }
                                 objArray1 = list1.ToArray();
                             }
                         }
                     }
                 }
             }
         }
     }
     return(new TypeConverter.StandardValuesCollection(objArray1));
 }
Example #13
0
 public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     object[] values = null;
     if (context != null)
     {
         IComponent instance = context.Instance as IComponent;
         if (instance != null)
         {
             ISite site = instance.Site;
             if (site != null)
             {
                 IDesignerHost host = (IDesignerHost)site.GetService(typeof(IDesignerHost));
                 if (host != null)
                 {
                     IDesigner dataBoundControlDesigner = host.GetDesigner(instance);
                     DesignerDataSourceView view        = this.GetView(dataBoundControlDesigner);
                     if (view != null)
                     {
                         IDataSourceViewSchema schema = null;
                         try
                         {
                             schema = view.Schema;
                         }
                         catch (Exception exception)
                         {
                             IComponentDesignerDebugService service = (IComponentDesignerDebugService)site.GetService(typeof(IComponentDesignerDebugService));
                             if (service != null)
                             {
                                 service.Fail(System.Design.SR.GetString("DataSource_DebugService_FailedCall", new object[] { "DesignerDataSourceView.Schema", exception.Message }));
                             }
                         }
                         if (schema != null)
                         {
                             IDataSourceFieldSchema[] fields = schema.GetFields();
                             if (fields != null)
                             {
                                 values = new object[fields.Length];
                                 for (int i = 0; i < fields.Length; i++)
                                 {
                                     values[i] = fields[i].Name;
                                 }
                             }
                         }
                     }
                     if (((values == null) && (dataBoundControlDesigner != null)) && (dataBoundControlDesigner is IDataSourceProvider))
                     {
                         IDataSourceProvider provider   = dataBoundControlDesigner as IDataSourceProvider;
                         IEnumerable         dataSource = null;
                         if (provider != null)
                         {
                             dataSource = provider.GetResolvedSelectedDataSource();
                         }
                         if (dataSource != null)
                         {
                             PropertyDescriptorCollection dataFields = DesignTimeData.GetDataFields(dataSource);
                             if (dataFields != null)
                             {
                                 ArrayList list = new ArrayList();
                                 foreach (PropertyDescriptor descriptor in dataFields)
                                 {
                                     list.Add(descriptor.Name);
                                 }
                                 values = list.ToArray();
                             }
                         }
                     }
                 }
             }
         }
     }
     return(new TypeConverter.StandardValuesCollection(values));
 }
 public static bool ViewSchemasEquivalent(IDataSourceViewSchema viewSchema1, IDataSourceViewSchema viewSchema2)
 {
     if ((viewSchema1 == null) ^ (viewSchema2 == null))
     {
         return false;
     }
     if ((viewSchema1 != null) || (viewSchema2 != null))
     {
         IDataSourceFieldSchema[] fields = viewSchema1.GetFields();
         IDataSourceFieldSchema[] schemaArray2 = viewSchema2.GetFields();
         if ((fields == null) ^ (schemaArray2 == null))
         {
             return false;
         }
         if ((fields == null) && (schemaArray2 == null))
         {
             return true;
         }
         int length = fields.Length;
         int num2 = schemaArray2.Length;
         if (length != num2)
         {
             return false;
         }
         foreach (IDataSourceFieldSchema schema in fields)
         {
             bool flag = false;
             string name = schema.Name;
             Type dataType = schema.DataType;
             foreach (IDataSourceFieldSchema schema2 in schemaArray2)
             {
                 if ((name == schema2.Name) && (dataType == schema2.DataType))
                 {
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 return false;
             }
         }
     }
     return true;
 }
            public StringCollection GetStandardValues(Component component)
            {
                StringCollection fields = new StringCollection();

                if (component != null)
                {
                    ISite site1 = component.Site;
                    if (site1 != null)
                    {
                        IDesignerHost host1 = (IDesignerHost)site1.GetService(typeof(IDesignerHost));
                        if (host1 != null)
                        {
                            IDesigner designer1          = host1.GetDesigner(component);
                            DesignerDataSourceView view1 = ((DataBoundControlDesigner)designer1).DesignerView;
                            if (view1 != null)
                            {
                                IDataSourceViewSchema schema1 = null;
                                try
                                {
                                    schema1 = view1.Schema;
                                }
                                catch (Exception exception1)
                                {
                                    IComponentDesignerDebugService service1 = (IComponentDesignerDebugService)site1.GetService(typeof(IComponentDesignerDebugService));
                                    if (service1 != null)
                                    {
                                        service1.Fail("DataSource DebugService FailedCall\r\n" + exception1.ToString());
                                    }
                                }
                                if (schema1 != null)
                                {
                                    IDataSourceFieldSchema[] schemaArray1 = schema1.GetFields();
                                    if (schemaArray1 != null)
                                    {
                                        for (int num1 = 0; num1 < schemaArray1.Length; num1++)
                                        {
                                            fields.Add(schemaArray1[num1].Name);
                                        }
                                    }
                                }
                            }
                            if (((fields.Count == 0) && (designer1 != null)) && (designer1 is IDataSourceProvider))
                            {
                                IDataSourceProvider provider1   = designer1 as IDataSourceProvider;
                                IEnumerable         enumerable1 = null;
                                if (provider1 != null)
                                {
                                    enumerable1 = provider1.GetResolvedSelectedDataSource();
                                }
                                if (enumerable1 != null)
                                {
                                    PropertyDescriptorCollection collection1 = DesignTimeData.GetDataFields(enumerable1);
                                    if (collection1 != null)
                                    {
                                        foreach (PropertyDescriptor descriptor1 in collection1)
                                        {
                                            fields.Add(descriptor1.Name);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(fields);
            }
 private void AddTemplatesAndKeys(IDataSourceViewSchema schema)
 {
     StringBuilder builder = new StringBuilder();
     StringBuilder builder2 = new StringBuilder();
     StringBuilder builder3 = new StringBuilder();
     IDesignerHost service = (IDesignerHost) base.Component.Site.GetService(typeof(IDesignerHost));
     if (schema != null)
     {
         IDataSourceFieldSchema[] fields = schema.GetFields();
         if ((fields != null) && (fields.Length > 0))
         {
             ArrayList list = new ArrayList();
             foreach (IDataSourceFieldSchema schema2 in fields)
             {
                 string name = schema2.Name;
                 char[] chArray = new char[name.Length];
                 for (int i = 0; i < name.Length; i++)
                 {
                     char c = name[i];
                     if (char.IsLetterOrDigit(c) || (c == '_'))
                     {
                         chArray[i] = c;
                     }
                     else
                     {
                         chArray[i] = '_';
                     }
                 }
                 string str2 = new string(chArray);
                 string str3 = DesignTimeDataBinding.CreateEvalExpression(name, string.Empty);
                 string str4 = DesignTimeDataBinding.CreateBindExpression(name, string.Empty);
                 if (schema2.PrimaryKey || schema2.Identity)
                 {
                     if (this.EnableDynamicData)
                     {
                         builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{2}DynamicControl\" Mode=\"{1}\" /><br />", new object[] { name, "ReadOnly", str2 }));
                         builder2.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{2}DynamicControl\" Mode=\"{1}\" /><br />", new object[] { name, "ReadOnly", str2 }));
                     }
                     else
                     {
                         builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:Label Text='<%# {1} %>' runat=\"server\" id=\"{2}Label1\" /><br />", new object[] { name, str3, str2 }));
                         builder2.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:Label Text='<%# {1} %>' runat=\"server\" id=\"{2}Label\" /><br />", new object[] { name, str3, str2 }));
                     }
                     if (!schema2.Identity)
                     {
                         if (this.EnableDynamicData)
                         {
                             builder3.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{1}DynamicControl\" Mode=\"Insert\" ValidationGroup=\"Insert\" /><br />", new object[] { name, str2 }));
                         }
                         else
                         {
                             builder3.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:TextBox Text='<%# {1} %>' runat=\"server\" id=\"{2}TextBox\" /><br />", new object[] { name, str4, str2 }));
                         }
                     }
                 }
                 else if (this.EnableDynamicData)
                 {
                     builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{2}DynamicControl\" Mode=\"{1}\" /><br />", new object[] { name, "Edit", str2 }));
                     builder2.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{2}DynamicControl\" Mode=\"{1}\" /><br />", new object[] { name, "ReadOnly", str2 }));
                     builder3.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{1}DynamicControl\" Mode=\"Insert\" ValidationGroup=\"Insert\" /><br />", new object[] { name, str2 }));
                 }
                 else if ((schema2.DataType == typeof(bool)) || (schema2.DataType == typeof(bool?)))
                 {
                     builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:CheckBox Checked='<%# {1} %>' runat=\"server\" id=\"{2}CheckBox\" /><br />", new object[] { name, str4, str2 }));
                     builder2.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:CheckBox Checked='<%# {1} %>' runat=\"server\" id=\"{2}CheckBox\" Enabled=\"false\" /><br />", new object[] { name, str4, str2 }));
                     builder3.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:CheckBox Checked='<%# {1} %>' runat=\"server\" id=\"{2}CheckBox\" /><br />", new object[] { name, str4, str2 }));
                 }
                 else
                 {
                     builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:TextBox Text='<%# {1} %>' runat=\"server\" id=\"{2}TextBox\" /><br />", new object[] { name, str4, str2 }));
                     builder2.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:Label Text='<%# {1} %>' runat=\"server\" id=\"{2}Label\" /><br />", new object[] { name, str4, str2 }));
                     builder3.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:TextBox Text='<%# {1} %>' runat=\"server\" id=\"{2}TextBox\" /><br />", new object[] { name, str4, str2 }));
                 }
                 builder.Append(Environment.NewLine);
                 builder2.Append(Environment.NewLine);
                 builder3.Append(Environment.NewLine);
                 if (schema2.PrimaryKey)
                 {
                     list.Add(name);
                 }
             }
             bool flag = true;
             if (base.DesignerView.CanUpdate)
             {
                 builder2.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Edit", string.Empty, bool.FalseString, System.Design.SR.GetString("FormView_Edit") }));
                 flag = false;
             }
             if (this.EnableDynamicData)
             {
                 builder.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" ValidationGroup=\"Insert\" />", new object[] { "Update", string.Empty, bool.TrueString, System.Design.SR.GetString("FormView_Update") }));
             }
             else
             {
                 builder.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Update", string.Empty, bool.TrueString, System.Design.SR.GetString("FormView_Update") }));
             }
             builder.Append("&nbsp;");
             builder.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Cancel", "Update", bool.FalseString, System.Design.SR.GetString("FormView_Cancel") }));
             if (base.DesignerView.CanDelete)
             {
                 if (!flag)
                 {
                     builder2.Append("&nbsp;");
                 }
                 builder2.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Delete", string.Empty, bool.FalseString, System.Design.SR.GetString("FormView_Delete") }));
                 flag = false;
             }
             if (base.DesignerView.CanInsert)
             {
                 if (!flag)
                 {
                     builder2.Append("&nbsp;");
                 }
                 builder2.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "New", string.Empty, bool.FalseString, System.Design.SR.GetString("FormView_New") }));
             }
             if (this.EnableDynamicData)
             {
                 builder3.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" ValidationGroup=\"Insert\" />", new object[] { "Insert", string.Empty, bool.TrueString, System.Design.SR.GetString("FormView_Insert") }));
             }
             else
             {
                 builder3.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Insert", string.Empty, bool.TrueString, System.Design.SR.GetString("FormView_Insert") }));
             }
             builder3.Append("&nbsp;");
             builder3.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Cancel", "Insert", bool.FalseString, System.Design.SR.GetString("FormView_Cancel") }));
             builder.Append(Environment.NewLine);
             builder2.Append(Environment.NewLine);
             builder3.Append(Environment.NewLine);
             try
             {
                 ((FormView) base.Component).EditItemTemplate = ControlParser.ParseTemplate(service, builder.ToString());
                 ((FormView) base.Component).ItemTemplate = ControlParser.ParseTemplate(service, builder2.ToString());
                 ((FormView) base.Component).InsertItemTemplate = ControlParser.ParseTemplate(service, builder3.ToString());
             }
             catch
             {
             }
             int count = list.Count;
             if (count > 0)
             {
                 string[] array = new string[count];
                 list.CopyTo(array, 0);
                 ((FormView) base.Component).DataKeyNames = array;
             }
         }
     }
 }
Example #17
0
        private void AddTemplatesAndKeys(IDataSourceViewSchema schema)
        {
            StringBuilder builder  = new StringBuilder();
            StringBuilder builder2 = new StringBuilder();
            StringBuilder builder3 = new StringBuilder();
            IDesignerHost service  = (IDesignerHost)base.Component.Site.GetService(typeof(IDesignerHost));

            if (schema != null)
            {
                IDataSourceFieldSchema[] fields = schema.GetFields();
                if ((fields != null) && (fields.Length > 0))
                {
                    ArrayList list = new ArrayList();
                    foreach (IDataSourceFieldSchema schema2 in fields)
                    {
                        string name    = schema2.Name;
                        char[] chArray = new char[name.Length];
                        for (int i = 0; i < name.Length; i++)
                        {
                            char c = name[i];
                            if (char.IsLetterOrDigit(c) || (c == '_'))
                            {
                                chArray[i] = c;
                            }
                            else
                            {
                                chArray[i] = '_';
                            }
                        }
                        string str2 = new string(chArray);
                        string str3 = DesignTimeDataBinding.CreateEvalExpression(name, string.Empty);
                        string str4 = DesignTimeDataBinding.CreateBindExpression(name, string.Empty);
                        if (schema2.PrimaryKey || schema2.Identity)
                        {
                            if (this.EnableDynamicData)
                            {
                                builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{2}DynamicControl\" Mode=\"{1}\" /><br />", new object[] { name, "ReadOnly", str2 }));
                                builder2.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{2}DynamicControl\" Mode=\"{1}\" /><br />", new object[] { name, "ReadOnly", str2 }));
                            }
                            else
                            {
                                builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:Label Text='<%# {1} %>' runat=\"server\" id=\"{2}Label1\" /><br />", new object[] { name, str3, str2 }));
                                builder2.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:Label Text='<%# {1} %>' runat=\"server\" id=\"{2}Label\" /><br />", new object[] { name, str3, str2 }));
                            }
                            if (!schema2.Identity)
                            {
                                if (this.EnableDynamicData)
                                {
                                    builder3.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{1}DynamicControl\" Mode=\"Insert\" ValidationGroup=\"Insert\" /><br />", new object[] { name, str2 }));
                                }
                                else
                                {
                                    builder3.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:TextBox Text='<%# {1} %>' runat=\"server\" id=\"{2}TextBox\" /><br />", new object[] { name, str4, str2 }));
                                }
                            }
                        }
                        else if (this.EnableDynamicData)
                        {
                            builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{2}DynamicControl\" Mode=\"{1}\" /><br />", new object[] { name, "Edit", str2 }));
                            builder2.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{2}DynamicControl\" Mode=\"{1}\" /><br />", new object[] { name, "ReadOnly", str2 }));
                            builder3.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:DynamicControl DataField=\"{0}\" runat=\"server\" id=\"{1}DynamicControl\" Mode=\"Insert\" ValidationGroup=\"Insert\" /><br />", new object[] { name, str2 }));
                        }
                        else if ((schema2.DataType == typeof(bool)) || (schema2.DataType == typeof(bool?)))
                        {
                            builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:CheckBox Checked='<%# {1} %>' runat=\"server\" id=\"{2}CheckBox\" /><br />", new object[] { name, str4, str2 }));
                            builder2.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:CheckBox Checked='<%# {1} %>' runat=\"server\" id=\"{2}CheckBox\" Enabled=\"false\" /><br />", new object[] { name, str4, str2 }));
                            builder3.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:CheckBox Checked='<%# {1} %>' runat=\"server\" id=\"{2}CheckBox\" /><br />", new object[] { name, str4, str2 }));
                        }
                        else
                        {
                            builder.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:TextBox Text='<%# {1} %>' runat=\"server\" id=\"{2}TextBox\" /><br />", new object[] { name, str4, str2 }));
                            builder2.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:Label Text='<%# {1} %>' runat=\"server\" id=\"{2}Label\" /><br />", new object[] { name, str4, str2 }));
                            builder3.Append(string.Format(CultureInfo.InvariantCulture, "{0}: <asp:TextBox Text='<%# {1} %>' runat=\"server\" id=\"{2}TextBox\" /><br />", new object[] { name, str4, str2 }));
                        }
                        builder.Append(Environment.NewLine);
                        builder2.Append(Environment.NewLine);
                        builder3.Append(Environment.NewLine);
                        if (schema2.PrimaryKey)
                        {
                            list.Add(name);
                        }
                    }
                    bool flag = true;
                    if (base.DesignerView.CanUpdate)
                    {
                        builder2.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Edit", string.Empty, bool.FalseString, System.Design.SR.GetString("FormView_Edit") }));
                        flag = false;
                    }
                    if (this.EnableDynamicData)
                    {
                        builder.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" ValidationGroup=\"Insert\" />", new object[] { "Update", string.Empty, bool.TrueString, System.Design.SR.GetString("FormView_Update") }));
                    }
                    else
                    {
                        builder.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Update", string.Empty, bool.TrueString, System.Design.SR.GetString("FormView_Update") }));
                    }
                    builder.Append("&nbsp;");
                    builder.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Cancel", "Update", bool.FalseString, System.Design.SR.GetString("FormView_Cancel") }));
                    if (base.DesignerView.CanDelete)
                    {
                        if (!flag)
                        {
                            builder2.Append("&nbsp;");
                        }
                        builder2.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Delete", string.Empty, bool.FalseString, System.Design.SR.GetString("FormView_Delete") }));
                        flag = false;
                    }
                    if (base.DesignerView.CanInsert)
                    {
                        if (!flag)
                        {
                            builder2.Append("&nbsp;");
                        }
                        builder2.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "New", string.Empty, bool.FalseString, System.Design.SR.GetString("FormView_New") }));
                    }
                    if (this.EnableDynamicData)
                    {
                        builder3.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" ValidationGroup=\"Insert\" />", new object[] { "Insert", string.Empty, bool.TrueString, System.Design.SR.GetString("FormView_Insert") }));
                    }
                    else
                    {
                        builder3.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Insert", string.Empty, bool.TrueString, System.Design.SR.GetString("FormView_Insert") }));
                    }
                    builder3.Append("&nbsp;");
                    builder3.Append(string.Format(CultureInfo.InvariantCulture, "<asp:LinkButton runat=\"server\" Text=\"{3}\" CommandName=\"{0}\" id=\"{1}{0}Button\" CausesValidation=\"{2}\" />", new object[] { "Cancel", "Insert", bool.FalseString, System.Design.SR.GetString("FormView_Cancel") }));
                    builder.Append(Environment.NewLine);
                    builder2.Append(Environment.NewLine);
                    builder3.Append(Environment.NewLine);
                    try
                    {
                        ((FormView)base.Component).EditItemTemplate   = ControlParser.ParseTemplate(service, builder.ToString());
                        ((FormView)base.Component).ItemTemplate       = ControlParser.ParseTemplate(service, builder2.ToString());
                        ((FormView)base.Component).InsertItemTemplate = ControlParser.ParseTemplate(service, builder3.ToString());
                    }
                    catch
                    {
                    }
                    int count = list.Count;
                    if (count > 0)
                    {
                        string[] array = new string[count];
                        list.CopyTo(array, 0);
                        ((FormView)base.Component).DataKeyNames = array;
                    }
                }
            }
        }
 private string[] GetControlDataFieldNames()
 {
     if (this._dataFields == null)
     {
         ITypeDescriptorContext   context = this.editor.Context;
         IDataSourceFieldSchema[] fields  = null;
         IDataSourceViewSchema    dataSourceViewSchema = null;
         if ((context != null) && (context.Instance != null))
         {
             System.Web.UI.Control instance = context.Instance as System.Web.UI.Control;
             if (instance != null)
             {
                 ISite site = instance.Site;
                 if (site != null)
                 {
                     IDesignerHost host = (IDesignerHost)site.GetService(typeof(IDesignerHost));
                     if (host != null)
                     {
                         DataBoundControlDesigner designer = host.GetDesigner(instance) as DataBoundControlDesigner;
                         if (designer != null)
                         {
                             DesignerDataSourceView designerView = designer.DesignerView;
                             if (designerView != null)
                             {
                                 try
                                 {
                                     dataSourceViewSchema = designerView.Schema;
                                 }
                                 catch (Exception exception)
                                 {
                                     IComponentDesignerDebugService service = (IComponentDesignerDebugService)site.GetService(typeof(IComponentDesignerDebugService));
                                     if (service != null)
                                     {
                                         service.Fail(System.Design.SR.GetString("DataSource_DebugService_FailedCall", new object[] { "DesignerDataSourceView.Schema", exception.Message }));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             else
             {
                 IDataSourceViewSchemaAccessor accessor = context.Instance as IDataSourceViewSchemaAccessor;
                 if (accessor != null)
                 {
                     dataSourceViewSchema = accessor.DataSourceViewSchema as IDataSourceViewSchema;
                 }
             }
         }
         if (dataSourceViewSchema != null)
         {
             fields = dataSourceViewSchema.GetFields();
             if (fields != null)
             {
                 int length = fields.Length;
                 this._dataFields = new string[length];
                 for (int i = 0; i < length; i++)
                 {
                     this._dataFields[i] = fields[i].Name;
                 }
             }
         }
     }
     return(this._dataFields);
 }