Bläddra i källkod

mxg:添加导出所有的设备和所在的空间数据

mengxiangge 5 år sedan
förälder
incheckning
7a455bc59b

+ 12 - 0
MBI/Menu/MBITool.xml

@@ -159,6 +159,18 @@
       <MenuTab>MBITool_W</MenuTab>
       <Modules>MBITool</Modules>
     </Button>
+  <Button ButtonStyles="Stacked">
+      <ButtonName>SAGA.MBI.ExportAllEquipCommand</ButtonName>
+      <ButtonText>导出所有的设备</ButtonText>
+      <ImageName>1、打开楼层模型</ImageName>
+      <DllName>..\OutputDll\SAGA.MBI.exe</DllName>
+      <ClassName>SAGA.MBI.ExportAllEquipCommand</ClassName>
+      <ToolTip>导出所有的设备</ToolTip>
+      <LongDescription>导出所有的设备</LongDescription>
+      <ToolTipImage></ToolTipImage>
+      <MenuTab>MBITool_W</MenuTab>
+      <Modules>MBITool</Modules>
+    </Button>
 
     <Button ButtonStyles="Stacked">
       <ButtonName>SAGA.MBI.VerticalPipeAlginCommand</ButtonName>

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

@@ -415,7 +415,7 @@
       <DependentUpon>WinModeCheckSetting.xaml</DependentUpon>
     </Compile>
     <Compile Include="ToolsData\CorrectLossDuty.cs" />
-    <Compile Include="ToolsData\ExportAllEquipmentAll.cs" />
+    <Compile Include="ToolsData\ExportAllEquipment.cs" />
     <Compile Include="ToolsData\IToolCommand.cs" />
     <Compile Include="ToolsData\ExportAllDuty.cs" />
     <Compile Include="ToolsData\UpdateRelationEquipinSpace.cs" />

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

@@ -228,6 +228,45 @@ namespace SAGA.MBI
         }
     }
     /// <summary>
+    /// 导出所有的设备
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class ExportAllEquipCommand : ExternalCommand
+    {
+        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            try
+            {
+                var tip = MessageShowBase.Question2("确定要导出所有岗位?\r\n是:全部楼层\r\n否:当前楼层\r\n取消:取消。");
+                switch (tip)
+                {
+                    case DialogResult.Yes:
+                        ExportAllEquipment.OperateAll();
+                        break;
+                    case DialogResult.No:
+                        ExportAllEquipment.OperateCurFloor();
+                        break;
+                    default:
+                        break;
+                }
+
+            }
+            catch (Exception e)
+            {
+                MessageShow.Show(e);
+                return Result.Cancelled;
+            }
+            return Result.Succeeded;
+        }
+
+        public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
+        {
+            return true;
+        }
+    }
+
+    /// <summary>
     /// 导出系统
     /// </summary>
     [Transaction(TransactionMode.Manual)]

+ 312 - 0
MBI/SAGA.MBI/ToolsData/ExportAllEquipment.cs

@@ -0,0 +1,312 @@
+/* ==============================================================================
+ * 功能描述:导出设备类
+ * 创 建 者:Garrett
+ * 创建日期:2018/10/15 11:26:18
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using Microsoft.Win32;
+using Newtonsoft.Json.Linq;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
+using SAGA.DotNetUtils.Extend;
+using SAGA.DotNetUtils.Others;
+using SAGA.MBI.Calc;
+using SAGA.MBI.Common;
+using SAGA.MBI.DataArrange;
+using SAGA.MBI.Model;
+using SAGA.MBI.RequestData;
+using SAGA.MBI.Tools;
+using SAGA.MBI.WinView.Upload;
+using SAGA.RevitUtils.Extends;
+
+namespace SAGA.MBI.ToolsData
+{
+    /// <summary>
+    /// ExportAllEquipmentAll
+    /// </summary>
+    public class ExportAllEquipment
+    {
+        /// <summary>
+        /// 检查并处理所有楼层
+        /// </summary>
+        public static void OperateAll()
+        {
+            var floors = DalUploadFloor.GetHasFileFloors();
+            List<CalcContext> contexts = new List<CalcContext>();
+            foreach (UploadFloor floor in floors)
+            {
+                contexts.Add(Operate(floor.MFloor));
+            }
+            ExportToExcel(contexts);
+        }
+        /// <summary>
+        /// 只处理当前楼层
+        /// </summary>
+        public static void OperateCurFloor()
+        {
+            MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor();
+            if (floor != null)
+            {
+                var context = Operate(floor);
+                ExportToExcel(new List<CalcContext>() { context });
+            }
+        }
+        /// <summary>
+        /// 检查并处理
+        /// </summary>
+        /// <param name="floor"></param>
+        /// <returns></returns>
+        private static CalcContext Operate(MFloor floor)
+        {
+            var context = DalCommon.DownLoadFloorDataByBIMFloorInfo(floor);
+            return context;
+        }
+
+        /// <summary>
+        /// 导出数据
+        /// </summary>
+        /// <param name="xyzsList"></param>
+        public static void ExportToExcel(List<CalcContext> contexts)
+        {
+            SaveFileDialog sflg = new SaveFileDialog();
+            sflg.Filter = "Excel(*.xlsx)|*.xlsx";
+            sflg.FileName = $"{MBIControl.ProjectCur}岗位汇总表";
+            if (sflg.ShowDialog() != true) return;
+            ExportToExcel(contexts, sflg.FileName, sflg.FilterIndex);
+        }
+
+        /// <summary>
+        /// 导出数据到指定目录
+        /// </summary>
+        /// <param name="xyzsList"></param>
+        /// <param name="fileName"></param>
+        private static void ExportToExcel(List<CalcContext> contexts, string fileName, int filterIndex = 0)
+        {
+            try
+            {
+                IWorkbook book = new XSSFWorkbook();
+
+                #region 添加数据
+
+                foreach (var context in contexts)
+                {
+                    int index = 0;
+                    ISheet sheet = book.CreateSheet(DalProjectTree.GetBuildingFloorName(context.FloorId));
+
+                    #region 添加表头
+
+                    IRow row = sheet.CreateRow(0);
+                    NPOI.SS.UserModel.ICell cell0 = row.CreateCell(0);
+                    cell0.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell0.SetCellValue("楼层名称");
+
+                    ICell cell1 = row.CreateCell(1);
+                    cell1.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell1.SetCellValue("类型");
+
+                    ICell cell2 = row.CreateCell(2);
+                    cell2.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell2.SetCellValue("族名称");
+
+                    ICell cell3 = row.CreateCell(3);
+                    cell3.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell3.SetCellValue("物理世界Id");
+
+
+                    ICell cell4 = row.CreateCell(4);
+                    cell4.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell4.SetCellValue("模型中的Id");
+
+                    ICell cell5 = row.CreateCell(5);
+                    cell5.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell5.SetCellValue("设备的本地名称");
+
+                    ICell cell6 = row.CreateCell(6);
+                    cell6.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell6.SetCellValue("设备的本地编码");
+
+                    ICell cell7 = row.CreateCell(7);
+                    cell7.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell7.SetCellValue("设备所在空间的名称");
+
+                    ICell cell8 = row.CreateCell(8);
+                    cell8.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell8.SetCellValue("设备所在空间的模型Id");
+
+                    #endregion
+
+                    Action<MEquipment, string> action = (equip, type) =>
+                    {
+                        string family = equip.EquipClassCode + "-" + equip.Family?.Name;
+                        var id = equip.Id;
+                        var bimid = equip.BimID.GetBIMID();
+                        index++;
+
+                        row = sheet.CreateRow(index);
+
+                        ICell cell = row.CreateCell(0, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(context.MFloor.ToString());
+
+                        cell = row.CreateCell(1, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(type);
+
+                        cell = row.CreateCell(2, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(family);
+
+                        cell = row.CreateCell(3, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(id);
+
+                        cell = row.CreateCell(4, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(bimid);
+
+                        cell = row.CreateCell(5, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(equip.LocalName);
+
+                        cell = row.CreateCell(6, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(equip.LocalId);
+
+                        if (equip.MSpace != null)
+                        {
+                            cell = row.CreateCell(7, NPOI.SS.UserModel.CellType.String);
+                            cell.SetCellValue(equip.MSpace.ToString());
+
+                            cell = row.CreateCell(8, NPOI.SS.UserModel.CellType.String);
+                            cell.SetCellValue(equip.MSpace.BimID.GetBIMID());
+                        }
+                        
+                    };
+                    foreach (var equip in context.MEquipments)
+                    {
+                        action(equip, "设备");
+                    }
+                    foreach (var part in context.MEquipmentParts)
+                    {
+                        //action(part as MEquipment, "部件");
+                    }
+                    //foreach (var beacon in context.MBeacons)
+                    //{
+                    //    action(beacon, "信标");
+                    //}
+                    //foreach (var space in context.MSpaces)
+                    //{
+                    //    action(space, "空间");
+                    //}
+                }
+
+                #endregion
+
+                #region 写入
+
+                MemoryStream ms = new MemoryStream();
+                book.Write(ms);
+                book = null;
+
+                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
+
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+        }
+
+        /// <summary>
+        /// 导出数据到指定目录
+        /// </summary>
+        /// <param name="xyzsList"></param>
+        /// <param name="fileName"></param>
+        private static void ExportToExcel2(List<CalcContext> contexts, string fileName, int filterIndex = 0)
+        {
+            try
+            {
+                IWorkbook book = new XSSFWorkbook();
+
+                #region 添加数据
+                ISheet sheet = book.CreateSheet("Summary");
+
+                #region 添加表头
+
+                IRow row = sheet.CreateRow(0);
+                NPOI.SS.UserModel.ICell cell0 = row.CreateCell(0);
+                cell0.SetCellType(NPOI.SS.UserModel.CellType.String);
+                cell0.SetCellValue("楼层名称");
+
+                ICell cell1 = row.CreateCell(1);
+                cell1.SetCellType(NPOI.SS.UserModel.CellType.String);
+                cell1.SetCellValue("类型");
+
+                ICell cell2 = row.CreateCell(2);
+                cell2.SetCellType(NPOI.SS.UserModel.CellType.String);
+                cell2.SetCellValue("总数");
+
+                List<string> list = new List<string>() { "FASE-光电感烟探测器", "FASE-智能感温探测器", "FSCP-消火栓起泵按钮" };
+                var list2 = list.Select(tt => tt.Substring(0, 4)).ToList();
+                int index = 0;
+                foreach (var context in contexts)
+                {
+                    var floorName = context.MFloor.ToString();
+
+
+                    #endregion
+                    Action<int> action = (count) =>
+                    {
+                        index++;
+
+                        row = sheet.CreateRow(index);
+
+                        ICell cell = row.CreateCell(0, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(floorName);
+
+                        cell = row.CreateCell(1, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(string.Join(",", list));
+
+                        cell = row.CreateCell(2, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(count);
+
+                    };
+                    action(context.MEquipments.Where(t => list2.Contains(t.EquipClassCode)).Count());
+
+                }
+
+                #endregion
+
+                #region 写入
+
+                MemoryStream ms = new MemoryStream();
+                book.Write(ms);
+                book = null;
+
+                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
+
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+        }
+    }
+}

+ 0 - 194
MBI/SAGA.MBI/ToolsData/ExportAllEquipmentAll.cs

@@ -1,194 +0,0 @@
-/* ==============================================================================
- * 功能描述:导出设备类
- * 创 建 者:Garrett
- * 创建日期:2018/10/15 11:26:18
- * ==============================================================================*/
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Autodesk.Revit.DB;
-using Microsoft.Win32;
-using Newtonsoft.Json.Linq;
-using NPOI.SS.UserModel;
-using NPOI.XSSF.UserModel;
-using SAGA.DotNetUtils.Extend;
-using SAGA.DotNetUtils.Others;
-using SAGA.MBI.RequestData;
-using SAGA.RevitUtils.Extends;
-
-namespace SAGA.MBI.ToolsData
-{
-    /// <summary>
-    /// ExportAllEquipmentAll
-    /// </summary>
-    class ExportAllEquipmentAll
-    {
-        public  void ExprotAll()
-        {
-            var json = CmbDataSourceRequest.EquipmentAll();
-            JObject jObject=JObject.Parse(json);
-            ExportToExcel(jObject);
-        }
-
-        /// <summary>
-        /// 导出数据
-        /// </summary>
-        /// <param name="xyzsList"></param>
-        public void ExportToExcel(JObject jObject)
-        {
-            SaveFileDialog sflg = new SaveFileDialog();
-            sflg.Filter = "Excel(*.xlsx)|*.xlsx";
-            if (sflg.ShowDialog() != true) return;
-            ExportToExcel(jObject, sflg.FileName);
-        }
-        /// <summary>
-        /// 导出数据到指定目录
-        /// </summary>
-        /// <param name="xyzsList"></param>
-        /// <param name="fileName"></param>
-        private void ExportToExcel(JObject jObject, string fileName)
-        {
-            try
-            {
-                IWorkbook book = new XSSFWorkbook();
-                ISheet sheet = book.CreateSheet("Summary");
-
-                #region 添加表头
-
-                IRow row = sheet.CreateRow(0);
-                NPOI.SS.UserModel.ICell cell0 = row.CreateCell(0);
-                cell0.SetCellType(NPOI.SS.UserModel.CellType.String);
-                cell0.SetCellValue("专业名称");
-
-                ICell cell1 = row.CreateCell(1);
-                cell1.SetCellType(NPOI.SS.UserModel.CellType.String);
-                cell1.SetCellValue("专业编码");
-                
-                ICell cell2 = row.CreateCell(2);
-                cell2.SetCellType(NPOI.SS.UserModel.CellType.String);
-                cell2.SetCellValue("系统类名称");
-
-                ICell cell3 = row.CreateCell(3);
-                cell3.SetCellType(NPOI.SS.UserModel.CellType.String);
-                cell3.SetCellValue("系统类编码");
-
-                ICell cell4 = row.CreateCell(4);
-                cell4.SetCellType(NPOI.SS.UserModel.CellType.String);
-                cell4.SetCellValue("设备类名称");
-
-                ICell cell5 = row.CreateCell(5);
-                cell5.SetCellType(NPOI.SS.UserModel.CellType.String);
-                cell5.SetCellValue("设备类编码");
-
-                ICell cell6 = row.CreateCell(6);
-                cell6.SetCellType(NPOI.SS.UserModel.CellType.String);
-                cell6.SetCellValue("设备部件类名称");
-
-                ICell cell7 = row.CreateCell(7);
-                cell7.SetCellType(NPOI.SS.UserModel.CellType.String);
-                cell7.SetCellValue("设备部件类编码");
-                #endregion
-
-                #region 添加数据
-                
-                int index = 1;
-                foreach (JObject classJObject in jObject["Content"])
-                {
-                    row = CreateRow(sheet, index);
-                    var className = (string)classJObject["class"];
-                    var classCode = (string)classJObject["code"];
-                    
-                    ICell cells = row.CreateCell(0, NPOI.SS.UserModel.CellType.String);
-                    cells.SetCellValue(className);
-                    ICell cells1 = row.CreateCell(1, NPOI.SS.UserModel.CellType.String);
-                    cells1.SetCellValue(classCode);
-
-
-                    if (!classJObject.IsContainKeyEx("content") || !((JArray) classJObject["content"]).Any())
-                    {
-                        index++;
-                        continue;
-                    }
-                    foreach (JObject sysJObject in ((JArray)classJObject["content"]))
-                    {
-                        row = CreateRow(sheet, index);
-
-                        var sysName = (string)sysJObject["system"];
-                        var sysCode = (string)sysJObject["code"];
-                        ICell cells2 = row.CreateCell(2, NPOI.SS.UserModel.CellType.String);
-                        cells2.SetCellValue(sysName);
-                        ICell cells3 = row.CreateCell(3, NPOI.SS.UserModel.CellType.String);
-                        cells3.SetCellValue(sysCode);
-
-                        if (!sysJObject.IsContainKeyEx("content") || !((JArray) sysJObject["content"]).Any())
-                        {
-                            index++;
-                            continue;
-                        }
-                        foreach (JObject facilityJObject in ((JArray)sysJObject["content"]))
-                        {
-                            row = CreateRow(sheet, index);
-                            var facilityName = (string)facilityJObject["facility"];
-                            var facilityCode = (string)facilityJObject["code"];
-                            ICell cells4 = row.CreateCell(4, NPOI.SS.UserModel.CellType.String);
-                            cells4.SetCellValue(facilityName);
-                            ICell cells5 = row.CreateCell(5, NPOI.SS.UserModel.CellType.String);
-                            cells5.SetCellValue(facilityCode);
-                            if (!facilityJObject.IsContainKeyEx("components") ||
-                                !((JArray) facilityJObject["components"]).Any())
-                            {
-                                index++;
-                                continue;
-                            }
-                            foreach (JObject partJObject in ((JArray)facilityJObject["components"]))
-                            {
-                                var partName = (string)partJObject["component"];
-                                var partCode = (string)partJObject["code"];
-                                ICell cells6 = row.CreateCell(6, NPOI.SS.UserModel.CellType.String);
-                                cells6.SetCellValue(partName);
-                                ICell cells7 = row.CreateCell(7, NPOI.SS.UserModel.CellType.String);
-                                cells7.SetCellValue(partCode);
-                                index++;
-                            }
-                        }
-                    }
-                }
-
-                #endregion
-
-                #region 写入
-
-                MemoryStream ms = new MemoryStream();
-                book.Write(ms);
-                book = null;
-
-                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
-
-            }
-            catch (Exception e)
-            {
-                MessageShowBase.Show(e);
-            }
-        }
-
-        private IRow CreateRow(ISheet sheet, int index)
-        {
-            IRow row = sheet.GetRow(index);
-            if (row == null)
-                row = sheet.CreateRow(index);
-            return row;
-        }
-    }
-}