コード例 #1
0
 /// <summary>
 /// 修改数据信息
 /// </summary>
 /// <typeparam name="T">数据表类型集合</typeparam>
 /// <param name="args">参数</param>
 /// <returns>影响行数</returns>
 public CustomResult Update(UpdateHdayExViewModel args)
 {
     using (DataSubmittedEntities db = new DataSubmittedEntities())
     {
         using (TransactionScope transaction = new TransactionScope())
         {
             CustomResult    pReturnValue = new CustomResult();
             int             count        = (args.EndTime.Value - args.StartTime.Value).Days + 1;
             HDayExViewModel model        = null;
             if (args.DataInfo.Count > 0)
             {
                 if (args.DataInfo[0].Num == 15)
                 {
                     model = args.DataInfo[0];
                 }
             }
             try
             {
                 for (int i = 0; i < count; i++)
                 {
                     DateTime pDateTime = args.StartTime.Value.AddDays(i);
                     var      listHDa   = db.RP_HDayAADT.Where(a => a.CalcuTime == pDateTime).ToList();
                     foreach (RP_HDayAADT hd in listHDa)
                     {
                         Type         myType = model.GetType();
                         PropertyInfo pinfo  = myType.GetProperty("Tra" + (i + 1));
                         hd.Out     = (double)pinfo.GetValue(model);
                         hd.UpdDate = DateTime.Now;
                         hd.State   = "1";
                         if (SessionManage.GetLoginUser() != null)
                         {
                             hd.UpdBy = SessionManage.GetLoginUser().UserName;
                         }
                     }
                 }
                 db.SaveChanges();
                 transaction.Complete();
                 pReturnValue.ResultKey   = (byte)EResult.Succeed;
                 pReturnValue.ResultValue = TipInfo.UpdateSuccess;
                 return(pReturnValue);
             }
             catch (Exception ex)
             {
                 Common.SystemLog.GetInstance().Log.Info(TipInfo.UpdateDataRepeat, ex);
                 pReturnValue.ResultKey   = (byte)EResult.Fail;
                 pReturnValue.ResultValue = TipInfo.UpdateDataRepeat;
                 return(pReturnValue);
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        public IReportViewModel GetListByPra(QueryParameters para)
        {
            QueryHDayExViewModel   pReturnData = new QueryHDayExViewModel();
            List <HDayExViewModel> pTList      = new List <HDayExViewModel>();
            int pDataCount = 0;

            if (para.EndTime.Value >= para.StartTime.Value)
            {
                pDataCount = (para.EndTime.Value - para.StartTime.Value).Days + 1;
            }
            //添加标头
            pReturnData.TitleList = new List <string>();
            pReturnData.TitleList.Add("序号");
            pReturnData.TitleList.Add("高速名称");
            //日期天数
            pReturnData.CountDay = pDataCount;
            for (int i = 0; i < 15; i++)
            {
                //日期
                pReturnData.TitleList.Add(para.StartTime.Value.AddDays(i).ToString("M月d日"));
            }
            pReturnData.TitleList.Add("合计");
            pReturnData.TitleList.Add("去年同期总流量");
            pReturnData.TitleList.Add("同比增幅");
            try
            {
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    HDayExViewModel pHdayExInfo = new HDayExViewModel();
                    pHdayExInfo.RoadName = SystemConst.RoadName;

                    for (int n = 0; n < pDataCount; n++)
                    {
                        DateTime?pDt = para.StartTime.Value.AddDays(n);
                        //如果所选日期数据不存在,则进行添加
                        if (db.RP_HDayAADT.Where(s => DbFunctions.TruncateTime(s.CalcuTime) == pDt).ToList().Count <= 0)
                        {
                            if (pDt <= DateTime.Now)
                            {
                                InsertNull(pDt.Value);
                            }
                        }
                        List <RP_HDayAADT> pHourAADTList = db.RP_HDayAADT.Where(s => DbFunctions.TruncateTime(s.CalcuTime) == pDt).ToList();

                        if (pHourAADTList.Count == 1)
                        {
                            //通过反射取字段名
                            Type         myType = pHdayExInfo.GetType();
                            PropertyInfo pinfo  = myType.GetProperty("Tra" + (n + 1));
                            //给字段赋值
                            double pTemp = pHourAADTList.SingleOrDefault().Out.Value;
                            pinfo.SetValue(pHdayExInfo, pTemp);
                        }
                    }
                    pHdayExInfo.Num     = 15;
                    pHdayExInfo.Sum     = db.RP_HDayAADT.Where(s => DbFunctions.TruncateTime(s.CalcuTime) >= para.StartTime.Value && DbFunctions.TruncateTime(s.CalcuTime) <= para.EndTime.Value).Sum(s => s.Out);
                    pHdayExInfo.LastSum = db.RP_HDayAADT.Where(s => DbFunctions.TruncateTime(s.CalcuTime) >= para.LastYearStart.Value && DbFunctions.TruncateTime(s.CalcuTime) <= para.LastYearEnd.Value).Sum(s => s.Out);
                    if (pHdayExInfo.Sum.HasValue && pHdayExInfo.LastSum.HasValue && pHdayExInfo.LastSum != 0 && pHdayExInfo.LastSum != 0.0)
                    {
                        pHdayExInfo.Growth = Math.Round((pHdayExInfo.Sum.Value - pHdayExInfo.LastSum.Value) / pHdayExInfo.LastSum.Value, 2);
                    }
                    pTList.Add(pHdayExInfo);
                    //添加合计
                    pTList.Add(GetSum(pHdayExInfo));
                    pReturnData.ReportData = pTList.OrderBy(s => s.Num).ToList();
                    //报表数据
                    //判断当前统计站类型,数据是否完整
                    if (GetNoDataList(para).Count() > 0)
                    {
                        pReturnData.IsFull = 0;//不完整
                    }
                    else
                    {
                        pReturnData.IsFull = 1;//完整
                    }
                }
            }
            catch (Exception ex)
            {
                SystemLog.GetInstance().Info(ex.Message);
            }
            return(pReturnData);
        }