Browse Source

mxg:添加多个岗位同用一个BIMId检查

mengxiangge 6 years ago
parent
commit
bbc67a51ba

+ 0 - 14
MBI/SAGA.MBI/Common/MBIControl.cs

@@ -73,20 +73,6 @@ namespace SAGA.MBI.Common
                 return m_ProjectTree;
                 return m_ProjectTree;
             }
             }
         }
         }
-        private  ObservableCollection<TreeNodeItem> m_ProjectTreeItems = null;
-
-        public  ObservableCollection<TreeNodeItem> ProjectTreeItems
-        {
-            get
-            {
-                if (m_ProjectTreeItems == null)
-                {
-                    m_ProjectTreeItems = new ObservableCollection<TreeNodeItem>() { ProjectTree };
-
-                }
-                return m_ProjectTreeItems;
-            }
-        }
 
 
 
 
 
 

+ 9 - 0
MBI/SAGA.MBI/DataArrange/DalCommon.cs

@@ -449,6 +449,15 @@ namespace SAGA.MBI.DataArrange
             }
             }
             return rbase;
             return rbase;
         }
         }
+        /// <summary>
+        /// 缓存所有Revit数据,除了信标
+        /// </summary>
+        /// <param name="buildingId"></param>
+        /// <returns></returns>
+        public static List<MRevitEquipBase> GetAllDutys(string buildingId)
+        {
+            return CommonConvert.CacheAllData(buildingId); 
+        }
 
 
         /// <summary>
         /// <summary>
         /// 由BimID查询CloudID
         /// 由BimID查询CloudID

+ 2 - 1
MBI/SAGA.MBI/Extend/MRevitEquipBaseExtend.cs

@@ -55,7 +55,8 @@ namespace SAGA.MBI.Extend
                 var rltmode = CommonConvert.QueryObjectById(dutyid);
                 var rltmode = CommonConvert.QueryObjectById(dutyid);
                 if (!rltmode.IsNullOrDefaultEquip())
                 if (!rltmode.IsNullOrDefaultEquip())
                 {
                 {
-                    rltmode.HasUpload = false;
+                    //之前要求没有上传模型的岗位信息只能看不能编辑,现在改为都可以编辑
+                    //rltmode.HasUpload = false;
                     rltmode.BimID = mode?.BimID;
                     rltmode.BimID = mode?.BimID;
                     return rltmode;
                     return rltmode;
                 }
                 }

+ 1 - 0
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -279,6 +279,7 @@
     <Compile Include="ToolsData\CheckBase\ICheckBase.cs" />
     <Compile Include="ToolsData\CheckBase\ICheckBase.cs" />
     <Compile Include="ToolsData\CheckDocumentData.cs" />
     <Compile Include="ToolsData\CheckDocumentData.cs" />
     <Compile Include="ToolsData\AddEquipLocation.cs" />
     <Compile Include="ToolsData\AddEquipLocation.cs" />
+    <Compile Include="ToolsData\CheckDuplicationBIMId.cs" />
     <Compile Include="ToolsData\DataCheck\DataCheckBase.cs" />
     <Compile Include="ToolsData\DataCheck\DataCheckBase.cs" />
     <Compile Include="ToolsData\CheckBase\CheckContext.cs" />
     <Compile Include="ToolsData\CheckBase\CheckContext.cs" />
     <Compile Include="ToolsData\DataCheck\DataCheckResultBase.cs" />
     <Compile Include="ToolsData\DataCheck\DataCheckResultBase.cs" />

+ 33 - 0
MBI/SAGA.MBI/ToolCommand.cs

@@ -66,6 +66,39 @@ namespace SAGA.MBI
             return true;
             return true;
         }
         }
     }
     }
+    /// <summary>
+    /// 检查BimID是否重复,多个岗位对应一个模型
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class CheckDuplicationBIMIdCommand : ExternalCommand
+    {
+        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            try
+            {
+                var tip = MessageShow.Question("确定要执行设备BIMID重复性检查?\r\n未在空间中的岗位将会被导出的excel中。");
+                if (tip)
+                    CheckDuplicationBIMId.CheckAll();
+            }
+            catch (Exception e)
+            {
+                MessageShow.Show(e);
+                return Result.Cancelled;
+            }
+            return Result.Succeeded;
+        }
+
+
+        /// <summary>
+        /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
+        /// when a document is open.
+        /// </summary>
+        public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
+        {
+            return true;
+        }
+    }
 
 
     /// <summary>
     /// <summary>
     /// 修正云平台族类型和本地族类型不一致
     /// 修正云平台族类型和本地族类型不一致

+ 154 - 0
MBI/SAGA.MBI/ToolsData/CheckDuplicationBIMId.cs

@@ -0,0 +1,154 @@
+/* ==============================================================================
+ * 功能描述:检查BimID是否重复,多个岗位对应一个模型
+ * 创 建 者:Garrett
+ * 创建日期:2018/12/13 17:25:22
+ * ==============================================================================*/
+using SAGA.MBI.Calc;
+using SAGA.MBI.DataArrange;
+using SAGA.MBI.Model;
+using SAGA.MBI.RequestData;
+using SAGA.MBI.WinView.Upload;
+using SAGA.RevitUtils.Extends;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using DevExpress.Data.Helpers;
+using Microsoft.Win32;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
+using SAGA.DotNetUtils.Extend;
+using SAGA.DotNetUtils.Logger;
+using SAGA.DotNetUtils.Others;
+using SAGA.MBI.Common;
+using SAGA.MBI.Tools;
+
+namespace SAGA.MBI.ToolsData
+{
+    /// <summary>
+    /// CheckDuplicationBIMId
+    /// </summary>
+    class CheckDuplicationBIMId
+    {
+        /// <summary>
+        /// 检查BIMId是否重复
+        /// </summary>
+        public static void CheckAll()
+        {
+            List<IEnumerable<IGrouping<string, MRevitEquipBase>>> groupss=new List<IEnumerable<IGrouping<string, MRevitEquipBase>>>();
+            foreach (TreeNodeItem buildingItem in MBIControl.ProjectTree.Children)
+            {
+                string buildingId = buildingItem.Item.Id;
+                groupss.Add(Check(buildingId));
+            }
+            ExportToExcel(groupss);
+        }
+        /// <summary>
+        /// 检查BIMId是否重复
+        /// </summary>
+        private static IEnumerable<IGrouping<string, MRevitEquipBase>> Check(string buildingId)
+        {
+            var dutys = DalCommon.GetAllDutys(buildingId);
+            var bybimidGroups = dutys.GroupBy(t => t.BimID);
+            var exceptionGroups = bybimidGroups.Where(t => t.Count() >= 2 && !t.Key.IsOnlyDutyNoModelBIMID());
+            return exceptionGroups;
+        }
+
+
+        /// <summary>
+        /// 导出数据
+        /// </summary>
+        /// <param name="xyzsList"></param>
+        public static void ExportToExcel(List<IEnumerable<IGrouping<string, MRevitEquipBase>>> groupss)
+        {
+            SaveFileDialog sflg = new SaveFileDialog();
+            sflg.Filter = "Excel(*.xlsx)|*.xlsx";
+            if (sflg.ShowDialog() != true) return;
+            string fileName = sflg.FileName;
+            IWorkbook book = new XSSFWorkbook();
+            ISheet sheet = book.CreateSheet("Summary");
+            foreach (IEnumerable<IGrouping<string, MRevitEquipBase>> groups in groupss)
+            {
+                ExportToExcel(sheet, groups, fileName);
+            }
+            Save(book, fileName);
+        }
+
+        /// <summary>
+        /// 导出数据到指定目录
+        /// </summary>
+        /// <param name="xyzsList"></param>
+        /// <param name="fileName"></param>
+        private static void ExportToExcel(ISheet sheet, IEnumerable<IGrouping<string, MRevitEquipBase>> groups, string fileName)
+        {
+            try
+            {
+                #region 添加表头
+
+                IRow row = sheet.CreateRow(0);
+                NPOI.SS.UserModel.ICell cell0 = row.CreateCell(0);
+                cell0.SetCellType(NPOI.SS.UserModel.CellType.String);
+                cell0.SetCellValue("BIMID");
+
+                ICell cell1 = row.CreateCell(1);
+                cell1.SetCellType(CellType.String);
+                cell1.SetCellValue("DutyId");
+
+                #endregion
+
+                #region 添加数据
+
+                int index = 1;
+                foreach (var group in groups)
+                {
+                    var bimid = group.Key;
+                    var dutys = "";
+                    foreach (var equip in group)
+                    {
+                        dutys += equip.Id + ";";
+                    }
+                    IRow rowN = sheet.CreateRow(index);
+                    NPOI.SS.UserModel.ICell cellN0 = rowN.CreateCell(0);
+                    cellN0.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cellN0.SetCellValue(bimid);
+
+                    ICell cellN1 = rowN.CreateCell(1);
+                    cellN1.SetCellType(CellType.String);
+                    cellN1.SetCellValue(dutys);
+                    index++;
+
+                }
+
+                #endregion
+
+
+
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+        }
+
+        private static void Save(IWorkbook book, string fileName)
+        {
+            #region 写入
+
+            MemoryStream ms = new MemoryStream();
+            book.Write(ms);
+
+            using (System.IO.FileStream fs = new System.IO.FileStream(fileName, FileMode.Create, FileAccess.Write))
+            {
+                byte[] data = ms.ToArray();
+                fs.Write(data, 0, data.Length);
+                fs.Flush();
+            }
+            ms.Close();
+            ms.Dispose();
+
+            #endregion
+        }
+    }
+}