Bladeren bron

进行了一些优化

djs 4 maanden geleden
bovenliggende
commit
4bbfef5386

+ 61 - 0
MV485/Dlg/DlgSaveImagePath.xaml

@@ -0,0 +1,61 @@
+<Window x:Class="MV485.Dlg.DlgSaveImagePath"
+        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:MV485.Dlg"
+        mc:Ignorable="d"
+        Background="WhiteSmoke"
+        ResizeMode="NoResize"
+        WindowStartupLocation="CenterOwner"
+        ShowInTaskbar="False"
+        Title="设置监听数据中图像的保存路径" Height="240" Width="400">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="*" />
+            <RowDefinition Height="40" />
+        </Grid.RowDefinitions>
+        
+        <Border BorderBrush="#D3D3D3" Background="White" BorderThickness="0 0 0 1" Padding="10" Margin="10">
+            <Grid>
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="40" />
+                    <RowDefinition Height="40" />
+                </Grid.RowDefinitions>
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition Width="*" />
+                    <ColumnDefinition Width="80" />
+                </Grid.ColumnDefinitions>
+
+                <TextBlock x:Name="txtPrompt" Grid.Row="0" Grid.Column="0" Margin="0 0 0 10" 
+                           VerticalAlignment="Center"
+                       Text="图像保存路径:" FontSize="14" TextWrapping="Wrap" />
+
+                <TextBox x:Name="txtImagePath" Grid.Row="1" Grid.Column="0" 
+                         IsReadOnly="True" FontSize="13px" Margin="0 0 0 0" 
+                          Padding="5"  VerticalAlignment="Center"/>
+                <Button x:Name="btnBrowser" Grid.Row="1" Grid.Column="1" Content="浏览..."  
+                        Height="26" VerticalAlignment="Center"
+                    Margin="10 0 0 0" FontSize="14px"
+                    Click="BtnBrowser_Click"/>
+            </Grid>
+            <!--<StackPanel Orientation="Vertical">
+                
+                <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
+                    
+                    
+                </StackPanel>                    
+            </StackPanel>-->
+        </Border>
+
+        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
+            <Button Name="btnOK" Content="确  定" Width="80" Height="26" VerticalAlignment="Center"
+                    Margin="10 0 0 0" FontSize="14px"
+                    Click="BtnOK_Click"/>
+            <Button Name="btnClose" Content="关  闭" Width="80" Height="26" VerticalAlignment="Center"
+                    Margin="10 0 0 0" FontSize="14px"
+                    Click="BtnClose_Click"/>
+        </StackPanel>
+
+    </Grid>
+</Window>

+ 73 - 0
MV485/Dlg/DlgSaveImagePath.xaml.cs

@@ -0,0 +1,73 @@
+using MV485.helper;
+using Ookii.Dialogs.Wpf;
+using System;
+using System.Collections.Generic;
+using System.IO;
+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.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+
+namespace MV485.Dlg
+{
+    /// <summary>
+    /// DlgSaveImagePath.xaml 的交互逻辑
+    /// </summary>
+    public partial class DlgSaveImagePath : Window
+    {
+        //默认的图像保存路径
+        public static string DefaultImagePath =
+            Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wm_image");
+        //private string _selectedSavePath = "";
+        public DlgSaveImagePath()
+        {
+            InitializeComponent();
+
+            //获取图像保存路径
+            string savePath = ConfigManager.Instance.GetConfigValue(ConfigKey.SaveImagePath, DefaultImagePath);
+            txtImagePath.Text = savePath;
+        }
+
+        private void BtnBrowser_Click(object sender, RoutedEventArgs e)
+        {
+            var dialog = new VistaFolderBrowserDialog();
+            //dialog.Description = "请选择目标图像输出文件夹";
+            dialog.Description = "请选择数据监听时图像数据的保存文件夹";
+            dialog.UseDescriptionForTitle = true; // 使用 Description 作为窗口标题
+
+            // 显示对话框并检查用户是否点击了“确定”
+            if (dialog.ShowDialog() == true)
+            {
+                // 获取用户选择的文件夹路径
+                string selectedFolderPath = dialog.SelectedPath;
+                //mConfigItem.Output = selectedFolderPath;
+                //_selectedSavePath = selectedFolderPath;
+                txtImagePath.Text = selectedFolderPath;
+            }
+        }
+
+        private void BtnOK_Click(object sender, RoutedEventArgs e)
+        {
+            if(string.IsNullOrEmpty(txtImagePath.Text))
+            {
+                MessageBox.Show("文件夹不能为空", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+            ConfigManager.Instance.UpdateConfig(ConfigKey.SaveImagePath, txtImagePath.Text.Trim());
+            DialogResult = true;
+            this.Close();
+        }
+
+        private void BtnClose_Click(object sender, RoutedEventArgs e)
+        {
+            this.Close();
+        }
+        //-------------------------------------------------------
+    }
+}

+ 7 - 0
MV485/MV485.csproj

@@ -123,6 +123,9 @@
     <Compile Include="Dlg\DlgMark.xaml.cs">
       <DependentUpon>DlgMark.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Dlg\DlgSaveImagePath.xaml.cs">
+      <DependentUpon>DlgSaveImagePath.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Dlg\DlgSearchDevices.xaml.cs">
       <DependentUpon>DlgSearchDevices.xaml</DependentUpon>
     </Compile>
@@ -224,6 +227,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Dlg\DlgSaveImagePath.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Dlg\DlgSearchDevices.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 1 - 0
MV485/helper/ConfigManager.cs

@@ -111,6 +111,7 @@ namespace MV485.helper
         DataLeftWidth,      //数据监控左侧*的宽度
         AutoListenData,     //自动监听数据    
         IsSearchOne,          //搜索一个设备
+        SaveImagePath,        //图像的保存路径
         // 其他配置项...
     }
     //-----------------------------------------------

+ 1 - 1
MV485/helper/FindDeviceHelper.cs

@@ -50,7 +50,7 @@ namespace MV485.helper
         private string _message;
 
         private bool _blSearchOne = false;
-        private int _findCount = 0;
+        public int _findCount = 0;
         public FindDeviceHelper()
         {
             //_portName = portName;

+ 1 - 1
MV485/helper/RWRunConfig.cs

@@ -272,7 +272,7 @@ namespace MV485.helper
                 WMData data = new WMData();
                 ushort[] readRegisters;
 
-                readName = "读取波特率";
+                readName = "波特率";
                 readRegisters = _modbusMaster.ReadHoldingRegisters(devId,
                     Constant.MB_REGISTER_ADD_BAUDRATE, Constant.MB_REGISTER_NUM_BAUDRATE);
                 //data.BaudRate =  readRegisters[0];

+ 9 - 3
MV485/helper/SerialPollingGroup.cs

@@ -1,4 +1,5 @@
 using MV485.db;
+using MV485.Dlg;
 using MV485.model;
 using System;
 using System.Collections.Generic;
@@ -132,9 +133,14 @@ namespace MV485.helper
                 {
                     ushort imageSize = _reader.ReadImageSize(slave.PortName, slave.BaudRate, (byte)slave.Address);
                     imageFilePath = $"{data.DeviceSn}_{data.SampleTime.ToString("yyyyMMddHHmm")}_{dtReadTime.ToString("yyyyMMddHHmmss")}.jpg";
-                    imageFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, 
-                        "wm_image", $"{DateTime.Now.ToString("yyyyMMdd")}",imageFilePath);
-                   
+
+                    string savePath = ConfigManager.Instance.GetConfigValue(ConfigKey.SaveImagePath, DlgSaveImagePath.DefaultImagePath);
+
+                    //imageFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, 
+                    //    "wm_image", $"{DateTime.Now.ToString("yyyyMMdd")}",imageFilePath);
+                    imageFilePath = Path.Combine(savePath, $"{DateTime.Now.ToString("yyyyMMdd")}", imageFilePath);
+
+
                     if (imageSize > 0)
                     {
                         XModemReceiver receiver = new XModemReceiver();

+ 5 - 0
MV485/uc/UCDeviceFinder.xaml.cs

@@ -234,6 +234,11 @@ namespace MV485.uc
                 //waitWindow.Close();
                 _dlgSearch?.Close();
                 Application.Current.MainWindow.IsEnabled = true;
+
+                string findCounMsg = _deviceFinder._findCount == 0 ? 
+                    "未搜索到设备" : $"已搜索到{_deviceFinder._findCount}台设备";
+                MessageBox.Show(Application.Current.MainWindow, findCounMsg, "提示", 
+                    MessageBoxButton.OK, MessageBoxImage.Information);
                 //StopSearch();
             }
         }

+ 4 - 0
MV485/uc/UCMonitorData2.xaml

@@ -71,6 +71,10 @@
                                       DisplayMemberPath="Value" SelectedValuePath="Key" Width="110" Visibility="Collapsed"                                  
                                       Margin="0,0,10,0" Padding="4" VerticalAlignment="Center"/>
 
+                        <zdfflatui:FlatButton Grid.Column="0" x:Name="btnSetImagePath" HorizontalAlignment="Left"
+                                                  Background="#2196F3" Content="图像路径"
+                                                    Click="BtnSetImagePath_Click" Foreground="White"
+                                                  Width="80" Height="28" FontSize="13" Margin="10 0 0 0" />
                             <zdfflatui:FlatButton Grid.Column="0" x:Name="btnAddDevice" HorizontalAlignment="Left"
                                                   Background="#4CAF50" Content="添加设备"
                                                     Click="BtnAddDevice_Click" Foreground="White"

+ 12 - 0
MV485/uc/UCMonitorData2.xaml.cs

@@ -907,6 +907,18 @@ namespace MV485.uc
             //}
         }
 
+        private void BtnSetImagePath_Click(object sender, RoutedEventArgs e)
+        {
+            DlgSaveImagePath dlgSave = new DlgSaveImagePath()
+            {
+                Owner = Application.Current.MainWindow,
+                WindowStartupLocation = WindowStartupLocation.CenterOwner
+            };
+
+            dlgSave.ShowDialog();
+
+        }
+
 
         //----------------------------------------------------------
     }

+ 1 - 1
MV485/uc/UCRunConfig.xaml

@@ -162,7 +162,7 @@
                             </Grid>
 
                             <Border BorderBrush="#D3D3D3" BorderThickness="1" Margin="10 0 10 0" Padding="0 5 0 5">
-                                <Image x:Name="imgMeter" Width="360" Height="270">
+                                <Image x:Name="imgMeter" MouseLeftButtonDown="ImgMeter_MouseLeftButtonDown" Width="360" Height="270">
 
                                 </Image>
                             </Border>

+ 13 - 0
MV485/uc/UCRunConfig.xaml.cs

@@ -1182,6 +1182,19 @@ namespace MV485.uc
             }
         }
 
+        private void ImgMeter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+        {
+            if(imgMeter.Source != null && File.Exists(ImageFilePath))
+            {
+                DlgImage dialog = new DlgImage(ImageFilePath)
+                {
+                    Owner = Application.Current.MainWindow
+                };
+                //dialog.ShowDialog();
+                dialog.Show();
+            }
+        }
+
         //------------------------------------------------------------------
     }
 }