コード例 #1
0
        public void FilterData()
        {
            if (string.IsNullOrWhiteSpace(ConditionsSelected))
            {
                DataHelpers.windowManager.ShowMessageBox("Vérifier les conditions");
                return;
            }
            if (string.IsNullOrEmpty(Valeur))
            {
                Valeur = " ";
                //DataHelpers.windowManager.ShowMessageBox("Vérifier les valeurs");
                //return;
            }

            var query = Inputs;

            //var query = new List<IDocument>();
            //query =   ((System.Collections.Generic.List<IDocument>) Inputs) ;
            if (GetTypeName(SelectedProeprty.PropertyType) == "DateTime")
            {
                var _Valeur = DateTime.Parse(Valeur);
                switch (ConditionsSelected)
                {
                case "égale":
                    var result = query.Where(a => (SelectedProeprty.GetValue(a, null) as DateTime?)?.Date == (_Valeur.Date));
                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case "déffirent de":
                    var resultDef = query.Where(a => !((SelectedProeprty.GetValue(a, null) as DateTime?)?.Date == _Valeur.Date));
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;

                case "inférieur à":
                    var resultInf = query.Where(a => (SelectedProeprty.GetValue(a, null) as DateTime?)?.Ticks <= (_Valeur.Ticks));
                    Result = resultInf.ToList();
                    Inputs = Result;
                    break;

                case "supérieur à":
                    var resultSup = query.Where(a => (SelectedProeprty.GetValue(a, null) as DateTime?)?.Ticks >= (_Valeur.Ticks));
                    Result = resultSup.ToList();
                    Inputs = Result;
                    break;

                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "Int32")
            {
                var _Valeur = int.Parse(Valeur);
                switch (ConditionsSelected)
                {
                case "ressemble":
                    try
                    {
                        var resultd = query.Where(a => SelectedProeprty.GetValue(a, null).ToString().Contains(Valeur));
                        Result = resultd.ToList();
                        Inputs = Result;
                    }
                    catch
                    { }


                    break;

                case "égale":
                    var result = query.Where(a => (int)SelectedProeprty.GetValue(a, null) == (_Valeur));
                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case "déffirent de":
                    var resultDef = query.Where(a => (int)SelectedProeprty.GetValue(a, null) != _Valeur);
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;

                case "inférieur à":
                    var resultInf = query.Where(a => (int)SelectedProeprty.GetValue(a, null) <= (_Valeur));
                    Result = resultInf.ToList();
                    Inputs = Result;
                    break;

                case "supérieur à":
                    var resultSup = query.Where(a => (int)SelectedProeprty.GetValue(a, null) >= (_Valeur));
                    Result = resultSup.ToList();
                    Inputs = Result;
                    break;

                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "Decimal")
            {
                var _Valeur = decimal.Parse(Valeur);
                switch (ConditionsSelected)
                {
                case "ressemble":
                    try
                    {
                        var resultd = query.Where(a => SelectedProeprty.GetValue(a, null).ToString().Contains(Valeur));
                        Result = resultd.ToList();
                        Inputs = Result;
                    }
                    catch
                    {}

                    break;

                case "égale":
                    var result = query.Where(a => (decimal)SelectedProeprty.GetValue(a, null) == (_Valeur));
                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case "déffirent de":
                    var resultDef = query.Where(a => (decimal)SelectedProeprty.GetValue(a, null) != _Valeur);
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;

                case "inférieur à":
                    var resultInf = query.Where(a => (decimal)SelectedProeprty.GetValue(a, null) <= (_Valeur));
                    Result = resultInf.ToList();
                    Inputs = Result;
                    break;

                case "supérieur à":
                    var resultSup = query.Where(a => (decimal)SelectedProeprty.GetValue(a, null) >= (_Valeur));
                    Result = resultSup.ToList();
                    Inputs = Result;
                    break;

                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "Double")
            {
                var _Valeur = double.Parse(Valeur);
                switch (ConditionsSelected)
                {
                case "ressemble":
                    try
                    {
                        var resultd = query.Where(a => SelectedProeprty.GetValue(a, null).ToString().Contains(Valeur));
                        Result = resultd.ToList();
                        Inputs = Result;
                    }
                    catch
                    { }
                    break;

                case "égale":
                    var result = query.Where(a => (double)SelectedProeprty.GetValue(a, null) == (_Valeur));
                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case "déffirent de":
                    var resultDef = query.Where(a => (double)SelectedProeprty.GetValue(a, null) != _Valeur);
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;

                case "inférieur à":
                    var resultInf = query.Where(a => (double)SelectedProeprty.GetValue(a, null) <= (_Valeur));
                    Result = resultInf.ToList();
                    Inputs = Result;
                    break;

                case "supérieur à":
                    var resultSup = query.Where(a => (double)SelectedProeprty.GetValue(a, null) >= (_Valeur));
                    Result = resultSup.ToList();
                    Inputs = Result;
                    break;

                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "String")
            {
                switch (ConditionsSelected)
                {
                case "ressemble":
                    try
                    {
                        var results = query.Where(s =>
                        {
                            var value = SelectedProeprty.GetValue(s, null);
                            if (value == null)
                            {
                                return(false);
                            }
                            return(value.ToString().ToLower().Contains(Valeur.ToLower()));
                        });


                        Result = results.ToList();
                        Inputs = Result;
                    }
                    catch
                    {}

                    break;

                case "égale":
                    var result = query.Where(s =>
                    {
                        var value = SelectedProeprty.GetValue(s, null);
                        if (value == null)
                        {
                            return(false);
                        }
                        return(value.ToString() == (Valeur));
                    });

                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case "déffirent de":
                    var resultDef = query.Where(s =>
                    {
                        var value = SelectedProeprty.GetValue(s, null);
                        if (value == null)
                        {
                            return(false);
                        }
                        return(!(value.ToString() == (Valeur)));
                    });
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;


                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "ObjectId")
            {
                var attributes = SelectedProeprty.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute;
                var option     = attributes.Options;
                var link       = DataHelpers.GetMongoData(option, "Name", Valeur, true).FirstOrDefault();
                if (link == null && ConditionsSelected != "ressemble")
                {
                    return;
                }
                switch (ConditionsSelected)
                {
                case "égale":
                    var result = query.Where(a => SelectedProeprty.GetValue(a, null).ToString().Equals(link.Id.ToString()));
                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case "déffirent de":
                    var resultDef = query.Where(a => !SelectedProeprty.GetValue(a, null).ToString().Contains(link.Id.ToString()));
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;


                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "Boolean")
            {
                switch (ConditionsSelected)
                {
                case "ressemble":
                    try
                    {
                        var results = query.Where(s =>
                        {
                            var value = SelectedProeprty.GetValue(s, null);
                            if (value == null)
                            {
                                return(false);
                            }
                            return(value.ToString().Contains(Valeur));
                        });


                        Result = results.ToList();
                        Inputs = Result;
                    }
                    catch
                    { }

                    break;

                case "égale":
                    var result = query.Where(s =>
                    {
                        var value = SelectedProeprty.GetValue(s, null);
                        if (value == null)
                        {
                            return(false);
                        }
                        return(value.ToString() == (Valeur));
                    });

                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case "déffirent de":
                    var resultDef = query.Where(s =>
                    {
                        var value = SelectedProeprty.GetValue(s, null);
                        if (value == null)
                        {
                            return(false);
                        }
                        return(!(value.ToString() == (Valeur)));
                    });
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;


                default:
                    break;
                }
            }
        }
コード例 #2
0
        public void FilterData()
        {
            if (SelectedProeprty == null)
            {
                DataHelpers.ShowMessage(_("Données Insuffisantes"));
                return;
            }

            if (ConditionsSelected == null)
            {
                DataHelpers.ShowMessage(_("Vérifier les conditions"));
                return;
            }
            if (string.IsNullOrEmpty(Valeur))
            {
                Valeur = " ";
                //DataHelpers.ShowMessage("Vérifier les valeurs");
                //return;
            }

            var query = Inputs;

            //var query = new List<IDocument>();
            //query =   ((System.Collections.Generic.List<IDocument>) Inputs) ;
            if (GetTypeName(SelectedProeprty.PropertyType) == "DateTime")
            {
                var _Valeur = DateTime.Parse(Valeur);
                switch (ConditionsSelected.Value)
                {
                case EnumConditions.egale:
                    var result = query.Where(a => (SelectedProeprty.GetValue(a, null) as DateTime?)?.Date == (_Valeur.Date));
                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case EnumConditions.ressemble:
                    var resultRes = query.Where(a => (SelectedProeprty.GetValue(a, null) as DateTime?)?.Date == (_Valeur.Date));
                    Result = resultRes.ToList();
                    Inputs = Result;

                    break;

                case EnumConditions.déffirent:
                    var resultDef = query.Where(a => !((SelectedProeprty.GetValue(a, null) as DateTime?)?.Date == _Valeur.Date));
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;

                case EnumConditions.inférieur:
                    var resultInf = query.Where(a => (SelectedProeprty.GetValue(a, null) as DateTime?)?.Ticks <= (_Valeur.Ticks));
                    Result = resultInf.ToList();
                    Inputs = Result;
                    break;

                case EnumConditions.supérieur:
                    var resultSup = query.Where(a => (SelectedProeprty.GetValue(a, null) as DateTime?)?.Ticks >= (_Valeur.Ticks));
                    Result = resultSup.ToList();
                    Inputs = Result;
                    break;

                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "Int32")
            {
                var _Valeur = int.Parse(Valeur);
                switch (ConditionsSelected.Value)
                {
                case EnumConditions.ressemble:
                    try
                    {
                        var resultd = query.Where(a => SelectedProeprty.GetValue(a, null).ToString().Contains(Valeur));
                        Result = resultd.ToList();
                        Inputs = Result;
                    }
                    catch
                    { }


                    break;

                case EnumConditions.egale:
                    var result = query.Where(a => (int?)SelectedProeprty.GetValue(a, null) == (_Valeur));
                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case EnumConditions.déffirent:
                    var resultDef = query.Where(a => (int?)SelectedProeprty.GetValue(a, null) != _Valeur);
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;

                case EnumConditions.inférieur:
                    var resultInf = query.Where(a => (int?)SelectedProeprty.GetValue(a, null) <= (_Valeur));
                    Result = resultInf.ToList();
                    Inputs = Result;
                    break;

                case EnumConditions.supérieur:
                    var resultSup = query.Where(a => (int?)SelectedProeprty.GetValue(a, null) >= (_Valeur));
                    Result = resultSup.ToList();
                    Inputs = Result;
                    break;

                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "Decimal")
            {
                var _Valeur = decimal.Parse(Valeur);
                switch (ConditionsSelected.Value)
                {
                case EnumConditions.ressemble:
                    try
                    {
                        var resultd = query.Where(a => SelectedProeprty.GetValue(a, null)?.ToString()?.Contains(Valeur) == true);
                        Result = resultd.ToList();
                        Inputs = Result;
                    }
                    catch
                    { }

                    break;

                case EnumConditions.egale:
                    var result = query.Where(a => (decimal?)SelectedProeprty.GetValue(a, null) == (_Valeur));
                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case EnumConditions.déffirent:
                    var resultDef = query.Where(a => (decimal?)SelectedProeprty.GetValue(a, null) != _Valeur);
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;

                case EnumConditions.inférieur:
                    var resultInf = query.Where(a => (decimal?)SelectedProeprty.GetValue(a, null) <= (_Valeur));
                    Result = resultInf.ToList();
                    Inputs = Result;
                    break;

                case EnumConditions.supérieur:
                    var resultSup = query.Where(a => (decimal?)SelectedProeprty.GetValue(a, null) >= (_Valeur));
                    Result = resultSup.ToList();
                    Inputs = Result;
                    break;

                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "Double")
            {
                var _Valeur = double.Parse(Valeur);
                switch (ConditionsSelected.Value)
                {
                case EnumConditions.ressemble:
                    try
                    {
                        var resultd = query.Where(a => SelectedProeprty.GetValue(a, null).ToString().Contains(Valeur));
                        Result = resultd.ToList();
                        Inputs = Result;
                    }
                    catch
                    { }
                    break;

                case EnumConditions.egale:
                    var result = query.Where(a => (double?)SelectedProeprty.GetValue(a, null) == (_Valeur));
                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case EnumConditions.déffirent:
                    var resultDef = query.Where(a => (double?)SelectedProeprty.GetValue(a, null) != _Valeur);
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;

                case EnumConditions.inférieur:
                    var resultInf = query.Where(a => (double?)SelectedProeprty.GetValue(a, null) <= (_Valeur));
                    Result = resultInf.ToList();
                    Inputs = Result;
                    break;

                case EnumConditions.supérieur:
                    var resultSup = query.Where(a => (double?)SelectedProeprty.GetValue(a, null) >= (_Valeur));
                    Result = resultSup.ToList();
                    Inputs = Result;
                    break;

                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "String")
            {
                switch (ConditionsSelected.Value)
                {
                case EnumConditions.ressemble:
                    try
                    {
                        var results = query.Where(s =>
                        {
                            var value = SelectedProeprty.GetValue(s, null);
                            if (value == null)
                            {
                                return(false);
                            }
                            return(value.ToString().ToLower().Contains(Valeur.ToLower()));
                        });


                        Result = results.ToList();
                        Inputs = Result;
                    }
                    catch
                    { }

                    break;

                case EnumConditions.egale:
                    var result = query.Where(s =>
                    {
                        var value = SelectedProeprty.GetValue(s, null);
                        if (value == null)
                        {
                            return(false);
                        }
                        return(value.ToString() == (Valeur));
                    });

                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case EnumConditions.déffirent:
                    var resultDef = query.Where(s =>
                    {
                        var value = SelectedProeprty.GetValue(s, null);
                        if (value == null)
                        {
                            return(false);
                        }
                        return(!(value.ToString() == (Valeur)));
                    });
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;


                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "Guid")
            {
                var attributes = SelectedProeprty.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute;
                var option     = attributes.Options;
                var link       = DS.Generic(option)?.Find("Name", Valeur, true)?.FirstOrDefault();
                if (link == null && ConditionsSelected.Value != EnumConditions.ressemble)
                {
                    return;
                }
                switch (ConditionsSelected.Value)
                {
                case EnumConditions.egale:
                    var result = query.Where(a => SelectedProeprty.GetValue(a, null).ToString().Equals(link.Id.ToString()));
                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case EnumConditions.ressemble:
                    var resultRes = query.Where(a => SelectedProeprty.GetValue(a, null).ToString().Equals(link.Id.ToString()));
                    Result = resultRes.ToList();
                    Inputs = Result;

                    break;

                case EnumConditions.déffirent:
                    var resultDef = query.Where(a => !SelectedProeprty.GetValue(a, null).ToString().Contains(link.Id.ToString()));
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;


                default:
                    break;
                }
            }
            if (GetTypeName(SelectedProeprty.PropertyType) == "Boolean")
            {
                switch (ConditionsSelected.Value)
                {
                case EnumConditions.ressemble:
                    try
                    {
                        var results = query.Where(s =>
                        {
                            var value = SelectedProeprty.GetValue(s, null);
                            if (value == null)
                            {
                                return(false);
                            }
                            return(value.ToString().Contains(Valeur));
                        });


                        Result = results.ToList();
                        Inputs = Result;
                    }
                    catch
                    { }

                    break;

                case EnumConditions.egale:
                    var result = query.Where(s =>
                    {
                        var value = SelectedProeprty.GetValue(s, null);
                        if (value == null)
                        {
                            return(false);
                        }
                        return(value.ToString() == (Valeur));
                    });

                    Result = result.ToList();
                    Inputs = Result;

                    break;

                case EnumConditions.déffirent:
                    var resultDef = query.Where(s =>
                    {
                        var value = SelectedProeprty.GetValue(s, null);
                        if (value == null)
                        {
                            return(false);
                        }
                        return(!(value.ToString() == (Valeur)));
                    });
                    Result = resultDef.ToList();
                    Inputs = Result;
                    break;


                default:
                    break;
                }
            }
        }