using DevExpress.XtraEditors; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace IStation.WinFrmUI.Basic { public partial class PumpInfoGridCtrl : DevExpress.XtraEditors.XtraUserControl { public PumpInfoGridCtrl() { InitializeComponent(); this.gridView1.SetNormalView(); this.gridView1.RegistCustomDrawRowIndicator(); } public class CurrentViewModel : Model.Equipment { public CurrentViewModel() { } public CurrentViewModel(Model.Equipment rhs) : base(rhs) { Reset(rhs); } public void Reset(Model.Equipment rhs) { base.Reset(rhs); if (rhs.RatedParas != null) { var paras = rhs.RatedParas; this.Qr = paras.Qr; this.Hr = paras.Hr; this.Nr = paras.Nr; this.Pr = paras.Pr; this.Er = paras.Er; this.NPSHr = paras.NPSHr; this.StNumr = paras.StNumr; this.Ic = paras.Ic; this.Oc = paras.Oc; this.IOd = paras.IOd; this.IsBp = paras.IsBp; this.IsSxp = paras.IsSxp; } } public double Qr { get; set; } public double Hr { get; set; } public double Nr { get; set; } public double Pr { get; set; } public double Er { get; set; } public double NPSHr { get; set; } public int StNumr { get; set; } public double? Ic { get; set; } public double? Oc { get; set; } public double? IOd { get; set; } public bool IsBp { get; set; } public bool IsSxp { get; set; } } private List _allBindingList = null; /// /// 绑定数据 /// public void SetBindingData(List> list) { _allBindingList = new List(); if (list != null && list.Any()) { foreach (var item in list) { var vm = new CurrentViewModel(item); _allBindingList.Add(vm); } } this.gridControl1.DataSource = _allBindingList; this.gridView1.BestFitColumns(); } /// /// 编辑 /// public void Edit() { var vm = this.gridView1.GetCurrentViewModel(_allBindingList); if (vm == null) { XtraMessageBox.Show("请选择数据行!"); return; } WaitFrmHelper.ShowWaitForm(); var dlg = new EditEquipmentDlg(); dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); }; dlg.SetBindingData(vm); dlg.ReloadDataEvent += (rhs) => { var bol = new BLL.Equipment().Update(rhs); if (bol) { var model = new Model.Equipment(rhs); vm.Reset(model); this.gridView1.RefreshRow(this.gridView1.FocusedRowHandle); } return bol; }; dlg.ShowDialog(); } public void ExportExcel() { var dlg = new System.Windows.Forms.SaveFileDialog(); dlg.FileName = DateTime.Now.ToString("G");//设置文件保存名称 dlg.Filter = "Excel 文件(*.xls)|*.xls|Excel 文件(*.xlsx)|*.xlsx"; if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; var path = dlg.FileName; this.gridView1.OptionsPrint.PrintDetails = true;//导出明细 this.gridView1.OptionsPrint.ExpandAllDetails = true;//导出所有明细,false的话,只会导出展开的明细 this.gridView1.ExportToXlsx(path, new DevExpress.XtraPrinting.XlsxExportOptionsEx() { ExportType = DevExpress.Export.ExportType.WYSIWYG, TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text }); DialogResult dr = XtraMessageBox.Show("导出成功!是否打开刚刚保存的Excel文件?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dr != DialogResult.OK) return; System.Diagnostics.Process.Start(path); } } }