MRevitEquipBase.cs 12 KB

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