/* ============================================================================== * 功能描述:所有revit实体的基类 * 创 建 者:Garrett * 创建日期:2018/5/25 16:43:21 * ==============================================================================*/ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json.Linq; using SAGA.DotNetUtils; using SAGA.DotNetUtils.Extend; using SAGA.DotNetUtils.Logger; using SAGA.MBI.Common; using SAGA.MBI.DataArrange; using SAGA.MBI.JsonConvert; using SAGA.MBI.RequestData; using SAGA.MBI.Tools; using SAGA.MBI.WinView.ModeInfoMaintenance; using WPG.Data; namespace SAGA.MBI.Model { /// /// MEquipPartBase /// public class MRevitEquipBase : CloudDataBase { #region ModefileDelProperty private bool m_HasFM; /// /// 是否已关联资产 /// public bool HasFM { get { return m_HasFM; } set { m_HasFM = value; NotifyPropertyChanged("HasFM"); } } private bool m_HasFMChecked; /// /// 贴码验证 /// public bool HasFMChecked { get { return m_HasFMChecked; } set { m_HasFMChecked = value; NotifyPropertyChanged("HasFMChecked"); } } #endregion #region AttachProperty //是否上传 public bool HasUpload { get; set; } //设备族名称 public string RevitFamilyName { get; set; } //设备类编码 public string EquipClassCode { get; set; } //设备类名称 private string m_EquipClassName; public string EquipClassName { get { if (m_EquipClassName.IsNullOrEmpty()) m_EquipClassName = Family.GetEquipClassName(EquipClassCode); return m_EquipClassName; } } //楼层Id public string FloorId { get; set; } //族类型 public MEquipmentFamily Family { get; set; } /// /// PropertyGrid的数据源 /// public CompositeItem CompositeItem { get; set; } private string m_CloudInfos; /// /// 物理世界存储的信息点的值 /// public string CloudInfos { get { return this.m_CloudInfos; } set { this.m_CloudInfos = value; #region 设置信息点关联json对象 try { CloundJObject = JObject.Parse(value); } catch (Exception) { } #endregion } } /// /// 关联json对象 /// public JObject CloundJObject { get; private set; } private ObservableCollection m_ServirceImages; /// /// 设备图片列表 /// public ObservableCollection ServirceImages { get { return m_ServirceImages; } set { m_ServirceImages = value; NotifyPropertyChanged(nameof(ServirceImages)); } } private MServiceAttachment m_ServirceImageCur; /// /// 设备图片列表-选中项 /// public MServiceAttachment ServirceImageCur { get { return m_ServirceImageCur; } set { m_ServirceImageCur = value; NotifyPropertyChanged(nameof(ServirceImageCur)); if (value == null) return; H5PageExtend.ShowImage(value); } } public Bitmap PreviewImage { get; set; } private string m_FMID; /// /// 可看做资产ID,点位标签Id /// public string FMID { get { return m_FMID; } set { m_FMID = value; //NotifyPropertyChanged("FMID"); } } #endregion #region CloudProperty private string m_BimID; [Description("BIMID")] public string BimID { get { return m_BimID; } set { m_BimID = value; NotifyPropertyChanged("BimID"); } } private string m_Location; [Description("BIMLocation")] public string Location { get { return m_Location; } set { m_Location = value; } } /// /// 为属性赋值 /// /// public override void SetPropertyValue(string json) { this.CloudInfos = json; base.SetPropertyValue(json); JObject infoJObject = JObject.Parse(json); if (infoJObject.IsContainKeyEx("Pic")) { var list = new List(); foreach (JObject imageObj in infoJObject["Pic"]) { //视频不在列表中显示--用一个视频资料用来替代视频 var type = imageObj.GetValueEx("type").ConvertToServiceImageType(); if (type == ServiceImageType.video) continue; list.Add(new MServiceAttachment(imageObj.GetValueEx("key"), imageObj.GetValueEx("name"), type)); } list.Sort(new ServiceImageComparer()); ServirceImages = new ObservableCollection(list); } } #endregion Model #region Method public void BeginWatch() { PropertyChanged += MEquipment_PropertyChanged; if (CompositeItem?.Items != null) foreach (Property property in CompositeItem.Items) { property.PropertyChangeAction += PWGInstace.PropertyChangeAction; } } public void StopWatch() { try { PropertyChanged -= MEquipment_PropertyChanged; } catch (Exception e) { Console.WriteLine(e); throw; } } /// /// 更改属性时,直接更新到数据库 /// /// /// private void MEquipment_PropertyChanged(object sender, PropertyChangedEventArgs e) { PropertyInfo info = sender.GetType().GetProperty(e.PropertyName); var attributes = info?.GetCustomAttributes(typeof(DescriptionAttribute)); var att = attributes?.FirstOrDefault(); if (att == null) return; if (att is DescriptionAttribute descriptionAttribute) { var description = descriptionAttribute.Description; if (description.IsNotNullEmpty()) { object value = info.GetValue(this); if (value != null)// && (string)value != "") { if (info.PropertyType == typeof(int)) value = ((int)value).ToString(); UpdateSingleProperty(description, (string)value); } } } } /// /// 更新单个信息点 /// /// /// public void UpdateSingleProperty(string code, string value) { JObject jObject = new JObject(); JArray jArray = CommonTool.GetPropertyJArray(value); jObject.Add(code, jArray); CommonConvert.UpdateInfosSigle(Id, jObject); } /// /// 设置属性窗格显示的属性值 /// public void SetPropertyGridValue() { var json = this.CloudInfos; JObject jObject = JObject.Parse(json); CompositeItem = PWGInstace.GetItems(this); foreach (Property property in CompositeItem.Items) { //关闭弹窗后,刷新界面 property.ExtendClickAction += PWGInstace.ExtendClickRefrushAction; try { if (property.Define == null) continue; PropertyDefineItem defineItem = property.Define as PropertyDefineItem; string codeName = defineItem?.CodeName; if (codeName == null) continue; object value = (string)jObject.GetValueEx(codeName); //Type应该先于Value进行赋值 property.PropertyType = defineItem.CollectionCmptCode; property.Value = value; #region 控制关系更新图 if (defineItem.CodeName == "ctm-ContrlObjects") property.ValidationRuleFunc += PWGInstace.PropertyUpdateCotrolRelationGriph; #endregion } catch (Exception e) { continue; } } PWGInstace.InitValues(this); } /// /// 模型文件上传时,删除或者清除BimId后更新 /// /// public bool DelOrClearBIMIDSave() { if (Operator == DocumentChangedOperator.DeleteSaveDuty) { //保留,清除BIMID return DalCommon.UpdateBimId(Id, FloorId); } else { return DelObject(); } } /// /// 获取Cloud id /// /// public string GetColudId() { if (Id.IsNullOrEmpty()) { this.Id = UpLoadFileRequest.QueryColudIdByBimId(this.FloorId, this.BimID); } return Id; } #endregion /// /// 信息点维护的固定参数 /// /// public virtual CompositeItem SetFixedProperty() { CompositeItem item = new PropertyCollection(); return item; } public override bool AddorUpdateObject() { bool result = true; switch (Operator) { case DocumentChangedOperator.Add: if (Id.IsNullOrEmpty()) { result = AddObject(); } break; case DocumentChangedOperator.Modified: if (Id.IsNullOrEmpty()) { this.Id = UpLoadFileRequest.QueryColudIdByBimId(this.FloorId, this.BimID); } if (!Id.IsNullOrEmpty()) { JObject infos = this.GetInfosJObject(); result = CommonConvert.UpdateInfosSigle(Id, infos); } break; case DocumentChangedOperator.Delete: if (!Id.IsNullOrEmpty()) result = this.DelObject(); break; case DocumentChangedOperator.DeleteSaveDuty: if (!Id.IsNullOrEmpty()) result = DalCommon.UpdateBimId(Id, FloorId); break; default: if (Id.IsNullOrEmpty()) this.Id = UpLoadFileRequest.QueryColudIdByBimId(this.FloorId, this.BimID); break; } return result; } } }