using DevExpress.Mvvm.POCO;
|
using DevExpress.XtraBars;
|
using DevExpress.XtraEditors;
|
using DevExpress.XtraEditors.Repository;
|
using DevExpress.XtraLayout.Utils;
|
using DevExpress.XtraVerticalGrid.Events;
|
using PBS.Vmo;
|
using System.ComponentModel;
|
using Yw.Untity;
|
using Yw.WinFrmUI;
|
|
namespace PBS.WinFrmUI
|
{
|
public partial class HomePbsProjectPropertyCtrl : XtraUserControl
|
{
|
public HomePbsProjectPropertyCtrl()
|
{
|
InitializeComponent();
|
//this.layoutControl1.SetupLayoutControl();
|
SetDescriptionVisible(false);//默认设置属性描述面板不显示
|
this.treeList1.InitialDefaultSettings();
|
}
|
|
/// <summary>
|
/// 跳转事件
|
/// </summary>
|
public event Action<long> JumpDirectEvent;
|
|
private List<FacilityVmo> _allBindingList;
|
|
/// <summary>
|
/// 选择设施事件
|
/// </summary>
|
public event Action<Vmo.FacilityVmo> SelectFacEvent;
|
|
/// <summary>
|
/// 绑定对象
|
/// </summary>
|
public HomePbsProjectPropertyViewModel SelectedObject
|
{
|
get
|
{
|
return this.propertyGridControl1.SelectedObject as HomePbsProjectPropertyViewModel;
|
}
|
set
|
{
|
this.propertyGridControl1.SelectedObject = value;
|
OnChanged();
|
}
|
}
|
|
//改变触发
|
protected virtual void OnChanged()
|
{
|
if (this.SelectedObject == null)
|
{
|
// this.barBtnDirect.Visibility = BarItemVisibility.Never;
|
}
|
else
|
{
|
// this.barBtnDirect.Visibility = BarItemVisibility.Always;
|
}
|
}
|
|
public async void SetBindingData(Vmo.PlaceVmo place)
|
{
|
var allList = await new BLL.Facility().GetAll();
|
_allBindingList = new List<FacilityVmo>();
|
if (allList != null)
|
{
|
foreach (var item in allList)
|
{
|
if (item.PlaceID == place.ID)
|
{
|
_allBindingList.Add(item);
|
}
|
}
|
}
|
this.treeList1.DataSource = _allBindingList;
|
this.treeList1.ForceInitialize();
|
this.treeList1.ExpandAll();
|
}
|
|
/// <summary>
|
/// 重新从数据源中读取数据,外观恢复刚开始加载的样子
|
/// </summary>
|
public void UpdateData()
|
{
|
this.propertyGridControl1.UpdateData();
|
}
|
|
/// <summary>
|
/// 更新数据,样式不变
|
/// </summary>
|
public void UpdateRows()
|
{
|
this.propertyGridControl1.UpdateRows();
|
}
|
|
//设置描述控件的可见性
|
private void SetDescriptionVisible(bool isVisible)
|
{
|
var visible = isVisible ? LayoutVisibility.Always : LayoutVisibility.Never;
|
this.layoutDescription.Visibility = this.splitterItem1.Visibility = visible;
|
}
|
|
//自定义属性值显示内容
|
private void propertyGridControl1_CustomDrawRowValueCell(object sender, CustomDrawRowValueCellEventArgs e)
|
{
|
var rowTypeFullName = e.Row.Properties.RowType.FullName;
|
|
if (rowTypeFullName == typeof(DateTime).FullName)
|
{
|
e.CellText = ((DateTime)e.Properties.Value).ToString("yyyy-MM-dd HH:mm:ss");
|
}
|
else
|
{
|
var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
|
var displayUnit = (DisplayUnitAttribute)descriptor.Attributes[typeof(DisplayUnitAttribute)];
|
if (displayUnit != null)
|
{
|
if (e.Properties.Value != null)
|
{
|
e.CellText = e.Properties.Value.ToString() + displayUnit.Unit;
|
}
|
}
|
}
|
}
|
|
//属性编辑框的显示与取消
|
private void propertyGridControl1_ShowingEditor(object sender, CancelEventArgs e)
|
{
|
var rowTypeFullName = this.propertyGridControl1.FocusedRow.Properties.RowType.FullName;
|
var fieldName = this.propertyGridControl1.FocusedRow.Properties.FieldName.Split(new char[] { '.' }).Last();
|
|
if (rowTypeFullName == typeof(Image).FullName)
|
{
|
e.Cancel = true;
|
return;
|
}
|
|
var descriptor = this.propertyGridControl1.GetPropertyDescriptor(this.propertyGridControl1.FocusedRow);
|
var showEditor = (ShowEditorAttribute)descriptor.Attributes[typeof(ShowEditorAttribute)];
|
if (showEditor != null)
|
{
|
if (!showEditor.ShowEditor)
|
{
|
e.Cancel = true;
|
return;
|
}
|
}
|
}
|
|
//行标题,描述,编辑框
|
private void propertyGridControl1_CustomRecordCellEdit(object sender, GetCustomRowCellEditEventArgs e)
|
{
|
var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
|
var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
|
var rowTypeFullName = e.Row.Properties.RowType.FullName;
|
|
#region 属性显示名称和描述
|
|
//名称
|
var attri_caption = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)];
|
if (attri_caption != null && !string.IsNullOrEmpty(attri_caption.DisplayName))
|
{
|
e.Row.Properties.Caption = attri_caption.DisplayName;
|
}
|
|
//备注
|
if (e.Row.Properties.Value == null)
|
{
|
e.Row.Properties.ToolTip = string.Empty;
|
}
|
else
|
{
|
if (e.Row.Properties.RowType.IsEnum)
|
{
|
e.Row.Properties.ToolTip = ((Enum)(e.Row.Properties.Value)).GetDisplayText();
|
}
|
else if (e.Row.Properties.RowType.FullName == typeof(DateTime).FullName)
|
{
|
e.Row.Properties.ToolTip = ((DateTime)e.Row.Properties.Value).ToString("yyyy-MM-dd HH:mm:ss");
|
}
|
else if (e.Row.Properties.RowType.FullName == typeof(Image).FullName)
|
{
|
e.Row.Properties.ToolTip = string.Empty;
|
}
|
else
|
{
|
e.Row.Properties.ToolTip = e.Row.Properties.Value.ToString();
|
}
|
}
|
|
#endregion 属性显示名称和描述
|
|
#region bool
|
|
if (rowTypeFullName == typeof(bool).FullName)
|
{
|
var ckEdit = new RepositoryItemCheckEdit();
|
ckEdit.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.Standard;
|
if (e.Row.Properties.ReadOnly == true)
|
{
|
ckEdit.ReadOnly = true;
|
}
|
e.RepositoryItem = ckEdit;
|
}
|
|
#endregion bool
|
|
#region 富文本
|
|
var attri_multi = (MultiTextAttribute)descriptor.Attributes[typeof(MultiTextAttribute)];
|
if (attri_multi != null)
|
{
|
var memoEdit = new RepositoryItemMemoEdit();
|
if (e.Row.Properties.ReadOnly == true)
|
{
|
memoEdit.ReadOnly = true;
|
}
|
e.RepositoryItem = memoEdit;
|
}
|
|
#endregion 富文本
|
|
#region 图片
|
|
if (rowTypeFullName == typeof(Image).FullName)
|
{
|
var picEdit = new RepositoryItemPictureEdit();
|
picEdit.ReadOnly = true;
|
picEdit.NullText = "空";
|
e.RepositoryItem = picEdit;
|
e.Row.Expanded = true;
|
}
|
|
#endregion 图片
|
}
|
|
//属性值正在改变
|
private void propertyGridControl1_CellValueChanging(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
|
{
|
}
|
|
//属性值改变,更新地图和JsonModel对象
|
private void propertyGridControl1_CellValueChanged(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
|
{
|
var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
|
var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
|
}
|
|
// 描述
|
private void barBtnHelp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var visible = this.splitterItem1.Visibility == LayoutVisibility.Always ? false : true;
|
SetDescriptionVisible(visible);
|
}
|
|
//全部展开
|
private void barBtnExpandAll_ItemClick(object sender, ItemClickEventArgs e)
|
{
|
this.propertyGridControl1.ExpandAllRows();
|
}
|
|
//全部折叠
|
private void barBtnCollpseAll_ItemClick(object sender, ItemClickEventArgs e)
|
{
|
this.propertyGridControl1.CollapseAllRows();
|
}
|
|
//跳转
|
private void barBtnDirect_ItemClick(object sender, ItemClickEventArgs e)
|
{
|
/* if (this.SelectedObject == null)
|
{
|
return;
|
}
|
JumpDirectEvent?.Invoke(this.SelectedObject.Project.ID);*/
|
}
|
|
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
{
|
var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
|
var model = new HomePbsProjectPropertyViewModel(vm);
|
this.SelectedObject = model;
|
SelectFacEvent.Invoke(vm);
|
}
|
}
|
}
|