예제 #1
0
        /// <summary>
        /// 根据StatTile获得汇总结果
        /// </summary>
        /// <param name="rowList"></param>
        /// <param name="titleFormat"></param>
        /// <returns></returns>
        public static string GetSummaryResult(Xceed.Grid.Collections.ReadOnlyDataRowList rowList, string titleFormat)
        {
            string functionName, fieldName, format, expression;
            int    level = -1;

            ExtractParameters(titleFormat, out functionName, out fieldName, out format, ref level, out expression);
            return(GetVariableFunctionResult(rowList, functionName, fieldName, format, level, expression));
        }
예제 #2
0
        /// <summary>
        /// GetVariableFunctionResult
        /// </summary>
        /// <param name="rowList"></param>
        /// <param name="functionName"></param>
        /// <param name="fieldName"></param>
        /// <param name="format"></param>
        /// <param name="level"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static string GetVariableFunctionResult(Xceed.Grid.Collections.ReadOnlyDataRowList rowList, string functionName, string fieldName,
                                                       string format, int level, string expression)
        {
            // VariableText中不能带%(默认是作为VariableText的分隔符)
            if (!string.IsNullOrEmpty(expression))
            {
                expression = expression.Replace('#', '%');
            }

            switch (functionName.ToUpper())
            {
            case "COUNT":
                int cnt = 0;
                foreach (Xceed.Grid.DataRow row in rowList)
                {
                    if (string.IsNullOrEmpty(expression))
                    {
                        cnt++;
                    }
                    else
                    {
                        object s = EntityScript.CalculateExpression(expression, row.Tag);
                        int?   r = Feng.Utils.ConvertHelper.ToInt(s);
                        if (r.HasValue)
                        {
                            cnt += r.Value;
                        }
                    }
                }
                return(cnt.ToString());

            case "SUM":
                decimal sum = 0;
                foreach (Xceed.Grid.DataRow row in rowList)
                {
                    if (string.IsNullOrEmpty(expression))
                    {
                        sum += Convert.ToDecimal(row.Cells[fieldName].Value);
                    }
                    else
                    {
                        object  s = EntityScript.CalculateExpression(expression, row.Tag);
                        decimal?r = Feng.Utils.ConvertHelper.ToDecimal(s);
                        if (r.HasValue)
                        {
                            sum += r.Value;
                        }
                    }
                }
                return(string.IsNullOrEmpty(format) ? sum.ToString("N2") : sum.ToString(format));

            case "ALLTRUE":
            {
                bool all = true;
                foreach (Xceed.Grid.DataRow row in rowList)
                {
                    if (string.IsNullOrEmpty(expression))
                    {
                    }
                    else
                    {
                        object s = EntityScript.CalculateExpression(expression, row.Tag);
                        bool?  r = Feng.Utils.ConvertHelper.ToBoolean(s);
                        if (!r.HasValue || !r.Value)
                        {
                            all = false;
                            break;
                        }
                    }
                }
                return(all ? "全" : "否");
            }
            }
            return(string.Empty);
        }