예제 #1
0
        public override object ResolveDbValue(DbObject db)
        {
            List <SelectOption> v = null;
            var d       = db.Get <int[]>(this.Name, null);
            var reldata = db.Get <string[]>(this.Name + "__data", null);

            if (d != null)
            {
                v = new List <SelectOption>();
                for (int i = 0; i < d.Length; i++)
                {
                    var option = new SelectOption();
                    option.Add("Value", d[i]);
                    option.Add("Text", reldata[i]);
                    v.Add(option);
                }
            }
            // var relData = db.Get<IEnumerable<DbObject>>(this.DBName + "__data", null);

            // if (relData != null)
            // {
            //     v = new List<SelectOption>();
            //     foreach(DbObject obj in relData)
            //     {
            //         var option = new SelectOption();
            //         option.Add("Value", obj.Get("ID", 0));
            //         option.Add("Text", obj.Get("NAME", ""));
            //         v.Add(option);
            //     }
            // }

            return(v);
        }
예제 #2
0
        public override object ResolveDbValue(DbObject db)
        {
            List <SelectOption> v = null;
            var d       = db.Get <int[]>(this.DBName, null);
            var reldata = db.Get <string[]>(this.DBName + "__data", null);

            if (d != null)
            {
                v = new List <SelectOption>();
                for (int i = 0; i < d.Length; i++)
                {
                    var option = new SelectOption();
                    if (this.ControlInfo.CollectionInfo.SourceType == DataSourceType.Enum)
                    {
                        option = GetEnumValue(d[i]);
                    }
                    else
                    {
                        option.Add("Value", d[i]);
                        option.Add("Text", reldata[i]);
                    }
                    v.Add(option);
                }
            }

            return(v);
        }
예제 #3
0
        public override object ResolveDbValue(DbObject db)
        {
            var v = db.Get(this.Name, 0);
            var t = db.Get <string>(this.Name + "__name", null);

            if (v == 0)
            {
                return(null);
            }
            else
            {
                var option = new SelectOption();
                option.Add("Value", v);
                option.Add("Text", t);

                return(option);
            }
        }
예제 #4
0
        public override object ResolveDbValue(DbObject db)
        {
            var v = db.Get(this.Name, 0);
            var t = db.Get <string>(this.Name + "__name", null);

            if (v == 0)
            {
                return(null);
            }
            else
            {
                if (this.ControlInfo.CollectionInfo.SourceType == DataSourceType.Enum)
                {
                    return(GetEnumValue(v));
                }
                var option = new SelectOption();
                option.Add("Value", v);
                option.Add("Text", t);

                return(option);
            }
        }
예제 #5
0
        public override object ResolveDbValue(DbObject db)
        {
            var v = db.Get <string>(this.DBName, null);

            if (v == null || v == "")
            {
                return(DateTime.MinValue);
            }
            else
            {
                return(DateTime.Parse(v));
            }
        }
예제 #6
0
        public override object ResolveDbValue(DbObject db)
        {
            var v = db.Get <object>(this.DBName, null);

            if (v == null)
            {
                return(null);
            }
            else
            {
                return((decimal)v);
            }
        }
예제 #7
0
        public override object ResolveDbValue(DbObject db)
        {
            var v = db.Get <object>(this.DBName, null);

            if (v == null)
            {
                return(false);
            }
            else
            {
                return(DataHelper.GetDataValue(v, BaseType));
            }
        }
예제 #8
0
        protected override void OnPrepareRow(DataListContext context, DataListDefinition defn, DynamicObj row, DbObject dataRow)
        {
            var pickerContext = context as PickerListContext;

            if (pickerContext.FormModelMapping != null)
            {
                var mapping = new DynamicObj();
                foreach (var c in pickerContext.FormModelMapping)
                {
                    mapping.Add(c.Key, dataRow.Get <object>(c.Value.ToString(), null));
                }

                row.Add("_ModelMapping", mapping);
            }
        }
예제 #9
0
        protected DynamicObj PrepareRowData(DbObject dataRow, DataListContext context, DataListDefinition defn)
        {
            var row = new DynamicObj();

            row.Add(ViewConstant.RowId, dataRow.Get(context.DbQuery.ItemIdField, 0));
            foreach (var field in context.DbQuery.Fields)
            {
                var val = field.Field.ResolveDbValue(dataRow);
                if (context.Fields.Keys.Contains(field.FieldName))
                {
                    row.Add(context.Fields[field.FieldName].WidgetId, OnPrepareCell(context, defn, field.FieldName, val, row), true);
                }
                else
                {
                    row.Add(field.FieldName, val);
                }
            }
            OnPrepareRow(context, defn, row, dataRow);

            return(row);
        }
예제 #10
0
        public DbObject ProcessObjectCoverage(DbObject dbObject)
        {
            var dbObjectClone = dbObject.Get();

            if (dbObjectClone.Code == null)
            {
                return(dbObjectClone);
            }

            if (dbObjectClone.CoveredSegments.Count > 0)
            {
                var codeWithHighlights = _dbCodeFormatter.FormatCodeWithHighlights(dbObjectClone.Code,
                                                                                   dbObjectClone.CoveredSegments);
                dbObjectClone.CoveredSegments = ProcessHighlightedCode(codeWithHighlights);

                var functionalHighlightedCode = _dataScrubber.Scrub(codeWithHighlights, "floc.scrub");
                var functionalSegments        = ProcessHighlightedCode(functionalHighlightedCode);
                foreach (var functionalSegment in functionalSegments)
                {
                    dbObjectClone.CoveredCharacters  += functionalSegment.EndByte - functionalSegment.StartByte;
                    dbObjectClone.CoveredLinesOfCode += functionalSegment.LinesOfCode;
                }
            }

            var functionalCode = _dataScrubber.Scrub(dbObjectClone.Code, "floc.scrub");

            dbObjectClone.TotalLoc        = dbObjectClone.Code.Split('\n').Length;
            dbObjectClone.TotalCharacters = dbObjectClone.Code.Length;

            dbObjectClone.TotalFloc = functionalCode.Split('\n').Length;
            dbObjectClone.TotalFunctionalCharacters = functionalCode.Length;

            dbObjectClone.CoveredPercent = (decimal)dbObjectClone.CoveredCharacters / dbObjectClone.TotalFunctionalCharacters;

            return(dbObjectClone);
        }
예제 #11
0
        public override void BuiltWithDB(DbObject dbData)
        {
            this.ID = _id = dbData.Get("id", 0);

            this.CreatedOn  = dbData.Get("createdon", DateTime.MinValue);
            this.UpdatedOn  = dbData.Get("updatedon", DateTime.MinValue);
            this.CreatedBy  = dbData.Get("CreatedBy", 0);
            this.UpdatedBy  = dbData.Get("UpdatedBy", 0);
            this.ItemTypeId = dbData.Get("itemtype", 0);

            this.SetChangeTrack(true);
            foreach (var f in Entity.Fields)
            {
                var field = f.Value;
                var val   = field.ResolveDbValue(dbData);

                _attr.Add(f.Key, new FieldData(f.Value, val)
                {
                    IsChanged = false
                });
            }
            this.SetChangeTrack(false);
        }
예제 #12
0
        public override object ResolveDbValue(DbObject db)
        {
            var v = db.Get(this.DBName, 0);

            return(v);
        }
예제 #13
0
        internal static BaseField BuildField(string entName, string table, DbObject sch, List <DbObject> dbentities)
        {
            var fieldId = sch.Get("id", 0);
            var typ     = sch.Get("fieldtype", 0);
            var fname   = sch.Get("FIELDNAME", "");
            var dbname  = sch.Get("dbname", "");

            var field = CreateField((FieldType)typ);

            field.FieldId         = fieldId;
            field.Name            = fname;
            field.Type            = (FieldType)typ;
            field.DBName          = dbname;
            field.ViewId          = sch.Get <short>("viewtype", 0);
            field.IsDbStore       = !String.IsNullOrEmpty(dbname);
            field.TableName       = table;
            field._TempSchemaData = new DynamicObj();
            field.DefaultValue    = sch.Get <object>("defaultvalue", null);
            field.ViewOrder       = sch.Get("vieworder", 10000);

            field.IsRequired = sch.Get("isrequired", false);
            field.IsReadOnly = sch.Get("isreadonly", false);

            var computeexpression = sch.Get("computeexpression", "");

            if (!string.IsNullOrEmpty(computeexpression))
            {
                field.IsComputed        = true;
                field.ComputeExpression = new Model.Form.EvalExpression(computeexpression);
            }

            var relatedexp = sch.Get("relatedexp", String.Empty);

            if (!string.IsNullOrEmpty(relatedexp))
            {
                field.Related = new Model.Form.FieldPathExpression(relatedexp);
            }
            var linkEnt = sch.Get("linkentity", 0);

            if (field.Type == FieldType.ObjectLink || field.Type == FieldType.MultiObjectLink)
            {
                field.RefObject = linkEnt;

                // if (dbentities ==null)
                // {
                //     field.RefObject = linkEnt;
                // }
                // else
                // {
                //     var linkDbEnt = dbentities.Where(x => x.Get("id", 0) == linkEnt);
                //     if (linkDbEnt.Count() > 0)
                //     {
                //         field.RefObject = linkEnt;
                //     }
                // }

                field._TempSchemaData.Add("linkentity_domain", sch.Get("linkentity_domain", ""));
            }

            if (field is SelectField)
            {
                var collectionid = sch.Get("collectionid", 0);
                ((SelectField)field).CollectionId = collectionid;

                if (collectionid > 0)
                {
                    var info = StackErp.Core.Entity.CollectionService.GetCollectionInfo(collectionid);
                    field._TempSchemaData.Add("collectioninfo", info);
                }
            }

            if (field is OneToManyField)
            {
                var rField = (OneToManyField)field;
                if (dbentities == null)
                {
                    rField.RefObject = linkEnt;
                }
                else
                {
                    var linkDbEnt = dbentities.Where(x => x.Get("id", 0) == linkEnt);
                    if (linkDbEnt.Count() > 0)
                    {
                        rField.RefObject = linkEnt;
                    }
                }

                var linkentity_field = sch.Get("linkentity_field", "");
                rField.SetRelationShipInfo(rField.RefObject, linkentity_field);
            }

            return(field);
        }
예제 #14
0
        public DBEntity(int masterId,
                        int id,
                        string name,
                        Dictionary <string, BaseField> fields,
                        EntityType entityType,
                        DbObject entityDbo)
        {
            this.MasterId   = masterId;
            this.EntityId   = id;
            this.Name       = name;
            this.DBName     = entityDbo.Get("tablename", ""); //t_{namespace}
            this.IDField    = "ID";
            this.Text       = name;
            this.EntityType = entityType;

            _fieldText = entityDbo.Get("namefield", "");

            this.Fields = new InvariantDictionary <BaseField>();

            #region Default Fields
            if (fields.Where(f => f.Key.ToUpper() == "ID").Count() == 0)
            {
                this.Fields.Add("ID", new ObjectKeyField()
                {
                    Type       = FieldType.ObjectKey,
                    Name       = "ID",
                    DBName     = "ID",
                    IsReadOnly = true,
                    Entity     = this,
                    IsDbStore  = true
                });
            }

            fields.Add("CREATEDON", new DateTimeField()
            {
                Type       = FieldType.DateTime,
                Name       = "CreatedOn",
                DBName     = "CreatedOn",
                IsReadOnly = true,
                Copy       = false,
                IsDbStore  = true,
                ViewId     = -1
            });
            fields.Add("UPDATEDON", new DateTimeField()
            {
                Type       = FieldType.DateTime,
                BaseType   = TypeCode.DateTime,
                Name       = "UpdatedOn",
                DBName     = "UpdatedOn",
                IsReadOnly = true,
                Copy       = false,
                IsDbStore  = true,
                ViewId     = -1
            });
            fields.Add("CREATEDBY", new IntegerField()
            {
                Type       = FieldType.Integer,
                Name       = "CreatedBy",
                DBName     = "CreatedBy",
                IsReadOnly = true,
                Copy       = false,
                IsDbStore  = true,
                ViewId     = -1
            });
            fields.Add("UPDATEDBY", new IntegerField()
            {
                Type       = FieldType.Integer,
                Name       = "UpdatedBy",
                DBName     = "UpdatedBy",
                IsReadOnly = true,
                Copy       = false,
                IsDbStore  = true,
                ViewId     = -1
            });

            if (entityType == EntityType.CoreEntity)
            {
                fields.Add("ITEMTYPE", new IntegerField()
                {
                    Type       = FieldType.Integer,
                    Name       = "ItemType",
                    DBName     = "itemtype",
                    IsReadOnly = true,
                    IsDbStore  = true,
                    ViewId     = -1
                });
            }
            #endregion

            var orderedFields = fields.Select(x => x.Value).OrderBy(x => x.ViewOrder);

            foreach (var f in orderedFields)
            {
                if (!this.Fields.Keys.Contains(f.Name.ToUpper()))
                {
                    f.Entity = this;
                    this.Fields.Add(f.Name.ToUpper(), f);
                }
            }

            this.Relations = new List <IEntityRelation>();
            //this.DbConstraint
        }
예제 #15
0
        private static DBEntity BuildEntity(List <DbObject> dbentities, IEnumerable <DbObject> dbentitiesScbhemas, DbObject ent)
        {
            var entMasterId = ent.Get("masterid", 0);
            var entid       = ent.Get("id", 0);
            var name        = ent.Get("name", "");

            EntityCode.AllEntities.Remove(name.ToUpper());
            EntityCode.AllEntities.Add(name.ToUpper(), entid);

            var table = ent.Get("tablename", "");

            Dictionary <string, BaseField> fields = new Dictionary <string, BaseField>();

            var schemas = dbentitiesScbhemas.Where(x => x.Get("entityid", 0) == entid);

            foreach (var sch in schemas)
            {
                var fname = sch.Get("FIELDNAME", "");

                if (fields.Keys.Contains(fname.ToUpper()))
                {
                    throw new AppException($"Field with same name <{fname}> in entity <{name}> found in system.");
                }

                var field = BuildField(name, table, sch, dbentities);
                fields.Add(fname.ToUpper(), field);
            }

            var entityType   = EntityType.CoreEntity;
            var parententity = ent.Get("parententity", 0);

            if (parententity > 0)
            {
                entityType = EntityType.ChildEntity;
            }

            var hasstages = ent.Get("hasstages", false);

            if (hasstages)
            {
                fields.Add("STAGEID", new IntegerField()
                {
                    Type       = FieldType.Integer,
                    Name       = "stageid",
                    DBName     = "stageid",
                    IsReadOnly = true,
                    IsDbStore  = true,
                    ViewId     = -1
                });

                fields.Add("STATUSID", new IntegerField()
                {
                    Type       = FieldType.Integer,
                    Name       = "statusid",
                    DBName     = "statusid",
                    Text       = "Status",
                    IsReadOnly = true,
                    IsDbStore  = true,
                    ViewId     = 0
                });
            }

            var hasimage = ent.Get("hasimage", false);

            if (hasimage)
            {
                fields.Add("OBJECTIMAGE", new ImageField()
                {
                    Type       = FieldType.Integer,
                    Name       = "objectimage",
                    DBName     = "objectimage",
                    Text       = "Image",
                    IsReadOnly = true,
                    IsDbStore  = true,
                    ViewId     = 0
                });
            }

            var dbEntity = GetDBEntity(10, entid, name, fields, entityType, ent);

            dbEntity.ParentEntity = parententity;
            dbEntity.HasStages    = hasstages;
            if (hasstages)
            {
                dbEntity.StageGroupId = ent.Get("stagegroupid", 0);
            }

            dbEntity.EntityFeatures = ent.Get("features", "");

            return(dbEntity);
        }