瀏覽代碼

Merge branch 'master' of https://git.dev.tencent.com/xuhuo1234/saga

mengxiangge 6 年之前
父節點
當前提交
a8e77f1dc0

+ 10 - 0
MBI/SAGA.DotNetUtils/SAGA.DotNetUtils.csproj

@@ -476,6 +476,12 @@
     <Compile Include="WPF\Converter\StringNullToDefaultConverter.cs" />
     <Compile Include="WPF\Converter\StringToEnableConverter.cs" />
     <Compile Include="WPF\Converter\ValueEqualConverter.cs" />
+    <Compile Include="WPF\ShowWindow\MessageTip.cs" />
+    <Compile Include="WPF\ShowWindow\TipButtonItem.cs" />
+    <Compile Include="WPF\ShowWindow\WindowCom.cs" />
+    <Compile Include="WPF\ShowWindow\WinMessage.xaml.cs">
+      <DependentUpon>WinMessage.xaml</DependentUpon>
+    </Compile>
     <Compile Include="WPF\UserControl\AccessDecimal.cs" />
     <Compile Include="WPF\UserControl\AccessInteger.cs" />
     <Compile Include="WPF\UserControl\AccessPlusDecimal.cs" />
@@ -543,6 +549,10 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
+    <Page Include="WPF\ShowWindow\WinMessage.xaml">
+      <Generator>MSBuild:Compile</Generator>
+      <SubType>Designer</SubType>
+    </Page>
     <Page Include="WPF\UserControl\EditSaveTextbox.xaml">
       <SubType>Designer</SubType>
       <Generator>XamlIntelliSenseFileGenerator</Generator>

+ 149 - 0
MBI/SAGA.DotNetUtils/WPF/ShowWindow/MessageTip.cs

@@ -0,0 +1,149 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Windows;
+using System.Windows.Interop;
+using SysWindow = System.Windows.Window;
+namespace SAGA.DotNetUtils.WPF
+{
+    /*
+     * 一点,窗体自然关闭时取消按钮
+     * 如果有取消按钮,则窗体可有标题栏关闭,否则不能
+     */
+    public static class CustomMessageShow
+    {
+        private const string DefaultCaption = "提示";
+        public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button)
+        {
+            return (MessageBoxResult)Show(null, messageBoxText, caption, CreateButtons(button));
+        }
+
+        public static MessageBoxResult Show(string messageBoxText, string caption)
+        {
+            return (MessageBoxResult)Show(null, messageBoxText, caption, CreateButtons(MessageBoxButton.OK));
+        }
+        public static MessageBoxResult Show(string messageBoxText)
+        {
+            return (MessageBoxResult)Show(null, messageBoxText, DefaultCaption, CreateButtons(MessageBoxButton.OK));
+        }
+
+        public static MessageBoxResult Show(SysWindow owner, string messageBoxText, string caption, MessageBoxButton button)
+        {
+            return (MessageBoxResult)Show(owner, messageBoxText, caption, CreateButtons(button));
+        }
+
+        public static MessageBoxResult Show(SysWindow owner, string messageBoxText, string caption)
+        { return (MessageBoxResult)Show(owner, messageBoxText, caption, CreateButtons(MessageBoxButton.OK));
+        }
+        public static MessageBoxResult Show(SysWindow owner, string messageBoxText)
+        {
+            string caption = DefaultCaption;
+            if (owner != null && !string.IsNullOrEmpty(owner.Title))
+                caption = owner.Title;
+            return (MessageBoxResult)Show(owner, messageBoxText, caption, CreateButtons(MessageBoxButton.OK));
+        }
+
+        public static MessageBoxResult ShowOverride(SysWindow owner, string messageBoxText,string ensureText,string cancelText)
+        {
+            string caption = DefaultCaption;
+            if (owner != null && !string.IsNullOrEmpty(owner.Title))
+                caption = owner.Title;
+            var buttons = CreateButtons(MessageBoxButton.OKCancel);
+            List<string> texts = new List<string>() {ensureText, cancelText};
+            for(int i=0;i<texts.Count;i++)
+            {
+                var text = texts[i];
+                if (string.IsNullOrWhiteSpace(text))
+                {
+                    continue;
+                }
+
+                buttons[i].Content = text;
+            }     
+            return (MessageBoxResult)Show(owner, messageBoxText, caption, buttons);
+        }
+        #region 核心显示方法
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="owner"></param>
+        /// <param name="messageBoxText"></param>
+        /// <param name="caption"></param>
+        /// <param name="buttonItems">如果flag,有2的话,则启用关闭按钮</param>
+        /// <returns></returns>
+        public static int Show(SysWindow owner, string messageBoxText, string caption, List<TipButtonItem> buttonItems)
+        {
+            if (buttonItems == null || !buttonItems.Any())
+                return -1;
+            WinMessage tip = new WinMessage(buttonItems);
+          
+            tip.Title = caption;
+            if (owner != null)
+            {
+                  tip.Owner = owner;
+            }
+            else
+            {
+                //设置主线程窗体为父窗体
+                var handle = Process.GetCurrentProcess().MainWindowHandle;
+                if (handle != IntPtr.Zero)
+                {
+                    var winHelp = new WindowInteropHelper(tip);
+                    winHelp.EnsureHandle();
+                    winHelp.Owner = handle;
+                    //WinAPi.SetParent(winHelp.EnsureHandle(), handle);
+                }
+            }
+
+            tip.Message = messageBoxText ?? string.Empty;
+            if (buttonItems.Any(i => i.Flag == 2))
+            {
+                tip.DisableUseClose = false;
+            }
+
+            var result = tip.ShowDialog();            
+            if (result != null && result.Value == true)
+            {
+                return tip.Flag;
+            }
+            return 2;
+        }
+        
+
+        #endregion
+
+
+        private static List<TipButtonItem> CreateButtons(MessageBoxButton button)
+        {
+            List<TipButtonItem> items = new List<TipButtonItem>();
+            switch (button)
+            {
+                case MessageBoxButton.OK:
+                    items.Add(new TipButtonItem() { Content = "确定", Flag = 1,IsDefault=true });
+                    break;
+                case MessageBoxButton.OKCancel:
+                    items.Add(new TipButtonItem() { Content = "确定", Flag = 1, IsDefault = true });
+                    items.Add(new TipButtonItem() { Content = "取消", Flag = 2 , IsCancel = true });
+                    break;
+                case MessageBoxButton.YesNoCancel:
+                    items.Add(new TipButtonItem() { Content = "是", Flag = 6, IsDefault = true });
+                    items.Add(new TipButtonItem() { Content = "否", Flag = 7 });
+                    items.Add(new TipButtonItem() { Content = "取消", Flag = 2, IsCancel = true });
+                    break;
+                case MessageBoxButton.YesNo:
+                    items.Add(new TipButtonItem() { Content = "是", Flag = 6, IsDefault = true });
+                    items.Add(new TipButtonItem() { Content = "否", Flag = 7, IsCancel = true });
+                    break;
+                default:
+                    break;
+            }
+
+
+            return items;
+        }
+    }
+
+
+}

+ 29 - 0
MBI/SAGA.DotNetUtils/WPF/ShowWindow/TipButtonItem.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace SAGA.DotNetUtils.WPF
+{
+    public class TipButtonItem
+    {
+        /// <summary>
+        /// 提示框按钮内容
+        /// </summary>
+        public object Content { get; set; }
+        /// <summary>
+        /// 提示框按钮模板
+        /// </summary>
+        public DataTemplate ContentTemplate{ get; set; }
+        /// <summary>
+        /// 按钮标志
+        /// </summary>
+        public int  Flag { get; set; }
+
+        public bool IsDefault { get; set; }
+
+        public bool IsCancel { get; set; }
+    }
+}

+ 21 - 0
MBI/SAGA.DotNetUtils/WPF/ShowWindow/WinMessage.xaml

@@ -0,0 +1,21 @@
+<Window x:Class="SAGA.DotNetUtils.WPF.WinMessage"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             WindowStartupLocation="CenterOwner" Width="300" MinWidth="300" MaxWidth="400" Height="200" MinHeight="200" MaxHeight="300"
+             ResizeMode="NoResize" SizeToContent="WidthAndHeight">
+    <Grid >
+        <Grid.RowDefinitions>
+            <RowDefinition></RowDefinition>
+            <RowDefinition Height="38"></RowDefinition>
+        </Grid.RowDefinitions>
+        <ScrollViewer VerticalScrollBarVisibility="Auto">
+        <TextBlock x:Name="TxtMessage" Margin="20" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap"></TextBlock>
+        </ScrollViewer> 
+            <Border Grid.Row="1" BorderBrush="Black" BorderThickness="0,1,0,0" >
+            <StackPanel x:Name="StackButtons" Margin="4" Orientation="Horizontal"  HorizontalAlignment="Right"></StackPanel>
+        </Border>
+       
+    </Grid>
+</Window>

+ 111 - 0
MBI/SAGA.DotNetUtils/WPF/ShowWindow/WinMessage.xaml.cs

@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Interop;
+
+namespace SAGA.DotNetUtils.WPF
+{
+    /// <summary>
+    /// WinMessageTip.xaml 的交互逻辑
+    /// </summary>
+    public partial class WinMessage : Window
+    {
+        public WinMessage(List<TipButtonItem> items)
+        {
+            InitializeComponent();
+            this.DisableUseClose = true;
+            this.ShowInTaskbar = false;
+            this.AddHandler(Button.ClickEvent, new RoutedEventHandler(Button_Click));
+            items.ForEach(item => StackButtons.Children.Add(CreateButton(item)));
+            this.Loaded += WinMessageTip_Loaded;
+            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (s,e)=> {
+                Clipboard.SetDataObject(Message, false);
+            }));
+        }
+
+        private void WinMessageTip_Loaded(object sender, RoutedEventArgs e)
+        {
+            if(DisableUseClose)
+            {
+                DisableClose();
+            }
+
+        }
+
+        private void Button_Click(object sender, RoutedEventArgs e)
+        {
+            Button button = e.Source as Button;
+            if (button == null)
+                return;
+            TipButtonItem tipItem = button.Tag as  TipButtonItem;
+            try
+            {
+                if (tipItem == null)
+                {
+                    Flag = 0;
+                }
+                else
+                {
+                    Flag = Convert.ToInt32(tipItem.Flag);
+                }
+            }
+            catch (Exception)
+            {
+
+                Flag = 0;
+            }
+            this.DialogResult = true;
+        }
+        
+        internal bool DisableUseClose { get; set; }
+        /// <summary>
+        /// 选中标志
+        /// </summary>
+        public int Flag { get; private set; }
+
+        public string Message {
+            get { return TxtMessage.Text; }
+            set { this.TxtMessage.Text = value;
+            }
+        }
+
+        private Button CreateButton(TipButtonItem item)
+        {
+            Button button = new Button();
+            button.MinWidth = 60;
+            button.MinHeight = 23;
+            button.Margin = new Thickness(10, 0, 10, 0);
+            button.VerticalAlignment = VerticalAlignment.Center;
+            button.Content = item.Content;
+
+            button.IsDefault = item.IsDefault;
+            button.IsCancel = item.IsCancel;
+            if (item.ContentTemplate != null)
+            {
+                button.ContentTemplate = item.ContentTemplate;
+            }
+            button.Tag = item;
+            return button;
+        }
+
+        private void DisableClose()
+        {
+            this.Closing += WinMessageTip_Closing;
+            var interop = new WindowInteropHelper(this);
+            int handle = interop.EnsureHandle().ToInt32();
+            CloseButton.Disable(handle);
+
+        }
+
+        private void WinMessageTip_Closing(object sender, System.ComponentModel.CancelEventArgs e)
+        {
+            //当关闭按钮不能用,并且dialogResult不是ture时,定义为atl+F4,关闭,这种关闭方式取消
+            if (DisableUseClose&&this.DialogResult!=true)
+            {
+                e.Cancel = true;
+            }
+        }
+    }
+}

+ 40 - 0
MBI/SAGA.DotNetUtils/WPF/ShowWindow/WindowCom.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace SAGA.DotNetUtils.WPF
+{
+    public static class CloseButton
+    {
+        [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
+        private static extern int GetSystemMenu(int hwnd, int revert);
+        [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
+        private static extern int EnableMenuItem(int menu, int ideEnableItem, int enable);
+        private const int SC_CLOSE = 0xF060;
+        private const int MF_BYCOMMAND = 0x00000000;
+        private const int MF_GRAYED = 0x00000001;
+        private const int MF_ENABLED = 0x00000002;
+
+        //private CloseButton()
+        //{
+        //}
+
+        public static void Disable(int handle)
+        {
+            // The return value specifies the previous state of the menu item 
+            // (it is either MF_ENABLED or MF_GRAYED). 0xFFFFFFFF indicates that 
+            // the menu item does not exist. 
+            switch (EnableMenuItem(GetSystemMenu(handle, 0), SC_CLOSE, MF_BYCOMMAND | MF_GRAYED))
+            {
+                case MF_ENABLED:
+                    break;
+                case MF_GRAYED:
+                    break;
+                case -1:
+                    throw new Exception("The Close menu item does not exist.");
+                default:
+                    break;
+            }
+        }
+    }
+}
+

+ 25 - 0
MBI/SAGA.GplotManage/CalcMessageTip.cs

@@ -0,0 +1,25 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:CalcMessageTip
+ * 作者:xulisong
+ * 创建时间: 2019/5/28 11:28:50
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using SAGA.DotNetUtils.WPF;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.GplotManage
+{
+    public static class CalcMessageTip
+    {
+        public static bool StartCalc(string message)
+        {
+            var result = CustomMessageShow.ShowOverride(null, message, "开始计算", "关闭");
+            return result == System.Windows.MessageBoxResult.OK;
+        }
+    }
+}

+ 80 - 28
MBI/SAGA.GplotManage/GplotCommand.cs

@@ -6,6 +6,7 @@ using Autodesk.Revit.Attributes;
 using Autodesk.Revit.DB;
 using Autodesk.Revit.UI;
 using SAGA.DotNetUtils.Others;
+using SAGA.DotNetUtils.WPF;
 using SAGA.GplotDrawData;
 using SAGA.GplotDrawData.View;
 using SAGA.GplotManage.RelationManager;
@@ -37,14 +38,25 @@ namespace SAGA.GplotManage
             var state = SpaceComputerDataUtil.ComputeFileState();
             if (state==CacheFileState.Miss)
             {
-                SpaceComputerHandler.ComputerAllRelations();              
+                if (CalcMessageTip.StartCalc("此拓扑需要初始化计算!"))
+                {
+                    SpaceComputerHandler.ComputerAllRelations();
+                }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             else if(state == CacheFileState.Expire)
             {
-                if (MessageShowBase.ConfirmYesNo("您是否要重新计算?"))
+                if (CalcMessageTip.StartCalc("拓扑已发生变化,需要重新计算!"))
                 {
                     SpaceComputerHandler.ComputerAllRelations();
                 }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             var win = new WinDrawSpace_Web(GplotShowType.ViewPlan);// 
             win.Show();
@@ -65,21 +77,28 @@ namespace SAGA.GplotManage
     {
         public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
         {
-            //if (!MessageShowBase.Confirm("确定要执行拓扑计算命令吗"))
-            //{
-            //    return Result.Succeeded;
-            //}
             var state = SpaceComputerDataUtil.ComputeFileState();
             if (state == CacheFileState.Miss)
             {
-                SpaceComputerHandler.ComputerAllRelations();
+                if (CalcMessageTip.StartCalc("此拓扑需要初始化计算!"))
+                {
+                    SpaceComputerHandler.ComputerAllRelations();
+                }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             else if (state == CacheFileState.Expire)
             {
-                if (MessageShowBase.ConfirmYesNo("您是否要重新计算?"))
+                if (CalcMessageTip.StartCalc("拓扑已发生变化,需要重新计算!"))
                 {
                     SpaceComputerHandler.ComputerAllRelations();
                 }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             var win = new WinDrawSpace_Web(GplotShowType.VerticalPlan);
             win.Show();
@@ -108,14 +127,25 @@ namespace SAGA.GplotManage
             var state = SystemComputerHandler.ComputeFileState();
             if (state == CacheFileState.Miss)
             {
-                SystemComputerHandler.ComputerAllRelations();
+                if (CalcMessageTip.StartCalc("此拓扑需要初始化计算!"))
+                {
+                    SystemComputerHandler.ComputerAllRelations();
+                }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             else if (state == CacheFileState.Expire)
             {
-                if (MessageShowBase.ConfirmYesNo("您是否要重新计算?"))
+                if (CalcMessageTip.StartCalc("拓扑已发生变化,需要重新计算!"))
                 {
                     SystemComputerHandler.ComputerAllRelations();
                 }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             WinSystem floorWin = new WinSystem(GplotShowType.ViewPlan);
             floorWin.Show();
@@ -137,21 +167,29 @@ namespace SAGA.GplotManage
     {
         public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
         {
-            //if (!MessageShowBase.Confirm("确定要执行拓扑计算命令吗"))
-            //{
-            //    return Result.Succeeded;
-            //}
+           
             var state = SystemComputerHandler.ComputeFileState();
             if (state == CacheFileState.Miss)
             {
-                SystemComputerHandler.ComputerAllRelations();
+                if (CalcMessageTip.StartCalc("此拓扑需要初始化计算!"))
+                {
+                    SystemComputerHandler.ComputerAllRelations();
+                }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             else if (state == CacheFileState.Expire)
             {
-                if (MessageShowBase.ConfirmYesNo("您是否要重新计算?"))
+                if (CalcMessageTip.StartCalc("拓扑已发生变化,需要重新计算!"))
                 {
                     SystemComputerHandler.ComputerAllRelations();
                 }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             WinSystem floorWin = new WinSystem(GplotShowType.ViewPlan);
             floorWin.Show();
@@ -173,21 +211,28 @@ namespace SAGA.GplotManage
     {
         public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
         {
-            //if (!MessageShowBase.Confirm("确定要执行拓扑计算命令吗"))
-            //{
-            //    return Result.Succeeded;
-            //}
             var state = SystemComputerHandler.ComputeFileState();
             if (state == CacheFileState.Miss)
             {
-                SystemComputerHandler.ComputerAllRelations();
+                if (CalcMessageTip.StartCalc("此拓扑需要初始化计算!"))
+                {
+                    SystemComputerHandler.ComputerAllRelations();
+                }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             else if (state == CacheFileState.Expire)
             {
-                if (MessageShowBase.ConfirmYesNo("您是否要重新计算?"))
+                if (CalcMessageTip.StartCalc("拓扑已发生变化,需要重新计算!"))
                 {
                     SystemComputerHandler.ComputerAllRelations();
                 }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             WinSystem verticalWin = new WinSystem(GplotShowType.VerticalPlan);
             verticalWin.Show();
@@ -210,21 +255,28 @@ namespace SAGA.GplotManage
     {
         public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
         {
-            //if (!MessageShowBase.Confirm("确定要执行拓扑计算命令吗"))
-            //{
-            //    return Result.Succeeded;
-            //}
             var state = SystemComputerHandler.ComputeFileState();
             if (state == CacheFileState.Miss)
             {
-                SystemComputerHandler.ComputerAllRelations();
+                if (CalcMessageTip.StartCalc("此拓扑需要初始化计算!"))
+                {
+                    SystemComputerHandler.ComputerAllRelations();
+                }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             else if (state == CacheFileState.Expire)
             {
-                if (MessageShowBase.ConfirmYesNo("您是否要重新计算?"))
+                if (CalcMessageTip.StartCalc("拓扑已发生变化,需要重新计算!"))
                 {
                     SystemComputerHandler.ComputerAllRelations();
                 }
+                else
+                {
+                    return Result.Succeeded;
+                }
             }
             WinMachineRoom room = new WinMachineRoom();
             room.Show();

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

@@ -99,6 +99,7 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="CalcMessageTip.cs" />
     <Compile Include="Command.cs" />
     <Compile Include="GplotCommand.cs" />
     <Compile Include="GraphTypeEnum.cs" />

+ 3 - 2
MBI/SAGA.MBI/WinView/Upload/VMUploadModeManage.cs

@@ -118,6 +118,7 @@ namespace SAGA.MBI.WinView.Upload
                         int i = 0, count = upfloors.Count;
                         List<string> successList = new List<string>();
                         List<string> failList = new List<string>();
+                        List<CalcContext> useCalcContexts = new List<CalcContext>();
                         foreach (var ufloor in upfloors)
                         {
                             try
@@ -128,7 +129,7 @@ namespace SAGA.MBI.WinView.Upload
                                 string floorName = ufloor.FloorName;
                                 failList.Add(floorName);
 
-
+                                useCalcContexts.Add(new CalcContext(floor));
                                 #region 同步空间名称
                                 var document = ExternalDataWrapper.Current.App.OpenDocumentFile(floor.FullPath);
                                 MBIModelInfoManager.SyncPlatformToRevit(document);
@@ -160,7 +161,7 @@ namespace SAGA.MBI.WinView.Upload
                         }
                         #region 上传底图文件
                         Log4Net.Debug($"开始楼层底图上传");
-                        MBIModelInfoUpload.UpdateMbiInfo(upfloors.Select(f => f.CalcContext).ToList());
+                        MBIModelInfoUpload.UpdateMbiInfo(useCalcContexts);
                         Log4Net.Debug($"结束楼层底图上传");
                         #endregion