@@ -5,6 +5,7 @@ using BPASmartClient.IoT; | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.IO; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Net; | using System.Net; | ||||
using System.Net.Sockets; | using System.Net.Sockets; | ||||
@@ -461,6 +462,31 @@ namespace DataVAPI.Tool.IOT | |||||
} | } | ||||
return "192.168.1.124"; | return "192.168.1.124"; | ||||
} | } | ||||
/// <summary> | |||||
/// Http下载文件 | |||||
/// </summary> | |||||
public static string HttpDownloadFile(string url, string path) | |||||
{ | |||||
// 设置参数 | |||||
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; | |||||
//发送请求并获取相应回应数据 | |||||
HttpWebResponse response = request.GetResponse() as HttpWebResponse; | |||||
//直到request.GetResponse()程序才开始向目标网页发送Post请求 | |||||
Stream responseStream = response.GetResponseStream(); | |||||
//创建本地文件写入流 | |||||
Stream stream = new FileStream(path, FileMode.Create); | |||||
byte[] bArr = new byte[1024]; | |||||
int size = responseStream.Read(bArr, 0, (int)bArr.Length); | |||||
while (size > 0) | |||||
{ | |||||
stream.Write(bArr, 0, size); | |||||
size = responseStream.Read(bArr, 0, (int)bArr.Length); | |||||
} | |||||
stream.Close(); | |||||
responseStream.Close(); | |||||
return path; | |||||
} | |||||
} | } | ||||
@@ -0,0 +1,115 @@ | |||||
using BPASmartClient.CustomResource.UserControls; | |||||
using BPASmartClient.CustomResource.UserControls.MessageShow; | |||||
using BPASmartClient.Helper; | |||||
using BPASmartClient.IoT; | |||||
using DataVAPI.Tool.IOT; | |||||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||||
using Microsoft.Toolkit.Mvvm.Input; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Collections.ObjectModel; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using System.Windows.Media; | |||||
namespace BPASmartClient.ViewModel | |||||
{ | |||||
public class LogOrAlarmIOTViewModel : ObservableObject | |||||
{ | |||||
#region 单一变量 | |||||
private volatile static LogOrAlarmIOTViewModel _Instance; | |||||
public static LogOrAlarmIOTViewModel GetInstance() => _Instance ?? (_Instance = new LogOrAlarmIOTViewModel()); | |||||
private LogOrAlarmIOTViewModel() | |||||
{ | |||||
Init(); | |||||
} | |||||
#endregion | |||||
#region 变量 | |||||
public string api = "https://bpa.black-pa.com:21527/datav/api/Log/QueryLogFile?DeviceName="; | |||||
private ObservableCollection<FileModel> _LogModels; public ObservableCollection<FileModel> LogDataFile | |||||
{ | |||||
get | |||||
{ | |||||
return _LogModels; | |||||
} | |||||
set | |||||
{ | |||||
if (_LogModels == value) | |||||
return; | |||||
_LogModels = value; | |||||
OnPropertyChanged("LogDataFile"); | |||||
} | |||||
} | |||||
#endregion | |||||
#region Command | |||||
public RelayCommand QueryCommand { get; set; } | |||||
#endregion | |||||
#region 函数 | |||||
public void Init() | |||||
{ | |||||
LogDataFile = new ObservableCollection<FileModel>(); | |||||
//查询 | |||||
QueryCommand = new RelayCommand(() => | |||||
{ | |||||
Res(); | |||||
}); | |||||
} | |||||
public void Res() | |||||
{ | |||||
if (DataVClient.GetInstance().DeviceDataV != null && DataVClient.GetInstance().DeviceDataV.deviceTable != null) | |||||
{ | |||||
try | |||||
{ | |||||
LogDataFile.Clear(); | |||||
api = $"https://bpa.black-pa.com:21527/datav/api/Log/QueryLogFile?DeviceName={DataVClient.GetInstance().DeviceDataV.deviceTable.devicename}"; ; | |||||
string json = HttpRequestHelper.HttpGetRequest(api, 1000); | |||||
JsonMsg<List<FileModel>> jsonMsg = Tools.JsonToObjectTools<JsonMsg<List<FileModel>>>(json); | |||||
jsonMsg.obj?.data?.ForEach(file => | |||||
{ | |||||
LogDataFile.Add(file); | |||||
}); | |||||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "提示", $"查询成功,文件数{LogDataFile.Count}!"); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, MainViewModel.GetInstance().window, "提示", $"查询失败!"); | |||||
} | |||||
} | |||||
} | |||||
#endregion | |||||
} | |||||
public class FileModel : ObservableObject | |||||
{ | |||||
public string downloadUrl { get; set; } | |||||
public string fileId { get; set; } | |||||
public string name { get; set; } | |||||
public string size { get; set; } | |||||
public string utcCreatedOn { get; set; } | |||||
private Brush _foreground; | |||||
public Brush foreground | |||||
{ | |||||
get | |||||
{ | |||||
return _foreground; | |||||
} | |||||
set | |||||
{ | |||||
if (_foreground == value) | |||||
return; | |||||
_foreground = value; | |||||
OnPropertyChanged("foreground"); | |||||
} | |||||
} | |||||
public FileModel() | |||||
{ | |||||
foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#21bb2e")); | |||||
} | |||||
} | |||||
} |
@@ -186,16 +186,6 @@ namespace BPASmartClient.ViewModel | |||||
}); | }); | ||||
} | } | ||||
/// <summary> | |||||
/// 查询告警或日志 | |||||
/// </summary> | |||||
/// <param name="time"></param> | |||||
/// <param name="info"></param> | |||||
public void QueryLogOrAlarm(DateTime time, string info) | |||||
{ | |||||
} | |||||
/// <summary> | /// <summary> | ||||
/// 读取文件 | /// 读取文件 | ||||
/// </summary> | /// </summary> | ||||
@@ -0,0 +1,74 @@ | |||||
<UserControl x:Class="BPASmartClient.Control.LogOrAlarmIOTView" | |||||
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" | |||||
xmlns:local="clr-namespace:BPASmartClient.Control" | |||||
mc:Ignorable="d" | |||||
d:DesignHeight="450" d:DesignWidth="800"> | |||||
<UserControl.Resources> | |||||
<ResourceDictionary> | |||||
<ResourceDictionary.MergedDictionaries> | |||||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/GenricStyle.xaml" /> | |||||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml" /> | |||||
</ResourceDictionary.MergedDictionaries> | |||||
</ResourceDictionary> | |||||
</UserControl.Resources> | |||||
<Grid> | |||||
<Grid.RowDefinitions> | |||||
<RowDefinition Height="45" /> | |||||
<RowDefinition Height="*" /> | |||||
</Grid.RowDefinitions> | |||||
<!-- 查询按钮栏 --> | |||||
<StackPanel Margin="10,0,50,0" Orientation="Horizontal" HorizontalAlignment="Right"> | |||||
<Button Margin="10,0,0,0" Cursor="Hand" Command="{Binding QueryCommand}" >查询数据</Button> | |||||
</StackPanel> | |||||
<!-- 表格栏 --> | |||||
<Grid Grid.Row="1"> | |||||
<DataGrid Margin="10" ItemsSource="{Binding LogDataFile, UpdateSourceTrigger=PropertyChanged}" Grid.Row="2"> | |||||
<DataGrid.Columns> | |||||
<DataGridTemplateColumn Header="文件名称" Width="250"> | |||||
<DataGridTemplateColumn.CellTemplate> | |||||
<DataTemplate> | |||||
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontSize="14" Foreground="{Binding foreground, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> | |||||
</DataTemplate> | |||||
</DataGridTemplateColumn.CellTemplate> | |||||
</DataGridTemplateColumn> | |||||
<DataGridTemplateColumn Header="上传时间" Width="250"> | |||||
<DataGridTemplateColumn.CellTemplate> | |||||
<DataTemplate> | |||||
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding utcCreatedOn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontSize="14" Foreground="{Binding foreground, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> | |||||
</DataTemplate> | |||||
</DataGridTemplateColumn.CellTemplate> | |||||
</DataGridTemplateColumn> | |||||
<DataGridTemplateColumn Header="文件大小" Width="100"> | |||||
<DataGridTemplateColumn.CellTemplate> | |||||
<DataTemplate> | |||||
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding size, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontSize="14" Foreground="{Binding foreground, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> | |||||
</DataTemplate> | |||||
</DataGridTemplateColumn.CellTemplate> | |||||
</DataGridTemplateColumn> | |||||
<DataGridTemplateColumn Header="文件ID" Width="300"> | |||||
<DataGridTemplateColumn.CellTemplate> | |||||
<DataTemplate> | |||||
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding fileId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontSize="14" Foreground="{Binding foreground, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> | |||||
</DataTemplate> | |||||
</DataGridTemplateColumn.CellTemplate> | |||||
</DataGridTemplateColumn> | |||||
<DataGridTemplateColumn Header=" " Width="*"> | |||||
<DataGridTemplateColumn.CellTemplate> | |||||
<DataTemplate> | |||||
<Button Tag="{Binding downloadUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" ToolTip="{Binding name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Margin="10,5,0,5" Click="Button_Click">文件下载</Button> | |||||
</DataTemplate> | |||||
</DataGridTemplateColumn.CellTemplate> | |||||
</DataGridTemplateColumn> | |||||
</DataGrid.Columns> | |||||
</DataGrid> | |||||
</Grid> | |||||
</Grid> | |||||
</UserControl> |
@@ -0,0 +1,70 @@ | |||||
using BPASmartClient.CustomResource.UserControls; | |||||
using BPASmartClient.CustomResource.UserControls.MessageShow; | |||||
using BPASmartClient.Helper; | |||||
using BPASmartClient.ViewModel; | |||||
using DataVAPI.Tool.IOT; | |||||
using Microsoft.Win32; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
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; | |||||
using System.Windows.Navigation; | |||||
using System.Windows.Shapes; | |||||
namespace BPASmartClient.Control | |||||
{ | |||||
/// <summary> | |||||
/// LogOrAlarmIOTView.xaml 的交互逻辑 | |||||
/// </summary> | |||||
public partial class LogOrAlarmIOTView : UserControl | |||||
{ | |||||
public LogOrAlarmIOTView() | |||||
{ | |||||
InitializeComponent(); | |||||
this.DataContext = LogOrAlarmIOTViewModel.GetInstance(); | |||||
} | |||||
/// <summary> | |||||
/// 下载文件 | |||||
/// </summary> | |||||
/// <param name="sender"></param> | |||||
/// <param name="e"></param> | |||||
private void Button_Click(object sender, RoutedEventArgs e) | |||||
{ | |||||
try | |||||
{ | |||||
Button button = (Button)sender; | |||||
if (button.Tag != null) | |||||
{ | |||||
string url=button.Tag.ToString(); | |||||
SaveFileDialog openfile = new SaveFileDialog(); | |||||
openfile.Filter = "log文件(*.log)|*.log"; | |||||
openfile.FileName = button.ToolTip.ToString(); | |||||
if (openfile.ShowDialog() == false) | |||||
{ | |||||
return; | |||||
} | |||||
string path = openfile.FileName; | |||||
Tools.HttpDownloadFile(url,path); | |||||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, MainViewModel.GetInstance().window, "提示", $"下载成功!"); | |||||
string msg = string.Format("下载成功,是否打开!"); | |||||
if (System.Windows.MessageBox.Show(msg, "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK) | |||||
{ | |||||
logHelper.GetLogConfigInstance().OpenFile(openfile.FileName); | |||||
} | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, MainViewModel.GetInstance().window, "提示", $"下载失败!"); | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -26,15 +26,5 @@ namespace BPASmartClient.Control | |||||
InitializeComponent(); | InitializeComponent(); | ||||
this.DataContext = LogOrAlarmViewModel.GetInstance(); | this.DataContext = LogOrAlarmViewModel.GetInstance(); | ||||
} | } | ||||
private void CheckBox_Checked(object sender, RoutedEventArgs e) | |||||
{ | |||||
} | |||||
private void CheckBox_Unchecked(object sender, RoutedEventArgs e) | |||||
{ | |||||
} | |||||
} | } | ||||
} | } |
@@ -118,14 +118,14 @@ | |||||
<MenuItem | <MenuItem | ||||
Click="MenuItem_Click" | Click="MenuItem_Click" | ||||
FontSize="12" | FontSize="12" | ||||
Header="日志/告警查询" | |||||
Header="本地日志查询" | |||||
Tag="LogOrAlarmView" /> | Tag="LogOrAlarmView" /> | ||||
<Separator /> | <Separator /> | ||||
<MenuItem | <MenuItem | ||||
Click="MenuItem_Click" | Click="MenuItem_Click" | ||||
FontSize="12" | FontSize="12" | ||||
Header="维护查询" | |||||
Tag="LogOrAlarmView" /> | |||||
Header="云端日志下载" | |||||
Tag="LogOrAlarmIOTView" /> | |||||
</MenuItem> | </MenuItem> | ||||
<MenuItem Header="参数配置"> | <MenuItem Header="参数配置"> | ||||
<MenuItem | <MenuItem | ||||