using MiniExcelLibs; using Serenity.Services; using SqlSugar; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using HT.Cloud.Domain.ReportManage; namespace HT.Cloud.Service.ReportManage { public class HistoryReportService : BaseService, IDenpendency { public HistoryReportService(ISqlSugarClient context) : base(context) { } public async Task GetReportFileName(string startdt, string enddt, int timeinterval) { //SqlParameter[] sqlParameters = //{ // new SqlParameter("@startdt",startdt), // new SqlParameter("@enddt",enddt), // new SqlParameter("@timeinterval",timeinterval) //}; ////* //string conn = db.Database.GetConnectionString(); //"Data Source=192.168.110.32;Initial Catalog=SCADA;User Id= sa;Password= Sa1qaz;Integrated Security=False;Encrypt=True;TrustServerCertificate=True;"; //SqlConnection sqlConnection = new SqlConnection(conn); //var ds = sqlConnection.SqlQueryex("Query_Report_YL", sqlParameters); //* //var ds = db.SqlQuery("Query_Report_Period", sqlParameters);/// SugarParameter[] sqlParameters ={ new SugarParameter("@startdt",startdt), new SugarParameter("@enddt",enddt), new SugarParameter("@timeinterval",timeinterval) }; var Report = _context.Ado.UseStoredProcedure().GetDataTable("Query_Report_YL", sqlParameters); Report.TableName = "Report"; var value = new Dictionary() { ["title"] = "Report", ["Report"] = Report, }; //var pathroot = ""; //var Isdebug = Configuration["Isdebug"]; //if (Isdebug.Equals("yes")) //{ // pathroot = Directory.GetCurrentDirectory(); //} //else //{ // pathroot = AppContext.BaseDirectory; //} var pathroot = Directory.GetCurrentDirectory(); var templatePath = pathroot + "\\wwwroot\\report\\" + "报表预设模板" + ".xlsx"; string fileurl = "Report" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"; //var fileurl = $"电子报表2023_01_03_11_19_53.xlsx"; var path = pathroot + "\\wwwroot\\report\\" + fileurl;//{StartTime}-{EndTime} MiniExcel.SaveAsByTemplate(path: path, templatePath: templatePath, value: value); ////await Task.Delay(1); //Result result = new Result(); //result.data = fileurl; return fileurl; } } }