コード例 #1
0
        public Dictionary <string, string> Calc(Dictionary <string, string> template)
        {
            SystemProfileService systemProfile = SystemProfileService.GetInstance(mContext);
            var curYear   = systemProfile.GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentYear);
            var curPeriod = systemProfile.GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentPeriod);

            AccountBalanceService abService = AccountBalanceService.GetInstance(mContext);

            m_lstYear   = abService.QueryOccurs(curYear, 1, curYear, 12);
            m_lstOccurs = abService.QueryOccurs(curYear, curPeriod, curYear, curPeriod);
            m_lstAso    = DataManager.GetInstance(mContext).Query <AccountSubject>(null).OrderBy(a => a.no).ToList();

            Dictionary <string, string> result = new Dictionary <string, string>();
            List <string> sumKeys = new List <string>();

            foreach (KeyValuePair <string, string> kv in template)
            {
                if (Regex.IsMatch(kv.Value, "(L)") && !Regex.IsMatch(kv.Value, "(SL)"))
                {
                    sumKeys.Add(kv.Key);
                    continue;
                }
                result.Add(kv.Key, Calc(kv.Value));
            }

            sumKeys.Sort();
            foreach (string key in sumKeys)
            {
                result.Add(key, SampleCalculator.sumLine(template[key], key, result));
            }

            return(result);
        }
コード例 #2
0
        //'=L4+L5+L6+L7
        bool CalcSum(int lineNo, Dictionary <int, CalTempObj> dict, out decimal amount)
        {
            var result = false;

            amount = 0;
            if (!dict.ContainsKey(lineNo))
            {
                logger.Debug("dict don't have key:{0}", lineNo);
                return(result);
            }

            var           expression = dict[lineNo].templateItem.c;
            List <string> lstParams  = CommonUtils.MatchPattern(expression, @"L([0-9]+)");
            List <string> lstOpratio = CommonUtils.MatchPattern(expression, "(\\+|\\-|\\*|/)");
            var           size       = lstParams.Count;

            if (size == 0)
            {
                return(result);
            }

            if (lstOpratio.Count + 1 != size)
            {
                logger.Error("error expression:" + expression);
                return(result);
            }

            result = size > 0;

            for (int i = 0; i < size; i++)
            {
                var rowStr = lstParams[i].Substring(1);
                var row    = 0;
                if (int.TryParse(rowStr, out row))
                {
                    if (!dict.ContainsKey(row))
                    {
                        logger.Debug("dict don't have key:{0}", row);
                        continue;
                    }
                    var tmp = dict[row].originAmount;
                    if (i > 0)
                    {
                        amount = SampleCalculator.CalcOpration(amount, lstOpratio[i - 1], tmp);
                    }
                    else
                    {
                        amount = tmp;
                    }
                }
            }
            logger.Debug("calcSum : [{0}]{1}{2}", lineNo, amount, expression);
            return(result);
        }
コード例 #3
0
        //'=SY("6301")-SY("1221")
        decimal CalcFormula(int lineNo, string formula)
        {
            if (string.IsNullOrEmpty(formula))
            {
                return(0);
            }
            if (!formula.StartsWith("="))
            {
                return(0);
            }

            List <string> lstMethod = CommonUtils.MatchPattern(formula, "(SY|C|SJY|SL)");

            if (lstMethod.Count == 0)
            {
                return(0);
            }

            List <string> lstParams  = CommonUtils.MatchPattern(formula, "(?<=\")[^\"^(^)]*(?=\")");
            List <string> lstOpratio = CommonUtils.MatchPattern(formula, "(\\+|\\-|\\*|/)");

            if (lstMethod.Count != lstParams.Count)
            {
                throw new FinanceException(FinanceResult.IMPERFECT_DATA, "公式错误");
            }

            decimal result = 0M;

            for (int i = 0; i < lstMethod.Count; i++)
            {
                var param = lstParams[i];
                var ids   = SampleCalculator.GetAccountSubjectIds(m_lstAso, param);
                if (ids.Count == 0)
                {
                    continue;
                }
                var method = lstMethod[i];
                var amount = CalcMethod(method, ids);
                if (i > 0)
                {
                    result = SampleCalculator.CalcOpration(result, lstOpratio[i - 1], amount);
                }
                else
                {
                    result = amount;
                }
            }

            logger.Debug("CalcFormula : [{0}]{1}{2}", lineNo, result, formula);
            return(result);
        }
コード例 #4
0
        string Calc(string formula)
        {
            if (string.IsNullOrEmpty(formula))
            {
                return("");
            }
            if (!formula.StartsWith("="))
            {
                return(formula);
            }

            List <string> lstMethod  = CommonUtils.MatchPattern(formula, "(Y|C|JY|DC|DY)");
            List <string> lstParams  = CommonUtils.MatchPattern(formula, "(?<=\")[^\"^(^)]*(?=\")");
            List <string> lstOpratio = CommonUtils.MatchPattern(formula, "(\\+|\\-|\\*|/)");

            if (lstMethod.Count != lstParams.Count)
            {
                throw new FinanceException(FinanceResult.IMPERFECT_DATA, "公式错误");
            }
            if (lstMethod.Count != lstOpratio.Count + 1)
            {
                throw new FinanceException(FinanceResult.IMPERFECT_DATA, "公式错误");
            }

            decimal result = 0M;

            for (int i = 0; i < lstMethod.Count; i++)
            {
                var param = lstParams[i];
                var ids   = SampleCalculator.GetAccountSubjectIds(m_lstAso, param);
                if (ids.Count == 0)
                {
                    continue;
                }
                var method = lstMethod[i];
                var amount = CalcMethod(method, ids);
                if (i > 0)
                {
                    result = SampleCalculator.CalcOpration(result, lstOpratio[i - 1], amount);
                }
                else
                {
                    result = amount;
                }
            }
            return(result.ToString("0.00"));
        }
コード例 #5
0
        public Dictionary <string, string> Calc(IDictionary <string, object> filter, IDictionary <string, string> template)
        {
            var beginYear   = int.Parse(filter["beginYear"].ToString());
            var beginPeriod = int.Parse(filter["beginPeriod"].ToString());
            var endYear     = int.Parse(filter["endYear"].ToString());
            var endPeriod   = int.Parse(filter["endPeriod"].ToString());

            AccountBalanceService abService = AccountBalanceService.GetInstance(mContext);
            var prev = CommonUtils.CalcPrevPeriod(new PeridStrunct {
                Year = beginYear, Period = beginPeriod
            });

            m_lstBegin  = abService.QuerySettled(prev.Year, prev.Period);
            m_lstOccurs = abService.QueryOccurs(beginYear, beginPeriod, endYear, endPeriod);
            m_lstAso    = DataManager.GetInstance(mContext).Query <AccountSubject>(null).OrderBy(a => a.no).ToList();

            Dictionary <string, string> result = new Dictionary <string, string>();
            List <string> sumKeys = new List <string>();

            foreach (KeyValuePair <string, string> kv in template)
            {
                if (Regex.IsMatch(kv.Value, "(L)"))
                {
                    sumKeys.Add(kv.Key);
                    continue;
                }
                var rnt = Calc(kv.Value);
                result.Add(kv.Key, rnt);
                logger.Debug("{0} {1} {2}", kv.Key, rnt, kv.Value);
            }

            sumKeys.Sort();
            foreach (string key in sumKeys)
            {
                result.Add(key, SampleCalculator.sumLine(template[key], key, result));
            }

            return(result);
        }