MRevitEquipBase.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /* ==============================================================================
  2. * 功能描述:所有revit实体的基类
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/5/25 16:43:21
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.ComponentModel;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using Newtonsoft.Json.Linq;
  16. using SAGA.DotNetUtils;
  17. using SAGA.DotNetUtils.Extend;
  18. using SAGA.DotNetUtils.Logger;
  19. using SAGA.MBI.Common;
  20. using SAGA.MBI.DataArrange;
  21. using SAGA.MBI.JsonConvert;
  22. using SAGA.MBI.RequestData;
  23. using SAGA.MBI.Tools;
  24. using SAGA.MBI.WinView.ModeInfoMaintenance;
  25. using SAGA.RevitUtils.Windows;
  26. using WPG.Data;
  27. namespace SAGA.MBI.Model
  28. {
  29. /// <summary>
  30. /// MEquipPartBase
  31. /// </summary>
  32. public class MRevitEquipBase : CloudDataBase
  33. {
  34. #region ModefileDelProperty
  35. private bool m_HasFM;
  36. /// <summary>
  37. /// 是否已关联资产
  38. /// </summary>
  39. public bool HasFM
  40. {
  41. get { return m_HasFM; }
  42. set
  43. {
  44. m_HasFM = value;
  45. NotifyPropertyChanged("HasFM");
  46. }
  47. }
  48. private bool m_HasFMChecked;
  49. /// <summary>
  50. /// 贴码验证
  51. /// </summary>
  52. public bool HasFMChecked
  53. {
  54. get { return m_HasFMChecked; }
  55. set
  56. {
  57. m_HasFMChecked = value;
  58. NotifyPropertyChanged("HasFMChecked");
  59. }
  60. }
  61. #endregion
  62. #region AttachProperty
  63. /// <summary>
  64. /// 设备所在元空间
  65. /// </summary>
  66. public MSpace MSpace { get; set; }
  67. //是否上传
  68. public bool HasUpload { get; set; }
  69. //设备族名称
  70. public string RevitFamilyName { get; set; }
  71. //设备类编码
  72. public string EquipClassCode { get; set; }
  73. //设备类名称
  74. private string m_EquipClassName;
  75. public string EquipClassName
  76. {
  77. get
  78. {
  79. if (m_EquipClassName.IsNullOrEmpty())
  80. m_EquipClassName = Family.GetEquipClassName(EquipClassCode);
  81. return m_EquipClassName;
  82. }
  83. }
  84. //楼层Id
  85. public string FloorId { get; set; }
  86. //族类型
  87. public MEquipmentFamily Family { get; set; }
  88. /// <summary>
  89. /// PropertyGrid的数据源
  90. /// </summary>
  91. public CompositeItem CompositeItem { get; set; }
  92. private string m_CloudInfos;
  93. /// <summary>
  94. /// 物理世界存储的信息点的值
  95. /// </summary>
  96. public string CloudInfos
  97. {
  98. get { return this.m_CloudInfos; }
  99. set
  100. {
  101. this.m_CloudInfos = value;
  102. #region 设置信息点关联json对象
  103. try
  104. {
  105. CloundJObject = JObject.Parse(value);
  106. }
  107. catch (Exception)
  108. {
  109. }
  110. #endregion
  111. }
  112. }
  113. /// <summary>
  114. /// 关联json对象
  115. /// </summary>
  116. public JObject CloundJObject { get; private set; }
  117. private ObservableCollection<MServiceAttachment> m_ServirceImages;
  118. /// <summary>
  119. /// 设备图片列表
  120. /// </summary>
  121. public ObservableCollection<MServiceAttachment> ServirceImages
  122. {
  123. get { return m_ServirceImages; }
  124. set
  125. {
  126. m_ServirceImages = value;
  127. NotifyPropertyChanged(nameof(ServirceImages));
  128. }
  129. }
  130. private MServiceAttachment m_ServirceImageCur;
  131. /// <summary>
  132. /// 设备图片列表-选中项
  133. /// </summary>
  134. public MServiceAttachment ServirceImageCur
  135. {
  136. get { return m_ServirceImageCur; }
  137. set
  138. {
  139. m_ServirceImageCur = value;
  140. NotifyPropertyChanged(nameof(ServirceImageCur));
  141. if (value == null) return;
  142. H5PageExtend.ShowImage(value);
  143. }
  144. }
  145. public Bitmap PreviewImage { get; set; }
  146. private string m_FMID;
  147. /// <summary>
  148. /// 可看做资产ID,点位标签Id
  149. /// </summary>
  150. public string FMID
  151. {
  152. get { return m_FMID; }
  153. set
  154. {
  155. m_FMID = value;
  156. //NotifyPropertyChanged("FMID");
  157. }
  158. }
  159. #endregion
  160. #region CloudProperty
  161. private string m_BimID;
  162. [Description("BIMID")]
  163. public string BimID
  164. {
  165. get { return m_BimID; }
  166. set
  167. {
  168. m_BimID = value;
  169. NotifyPropertyChanged("BimID");
  170. }
  171. }
  172. private string m_Location;
  173. [Description("BIMLocation")]
  174. public string Location
  175. {
  176. get { return m_Location; }
  177. set
  178. {
  179. m_Location = value;
  180. }
  181. }
  182. /// <summary>
  183. /// 为属性赋值
  184. /// </summary>
  185. /// <param name="json"></param>
  186. public override void SetPropertyValue(string json)
  187. {
  188. this.CloudInfos = json;
  189. base.SetPropertyValue(json);
  190. JObject infoJObject = JObject.Parse(json);
  191. if (infoJObject.IsContainKeyEx("Pic"))
  192. {
  193. var list = new List<MServiceAttachment>();
  194. foreach (JObject imageObj in infoJObject["Pic"])
  195. {
  196. //视频不在列表中显示--用一个视频资料用来替代视频
  197. var type = imageObj.GetValueEx("type").ConvertToServiceImageType();
  198. if (type == ServiceImageType.video) continue;
  199. list.Add(new MServiceAttachment(imageObj.GetValueEx("key"),
  200. imageObj.GetValueEx("name"), type));
  201. }
  202. list.Sort(new ServiceImageComparer());
  203. ServirceImages = new ObservableCollection<MServiceAttachment>(list);
  204. }
  205. }
  206. #endregion Model
  207. #region Method
  208. public void BeginWatch()
  209. {
  210. PropertyChanged += MEquipment_PropertyChanged;
  211. if (CompositeItem?.Items != null)
  212. foreach (Property property in CompositeItem.Items)
  213. {
  214. property.PropertyChangeAction += PWGInstace.PropertyChangeAction;
  215. }
  216. }
  217. public void StopWatch()
  218. {
  219. try
  220. {
  221. PropertyChanged -= MEquipment_PropertyChanged;
  222. }
  223. catch (Exception e)
  224. {
  225. Console.WriteLine(e);
  226. throw;
  227. }
  228. }
  229. /// <summary>
  230. /// 更改属性时,直接更新到数据库
  231. /// </summary>
  232. /// <param name="sender"></param>
  233. /// <param name="e"></param>
  234. private void MEquipment_PropertyChanged(object sender, PropertyChangedEventArgs e)
  235. {
  236. PropertyInfo info = sender.GetType().GetProperty(e.PropertyName);
  237. var attributes = info?.GetCustomAttributes(typeof(DescriptionAttribute));
  238. var att = attributes?.FirstOrDefault();
  239. if (att == null) return;
  240. if (att is DescriptionAttribute descriptionAttribute)
  241. {
  242. var description = descriptionAttribute.Description;
  243. if (description.IsNotNullEmpty())
  244. {
  245. object value = info.GetValue(this);
  246. if (value != null)// && (string)value != "")
  247. {
  248. if (info.PropertyType == typeof(int))
  249. value = ((int)value).ToString();
  250. RevitParameterUpdate.UpdateRevitParameter(BimID, description, value.ToString());
  251. UpdateSingleProperty(description, (string)value);
  252. }
  253. }
  254. }
  255. }
  256. /// <summary>
  257. /// 更新单个信息点
  258. /// </summary>
  259. /// <param name="code"></param>
  260. /// <param name="value"></param>
  261. public void UpdateSingleProperty(string code, string value)
  262. {
  263. JObject jObject = new JObject();
  264. JArray jArray = CommonTool.GetPropertyJArray(value);
  265. jObject.Add(code, jArray);
  266. CommonConvert.UpdateInfosSigle(Id, jObject);
  267. }
  268. /// <summary>
  269. /// 设置属性窗格显示的属性值
  270. /// </summary>
  271. public void SetPropertyGridValue()
  272. {
  273. var json = this.CloudInfos;
  274. JObject jObject = JObject.Parse(json);
  275. CompositeItem = PWGInstace.GetItems(this);
  276. foreach (Property property in CompositeItem.Items)
  277. {
  278. //关闭弹窗后,刷新界面
  279. property.ExtendClickAction += PWGInstace.ExtendClickRefrushAction;
  280. try
  281. {
  282. if (property.Define == null) continue;
  283. PropertyDefineItem defineItem = property.Define as PropertyDefineItem;
  284. string codeName = defineItem?.CodeName;
  285. if (codeName == null) continue;
  286. object value = (string)jObject.GetValueEx(codeName);
  287. //Type应该先于Value进行赋值
  288. property.PropertyType = defineItem.CollectionCmptCode;
  289. property.Value = value;
  290. #region 控制关系更新图
  291. if (defineItem.CodeName == "ctm-ContrlObjects")
  292. property.ValidationRuleFunc += PWGInstace.PropertyUpdateCotrolRelationGriph;
  293. #endregion
  294. }
  295. catch (Exception e)
  296. {
  297. continue;
  298. }
  299. }
  300. PWGInstace.InitValues(this);
  301. }
  302. /// <summary>
  303. /// 模型文件上传时,删除或者清除BimId后更新
  304. /// </summary>
  305. /// <returns></returns>
  306. public bool DelOrClearBIMIDSave()
  307. {
  308. if (Operator == DocumentChangedOperator.DeleteSaveDuty)
  309. {
  310. //保留,清除BIMID
  311. return DalCommon.UpdateBimId(Id, FloorId);
  312. }
  313. else
  314. {
  315. return DelObject();
  316. }
  317. }
  318. /// <summary>
  319. /// 获取Cloud id
  320. /// </summary>
  321. /// <returns></returns>
  322. public string GetColudId()
  323. {
  324. if (Id.IsNullOrEmpty())
  325. {
  326. this.Id = DalCommon.QueryDutyIdByBIMID(this.BimID);
  327. }
  328. return Id;
  329. }
  330. #endregion
  331. /// <summary>
  332. /// 信息点维护的固定参数
  333. /// </summary>
  334. /// <returns></returns>
  335. public virtual CompositeItem SetFixedProperty()
  336. {
  337. CompositeItem item = new PropertyCollection();
  338. return item;
  339. }
  340. public override bool AddorUpdateObject()
  341. {
  342. bool result = true;
  343. switch (Operator)
  344. {
  345. case DocumentChangedOperator.Add:
  346. if (Id.IsNullOrEmpty())
  347. {
  348. result = AddObject();
  349. }
  350. break;
  351. case DocumentChangedOperator.Modified:
  352. if (Id.IsNullOrEmpty())
  353. {
  354. this.Id = DalCommon.QueryDutyIdByBIMID(this.BimID);
  355. }
  356. if (!Id.IsNullOrEmpty())
  357. {
  358. JObject infos = this.GetInfosJObject();
  359. result = CommonConvert.UpdateInfosSigle(Id, infos);
  360. }
  361. break;
  362. case DocumentChangedOperator.Delete:
  363. if (!Id.IsNullOrEmpty())
  364. result = this.DelObject();
  365. break;
  366. case DocumentChangedOperator.DeleteSaveDuty:
  367. if (!Id.IsNullOrEmpty())
  368. result = DalCommon.UpdateBimId(Id, FloorId);
  369. break;
  370. default:
  371. if (Id.IsNullOrEmpty())
  372. this.Id = DalCommon.QueryDutyIdByBIMID(this.BimID);
  373. break;
  374. }
  375. return result;
  376. }
  377. }
  378. }