Exemplo n.º 1
0
        /// <summary>
        /// 真正处理报表数据和返回视图的地方,预览和查看公用
        /// </summary>
        /// <param name="report"></param>
        /// <param name="cTime"></param>
        /// <param name="pId"></param>
        /// <returns></returns>
        private ActionResult HandleViewReport(DefineReport report, int tId, string cTime, string pId, string type)
        {
            ViewData["Culture"] = Session["Culture"];
            ViewData["rId"] = report.Id;
            ViewData["tId"] = tId.ToString();
            ViewData["cTime"] = cTime;
            ViewData["pId"] = pId;
            if (!(string.IsNullOrEmpty(pId)))
            {
                if (string.IsNullOrEmpty(cTime)) cTime = CalenderUtil.curDateWithTimeZone(report.plant.timezone, "yyyyMMdd");
            }
            else
            {
                if (string.IsNullOrEmpty(cTime)) cTime = CalenderUtil.curDateWithTimeZone(report.user.timezone, "yyyyMMdd");
            }

            ViewData["time"] = cTime;
            if (tId == DataReportType.TOTAL_REPORT_CODE)
            {
                IList<int> workYears = null;
                if (!(string.IsNullOrEmpty(pId)))
                {
                    workYears = collectorYearDataService.GetWorkYears(report.plant);
                    cTime = CalenderUtil.curDateWithTimeZone(report.plant.timezone, "yyyy");
                }
                else
                {
                    workYears = collectorYearDataService.GetWorkYears(report.user.plants);
                    cTime = CalenderUtil.curDateWithTimeZone(report.user.timezone, "yyyy");
                }
                if (workYears.Count > 0)
                {
                    cTime = workYears[0] + "-" + workYears[workYears.Count - 1];
                    ViewData["time"] = cTime;
                }
                else
                {
                    cTime += "-" + cTime;
                    ViewData["time"] = Resources.SunResource.NO_WORK_YEARS;
                }
            }
            else if (tId == DataReportType.WEEK_REPORT_CODE)
            {
                string[] wTime = reportService.convertToDateArr(tId, cTime);
                int year1 = int.Parse(wTime[0].Substring(0, 4));
                int mm1 = int.Parse(wTime[0].Substring(4, 2));
                int dd1 = int.Parse(wTime[0].Substring(6, 2));
                int year2 = int.Parse(wTime[1].Substring(0, 4));
                int mm2 = int.Parse(wTime[1].Substring(4, 2));
                int dd2 = int.Parse(wTime[1].Substring(6, 2));
                string weekTime = year1 + "/" + mm1 + "/" + dd1 + "-" + year2 + "/" + mm2 + "/" + dd2;
                ViewData["time"] = weekTime;
            }
            else if (tId == DataReportType.MONTH_REPORT_CODE)
            {
                cTime = cTime.Split('-').Length > 2 ? cTime.Substring(0, cTime.LastIndexOf("-")) : cTime;
                ViewData["time"] = cTime;
            }
            else if (tId == DataReportType.YEAR_REPORT_CODE)
            {
                cTime = cTime.Split('-').Length > 2 ? cTime.Substring(0, cTime.IndexOf("-")) : cTime;
                ViewData["time"] = cTime;
            }

            if (report != null)
            {
                IList<Object> datalist = reportService.getDatabyItemCodes(report, cTime);
                if (datalist.Count != 0)
                {
                    ViewData["deviceHash"] = (Hashtable)datalist[2];
                    ViewData["plantItemCodes"] = addIntNumtoList((IList<int>)datalist[0]);
                    ViewData["plantHash"] = (Hashtable)datalist[1];
                    ViewData["deviceItemCodes"] = (IList<int>)datalist[3];
                }
                else
                {
                    ViewData["NoData"] = LanguageUtil.getDesc("NODATA");
                }
            }
            else
            {
                ViewData["NoData"] = LanguageUtil.getDesc("NODATA");
            }

            if (!(string.IsNullOrEmpty(pId)))
            {
                base.FillPlantYears(int.Parse(pId));

                string yyyy = ViewData["cTime"] != null ? ViewData["cTime"] as string : DateTime.Now.Year.ToString();

                yyyy = yyyy.Length >= 4 ? yyyy.Substring(0, 4) : yyyy;

                if (ViewData[ComConst.WorkYears] != null && (ViewData[ComConst.WorkYears] as IList<SelectListItem>).Count > 0)
                {
                    foreach (SelectListItem item in ViewData[ComConst.WorkYears] as IList<SelectListItem>)
                    {
                        item.Selected = false;
                        item.Selected = item.Text.Equals(yyyy);
                    }
                }

                if (tId == DataReportType.TODAY_REPORT_CODE)
                {
                    if (string.IsNullOrEmpty(type))
                        return View("ViewDayReport", report);
                    else
                        return View("EmailViewDayReport", report);
                }
                else
                {
                    if (string.IsNullOrEmpty(type))
                        return View("ViewNotDayReport", report);
                    else
                        return View("EmailViewNotDayReport", report);
                }
            }
            else
            {
                base.FillAllPlantYears(report.user);

                string yyyy = ViewData["cTime"] != null ? ViewData["cTime"] as string : DateTime.Now.Year.ToString();

                yyyy = yyyy.Length >= 4 ? yyyy.Substring(0, 4) : yyyy;

                if (ViewData[ComConst.WorkYears] != null && (ViewData[ComConst.WorkYears] as IList<SelectListItem>).Count > 0)
                {
                    foreach (SelectListItem item in ViewData[ComConst.WorkYears] as IList<SelectListItem>)
                    {
                        item.Selected = false;
                        item.Selected = item.Text.Equals(yyyy);
                    }

                }
                if (string.IsNullOrEmpty(type))
                    return View("ViewUserReport", report);
                else
                    return View("EmailViewUserReport", report);
            }
        }
Exemplo n.º 2
0
 public ActionResult SaveReport(DefineReport report, ReportConfig rc)
 {
     int lastId = 0;
     if (report.PlantId == 0)
     {
         report.UserId = (UserUtil.getCurUser()).id;//如果是所有电站就取当前用户ID
     }
     lastId = reportService.AddRunReport(report);
     rc.reportId = lastId;
     if (string.IsNullOrEmpty(rc.email) == false)
         rc.email = rc.email.Replace(";", ",");
     reportConfigService.SendEventReport(rc);
     if (report.PlantId == 0)
     {
         return Redirect("/user/AllPlantsReport");
     }
     else
     {
         return RedirectToAction("PlantReport", "plant", new { @id = report.PlantId });
     }
 }
Exemplo n.º 3
0
        public ActionResult UpdateReport(DefineReport report, ReportConfig rc)
        {
            if (report.PlantId == 0)
            {
                report.UserId = (UserUtil.getCurUser()).id;
            }
            rc.reportId = report.Id;

            if (string.IsNullOrEmpty(rc.email) == false)
                rc.email = rc.email.Replace(";", ",");

            reportConfigService.UpdateReportConfig(rc);
            reportService.EditReportById(report);

            if (report.PlantId == 0)
            {
                return Redirect("/user/AllPlantsReport");
            }
            else
            {
                return RedirectToAction("PlantReport", "plant", new { @id = report.PlantId });
            }
        }
Exemplo n.º 4
0
 public int AddRunReport(DefineReport report)
 {
     return  _runReportDao.AddRunReport(report);
 }
Exemplo n.º 5
0
 /// <summary>
 /// 报表预览 包括所有电站和单个电站
 /// 其实报表预览就是查看唯一区别是要重新组织成一个报表对象作为输入而已
 /// </summary>
 /// <param name="id">数据项名称</param>
 /// <param name="tId">报表类型</param>
 /// <param name="rName">报表名称</param>
 /// <returns></returns>
 public ActionResult PreviewReport(string userId, string dataItem, int tId, string rName, string cTime, string plantId, string type)
 {
     ViewData["preview"] = "preview";
     DefineReport report = new DefineReport();
     if (string.IsNullOrEmpty(plantId) || plantId.Equals("null"))
     {
         plantId = null;
         report.user = UserService.GetInstance().Get(int.Parse(userId));
         report.UserId = report.user.id;
     }
     else
     {
         report.PlantId = int.Parse(plantId);
         report.plant = PlantService.GetInstance().GetPlantInfoById(report.PlantId);
     }
     report.ReportName = rName;
     report.ReportType = tId;
     report.dataitem = dataItem;
     return HandleViewReport(report, tId, cTime, plantId, type);
 }
Exemplo n.º 6
0
 /// <summary>
 /// 根据具体代码取得对应数据
 /// </summary>
 /// <param name="dataItemCode">数据项代码</param>
 /// <param name="datetime">数据时间,格式:yyyyMMdd</param>
 /// <returns></returns>
 private Hashtable getPlantDatabyReportType(DefineReport defineReport,string startTime, string endTime)
 {
     Plant plant = defineReport.plant;//所在电站
     User user = defineReport.user;//所属用户
     bool isPlantReport = plant == null?false:true;
     if (isPlantReport)
     {
         User plantUser = UserService.GetInstance().Get(int.Parse(plant.userID.ToString()));
         plant.currencies = plantUser.currencies;
         return getPlantItemData(plant, defineReport.ReportType, startTime, endTime);
     }
     else
         return getUserItemData(user, defineReport.ReportType, startTime, endTime);
 }
Exemplo n.º 7
0
        private Hashtable construtPlantReportObj(int plantid, int type, string dataitem)
        {
            Hashtable table = new Hashtable();
            string plantName = PlantService.GetInstance().GetPlantInfoById(plantid).name+" ";
            DefineReport report1 = new DefineReport()
            {
                ReportType = type,
                ReportName =plantName+"-"+DataReportType.getNameByCode(type),
                SaveTime = DateTime.Now,
                dataitem = dataitem,
                PlantId = plantid
            };
            ReportConfig config1 = new ReportConfig()
            {
                sendFormat = "html",
                email = "",
                sendMode = "2",
                reportId = 0,
                plantId = plantid

            };
            table.Add(0, report1);
            table.Add(1, config1);
            return table;
        }
Exemplo n.º 8
0
        private Hashtable construtAllPlantsReportObj(int userid, int type, string dataitem)
        {
            Hashtable table = new Hashtable();
            DefineReport report1 = new DefineReport()
            {
                ReportType = type,
                ReportName = "All plants-" + DataReportType.getNameByCode(type),
                SaveTime = DateTime.Now,
                dataitem = dataitem,
                UserId = userid
            };
            ReportConfig config1 = new ReportConfig()
            {
                tinterval = "4",
                sendFormat = "html",
                sendMode = "2",
                email = "",
                reportId = 0,
                plantId = 0

            };
            table.Add(0,report1);
            table.Add(1,config1);
            return table;
        }
Exemplo n.º 9
0
        /// <summary>
        /// 根据数据项代码数组取得对应数据项的数据
        /// </summary>
        /// <param name="itemCodes">数据项代码</param>
        /// <param name="datetime">报表数据的时间,格式yyyyMMdd</param>
        /// <returns>返回map结构,key为数据项名称,value为值</returns>
        public IList<Object> getDatabyItemCodes(DefineReport defineReport, string datetime)
        {
            string[] datearr = convertToDateArr(defineReport.ReportType, datetime);
            IList<Object> resList = new List<Object>();
            Hashtable deviceDataHash = new Hashtable();
            IList<int> plantDatacodeList = new List<int>() ;
            Hashtable plantDataHash = getPlantDatabyReportType(defineReport, datearr[0], datearr[1]);
            //取得设备数据项数组
            IList<int> deviceItemCodes = new List<int>();
            foreach (int itemcode in DataItem.deviceDataItemMap)
            {
                if (defineReport.dataItems.Contains(itemcode.ToString()))
                    deviceItemCodes.Add(itemcode);
            }

            foreach(string itemcode in defineReport.dataItems){
                if (string.IsNullOrEmpty(itemcode)) continue;
                if (!DataItem.deviceDataItemMap.Contains(int.Parse(itemcode))){
                    plantDatacodeList.Add(int.Parse(itemcode));
                }
            }

            //取得设备数据
            if (deviceItemCodes.Count > 0 && defineReport.plant!=null)
            {
                deviceDataHash = this.getPlantDeviceData(defineReport.plant, defineReport.ReportType, deviceItemCodes, datearr[0], datearr[1]);
            }
            resList.Add(plantDatacodeList);
            resList.Add(plantDataHash);
            resList.Add(deviceDataHash);
            resList.Add(deviceItemCodes);

            return resList;
        }
Exemplo n.º 10
0
 public int EditReportById(DefineReport report)
 {
     return _runReportDao.EditReportById(report);
 }