Example #1
0
        /// <summary>
        ///根据tableName参数,为客户端请求,建立Table的框架格式。
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="schema"></param>
        internal void ImportTableSchema(string tableName, WbdlSchema schema)
        {
            DataSourceSchema tableSchema = DataSourceSchemaContainer.Instance().GetItem(tableName);
            string           keyField    = tableSchema.PrimaryKeys + "_Key";

            foreach (FieldBindSchema fieldBind in schema.FieldBinds)
            {
                if (fieldBind.TableId.Equals(tableName, StringComparison.OrdinalIgnoreCase))
                {
                    if (!this.ContainsKey(fieldBind.Id))
                    {
                        this.Add(fieldBind.Id, "");
                    }
                    //                    this.
                }
            }

            if (!this.ContainsKey(keyField))
            {
                this.Add(keyField, "");
            }

            foreach (DataListBindSchema listBind in schema.DataListBinds)
            {
                string   listKey  = listBind.Id + WbapDataType._List.ToString();
                WbapList dataList = null;
                if (this.ContainsKey(listKey))
                {
                    dataList = this[listKey] as WbapList;
                }
                else
                {
                    dataList = new WbapList();
                    this.Add(listBind.Id + WbapDataType._List.ToString(), dataList);
                }
                foreach (FieldBindSchema fieldBind in listBind.Columns)
                {
                    if (fieldBind.TableId.Equals(tableName, StringComparison.OrdinalIgnoreCase))
                    {
                        if (dataList == null)
                        {
                            dataList = new WbapList();
                            this.Add(listBind.Id + WbapDataType._List.ToString(), dataList);
                        }
                        dataList.Columns.Add(fieldBind.Id);
                    }
                }

                dataList.Columns.Add(keyField);
            }
        }
Example #2
0
        public void Delete()
        {
            var dataSourceSchema = new DataSourceSchema <RegionModel>();
            var db = new DataAccess <RegionModel> {
                Schema = dataSourceSchema
            };
            var isDelete = db.Delete(new RegionModel()
            {
                RegionID         = 6,
                RegionDescripton = "Test11"
            });

            Assert.IsTrue(isDelete);
        }
Example #3
0
        public void Insert()
        {
            var dataSourceSchema = new DataSourceSchema <RegionModel>();
            var db = new DataAccess <RegionModel> {
                Schema = dataSourceSchema
            };
            var id = db.Insert(new RegionModel()
            {
                RegionID         = 6,
                RegionDescripton = "Test"
            });

            Assert.IsTrue(id > 0);
        }
Example #4
0
        public DataSourceBase()
        {
            Transport = new TransportBase();

            Filters = new List <IFilterDescriptor>();

            ServerFiltering = true;

            OrderBy = new List <SortDescriptor>();

            Groups = new List <GroupDescriptor>();

            Aggregates = new List <AggregateDescriptorFunction>();

            Schema = new DataSourceSchema();

            Events = new Dictionary <DataSourceEvent, object>();

            Type = Core.Mvc.Helpers.CustomWrapper.DataSource.DataSourceType.Ajax;
        }
Example #5
0
 private void getFormItems(DataSourceSchema dss)
 {
     fromItems   = new List <FieldSchema>();
     imageFields = new List <FieldSchema>();
     memoFields  = new List <FieldSchema>();
     foreach (FieldSchema fld in dss.Fields)
     {
         if (fld.ExtendType == DataExtendType.ImageFile)
         {
             imageFields.Add(fld);
         }
         else if (fld.ExtendType == DataExtendType.Html)
         {
             memoFields.Add(fld);
         }
         else if (fld.IsInForm)
         {
             fromItems.Add(fld);
         }
     }
 }
Example #6
0
        public string post()
        {
            ListDataRow row = new ListDataRow();

            foreach (string fld in this.Request.Form.AllKeys)
            {
                row.Add(fld, Request.Form[fld]);
            }

            DataSource ds = getDataSourse();

            //  bool isNew = DataSource.isNewRow(row);
            //  ds.updateRow(row);

            DataSourceSchema dss = ds.getSchema();

            foreach (string fld in Request.Files.Keys)
            {
                HttpPostedFile file = Request.Files[fld];
                if (file != null && file.ContentLength > 0)
                {
                    string fileName = Path.GetFileName(file.FileName);
                    fileName = ds.getFieldFolder(fld) + fileName;
                    file.SaveAs(fileName);
                    string virPath = XSite.DataFileVirPath + fileName.Remove(0, XSite.DataFilePath.Length).Replace("\\", "/");
                    //row.Add(fld, virPath);
                    string fname = fld;
                    if (fname.StartsWith("file_"))
                    {
                        fname = fld.Remove(0, 5);
                    }
                    row[fname] = virPath;
                }
            }
            //  if (isNew)
            ds.updateRow(row);
            _row = row;

            return(draw(null));
        }
 public CustomDataSourceSchemaBuilder(DataSourceSchema schema)
     : base(schema)
 {
 }
Example #8
0
        public static IEnumerable <T> IncludeRelation <T>(this IEnumerable <T> source, string dataSourceName,
                                                          params Expression <Func <T, object> >[] path) where T : DataModel, new()
        {
            var schema = new DataSourceSchema <T>();
            //Table Relations Map
            //To be sent to the DB Lib for SQL Query generation
            var tableRelationsMap = new List <SqlJoinRelation>();

            //This will hold the information about the sub joins object types
            var expressionLookup = new Dictionary <string, string>();

            foreach (var t in path)
            {
                var memberExpression = t.Body as MemberExpression;
                if (memberExpression != null)
                {
                    expressionLookup.Add(memberExpression.Member.Name, t.Body.Type.Name);
                }
            }

            var dbRelationsList = schema.DataFields.Where(field => field.Relation != null &&
                                                          expressionLookup.Values.Contains(
                                                              field.Relation.WithDataModel.Name) &&
                                                          expressionLookup.Keys.Contains(field.Name)
                                                          ).
                                  Select(field => field.Relation).
                                  ToList();


            //Start processing the list of table relations
            if (dbRelationsList.Any())
            {
                //Foreach relation in the relations list, process it and construct the big TablesRelationsMap
                foreach (var relation in dbRelationsList)
                {
                    //Create a temporary map for this target table relation
                    var joinedTableInfo = new SqlJoinRelation();

                    //Get the data model we're in relation with.
                    var relationType = relation.WithDataModel;

                    //Build a data source schema for the data model we're in relation with.
                    var     generalModelSchemaType = typeof(DataSourceSchema <>);
                    var     specialModelSchemaType = generalModelSchemaType.MakeGenericType(relationType);
                    dynamic joinedModelSchema      = Activator.CreateInstance(specialModelSchemaType);

                    //Get it's Data Fields.
                    List <DataField> joinedModelFields = joinedModelSchema.GetDataFields();

                    //Get the table column names - exclude the ID field name.
                    var joinedModelTableColumns = joinedModelFields
                                                  .Where(field => field.TableField != null)
                                                  .Select(field => field.TableField.ColumnName)
                                                  .ToList();

                    //Get the field that describes the relation key from the target model schema
                    var joinedModelKey =
                        joinedModelFields.Find(item => item.TableField != null && item.Name == relation.OnDataModelKey);

                    //Get the field that describes our key on which we are in relation with the target model
                    var thisKey =
                        schema.DataFields.Find(item => item.TableField != null && item.Name == relation.ThisKey);

                    if (thisKey != null && joinedModelKey != null)
                    {
                        //Initialize the temporary map and add it to the original relations map
                        joinedTableInfo.RelationName = relation.RelationName;
                        joinedTableInfo.RelationType = relation.RelationType;


                        joinedTableInfo.MasterTableName    = dataSourceName;
                        joinedTableInfo.MasterTableKey     = thisKey.TableField.ColumnName;
                        joinedTableInfo.JoinedTableName    = joinedModelSchema.GetDataSourceName();
                        joinedTableInfo.JoinedTableKey     = joinedModelKey.TableField.ColumnName;
                        joinedTableInfo.JoinedTableColumns = joinedModelTableColumns;

                        //Add the relation keys to the TableRelationsMap
                        tableRelationsMap.Add(joinedTableInfo);
                    }
                } //end-foreach
            }     //end-outer-if

            //Get our table columns from the schema
            var thisModelTableColumns = schema.DataFields
                                        .Where(field => field.TableField != null)
                                        .Select(
                field => field.TableField.ColumnName)
                                        .ToList();

            var dt = DbRoutines.SELECT_WITH_JOIN(dataSourceName, thisModelTableColumns, null, tableRelationsMap, 0);

            return(dt.ConvertToList(path));
        }
Example #9
0
        public static T GetWithRelations <T>(this T source, params Expression <Func <T, object> >[] path)
            where T : DataModel, new()
        {
            var schema = new DataSourceSchema <T>();

            // Table Relations Map
            // To be sent to the DB Lib for SQL Query generation
            var tableRelationsMap = new List <SqlJoinRelation>();

            //
            // Database related
            // Where conditions dictionary
            //var finalDataSourceName = string.Empty;
            var whereConditions = new Dictionary <string, object>();


            // This will hold the information about the sub joins object types
            var expressionLookup = path.ToDictionary(t =>
            {
                var memberExpression = t.Body as MemberExpression;
                return(memberExpression != null ? memberExpression.Member.Name : null);
            }, t => t.Body.Type.Name);


            //
            // Get the Relations Fields from the Schema
            var dbRelationsList = schema.DataFields
                                  .Where(field =>
                                         field.Relation != null &&
                                         expressionLookup.Values.Contains(field.Relation.WithDataModel.Name) &&
                                         expressionLookup.Keys.Contains(field.Name))
                                  .Select(field => field.Relation).
                                  ToList();


            //
            // Start processing the list of table relations
            if (dbRelationsList.Any())
            {
                //Foreach relation in the relations list, process it and construct the big TablesRelationsMap
                foreach (var relation in dbRelationsList)
                {
                    //Create a temporary map for this target table relation
                    var joinedTableInfo = new SqlJoinRelation();

                    //Get the data model we're in relation with.
                    var relationType = relation.WithDataModel;

                    //Build a data source schema for the data model we're in relation with.
                    var     generalModelSchemaType = typeof(DataSourceSchema <>);
                    var     specialModelSchemaType = generalModelSchemaType.MakeGenericType(relationType);
                    dynamic joinedModelSchema      = Activator.CreateInstance(specialModelSchemaType);

                    //Get it's Data Fields.
                    List <DataField> joinedModelFields = joinedModelSchema.GetDataFields();

                    //Get the table column names - exclude the ID field name.
                    var joinedModelTableColumns = joinedModelFields
                                                  .Where(field => field.TableField != null)
                                                  .Select(field => field.TableField.ColumnName)
                                                  .ToList();

                    //Get the field that describes the relation key from the target model schema
                    var joinedModelKey =
                        joinedModelFields.Find(item => item.TableField != null && item.Name == relation.OnDataModelKey);

                    //Get the field that describes our key on which we are in relation with the target model
                    var thisKey =
                        schema.DataFields.Find(item => item.TableField != null && item.Name == relation.ThisKey);

                    if (thisKey != null && joinedModelKey != null)
                    {
                        //Initialize the temporary map and add it to the original relations map
                        joinedTableInfo.RelationName       = relation.RelationName;
                        joinedTableInfo.RelationType       = relation.RelationType;
                        joinedTableInfo.MasterTableName    = schema.DataSourceName;
                        joinedTableInfo.MasterTableKey     = thisKey.TableField.ColumnName;
                        joinedTableInfo.JoinedTableName    = joinedModelSchema.GetDataSourceName();
                        joinedTableInfo.JoinedTableKey     = joinedModelKey.TableField.ColumnName;
                        joinedTableInfo.JoinedTableColumns = joinedModelTableColumns;

                        //Add the relation keys to the TableRelationsMap
                        tableRelationsMap.Add(joinedTableInfo);
                    }
                } //end-foreach
            }     //end-outer-if


            //
            // Get the ID Field to find the relations for.
            // If the ID Field was not found, return an empty instance of the object.
            var idField = schema.DataFields.Find(field => field.TableField != null && field.TableField.IsIdField);

            if (idField != null)
            {
                var dataObjectAttr = source.GetType().GetProperty(idField.Name);

                var dataObjectAttrValue = dataObjectAttr.GetValue(source, null);

                // Put the ID Field in the WHERE CONDITIONS
                if (dataObjectAttrValue != null)
                {
                    whereConditions.Add(idField.TableField.ColumnName,
                                        Convert.ChangeType(dataObjectAttrValue, idField.TableField.FieldType));
                }
                else
                {
                    return(source);
                }
            }
            else
            {
                return(source);
            }

            //
            // Get our table columns from the schema
            var thisModelTableColumns = schema.DataFields
                                        .Where(field => field.TableField != null)
                                        .Select(
                field => field.TableField.ColumnName)
                                        .ToList();

            //
            // Query the data-srouce
            var dt = DbRoutines.SELECT_WITH_JOIN(schema.DataSourceName, thisModelTableColumns, whereConditions,
                                                 tableRelationsMap, 1);

            // Return data
            var data = dt.ConvertToList(path);

            if (data != null && data.Count > 0)
            {
                return(data.First());
            }
            return(source);
        }
Example #10
0
        public string draw(string dsName)
        {
            if (!string.IsNullOrEmpty(dsName))
            {
                this._dsName = dsName;
            }

            DataSource ds = getDataSourse();

            if (ds == null)
            {
                throw new Exception(Lang.DataSourceNameIsNull);
            }


            DataSourceSchema dss = ds.getSchema();

            StringBuilder sb = new StringBuilder();

            //<form method="post" enctype="multipart/form-data" id="frmTransfer" action="">
            sb.Append(@"<form method=""post"" enctype=""multipart/form-data"" action=""DataForm.");
            sb.Append(name);
            sb.Append(@".post.wbo"" ");
            sb.Append(@" id=""");
            sb.Append(name);
            sb.Append(@""" name=""");
            sb.Append(name);
            sb.Append(@""">");
            sb.Append("<table border='0'>");
            sb.Append("<tr>");
            sb.Append("<td colspan='");
            sb.Append(_rowFieldCount * 2);
            sb.Append("'>");
            sb.Append(dss.Title);
            sb.Append("</td>");
            sb.Append("</tr>");
            getFormItems(dss);
            int i = 0;

            while (i < fromItems.Count)
            {
                sb.Append("<tr>");
                for (int c = 0; c < this._rowFieldCount; c++)
                {
                    FieldSchema fss = null;
                    if (i < fromItems.Count)
                    {
                        fss = fromItems[i];
                    }


                    string value = "";
                    if (fss != null && _row != null && _row.Count > 0)
                    {
                        if (_row.ContainsKey(fss.Id))
                        {
                            value = _row[fss.Id];
                        }
                    }

                    sb.Append(@"<td style=""padding:1px;text-align: left;"">");
                    if (fss != null)
                    {
                        sb.Append("<label>");
                        string title = string.IsNullOrEmpty(fss.Title) ? fss.Id : fss.Title;
                        sb.Append(title);
                        sb.Append(":</label>");
                    }
                    else
                    {
                        sb.Append("&nbsp;");
                    }

                    sb.Append(@"</td><td style=""padding:1px 10px 1px 1px"">");

                    if (fss != null)
                    {
                        sb.Append(@"<input type=""text""");
                        sb.Append(@" name=""");
                        sb.Append(fss.Id);
                        sb.Append(@"""");
                        sb.Append(@" value=""");
                        sb.Append(value);
                        sb.Append(@""" />");
                    }
                    else
                    {
                        sb.Append("&nbsp;");
                    }
                    sb.Append("</td>");
                    i++;
                }
                sb.Append("</tr>");
            }

            //添加备注
            i = 0;
            while (i < memoFields.Count)
            {
                sb.Append("<tr>");
                sb.Append("<td colspan='");
                sb.Append(_rowFieldCount * 2);
                sb.Append("'>");
                FieldSchema fld   = memoFields[i];
                string      value = _row == null ? "" : _row[fld.Id];
                string      title = string.IsNullOrEmpty(fld.Title) ? fld.Id : fld.Title;
                sb.Append(title);
                sb.Append("<br/>");
                sb.Append(@"<textarea style='width:");
                sb.Append(_rowFieldCount * _colWidth);
                sb.Append("px;height:");
                sb.Append(80);
                sb.Append("px;'");
                sb.Append(@" name=""");
                sb.Append(fld.Id);
                sb.Append(@""">");
                sb.Append(value);
                sb.Append(@"</textarea> ");
                sb.Append("</td>");
                sb.Append("</tr>");
                i++;
            }

            //添加图像
            i = 0;
            while (i < imageFields.Count)
            {
                sb.Append("<tr>");
                for (int c = 0; c < _rowFieldCount; c++)
                {
                    sb.Append("<td colspan='2'>");
                    if (i < imageFields.Count)
                    {
                        FieldSchema fld   = imageFields[i];
                        string      value = _row == null ? "" : _row[fld.Id];
                        string      title = string.IsNullOrEmpty(fld.Title) ? fld.Id : fld.Title;
                        sb.Append(title);
                        sb.Append(@"<input type=""file"" ");
                        sb.Append(@" class=""easyui-filebox"" ");
                        sb.Append(@" name=""file_");
                        sb.Append(fld.Id);
                        sb.Append(@""" value=""""/> ");
                        sb.Append("<br/>");
                        sb.Append(@"<img src=""");
                        sb.Append(value);
                        sb.Append(@""" width=""200px""  /> ");

                        sb.Append(@"<input type=""hidden"" ");
                        sb.Append(@" name=""");
                        sb.Append(fld.Id);
                        sb.Append(@""" value=""");
                        sb.Append(value);
                        sb.Append(@""" />");
                    }
                    else
                    {
                        sb.Append("&nbsp");
                    }

                    sb.Append("</td>");
                    i++;
                }
                sb.Append("</tr>");
            }

            //sb.Append("<tr>");
            //sb.Append("<td colspan='");
            //sb.Append(_rowFieldCount * 2);
            //sb.Append("'>");
            //sb.Append(@"<input type=""button"" ");
            //sb.Append(@" onclick=""");
            //sb.Append(@"$('#");
            //sb.Append(name);
            //sb.Append(@"').submit()"" ");
            //sb.Append(@" value=""保存""/> ");
            //sb.Append("</td>");
            //sb.Append("</tr>");
            sb.Append("</table>");
            foreach (string fld in dss.PrimaryKeys)
            {
                //fld = XSqlBuilder.OLD_VERSION_PIX + fld;
                string value = _row == null || _row.Count < 1 ? "" : _row[XSqlBuilder.OLD_VERSION_PIX + fld];
                sb.Append(@"<input type=""hidden""  name=""");
                sb.Append(XSqlBuilder.OLD_VERSION_PIX);
                sb.Append(fld);
                sb.Append(@""" value=""");
                sb.Append(value);
                sb.Append(@"""/>");
            }
            sb.Append("</form>");

            //            sb.Append(@"<script language=""javascript"" type=""text/javascript"">");
            //            sb.Append(@"$('");
            //            sb.Append(name);
            //            sb.Append(@"').({
            //                success:function(data){
            //                  alert('记录保存')
            //                }
            //            })");
            //sb.Append("</script>");
            return(sb.ToString());
        }
 public SignalRHierarchicalDataSourceSchemaBuilder(DataSourceSchema schema)
     : base(schema)
 {
 }
Example #12
0
 public CustomDataSourceSchemaBuilderBase(DataSourceSchema schema)
 {
     this.schema = schema;
 }
Example #13
0
 public CustomHierarchicalDataSourceSchemaBuilder(DataSourceSchema schema, ViewContext viewContext, IUrlGenerator urlGenerator)
     : base(schema)
 {
     this.viewContext  = viewContext;
     this.urlGenerator = urlGenerator;
 }