예제 #1
0
        /// <summary>
        /// 生成数据json
        /// </summary>
        /// <param name="strFmter">格式字符串</param>
        /// <param name="cfg">配置</param>
        /// <param name="val">递延值</param>
        /// <returns></returns>
        private string GenJson_PL(string strFmter, KeyValuePair <int, List <int> > cfg, ref decimal val)
        {
            T_ReportDetails curRec  = new T_ReportDetails();
            StringBuilder   strJson = new StringBuilder("[ ");

            foreach (int item in cfg.Value)
            {
                if (Details.Any(i => i.Code.Equals(item.ToString())))
                {
                    curRec = Details.First(i => i.Code.Equals(item.ToString()));
                    strJson.AppendFormat(strFmter, curRec.Name, "[]", curRec.EndingValue, curRec.Code);
                    val += curRec.EndingValue;
                }
            }
            strJson.Remove(strJson.Length - 1, 1);
            strJson.Append("]");
            return(strJson.ToString());
        }
예제 #2
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public string GetDetailsJSON_PL()
        {
            StringBuilder   strJson = new StringBuilder("[");
            T_ReportDetails curRec  = new T_ReportDetails();
            Dictionary <int, List <int> > config = new Dictionary <int, List <int> >();

            config.Add(6001, new List <int>()
            {
                6401, 6403
            });
            config.Add(1, new List <int>()
            {
                6051, 6402, 6601, 6602, 6603
            });
            config.Add(2, new List <int>());
            config.Add(3, new List <int>()
            {
                6801
            });
            config.Add(4, new List <int>());

            string strRowFmt = "{{\"Acc_Name\":\"{0}\",\"children\":{1},\"Money\":{2},\"Acc_Code\":\"{3}\"}},";

            if (Details.Any(i => i.Code.Equals("6001")))
            {
                decimal curVal = 0;
                decimal rtVal  = 0;
                foreach (KeyValuePair <int, List <int> > kvPair in config)
                {
                    switch (kvPair.Key)
                    {
                    case 6001:
                        curRec = Details.First(i => i.Code.Equals("6001"));
                        curVal = curRec.EndingValue;
                        strJson.AppendFormat(strRowFmt, curRec.Name, GenJson_PL(strRowFmt, kvPair, ref curVal), curRec.EndingValue, curRec.Code);
                        break;

                    case 1:
                        rtVal = curVal;
                        strJson.AppendFormat(strRowFmt, "主营业务利润", GenJson_PL(strRowFmt, kvPair, ref curVal), rtVal, "1");
                        break;

                    case 2:
                        rtVal = curVal;
                        strJson.AppendFormat(strRowFmt, "营业利润", GenJson_PL(strRowFmt, ref curVal), rtVal, "2");
                        break;

                    case 3:
                        rtVal = curVal;
                        strJson.AppendFormat(strRowFmt, "利润总额", GenJson_PL(strRowFmt, kvPair, ref curVal), rtVal, "3");
                        break;

                    case 4:
                        rtVal = curVal;
                        strJson.AppendFormat(strRowFmt, "净利润", GenJson_PL(strRowFmt, kvPair, ref curVal), rtVal, "4");
                        break;

                    default:
                        break;
                    }
                }
                strJson.Remove(strJson.Length - 1, 1);
                strJson.Append("]");
                return(strJson.ToString());
            }
            else
            {
                return("[]");
            }
        }