Browse Source

调整左侧保存,增加清空按钮

master
fyf 2 years ago
parent
commit
a99f1f5d69
10 changed files with 243 additions and 5 deletions
  1. +8
    -0
      BeDesignerSCADA/BeDesignerSCADA.csproj
  2. +5
    -0
      BeDesignerSCADA/Controls/CanvasPanelNew.xaml
  3. BIN
     
  4. BIN
     
  5. BIN
     
  6. BIN
     
  7. +3
    -0
      BeDesignerSCADA/Themes/Styles.xaml
  8. +51
    -0
      BeDesignerSCADA/View/MyMessageBox.xaml
  9. +126
    -0
      BeDesignerSCADA/View/MyMessageBox.xaml.cs
  10. +50
    -5
      BeDesignerSCADA/ViewModel/MainViewModelNew.cs

+ 8
- 0
BeDesignerSCADA/BeDesignerSCADA.csproj View File

@@ -60,11 +60,14 @@
<ItemGroup>
<None Remove="Fonts\ds-digib.ttf" />
<None Remove="Images\bj.png" />
<None Remove="Images\error.png" />
<None Remove="Images\Exp.png" />
<None Remove="Images\fyf.ico" />
<None Remove="Images\gaugeMask.png" />
<None Remove="Images\hbl.ico" />
<None Remove="Images\ico.ico" />
<None Remove="Images\info.png" />
<None Remove="Images\question.png" />
<None Remove="Images\redis.png" />
<None Remove="Images\State0.png" />
<None Remove="Images\State1.png" />
@@ -75,6 +78,7 @@
<None Remove="Images\wx.jpg" />
<None Remove="Images\zfb.jpg" />
<None Remove="Images\光柱.png" />
<None Remove="Images\报错.png" />
<None Remove="Images\配置.ico" />
</ItemGroup>

@@ -94,11 +98,14 @@
<ItemGroup>
<Resource Include="Fonts\ds-digib.ttf" />
<Resource Include="Images\bj.png" />
<Resource Include="Images\error.png" />
<Resource Include="Images\Exp.png" />
<Resource Include="Images\fyf.ico" />
<Resource Include="Images\gaugeMask.png" />
<Resource Include="Images\hbl.ico" />
<Resource Include="Images\ico.ico" />
<Resource Include="Images\info.png" />
<Resource Include="Images\question.png" />
<Resource Include="Images\redis.png" />
<Resource Include="Images\State0.png" />
<Resource Include="Images\State1.png" />
@@ -111,6 +118,7 @@
<Resource Include="Images\光柱.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Images\报错.png" />
<Resource Include="Images\配置.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>


+ 5
- 0
BeDesignerSCADA/Controls/CanvasPanelNew.xaml View File

@@ -69,6 +69,11 @@
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Delete" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="清空该页" Command="{Binding ClearPageCommand}" CommandParameter="{Binding MenuModel.SelectPageModels}">
<MenuItem.Icon>
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Clean" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="(加载)页面" Command="{Binding LoadAllPageCommand}">
<MenuItem.Icon>
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="DiskDownload" />


BIN
View File


BIN
View File


BIN
View File


BIN
View File


+ 3
- 0
BeDesignerSCADA/Themes/Styles.xaml View File

@@ -239,6 +239,9 @@
<Button Width="24" Cursor="Hand" BorderBrush="Transparent" Background="Transparent" CommandParameter="{Binding .}" Command="{Binding DataContext.DeletePageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" VerticalAlignment="Center" Padding="0" ToolTip="删除页">
<icon:PackIconModern ToolTip="删除页" Width="10" HorizontalAlignment="Center" Foreground="White" Kind="Delete" />
</Button>
<Button Width="24" Cursor="Hand" BorderBrush="Transparent" Background="Transparent" CommandParameter="{Binding .}" Command="{Binding DataContext.ClearPageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" VerticalAlignment="Center" Padding="0" ToolTip="清空页">
<icon:PackIconModern ToolTip="清空页" Width="10" HorizontalAlignment="Center" Foreground="White" Kind="Clean" />
</Button>
</StackPanel>
</Grid>
<ControlTemplate.Triggers>


+ 51
- 0
BeDesignerSCADA/View/MyMessageBox.xaml View File

@@ -0,0 +1,51 @@
<Window x:Class="BeDesignerSCADA.View.MyMessageBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BeDesignerSCADA.View"
x:Name="frmMessageBox"
WindowState="Normal"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
Title="提示" Height="150" Width="393">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="19"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.ColumnSpan="2">
<TextBlock Margin="10,0,0,0" FontSize="18" FontFamily="宋体" VerticalAlignment="Center" HorizontalAlignment="Left">提示</TextBlock>
<Image Margin="0,0,10,0" VerticalAlignment="Center" HorizontalAlignment="Right" Source="../Images/报错.png" Cursor="Hand" MouseLeftButtonDown="Image_MouseLeftButtonDown"></Image>
</Grid>

<Image Grid.Row="1" x:Name="picICO" Width="70" Height="70" HorizontalAlignment="Center" VerticalAlignment="Center" Source="../Images/bj.png" Stretch="Fill"></Image>
<Grid Grid.Column="1" Grid.Row="1" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="224*"/>
<ColumnDefinition Width="69*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Border Padding="10" Grid.ColumnSpan="2">
<TextBlock x:Name="labInfo" Grid.Row="0" Text="确定要删除数据吗?" FontSize="18" FontFamily="宋体" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Center"></TextBlock>
</Border>
<Grid Grid.Row="1" Grid.ColumnSpan="2">
<StackPanel x:Name="panel2" Orientation="Horizontal">
<Button x:Name="btnYes" Cursor="Hand" Width="110" Height="31" Content="是(Y)" HorizontalAlignment="Left" VerticalAlignment="Top" ></Button>
<Button x:Name="btnNo" Cursor="Hand" Width="110" Margin="30,0,0,0" Height="31" Content="否(N)" HorizontalAlignment="Left" VerticalAlignment="Top"></Button>
</StackPanel>
<StackPanel x:Name="panel1" Orientation="Horizontal" Visibility="Collapsed">
<Button x:Name="btnOk" Cursor="Hand" Width="250" Height="31" Content="确定(O)" HorizontalAlignment="Left" VerticalAlignment="Top" ></Button>
</StackPanel>
</Grid>
</Grid>
</Grid>
</Window>


+ 126
- 0
BeDesignerSCADA/View/MyMessageBox.xaml.cs View File

@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace BeDesignerSCADA.View
{
/// <summary>
/// MyMessageBox.xaml 的交互逻辑
/// </summary>
public partial class MyMessageBox : Window
{
public MyMessageBox(MessageBoxStyle messageBoxStyle, string msg)
{
InitializeComponent();
this.Width = 393;
btnYes.Click += BtnYes_Click;
btnNo.Click += BtnNo_Click;
btnOk.Click += BtnOk_Click;
this.KeyDown += MyMessageBox_KeyDown;
if (messageBoxStyle == MessageBoxStyle.info)
{
picICO.Source = new BitmapImage(new Uri("../Images/info.png", UriKind.Relative));
//picICO.Image = global::myAlarmSystem.Properties.Resources.info;
this.Title = "提示";
panel1.Visibility = Visibility.Visible;
panel2.Visibility = Visibility.Collapsed;
}
else if (messageBoxStyle == MessageBoxStyle.question)
{
picICO.Source = new BitmapImage(new Uri("../Images/question.png", UriKind.Relative));
//picICO.Image = global::myAlarmSystem.Properties.Resources.question;
this.Title = "询问";
panel1.Visibility = Visibility.Collapsed;
panel2.Visibility = Visibility.Visible;
}
else if (messageBoxStyle == MessageBoxStyle.error)
{
picICO.Source = new BitmapImage(new Uri("../Images/error.png", UriKind.Relative));
//picICO.Image = global::myAlarmSystem.Properties.Resources.error;
this.Title = "错误";
panel1.Visibility = Visibility.Visible;
panel2.Visibility = Visibility.Collapsed;
}

this.labInfo.Text = msg;

SizeF size = TextRenderer.MeasureText(msg, new Font("宋体", 15, System.Drawing.FontStyle.Regular));

int TempWidth = (int)size.Width;
if (TempWidth <= 289) { return; }

this.Height = 150 + ((int)size.Width / 289) * 20;
//this.panel1.Width = TempWidth - 20;
//this.panel2.Width = TempWidth - 20;
//btnYes.Width = TempWidth / 2 - 20;
//btnNo.Width = TempWidth / 2 - 20;
}

private void MyMessageBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.KeyStates == Keyboard.GetKeyStates(Key.N))
{
BtnNo_Click(null, null);
}
else if (e.KeyStates == Keyboard.GetKeyStates(Key.Y))
{
BtnYes_Click(null, null);
}
else if (e.KeyStates == Keyboard.GetKeyStates(Key.O))
{
BtnOk_Click(null, null);
}
}

private void BtnOk_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}

private void BtnNo_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}

private void BtnYes_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}

private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.Close();
}
}

/// <summary>
/// 消息样式类型
/// </summary>
public enum MessageBoxStyle
{
/// <summary>
/// 通知
/// </summary>
info = 0,
/// <summary>
/// 选择
/// </summary>
question = 1,
/// <summary>
/// 错误
/// </summary>
error = 2
};
}

+ 50
- 5
BeDesignerSCADA/ViewModel/MainViewModelNew.cs View File

@@ -426,6 +426,10 @@ namespace BeDesignerSCADA.ViewModel
/// </summary>
public RelayCommand<object> DeletePageCommand { get; set; }
/// <summary>
/// 清除当前页子集
/// </summary>
public RelayCommand<object> ClearPageCommand { get; set; }
/// <summary>
/// 选中该页
/// </summary>
public RelayCommand<object> SelectPageCommand { get; set; }
@@ -455,6 +459,7 @@ namespace BeDesignerSCADA.ViewModel
SetBottomPageCommand = new RelayCommand(new Action(SetBottomPageHeader));
AddPageCommand = new RelayCommand<object>(new Action<object?>(AddPageHeader));
DeletePageCommand = new RelayCommand<object>(new Action<object?>(DeletePageHeader));
ClearPageCommand = new RelayCommand<object>(new Action<object?>(ClearPageHeader));
SelectPageCommand = new RelayCommand<object>(new Action<object?>(SelectPageHeader));
SaveAllPageCommand = new RelayCommand(new Action(SaveAllPageHeader));
LWSaveAllPageCommand=new RelayCommand(new Action(LWSaveAllPageHeader));
@@ -555,7 +560,6 @@ namespace BeDesignerSCADA.ViewModel
{
try
{

if (obj != null && obj is PageModel mode)
{
if (mode.Sort >= 0 && mode.Sort + 1 < MenuModel.pageModels.Count)
@@ -579,13 +583,54 @@ namespace BeDesignerSCADA.ViewModel
/// 删除该页
/// </summary>
public void DeletePageHeader(object obj)
{
try
{
if (obj != null && obj is PageModel page && MenuModel.pageModels.Count > 1)
{
if (new MyMessageBox(MessageBoxStyle.question, $"当前选中页面名称:{page.Name},确认是否删除!").ShowDialog() == true)
{
if (MenuModel.SelectPageModels == page)
{
MenuModel.pageModels.Remove(page);
GxSortTarget();
SelectPageHeader(MenuModel.pageModels[0]);
}
else
{
MenuModel.pageModels.Remove(page);
GxSortTarget();
}
}
}
else if (obj != null)//最后一页
{
if (new MyMessageBox(MessageBoxStyle.question, "至少保留一页,是否清空该页!").ShowDialog() == true)
{
(obj as PageModel).visual.Children.Clear();
SelectPageHeader(MenuModel.pageModels[0]);
}
}
}
catch (Exception ex)
{

}
}
/// <summary>
/// 清空该页
/// </summary>
/// <param name="obj"></param>
public void ClearPageHeader(object obj)
{
try
{
if (obj != null && obj is PageModel page)
{
MenuModel.pageModels.Remove(page);
GxSortTarget();
if (new MyMessageBox(MessageBoxStyle.question, $"页面名称:{page.Name},是否清空该页!").ShowDialog() == true)
{
(obj as PageModel).visual.Children.Clear();
}
}
}
catch (Exception ex)
@@ -674,11 +719,11 @@ namespace BeDesignerSCADA.ViewModel
try
{
BinaryFile.SaveBinary(MenuModel, path);
MessageBox.Show("保存成功!");
new MyMessageBox(MessageBoxStyle.info, $"保存成功!").ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show("保存失败!原因:" +ex.Message);
new MyMessageBox(MessageBoxStyle.error, "保存失败!原因:" + ex.Message).ShowDialog();
}
}
/// <summary>


Loading…
Cancel
Save