private void recordsLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            using (TenderContext tc = new TenderContext())
            {
                FilterArgument selectedEstimate = e.Argument as FilterArgument;

                var result = (from rec in tc.TenderPlanRecords.ToList()
                              where ((rec.EstimateId == selectedEstimate.Estimate.Id) && !rec.IsTenderComplete)
                              orderby rec.Dk.Code ascending
                              select new TPEntry
                {
                    Kekv = (selectedEstimate.IsNewSystem) ? rec.PrimaryKekv : rec.SecondaryKekv,
                    Dk = rec.Dk,
                    PlannedMoney = rec.PlannedSum,
                    MoneyRemain = rec.AvailableForContractsMoney,
                    Commentary = rec.CodeRepeatReason,
                    Record = rec
                } into s1
                              where s1.MoneyRemain > 0
                              select s1);

                if (selectedEstimate.Kekv.Id < 0)
                {
                    recordsList = new BindingList <TPEntry>(result.ToList());
                }
                else
                {
                    recordsList = new BindingList <TPEntry>(result.Where(p => p.Kekv.Id == selectedEstimate.Kekv.Id).ToList());
                }
            }
        }
Example #2
0
        /// <summary>
        /// Adds the given filter arguments as a new filter, which is ANDed together with
        /// other filters by default.
        /// </summary>
        public void AddFilter(FilterOperator op, params FilterArgument[] arguments)
        {
            EnsureFilterExists();
            Filter filter = Raw.Filter;

            if (filter.Args == null)
            {
                filter.Args = new ObservableCollection <FilterArgument>();
            }

            var wrapper = new FilterArgument
            {
                Type = FilterArgumentType.Filter
            };

            var inner = new Filter
            {
                Operator = op,
                Args     = new ObservableCollection <FilterArgument>()
            };

            foreach (var arg in arguments)
            {
                inner.Args.Add(arg);
            }

            wrapper.Value = inner;
            filter.Args.Add(wrapper);
        }
Example #3
0
        /// <summary>
        /// Filter
        /// </summary>
        ///
        public static IQueryable <RollBackDistributionCompanyInfo> SelectFilter(FilterArgument fArgument, string orderBy, int startRowIndex, int maximumRows)
        {
            if (startRowIndex == -1)
            {
                return(null);
            }

            return(SelectDynamicFilter(fArgument, orderBy).Skip(startRowIndex).Take(maximumRows));
        }
Example #4
0
        private static string getTarget(FilterAction filterAction)
        {
            FilterArgument farg = filterAction.getArgument("target");

            if (farg != null)
            {
                return(farg.Value);
            }
            return(string.Empty);
        }
Example #5
0
        private static string getSelector(FilterAction filterAction)
        {
            FilterArgument farg = filterAction.getArgument("selector");

            if (farg != null)
            {
                return(farg.Value);
            }
            return(string.Empty);
        }
 private void LoadRecords()
 {
     if (!recordsLoader.IsBusy)
     {
         FilterArgument arg = new FilterArgument();
         arg.IsNewSystem = tpNewSystemRButton.Checked;
         arg.Kekv        = tpKekvsCBList.SelectedItem as KekvCode;
         arg.Estimate    = tpEstimateCBList.SelectedItem as Estimate;
         recordsLoader.RunWorkerAsync(arg);
         ToggleLoadingAnimation();
     }
 }
Example #7
0
        public Statement Parse(ParseTreeNode node, ParserContext context)
        {
            var nodes     = node.ChildNodes[0].ChildNodes;
            var arguments = new FilterArgument[nodes.Count];

            for (var i = 0; i < nodes.Count; i++)
            {
                arguments[i] = DefaultFluidParser.BuildFilterArgument(nodes[i]);
            }

            return(new DelegateStatement((writer, encoder, ctx) => WriteToAsync(writer, encoder, ctx, arguments)));
        }
Example #8
0
        public static int SelectFilterCountCached(FilterArgument fArgument)
        {
            string key   = GetCacheKey("Count") + fArgument.PropertyField + fArgument.Comparator + fArgument.FValue.ToString();
            int?   count = (int?)HttpContext.Current.Cache[key];

            if (count == null)
            {
                count = SelectFilterCount(fArgument);
                AddCache(key, count);
            }
            return(count.Value);
        }
        private object ProcessFilterArgument(FilterArgument filterArgument)
        {
            switch (filterArgument.DataType)
            {
            case "Edm.Binary":
                throw new NotImplementedException(string.Format("ProcessFilterArgument can't process the {0} data type", filterArgument.DataType));

            case "Edm.Boolean":
                return(Convert.ToBoolean(filterArgument.DataValue));

            case "Edm.Byte":
                return(Convert.ToByte(filterArgument.DataValue));

            case "Edm.DateTime":
                return(DateTime.Parse(filterArgument.DataValue));

            case "Edm.DateTimeOffset":
                throw new NotImplementedException(string.Format("ProcessFilterArgument can't process the {0} data type", filterArgument.DataType));

            case "Edm.Decimal":
                return(Convert.ToDecimal(filterArgument.DataValue));

            case "Edm.Double":
                return(Convert.ToDouble(filterArgument.DataValue));

            case "Edm.Guid":
                return(Guid.Parse(filterArgument.DataValue));

            case "Edm.Int16":
                return(Convert.ToInt16(filterArgument.DataValue));

            case "Edm.Int32":
                return(Convert.ToInt32(filterArgument.DataValue));

            case "Edm.Int64":
                return(Convert.ToInt64(filterArgument.DataValue));

            case "Edm.SByte":
                return(Convert.ToSByte(filterArgument.DataValue));

            case "Edm.Single":
                return(Convert.ToSingle(filterArgument.DataValue));

            case "Edm.String":
                return(filterArgument.DataValue);

            case "Edm.Time":
                throw new NotImplementedException(string.Format("ProcessFilterArgument can't process the {0} data type", filterArgument.DataType));

            default:
                throw new NotImplementedException(string.Format("ProcessFilterArgument can't process the {0} data type", filterArgument.DataType));
            }
        }
Example #10
0
        public override Statement Parse(ParseTreeNode node, ParserContext context)
        {
            var e         = context.CurrentBlock.Tag.ChildNodes[0];
            var arguments = new FilterArgument[e.ChildNodes.Count];

            for (var i = 0; i < e.ChildNodes.Count; i++)
            {
                arguments[i] = DefaultFluidParser.BuildFilterArgument(e.ChildNodes[i]);
            }

            var statements = context.CurrentBlock.Statements;

            return(new DelegateStatement((writer, encoder, ctx) => WriteToAsync(writer, encoder, ctx, arguments, statements)));
        }
Example #11
0
        public static FilterArgument[] BuildArguments(ParseTreeNode node)
        {
            var arguments = node.ChildNodes[0].ChildNodes.Select(DefaultFluidParser.BuildFilterArgument).ToArray();

            var defaultArgument = node.ChildNodes[0].ChildNodes[0].ChildNodes[0];

            if (defaultArgument.Term.Name != "identifier")
            {
                if (DefaultArguments.TryGetValue(node.Term.Name, out var name))
                {
                    arguments[0] = new FilterArgument(name, DefaultFluidParser.BuildTermExpression(defaultArgument));
                }
            }

            return(arguments);
        }
Example #12
0
        public static async ValueTask <Completion> WriteToAsync(string identifier, List <FilterArgument> arguments, IReadOnlyList <Statement> statements, TextWriter writer, TextEncoder encoder, TemplateContext context)
        {
            var services = ((LiquidTemplateContext)context).Services;

            var viewContextAccessor = services.GetRequiredService <ViewContextAccessor>();
            var viewContext         = viewContextAccessor.ViewContext;

            // If no identifier is set, use the first argument as the name of the tag helper
            // e.g., {% helper "input", for: "Text", class: "form-control" %}

            identifier ??= (await arguments[0].Expression.EvaluateAsync(context)).ToStringValue();

            // These mapping will assign an argument name to the first element in the filter arguments,
            // such that the tag helper can be matched based on the expected attribute names.
            if (DefaultArgumentsMapping.TryGetValue(identifier, out var mapping))
            {
                arguments    = new List <FilterArgument>(arguments);
                arguments[0] = new FilterArgument(mapping, arguments[0].Expression);
            }

            var filterArguments = new FilterArguments();

            foreach (var argument in arguments)
            {
                filterArguments.Add(argument.Name, await argument.Expression.EvaluateAsync(context));
            }

            var factory   = services.GetRequiredService <LiquidTagHelperFactory>();
            var activator = factory.GetActivator(identifier, filterArguments.Names);

            if (activator == LiquidTagHelperActivator.None)
            {
                return(Completion.Normal);
            }

            var tagHelper = factory.CreateTagHelper(activator, viewContext,
                                                    filterArguments, out var contextAttributes, out var outputAttributes);

            ViewBufferTextWriterContent content = null;

            if (statements != null && statements.Count > 0)
            {
                content = new ViewBufferTextWriterContent();

                var completion = await statements.RenderStatementsAsync(content, encoder, context);

                if (completion != Completion.Normal)
                {
                    return(completion);
                }
            }

            Interlocked.CompareExchange(ref _uniqueId, long.MaxValue, 0);
            var id = Interlocked.Increment(ref _uniqueId);

            var tagHelperContext = new TagHelperContext(contextAttributes, new Dictionary <object, object>(), id.ToString());

            TagHelperOutput tagHelperOutput = null;

            if (content != null)
            {
                tagHelperOutput = new TagHelperOutput(
                    identifier,
                    outputAttributes, (_, e) => Task.FromResult(new DefaultTagHelperContent().AppendHtml(content))
                    );
            }
            else
            {
                tagHelperOutput = new TagHelperOutput(
                    identifier,
                    outputAttributes, (_, e) => Task.FromResult <TagHelperContent>(new DefaultTagHelperContent())
                    );
            }

            await tagHelper.ProcessAsync(tagHelperContext, tagHelperOutput);

            return(Completion.Normal);
        }
Example #13
0
        public static int SelectFilterCount(FilterArgument fArgument)
        {
            string orderBy = "";

            return(SelectDynamicFilter(fArgument, orderBy).Count());
        }
Example #14
0
        private static IQueryable <RollBackDistributionCompanyInfo> SelectDynamicFilter(FilterArgument fArgument, string orderBy)
        {
            string       propertyName = fArgument.PropertyField;
            string       comparator   = fArgument.Comparator;
            object       value        = fArgument.FValue;
            PropertyInfo prop         = typeof(RollBackDistributionCompanyInfo).GetProperty(propertyName);
            Type         myType;
            bool         nullable = false;

            if (IsNullableType(prop.PropertyType))
            {
                NullableConverter nc = new NullableConverter(prop.PropertyType);
                myType   = nc.UnderlyingType;
                nullable = true;
            }
            else
            {
                myType = prop.PropertyType;
            }

            if (!nullable)
            {
                switch (Type.GetTypeCode(myType))
                {
                case TypeCode.Boolean:
                    return(GetDynamicFilterResults <bool>(propertyName, comparator, Convert.ToBoolean(value), orderBy, myType));

                case TypeCode.Byte:
                    return(GetDynamicFilterResults <byte>(propertyName, comparator, Convert.ToByte(value), orderBy, myType));

                case TypeCode.Char:
                    return(GetDynamicFilterResults <char>(propertyName, comparator, Convert.ToChar(value), orderBy, myType));

                case TypeCode.DateTime:
                    return(GetDynamicFilterResults <DateTime>(propertyName, comparator, Convert.ToDateTime(value), orderBy, myType));

                case TypeCode.Decimal:
                    return(GetDynamicFilterResults <Decimal>(propertyName, comparator, Convert.ToDecimal(value), orderBy, myType));

                case TypeCode.Double:
                    return(GetDynamicFilterResults <double>(propertyName, comparator, Convert.ToDouble(value), orderBy, myType));

                case TypeCode.Int16:
                    return(GetDynamicFilterResults <Int16>(propertyName, comparator, Convert.ToInt16(value), orderBy, myType));

                case TypeCode.Int32:
                    return(GetDynamicFilterResults <Int32>(propertyName, comparator, Convert.ToInt32(value), orderBy, myType));

                case TypeCode.Int64:
                    return(GetDynamicFilterResults <Int64>(propertyName, comparator, Convert.ToInt64(value), orderBy, myType));

                case TypeCode.Single:
                    return(GetDynamicFilterResults <Single>(propertyName, comparator, Convert.ToSingle(value), orderBy, myType));

                case TypeCode.String:
                    return(GetDynamicFilterResults <String>(propertyName, comparator, Convert.ToString(value), orderBy, myType));

                default:
                    throw new Exception("Cannot filter by column " + propertyName + " because of its type");
                }
            }
            else
            {
                switch (Type.GetTypeCode(myType))
                {
                case TypeCode.Boolean:
                    return(GetDynamicFilterResults <System.Nullable <bool> >(propertyName, comparator, Convert.ToBoolean(value), orderBy, myType));

                case TypeCode.Byte:
                    return(GetDynamicFilterResults <System.Nullable <byte> >(propertyName, comparator, Convert.ToByte(value), orderBy, myType));

                case TypeCode.Char:
                    return(GetDynamicFilterResults <System.Nullable <char> >(propertyName, comparator, Convert.ToChar(value), orderBy, myType));

                case TypeCode.DateTime:
                    return(GetDynamicFilterResults <System.Nullable <DateTime> >(propertyName, comparator, Convert.ToDateTime(value), orderBy, myType));

                case TypeCode.Decimal:
                    return(GetDynamicFilterResults <System.Nullable <Decimal> >(propertyName, comparator, Convert.ToDecimal(value), orderBy, myType));

                case TypeCode.Double:
                    return(GetDynamicFilterResults <System.Nullable <double> >(propertyName, comparator, Convert.ToDouble(value), orderBy, myType));

                case TypeCode.Int16:
                    return(GetDynamicFilterResults <System.Nullable <Int16> >(propertyName, comparator, Convert.ToInt16(value), orderBy, myType));

                case TypeCode.Int32:
                    return(GetDynamicFilterResults <System.Nullable <Int32> >(propertyName, comparator, Convert.ToInt32(value), orderBy, myType));

                case TypeCode.Int64:
                    return(GetDynamicFilterResults <System.Nullable <Int64> >(propertyName, comparator, Convert.ToInt64(value), orderBy, myType));

                case TypeCode.Single:
                    return(GetDynamicFilterResults <System.Nullable <Single> >(propertyName, comparator, Convert.ToSingle(value), orderBy, myType));

                case TypeCode.String:
                    return(GetDynamicFilterResults <String>(propertyName, comparator, Convert.ToString(value), orderBy, myType));

                default:
                    throw new Exception("Cannot filter by column " + propertyName + " because of its type");
                }
            }
        }
Example #15
0
        /// <summary>
        /// Filter
        /// </summary>
        ///

        public static IQueryable <RollBackDistributionCompanyInfo> SelectDynamicFilterByFK(string foreignKeyName, int id, FilterArgument fArgument, string orderBy)
        {
            ParameterExpression e        = Expression.Parameter(typeof(RollBackDistributionCompanyInfo), "e");
            PropertyInfo        propInfo = typeof(RollBackDistributionCompanyInfo).GetProperty(foreignKeyName);
            MemberExpression    m        = Expression.MakeMemberAccess(e, propInfo);
            ConstantExpression  c        = Expression.Constant(id, typeof(int));
            BinaryExpression    b        = Expression.Equal(m, c);
            Expression <Func <RollBackDistributionCompanyInfo, bool> > lambda = Expression.Lambda <Func <RollBackDistributionCompanyInfo, bool> >(b, e);

            return(SelectDynamicFilter(fArgument, orderBy).Where(lambda));
        }