/// <summary> /// 报表12:天津市高速公路支队****年**假期流量表(出口) /// </summary> /// <returns></returns> public ActionResult HDayEx() { try { HolidayConfigViewModel pHdayConfig = ReportFactory.Instance.GetHolidayConfigById(12); ViewBag.StartTime = pHdayConfig.HolidayStartTime.Value.ToString("yyyy年M月d日"); ViewBag.EndTime = pHdayConfig.HolidayEndTime.Value.ToString("yyyy年M月d日"); //去年同期 ViewBag.LastSameStart = pHdayConfig.ComparedStartTime.Value.ToString("yyyy年M月d日"); ViewBag.LastSameEnd = pHdayConfig.ComparedEndTime.Value.ToString("yyyy年M月d日"); //配置天数 ViewBag.CountDay = (pHdayConfig.HolidayEndTime.Value - pHdayConfig.HolidayStartTime.Value).Days; IEnumerable <SelectListItem> pHolName = ReportFactory.Instance.DicGetListbyId((int)EDicParentId.Holiday).Select(i => new SelectListItem() { Value = i.DictId.ToString(), Text = i.Name, }); ViewBag.HolName = pHolName; ViewBag.HolidayId = pHdayConfig.HolidayId.ToString(); } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } return(View()); }
/// <summary> /// 预测导出--如果需要将入出口数据进行区分,则分别放在两个list的集合中,若不需区分,则将数据放入list1中,list2为空即可 /// </summary> /// <param name="path"></param> /// <param name="para"></param> /// <param name="forecase"></param> /// <param name="list1">出口</param> /// <param name="list2">入口</param> /// <returns></returns> public string ExportExcel(string path, QueryParameters para, IForecast forecase, List <IReportViewModel> list1, List <IReportViewModel> list2) { string[] num = path.Split('\\'); string filename = num[num.Length - 1].Split('.')[0] + "(预测).xlsx"; string savepath = string.Empty; try { if (System.IO.File.Exists(path)) { using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { IWorkbook readworkbook = new XSSFWorkbook(stream); stream.Close(); readworkbook = forecase.GenerateSheet(readworkbook, para, list1, list2); savepath = SaveFile(readworkbook, filename, para); } } else { SystemLog.GetInstance().Info("导出错误:模板信息不存在!"); } } catch (Exception e) { SystemLog.GetInstance().Error(e); } return(savepath); }
/// <summary> /// 根据查询条件获取数据 /// </summary> /// <param name="para">查询条件类,站类型也需要</param> /// <returns></returns> public IReportViewModel GetListByPra(QueryParameters para) { //查询返回实体 QueryHourAADTViewModel pReturn = new QueryHourAADTViewModel(); try { using (DataSubmittedEntities db = new DataSubmittedEntities()) { //补充空数据 InsertNull(para.StartTime.Value); List <int> pStationNames = StationConfiguration.GetBJStaion(); List <RP_HourAADT> pHourAADTList = db.RP_HourAADT.Where(s => s.CalcuTime == para.StartTime).ToList(); RP_HourAADT pHourAADTInfo = new RP_HourAADT(); //创建或更新合计 CreateOrUpdateSum(para); //报表数据 pReturn.ReportData = GetViewModelInfo(para); //判断当前统计站类型,数据是否完整 if (GetNoDataList(para).Count() > 0) { pReturn.IsFull = 0;//不完整 } else { pReturn.IsFull = 1;//完整 } } } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } return(pReturn); }
/// <summary> /// 写入日志,非报表类操作 /// </summary> /// <param name="type">操作类型</param> /// <param name="describe">操作描述</param> /// <returns></returns> public byte WriteLog(String type, string describe) { OT_Log pTemp = new OT_Log(); try { var pUser = SessionManage.GetLoginUser(); if (pUser != null) { pTemp.Id = Guid.NewGuid(); pTemp.LogDate = DateTime.Now; pTemp.Type = type; pTemp.UserName = pUser.UserName; pTemp.RptName = string.Empty; pTemp.Describe = describe; if (pUser.RoleList.Count > 0 && pUser.RoleList[0] != null) { pTemp.RoleName = pUser.RoleList[0].RoleName; } return(Create(pTemp)); } } catch (Exception ex) { SystemLog.GetInstance().Error("插入操作日志失败!", ex); } return((byte)EResult.Fail); }
/// <summary> /// 写入日志,报表类操作 /// </summary> /// <param name="type">操作类型</param> /// <param name="report">报表名称</param> /// <param name="dt">时间(yyyy-MM-dd)或时间范围(yyyy-MM-dd - yyyy-MM-dd)</param> /// <returns></returns> public byte WriteLog(String type, String report, String dt) { OT_Log pTemp = new OT_Log(); try { var pUser = SessionManage.GetLoginUser(); if (pUser != null) { pTemp.Id = Guid.NewGuid(); pTemp.LogDate = DateTime.Now; pTemp.Type = type; pTemp.UserName = pUser.UserName; if (type != OperationType.Login && type != OperationType.LoginOut) { pTemp.RptName = report; pTemp.Describe = String.Format("{0}{1}{2}", type, dt, report); } if (pUser.RoleList.Count > 0 && pUser.RoleList[0] != null) { pTemp.RoleName = pUser.RoleList[0].RoleName; } return(Create(pTemp)); } } catch (Exception ex) { SystemLog.GetInstance().Error("插入操作日志失败!", ex); } return((byte)EResult.Fail); }
public void Start(DataService da) { dataService = da; try { if (RemoteConnection()) { SystemLog.GetInstance().Log.Info(string.Format("远程服务器连接成功:{0} ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); this.timer.AutoReset = true; this.timer.Enabled = true; this.timer.Elapsed += new ElapsedEventHandler(this.timer_Elapsed); this.timer.Interval = INTERVALTIME; SystemLog.GetInstance().Log.Info(string.Format("服务启动成功,启动时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); SystemLog.GetInstance().Log.Info(string.Format("定时器启动成功,启动时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); } else { SystemLog.GetInstance().Log.Info(string.Format("{0}:服务启动失败,{1} ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "远程服务器连接失败")); } } catch (Exception e) { SystemLog.GetInstance().Log.Error(string.Format("远程服务器连接失败:{0} ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), e); dataService.Stop(); } }
public StagingReport() { try { if (this.Update != null) { Delegate[] dels = this.Update.GetInvocationList(); for (int i = 0; i < dels.Count(); i++) { this.Update -= (UpdateEventHandler)dels[i]; } } //报表1,2,3,4 this.Update += new UpdateEventHandler(new DataDailyStatisticalReport("DataDailyStatisticalReport").Update); //报表5,6 this.Update += new UpdateEventHandler(new EnExStatisticalReport("EnExStatisticalReport").Update); //报表7 this.Update += new UpdateEventHandler(new AADTTransStatisticalReport("AADTTransStatisticalReport").Update); //报表8,9,10 this.Update += new UpdateEventHandler(new AADTStatisticalReport("AADTStatisticalReport").Update); //报表11,12 this.Update += new UpdateEventHandler(new HDayStatisticalReport("HDayStatisticalReport").Update); //报表13,14 this.Update += new UpdateEventHandler(new HourAADTStatisticalReport("HourAADTStatisticalReport").Update); //报表15,16,17 this.Update += new UpdateEventHandler(new DailyTrafficStatisticalReport("DailyTrafficStatisticalReport").Update); //报表18 this.Update += new UpdateEventHandler(new HDayAADTStatisticalReport("HDayAADTStatisticalReport").Update); } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } }
/// <summary> /// 计算小型车收费免征金额 /// </summary> /// <param name="stattionid"></param> /// <returns></returns> private decimal GetCharge(List <int> stationlist, IEnumerable <DS_DataSource> datasource) { //小型车辆数 int smlvehnum; //单车费额 decimal vehcharge; //收费免征金额 decimal sumcharge = 0; try { using (DataSubmittedEntities db = new DataSubmittedEntities()) { for (int i = 0; i < stationlist.Count; i++) { smlvehnum = datasource.Where(s => s.StaID == stationlist[i] && s.CalcuType == 0).Sum(s => s.OutNum.Value); string ptemp = stationlist[i].ToString(); vehcharge = (decimal)db.OT_Station.Where(s => s.Num == ptemp).Select(s => s.Charge).Sum(); sumcharge += smlvehnum * vehcharge; } } } catch (Exception e) { SystemLog.GetInstance().Info(e.Message, e); } return(sumcharge); }
/// <summary> /// 预测数据 /// </summary> /// <param name="para"></param> /// <returns></returns> public CustomResult ForecastData(QueryParameters para) { log.WriteLog(OperationType.Forecast, Utility.GetReportNameByType(para.ReportType), Utility.GetFormatDate(para.LastYearStart, para.LastYearEnd)); switch (para.ReportType) { case 1: { para.StationType = 1; return(report1.ForecastData(para)); } case 2: { para.StationType = 3; return(report1.ForecastData(para)); } case 3: { para.StationType = 15; return(report1.ForecastData(para)); } case 4: { para.StationType = 33; return(report1.ForecastData(para)); } case 5: { para.StationType = 1; return(report5.ForecastData(para)); } case 6: { para.StationType = 33; return(report6.ForecastData(para)); } case 8: { para.StationType = 1; return(report8.ForecastData(para)); } case 9: { para.StationType = 1; return(report9.ForecastData(para)); } } SystemLog.GetInstance().Info("缺少参数:报表类型!"); return(null); }
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; } }
/// <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.CalculTime).ToList().Contains(dtime); if (!flag)//补数据 { RP_AADTSta hday = new RP_AADTSta(); hday.CalculTime = dtime; if (SessionManage.GetLoginUser() != null) { hday.CrtBy = SessionManage.GetLoginUser().UserName; } hday.CrtDate = DateTime.Now; hday.Id = Guid.NewGuid(); hday.LineEnSum = 0; hday.LineExSum = 0; db.RP_AADTSta.Add(hday); } else//将数据中有空值的改成0 { var hday = db.RP_AADTSta.Where(a => a.CalculTime == dtime).ToList()[0]; if (hday.LineEnSum == null) { hday.LineEnSum = 0; } if (hday.LineExSum == null) { hday.LineExSum = 0; } } } } try { db.SaveChanges(); transaction.Complete(); } catch (Exception ex) { SystemLog.GetInstance().Error(TipInfo.AddFaile, ex); } } } }
/// <summary> /// 获取无收费站数据列表 /// </summary> /// <param name="para">统计站类型,数据日期</param> /// <returns></returns> public List <ReportRelatedViewModels> GetNoDataList(QueryParameters para) { List <ReportRelatedViewModels> pList = new List <ReportRelatedViewModels>(); try { using (DataSubmittedEntities db = new DataSubmittedEntities()) { //获取某类报表所涉及的收费站名称 string[] pStationNames = null; if (para.StationType == (int)StationConfiguration.StationID.DYF || para.StationType == (int)StationConfiguration.StationID.SCD)//大羊坊或泗村店收费站 { pStationNames = db.OT_Station.Where(s => s.Num == para.StationType.Value.ToString()).Select(s => s.Name).ToArray(); } else if (para.StationType == (int)StationConfiguration.StationType.BeiJingDuan || para.StationType == (int)StationConfiguration.StationType.HeBei || para.StationType == (int)StationConfiguration.StationType.TianJinDuan)//多个收费站 { pStationNames = db.OT_Station.Where(s => s.District == para.StationType.Value).Select(s => s.Name).ToArray(); } List <OT_ErrorStation> pNoaccept = new List <OT_ErrorStation>(); if (para.StartTime.HasValue && para.EndTime.HasValue) { pNoaccept = db.OT_ErrorStation.Where(i => pStationNames.Contains(i.StaName)).ToList().Where(s => s.CalcuTime >= para.StartTime && s.CalcuTime <= para.EndTime).ToList(); } else { pNoaccept = db.OT_ErrorStation.Where(i => pStationNames.Contains(i.StaName)).ToList().Where(s => s.CalcuTime == para.StartTime).ToList(); } var nolist = pNoaccept.GroupBy(s => s.StaID); foreach (var s in nolist) { string pDicNmae = db.OT_Station.Single(m => m.Num == s.Key.ToString() && m.IsDelete == 0).Name; List <byte?> timePeriods = pNoaccept.Where(n => n.StaID == s.Key).Select(n => n.HourPer).OrderBy(n => n.Value).ToList(); ReportRelatedViewModels pData = new ReportRelatedViewModels(); string value = string.Empty; for (int i = 0; i < timePeriods.Count; i++) { value += timePeriods[i].Value.ToString() + "时、"; } pData.StationName = pDicNmae; pData.Time = value.Remove(value.Length - 1); pList.Add(pData); } return(pList); } } catch (Exception e) { SystemLog.GetInstance().Error(e.ToString()); return(null); } }
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; } }
public void Stop() { try { this.timer.Elapsed -= new System.Timers.ElapsedEventHandler(this.timer_Elapsed); this.timer.Enabled = false; SystemLog.GetInstance().Log.Info(string.Format("服务已停止:{0} ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")) + Environment.NewLine); } catch (Exception e) { SystemLog.GetInstance().Log.Error(string.Format("{0} 服务异常:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), e); } }
/// <summary> /// 报表14:各高速公路各收费站出口小时交通量 /// </summary> /// <returns></returns> public ActionResult RoadStaExHour() { try { HolidayConfigViewModel pHdayConfig = ReportFactory.Instance.GetHolidayConfigById(13); ViewBag.HolidayStartTime = pHdayConfig.HolidayStartTime.Value.ToString("yyyy年M月d日"); ViewBag.HolidayEndTime = pHdayConfig.HolidayEndTime.Value.ToString("yyyy年M月d日"); } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } return(View()); }
/// <summary> /// 报表6:重点城市出入境车辆数日报表 /// </summary> /// <returns></returns> public ActionResult CityDailyEnEx() { try { HolidayConfigViewModel pHdayConfig = ReportFactory.Instance.GetHolidayConfigById(6); ViewBag.StartTime = pHdayConfig.ForecastDate.Value.ToString("yyyy年M月d日"); ViewBag.HolidayStartTime = pHdayConfig.HolidayStartTime.Value.ToString("yyyy年M月d日"); ViewBag.HolidayEndTime = pHdayConfig.HolidayEndTime.Value.ToString("yyyy年M月d日"); } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } return(View()); }
/// <summary> ///报表8:假期交通量统计表 /// </summary> /// <returns></returns> public ActionResult HDaySta() { try { ForecastViewModel model = ReportFactory.Instance.report8.GetForecastWhere(); ViewBag.StartTime = model.ForecastDate.Value.ToString("yyyy年M月d日"); HolidayConfigViewModel pHdayConfig = ReportFactory.Instance.GetHolidayConfigById(8); ViewBag.HolidayStartTime = pHdayConfig.HolidayStartTime.Value.ToString("yyyy年M月d日"); ViewBag.HolidayEndTime = pHdayConfig.HolidayEndTime.Value.ToString("yyyy年M月d日"); } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } return(View()); }
/// <summary> /// 进行IoC的初始化 /// </summary> public static void Run() { try { //创建容器 IUnityContainer container = new UnityContainer(); UnityConfigurationSection configuration = ConfigurationManager.GetSection(UnityConfigurationSection.SectionName) as UnityConfigurationSection; configuration.Configure(container, "serviceContainer"); IBLL.ServicesFactory.Instance = container.Resolve(typeof(IBLL.ServicesFactory)) as IBLL.ServicesFactory; } catch (Exception ex) { SystemLog.GetInstance().Log.Error(ex.Message); } }
/// <summary> /// 定时执行方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer_Elapsed(object sender, ElapsedEventArgs e) { int pHourPer = DateTime.Now.Hour; int pTimePeriodMinute = DateTime.Now.Minute; if (pTimePeriodMinute == 2 || pTimePeriodMinute == 3) { try { DateTime pDt = DateTime.Today.AddHours(pHourPer); ServicesFactory.Instance.stagingReport.UpdateData(pDt, pHourPer); } catch (Exception ex) { SystemLog.GetInstance().Log.Info(string.Format(ex.Message)); } } }
/// <summary> ///报表9:收费公路运行情况 /// </summary> /// <returns></returns> public ActionResult RoadRunSit() { try { ConfigTimeViewModel model = ReportFactory.Instance.report9.GetRoadRunSitWhere(); ViewBag.HolidayStartTime = model.HolidayStartTime.Value.ToString("yyyy年M月d日"); ViewBag.HolidayEndTime = model.HolidayEndTime.Value.ToString("yyyy年M月dd日"); ViewBag.ComparedStartTime = model.ComparedStartTime.Value.ToString("yyyy年M月d日"); ViewBag.ComparedEndTime = model.ComparedEndTime.Value.ToString("yyyy年M月d日"); ForecastViewModel modelForecast = ReportFactory.Instance.report9.GetForecastWhere(); ViewBag.ForecastDate = modelForecast.ForecastDate.Value.ToString("yyyy年M月d日"); ViewBag.ForecastFloat = modelForecast.ForecastFloat; } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } return(View()); }
/// <summary> /// 报表4:重要运输通道主线收费站数据日报表 /// </summary> /// <returns></returns> public ActionResult ImpStaDaily() { try { ForecastViewModel model = ReportFactory.Instance.report1.GetForecastWhere(new QueryParameters() { ReportType = 4 }); ViewBag.StartTime = model.ForecastDate.Value.ToString("yyyy年M月d日"); HolidayConfigViewModel pHdayConfig = ReportFactory.Instance.GetHolidayConfigById(4); ViewBag.HolidayStartTime = pHdayConfig.HolidayStartTime.Value.ToString("yyyy年M月d日"); ViewBag.HolidayEndTime = pHdayConfig.HolidayEndTime.Value.ToString("yyyy年M月d日"); } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } return(View()); }
// // GET: /DownFile/ public void Downfile() { try { string config = Common.Utility.GetDownLoadPath(); string reallyname = Request.QueryString["name"]; string reptype = Request.QueryString["reporttype"]; string filepath = config; string FullFileName = string.Empty; if (filepath.Substring(filepath.Length - 1) != "\\") { filepath = filepath + "\\"; } if (reptype != "all") { FullFileName = filepath + DateTime.Now.ToString("yyyyMMdd") + "\\" + reptype + "\\" + reallyname; } else { FullFileName = reallyname; reallyname = reallyname.Substring(reallyname.LastIndexOf("\\") + 1); } FileInfo info = new FileInfo(FullFileName); Response.Clear(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(reallyname)); // 添加头信息,指定文件大小,让浏览器能够显示下载进度 Response.AddHeader("Content-Length", info.Length.ToString()); Response.ContentType = "application/octet-stream"; // 把文件流发送到客户端 Response.WriteFile(info.FullName); // 停止页面的执行 Response.End(); } catch (Exception e) { SystemLog.GetInstance().Info(e); } }
/// <summary> /// 获取数据 /// </summary> public void UpdateData(DateTime pDt, int pHourPer) { try { using (DataSubmittedEntities db = new DataSubmittedEntities()) { string startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); SystemLog.GetInstance().Log.Info(string.Format("{0}:开始获取中间表数据", startTime)); db.SP_StaDataSource(pHourPer, pDt); string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); SystemLog.GetInstance().Log.Info(string.Format("{0}:结束获取中间表数据", endTime)); SystemLog.GetInstance().Log.Info(string.Format("统计中间表数据耗时{0}秒", (DateTime.Parse(endTime) - DateTime.Parse(startTime)).TotalSeconds)); this.State = 1; if (State == 1) { int timeHour; DateTime dt = pDt.AddHours(-1); if (pHourPer == 0) { timeHour = 23; } else { if (pHourPer == 1) { timeHour = 0; } else { timeHour = pHourPer - 1; } } this.Notify(new ThreadParameter(dt, timeHour)); } } } catch (Exception ex) { SystemLog.GetInstance().Log.Info(ex.Message); } }
/// <summary> /// 根据报表配置ID读取(假期和非假期表都存在HolidayConfig表) /// </summary> /// <param name="id"></param> /// <returns></returns> public OT_HDayConfig GetById(int id) { OT_HDayConfig pHolidayConfig = null; try { using (DataSubmittedEntities db = new DataSubmittedEntities()) { List <OT_HDayConfig> list = db.OT_HDayConfig.Where(s => s.Id == id).ToList(); if (list.Count > 0) { pHolidayConfig = list[0]; } } } catch (Exception ex) { SystemLog.GetInstance().Error(ex); pHolidayConfig = null; } return(pHolidayConfig); }
/// <summary> ///报表7:黄金周京津塘高速公路交通量统计表 /// </summary> /// <returns></returns> public ActionResult JJTHighWay() { try { AADTAndTransCalcuWViewModel pTemp = ReportFactory.Instance.report7.GetHdayExEnWhere(); IEnumerable <SelectListItem> pHolName = ReportFactory.Instance.DicGetListbyId((int)EDicParentId.Holiday).Select(i => new SelectListItem() { Value = i.DictId.ToString(), Text = i.Name, }); ViewBag.StartTime = pTemp.StartTime.ToString("yyyy年M月d日"); ViewBag.EndTime = pTemp.EndTime.ToString("yyyy年M月d日"); ViewBag.HolName = pHolName; ViewBag.HolidayId = pTemp.HolidayId.ToString(); } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } return(View()); }
/// <summary> /// 报表18:假期高速公路交通流量统计表 /// </summary> /// <returns></returns> public ActionResult HDayRoadSta() { try { HDayAADTViewModelParaViewModel pTemp = ReportFactory.Instance.report18.GetHDayAADTPara(); IEnumerable <SelectListItem> pHolName = ReportFactory.Instance.DicGetListbyId((int)EDicParentId.Holiday).Select(i => new SelectListItem() { Value = i.DictId.ToString(), Text = i.Name, }); ViewBag.StartTime = pTemp.StartTime.ToString("yyyy年M月d日"); ViewBag.EndTime = pTemp.EndTime.ToString("yyyy年M月d日"); ViewBag.HolName = pHolName; ViewBag.HolidayId = pTemp.HolidayId.ToString(); } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } return(View()); }
/// <summary> /// 保存文件 /// </summary> /// <param name="hssfworkbook"></param> /// <param name="filename"></param> /// <returns>返回文件保存路径</returns> private string SaveFile(IWorkbook hssfworkbook, string filename, QueryParameters para) { try { string pPath = config; if (pPath.Substring(pPath.Length - 1) != "\\") { pPath = pPath + "\\"; } var tmpPath = pPath + DateTime.Now.ToString("yyyyMMdd") + "\\" + para.ReportType; //创建存储目录 if (!Directory.Exists(tmpPath)) { Directory.CreateDirectory(tmpPath); } //创建文件 string path = tmpPath + "\\" + filename; FileStream files = new FileStream(path, FileMode.Create); hssfworkbook.Write(files); files.Close(); //添加数据导出记录 ContactInfo pContactinfo = new ContactInfo(); OT_ExportHis contactinfo = new OT_ExportHis(); contactinfo.Id = Guid.NewGuid(); contactinfo.DataDate = para.StartTime; contactinfo.HDayId = para.HolidayId; contactinfo.CalcuTime = DateTime.Now; contactinfo.SavePath = path; contactinfo.TableType = para.ReportType; pContactinfo.Create(contactinfo); return(filename); } catch (Exception e) { SystemLog.GetInstance().Error(e); } return(null); }
/// <summary> /// 触发事件 /// </summary> /// <param name="dt"></param> /// <param name="HourPer"></param> public void Notify(object prame) { ThreadParameter pThreadparameter = prame as ThreadParameter; //检查委托是否为空 UpdateEventHandler pEventHandler = Update; if (pEventHandler != null) { foreach (UpdateEventHandler handler in pEventHandler.GetInvocationList()) { try { //异步调用委托 handler.BeginInvoke(pThreadparameter.Datetime, pThreadparameter.HourPer, null, null); //循环调用每一个事件,防止其中一个报错,使得下面的事件不被执行 //handler(pThreadparameter.Datetime, pThreadparameter.HourPer); } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } } } }
/// <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="readworkbook"></param> /// <param name="para"></param> /// <returns></returns> public IWorkbook GenerateSheet(IWorkbook readworkbook, QueryParameters para) { try { using (DataSubmittedEntities db = new DataSubmittedEntities()) { //日期合计 //获取工作簿 ISheet sheet = readworkbook.GetSheetAt(0); int pDataCount = 0; if (para.EndTime.Value >= para.StartTime.Value) { pDataCount = (para.EndTime.Value - para.StartTime.Value).Days + 1; } //设置标题 var holidayName = db.OT_Dic.Where(a => a.Id == para.HolidayId).Select(a => a.Name).ToList(); string title = string.Format("天津市高速公路支队{0}年{1}假期流量表(出口)", ((DateTime)para.EndTime).Year, holidayName[0].ToString()); SetValue(sheet, 0, 0, title); //如果多于4天,则手动添加单元格 if (pDataCount > 4) { int pTemp = pDataCount - 4; //遍历创建所有单元格 //列 for (int i = 0; i < pTemp; i++) { //行--该模版有隐藏行 for (int n = 0; n < 19; n++) { IRow row = sheet.GetRow(n); ICell cell = row.CreateCell(9 + i);//创建列 cell.CellStyle = GetCellStyle(readworkbook, 1); } } } else if (pDataCount < 4)//如果小于4天,则删除列 { int pTemp = 4 - pDataCount; //遍历设置所有单元格没有边框 //列 for (int i = 0; i < pTemp; i++) { for (int n = 0; n < 19; n++) { ICell cell = sheet.GetRow(n).GetCell(i + 5 + pDataCount); cell.CellStyle = GetCellStyle(readworkbook, 0); } } } double?pSum = db.RP_HDayAADT.Where(s => DbFunctions.TruncateTime(s.CalcuTime) >= para.StartTime.Value && DbFunctions.TruncateTime(s.CalcuTime) <= para.EndTime.Value).Sum(s => s.Out); double?pLastSum = db.RP_HDayAADT.Where(s => DbFunctions.TruncateTime(s.CalcuTime) >= para.LastYearStart.Value && DbFunctions.TruncateTime(s.CalcuTime) <= para.LastYearEnd.Value).Sum(s => s.Out); double?Growth = null; if (pLastSum.HasValue && pLastSum != 0 && pLastSum != 0.0 && pSum.HasValue) { Growth = Math.Round((pSum.Value - pLastSum.Value) / pLastSum.Value, 2); } if (pSum.HasValue) { SetValue(sheet, 17, 2 + pDataCount, pSum.ToString()); SetValue(sheet, 18, 2 + pDataCount, pSum.ToString()); } if (pLastSum.HasValue) { SetValue(sheet, 17, 3 + pDataCount, pLastSum.ToString()); SetValue(sheet, 18, 3 + pDataCount, pLastSum.ToString()); } if (Growth.HasValue) { SetValue(sheet, 17, 4 + pDataCount, Growth.ToString()); SetValue(sheet, 18, 4 + pDataCount, Growth.ToString()); } //合并单元格 //标题行 SetCellRangeAddress(sheet, 0, 0, 0, 4 + pDataCount); //日期行 SetCellRangeAddress(sheet, 1, 1, 2, pDataCount + 1); //合并最后三列 SetCellRangeAddress(sheet, 1, 2, 2 + pDataCount, 2 + pDataCount); SetCellRangeAddress(sheet, 1, 2, 3 + pDataCount, 3 + pDataCount); SetCellRangeAddress(sheet, 1, 2, 4 + pDataCount, 4 + pDataCount); // SetValue(sheet, 1, 2 + pDataCount, "合计"); SetValue(sheet, 1, 3 + pDataCount, "去年同期总流量"); SetValue(sheet, 1, 4 + pDataCount, "同比增幅"); for (int i = 0; i < pDataCount; i++) { DateTime? pDt = para.StartTime.Value.AddDays(i); List <RP_HDayAADT> pHourAADTList = db.RP_HDayAADT.Where(s => DbFunctions.TruncateTime(s.CalcuTime) == pDt).ToList(); if (pHourAADTList.Count == 1) { SetValue(sheet, 17, 2 + i, pHourAADTList.Sum(s => s.Out).ToString()); SetValue(sheet, 18, 2 + i, pHourAADTList.Sum(s => s.Out).ToString()); } //添加表头 SetValue(sheet, 2, 2 + i, para.StartTime.Value.AddDays(i).ToString("M月d日")); } } } catch (Exception ex) { SystemLog.GetInstance().Info(ex.Message); } return(readworkbook); }