123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- /* ==============================================================================
- * 功能描述:所有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
- {
- /// <summary>
- /// MEquipPartBase
- /// </summary>
- public class MRevitEquipBase : CloudDataBase
- {
- #region ModefileDelProperty
- private bool m_HasFM;
- /// <summary>
- /// 是否已关联资产
- /// </summary>
- public bool HasFM
- {
- get { return m_HasFM; }
- set
- {
- m_HasFM = value;
- NotifyPropertyChanged("HasFM");
- }
- }
- private bool m_HasFMChecked;
- /// <summary>
- /// 贴码验证
- /// </summary>
- 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; }
- /// <summary>
- /// PropertyGrid的数据源
- /// </summary>
- public CompositeItem CompositeItem { get; set; }
- private string m_CloudInfos;
- /// <summary>
- /// 物理世界存储的信息点的值
- /// </summary>
- public string CloudInfos
- {
- get { return this.m_CloudInfos; }
- set
- {
- this.m_CloudInfos = value;
- #region 设置信息点关联json对象
- try
- {
- CloundJObject = JObject.Parse(value);
- }
- catch (Exception)
- {
- }
- #endregion
- }
- }
- /// <summary>
- /// 关联json对象
- /// </summary>
- public JObject CloundJObject { get; private set; }
- private ObservableCollection<MServiceAttachment> m_ServirceImages;
- /// <summary>
- /// 设备图片列表
- /// </summary>
- public ObservableCollection<MServiceAttachment> ServirceImages
- {
- get { return m_ServirceImages; }
- set
- {
- m_ServirceImages = value;
- NotifyPropertyChanged(nameof(ServirceImages));
- }
- }
- private MServiceAttachment m_ServirceImageCur;
- /// <summary>
- /// 设备图片列表-选中项
- /// </summary>
- 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;
- /// <summary>
- /// 可看做资产ID,点位标签Id
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// 为属性赋值
- /// </summary>
- /// <param name="json"></param>
- 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<MServiceAttachment>();
- 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<MServiceAttachment>(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;
- }
- }
- /// <summary>
- /// 更改属性时,直接更新到数据库
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- }
- }
- /// <summary>
- /// 更新单个信息点
- /// </summary>
- /// <param name="code"></param>
- /// <param name="value"></param>
- public void UpdateSingleProperty(string code, string value)
- {
- JObject jObject = new JObject();
- JArray jArray = CommonTool.GetPropertyJArray(value);
- jObject.Add(code, jArray);
- CommonConvert.UpdateInfosSigle(Id, jObject);
- }
- /// <summary>
- /// 设置属性窗格显示的属性值
- /// </summary>
- 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);
- }
- /// <summary>
- /// 模型文件上传时,删除或者清除BimId后更新
- /// </summary>
- /// <returns></returns>
- public bool DelOrClearBIMIDSave()
- {
- if (Operator == DocumentChangedOperator.DeleteSaveDuty)
- {
- //保留,清除BIMID
- return DalCommon.UpdateBimId(Id, FloorId);
- }
- else
- {
- return DelObject();
- }
- }
- /// <summary>
- /// 获取Cloud id
- /// </summary>
- /// <returns></returns>
- public string GetColudId()
- {
- if (Id.IsNullOrEmpty())
- {
- this.Id = UpLoadFileRequest.QueryColudIdByBimId(this.FloorId, this.BimID);
- }
- return Id;
- }
- #endregion
- /// <summary>
- /// 信息点维护的固定参数
- /// </summary>
- /// <returns></returns>
- 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;
- }
- }
- }
|