Example #1
0
        public void refreshFields()
        {
            DatabaseAdmin dba = DatabaseAdmin.getInstance(_schema.ConnectionName);
            DataSet       ds  = getDataSet();

            if (ds == null || ds.Tables.Count < 1)
            {
                return;
            }
            foreach (DataColumn col in ds.Tables[0].Columns)
            {
                FieldSchema fs = _schema.Fields.FindItem(col.ColumnName);
                if (fs == null)
                {
                    fs          = new FieldSchema();
                    fs.Id       = col.ColumnName;
                    fs.DataType = dba.getDbType(col.DataType);
                    _schema.Fields.Add(fs);
                }
            }
            if (DataSourceSchemaContainer.Instance().Contains(_name))
            {
                DataSourceSchemaContainer.Instance().UpdateItem(_name, _schema);
            }
        }
        private void applyTableDef(DataSet dataSet)
        {
            foreach (DataTable table in dataSet.Tables)
            {
                string tableName = table.TableName;

                List <string> pks = dbAdmin.GetPrimaryKeys(tableName);


                var      tbName = tableName.Trim('[', ']');
                TableDef tbDef  = dbAdmin.getTableDef(tbName);
                if (tbDef == null)
                {
                    break;
                }
                List <FieldDef> fieldDefs = tbDef.FieldDefs;

                for (int i = 0; i < fieldDefs.Count; i++)
                {
                    FieldDef fieldDef = fieldDefs[i];
                    string   colName  = fieldDef.Name;
                    if (table.Columns.Contains(colName))
                    {
                        DataColumn col = table.Columns[colName];
                        col.Caption = colName;
                        if (!string.IsNullOrEmpty(fieldDef.Title))
                        {
                            col.Caption = fieldDef.Title;
                        }
                        //if (string.IsNullOrEmpty(fieldDef.DefaultValue))
                        //    col.DefaultValue = fieldDef.DefaultValue;
                        col.AutoIncrement = fieldDef.IsIdentity;
                        //if (!string.IsNullOrEmpty(fieldDef.Description))
                        col.ExtendedProperties[DataSourceConst.ExProDescription] = fieldDef.Description;
                        DbType dbType;
                        try
                        {
                            dbType = dbAdmin.getDbType(fieldDef.Type);
                        }
                        catch
                        {
                            throw new Exception(string.Format(Lang.unknowDbType, tableName, colName));
                        }

                        if (!col.ExtendedProperties.ContainsKey(DataSourceConst.ExProDbType))
                        {
                            col.ExtendedProperties.Add(DataSourceConst.ExProDbType, dbType);
                        }
                        else
                        {
                            col.ExtendedProperties[DataSourceConst.ExProDbType] = dbType;
                        }
                    }
                }

                if (pks != null && pks.Count > 0)
                {
                    DataColumn[] cols = new DataColumn[pks.Count];
                    for (int i = 0; i < pks.Count; i++)
                    {
                        string colName = pks[i];
                        if (table.Columns.Contains(colName))
                        {
                            cols[i] = table.Columns[colName];
                        }
                    }
                    table.PrimaryKey = cols;
                }
            }
        }