Browse Source

mxg:添加导出所有岗位命令

mengxiangge 6 years ago
parent
commit
d5460200a4

+ 1 - 1
MBI/SAGA.MBI/Common/CacheAspect.cs

@@ -27,7 +27,7 @@ namespace SAGA.MBI.Common
                     context.Proceed();
                     return context.ReturnValue;
                 },
-                new TimeSpan(0, 30, 0));//30分钟过期
+                new TimeSpan(12, 30, 0));//30分钟过期
             context.ReturnValue = result;
         }
     }

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

@@ -341,6 +341,7 @@
     <Compile Include="ToolsData\ExportAllCategory.cs" />
     <Compile Include="ToolsData\ExportAllEquipmentAll.cs" />
     <Compile Include="ToolsData\IToolCommand.cs" />
+    <Compile Include="ToolsData\ExportAllDuty.cs" />
     <Compile Include="ToolsData\UpdateRelationEquipinSpace.cs" />
     <Compile Include="WinView\BeModingDutyList\MEquipNoMode.cs" />
     <Compile Include="WinView\BeModingDutyList\VMBeModeDutyList.cs" />

+ 73 - 34
MBI/SAGA.MBI/ToolCommand.cs

@@ -75,6 +75,40 @@ namespace SAGA.MBI
         }
     }
     /// <summary>
+    /// 导出类别
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class ExportCategoriesCommand : ExternalCommand
+    {
+        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            try
+            {
+
+                var tip = MessageShow.Question("确定要导出所有的族类别?");
+                if (tip)
+                    BllFactory<ExportAllCategory>.Instance.Operate();
+            }
+            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 bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
+        {
+            return true;
+        }
+    }
+    /// <summary>
     /// 报告设备所在空间
     /// </summary>
     [Transaction(TransactionMode.Manual)]
@@ -97,6 +131,44 @@ namespace SAGA.MBI
             return Result.Succeeded;
         }
     }
+    /// <summary>
+    /// 导出所有的岗位
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class ExportAllDutyCommand : 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:
+                        ExportAllDuty.OperateAll();
+                        break;
+                    case DialogResult.No:
+                        ExportAllDuty.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;
+        }
+    }
     #endregion
 
 
@@ -241,40 +313,7 @@ namespace SAGA.MBI
             return true;
         }
     }
-    /// <summary>
-    /// 导出类别
-    /// </summary>
-    [Transaction(TransactionMode.Manual)]
-    [Regeneration(RegenerationOption.Manual)]
-    public class ExportCategoriesCommand : ExternalCommand
-    {
-        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
-        {
-            try
-            {
-
-                var tip = MessageShow.Question("确定要导出所有的族类别?");
-                if (tip)
-                    BllFactory<ExportAllCategory>.Instance.Operate();
-            }
-            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 bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
-        {
-            return true;
-        }
-    }
+   
 
 
     /// <summary>

+ 284 - 0
MBI/SAGA.MBI/ToolsData/ExportAllDuty.cs

@@ -0,0 +1,284 @@
+/* ==============================================================================
+ * 功能描述:导出所有的岗位
+ * 创 建 者:Garrett
+ * 创建日期:2018/8/10 16:36:26
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Mechanical;
+using Microsoft.Win32;
+using Newtonsoft.Json.Linq;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
+using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Logger;
+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;
+using CellType = Autodesk.Revit.DB.CellType;
+
+namespace SAGA.MBI.ToolsData
+{
+    /// <summary>
+    /// UpdateRelationEquipinFloor
+    /// </summary>
+    public class ExportAllDuty
+    {
+        /// <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";
+            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;
+                    var floorName = context.MFloor.ToString();
+                    var floorPath = context.MFloor.FullPath;
+                    ISheet sheet = book.CreateSheet(floorName);
+
+                    #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("Dutyid");
+
+
+                    ICell cell4 = row.CreateCell(3);
+                    cell4.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell4.SetCellValue("BIMID");
+
+                    #endregion
+
+                    Action<MRevitEquipBase, string> action = (equip, type) =>
+                     {
+                         var family = equip.EquipClassCode;
+                         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(floorName);
+
+                         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);
+                     };
+                    foreach (var equip in context.MEquipments)
+                    {
+                        action(equip, "设备");
+                    }
+                    foreach (var part in context.MEquipmentParts)
+                    {
+                        action(part, "部件");
+                    }
+                    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);
+            }
+        }
+    }
+}

+ 1 - 0
MBI/SAGA.Revit.sln.DotSettings.user

@@ -1,4 +1,5 @@
 <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
+	<s:String x:Key="/Default/CodeInspection/Highlighting/AnalysisEnabled/@EntryValue">VISIBLE_FILES</s:String>
 	<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
   &lt;Assembly Path="D:\SVNCode\MBI\Dlls\Newtonsoft.Json.dll" /&gt;&#xD;
   &lt;Assembly Path="D:\SVNCode\MBI\Dlls\FirmLibDll\FWindSoft.Wpf.dll" /&gt;&#xD;