public void Update(DateTime dt, int HourPer)
        {
            try
            {
                string startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:开始获取13,14报表数据", startTime));
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    DateTime pDt = DateTime.Parse(dt.ToShortDateString());
                    //报表13,14收费站
                    List<int> BJStation = StationConfiguration.GetBJStaion();
                    //获取今年当日数据//p.VehType == 0 表示合计数据,
                    List<DS_DataSource> pCollection = db.DS_DataSource.Where(p => p.CalcuTime == dt && p.VehType == 0 && p.HourPer == HourPer && BJStation.Contains(p.StaID.Value)).ToList();

                    bool pIsHas = false;
                    //北京段数据
                    RP_HourAADT pHoursTraffic = null;
                    List<RP_HourAADT> pBJList = db.RP_HourAADT.Where(p => p.CalcuTime == pDt && p.HourPer == (byte)HourPer).ToList();
                    if (pBJList.Count > 0)
                    {
                        pHoursTraffic = pBJList.FirstOrDefault();
                        //每种状态需要重新赋值,防止公用同一个变量,值不明确
                        pIsHas = true;
                    }
                    else
                    {
                        pHoursTraffic = new RP_HourAADT();
                        pIsHas = false;
                    }
                    //更新实体
                    UpdateInfo(pCollection, pHoursTraffic, HourPer, pDt, pIsHas);

                    using (TransactionScope transaction = new TransactionScope())
                    {
                        //更新或添加
                        if (!pIsHas)
                            db.RP_HourAADT.Add(pHoursTraffic);
                        db.SaveChanges();
                        //提交事务
                        transaction.Complete();
                    }
                }
                string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:结束获取,13,14报表数据", endTime));
                SystemLog.GetInstance().Log.Info(string.Format("统计13,14报表数据耗时{0}秒", (DateTime.Parse(endTime) - DateTime.Parse(startTime)).TotalSeconds));
                //显示执行该方法的线程ID
                //SystemLog.GetInstance().Log.Info(string.Format("调用13,14Update的线程ID为:{0}", Thread.CurrentThread.ManagedThreadId));
                Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Update(DateTime dt, int HourPer)
        {
            try
            {
                string startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:开始获取7报表数据", startTime));
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    DateTime pDt = DateTime.Parse(dt.ToShortDateString());

                    //获取数据//p.VehType == 0 表示合计数据,
                    IEnumerable<DS_DataSource> pCollection = db.DS_DataSource.Where(p =>
                        DbFunctions.TruncateTime(p.CalcuTime) == DbFunctions.TruncateTime(dt)
                        && p.VehType == 0 && p.StaID == (int)StationConfiguration.StationID.DYF);
                    //大羊坊单日数据
                    List<RP_AADTAndTransCalcu> pList = db.RP_AADTAndTransCalcu.Where(p => p.CalcuTime == pDt).ToList();
                    RP_AADTAndTransCalcu pAADTInfo = null;
                    bool pIsHas = false;
                    if (pList.Count > 0)
                    {
                        pAADTInfo = pList.FirstOrDefault();
                        pIsHas = true;
                    }
                    else
                    {
                        pAADTInfo = new RP_AADTAndTransCalcu();
                    }
                    //更新实体
                    UpdateInfo(pCollection, pAADTInfo, pDt, pIsHas);
                    using (TransactionScope transaction = new TransactionScope())
                    {
                        //如果不存在,则添加,否则则更新
                        if (pList.Count <= 0)
                            db.RP_AADTAndTransCalcu.Add(pAADTInfo);
                        db.SaveChanges();
                        transaction.Complete();
                    }

                }
                string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:结束获取7报表数据", endTime));
                SystemLog.GetInstance().Log.Info(string.Format("统计7报表数据耗时{0}秒", (DateTime.Parse(endTime) - DateTime.Parse(startTime)).TotalSeconds));
                //显示执行该方法的线程ID
                //SystemLog.GetInstance().Log.Info(string.Format("调用7Update的线程ID为:{0}", Thread.CurrentThread.ManagedThreadId));
                Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <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;
                    }
                }
            }
        }
 /// <summary>
 /// 添加文件导出记录
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 public byte Create(OT_ExportHis args)
 {
     byte num;
     using (DataSubmittedEntities db = new DataSubmittedEntities())
     {
         using (TransactionScope transaction = new TransactionScope())
         {
             db.OT_ExportHis.Add(args);
             num = (byte)db.SaveChanges();
             transaction.Complete();
         }
     }
     return num;
 }
示例#5
0
 /// <summary>
 /// 数据提交结果-删除
 /// </summary>
 /// <param name="db">提交数据库对象</param>
 /// <returns>提交结果</returns>
 public static CustomResult DelChangesResult(DataSubmittedEntities db)
 {
     CustomResult pReturnValue = new CustomResult();
     if (db.SaveChanges() > 0)
     {
         pReturnValue.ResultKey = (byte)EResult.Succeed;
         pReturnValue.ResultValue = Resources.TipInfo.DeleteSuccess;
     }
     else
     {
         pReturnValue.ResultKey = (byte)EResult.Fail;
         pReturnValue.ResultValue = Resources.TipInfo.DeleteFaile;
     }
     return pReturnValue;
 }
示例#6
0
 /// <summary>
 /// 返回带事物的提交结果-新增
 /// </summary>
 /// <param name="db">提交数据库对象</param>
 /// <param name="transaction">事物</param>
 /// <returns>提交结果</returns>
 public static CustomResult SaveChangesResult(DataSubmittedEntities db, TransactionScope transaction)
 {
     CustomResult pReturnValue = new CustomResult();
     if (db.SaveChanges() > 0)
     {
         transaction.Complete();
         pReturnValue.ResultKey = (byte)EResult.Succeed;
         pReturnValue.ResultValue = Resources.TipInfo.AddSuccess;
     }
     else
     {
         pReturnValue.ResultKey = (byte)EResult.Fail;
         pReturnValue.ResultValue = Resources.TipInfo.AddFaile;
     }
     return pReturnValue;
 }
        /// <summary>
        /// 补数据
        /// </summary>
        /// <param name="para"></param>
        private void RepairData(QueryParameters para)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    DateTime dtime = para.StartTime.Value;

                    //时间小于当前时间
                    if (DateTime.Now > dtime)
                    {
                        bool flag = StrWhere(db, para).Select(a => a.CalculTime).ToList().Contains(dtime);
                        if (!flag)//补数据
                        {
                            RP_AADTSta model = new RP_AADTSta();
                            model.CalculTime = dtime;
                            if (SessionManage.GetLoginUser() != null)
                            {
                                model.CrtBy = SessionManage.GetLoginUser().UserName;
                            }
                            model.CrtDate = DateTime.Now;
                            model.Id = Guid.NewGuid();
                            model.ChagSumNum = 0.00;
                            model.ExEnPer = 0.00;
                            model.LineEnSum = 0.00;
                            model.LineExSum = 0.00;
                            model.LineSum = 0.00;
                            model.SmaCarCompGrow = 0.00;
                            model.SmaCarFee = (decimal)0.00;
                            model.SmaCarFeeNum = 0.00;
                            model.SumGrow = 0.00;
                            model.State = "0";
                            db.RP_AADTSta.Add(model);
                        }
                        else//将数据中有空值的改成0
                        {
                            var model = db.RP_AADTSta.Where(a => a.CalculTime == dtime).ToList()[0];
                            if (model.ChagSumNum == null)
                                model.ChagSumNum = 0.00;
                            if (model.ExEnPer == null)
                                model.ExEnPer = 0.00;
                            if (model.LineEnSum == null)
                                model.LineEnSum = 0.00;
                            if (model.LineExSum == null)
                                model.LineExSum = 0.00;
                            if (model.LineSum == null)
                                model.LineSum = 0.00;
                            if (model.SmaCarCompGrow == null)
                                model.SmaCarCompGrow = 0.00;
                            if (model.SmaCarFee == null)
                                model.SmaCarFee = (decimal)0.00;
                            if (model.SmaCarFeeNum == null)
                                model.SmaCarFeeNum = 0.00;
                            if (model.SumGrow == null)
                                model.SumGrow = 0.00;
                        }
                    }
                    try
                    {
                        db.SaveChanges();
                        transaction.Complete();
                    }
                    catch (Exception ex)
                    {
                        SystemLog.GetInstance().Error(TipInfo.AddFaile, ex);
                    }
                }
            }
        }
        /// <summary>
        /// 修改功能
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public CustomResult Update(UHDayRoadStaViewModel args)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    CustomResult pReturnValue = new CustomResult();
                    List<UpdateHDayRoadStaViewModel> list = args.DataInfo.Where(a => a.LineType != 0).ToList();
                    try
                    {
                        foreach (UpdateHDayRoadStaViewModel model in list)
                        {
                            var listHDayRoadSta = db.RP_HDayAADTSta.Where(a => a.CalcuTime == args.DataDate && a.LineType == model.LineType).ToList();
                            foreach (RP_HDayAADTSta hd in listHDayRoadSta)
                            {
                                //  hd.LineType = model.LineType;
                                hd.ExNat = model.ExNat;
                                hd.EnNat = model.EnNat;
                                hd.ExEqu = model.ExEqu;
                                hd.EnEqu = model.EnEqu;

                                //拥挤度-“拥挤度”=交通量(当量交通量)合计/设计交通量,保留四位小数;
                                if (hd.ExEqu != null && hd.EnEqu != null)
                                {
                                    HDayAADTViewModel model1 = new HDayAADTViewModel();
                                    model1.LineType = model.LineType;
                                    Nullable<double> crowDeg = double.Parse(string.Format("{0:0.0000}", (hd.ExEqu + hd.EnEqu) / model1.DeTra));
                                    hd.CrowDeg = crowDeg;
                                }
                                hd.SmaEx = model.SmaEx;
                                hd.SmaEn = model.SmaEn;
                                hd.MedEx = model.MedEx;
                                hd.MedEn = model.MedEn;
                                hd.LarEx = model.LarEx;
                                hd.LarEn = model.LarEn;
                                hd.HeaEx = model.HeaEx;
                                hd.HeaEn = model.HeaEn;
                                hd.SupEx = model.SupEx;
                                hd.SupEn = model.SupEn;
                                hd.EnExTrukNum = model.EnExTrukNum;

                                //客车货车比例-客车货车比例=(交通量(自然交通量)合计-进出京货车数量)/进出京货车数量*100%,保留四位小数;
                                if (hd.ExNat != null && hd.EnNat != null && hd.EnExTrukNum != null && hd.EnExTrukNum != null)
                                {
                                    if (hd.EnExTrukNum != 0)
                                    {
                                        Nullable<double> carTrukPer = double.Parse(string.Format("{0:0.0000}", (hd.ExNat.Value + hd.EnNat.Value - hd.EnExTrukNum.Value) / hd.EnExTrukNum.Value));
                                        hd.CarTrukPer = carTrukPer;
                                    }
                                    else
                                    {
                                        hd.CarTrukPer = 0;
                                    }
                                }

                                //进出京大货车以上车型数量-进出京大货车以上车型数量”=大型车(合计)+重型车(合计)+超大型车(合计)。
                                if (hd.LarEx != null && hd.LarEn != null && hd.HeaEx != null && hd.HeaEn != null && hd.SupEx != null && hd.SupEn != null)
                                {
                                    Nullable<double> supTruNum = hd.LarEx.Value + hd.LarEn.Value + hd.HeaEx.Value + hd.HeaEn.Value + hd.SupEx.Value + hd.SupEn.Value;
                                    hd.SupTruNum = supTruNum;
                                }
                                //大货车以上占货车交通量比例-大货车以上占货车交通量比例(%)=进出京大货车以上车型的数量/进出京货车数量*100%,保留四位小数。
                                if (hd.SupTruNum != null && hd.EnExTrukNum != null)
                                {
                                    if (hd.EnExTrukNum.Value != 0)
                                    {
                                        Nullable<double> supTruPer = double.Parse(string.Format("{0:0.0000}", hd.SupTruNum.Value / hd.EnExTrukNum.Value));
                                        hd.SupTruPer = supTruPer;
                                    }
                                    else
                                    {
                                        hd.SupTruPer = 0;
                                    }
                                }
                                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;
                    }
                }
            }
        }
        /// <summary>
        /// 补充数据
        /// </summary>
        /// <param name="dt">统计日期</param>
        private void InsertNull(DateTime dt)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {

                List<RP_HDayAADTSta> pList = new List<RP_HDayAADTSta>();
                for (int i = 1; i < 7; i++)
                {

                    List<RP_HDayAADTSta> pTemp = db.RP_HDayAADTSta.Where(s => s.CalcuTime == dt && s.LineType == i).ToList();
                    //如果数据不存在,才补充
                    if (pTemp.Count <= 0)
                    {
                        RP_HDayAADTSta pHDayAADTSta = new RP_HDayAADTSta();
                        pHDayAADTSta.Id = Guid.NewGuid();
                        pHDayAADTSta.LineType = i;
                        if (i != 6)
                        {
                            pHDayAADTSta.ExNat = 0;
                            pHDayAADTSta.EnNat = 0;
                            pHDayAADTSta.ExEqu = 0;
                            pHDayAADTSta.EnEqu = 0;
                            pHDayAADTSta.CrowDeg = 0;
                            pHDayAADTSta.SmaEx = 0;
                            pHDayAADTSta.SmaEn = 0;
                            pHDayAADTSta.MedEx = 0;
                            pHDayAADTSta.MedEn = 0;
                            pHDayAADTSta.LarEx = 0;
                            pHDayAADTSta.LarEn = 0;
                            pHDayAADTSta.HeaEx = 0;
                            pHDayAADTSta.HeaEn = 0;
                            pHDayAADTSta.SupEx = 0;
                            pHDayAADTSta.SupEn = 0;
                            pHDayAADTSta.EnExTrukNum = 0;
                            pHDayAADTSta.CarTrukPer = 0;
                            pHDayAADTSta.SupTruNum = 0;
                            pHDayAADTSta.SupTruPer = 0;
                        }
                        else
                        {
                            pHDayAADTSta.ExNat = null;
                            pHDayAADTSta.EnNat = null;
                            pHDayAADTSta.ExEqu = null;
                            pHDayAADTSta.EnEqu = null;
                            pHDayAADTSta.CrowDeg = null;
                            pHDayAADTSta.SmaEx = null;
                            pHDayAADTSta.SmaEn = null;
                            pHDayAADTSta.MedEx = null;
                            pHDayAADTSta.MedEn = null;
                            pHDayAADTSta.LarEx = null;
                            pHDayAADTSta.LarEn = null;
                            pHDayAADTSta.HeaEx = null;
                            pHDayAADTSta.HeaEn = null;
                            pHDayAADTSta.SupEx = null;
                            pHDayAADTSta.SupEn = null;
                            pHDayAADTSta.EnExTrukNum = null;
                            pHDayAADTSta.CarTrukPer = null;
                            pHDayAADTSta.SupTruNum = null;
                            pHDayAADTSta.SupTruPer = null;
                        }
                        pHDayAADTSta.CalcuTime = dt;
                        pHDayAADTSta.CrtDate = DateTime.Now;
                        pHDayAADTSta.State = "0";
                        pList.Add(pHDayAADTSta);
                    }
                }
                using (TransactionScope transac = new TransactionScope())
                {
                    db.RP_HDayAADTSta.AddRange(pList);
                    if (pList.Count > 0)
                    {
                        db.SaveChanges();
                        transac.Complete();
                    }
                }
            }
        }
        /// <summary>
        /// 校正数据
        /// </summary>
        /// <param name="args">校正日期,参考日期,浮动百分比</param>
        /// <returns></returns>
        public CustomResult CalibrationData(QueryParameters para)
        {
            CustomResult pReturnValue = new CustomResult();
            // QueryNaturalInfoViewModel queryNatural = new QueryNaturalInfoViewModel();

            //校正浮动范围
            double pFloating = para.FloatingRange * 0.01;
            List<RP_Daily> pDailyList = new List<RP_Daily>();
            try
            {
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    //判断报表浮动百分比配置是否存在
                    OT_HDayConfig pds = HolidayConfig.GetInstance().GetById(para.ReportType);
                    if (pds == null)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileNoConfig;
                        return pReturnValue;
                    }
                    //判断报表浮动百分比配置是否正确
                    if (Math.Abs(para.FloatingRange) > (double)pds.CheckFloat.Value)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.ErrorInfo + "范围应在负%" + pds.CheckFloat.Value + "-正%" + pds.CheckFloat.Value + "之间";
                        return pReturnValue;
                    }
                    //获取参考日期符合校正时间段的数据,因为只校正一天的数据,所以只查询开始数据的日期就可以
                    List<RP_Daily> pRefDataDailyInfo = db.RP_Daily.Where(s => s.CalcuTime == para.LastYearStart && s.StaType == para.StationType).ToList();
                    //如果参考日期数据为0 则返回失败
                    if (pRefDataDailyInfo.Count == 0)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileRefNoData;
                        return pReturnValue;
                    }
                    //判断校正数据日期是否合理
                    if (para.LastYearStart < para.StartTime && para.StartTime < DateTime.Now.AddDays(1))
                    {
                        //需要校正的数据
                        var pCheckList = db.RP_Daily.Where(s => s.CalcuTime == para.StartTime && s.StaType == para.StationType).ToList();
                        //如果校正数据不存在则返回失败
                        if (pCheckList.Count == 0)
                        {
                            pReturnValue.ResultKey = (byte)EResult.Fail;
                            pReturnValue.ResultValue = TipInfo.CalibrationFaileNoData;
                            return pReturnValue;
                        }
                        using (TransactionScope tran = new TransactionScope())
                        {
                            foreach (var item in pCheckList)
                            {
                                IEnumerable<RP_Daily> plist = pRefDataDailyInfo.Where(i => i.VehType == item.VehType);
                                if (plist.Count() > 0)
                                {
                                    RP_Daily pTemp = plist.First();
                                    item.InNum = (int)(pTemp.InNum + pTemp.InNum * pFloating);
                                    item.OutNum = (int)(pTemp.OutNum + pTemp.OutNum * pFloating);
                                    item.ChagFee = pTemp.ChagFee.Value + pTemp.ChagFee.Value * decimal.Parse(pFloating.ToString());
                                    item.CalcuTime = para.StartTime.Value;
                                    item.StaType = para.StationType;
                                    if (SessionManage.GetLoginUser() != null)
                                    {
                                        item.UpdBy = SessionManage.GetLoginUser().UserName;
                                    }
                                    item.UpdDate = DateTime.Now;
                                    item.State = 1;
                                }
                            }
                            db.SaveChanges();
                            tran.Complete();
                            pReturnValue.ResultKey = (byte)EResult.Succeed;
                            pReturnValue.ResultValue = TipInfo.CalibrationSuccess;
                        }
                    }
                    else
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileDate;
                    }

                }
                return pReturnValue;
            }
            catch (Exception e)
            {
                pReturnValue.ResultKey = (byte)EResult.Fail;
                pReturnValue.ResultValue = TipInfo.CalibrationFaile + e.Message.ToString();
                SystemLog.GetInstance().Error(TipInfo.CalibrationFaile, e);
                return pReturnValue;
            }
        }
        /// <summary>
        /// 校正
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        public CustomResult CalibrationData(QueryParameters para)
        {
            CustomResult pReturnValue = new CustomResult();
            double pFloating = 1 + para.FloatingRange * 0.01;

            List<RP_HDayAADTSta> pNaturalTraList = new List<RP_HDayAADTSta>();
            try
            {
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    //判断报表浮动百分比配置是否正确
                    OT_HDayConfig pds = HolidayConfig.GetInstance().GetById(para.ReportType);
                    if (pds == null)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileNoConfig;
                        return pReturnValue;
                    }
                    if (Math.Abs(para.FloatingRange) > (double)pds.CheckFloat.Value)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.ErrorInfo + "范围应在负" + pds.CheckFloat.Value + "%-正" + pds.CheckFloat.Value + "%之间";
                        return pReturnValue;
                    }
                    //判断校正数据日期是否合理
                    if (para.LastYearStart < para.StartTime && para.StartTime < DateTime.Now.AddDays(1))
                    {
                        //获取参考日期符合校正时间段的数据,因为只校正一天的数据,所以只查询开始数据的日期就可以
                        List<RP_HDayAADTSta> pRefNaturalList = db.RP_HDayAADTSta.Where(s => s.CalcuTime == para.LastYearStart).ToList();
                        //如果参考日期数据为0 则返回失败
                        if (pRefNaturalList.Count == 0)
                        {
                            pReturnValue.ResultKey = (byte)EResult.Fail;
                            pReturnValue.ResultValue = TipInfo.CalibrationFaileRefNoData;
                            return pReturnValue;
                        }
                        //需要校正的数据
                        var pCheckNaturalList = db.RP_HDayAADTSta.Where(s => s.CalcuTime == para.StartTime).ToList();
                        //如果需要校正的数据为空则返回失败
                        if (pCheckNaturalList.Count == 0)
                        {
                            pReturnValue.ResultKey = (byte)EResult.Fail;
                            pReturnValue.ResultValue = TipInfo.CalibrationFaileNoData;
                            return pReturnValue;
                        }
                        using (TransactionScope tran = new TransactionScope())
                        {

                            ////校正数据
                            //RP_HDayAADTSta pCheckInfo = pCheckNaturalList.First();
                            ////参考数据
                            //RP_HDayAADTSta pRefInfo = pRefNaturalList.First();

                            foreach (RP_HDayAADTSta pCheckInfo in pCheckNaturalList)//校正数据
                            {
                                foreach (RP_HDayAADTSta pRefInfo in pRefNaturalList)//参考数据
                                {
                                    if (pRefInfo.LineType != 0 && pCheckInfo.LineType == pRefInfo.LineType)
                                    {
                                        //出京自然交通辆
                                        if (pRefInfo.ExNat != null)
                                            pCheckInfo.ExNat = Math.Round(pRefInfo.ExNat.Value * pFloating);
                                        //进京自然交通辆
                                        if (pRefInfo.EnNat != null)
                                            pCheckInfo.EnNat = Math.Round(pRefInfo.EnNat.Value * pFloating);
                                        //出京当量交通辆
                                        if (pRefInfo.ExEqu != null)
                                            pCheckInfo.ExEqu = Math.Round(pRefInfo.ExEqu.Value * pFloating);
                                        //进京当量交通辆
                                        if (pRefInfo.EnEqu != null)
                                            pCheckInfo.EnEqu = Math.Round(pRefInfo.EnEqu.Value * pFloating);
                                        //拥挤度-“拥挤度”=交通量(当量交通量)合计/设计交通量,保留四位小数;
                                        if (pCheckInfo.ExEqu != null && pCheckInfo.EnEqu != null)
                                        {
                                            HDayAADTViewModel model = new HDayAADTViewModel();
                                            model.LineType = pRefInfo.LineType;
                                            pCheckInfo.CrowDeg = double.Parse(string.Format("{0:0.0000}", (pCheckInfo.ExEqu + pCheckInfo.EnEqu) / model.DeTra));
                                        }
                                        //小型车出京
                                        if (pRefInfo.SmaEx != null)
                                            pCheckInfo.SmaEx = Math.Round(pRefInfo.SmaEx.Value * pFloating);
                                        //小型车进京
                                        if (pRefInfo.SmaEn != null)
                                            pCheckInfo.SmaEn = Math.Round(pRefInfo.SmaEn.Value * pFloating);
                                        //中型车出京
                                        if (pRefInfo.MedEx != null)
                                            pCheckInfo.MedEx = Math.Round(pRefInfo.MedEx.Value * pFloating);
                                        //中型车进京
                                        if (pRefInfo.MedEn != null)
                                            pCheckInfo.MedEn = Math.Round(pRefInfo.MedEn.Value * pFloating);
                                        //大型车出京
                                        if (pRefInfo.LarEx != null)
                                            pCheckInfo.LarEx = Math.Round(pRefInfo.LarEx.Value * pFloating);
                                        //大型车进京
                                        if (pRefInfo.LarEn != null)
                                            pCheckInfo.LarEn = Math.Round(pRefInfo.LarEn.Value * pFloating);
                                        //重型车出京
                                        if (pRefInfo.HeaEx != null)
                                            pCheckInfo.HeaEx = Math.Round(pRefInfo.HeaEx.Value * pFloating);
                                        //重型车进京
                                        if (pRefInfo.HeaEn != null)
                                            pCheckInfo.HeaEn = Math.Round(pRefInfo.HeaEn.Value * pFloating);
                                        //超大型车出京
                                        if (pRefInfo.SupEx != null)
                                            pCheckInfo.SupEx = Math.Round(pRefInfo.SupEx.Value * pFloating);
                                        //超大型车进京
                                        if (pRefInfo.SupEn != null)
                                            pCheckInfo.SupEn = Math.Round(pRefInfo.SupEn.Value * pFloating);
                                        //进出京大货车以上车型数量-进出京大货车以上车型数量”=大型车(合计)+重型车(合计)+超大型车(合计)。
                                        if (pCheckInfo.LarEx != null && pCheckInfo.LarEn != null && pCheckInfo.HeaEx != null && pCheckInfo.HeaEn != null && pCheckInfo.SupEx != null && pCheckInfo.SupEn != null)
                                            pCheckInfo.SupTruNum = pCheckInfo.LarEx + pCheckInfo.LarEn + pCheckInfo.HeaEx + pCheckInfo.HeaEn + pCheckInfo.SupEx + pCheckInfo.SupEn;
                                        //进出京货车数量
                                        if (pRefInfo.EnExTrukNum != null)
                                            pCheckInfo.EnExTrukNum = Math.Round(pRefInfo.EnExTrukNum.Value * pFloating);
                                        //客车货车比例-客车货车比例=(交通量(自然交通量)合计-进出京货车数量)/进出京货车数量*100%,保留四位小数;
                                        if (pCheckInfo.ExNat != null && pCheckInfo.EnNat != null && pCheckInfo.EnExTrukNum != null && pCheckInfo.EnExTrukNum != null && pCheckInfo.EnExTrukNum != 0)
                                        {
                                            pCheckInfo.CarTrukPer = double.Parse(string.Format("{0:0.0000}", (pCheckInfo.ExNat + pCheckInfo.EnNat - pCheckInfo.EnExTrukNum) / pCheckInfo.EnExTrukNum));
                                        }
                                        //大货车以上占货车交通量比例-大货车以上占货车交通量比例(%)=进出京大货车以上车型的数量/进出京货车数量*100%,保留四位小数。
                                        if (pCheckInfo.SupTruNum != null && pCheckInfo.EnExTrukNum != null && pCheckInfo.EnExTrukNum != 0)
                                        {
                                            pCheckInfo.SupTruPer = double.Parse(string.Format("{0:0.0000}", pCheckInfo.SupTruNum / pCheckInfo.EnExTrukNum));
                                        }
                                        if (SessionManage.GetLoginUser() != null)
                                        {
                                            pCheckInfo.UpdBy = SessionManage.GetLoginUser().UserName;
                                        }
                                        pCheckInfo.UpdDate = DateTime.Now;
                                        pCheckInfo.State = "1";
                                        break;
                                    }
                                }
                            }
                            db.SaveChanges();
                            tran.Complete();
                            pReturnValue.ResultKey = (byte)EResult.Succeed;
                            pReturnValue.ResultValue = TipInfo.CalibrationSuccess;
                        }
                    }
                    else
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileDate;
                    }
                }
                return pReturnValue;
            }
            catch (Exception e)
            {
                pReturnValue.ResultKey = (byte)EResult.Fail;
                pReturnValue.ResultValue = TipInfo.CalibrationFaile + e.Message.ToString();
                SystemLog.GetInstance().Error(TipInfo.CalibrationFaile, e);
                return pReturnValue;
            }
        }
        /// <summary>
        /// 创建或修改15,16合计
        /// </summary>
        /// <param name="para"></param>
        /// <param name="stationtype">收费站类型</param>
        public void CreateOrUpdateSum(QueryParameters para, int stationtype)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                #region 合计
                //查询日期当天除合计外的全部数据
                IEnumerable<RP_NatSta> naturalall = db.RP_NatSta.Where(s => s.CalcuTime == para.StartTime && s.StaType == stationtype && s.HourPer != 24);

                IEnumerable<RP_NatSta> naturallistsum = db.RP_NatSta.Where(s => s.CalcuTime == para.StartTime && s.HourPer == 24 && s.StaType == stationtype);
                RP_NatSta natural = new RP_NatSta();
                //如果有数据则进行合计
                if (naturalall.Count() > 0)
                {
                    if (naturallistsum.Count() > 0)
                    {
                        natural = naturallistsum.First();
                    }

                    natural.Sum = naturalall.Sum(s => s.Sum);
                    natural.ExNum = naturalall.Sum(s => s.ExNum);
                    natural.EnNum = naturalall.Sum(s => s.EnNum);
                    natural.State = "1";
                    natural.UpdDate = DateTime.Now;
                    using (TransactionScope transaction = new TransactionScope())
                    {
                        if (naturallistsum.Count() <= 0)
                        {
                            natural.RunStae = "正常";
                            natural.HourPer = 24;//24代表合计
                            natural.Id = Guid.NewGuid();
                            natural.StaType = stationtype;
                            natural.CalcuTime = (DateTime)para.StartTime;
                            natural.CrtDate = DateTime.Now;
                            db.RP_NatSta.Add(natural);
                        }
                        db.SaveChanges();
                        //提交事务
                        transaction.Complete();
                    }
                #endregion
                }
            }
        #endregion

            #region 10 Static Methods
            #endregion

            #region 11 Private Methods
            #endregion

            #region 12 Protected Methods
            #endregion
        }
        /// <summary>
        /// 校正数据
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public CustomResult CalibrationData(QueryParameters para)
        {
            CustomResult pReturnValue = new CustomResult();
            //判断选择校正时间段的有效性
            string[] calibrationDataHour = new string[24];
            if (para.StartHour <= para.EndHour)
            {
                for (int i = para.StartHour; i <= para.EndHour; i++)
                {
                    calibrationDataHour[i] = i.ToString();
                }
            }
            else
            {
                pReturnValue.ResultKey = (byte)EResult.Fail;
                pReturnValue.ResultValue = TipInfo.CalibrationFaileHour;
                return pReturnValue;
            }
            double pFloating = 1 + para.FloatingRange * 0.01;
            List<RP_NatSta> pNaturalTraList = new List<RP_NatSta>();
            try
            {
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    //判断报表浮动百分比配置是否正确
                    OT_HDayConfig pds = HolidayConfig.GetInstance().GetById(para.ReportType);
                    if (pds == null)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileNoConfig;
                        return pReturnValue;
                    }
                    if (Math.Abs(para.FloatingRange) > (double)pds.CheckFloat.Value)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.ErrorInfo + "范围应在负" + pds.CheckFloat.Value + "%-正" + pds.CheckFloat.Value + "%之间";
                        return pReturnValue;
                    }
                    //获取参考日期符合校正时间段的数据,因为只校正一天的数据,所以只查询开始数据的日期就可以
                    List<RP_HourAADT> pRefHourAADTList = db.RP_HourAADT.Where(s => s.CalcuTime == para.LastYearStart && calibrationDataHour.Contains(s.HourPer.ToString())).ToList();
                    //如果参考日期数据为0 则返回失败
                    if (pRefHourAADTList.Count <= 0)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileRefNoData;
                        return pReturnValue;
                    }
                    //判断时间范围是否相同
                    if ((para.LastYearEnd - para.LastYearStart) == (para.EndTime - para.StartTime))
                    {
                        //需要校正的数据
                        var pCheckHourAADTList = db.RP_HourAADT.Where(s => s.CalcuTime == para.StartTime && calibrationDataHour.Contains(s.HourPer.ToString())).ToList();
                        if (pCheckHourAADTList.Count <= 0)
                        {
                            pReturnValue.ResultKey = (byte)EResult.Fail;
                            pReturnValue.ResultValue = TipInfo.CalibrationFaileNoData;
                            return pReturnValue;
                        }
                        using (TransactionScope tran = new TransactionScope())
                        {
                            foreach (var item in pCheckHourAADTList)
                            {
                                List<RP_HourAADT> plist = pRefHourAADTList.Where(i => i.HourPer == item.HourPer).ToList();
                                if (plist.Count() > 0)
                                {
                                    RP_HourAADT pTemp = plist.First();
                                    item.Dyf_EnOut = Math.Round(pTemp.Dyf_EnOut.Value * pFloating);
                                    item.Dyf_ExIn = Math.Round(pTemp.Dyf_ExIn.Value * pFloating);
                                    item.Mjqd_EnIn = Math.Round(pTemp.Mjqd_EnIn.Value * pFloating);
                                    item.Mjqd_EnOut = Math.Round(pTemp.Mjqd_EnOut.Value * pFloating);
                                    item.Mjqx_ExIn = Math.Round(pTemp.Mjqx_ExIn.Value * pFloating);
                                    item.Mjqx_EnOut = Math.Round(pTemp.Mjqx_EnOut.Value * pFloating);
                                    item.Cy_EnOut = Math.Round(pTemp.Cy_EnOut.Value * pFloating);
                                    item.Cy_ExIn = Math.Round(pTemp.Cy_ExIn.Value * pFloating);
                                    item.CalcuTime = para.StartTime.Value;

                                    if (SessionManage.GetLoginUser() != null)
                                    {
                                        item.UpdBy = SessionManage.GetLoginUser().UserName;
                                    }
                                    item.UpdDate = DateTime.Now;
                                    item.State = "1";
                                }
                            }
                            db.SaveChanges();
                            tran.Complete();
                            pReturnValue.ResultKey = (byte)EResult.Succeed;
                            pReturnValue.ResultValue = TipInfo.CalibrationSuccess;
                        }
                    }
                    else
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationRangeFaile;
                    }
                }
            }
            catch (Exception e)
            {
                pReturnValue.ResultKey = (byte)EResult.Fail;
                pReturnValue.ResultValue = TipInfo.CalibrationFaile + e.Message.ToString();
                SystemLog.GetInstance().Error(TipInfo.CalibrationFaile, e);
                return pReturnValue;
            }
            return pReturnValue;
        }
        /// <summary>
        /// 校正
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        public Common.CustomResult CalibrationData(Common.QueryParameters para)
        {
            CustomResult pReturnValue = new CustomResult();
            double pFloating = 1 + para.FloatingRange * 0.01;

            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                //判断报表浮动百分比配置是否正确
                OT_HDayConfig pds = HolidayConfig.GetInstance().GetById(para.ReportType);
                if (pds == null)
                {
                    pReturnValue.ResultKey = (byte)EResult.Fail;
                    pReturnValue.ResultValue = TipInfo.CalibrationFaileNoConfig;
                    return pReturnValue;
                }
                if (Math.Abs(para.FloatingRange) > (double)pds.CheckFloat.Value)
                {
                    pReturnValue.ResultKey = (byte)EResult.Fail;
                    pReturnValue.ResultValue = TipInfo.ErrorInfo + "范围应在负" + pds.CheckFloat.Value + "%-正" + pds.CheckFloat.Value + "%之间";
                    return pReturnValue;
                }
                //判断时间范围是否相同
                if ((para.LastYearEnd - para.LastYearStart) == (para.EndTime - para.StartTime))
                {
                    //获取参考日期符合校正时间段的数据
                    List<RP_HDayAADT> pRefNaturalList = db.RP_HDayAADT.Where(a => a.CalcuTime >= para.LastYearStart & a.CalcuTime <= para.LastYearEnd).OrderBy(a => a.CalcuTime).ToList();
                    //如果参考日期数据为0 则返回失败
                    if (pRefNaturalList == null || pRefNaturalList.Count == 0)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileRefNoData;
                        return pReturnValue;
                    }
                    //需要校正的数据
                    var pCheckNaturalList = db.RP_HDayAADT.Where(a => a.CalcuTime >= para.StartTime & a.CalcuTime <= para.EndTime).OrderBy(a => a.CalcuTime).ToList();
                    //如果需要校正的数据为空则返回失败
                    if (pCheckNaturalList == null || pCheckNaturalList.Count == 0)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileNoData;
                        return pReturnValue;
                    }
                    using (TransactionScope tran = new TransactionScope())
                    {
                        for (int i = 0; i < pCheckNaturalList.Count; i++)
                        {
                            if (pRefNaturalList[i].JC != null)
                                pCheckNaturalList[i].JC = Math.Round(pRefNaturalList[i].JC.Value * pFloating);
                            if (pRefNaturalList[i].JZL != null)
                                pCheckNaturalList[i].JZL = Math.Round(pRefNaturalList[i].JZL.Value * pFloating);
                            if (pRefNaturalList[i].KG != null)
                                pCheckNaturalList[i].KG = Math.Round(pRefNaturalList[i].KG.Value * pFloating);
                            if (pRefNaturalList[i].TGB != null)
                                pCheckNaturalList[i].TGB = Math.Round(pRefNaturalList[i].TGB.Value * pFloating);
                            if (pRefNaturalList[i].TGX != null)
                                pCheckNaturalList[i].TGX = Math.Round(pRefNaturalList[i].TGX.Value * pFloating);
                            if (pRefNaturalList[i].TGXF != null)
                                pCheckNaturalList[i].TGXF = Math.Round(pRefNaturalList[i].TGXF.Value * pFloating);
                            if (pRefNaturalList[i].YC != null)
                                pCheckNaturalList[i].YC = Math.Round(pRefNaturalList[i].YC.Value * pFloating);
                            if (pRefNaturalList[i].YXBD != null)
                                pCheckNaturalList[i].YXBD = Math.Round(pRefNaturalList[i].YXBD.Value * pFloating);
                            if (pRefNaturalList[i].YXBX != null)
                                pCheckNaturalList[i].YXBX = Math.Round(pRefNaturalList[i].YXBX.Value * pFloating);
                            if (SessionManage.GetLoginUser() != null)
                            {
                                pCheckNaturalList[i].UpdBy = SessionManage.GetLoginUser().UserName;
                            }
                            pCheckNaturalList[i].UpdDate = DateTime.Now;
                            pCheckNaturalList[i].State = "1";
                        }
                        try
                        {
                            db.SaveChanges();
                            tran.Complete();
                            pReturnValue.ResultKey = (byte)EResult.Succeed;
                            pReturnValue.ResultValue = TipInfo.CalibrationSuccess;
                        }
                        catch (Exception e)
                        {
                            pReturnValue.ResultKey = (byte)EResult.Fail;
                            pReturnValue.ResultValue = TipInfo.CalibrationFaile + e.Message.ToString();
                            SystemLog.GetInstance().Error(TipInfo.CalibrationFaile, e);
                            return pReturnValue;
                        }
                    }
                }
                else
                {
                    pReturnValue.ResultKey = (byte)EResult.Fail;
                    pReturnValue.ResultValue = TipInfo.CalibrationRangeFaile;
                }
            }
            return pReturnValue;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public Common.CustomResult Update(Common.ViewModels.UpdateHDayStaExEnViewModel args)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    CustomResult pReturnValue = new CustomResult();

                    bool flag = false;//标记数据库中是否有数据修改
                    int count = (args.EndTime - args.StartTime).Days + 1;

                    for (int j = 1; j < args.DataInfo.Count; j++)
                    {
                        HDayStaExEnViewModel model = args.DataInfo[j];

                        Type myType0 = qModel.TitleList[0].GetType();

                        for (int i = 1; i < count + 1; i++)
                        {
                            Type myType = model.GetType();
                            PropertyInfo pinfo = myType.GetProperty("Date" + i);
                            PropertyInfo pinfo0 = myType0.GetProperty("Date" + i);
                            if (args.StartTime.AddDays(i - 1).ToString("M月d日").ToString() == pinfo0.GetValue(qModel.TitleList[0]).ToString())
                            {
                                DateTime dt = args.StartTime.AddDays(i - 1);
                                var list = db.RP_HDayAADT.Where(a => a.CalcuTime == dt).ToList();

                                double info = double.Parse(pinfo.GetValue(model).ToString());

                                foreach (var item in list)
                                {
                                    flag = true;
                                    if (model.Num == "43")//杨村站
                                        item.YC = info;
                                    else if (model.Num == "44")//宜兴埠东站
                                        item.YXBD = info;
                                    else if (model.Num == "45")//宜兴埠西站
                                        item.YXBX = info;
                                    else if (model.Num == "46")//金钟路站
                                        item.JZL = info;
                                    else if (model.Num == "47")//机场站
                                        item.JC = info;
                                    else if (model.Num == "48")//空港经济区站
                                        item.KG = info;
                                    else if (model.Num == "49")//塘沽西站
                                        item.TGX = info;
                                    else if (model.Num == "50")//塘沽西分站
                                        item.TGXF = info;
                                    else if (model.Num == "51")//塘沽北站
                                        item.TGB = info;

                                    item.UpdDate = DateTime.Now;
                                    if (SessionManage.GetLoginUser() != null)
                                    {
                                        item.UpdBy = SessionManage.GetLoginUser().UserName;
                                    }
                                    item.State = "1";
                                }
                            }
                        }
                    }
                    if (flag)//有修改成功的数据
                    {
                        try
                        {
                            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;
                        }
                    }
                    else//存在数据尚未生成
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.UpdateDataRepeat;
                        return pReturnValue;
                    }
                }
            }
        }
        /// <summary>
        /// 补数据
        /// </summary>
        /// <param name="para"></param>
        private void RepairData(QueryParameters para)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    DateTime dtQuery = new DateTime();
                    //判断传入的时间段是否正确
                    if (para.StartTime != null && para.EndTime != null && DateTime.TryParse(para.StartTime.Value.ToString(), out dtQuery) && DateTime.TryParse(para.EndTime.Value.ToString(), out dtQuery))
                    {
                        int day = (para.EndTime.Value - para.StartTime.Value).Days + 1;
                        for (int i = 0; i < day; i++)
                        {
                            DateTime dtime = para.StartTime.Value.AddDays(i);

                            //时间小于当前时间
                            if (DateTime.Now > dtime)
                            {
                                bool flag = StrWhere(db, para).Select(a => a.CalcuTime).ToList().Contains(dtime);
                                if (!flag)//补数据
                                {
                                    RP_AADTAndTransCalcu hday = new RP_AADTAndTransCalcu();
                                    hday.CalcuTime = dtime;

                                    if (SessionManage.GetLoginUser() != null)
                                    {
                                        hday.CrtBy = SessionManage.GetLoginUser().UserName;
                                    }
                                    hday.CrtDate = DateTime.Now;
                                    hday.Id = Guid.NewGuid();
                                    hday.EnCar = 0;
                                    hday.EnTra = 0;
                                    hday.EnTrav = 0.00;
                                    hday.ExCar = 0;
                                    hday.ExTra = 0;
                                    hday.State = "0";
                                    hday.ExTrav = 0.00;

                                    db.RP_AADTAndTransCalcu.Add(hday);
                                }
                                else//将数据中有空值的改成0
                                {
                                    var hday = db.RP_AADTAndTransCalcu.Where(a => a.CalcuTime == dtime).ToList()[0];
                                    if (hday.EnCar == null)
                                        hday.EnCar = 0;
                                    if (hday.EnTra == null)
                                        hday.EnTra = 0;
                                    if (hday.EnTrav == null)
                                        hday.EnTrav = 0.00;
                                    if (hday.ExCar == null)
                                        hday.ExCar = 0;
                                    if (hday.ExTra == null)
                                        hday.ExTra = 0;
                                    if (hday.ExTrav == null)
                                        hday.ExTrav = 0.00;
                                }
                            }
                        }
                        try
                        {
                            db.SaveChanges();
                            transaction.Complete();
                        }
                        catch (Exception ex)
                        {
                            SystemLog.GetInstance().Error(TipInfo.AddFaile, ex);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 补充数据
        /// </summary>
        /// <param name="dt">统计日期</param>
        /// <param name="stationtype">统计类型</param>
        private void InsertNull(DateTime dt, int stationtype)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                List<RP_Daily> pDailyList = new List<RP_Daily>();
                for (int i = 0; i < 4; i++)
                {
                    //0小型客车,1其他客车,2货车(不包含绿通),3绿通
                    //每个站只有四条合计数据,每天数据表里一共只有16条
                    List<RP_Daily> pTemp = db.RP_Daily.Where(s => s.CalcuTime == dt && s.VehType == i && s.StaType == stationtype).ToList();
                    //如果数据不存在,才补充
                    if (pTemp.Count <= 0)
                    {
                        RP_Daily pDaily = new RP_Daily();

                        pDaily.Id = Guid.NewGuid();
                        pDaily.CrtDate = DateTime.Now;
                        pDaily.VehType = i;//车辆类型
                        pDaily.StaType = stationtype;
                        pDaily.State = 0;
                        pDaily.OutNum = 0;
                        pDaily.InNum = 0;
                        pDaily.ChagFee = 0;
                        pDaily.CalcuTime = DateTime.Parse(dt.ToShortDateString());
                        pDailyList.Add(pDaily);
                    }
                }
                using (TransactionScope transac = new TransactionScope())
                {
                    db.RP_Daily.AddRange(pDailyList);
                    if (pDailyList.Count > 0)
                    {
                        db.SaveChanges();
                        transac.Complete();
                    }
                }
            }
        }
        /// <summary>
        /// 8.9.10数据源更新方法
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="HourPer"></param>
        public void Update(DateTime dt, int HourPer)
        {
            try
            {
                string startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:开始获取8,9,10报表数据", startTime));
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    DateTime plasttime = new DateTime();
                    List<OT_HDayConfig> pdayconfigs = db.OT_HDayConfig.Where(s => s.Id == 9).ToList();
                    OT_HDayConfig pdayconfig = new OT_HDayConfig();
                    if (pdayconfigs.Count > 0)
                    {
                        pdayconfig = pdayconfigs.First();
                        if (pdayconfig.HDayStart.HasValue && pdayconfig.HDayEnd.HasValue)
                        {
                            int ptemp = 0;
                            //判断当天是否在假期配置时间范围内
                            DateTime ptempdt = DateTime.Parse(dt.ToShortDateString());
                            if (ptempdt >= pdayconfig.HDayStart.Value && ptempdt <= pdayconfig.HDayEnd)
                            {
                                //间隔的天数
                                ptemp = (ptempdt - pdayconfig.HDayStart.Value).Days;
                            }
                            if (pdayconfig.CompStart.HasValue)
                            {
                                plasttime = pdayconfig.CompStart.Value.AddDays(ptemp);
                            }
                        }
                    }

                    List<RP_AADTSta> pOlds = db.RP_AADTSta.Where(s => s.CalculTime == plasttime).ToList();
                    //判断去年同期是否存在
                    RP_AADTSta oldinfo = new RP_AADTSta();
                    if (pOlds.Count > 0)
                    {
                        oldinfo = pOlds.First();
                    }
                    DateTime pdt = DateTime.Parse(dt.ToShortDateString());
                    //北京段包含出入口收费站
                    List<int> BJStation = StationConfiguration.GetBJStaion();
                    //北京段只包含出口收费站
                    List<int> outBJStation = StationConfiguration.GetOutBJStaion();
                    //获取北京段数据//p.VehType == 0 表示合计数据,
                    IEnumerable<DS_DataSource> pBJCollection = db.DS_DataSource.Where(p =>
                        DbFunctions.TruncateTime(p.CalcuTime) == DbFunctions.TruncateTime(dt)
                        && p.VehType == 0
                        && BJStation.Contains(p.StaID.Value));
                    //判断数据是否已存在
                    RP_AADTSta pAADTStaInfo = null;
                    List<RP_AADTSta> pList = db.RP_AADTSta.Where(p => p.CalculTime == pdt).ToList();
                    if (pList.Count > 0)//已存在,则更新
                    {
                        pAADTStaInfo = pList.FirstOrDefault();
                        pAADTStaInfo.UpdDate = DateTime.Now;
                        pAADTStaInfo.State = "1";
                    }
                    else//不存在,添加
                    {
                        pAADTStaInfo = new RP_AADTSta();
                        pAADTStaInfo.Id = Guid.NewGuid();
                        pAADTStaInfo.CrtDate = DateTime.Now;
                        pAADTStaInfo.State = "0";
                    }
                    //涉及到金额的单位全部转为万元,保留两位小数
                    //出京路线总交通量,不包括绿通
                    pAADTStaInfo.LineExSum = pBJCollection.Where(s => outBJStation.Contains(s.StaID.Value) && s.CalcuType != 3).Sum(s => s.InNum);
                    //入京路线总交通量,不包括绿通
                    pAADTStaInfo.LineEnSum = pBJCollection.Where(s => BJStation.Contains(s.StaID.Value) && s.CalcuType != 3).Sum(s => s.OutNum);
                    pAADTStaInfo.LineSum = pAADTStaInfo.LineEnSum + pAADTStaInfo.LineExSum;
                    //总交通量同比增幅
                    if (oldinfo.LineSum.HasValue)
                    {
                        pAADTStaInfo.SumGrow = double.Parse(string.Format("{0:0.00}", (pAADTStaInfo.LineSum - oldinfo.LineSum) / oldinfo.LineSum));
                    }
                    //出进京比
                    pAADTStaInfo.ExEnPer = double.Parse(string.Format("{0:0.00}", (pAADTStaInfo.LineExSum / pAADTStaInfo.LineEnSum)));
                    //收费/免征总金额
                    pAADTStaInfo.FeeSum = Math.Round(pBJCollection.Sum(s => s.RecMoney.Value) / 10000, 2);
                    //出京小型客车免费通行交通量
                    pAADTStaInfo.ExSmaCarFee = pBJCollection.Where(s => s.CalcuType == 0 && outBJStation.Contains(s.StaID.Value)).Sum(s => s.InNum);
                    //进京小型客车免费通行交通量
                    pAADTStaInfo.EnSmaCarFee = pBJCollection.Where(s => s.CalcuType == 0).Sum(s => s.OutNum);
                    //小型客车免费通行交通量(合计)
                    pAADTStaInfo.SmaCarFeeNum = pAADTStaInfo.ExSmaCarFee + pAADTStaInfo.EnSmaCarFee;
                    //小型客车交通量同比增幅
                    if (oldinfo.SmaCarFeeNum.HasValue)
                    {
                        pAADTStaInfo.SmaCarCompGrow = double.Parse(string.Format("{0:0.00}", (pAADTStaInfo.SmaCarFeeNum - oldinfo.SmaCarFeeNum) / oldinfo.SmaCarFeeNum));

                    }//小型客车免费金额
                    pAADTStaInfo.SmaCarFee = Math.Round(pBJCollection.Where(s => s.CalcuType.Value == 0).Sum(s => s.RecMoney.Value) / 10000, 2);
                    //出京收费车辆
                    pAADTStaInfo.ExChagNum = pBJCollection.Where(s => outBJStation.Contains(s.StaID.Value) && (s.CalcuType == 1 || s.CalcuType == 2)).Sum(s => s.InNum);
                    //进京收费车辆
                    pAADTStaInfo.EnChagNum = pBJCollection.Where(s => s.CalcuType == 1 || s.CalcuType == 2).Sum(s => s.OutNum);
                    //收费车辆合计
                    pAADTStaInfo.ChagSumNum = pAADTStaInfo.ExChagNum + pAADTStaInfo.EnChagNum;
                    //收费额度
                    pAADTStaInfo.ChagAmount = Math.Round(pBJCollection.Where(s => s.CalcuType == 1 || s.CalcuType == 2).Sum(s => s.RecMoney.Value) / 10000, 2);
                    //绿色通道车辆数
                    pAADTStaInfo.GreNum = pBJCollection.Where(s => s.CalcuType == 3).Sum(s => s.OutNum);
                    //绿色通道免收费金额
                    pAADTStaInfo.GreFee = Math.Round(pBJCollection.Where(s => s.CalcuType == 3).Sum(s => s.RecMoney.Value) / 10000, 2);
                    //出京总交通量(站)
                    pAADTStaInfo.StaExSum = pBJCollection.Where(s => s.StaID == (int)StationConfiguration.StationID.DYF).Sum(s => s.InNum);
                    //进京总交通量(站)
                    pAADTStaInfo.StaEnSum = pBJCollection.Where(s => s.StaID == (int)StationConfiguration.StationID.DYF).Sum(s => s.OutNum);
                    pAADTStaInfo.CalculTime = pdt;

                    using (TransactionScope trans = new TransactionScope())
                    {
                        if (pList.Count <= 0)
                            db.RP_AADTSta.Add(pAADTStaInfo);
                        db.SaveChanges();
                        trans.Complete();
                    }
                }
                string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:结束获取8,9,10报表数据", endTime));
                SystemLog.GetInstance().Log.Info(string.Format("统计8,9,10报表数据耗时{0}秒", (DateTime.Parse(endTime) - DateTime.Parse(startTime)).TotalSeconds));
                //显示执行该方法的线程ID
                //SystemLog.GetInstance().Log.Info(string.Format("调用8,9,10Update的线程ID为:{0}", Thread.CurrentThread.ManagedThreadId));
                Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 校正数据
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public CustomResult CalibrationData(QueryParameters para)
        {
            CustomResult pReturnValue = new CustomResult();
            double pFloating = 1 + para.FloatingRange * 0.01;

            List<RP_HDayAADT> pHDayAADT = new List<RP_HDayAADT>();
            try
            {
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    //判断报表浮动百分比配置是否正确
                    OT_HDayConfig pds = HolidayConfig.GetInstance().GetById(para.ReportType);
                    if (pds == null)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileNoConfig;
                        return pReturnValue;
                    }
                    if (Math.Abs(para.FloatingRange) > (double)pds.CheckFloat.Value)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.ErrorInfo + "范围应在负" + pds.CheckFloat.Value + "%-正" + pds.CheckFloat.Value + "%之间";
                        return pReturnValue;
                    }
                    //判断时间范围是否相同
                    if ((para.LastYearEnd - para.LastYearStart) == (para.EndTime - para.StartTime))
                    {
                        //获取参考日期符合校正时间段的数据
                        List<RP_HDayAADT> pRefList = db.RP_HDayAADT.Where(s => s.CalcuTime >= para.LastYearStart && s.CalcuTime <= para.LastYearEnd).ToList();
                        //如果参考日期数据为0 则返回失败
                        if (pRefList.Count == 0)
                        {
                            pReturnValue.ResultKey = (byte)EResult.Fail;
                            pReturnValue.ResultValue = TipInfo.CalibrationFaileRefNoData;
                            return pReturnValue;
                        }
                        //需要校正的数据
                        var pCheckList = db.RP_HDayAADT.Where(s => s.CalcuTime >= para.StartTime && s.CalcuTime <= para.EndTime).ToList();
                        //如果需要校正的数据为空则返回失败
                        if (pCheckList.Count == 0)
                        {
                            pReturnValue.ResultKey = (byte)EResult.Fail;
                            pReturnValue.ResultValue = TipInfo.CalibrationFaileNoData;
                            return pReturnValue;
                        }
                        using (TransactionScope tran = new TransactionScope())
                        {

                            ////校正数据
                            //RP_HDayAADTSta pCheckInfo = pCheckNaturalList.First();
                            ////参考数据
                            //RP_HDayAADTSta pRefInfo = pRefNaturalList.First();

                            foreach (RP_HDayAADT pCheckInfo in pCheckList)//校正数据
                            {
                                foreach (RP_HDayAADT pRefInfo in pRefList)//参考数据
                                {
                                    if (pRefInfo.CalcuTime == pRefInfo.CalcuTime)
                                    {
                                        pCheckInfo.Out = Math.Round(pRefInfo.Out.Value * pFloating);
                                        if (SessionManage.GetLoginUser() != null)
                                        {
                                            pCheckInfo.UpdBy = SessionManage.GetLoginUser().UserName;
                                        }
                                        pCheckInfo.UpdDate = DateTime.Now;
                                        pCheckInfo.State = "1";
                                        break;
                                    }
                                }
                            }
                            db.SaveChanges();
                            tran.Complete();
                            pReturnValue.ResultKey = (byte)EResult.Succeed;
                            pReturnValue.ResultValue = TipInfo.CalibrationSuccess;
                        }
                    }
                    else
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationRangeFaile;
                    }
                }
                return pReturnValue;
            }
            catch (Exception e)
            {
                pReturnValue.ResultKey = (byte)EResult.Fail;
                pReturnValue.ResultValue = TipInfo.CalibrationFaile + e.Message.ToString();
                SystemLog.GetInstance().Error(TipInfo.CalibrationFaile, e);
                return pReturnValue;
            }
        }
        /// <summary>
        /// 补充数据
        /// </summary>
        /// <param name="dt">统计日期</param>
        private void InsertNull(DateTime dt)
        {
            HDayStatisticalReport pHday = new HDayStatisticalReport("");
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                RP_HDayAADT info = new RP_HDayAADT();

                info.Id = Guid.NewGuid();
                info.CrtDate = DateTime.Now;
                info.State = "0";
                info.CalcuTime = dt;
                //杨村站流量
                info.YC = 0;
                //宜兴埠东站流量
                info.YXBD = 0;
                //宜兴埠西站流量
                info.YXBX = 0;
                //金钟路站流量
                info.JZL = 0;
                //机场站流量
                info.JC = 0;
                //空港经济区站流量
                info.KG = 0;
                //塘沽西站流量
                info.TGX = 0;
                //塘沽西分站流量
                info.TGXF = 0;
                //塘沽北站流量
                info.TGB = 0;
                //表12出口流量
                info.Out = 0;
                //去年同期
                info.SameSum = pHday.GetSameSum(dt);
                using (TransactionScope transac = new TransactionScope())
                {
                    db.RP_HDayAADT.Add(info);
                    db.SaveChanges();
                    transac.Complete();
                }
            }
        }
示例#21
0
 /// <summary>
 /// 返回带事物的提交结果-修改使用
 /// </summary>
 /// <param name="db">提交数据库对象</param>
 /// <param name="transaction">事物</param>
 /// <returns>提交结果</returns>
 public static CustomResult SaveUpdateResult(DataSubmittedEntities db, TransactionScope transaction)
 {
     CustomResult pReturnValue = new CustomResult();
     try
     {
         db.SaveChanges();
         transaction.Complete();
         pReturnValue.ResultKey = (byte)EResult.Succeed;
         pReturnValue.ResultValue = Resources.TipInfo.UpdateSuccess;
     }
     catch (Exception ex)
     {
         SystemLog.GetInstance().Error(TipInfo.UpdateFaile, ex);
         pReturnValue.ResultKey = (byte)EResult.Fail;//程序已经使用多处,所有不变动
         pReturnValue.ResultValue = Resources.TipInfo.UpdateFaile;
     }
     return pReturnValue;
 }
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public CustomResult Update(UpdateDataDailyViewModel args)
        {
            CustomResult pReturnValue = new CustomResult();
            pReturnValue.ResultKey = (byte)EResult.Fail;
            pReturnValue.ResultValue = TipInfo.UpdateFaile;
            if (args.DataInfo == null)
            {
                pReturnValue.ResultKey = (byte)EResult.Succeed;
                pReturnValue.ResultValue = TipInfo.DataNull;
                return pReturnValue;
            }
            List<UpdateDataDailyInfo> pNewUpdateData = new List<UpdateDataDailyInfo>();

            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                var pReportData = db.RP_Daily.Where(s => s.CalcuTime == args.DataDate && s.StaType == args.StationType).ToList();
                using (TransactionScope transaction = new TransactionScope())
                {
                    try
                    {
                        foreach (var item in args.DataInfo)
                        {
                            //获取查询日期当天的数据
                            if (item.VehType == SystemConst.SmallCar)
                                item.VehType = "0";
                            if (item.VehType == SystemConst.OtherCar)
                                item.VehType = "1";
                            if (item.VehType == SystemConst.Truk)
                                item.VehType = "2";
                            if (item.VehType == SystemConst.Green)
                                item.VehType = "3";
                            int ptemp = int.Parse(item.VehType);
                            RP_Daily pDataTemp = new RP_Daily();
                            if (pReportData.Where(i => i.VehType == ptemp).Count() == 1)
                            {
                                pDataTemp = pReportData.Where(i => i.VehType == ptemp).SingleOrDefault();

                                if (item.ExEn == SystemConst.In)//入口
                                {
                                    pDataTemp.InNum = item.VehNum;//出口
                                }
                                else
                                {
                                    pDataTemp.OutNum = item.VehNum;
                                    pDataTemp.ChagFee = item.CarChag * 10000;//转为元,存到数据库
                                }
                                pDataTemp.UpdDate = DateTime.Now;
                                pDataTemp.State = 1;
                                if (SessionManage.GetLoginUser() != null)
                                {
                                    pDataTemp.UpdBy = SessionManage.GetLoginUser().UserName;
                                }
                            }
                        }
                        db.SaveChanges();
                        transaction.Complete();
                        pReturnValue.ResultKey = (byte)EResult.Succeed;
                        pReturnValue.ResultValue = TipInfo.UpdateSuccess;
                    }
                    catch (Exception ex)
                    {
                        Common.SystemLog.GetInstance().Log.Info(TipInfo.UpdateDataRepeat, ex);
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.UpdateDataRepeat;
                    }
                    return pReturnValue;
                }
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public Common.CustomResult Update(Common.ViewModels.AADTAndTransCalcuUViewModel args)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    CustomResult pReturnValue = new CustomResult();

                    bool flag = false;//标记数据库中是否有数据修改
                    foreach (AADTAndTransCalcuViewModel model in args.DataInfo)
                    {
                        if (!string.IsNullOrEmpty(model.CalcuTimeUpdate))
                        {
                            DateTime dt = new DateTime();
                            if (DateTime.TryParse(model.CalcuTimeUpdate, out dt))
                            {
                                var list = db.RP_AADTAndTransCalcu.Where(a => a.CalcuTime == dt).ToList();
                                foreach (var item in list)
                                {
                                    flag = true;

                                    item.EnTra = model.EnTra;
                                    item.EnCar = model.EnCar;
                                    //“旅客量”=“其中客车数”*5.84/10000
                                    item.EnTrav = item.EnCar == null ? 0.00 : Math.Round(item.EnCar.Value * 5.84 / 10000, 2);

                                    item.ExCar = model.ExCar;
                                    item.ExTra = model.ExTra;
                                    //“旅客量”=“其中客车数”*5.84/10000
                                    item.ExTrav = item.ExCar == null ? 0.00 : Math.Round(item.ExCar.Value * 5.84 / 10000, 2);

                                    item.State = "1";
                                    item.UpdDate = DateTime.Now;
                                    if (SessionManage.GetLoginUser() != null)
                                    {
                                        item.UpdBy = SessionManage.GetLoginUser().UserName;
                                    }
                                }
                            }
                        }
                    }
                    if (flag)//有修改成功的数据
                    {
                        try
                        {
                            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;
                        }
                    }
                    else//存在数据尚未生成
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.UpdateDataRepeat;
                        return pReturnValue;
                    }
                }
            }
        }
示例#24
0
        /// <summary>
        /// 初始化单条密码
        /// </summary>
        /// <param name="listUserRoleId">用户角色关系编号集合</param>
        /// <returns>修改结构</returns>
        public CustomResult StartPassword(List<Guid> listUserId)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    int flag=0;
                    string password = ConfigurationManager.AppSettings["StartPassword"];
                    foreach (Guid userId in listUserId)
                    {
                        var list = db.OT_User.Where(a => a.Id == userId & a.IsDelete == (byte)EUserStatus.Normal).ToList();

                        if (list != null && list.Count > 0)
                        {
                            foreach (var i in list)
                            {
                                i.Password = password;
                            }
                            flag++;
                        }
                      
                    }
                    if(flag>0)
                    {
                        CustomResult pReturnValue = new CustomResult();
                        if (db.SaveChanges() > 0)
                        {
                            transaction.Complete();
                            pReturnValue.ResultKey = (byte)EResult.Succeed;
                            pReturnValue.ResultValue = Wttech.DataSubmitted.Common.Resources.TipInfo.StartPassword;
                        }
                        else
                        {
                            pReturnValue.ResultKey = (byte)EResult.Fail;//程序已经使用多处,所有不变动
                            pReturnValue.ResultValue = Wttech.DataSubmitted.Common.Resources.TipInfo.StartPassword;
                        }
                        return pReturnValue;
                    }
                    else
                    {
                        CustomResult pReturnValue = new CustomResult();
                        pReturnValue.ResultKey = (byte)EResult.Fail;//程序已经使用多处,所有不变动
                        pReturnValue.ResultValue = Wttech.DataSubmitted.Common.Resources.TipInfo.Inexist;
                        return pReturnValue;
                    }
                }
            }
        }
        /// <summary>
        ///更新每日报送数据15.16.17
        /// </summary>
        public void Update(DateTime dt, int HourPer)
        {
            string startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            SystemLog.GetInstance().Log.Info(string.Format("{0}:开始获取15,16,17报表数据", startTime));
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                DateTime pdt = DateTime.Parse(dt.ToShortDateString());
                //北京段相同数据是否存在
                List<RP_NatSta> pBJlist = db.RP_NatSta.Where(p =>
                    p.CalcuTime == pdt
                    && p.HourPer == (byte?)HourPer
                    && p.StaType == (int)StationConfiguration.StationType.BeiJingDuan).ToList();
                bool BJHasTime = pBJlist.Count > 0;
                //大羊坊相同数据是否存在
                List<RP_NatSta> pDYFlist = db.RP_NatSta.Where(p =>
                    p.CalcuTime == pdt
                    && p.HourPer == (byte?)HourPer
                    && p.StaType == (int)StationConfiguration.StationID.DYF).ToList();
                bool DYFHasTime = pDYFlist.Count > 0;
                IList<RP_NatSta> pNaturalEntities = new List<RP_NatSta>();

                List<int> BJStation = StationConfiguration.GetBJStaion();
                List<int> outBJStation = StationConfiguration.GetOutBJStaion();
                //p.VehType != 0 表示不包括合计数据,
                IEnumerable<DS_DataSource> pStagingCollection = db.DS_DataSource.Where(p =>
                    p.CalcuTime == dt
                    && p.VehType != 0
                    && p.HourPer == HourPer
                    && BJStation.Contains(p.StaID.Value));


                RP_NatSta pNaturalTrafficBJ = null;//北京段
                RP_NatSta pNaturalTraffic = null;//大羊坊
                //北京段
                //如果相同日期,相同时间段,相同统计站类型数据已存在则进行更新
                if (!BJHasTime)
                {
                    pNaturalTrafficBJ = new RP_NatSta();//北京段
                    pNaturalTrafficBJ.Id = Guid.NewGuid();
                }
                else
                {
                    pNaturalTrafficBJ = pBJlist[0];
                }
                pNaturalTrafficBJ.EnNum = pStagingCollection.Sum(s => s.OutNum);
                pNaturalTrafficBJ.ExNum = pStagingCollection.Where(s => outBJStation.Contains(s.StaID.Value)).Sum(s => s.InNum);
                pNaturalTrafficBJ.Sum = pNaturalTrafficBJ.EnNum + pNaturalTrafficBJ.ExNum;
                pNaturalTrafficBJ.StaType = (int)StationConfiguration.StationType.BeiJingDuan;
                pNaturalTrafficBJ.CalcuTime = DateTime.Parse(dt.ToShortDateString());
                pNaturalTrafficBJ.HourPer = (byte)HourPer;
                pNaturalTrafficBJ.CrtDate = DateTime.Now;
                pNaturalTrafficBJ.RunStae = SystemConst.RunningStatus;
                pNaturalTrafficBJ.State = "0";
                //大羊坊
                //如果相同日期,相同时间段,相同统计站类型数据已存在则进行更新
                if (!DYFHasTime)
                {
                    pNaturalTraffic = new RP_NatSta();//大羊坊
                    pNaturalTraffic.Id = Guid.NewGuid();
                }
                else
                {
                    pNaturalTraffic = pDYFlist[0];
                }
                pNaturalTraffic.EnNum = pStagingCollection.Where(s => s.StaID == (int)StationConfiguration.StationID.DYF).Sum(s => s.OutNum);
                pNaturalTraffic.ExNum = pStagingCollection.Where(s => s.StaID == (int)StationConfiguration.StationID.DYF).Sum(s => s.InNum);
                pNaturalTraffic.Sum = pNaturalTraffic.EnNum + pNaturalTraffic.ExNum;
                pNaturalTraffic.StaType = (int)StationConfiguration.StationID.DYF;
                pNaturalTraffic.CrtDate = DateTime.Now;
                pNaturalTraffic.HourPer = (byte)HourPer;
                pNaturalTraffic.CalcuTime = DateTime.Parse(dt.ToShortDateString());
                pNaturalTraffic.RunStae = SystemConst.RunningStatus;
                pNaturalTraffic.State = "0";

                pNaturalEntities.Add(pNaturalTrafficBJ);
                pNaturalEntities.Add(pNaturalTraffic);
                using (TransactionScope transaction = new TransactionScope())
                {
                    //如果都不存在,则添加
                    if (!DYFHasTime && !BJHasTime)
                        db.RP_NatSta.AddRange(pNaturalEntities);
                    else if (!DYFHasTime && BJHasTime)
                        db.RP_NatSta.Add(pNaturalTraffic);
                    else if (DYFHasTime && !BJHasTime)
                        db.RP_NatSta.Add(pNaturalTrafficBJ);

                    db.SaveChanges();
                    //提交事务
                    transaction.Complete();
                }
                string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:结束获取15.16.17报表数据", endTime));
                SystemLog.GetInstance().Log.Info(string.Format("统计15,16,17报表数据耗时{0}秒", (DateTime.Parse(endTime) - DateTime.Parse(startTime)).TotalSeconds));
                //显示执行该方法的线程ID
                //SystemLog.GetInstance().Log.Info(string.Format("调用15,16,17Update的线程ID为:{0}", Thread.CurrentThread.ManagedThreadId));
                Thread.Sleep(1000);
            }
        }
 /// <summary>
 /// 批量修改
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 public CustomResult Update(UpdateHourAADTViewModel args)
 {
     CustomResult pReturnValue = new CustomResult();
     pReturnValue.ResultKey = (byte)EResult.Fail;
     pReturnValue.ResultValue = TipInfo.UpdateFaile;
     if (args.UpdateData == null)
     {
         pReturnValue.ResultKey = (byte)EResult.Succeed;
         pReturnValue.ResultValue = TipInfo.DataNull;
         return pReturnValue;
     }
     using (DataSubmittedEntities db = new DataSubmittedEntities())
     {
         var pReportData = db.RP_HourAADT.Where(s => s.CalcuTime == args.DataDate && s.HourPer != 24).ToList();
         using (TransactionScope transaction = new TransactionScope())
         {
             try
             {
                 //获取对应的数据                      
                 foreach (UpdateHourAADTInfo item in args.UpdateData)
                 {
                     for (int i = 0; i < 24; i++)
                     {
                         RP_HourAADT pHourAADT = null;
                         List<RP_HourAADT> pHourList = pReportData.Where(s => s.HourPer == i).ToList();
                         if (pHourList.Count > 0)
                         {
                             pHourAADT = pHourList.SingleOrDefault();
                         }
                         else
                         {
                             //如果该时段的数据没有找到,则进行下次循环
                             continue;
                         }
                         Type myType = item.GetType();
                         PropertyInfo pinfo = myType.GetProperty("Count_" + i);
                         if (item.StaName == "大羊坊站" && item.TraName == "出京入")
                         {
                             pHourAADT.Dyf_ExIn = (double)pinfo.GetValue(item);
                         }
                         if (item.StaName == "马驹桥东站" && item.TraName == "进京入")
                         {
                             pHourAADT.Mjqd_EnIn = (double)pinfo.GetValue(item);
                         }
                         if (item.StaName == "马驹桥西站" && item.TraName == "出京入")
                         {
                             pHourAADT.Mjqx_ExIn = (double)pinfo.GetValue(item);
                         }
                         if (item.StaName == "采育站" && item.TraName == "出京入")
                         {
                             pHourAADT.Cy_ExIn = (double)pinfo.GetValue(item);
                         }
                         if (item.StaName == "大羊坊站" && item.TraName == "进京出")
                         {
                             pHourAADT.Dyf_EnOut = (double)pinfo.GetValue(item);
                         }
                         if (item.StaName == "马驹桥东站" && item.TraName == "进京出")
                         {
                             pHourAADT.Mjqd_EnOut = (double)pinfo.GetValue(item);
                         }
                         if (item.StaName == "马驹桥西站" && item.TraName == "进京出")
                         {
                             pHourAADT.Mjqx_EnOut = (double)pinfo.GetValue(item);
                         }
                         if (item.StaName == "采育站" && item.TraName == "进京出")
                         {
                             pHourAADT.Cy_EnOut = (double)pinfo.GetValue(item);
                         }
                         pHourAADT.UpdDate = DateTime.Now;
                         pHourAADT.State = "1";
                         if (SessionManage.GetLoginUser() != null)
                         {
                             pHourAADT.UpdBy = SessionManage.GetLoginUser().UserName;
                         }
                     }
                 }
                 db.SaveChanges();
                 transaction.Complete();
                 pReturnValue.ResultKey = (byte)EResult.Succeed;
                 pReturnValue.ResultValue = TipInfo.UpdateSuccess;
             }
             catch (Exception ex)
             {
                 Common.SystemLog.GetInstance().Log.Info(TipInfo.UpdateDataRepeat, ex);
                 pReturnValue.ResultKey = (byte)EResult.Fail;
                 pReturnValue.ResultValue = TipInfo.UpdateDataRepeat;
             }
             return pReturnValue;
         }
     }
 }
        /// <summary>
        /// 补数据
        /// </summary>
        /// <param name="para"></param>
        private void RepairData(QueryParameters para)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    int day = (para.EndTime.Value - para.StartTime.Value).Days + 1;
                    for (int i = 0; i < day; i++)
                    {
                        DateTime dtime = para.StartTime.Value.AddDays(i);

                        //时间小于当前时间
                        if (DateTime.Now > dtime)
                        {
                            bool flag = StrWhere(db, para).Select(a => a.CalcuTime).ToList().Contains(dtime);
                            if (!flag)//补数据
                            {
                                RP_HDayAADT hday = new RP_HDayAADT();
                                hday.CalcuTime = dtime;
                                hday.CompGrow = 0;
                                if (SessionManage.GetLoginUser() != null)
                                {
                                    hday.CrtBy = SessionManage.GetLoginUser().UserName;
                                }
                                hday.CrtDate = DateTime.Now;
                                hday.Id = Guid.NewGuid();
                                hday.JC = 0;
                                hday.JZL = 0;
                                hday.KG = 0;
                                hday.Out = 0;
                                hday.SameSum = 0;
                                hday.State = "0";
                                hday.Sum = 0;
                                hday.TGB = 0;
                                hday.TGX = 0;
                                hday.TGXF = 0;
                                hday.YC = 0;
                                hday.YXBD = 0;
                                hday.YXBX = 0;
                                db.RP_HDayAADT.Add(hday);
                            }
                            else//将数据中有空值的改成0
                            {
                                var hday = db.RP_HDayAADT.Where(a => a.CalcuTime == dtime).ToList()[0];
                                if (hday.JC == null)
                                    hday.JC = 0;
                                if (hday.JZL == null)
                                    hday.JZL = 0;
                                if (hday.KG == null)
                                    hday.KG = 0;
                                if (hday.Out == null)
                                    hday.Out = 0;
                                if (hday.SameSum == null)
                                    hday.SameSum = 0;
                                if (hday.Sum == null)
                                    hday.Sum = 0;
                                if (hday.TGB == null)
                                    hday.TGB = 0;
                                if (hday.TGX == null)
                                    hday.TGX = 0;
                                if (hday.TGXF == null)
                                    hday.TGXF = 0;
                                if (hday.YC == null)
                                    hday.YC = 0;
                                if (hday.YXBD == null)
                                    hday.YXBD = 0;
                                if (hday.YXBX == null)
                                    hday.YXBX = 0;
                            }
                        }
                    }
                    try
                    {
                        db.SaveChanges();
                        transaction.Complete();
                    }
                    catch (Exception ex)
                    {
                        SystemLog.GetInstance().Error(TipInfo.AddFaile, ex);
                    }
                }
            }
        }
        /// <summary>
        /// 补充数据
        /// </summary>
        /// <param name="dt">统计日期</param>
        private void InsertNull(DateTime dt)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                int ptemp = 24;
                if (DateTime.Now.Date == dt)
                {
                    ptemp = DateTime.Now.Hour;
                }
                List<RP_HourAADT> pList = new List<RP_HourAADT>();
                for (int i = 0; i < ptemp; i++)
                {

                    List<RP_HourAADT> pTemp = db.RP_HourAADT.Where(s => s.CalcuTime == dt && s.HourPer == (byte)i).ToList();
                    //如果数据不存在,才补充
                    if (pTemp.Count <= 0)
                    {
                        RP_HourAADT pHour = new RP_HourAADT();
                        pHour.Id = Guid.NewGuid();
                        pHour.Mjqd_EnIn = 0;
                        pHour.Mjqd_EnOut = 0;
                        pHour.Dyf_EnOut = 0;
                        pHour.Dyf_ExIn = 0;
                        pHour.Mjqx_EnOut = 0;
                        pHour.Mjqx_ExIn = 0;
                        pHour.Cy_EnOut = 0;
                        pHour.Cy_ExIn = 0;
                        pHour.State = "0";
                        pHour.CalcuTime = dt;
                        pHour.CrtDate = DateTime.Now;
                        pHour.HourPer = (byte)i;
                        pList.Add(pHour);
                    }
                }
                using (TransactionScope transac = new TransactionScope())
                {
                    db.RP_HourAADT.AddRange(pList);
                    if (pList.Count > 0)
                    {
                        db.SaveChanges();
                        transac.Complete();
                    }
                }
            }
        }
        /// <summary>
        /// 更新或获取报表5,6数据
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="HourPer"></param>
        public void Update(DateTime dt, int HourPer)
        {
            try
            {
                string startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:开始获取5,6报表数据", startTime));
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    DateTime pDt = DateTime.Parse(dt.ToShortDateString());
                    //北京段包含出入口收费站
                    List<int> BJStation = StationConfiguration.GetBJStaion();

                    //获取数据//p.VehType == 0 表示合计数据,
                    IEnumerable<DS_DataSource> pCollection = db.DS_DataSource.Where(p =>
                        DbFunctions.TruncateTime(p.CalcuTime) == DbFunctions.TruncateTime(dt)
                        && p.VehType == 0);
                    //判断北京段数据是否已存在,StaType:1表示北京段,33表示泗村店
                    RP_EnEx pBJEnExInfo = null;
                    RP_EnEx pSCDEnExInfo = null;
                    bool pIsHas = false;
                    //北京段数据
                    List<RP_EnEx> pBJList = db.RP_EnEx.Where(p => p.CalcuTime == pDt && p.StaType == (int)StationConfiguration.StationType.BeiJingDuan).ToList();
                    if (pBJList.Count > 0)
                    {
                        pBJEnExInfo = pBJList.FirstOrDefault();
                        //每种状态需要重新赋值,防止公用同一个变量,值不明确
                        pIsHas = true;
                    }
                    else
                    {
                        pBJEnExInfo = new RP_EnEx();
                        pIsHas = false;
                    }
                    //更新北京段实体信息
                    UpdateInfo(pCollection.Where(s => BJStation.Contains(s.StaID.Value)), pBJEnExInfo, (int)StationConfiguration.StationType.BeiJingDuan, pDt, pIsHas);

                    //泗村店数据
                    List<RP_EnEx> pSCDList = db.RP_EnEx.Where(p => p.CalcuTime == pDt && p.StaType == (int)StationConfiguration.StationID.SCD).ToList();
                    if (pSCDList.Count > 0)
                    {
                        pSCDEnExInfo = pSCDList.FirstOrDefault();
                        pIsHas = true;
                    }
                    else
                    {
                        pSCDEnExInfo = new RP_EnEx();
                        pIsHas = false;
                    }
                    //更新泗村店实体信息
                    UpdateInfo(pCollection.Where(s => s.StaID.Value == (int)StationConfiguration.StationID.SCD), pSCDEnExInfo, (int)StationConfiguration.StationID.SCD, pDt, pIsHas);

                    //更新或添加到数据库
                    using (TransactionScope trans = new TransactionScope())
                    {
                        //如果不存在,则添加,否则则更新
                        if (pBJList.Count <= 0)
                            db.RP_EnEx.Add(pBJEnExInfo);
                        if (pSCDList.Count <= 0)
                            db.RP_EnEx.Add(pSCDEnExInfo);
                        db.SaveChanges();
                        trans.Complete();
                    }
                }
                string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:结束获取5,6报表数据", endTime));
                SystemLog.GetInstance().Log.Info(string.Format("统计5,6报表数据耗时{0}秒", (DateTime.Parse(endTime) - DateTime.Parse(startTime)).TotalSeconds));
                //显示执行该方法的线程ID
                //SystemLog.GetInstance().Log.Info(string.Format("调用5,6Update的线程ID为:{0}", Thread.CurrentThread.ManagedThreadId));
                Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 创建或修改13,14合计
        /// </summary>
        /// <param name="para"></param>
        /// <param name="stationtype">收费站类型</param>
        private void CreateOrUpdateSum(QueryParameters para)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                //查询日期当天除合计外的全部数据
                IEnumerable<RP_HourAADT> all = db.RP_HourAADT.Where(s => s.CalcuTime == para.StartTime && s.HourPer != 24);

                IEnumerable<RP_HourAADT> listsum = db.RP_HourAADT.Where(s => s.CalcuTime == para.StartTime && s.HourPer == 24);
                RP_HourAADT pHourAADT = new RP_HourAADT();
                //如果有数据则进行合计
                if (all.Count() > 0)
                {
                    if (listsum.Count() > 0)
                    {
                        pHourAADT = listsum.First();
                    }
                    pHourAADT.Dyf_ExIn = all.Sum(s => s.Dyf_ExIn);
                    pHourAADT.Dyf_EnOut = all.Sum(s => s.Dyf_EnOut);
                    pHourAADT.Mjqd_EnIn = all.Sum(s => s.Mjqd_EnIn);
                    pHourAADT.Mjqd_EnOut = all.Sum(s => s.Mjqd_EnOut);
                    pHourAADT.Mjqx_EnOut = all.Sum(s => s.Mjqx_EnOut);
                    pHourAADT.Mjqx_ExIn = all.Sum(s => s.Mjqx_ExIn);
                    pHourAADT.Cy_EnOut = all.Sum(s => s.Cy_EnOut);
                    pHourAADT.Cy_ExIn = all.Sum(s => s.Cy_ExIn);
                    pHourAADT.State = "1";
                    using (TransactionScope transaction = new TransactionScope())
                    {
                        if (listsum.Count() <= 0)
                        {
                            pHourAADT.HourPer = 24;//24代表合计
                            pHourAADT.Id = Guid.NewGuid();
                            pHourAADT.CalcuTime = (DateTime)para.StartTime;
                            pHourAADT.CrtDate = DateTime.Now;
                            pHourAADT.State = "0";
                            db.RP_HourAADT.Add(pHourAADT);
                        }
                        else
                        {
                            pHourAADT.UpdDate = DateTime.Now;
                        }
                        db.SaveChanges();
                        //提交事务
                        transaction.Complete();
                    }
                }
            }
        }