コード例 #1
0
ファイル: StatService.cs プロジェクト: ChampsyGnom/GeoPat
 public void ShowStatWizzard(EntityTableInfo entityTableInfo,List<String> fieldPaths)
 {
     StatWizzardViewModel vm = new StatWizzardViewModel(entityTableInfo, fieldPaths);
     IDialogService dialogService = ServiceLocator.Current.GetInstance<IDialogService>();
     Window dialog = dialogService.CreateDialog("StatWizzardRegion", "Assisstant de statistiques");
     dialog.DataContext = vm;
     Nullable<Boolean> result = dialog.ShowDialog();
     if (result.HasValue && result.Value == true)
     { }
 }
コード例 #2
0
ファイル: MainViewModel.cs プロジェクト: ChampsyGnom/GeoPat
 public override List<Control> GetEntityViews(EntityTableInfo tableInfo)
 {
     if (tableInfo.EntityType .Equals (typeof(InfAire)))
     {
         List<Control> views = new List<Control>();
         views.Add(new FicheAireView());
         views.Add(new GenericDataGridView());
         views.Add(new GenericDataFormView());
         return views;
     }
     return base.GetEntityViews(tableInfo);
 }
コード例 #3
0
 public DataFileViewModel(string file, EntityTableInfo entityTableInfo, bool isLegacy)
 {
     // TODO: Complete member initialization
     this._dispatcher = System.Windows.Application.Current.Dispatcher;
     this.FilePath = file;
     this.TableInfo = entityTableInfo;
     this.IsLegacy = true;
     this.FileInfo = new FileInfo(this.FilePath);
     this._headers = new List<string>();
     this._datas = new List<List<string>>();
     this.Import = false;
     this._mapping = new Dictionary<String, int>();
 }
コード例 #4
0
 private void OpenEntityTable(EntityTableInfo tableInfo)
 {
     Console.WriteLine ("Open "+tableInfo.DisplayName );
     SwapRegionView swapRegionView = new SwapRegionView();
     Object viewModel =  Activator.CreateInstance ( typeof(GenericListViewModel<>).MakeGenericType(new Type[] { tableInfo.EntityType  }));
     swapRegionView.DataContext = viewModel;
     IRegion region = this._regionManager.Regions["TabRegion"];
     IRegionManager detailsRegionManager = region.Add(swapRegionView, null, true);
     IRegion regionContent = detailsRegionManager.Regions["SwapableRegion"];
     List<Control> views = this.GetEntityViews(tableInfo);
     swapRegionView.Configure(detailsRegionManager, views.ToArray());
     region.Activate(swapRegionView);
     swapRegionView.SwapView();
 }
コード例 #5
0
 public virtual List<Control> GetEntityViews(EntityTableInfo tableInfo)
 {
     List<Control> views = new List<Control>();
     views.Add(new GenericDataGridView());
     views.Add(new GenericDataFormView());
     return views;
 }
コード例 #6
0
        public override Boolean Validate(Object entityObject, Dictionary<String, String> valueStrings, EntityTableInfo tableInfo, out String message)
        {
            IDataService dataService = ServiceLocator.Current.GetInstance<IDataService>();
            IReperageService reperageService = ServiceLocator.Current.GetInstance<IReperageService>();
             EntityColumnInfo columnChaussee = (from c in tableInfo.ColumnInfos
                                               where c.ControlType == ControlType.Combo &&
                                                   c.ColumnName.Equals("INF_CHAUSSEE__ID")
                                               select c).FirstOrDefault();
            Object chausseeObj = columnChaussee.Property.GetValue(entityObject);
            if (chausseeObj == null && valueStrings.ContainsKey("InfChaussee.Code") && valueStrings.ContainsKey("InfChaussee.InfLiaison.Code"))
            {
                 DbSet setChaussee = dataService.GetDbSet("InfChaussee");
                 IQueryable queryable = setChaussee.AsQueryable();
                  ParameterExpression expressionBase = Expression.Parameter(setChaussee.ElementType, "item");

                  Expression expressionChausseeCode = Expression.Equal(Expression.Property(expressionBase, "Code"), Expression.Constant(valueStrings["InfChaussee.Code"]));
                  Expression expressionLiaisonCode = Expression.Equal(Expression.Property(Expression.Property(expressionBase, "InfLiaison"), "Code"), Expression.Constant(valueStrings["InfChaussee.InfLiaison.Code"]));
                  Expression expAnd = Expression.And(expressionChausseeCode, expressionLiaisonCode);

                  MethodCallExpression whereCallExpression = Expression.Call(
                  typeof(Queryable),
                  "Where",
                  new Type[] { queryable.ElementType },
                  queryable.Expression,
                  Expression.Lambda(expAnd, expressionBase));
                  queryable = queryable.Provider.CreateQuery(whereCallExpression);
                  foreach (Object obj in queryable)
                  {chausseeObj = obj;}

            }
            if (chausseeObj == null)
            {
                message = "La chaussée n'existe pas";
                return false;
            }
            else
            {
                Int64 chausseeId = (Int64)chausseeObj.GetType().GetProperty("Id").GetValue(chausseeObj);
                Int64 chausseeAbsDeb = (Int64)chausseeObj.GetType().GetProperty("AbsDeb").GetValue(chausseeObj);
                Int64 chausseeAbsFin = (Int64)chausseeObj.GetType().GetProperty("AbsFin").GetValue(chausseeObj);
                EntityFieldInfo fieldInfo = (from f in tableInfo.FieldInfos where f.ColumnInfo.Equals(ColumnLocation) select f).FirstOrDefault();
                Nullable<Int64> abs = null;
                if (valueStrings[fieldInfo.Path].IndexOf("+") != -1)
                {abs = reperageService.PrToAbs(chausseeId, valueStrings[fieldInfo.Path]); }
                else
                {abs = Int64.Parse(valueStrings[fieldInfo.Path]); }

                if (abs.HasValue)
                {
                    if (abs.Value > chausseeAbsFin || abs.Value < chausseeAbsDeb)
                    {
                        message = fieldInfo.DisplayName + " " + valueStrings[fieldInfo.Path] + " ne peut pas être en dehors des bornes de la chaussée ( " + reperageService.AbsToPr(chausseeId, chausseeAbsDeb) + " <-> " + reperageService.AbsToPr(chausseeId, chausseeAbsFin);
                        return false;
                    }
                }
                else
                {
                    message = null;
                    return true;
                }

                message = null;
                return true;
            }
        }
コード例 #7
0
 public abstract Boolean Validate(Object entityObject, Dictionary<String, String> valueStrings, EntityTableInfo tableInfo, out String message);
コード例 #8
0
        public EntityColumnInfo(EntityTableInfo entityTableInfo, PropertyInfo property)
        {
            // TODO: Complete member initialization
            this.TableInfo = entityTableInfo;
            this.ForeignKeyNames = new List<string>();
            this.FieldInfos = new List<EntityFieldInfo>();
            this.Property = property;
            this.HasChausseeEmpriseRule = false;
            this.PropertyName = property.Name;
            this.UniqueKeyNames = new List<string>();
            this.PropertyType = property.PropertyType;
            IEnumerable<Attribute> atts = property.GetCustomAttributes();

            foreach (Attribute att in atts)
            {
                if (att is LocationAttribute)
                {
                    LocationAttribute locationAttribute = att as LocationAttribute;
                    if (locationAttribute.LocationAttributeType == Enums.LocationAttributeType.ReferenceDeb)
                    { this.IsLocalisationDeb = true; }

                    if (locationAttribute.LocationAttributeType == Enums.LocationAttributeType.ReferenceFin)
                    { this.IsLocalisationFin = true; }

                    if (locationAttribute.LocationAttributeType == Enums.LocationAttributeType.ReferenceId)
                    { this.IsLocalisationReferenceId = true; }

                    if (locationAttribute.LocationAttributeType == Enums.LocationAttributeType.ReferenceGeometry)
                    { this.IsLocalisationReferenceGeom = true; }

                }

                if (att is AllowNullAttribute)
                {
                    this.AllowNull = (att as AllowNullAttribute).AllowNull;
                }
                if (att is RuleEmpriseAttribute)
                {
                    this.EmpriseChausseeColumnName = (att as RuleEmpriseAttribute).ChauseeColumnName;
                    this.HasChausseeEmpriseRule = true;
                }
                if (att is ControlTypeAttribute)
                {
                    this.ControlType = (att as ControlTypeAttribute).ControlType;
                }

                if (att is ColumnNameAttribute)
                {
                    this.ColumnName = (att as ColumnNameAttribute).ColumnName;
                }

                if (att is MaxCharLengthAttribute )
                {
                    this.MaxCharLength  = (att as MaxCharLengthAttribute).MaxCharLength;
                }

                if (att is DisplayNameAttribute )
                {
                    this.DisplayName = (att as DisplayNameAttribute).DisplayName;
                }
                if (att is RangeValueAttribute )
                {
                    this.MinNumericValue = (att as RangeValueAttribute).MinValue;
                    this.MaxNumericValue = (att as RangeValueAttribute).MaxValue;
                }
                if (att is RulePrAttribute)
                {
                    this.IsPr = true;
                    this.PrChausseeColumnName = (att as RulePrAttribute).ChauseeColumnName;
                }

                if (att is PrimaryKeyAttribute)
                { this.PrimaryKeyName = (att as PrimaryKeyAttribute).PrimaryKeyName ; }

                if (att is ForeignKeyAttribute )
                { this.ForeignKeyNames.Add (  (att as ForeignKeyAttribute).ForeignKeyName); }

                if (att is UniqueKeyAttribute )
                { this.UniqueKeyNames.Add((att as UniqueKeyAttribute).UniqueKeyName); }

            }
        }
コード例 #9
0
        public override Boolean Validate(Object entityObject, Dictionary<String, String> valueStrings, EntityTableInfo tableInfo, out String message)
        {
            List<EntityFieldInfo> ukFieldInfos = new List<EntityFieldInfo>();
            IDataService dataService = ServiceLocator.Current.GetInstance<IDataService>();
            // On recherche les colonnes faisant parti de la clé unique
            foreach (EntityColumnInfo columnInfo in tableInfo.ColumnInfos)
            {
                if (columnInfo.UniqueKeyNames.Contains(UniqueKeyName))
                {
                    // Si il s'agit d'un clé étrangère on récupère la liste des champs coresspondant au clé unique des parent
                    if (columnInfo.ForeignKeyNames.Count > 0)
                    {
                        List<EntityColumnInfo> parentUkColumnInfos = dataService.GetAllParentUniqueKeyColumnInfos(columnInfo);
                        foreach (EntityColumnInfo parentUkColumnInfo in parentUkColumnInfos)
                        {
                            EntityFieldInfo fieldInfo = (from f in tableInfo.FieldInfos where
                                                             f.ParentColumnInfo != null &&
                                                             f.ParentColumnInfo.Equals(parentUkColumnInfo)
                                                            select f).FirstOrDefault();
                            ukFieldInfos.Add(fieldInfo);
                        }

                    }
                    // Sinon on ajoute le champ coresspondant
                    else
                    {
                        EntityFieldInfo fieldInfo = (from f in tableInfo.FieldInfos where f.ColumnInfo.Equals (columnInfo ) select f).FirstOrDefault();
                        ukFieldInfos.Add(fieldInfo);
                    }
                }
            }
            String messageString = null;
            Object value = null;
            List<Expression> expressions = new List<Expression>();
            Int64 currentId =(Int64) entityObject.GetType ().GetProperty ("Id").GetValue (entityObject );
            ParameterExpression expressionBase = Expression.Parameter(tableInfo.EntityType, "item");
            Expression expNotSameId = Expression.Property(expressionBase, "Id");
            expNotSameId = Expression.NotEqual(expNotSameId, Expression.Constant(currentId));
            expressions.Add(expNotSameId);
            foreach (EntityFieldInfo ukFieldInfo in ukFieldInfos)
            {
                if (valueStrings.ContainsKey(ukFieldInfo.Path))
                {
                    if (ukFieldInfo.ValidateString(valueStrings[ukFieldInfo.Path], out messageString, out value))
                    {
                        String[] items = ukFieldInfo.Path.Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        Expression expression = expressionBase;
                        foreach (String item in items)
                        { expression = Expression.Property(expression, item); }
                        if (ukFieldInfo.ControlType == Attributes.ControlType.Pr)
                        {
                            // On est jamais sur chaussé !!! :) ouf

                            // On récupère la colonne chausséé de l'entité
                            // Il faut récupérer la clé unique de la table chausséé
                            EntityColumnInfo columnInfoChaussee = (from c in tableInfo.ColumnInfos where
                                                                       c.ControlType == Attributes.ControlType.Combo &&
                                                                       c.ColumnName.Equals("INF_CHAUSSEE__ID") select c).FirstOrDefault();

                            List<EntityColumnInfo> columnInfoChausseeUks = dataService.GetAllParentUniqueKeyColumnInfos(columnInfoChaussee);

                            List<EntityFieldInfo> ukFieldChausseeInfos = new List<EntityFieldInfo>();
                            Boolean allChausseeValuePresent = true;
                            foreach (EntityColumnInfo columnInfoChausseeUk in columnInfoChausseeUks)
                            {
                                EntityFieldInfo fieldInfo = (from f in tableInfo .FieldInfos
                                                             where
                                                                 f.ParentColumnInfo != null &&
                                                                 f.ParentColumnInfo.Equals(columnInfoChausseeUk)
                                                             select f).FirstOrDefault();
                                ukFieldChausseeInfos.Add(fieldInfo);
                                if (!valueStrings.ContainsKey(fieldInfo.Path))
                                {

                                    allChausseeValuePresent = false;

                                }

                            }
                            if (allChausseeValuePresent == true)
                            {
                                EntityTableInfo tableInfoChaussee = dataService.GetEntityTableInfo("InfChaussee");
                                DbSet dbSetChaussee = dataService.GetDbSet(tableInfoChaussee.EntityType);
                                ParameterExpression expressionBaseChaussee = Expression.Parameter(tableInfoChaussee.EntityType, "item");
                                List<Expression> expressionsChaussees = new List<Expression>();
                                foreach (EntityFieldInfo ukFieldChausseeInfo in ukFieldChausseeInfos)
                                {
                                    if (ukFieldChausseeInfo.ValidateString(valueStrings[ukFieldChausseeInfo.Path], out messageString, out value))
                                    {
                                        String chausseePath = ukFieldChausseeInfo.Path.Substring("InfChaussee.".Length);
                                        String[] chausseePathItems = chausseePath.Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                        Expression expressionChaussee = null;
                                        foreach (String chausseePathItem in chausseePathItems)
                                        {
                                            if (expressionChaussee == null)
                                            { expressionChaussee = Expression.Property(expressionBaseChaussee, chausseePathItem); }
                                            else
                                            { expressionChaussee = Expression.Property(expressionChaussee, chausseePathItem); }
                                        }

                                        expressionChaussee = Expression.Equal(expressionChaussee, Expression.Constant(value));
                                        expressionsChaussees.Add(expressionChaussee);
                                    }
                                }

                                IQueryable queryableChaussee = dbSetChaussee;
                                if (expressionsChaussees.Count > 0)
                                {
                                    Expression expressionAnd = expressionsChaussees.First();
                                    for (int i = 1; i < expressionsChaussees.Count; i++)
                                    { expressionAnd = Expression.And(expressionAnd, expressionsChaussees[i]); }
                                    MethodCallExpression whereCallExpression = Expression.Call(
                                    typeof(Queryable),
                                    "Where",
                                    new Type[] { queryableChaussee.ElementType },
                                    queryableChaussee.Expression,
                                    Expression.Lambda(expressionAnd, expressionBaseChaussee));
                                    queryableChaussee = queryableChaussee.Provider.CreateQuery(whereCallExpression);
                                }
                                Object chausseeItem = null;
                                foreach (Object item in queryableChaussee)
                                {chausseeItem = item; break;}
                                if (chausseeItem != null)
                                {
                                    Int64 chausseId =(Int64) chausseeItem.GetType().GetProperty("Id").GetValue(chausseeItem);
                                    IReperageService reperageService = ServiceLocator.Current.GetInstance<IReperageService>();
                                   Nullable<Int64> abs =   reperageService.PrToAbs(chausseId, valueStrings[ukFieldInfo.Path]);
                                   if (ukFieldInfo.ColumnInfo.AllowNull)
                                   {
                                       expression = Expression.Equal(expression, Expression.Constant(abs, typeof(Nullable<Int64>)));
                                       expressions.Add(expression);
                                   }
                                   else
                                   {
                                       expression = Expression.Equal(expression, Expression.Constant(abs.Value));
                                       expressions.Add(expression);
                                   }
                                }
                                // il faut créer la requete sur la table chaussée avec les values de l'entité

                            } else throw new Exception("Impossible de récupérer toutes les valeurs de la clé unique chaussé, veuillé vérifier le modèle de donnée");
                            /*
                             IReperageService reperageService = ServiceLocator.Current.GetInstance<IReperageService>();
                             EntityColumnInfo columnChaussee = (from c in tableInfo.ColumnInfos
                                                                 where
                                                                     c.ColumnName.Equals("INF_CHAUSSEE__ID")
                                                                 select c).FirstOrDefault();
                              Int64 chausseeId = (Int64)columnChaussee.Property.GetValue(entityObject);
                              Nullable<Int64> abs = reperageService.PrToAbs(chausseeId, valueStrings[ukFieldInfo.Path]);
                              if (ukFieldInfo.ColumnInfo.AllowNull)
                              {
                                  expression = Expression.Equal(expression, Expression.Constant(abs,typeof(Nullable<Int64>)));
                                  expressions.Add(expression);
                              }
                              else
                              {
                                  expression = Expression.Equal(expression, Expression.Constant(abs.Value));
                                  expressions.Add(expression);
                              }

                          */
                        }
                        else
                        {
                            expression = Expression.Equal(expression, Expression.Constant(value));
                            expressions.Add(expression);
                        }

                    }
                }
                else throw new Exception("Impossible de créer les critères pour la règle de validation clé unique " + UniqueKeyName);

            }
            IQueryable queryable = dataService.GetDbSet(tableInfo.EntityType);
            if (expressions.Count > 0)
            {
                Expression expressionAnd = expressions.First();
                for (int i = 1; i < expressions.Count; i++)
                { expressionAnd = Expression.And(expressionAnd, expressions[i]); }
                MethodCallExpression whereCallExpression = Expression.Call(
                typeof(Queryable),
                "Where",
                new Type[] { queryable.ElementType },
                queryable.Expression,
                Expression.Lambda(expressionAnd, expressionBase));
                queryable = queryable.Provider.CreateQuery(whereCallExpression);
            }
            else throw new Exception("Impossible de créer les critères pour la règle de validation clé unique " + UniqueKeyName);
            bool hasSomeRow = false;
            foreach (Object o in queryable)
            { hasSomeRow = true; break; }

            if (hasSomeRow)
            {
                message = "il existe déja un enregistrement avec les mêmes "+String.Join (",", (from f in ukFieldInfos select f.DisplayName ));
                return false;
            }
            else
            {
                message = null;
                return true;
            }
        }
コード例 #10
0
        public StatWizzardViewModel(EntityTableInfo entityTableInfo, List<String> fieldPaths)
        {
            this.DisplayTypes = new List<StatDisplayType>();
            this.DisplayTypes.Add(StatDisplayType.Column);
            this.DisplayTypes.Add(StatDisplayType.Pie);
            this.DisplayTypes.Add(StatDisplayType.Line);
            this.DisplayTypes.Add(StatDisplayType.Bar);
            this.DisplayTypes.Add(StatDisplayType.Aera);

            this.StatValues = new ObservableCollection<StatValueViewModel>();
            this.EntityTableInfo = entityTableInfo;
            this.AllFields = new List<StatFieldViewModel>();
            this.StepConfigurationVisiblity = System.Windows.Visibility.Visible;
            this.StepPreviewVisiblity = System.Windows.Visibility.Hidden;
            this.StatTypes = new ObservableCollection<StatTypeViewModel>();
            StatTypeViewModel vmStateTypeCount = new StatTypeViewModel();
            vmStateTypeCount.DisplayName = "Nombre de " + entityTableInfo.DisplayName;
            vmStateTypeCount.StatType = StatType.Count;
            this.StatTypes.Add(vmStateTypeCount);
            this.StatFields = new ObservableCollection<StatFieldViewModel>();
            IDataService dataService = ServiceLocator.Current.GetInstance<IDataService>();

            foreach (EntityFieldInfo field in entityTableInfo.FieldInfos)
            {
                if (field.ParentColumnInfo == null)
                {
                    if (field.ColumnInfo.ControlType == ControlType.Check)
                    {
                        StatFieldViewModel statField = new StatFieldViewModel();
                        statField.Field = field;
                        this.AllFields.Add(statField);
                    }
                    else if (field.ColumnInfo.ControlType == ControlType.Date)
                    {
                        StatFieldViewModel statField = new StatFieldViewModel();
                        statField.Part = StatFieldPart.Year;
                        statField.Field = field;
                        this.AllFields.Add(statField);
                    }
                    else if (field.ColumnInfo.ControlType == ControlType.Decimal)
                    {
                        StatFieldViewModel statField = new StatFieldViewModel();
                        statField.Field = field;
                        this.AllFields.Add(statField);
                    }
                    else if (field.ColumnInfo.ControlType == ControlType.Integer)
                    {
                        StatFieldViewModel statField = new StatFieldViewModel();
                        statField.Field = field;
                        this.AllFields.Add(statField);
                    }

                }
                else
                {
                    if (field.ColumnInfo != null && field.ColumnInfo.ControlType == ControlType.Combo)
                    {
                        StatFieldViewModel statField = new StatFieldViewModel();
                        statField.Field = field;
                        this.AllFields.Add(statField);
                    }
                    else {

                    }
                }
            }
            this.Symbologies = new System.Collections.ObjectModel.ObservableCollection<Symbology>();
        }
コード例 #11
0
ファイル: CartoViewModel.cs プロジェクト: ChampsyGnom/GeoPat
        private void AddLayerMetier(TemplateViewModel templateViewModel, TemplateNodeFolderViewModel parentFolder, EntityTableInfo tableInfo)
        {
            long nextMapOrder = this.GetNextMapOrder();
            DbSet<SigNode> nodes = this.DataService.GetDbSet<SigNode>();
            DbSet<SigLayer> layers = this.DataService.GetDbSet<SigLayer>();


            DbSet<SigCodeNode> codeNodes = this.DataService.GetDbSet<SigCodeNode>();
            DbSet<SigCodeLayer> codeLayers = this.DataService.GetDbSet<SigCodeLayer>();
           
            SigNode nodeLayerMetier = new SigNode();
            nodeLayerMetier.SigTemplateId = templateViewModel.Id;
            if (parentFolder != null)
            {
                nodeLayerMetier.ParentId = parentFolder.Model.Id;
                nodeLayerMetier.Order = parentFolder.Nodes.Count;
            }
            else
            {
                nodeLayerMetier.ParentId = -1;
                nodeLayerMetier.Order = templateViewModel.Nodes.Count;
            }
            nodeLayerMetier.SigCodeNode = (from c in codeNodes where c.Code.Equals("Layer") select c).FirstOrDefault();
            nodeLayerMetier.Libelle = tableInfo.DisplayName;
            SigLayer layer = new SigLayer();
            layer.Libelle = tableInfo.DisplayName;
            layer.MapOrder = nextMapOrder;
            layer.EntityName = tableInfo.EntityType.Name;
            layer.SigCodeLayer = (from c in codeLayers where c.Code.Equals("Geocodage") select c).FirstOrDefault();
            layers.Add(layer);           
            this.DataService.DataContext.SaveChanges();
            nodeLayerMetier.SigLayer = layer;
            nodes.Add(nodeLayerMetier);
            this.DataService.DataContext.SaveChanges();
            nodeLayerMetier.SigLayer = layer;
            nodeLayerMetier.SigLayerId = layer.Id;
            TemplateNodeLayerViewModel vm = new TemplateNodeLayerViewModel(nodeLayerMetier);
            if (parentFolder == null)
            { templateViewModel.Nodes.Add(vm); }
            else
            { parentFolder.Nodes.Add(vm); }
            vm.CreateLayers();
            foreach (IMapLayer mapLayer in vm.Layers)
            {this.Map.Layers.Add(mapLayer);}
        }