Exemple #1
0
        /// <summary>
        /// 导出csv格式的图表数据
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="serieNo"></param>
        /// <returns></returns>
        public ActionResult ExportCsvChart(string filename, string serieNo)
        {
            CsvStreamWriter scvWriter  = new CsvStreamWriter();
            ChartData       chartData  = TempDataUtil.getChartData(serieNo);
            string          reportname = string.Empty;

            if (chartData != null)
            {
                reportname = (filename.Equals("chart") ? "" : filename) + chartData.name.Replace("/", "").Replace(" ", "");
                IList <string> dataList = new List <string>();
                string         xname    = Resources.SunResource.CUSTOMREPORT_CHART_TIME;
                if (chartData.names.Length > 0 && !string.IsNullOrEmpty(chartData.names[0]))
                {
                    xname = chartData.names[0] + "[" + chartData.units[0] + "]";
                }
                dataList.Add(xname);
                dataList.Add(convertArrtoStr(chartData.categories));
                foreach (YData ydata in chartData.series)
                {
                    dataList.Add(ydata.name);
                    dataList.Add(convertArrtoStr(ydata.data));
                }
                scvWriter.AddStrDataList(dataList);
            }
            string fullFile = Server.MapPath("/") + "tempexportfile\\" + serieNo + ".csv";

            scvWriter.Save(fullFile);
            //转化为csv格式的字符串
            ActionResult tmp = File(fullFile, "text/csv; charset=UTF-8", urlcode(reportname) + ".csv");

            return(tmp);
        }
        /// <summary>
        /// 输出csv文件
        /// </summary>
        /// <param name="allmts"></param>
        /// <param name="timemtMap"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public ActionResult DownLoadCsvRunData(IList <string> allmts, IDictionary <string, IDictionary <string, string> > timemtMap, string filename)
        {
            CsvStreamWriter scvWriter = new CsvStreamWriter();

            //输入出到csv文件中的数据列表
            IList <string> dataList = new List <string>();

            //设置抬头行
            dataList.Add("                        " + filename + "                       ");
            //循环设置数据行
            //设置标题行
            allmts.Insert(0, Resources.SunResource.REPORT_TIME);
            dataList.Add(scvWriter.ConvertToSaveLine(allmts));
            //数据行临时list
            IList <string> tempList = new List <string>();

            foreach (string key in timemtMap.Keys)
            {
                dataList.Add(scvWriter.ConvertToSaveCell(key) + "," + scvWriter.ConvertToSaveLine(timemtMap[key].Values));
            }

            scvWriter.AddStrDataList(dataList);
            scvWriter.Save(Server.MapPath("/") + "tempexportfile/" + filename + ".csv");
            return(File(Server.MapPath("/") + "tempexportfile/" + filename + ".csv", "text/csv; charset=UTF-8", urlcode(filename) + ".csv"));
        }
Exemple #3
0
        public ActionResult Units_Output(int id)
        {
            Plant             plant      = FindPlant(id);
            IList <PlantUnit> plantUnits = PlantUnitService.GetInstance().GetAllPlantUnitsByPlantId(id);
            CsvStreamWriter   writer     = new CsvStreamWriter();
            IList <string>    listData   = new List <string>();

            listData.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},", Resources.SunResource.PLANT_UNIT_LIST_STATUS, Resources.SunResource.PLANT_UNIT_DATA_SOURCE_CODE
                                       , Resources.SunResource.PLANT_UNIT_LIST_UNIT_NAME,
                                       Resources.SunResource.PLANT_UNIT_LIST_POWER + "(kW)",
                                       Resources.SunResource.PLANT_UNIT_LIST_YEAR_ENERGY + "(kWh)",
                                       Resources.SunResource.PLANT_UNIT_LIST_ENERGY + "(kWh)",
                                       Resources.SunResource.PLANT_UNIT_LIST_MONTH_ENERGY + "(kWh)",
                                       Resources.SunResource.PLANT_UNIT_LIST_MONTH_ENERGY_KWP + "(kWh/kWp)",
                                       Resources.SunResource.PLANT_UNIT_LIST_YEAR_ENERGY_KWP + "(kWh/kWp)"
                                       ));

            CollectorMonthDayData cmData = null;
            CollectorYearData     cyData = null;

            foreach (PlantUnit unit in plantUnits)
            {
                float currentMonthEnergy = 0;
                float currentYearEnergy  = 0;
                cmData             = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(DateTime.Now.Year, unit.collector.id, DateTime.Now.Month);
                currentMonthEnergy = cmData == null ? 0 : cmData.count();
                cyData             = CollectorYearDataService.GetInstance().GetCollectorYearData(unit.collector.id, DateTime.Now.Year);
                currentYearEnergy  = cyData == null ? 0 : cyData.dataValue;
                listData.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},", unit.isWork(plant.timezone) ? Resources.SunResource.MONITORITEM_WORKING : Resources.SunResource.MONITORITEM_STOPPED, string.Format("\t{0}", unit.collector.code)
                                           , string.Format("\t{0}", unit.displayname),
                                           unit.TodayPower(plant.timezone).ToString(),
                                           currentYearEnergy.ToString(),
                                           unit.displayTotalEnergy.ToString(),
                                           currentMonthEnergy.ToString(),
                                           Math.Round(currentMonthEnergy / unit.chartPower, 2).Equals(double.NaN) ? "0" : Math.Round(currentMonthEnergy / unit.chartPower, 2).ToString(),
                                           Math.Round(currentYearEnergy / unit.chartPower, 2).Equals(double.NaN) ? "0" : Math.Round(currentYearEnergy / unit.chartPower, 2).ToString()
                                           ));
            }

            writer.AddStrDataList(listData);


            string fullFile = Server.MapPath("/") + "tempexportfile\\" + Resources.SunResource.PLANT_UNIT_LIST_FILENAME + ".csv";

            writer.Save(fullFile);
            //转化为csv格式的字符串
            ActionResult tmp = File(fullFile, "text/csv; charset=UTF-8", urlcode(Resources.SunResource.PLANT_UNIT_LIST_FILENAME) + ".csv");

            return(tmp);
        }
        public ActionResult DownLoadDayReport(string id, string reportId, string cTime)
        {
            DefineReport    report         = reportService.GetRunReportById(reportId);
            int             tId            = report.ReportType;
            IList <string>  dataList       = new List <string>();
            IList <object>  obj            = reportService.getDatabyItemCodes(report, cTime);
            IList <int>     itemCode       = addIntNumtoList(obj[0] as List <int>);
            Hashtable       plantDataHash  = obj[1] as Hashtable;
            Hashtable       deviceDataHash = obj[2] as Hashtable;
            CsvStreamWriter csv            = new CsvStreamWriter();

            dataList.Add("                        " + report.ReportName + "                       ");
            ArrayList list2 = new ArrayList();

            list2.Add("                                         " + Resources.SunResource.REPORT_VIEW_TIME);
            list2.Add(cTime);
            dataList.Add(csv.ConvertToSaveLine(list2));
            dataList.Add(Resources.SunResource.REPORT_PLANT_COUNT_DATA);
            ArrayList list3 = new ArrayList();
            ArrayList list4 = new ArrayList();
            int       i     = 1;

            foreach (int code in itemCode)
            {
                int    tmpcode = code;
                string keystr = " ", keyvalue = " ";

                if (i == 5)
                {
                    i = 1;
                }
                else
                {
                    i++;
                }
                if (tmpcode != 0)
                {
                    keystr   = DataItem.getNameByCode(tmpcode);
                    keyvalue = plantDataHash[tmpcode].ToString();
                    list3.Add(keystr);
                    list3.Add(keyvalue);
                }
            }
            dataList.Add(csv.ConvertToSaveLine(list3));
            dataList.Add(Resources.SunResource.REPORT_DEVICE_COUNT_DATA);


            list4.Add(Resources.SunResource.REPORT_COUNT_ITEM);
            list4.Add(Resources.SunResource.REPORT_COUNT_DEVICE);
            list4.Add("7:00");
            list4.Add("8:00");
            list4.Add("9:00");
            list4.Add("10:00");
            list4.Add("11:00");
            list4.Add("12:00");
            list4.Add("13:00");
            list4.Add("14:00");
            list4.Add("15:00");
            list4.Add("16:00");
            list4.Add("17:00");
            list4.Add("18:00");
            list4.Add("19:00");
            list4.Add(Resources.SunResource.REPORT_COUNT_TODAYSUN);
            dataList.Add(csv.ConvertToSaveLine(list4));

            foreach (DictionaryEntry de in deviceDataHash)
            {
                i = 1;
                string tmpcode = de.Key.ToString();
                string keystr = "", unit = "";
                if (!tmpcode.StartsWith(" "))
                {
                    keystr = DataItem.getNameByCode(int.Parse(tmpcode));
                    unit   = MonitorType.getMonitorTypeByCode(int.Parse(tmpcode)).unit;
                }
                IList <string[]> dataArrList = (IList <string[]>)de.Value;
                for (int k = 1; k < dataArrList.Count; k++)
                {
                    ArrayList list5   = new ArrayList();
                    string[]  dataArr = dataArrList[k];
                    if (i == 1)
                    {
                        i++;
                        list5.Add(keystr + " " + unit);

                        list5.Add(dataArr[1]);
                        list5.Add(dataArr[2]);
                        list5.Add(dataArr[3]);
                        list5.Add(dataArr[4]);
                        list5.Add(dataArr[5]);
                        list5.Add(dataArr[6]);
                        list5.Add(dataArr[7]);
                        list5.Add(dataArr[8]);
                        list5.Add(dataArr[9]);
                        list5.Add(dataArr[10]);
                        list5.Add(dataArr[11]);
                        list5.Add(dataArr[12]);
                        list5.Add(dataArr[13]);
                        list5.Add(dataArr[14]);
                        list5.Add(dataArr[15]);
                    }
                    else
                    {
                        list5.Add(" ");
                        list5.Add(dataArr[1]);
                        list5.Add(dataArr[2]);
                        list5.Add(dataArr[3]);
                        list5.Add(dataArr[4]);
                        list5.Add(dataArr[5]);
                        list5.Add(dataArr[6]);
                        list5.Add(dataArr[7]);
                        list5.Add(dataArr[8]);
                        list5.Add(dataArr[9]);
                        list5.Add(dataArr[10]);
                        list5.Add(dataArr[11]);
                        list5.Add(dataArr[12]);
                        list5.Add(dataArr[13]);
                        list5.Add(dataArr[14]);
                        list5.Add(dataArr[15]);
                    }
                    dataList.Add(csv.ConvertToSaveLine(list5));
                }
            }
            CsvStreamWriter scvWriter = new CsvStreamWriter();

            scvWriter.AddStrDataList(dataList);
            scvWriter.Save(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv");
            //转化为csv格式的字符串
            //string res="dsfdsf";
            //byte[] bytes = Encoding.Default.GetBytes(res);
            return(File(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv", "text/csv; charset=UTF-8", urlcode(report.ReportName.Replace(" ", "") + "-" + cTime) + ".csv"));
        }
        public ActionResult DownLoadNotDayReport(string id, string reportId, string cTime)
        {
            DefineReport report   = reportService.GetRunReportById(reportId);
            int          tId      = report.ReportType;
            string       weekTime = string.Empty;

            if (tId == DataReportType.TOTAL_REPORT_CODE)
            {
                IList <int> workYears = null;
                if (!(string.IsNullOrEmpty(id)))
                {
                    workYears = collectorYearDataService.GetWorkYears(report.plant);
                }
                else
                {
                    workYears = collectorYearDataService.GetWorkYears(report.user.plants);
                }
                if (workYears.Count > 0)
                {
                    cTime = workYears[0] + "-" + workYears[workYears.Count - 1];
                }
            }
            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));
                weekTime = year1 + "/" + mm1 + "/" + dd1 + "-" + year2 + "/" + mm2 + "/" + dd2;
            }
            IList <string>  dataList       = new List <string>();
            IList <object>  obj            = reportService.getDatabyItemCodes(report, cTime);
            IList <int>     itemCode       = addIntNumtoList(obj[0] as List <int>);
            Hashtable       plantDataHash  = obj[1] as Hashtable;
            Hashtable       deviceDataHash = obj[2] as Hashtable;
            CsvStreamWriter csv            = new CsvStreamWriter();

            dataList.Add("                        " + report.ReportName + "                       ");
            ArrayList list2 = new ArrayList();

            list2.Add("                                         " + Resources.SunResource.REPORT_VIEW_TIME);
            if (tId == DataReportType.WEEK_REPORT_CODE)
            {
                list2.Add(weekTime);
            }
            else
            {
                list2.Add(cTime);
            }
            dataList.Add(csv.ConvertToSaveLine(list2));
            dataList.Add(Resources.SunResource.REPORT_PLANT_COUNT_DATA);
            ArrayList list3 = new ArrayList();
            ArrayList list4 = new ArrayList();
            int       i     = 1;

            foreach (int code in itemCode)
            {
                int    tmpcode = code;
                string keystr = " ", keyvalue = " ";

                if (i == 5)
                {
                    i = 1;
                }
                else
                {
                    i++;
                }
                if (tmpcode != 0)
                {
                    keystr   = DataItem.getNameByCode(tmpcode);
                    keyvalue = plantDataHash[tmpcode].ToString();
                    list3.Add(keystr);
                    list3.Add(keyvalue);
                }
            }
            dataList.Add(csv.ConvertToSaveLine(list3));
            dataList.Add(Resources.SunResource.REPORT_DEVICE_COUNT_DATA);

            foreach (DictionaryEntry de in  deviceDataHash)
            {
                i = 1;
                string tmpcode = de.Key.ToString();
                string keystr = "", unit = "";
                if (!tmpcode.StartsWith(" "))
                {
                    keystr = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE).name;
                    unit   = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE).unit;
                }
                IList <string[]> dataArrList = (IList <string[]>)de.Value;
                for (int k = 0; k < dataArrList.Count; k++)
                {
                    ArrayList list5   = new ArrayList();
                    string[]  dataArr = dataArrList[k];
                    if (i == 1)
                    {
                        i++;
                        foreach (string v in dataArr)
                        {
                            list5.Add(v);
                        }
                    }
                    else if (i == 2)
                    {
                        i++;
                        list5.Add(keystr + " " + unit);
                        for (int n = 1; n < dataArr.Length; n++)
                        {
                            list5.Add(dataArr[n]);
                        }
                    }
                    else
                    {
                        for (int m = 0; m < dataArr.Length; m++)
                        {
                            list5.Add(dataArr[m] == null?" ":dataArr[m]);
                        }
                    }
                    dataList.Add(csv.ConvertToSaveLine(list5));
                }
            }
            CsvStreamWriter scvWriter = new CsvStreamWriter();

            scvWriter.AddStrDataList(dataList);
            scvWriter.Save(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv");
            //转化为csv格式的字符串
            //string res="dsfdsf";
            //byte[] bytes = Encoding.Default.GetBytes(res);
            return(File(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv", "text/csv; charset=UTF-8", urlcode(report.ReportName.Replace(" ", "") + "-" + cTime) + ".csv"));
        }
        public ActionResult DownLoadAllPlantsReport(string id, string reportId, string cTime)
        {
            DefineReport report   = reportService.GetRunReportById(reportId);
            int          tId      = report.ReportType;
            string       weekTime = string.Empty;

            if (tId == DataReportType.TOTAL_REPORT_CODE)
            {
                IList <int> workYears = null;
                if (!(string.IsNullOrEmpty(id)))
                {
                    workYears = collectorYearDataService.GetWorkYears(report.plant);
                }
                else
                {
                    workYears = collectorYearDataService.GetWorkYears(report.user.plants);
                }
                if (workYears.Count > 0)
                {
                    cTime = workYears[0] + "-" + workYears[workYears.Count - 1];
                }
            }
            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));
                weekTime = year1 + "/" + mm1 + "/" + dd1 + "-" + year2 + "/" + mm2 + "/" + dd2;
            }
            IList <string>  dataList       = new List <string>();
            IList <object>  obj            = reportService.getDatabyItemCodes(report, cTime);
            IList <int>     itemCode       = addIntNumtoList(obj[0] as List <int>);
            Hashtable       plantDataHash  = obj[1] as Hashtable;
            Hashtable       deviceDataHash = obj[2] as Hashtable;
            CsvStreamWriter csv            = new CsvStreamWriter();

            dataList.Add("                        " + report.ReportName + "                       ");

            ArrayList list2 = new ArrayList();

            list2.Add("                                         " + Resources.SunResource.REPORT_VIEW_TIME);
            if (tId == 2)
            {
                list2.Add(weekTime);
            }
            else
            {
                list2.Add(cTime);
            }
            dataList.Add(csv.ConvertToSaveLine(list2));
            dataList.Add(Resources.SunResource.REPORT_PLANT_COUNT_DATA);
            ArrayList list3 = new ArrayList();

            int i = 1;

            foreach (int code in itemCode)
            {
                int    tmpcode = code;
                string keystr = " ", keyvalue = " ";

                if (i == 5)
                {
                    i = 1;
                }
                else
                {
                    i++;
                }

                if (tmpcode != 0)
                {
                    keystr   = DataItem.getNameByCode(tmpcode);
                    keyvalue = plantDataHash[tmpcode].ToString();
                    list3.Add(keystr);
                    list3.Add(keyvalue);
                }
            }
            dataList.Add(csv.ConvertToSaveLine(list3));
            CsvStreamWriter scvWriter = new CsvStreamWriter();

            scvWriter.AddStrDataList(dataList);
            scvWriter.Save(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv");
            //转化为csv格式的字符串
            //string res="dsfdsf";
            //byte[] bytes = Encoding.Default.GetBytes(res);

            return(File(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv", "text/csv; charset=UTF-8", urlcode(report.ReportName.Replace(" ", "") + "-" + cTime) + ".csv"));
        }