Пример #1
0
        public List <DataSummary> GetDbSummarise()
        {
            List <DataSummary> summarise = new List <DataSummary>();

            DbConnection conn = db.GetConnection();

            DataTable dt = conn.GetSchema("Tables");
            DataView  dv = dt.DefaultView;

            dv.Sort = "TABLE_NAME";

            conn.Close();
            SchemaContainer <XTableSchema> xtc = XTableSchemaContainer.Instance();

            foreach (DataRowView dr in dv)
            {
                DataSummary tbSummary = new DataSummary();
                tbSummary.Name        = dr["TABLE_NAME"].ToString();
                tbSummary.Description = dr["TABLE_NAME"].ToString();
                tbSummary.Caption     = dr["TABLE_NAME"].ToString();
                tbSummary.Type        = dr["TABLE_TYPE"].ToString();

                XTableSchema ts = xtc.GetItem(tbSummary.Name);
                if (xtc.Contains(tbSummary.Name))
                {
                    tbSummary.Caption     = ts.Title;
                    tbSummary.Description = ts.Description;
                }
                summarise.Add(tbSummary);
            }
            return(summarise);
        }
Пример #2
0
        public static void BuildSchemaCommand(XTableSchema schema)
        {
            XSqlBuilder cmdBuild = new XSqlBuilder(schema);

            try
            {
                //                schema.UpdateCommand = cmdBuild.GetUpdateCommand(true).CommandText;
                schema.UpdateCommand = cmdBuild.GetUpdateCommand();
            }
            catch
            {
                schema.UpdateCommand = "";
            }

            try
            {
                //schema.InsertCommand = cmdBuild.GetInsertCommand(true).CommandText;
                schema.InsertCommand = cmdBuild.GetInsertCommand();
            }
            catch (Exception)
            {
                schema.InsertCommand = "";
            }

            try
            {
                //schema.DeleteCommand = cmdBuild.GetDeleteCommand(true).CommandText;
                schema.DeleteCommand = cmdBuild.GetDeleteCommand();
            }
            catch (Exception)
            {
                schema.DeleteCommand = "";
            }
        }
Пример #3
0
        public static XTableSchema BuildSrcTableSchema(string fullTableName)
        {
            string[]     paths    = fullTableName.Split(ContainerConst.NamePathChar);
            string       connName = paths[0];
            string       tbName   = paths[1];
            string       sql      = "Select * From [" + tbName + "]";
            XTableSchema ret      = CreateTableSchema(tbName, connName, sql);

            XTableSchemaContainer.Instance().AddItem(fullTableName, ret);
            return(ret);
        }
Пример #4
0
        private static XTableSchema CreateTableSchema(string tableId, string connectionName, string selectSql)
        {
            XTableSchema schema = new XTableSchema();

            schema.Id             = tableId;
            schema.SelectCommand  = selectSql;
            schema.ConnectionName = connectionName;

            BuildFields(schema);

            BuildSchemaCommand(schema);

            return(schema);
        }
Пример #5
0
        public List <ObjectDocket> GetTableSummarise(string folder)
        {
            List <ObjectDocket> ret = new List <ObjectDocket>();

            string[] tables = XTableSchemaContainer.Instance().GetIDByFolder(folder);

            for (int i = 0; i < tables.Length; i++)
            {
                ObjectDocket tabSum = new ObjectDocket();
                tabSum.Name = tables[i];
                XTableSchema tabsch = XTableSchemaContainer.Instance().GetItem(tables[i]);
                tabSum.Title = tabsch.Title;
                ret.Add(tabSum);
            }
            return(ret);
        }
Пример #6
0
        public XTableSchema RefreshTableSchemaFields(string tableId)
        {
            XTableSchema tableSchema = null;

            if (XTableSchemaContainer.Instance().Contains(tableId))
            {
                tableSchema = XTableSchemaContainer.Instance().GetItem(tableId);
            }
            else
            {
                throw new XException("不能发现表(" + tableId + ")");
            }

            TableSchemaTools.RefreshSchemaFields(tableId, tableSchema);

            return(tableSchema);
        }
Пример #7
0
        public XTableSchema GetTableSchema(string tableFullName)
        {
            XTableSchema tableSchema = null;

            if (XTableSchemaContainer.Instance().Contains(tableFullName))
            {
                tableSchema = XTableSchemaContainer.Instance().GetItem(tableFullName);
            }
            else if (TableSchemaTools.isSrcTable(tableFullName))
            {
                tableSchema = TableSchemaTools.BuildSrcTableSchema(tableFullName);
            }
            else
            {
                throw new XException("不能发现表(" + tableFullName + ")");
            }

            return(tableSchema);
        }
Пример #8
0
        private void InitualElement(WbapResponse resp, FieldBindSchema fieldBindSchema)
        {
            string tableName = fieldBindSchema.TableId;

            if (tableName == null)
            {
                throw (new E_WbdlPageFieldBindSchemaNotAssignedFieldId(fieldBindSchema.Id));
            }

            XTableSchema tableSchema = this.pageCtr.GetTableSchema(tableName);

//            XTableAdapter tableAdapter = new XTableAdapter(tableSchema);

            if (tableSchema == null)
            {
                return;
            }

            FieldSchema fieldSchame = tableSchema.Fields.FindItem(fieldBindSchema.FieldId);

            if (fieldSchame == null)
            {
                return;
                //throw (new E_CannotGetFieldSchame(fieldBindSchema.TableId + "." + fieldBindSchema.FieldId));
            }
            //fieldSchame.DisplayName = fieldBindSchema.DisplayName;
            //捆绑初始值
            //if (fieldSchame.DefaultValue != null && fieldSchame.DefaultValue != "")
            //{
            //    if (!resp.ElementBinds.ContainsKey(fieldBindSchema.Id))
            //        resp.ElementBinds.Add(fieldBindSchema.Id, fieldSchame.DefaultValue);
            //}

            //捆绑下拉列表
            string codeTableName = fieldSchame.CodeTableName;

            if (codeTableName != null && codeTableName != "")
            {
                //     XData xData = new XData();
                //try
                //{
                //    CodeTable codeTable = xData.GetCodeTable(codeTableName);
                //    Dictionary<string, string> option = new Dictionary<string, string>();

                //    foreach (CodeTableData codeTableData in codeTable.Datas)
                //    {
                //        option.Add(codeTableData.Id, codeTableData.Text);
                //    }
                //    resp.ElementBinds.AddOption(fieldBindSchema.Id, option);
                //}
                //catch (Exception e)
                //{
                //    throw (new Exception("Bind Element CodeTable Error Element Id is'" + fieldBindSchema.Id + "'  CodeTable is '" + codeTableName + "'," + e.Message));
                //}
            }


            //捆绑Lookup

            LookupFieldSchema lookupField = tableSchema.LookupFields.FindItem(fieldBindSchema.FieldId);

            if (lookupField != null)
            {
                //WbapEvent wbapEvent = new WbapEvent();
                //wbapEvent.EventName = "onpropertychange";
                //string  actionId= "GetLookup("
                //                  + fieldBindSchema.TableId
                //                  + "," + fieldBindSchema.FieldId
                //                  + ","+field;
                //wbapEvent.Action.Request.ActionId =actionId;
                //wbapEvent.Action.Request.PageName = schema.Id;
                //wbapEvent.Action.Request.ElementBinds.Add("fieldName", fieldBindSchema.TableId);
                //wbapEvent.Action.Request.ElementBinds.Add("fieldName", fieldBindSchema.FieldId);
                //wbapEvent.Action.Request.ElementBinds.Add("fieldValue", "@" + fieldBindSchema.Id);
                //wbapEvent.Action.Request.ElementBinds.Add("ReturnValue", "@" + fieldBindSchema.Id + "_Lookup");

                //fieldBindSchema.

                //resp.ElementBinds.AddEvent(fieldBindSchema.Id, wbapEvent);
            }
        }
Пример #9
0
 /// <summary>
 /// //用物理数据库中的字段及表信息,重新更新XTableSchema信息
 /// </summary>
 /// <param name="tableId"></param>
 /// <param name="schema"></param>
 public static void RefreshSchemaFields(string tableId, XTableSchema schema)
 {
     BuildFields(schema);
     XTableSchemaContainer.Instance().UpdateItem(tableId, schema);
 }
Пример #10
0
        private static void BuildFields1(XTableSchema schema)
        {
            string connectionName = schema.ConnectionName;
            string selectSql      = schema.SelectCommand;

            //  XDataBase xdb = XDatabaseFactory.Instance.GetDataBase(connectionName);
            DatabaseAdmin

            XSql xSql = new XSql(selectSql);

            string tableName = xSql.GetFrom();
            //  schema.Fields.Clear();

            SchemaList <FieldSchema> tmpfs = new SchemaList <FieldSchema>();

            if (xSql.IsFromSourceTable(tableName))
            {
                string keyfield = xdb.GetPrimaryKey(tableName);
                if (!string.IsNullOrEmpty(keyfield))
                {
                    schema.KeyField = keyfield;
                }

                List <FieldDef> fieldDefs = xdb.GetFieldInfos(tableName);

                for (int i = 0; i < fieldDefs.Count; i++)
                {
                    FieldSchema field    = new FieldSchema();
                    FieldDef    fieldDef = fieldDefs[i];
                    field.Id          = fieldDef.Name;
                    field.DisplayName = fieldDef.Alias;//未用
                    if (string.IsNullOrEmpty(field.Title))
                    {
                        field.Title = fieldDef.Alias;
                    }
                    if (schema.Fields.FindItem(field.Id) == null)
                    {
                        schema.Fields.Add(field);
                    }
                    if (tmpfs.FindItem(field.Id) == null)
                    {
                        tmpfs.Add(field);
                    }
                }
            }
            else
            {
                DbConnection con      = xdb.GetConnection();
                DataTable    netTable = new DataTable();

                DbDataAdapter da = xdb.GetAdapter();

                DbCommand cmd = con.CreateCommand();

                xSql.ParamGetter = delegate(string name)
                {
                    if (!name.StartsWith("@"))
                    {
                        name = "@" + name;
                    }

                    if (schema.QueryParams.FindItem(name) != null)
                    {
                        XQueryParameterSchema paramSch = schema.QueryParams.GetItem(name);
                        return(paramSch.DefaultValue);
                    }
                    else
                    {
                        return(null);
                    }
                };



                cmd.CommandText = xSql.RelaceParamValue();

                da.SelectCommand = cmd;

                da.Fill(netTable);


                foreach (DataColumn col in netTable.Columns)
                {
                    FieldSchema field = new FieldSchema();
                    field.Id          = col.ColumnName;
                    field.DisplayName = col.Caption;
                    //                    schema.Fields.Add(field);
                    if (schema.Fields.FindItem(field.Id) == null)
                    {
                        schema.Fields.Add(field);
                    }

                    if (tmpfs.FindItem(field.Id) == null)
                    {
                        tmpfs.Add(field);
                    }
                }
            }

            for (int i = schema.Fields.Count - 1; i >= 0; i--)
            {
                FieldSchema fld    = schema.Fields[i];
                FieldSchema newFld = tmpfs.FindItem(fld.Id);
                if (newFld == null)
                {
                    schema.Fields.Remove(fld);
                }
            }

            xdb.Close();
        }
Пример #11
0
        private static void BuildFields(XTableSchema schema)
        {
            string connectionName = schema.ConnectionName;
            string selectSql      = schema.SelectCommand;

            XDataBase xdb = XDatabaseFactory.Instance.GetDataBase(connectionName);


            XSql xSql = new XSql(selectSql);

            string tableName = xSql.GetFrom();
            //  schema.Fields.Clear();

            SchemaList <FieldSchema> tmpfs = new SchemaList <FieldSchema>();

            DbConnection con      = xdb.GetConnection();
            DataTable    netTable = new DataTable();

            DbDataAdapter da = xdb.GetAdapter();

            DbCommand cmd = con.CreateCommand();

            cmd.CommandText = selectSql;

            string[] paramNames = xSql.GetParamNames();
            for (int i = 0; i < paramNames.Count(); i++)
            {
                string pName = paramNames[i];
                if (!string.IsNullOrEmpty(pName))
                {
                    pName = pName.Trim();
                }
                SqlParameter p = new SqlParameter();
                p.ParameterName = "@" + pName;
                //p.SourceColumn = pName;
                p.Value = "";
                cmd.Parameters.Add(p);
            }
            da.SelectCommand = cmd;

            da.Fill(netTable);
            //da.FillSchema(netTable, SchemaType.Source);

            foreach (DataColumn col in netTable.Columns)
            {
                FieldSchema field = new FieldSchema();
                field.Id          = col.ColumnName;
                field.DisplayName = col.Caption;
                //                    schema.Fields.Add(field);
                if (schema.Fields.FindItem(field.Id) == null)
                {
                    schema.Fields.Add(field);
                }

                if (tmpfs.FindItem(field.Id) == null)
                {
                    tmpfs.Add(field);
                }
            }


            //从原是表中获取,字段标题等信息;

            if (xSql.IsFromSourceTable(tableName))
            {
                string keyfield = xdb.GetPrimaryKey(tableName);
                if (!string.IsNullOrEmpty(keyfield))
                {
                    schema.KeyField = keyfield;
                }

                List <FieldDef> fieldDefs = xdb.GetFieldInfos(tableName);

                for (int i = 0; i < fieldDefs.Count; i++)
                {
                    FieldDef    fieldDef = fieldDefs[i];
                    FieldSchema field    = schema.Fields.FindItem(fieldDef.Name);

                    //                    field.Id =;
                    if (field != null)
                    {
                        field.DisplayName = fieldDef.Alias;//未用
                        if (string.IsNullOrEmpty(field.Title))
                        {
                            field.Title = fieldDef.Alias;
                        }
                        if (fieldDef.IsIdentity)
                        {
                            field.IsAutoInc = true;
                        }
                    }
                    //                    if (field == null)
                    //                        schema.Fields.Add(field);
                    //    if (tmpfs.FindItem(field.Id) == null)
                    //        tmpfs.Add(field);
                }
            }

            //删除不存在的字段
            for (int i = schema.Fields.Count - 1; i >= 0; i--)
            {
                FieldSchema fld    = schema.Fields[i];
                FieldSchema newFld = tmpfs.FindItem(fld.Id);
                if (newFld == null)
                {
                    schema.Fields.Remove(fld);
                }
            }

            xdb.Close();
        }
Пример #12
0
 public void UpdateTableSchema(string tableFullName, XTableSchema schema)
 {
     XTableSchemaContainer.Instance().UpdateItem(tableFullName, schema);
 }
Пример #13
0
 public XTableSchema BuildTableCommand(XTableSchema schema)
 {
     TableSchemaTools.BuildSchemaCommand(schema);
     return(schema);
 }