using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using BLL.Dto.DataDto; using BLL.Manager; using Helper; using HZY.Framework.DependencyInjection; using MiniExcelLibs; using Sunny.UI; namespace Scada.Page { public partial class PageReportManage : UIPage, ISingletonSelfDependency { private BaseResult res; private readonly DataManager _dataManager; public PageReportManage(DataManager dataManager) { InitializeComponent(); this._dataManager = dataManager; this.dtp_Start.Value = DateTime.Now.AddDays(-1); this.dtp_End.Value = DateTime.Now; this.dgv_Data.AutoGenerateColumns = false; } private void PageReportManage_Load(object sender, EventArgs e) { } private async void btn_QueryData_Click(object sender, EventArgs e) { DateTime d1 = this.dtp_Start.Value; DateTime d2 = this.dtp_End.Value; if (d1 >= d2) { UIMessageTip.ShowWarning("开始时间不可以大于结束时间"); return; } QueryDataDto queryDataDto = new QueryDataDto() { StartTime = d1, EndTime = d2 }; res = await _dataManager.GetDataListByTimeAsync(queryDataDto); if (res.Result == SystemEnums.Result.Success) { //设置分页的总数 pgn_Data.TotalCount = res.Data.Count; //设置每页的数量 pgn_Data.PageSize = 15; pgn_Data.ActivePage = 1; } } private void btn_ExportData_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Excel 文件(*.xlsx)|*.xlsx"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { var filePath = saveFileDialog.FileName; var rows = this.dgv_Data.DataSource as List; MiniExcel.SaveAs(filePath, rows); } catch (Exception ex) { UIMessageTip.ShowError("导出失败:" + ex.Message); LogExtension.ShowMessage("导出失败:" + ex.Message, Microsoft.Extensions.Logging.LogLevel.Error); } } } private void pgn_Data_PageChanged(object sender, object pagingSource, int pageIndex, int count) { var data = res.Data.Skip((pageIndex-1)*count).Take(count).ToList(); this.dgv_Data.DataSource = null; this.dgv_Data.DataSource = data; } } }