using DevExpress.XtraPrinting;
namespace HStation.WinFrmUI
{
///
///
///
public partial class XhsProjectResultRevitCtrl : DevExpress.XtraEditors.XtraUserControl
{
public XhsProjectResultRevitCtrl()
{
InitializeComponent();
this.gridView1.SetNormalView(30);
this.gridView1.RegistCustomDrawRowIndicator(40);
InitialPropStatus();
this.generalSearchAndExportCtrl1.SearchEvent += Search;
this.generalSearchAndExportCtrl1.ClearEvent += Clear;
this.generalSearchAndExportCtrl1.ExportEvent += Export;
}
private ImportXhsProjectViewModel _vm = null;//操作对象
private List _allList = null;//所有列表
private List _allBindingList;//绑定列表
///
/// 绑定数据
///
public void SetBindingData(ImportXhsProjectViewModel vm)
{
if (vm == null)
{
return;
}
_vm = vm;
SetBindingData(vm.RevitModel);
}
///
/// 绑定数据
///
public void SetBindingData(Model.RevitModel revitModel)
{
if (revitModel == null)
{
return;
}
_allList = new List();
var allParterList = revitModel.GetAllParters();
foreach (var parter in allParterList)
{
if (parter.PropStatusList != null && parter.PropStatusList.Count > 0)
{
foreach (var propStatus in parter.PropStatusList)
{
if (propStatus.PropStatus == Revit.ePropStatus.Normal)
{
continue;
}
_allList.Add(new XhsProjectResultRevitViewModel(parter, propStatus));
}
}
}
Search();
}
//查询
private void Search()
{
_allBindingList = _allList?.ToList();
var catalog = this.txtCatalog.Text.Trim();
if (!string.IsNullOrEmpty(catalog))
{
_allBindingList = _allBindingList?.Where(x => !string.IsNullOrEmpty(x.Catalog) && x.Catalog.Contains(catalog)).ToList();
}
var name = this.txtName.Text.Trim();
if (!string.IsNullOrEmpty(name))
{
_allBindingList = _allBindingList?.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.Contains(name)).ToList();
}
var code = this.txtCode.Text.Trim();
if (!string.IsNullOrEmpty(code))
{
_allBindingList = _allBindingList?.Where(x => !string.IsNullOrEmpty(x.Code) && x.Code.Contains(code)).ToList();
}
Revit.ePropStatus? propStatus = this.imgCmbPropStatus.EditValue == null ? null : (Revit.ePropStatus)this.imgCmbPropStatus.EditValue;
if (propStatus.HasValue)
{
_allBindingList = _allBindingList?.Where(x => x.PropStatus == propStatus.Value).ToList();
}
this.xhsProjectResultRevitViewModelBindingSource.DataSource = _allBindingList;
this.xhsProjectResultRevitViewModelBindingSource.ResetBindings(false);
}
//清理
private void Clear()
{
this.txtCatalog.EditValue = null;
this.txtName.EditValue = null;
this.txtCode.EditValue = null;
this.imgCmbPropStatus.EditValue = null;
Search();
}
//导出
private void Export()
{
var dlg = new SaveFileDialog();
dlg.Title = "Excel导出";
dlg.Filter = "Excel文件|*.xls";
if (dlg.ShowDialog() == DialogResult.OK)
{
this.gridView1.ExportToXls(dlg.FileName);
TipFormHelper.ShowSucceed("导出成功!");
}
}
//初始化属性状态
private void InitialPropStatus()
{
this.imgCmbPropStatus.Properties.BeginUpdate();
this.imgCmbPropStatus.Properties.Items.Clear();
this.imgCmbPropStatus.Properties.Items.Add("全部", null, -1);
this.imgCmbPropStatus.Properties.Items.Add(Revit.ePropStatus.Lack.GetDisplayText(), Revit.ePropStatus.Lack, -1);
this.imgCmbPropStatus.Properties.Items.Add(Revit.ePropStatus.Abnormal.GetDisplayText(), Revit.ePropStatus.Abnormal, -1);
this.imgCmbPropStatus.Properties.Items.Add(Revit.ePropStatus.Error.GetDisplayText(), Revit.ePropStatus.Error, -1);
this.imgCmbPropStatus.Properties.EndUpdate();
}
//自定义单元格颜色
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
var row = this.gridView1.GetRow(e.RowHandle) as XhsProjectResultRevitViewModel;
if (row == null)
{
return;
}
if (e.RowHandle != this.gridView1.FocusedRowHandle)
{
switch (row.PropStatus)
{
case Revit.ePropStatus.Lack:
{
e.Appearance.BackColor = Color.Gray;
e.Appearance.ForeColor = Color.White;
}
break;
case Revit.ePropStatus.Abnormal:
{
e.Appearance.BackColor = Color.Orange;
e.Appearance.ForeColor = Color.White;
}
break;
case Revit.ePropStatus.Error:
{
e.Appearance.BackColor = Color.Red;
e.Appearance.ForeColor = Color.White;
}
break;
default: break;
}
};
}
}
}