using DeviceRepair.Models; using DeviceRepair.Models.History; using DeviceRepair.Models.Logs; using DeviceRepairAndOptimization.Biz; using DeviceRepairAndOptimization.Common; using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace DeviceRepairAndOptimization.Pages.Log { public partial class page_UserLoginLog : FormBase { /// /// 开始时间 /// public DateTime StartDate { get { if (dtStart.EditValue == null) dtStart.EditValue = DateTime.Today.AddMonths(-1); return Convert.ToDateTime(dtStart.EditValue); } } /// /// 截至时间 /// public DateTime EndDate { get { if (dtEnd.EditValue == null) dtEnd.EditValue = DateTime.Today.AddDays(1).AddMilliseconds(-1); return Convert.ToDateTime(dtEnd.EditValue); } } /// /// 用户编号 /// public string UserCode { get { return (txtUserCode.EditValue + "").Trim(); } } /// /// 操作类型 /// public string ContentType { get { if (cbContentType.EditValue + "" == "全部") return ""; return cbContentType.EditValue + ""; } } /// /// 客户端名称 /// public string ClientName { get { return (txt_ClientName.EditValue + "").Trim(); } } public OperationFilterModel operationFilterModel { get { return new OperationFilterModel { sDate = StartDate, eDate = EndDate, LoginCode = UserCode, OperationType = ContentType, ClientName = ClientName }; } } public page_UserLoginLog() { InitializeComponent(); } private void btn_Query_Click(object sender, EventArgs e) { try { APIResponseData result = OperationManager.Instance.UserLoginContent(operationFilterModel); if (result.Code == -1) { XtraMessageBoxHelper.Error(result.Message); return; } List Datas = result.ToDeserializeObject>(); gridControl1.DataSource = Datas; // 设置行号列宽度 SizeF size = this.CreateGraphics().MeasureString(Datas.Count.ToString(), this.Font); gridView1.IndicatorWidth = Convert.ToInt32(size.Width) + 20; } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } private void simpleButton1_Click(object sender, EventArgs e) { try { if (gridView1.DataRowCount == 0) { throw new Exception("当前没有数据可供操作!"); } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "导出Excel"; saveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx"; DialogResult dialogResult = saveFileDialog.ShowDialog(this); if (dialogResult == DialogResult.OK) { DevExpress.XtraPrinting.XlsxExportOptionsEx options = new DevExpress.XtraPrinting.XlsxExportOptionsEx(); options.ExportType = DevExpress.Export.ExportType.WYSIWYG; gridControl1.ExportToXlsx(saveFileDialog.FileName.ToString(), options); XtraMessageBoxHelper.Info("导出成功!"); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } } }