Exemplo n.º 1
0
        protected virtual JObject ToResult(FlowDataTable table, bool formTable)
        {
            JObject jTable = new JObject();

            jTable["DataSource"] = TableIdentityHelper.IsDefaultDataSource(table.DataSourceName) ? "" : table.DataSourceName;
            jTable["TableName"]  = table.TableName;
            jTable["FormTable"]  = formTable;

            if (formTable)
            {
                jTable["IsRepeatable"]   = table.IsRepeatableTable;
                jTable["AllowAddRecord"] = table.AllowAddRecord;

                if (!table.IsRepeatableTable)
                {
                    jTable["CKeyName"]  = table.CKeyName;
                    jTable["CKeyValue"] = table.CKeyValue;
                }
            }

            JArray jColumns = new JArray();

            jTable["Columns"] = jColumns;
            foreach (FlowDataColumn column in table.Columns)
            {
                JObject jColumn = new JObject();
                jColumns.Add(jColumn);

                jColumn["ColumnName"] = column.ColumnName;
                jColumn["Type"]       = (column.DataType == null ? typeof(String):column.DataType).Name;
                if (formTable)
                {
                    jColumn["Length"]        = column.MaxLength;
                    jColumn["Readable"]      = column.AllowRead;
                    jColumn["Writeable"]     = column.AllowWrite;
                    jColumn["AutoIncrement"] = column.AutoIncrement;
                    jColumn["PrimaryKey"]    = column.PrimaryKey;
                    jColumn["DefaultValue"]  = new JValue(this.FormatValue(column.DefaultValue));
                    jColumn["ShowSpoor"]     = column.ShowSpoor;
                }
            }

            JArray jRows = new JArray();

            jTable["Rows"] = jRows;
            foreach (FlowDataRow row in table.Rows)
            {
                JObject jRow = new JObject();
                jRows.Add(jRow);

                foreach (string colName in row.Keys)
                {
                    jRow[colName] = new JValue(this.FormatValue(row[colName]));
                }
            }

            return(jTable);
        }
Exemplo n.º 2
0
        public virtual JObject GetTreeOfTables(HttpContext context)
        {
            YZRequest request    = new YZRequest(context);
            string    serverName = request.GetString("ServerName", null);
            bool      expand     = request.GetBool("expand", true);

            TableIdentityCollection tables = new TableIdentityCollection();
            string strTables = request.GetString("tables", "[]");
            JArray jtables   = JArray.Parse(strTables);

            foreach (JArray jtable in jtables)
            {
                tables.Add(new TableIdentity((string)jtable[0], (string)jtable[1]));
            }

            FlowDataSet dataSet;

            using (BPMConnection cn = new BPMConnection())
            {
                this.OpenConnection(cn, serverName);
                dataSet = DataSourceManager.LoadDataSetSchema(cn, tables);
            }

            JObject rv = new JObject();

            JArray jTables = new JArray();

            rv[YZJsonProperty.children] = jTables;

            foreach (FlowDataTable table in dataSet.Tables)
            {
                JObject jTable = new JObject();
                jTables.Add(jTable);

                jTable["leaf"]     = false;
                jTable["id"]       = table.DataSourceName + ":" + table.TableName;
                jTable["text"]     = TableIdentityHelper.GetTableIdentityName(table.DataSourceName, table.TableName);
                jTable["iconCls"]  = "dbtable";
                jTable["expanded"] = expand;

                JArray children = new JArray();
                jTable[YZJsonProperty.children] = children;

                foreach (FlowDataColumn column in table.Columns)
                {
                    JObject jColumn = new JObject();
                    children.Add(jColumn);

                    jColumn["leaf"]    = true;
                    jColumn["id"]      = table.DataSourceName + ":" + table.TableName + "." + column.ColumnName;
                    jColumn["text"]    = column.ColumnName;
                    jColumn["iconCls"] = "dbcolumn";

                    jColumn["data"] = JObject.FromObject(new {
                        DataSourceName = table.DataSourceName,
                        TableName      = table.TableName,
                        ColumnName     = column.ColumnName,
                        FullName       = table.TableName + "." + column.ColumnName,
                        Type           = column.DataType.Name
                    });
                }
            }

            rv[YZJsonProperty.success] = true;
            return(rv);
        }