Esempio n. 1
0
        /// <summary>
        /// 查询记账信息
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="startTime">记账开始时间</param>
        /// <param name="endTime">记账结束时间</param>
        /// <param name="flowTypeID">资金类型ID</param>
        /// <param name="feeitemID">费用科目类型ID</param>
        /// <returns></returns>
        public JsonResult GetApplyMainList(int userID, DateTime?startTime, DateTime?endTime, int flowTypeID = 0, int feeitemID = 0)
        {
            Thread.Sleep(500);
            LycJsonResult lycResult = new LycJsonResult();

            try
            {
                using (FDB = new FamilyCaiWuDBEntities())
                {
                    IQueryable <Apply_Main> qam = FDB.Apply_Main.Where(c => c.ApplyUserID == userID);
                    //筛选日期
                    if (startTime != null && endTime == null)
                    {
                        qam = qam.Where(c => c.ApplyDate >= startTime.Value);
                    }
                    else if (startTime == null && endTime != null)
                    {
                        qam = qam.Where(c => c.ApplyDate <= endTime.Value);
                    }
                    else if (startTime != null && endTime != null)
                    {
                        qam = qam.Where(c => c.ApplyDate >= startTime.Value && c.ApplyDate <= endTime.Value);
                    }

                    var result = qam.Select(c => new
                    {
                        ApplyMainID    = c.ID,
                        ApplyUserID    = c.ApplyUserID,
                        ApplyDate      = "",
                        ApplyDate_date = c.ApplyDate,
                        ApplyInMoney   = c.ApplyInMoney,
                        ApplyOutMoney  = c.ApplyOutMoney,
                        iyear          = c.iyear,
                        imonth         = c.imonth,
                        iday           = c.iday,
                        iNowCashMoney  = c.iNowCashMoney.Value
                    }).ToList();

                    List <QueryApplyMainModel> list = new List <QueryApplyMainModel>();
                    for (int i = 0; i < result.Count; i++)
                    {
                        QueryApplyMainModel am = new QueryApplyMainModel();
                        var c = result[i];
                        am.ApplyMainID   = c.ApplyMainID;
                        am.ApplyUserID   = c.ApplyUserID;
                        am.ApplyDate     = c.ApplyDate_date.ToString("yyyy-MM-dd");
                        am.ApplyInMoney  = c.ApplyInMoney.ToString();
                        am.ApplyOutMoney = c.ApplyOutMoney.ToString();
                        am.iyear         = c.iyear;
                        am.imonth        = c.imonth;
                        am.iday          = c.iday;
                        am.iNowCashMoney = c.iNowCashMoney.ToString();
                        list.Add(am);
                    }
                    var totalObj = new { totalIn = result.Sum(c => c.ApplyInMoney).ToString(), totalOut = result.Sum(c => c.ApplyOutMoney).ToString() };
                    var jsonObj  = new { totalObj = totalObj, info = list };
                    lycResult.Data = new JsonResultModel(true, "账单查询成功", jsonObj);
                }
            }
            catch
            {
                lycResult.Data = new JsonResultModel(false, "账单查询失败", null);
            }
            return(lycResult);
        }
        /// <summary>
        /// 查询记账信息
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="startTime">记账开始时间</param>
        /// <param name="endTime">记账结束时间</param>
        /// <param name="flowTypeID">资金类型ID</param>
        /// <param name="feeitemID">费用科目类型ID</param>
        /// <returns></returns>
        public JsonResult GetApplyMainList(int userID, DateTime? startTime, DateTime? endTime, int flowTypeID = 0, int feeitemID = 0)
        {
            Thread.Sleep(500);
            LycJsonResult lycResult = new LycJsonResult();
            try
            {
                using (FDB = new FamilyCaiWuDBEntities())
                {
                    IQueryable<Apply_Main> qam = FDB.Apply_Main.Where(c => c.ApplyUserID == userID);
                    //筛选日期
                    if (startTime != null && endTime == null)
                    {
                        qam = qam.Where(c => c.ApplyDate >= startTime.Value);
                    }
                    else if (startTime == null && endTime != null)
                    {
                        qam = qam.Where(c => c.ApplyDate <= endTime.Value);
                    }
                    else if (startTime != null && endTime != null)
                    {
                        qam = qam.Where(c => c.ApplyDate >= startTime.Value && c.ApplyDate <= endTime.Value);
                    }

                    var result = qam.Select(c => new
                    {
                        ApplyMainID = c.ID,
                        ApplyUserID = c.ApplyUserID,
                        ApplyDate = "",
                        ApplyDate_date = c.ApplyDate,
                        ApplyInMoney = c.ApplyInMoney,
                        ApplyOutMoney = c.ApplyOutMoney,
                        iyear = c.iyear,
                        imonth = c.imonth,
                        iday = c.iday,
                        iNowCashMoney = c.iNowCashMoney.Value
                    }).ToList();

                    List<QueryApplyMainModel> list = new List<QueryApplyMainModel>();
                    for (int i = 0; i < result.Count; i++)
                    {
                        QueryApplyMainModel am = new QueryApplyMainModel();
                        var c = result[i];
                        am.ApplyMainID = c.ApplyMainID;
                        am.ApplyUserID = c.ApplyUserID;
                        am.ApplyDate = c.ApplyDate_date.ToString("yyyy-MM-dd");
                        am.ApplyInMoney = c.ApplyInMoney.ToString();
                        am.ApplyOutMoney = c.ApplyOutMoney.ToString();
                        am.iyear = c.iyear;
                        am.imonth = c.imonth;
                        am.iday = c.iday;
                        am.iNowCashMoney = c.iNowCashMoney.ToString();
                        list.Add(am);
                    }
                    var totalObj = new {totalIn = result.Sum(c=>c.ApplyInMoney).ToString(), totalOut = result.Sum(c=>c.ApplyOutMoney).ToString()};
                    var jsonObj = new { totalObj = totalObj , info = list};
                    lycResult.Data = new JsonResultModel(true, "账单查询成功", jsonObj);
                }
            }
            catch
            {
                lycResult.Data = new JsonResultModel(false, "账单查询失败", null);
            }
            return lycResult;
        }