示例#1
0
        /// <summary>
        /// 导出所有能源信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string ExportItemEnergy(string starttime, string endtime, string objectid, string timeunit, string counttype, string SavePath)
        {
            try
            {
                Itemcode itemcodeBll = new Itemcode();

                ReportQueryModelNew model = new ReportQueryModelNew();
                model.startime   = DateTime.Parse(starttime);
                model.endtime    = DateTime.Parse(endtime);
                model.objectid   = objectid;
                model.timeunit   = (ReportStyleNew)(int.Parse(timeunit));
                model.objecttype = 0;
                model.itemcode   = counttype;

                string strPath    = SavePath; // AppDomain.CurrentDomain.BaseDirectory + "temp_file\\";
                string strTemPath = AppDomain.CurrentDomain.BaseDirectory + "ExcelTemplate\\项目能耗查询.xls";

                IList <Model.Itemcode> itemcode = itemcodeBll.GetItemcodeList(
                    " and itemcodenumber = '" + counttype + "'", "");
                string strUnit = "mch";
                if (itemcode.Count > 0)
                {
                    strUnit = itemcode[0].Unit;
                }

                #region 第2种方法
                DataTable dtlist = GetItemcodeData(model);

                string name = GetBaseLayerObjectName(model.objectid);


                #endregion

                if (dtlist != null)
                {
                    string temp_path = strPath; //AppDomain.CurrentDomain.BaseDirectory + "temp_file\\";
                    if (!Directory.Exists(temp_path))
                    {
                        Directory.CreateDirectory(temp_path);
                        string[] files = Directory.GetFiles(temp_path);
                        foreach (string fn in files)
                        {
                            File.Delete(temp_path + fn);
                        }
                    }
                    string save_path = DateTime.Now.Ticks + ".xls";

                    string templatePath = strTemPath; // AppDomain.CurrentDomain.BaseDirectory + "template\\区域能耗查询.xls";

                    string        datetime = model.startime.ToString("yyyy-MM-dd") + "~" + (model.timeunit == ReportStyleNew.DayStyle ? model.endtime.ToString("yyyy-MM-dd HH:59:59") : model.endtime.ToString("yyyy-MM-dd"));
                    TemplateParam param    = new TemplateParam(name, new CellParam(0, 0), datetime, new CellParam(3, 0), false, new CellParam(4, 0));
                    //param.DataColumn = new[] { 0, 3, 6, 7, 8, 9};
                    param.DataColumn = new[] { 0, 1, 3, 6, 7 };

                    param.ItemUnit     = "能耗值:(" + strUnit + ")";
                    param.ItemUnitCell = new CellParam(4, 4);
                    dtlist.TableName   = "能耗查询统计";

                    string strDownFile = temp_path + save_path;

                    //return "{\"status\":\"success\",\"msg\":\"" + "/temp_file/" + save_path + "\"}";
                    ExportHelper.ExportExcel(dtlist, strDownFile, strTemPath, param);

                    //return "{\"status\":\"success\",\"msg\":\"" + "/temp_file/" + save_path + "\"}";

                    return("{\"status\":\"success\",\"msg\":\"" + "/temp_file/" + save_path + "\"}");
                }
                else
                {
                    return("{\"status\":\"error\",\"msg\":\"导出失败:当前无任何数据\"}");
                }
            }
            catch (Exception ex)
            {
                return("{\"status\":\"error\",\"msg\":\"导出失败:没有数据!\"}");
            }
        }