Browse Source

增加demo

样式分支
applelon 2 years ago
parent
commit
2d481986b1
14 changed files with 592 additions and 2 deletions
  1. +2
    -2
      DosingSystem/App.xaml.cs
  2. +23
    -0
      SmartClient.sln
  3. +9
    -0
      WPFDemo/App.xaml
  4. +17
    -0
      WPFDemo/App.xaml.cs
  5. +10
    -0
      WPFDemo/AssemblyInfo.cs
  6. +23
    -0
      WPFDemo/MainWindow.xaml
  7. +53
    -0
      WPFDemo/MainWindow.xaml.cs
  8. +31
    -0
      WPFDemo/Segment.cs
  9. +36
    -0
      WPFDemo/Silo.xaml
  10. +60
    -0
      WPFDemo/Silo.xaml.cs
  11. +16
    -0
      WPFDemo/SiloPanel.xaml
  12. +288
    -0
      WPFDemo/SiloPanel.xaml.cs
  13. +24
    -0
      WPFDemo/WPFDemo.csproj
  14. BIN
     

+ 2
- 2
DosingSystem/App.xaml.cs View File

@@ -30,8 +30,8 @@ namespace BPASmartClient.DosingSystem
MenuInit();
DataInit();
DeviceInquire.GetInstance.Init();//配料机设备上线监听,设备列表初始化
NewMaterialDeviceParView newMaterialDeviceParView = new NewMaterialDeviceParView();
newMaterialDeviceParView.ShowDialog();
//NewMaterialDeviceParView newMaterialDeviceParView = new NewMaterialDeviceParView();
//newMaterialDeviceParView.ShowDialog();
MainView mv = new MainView();
//mv.Show();
LoginView lv = new LoginView();


+ 23
- 0
SmartClient.sln View File

@@ -132,6 +132,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.JXJFoodBigSt
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.JXJFoodSmallStation", "BPASmartClient.JXJFoodSmallStation\BPASmartClient.JXJFoodSmallStation.csproj", "{D609C4CF-FA5C-4D39-B12F-07A60FFE5E40}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPFDemo", "WPFDemo\WPFDemo.csproj", "{A456D582-D910-4CA2-8620-6D8F63344B47}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -1266,6 +1268,26 @@ Global
{D609C4CF-FA5C-4D39-B12F-07A60FFE5E40}.Release|x64.Build.0 = Release|Any CPU
{D609C4CF-FA5C-4D39-B12F-07A60FFE5E40}.Release|x86.ActiveCfg = Release|Any CPU
{D609C4CF-FA5C-4D39-B12F-07A60FFE5E40}.Release|x86.Build.0 = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|ARM.ActiveCfg = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|ARM.Build.0 = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|ARM64.Build.0 = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|x64.ActiveCfg = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|x64.Build.0 = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|x86.ActiveCfg = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Debug|x86.Build.0 = Debug|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|Any CPU.Build.0 = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|ARM.ActiveCfg = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|ARM.Build.0 = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|ARM64.ActiveCfg = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|ARM64.Build.0 = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|x64.ActiveCfg = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|x64.Build.0 = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|x86.ActiveCfg = Release|Any CPU
{A456D582-D910-4CA2-8620-6D8F63344B47}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1327,6 +1349,7 @@ Global
{D1F2379E-1755-4B50-9D67-15C960C33FFA} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625}
{FA695D7E-6F12-4483-A16D-8494609FAE68} = {8712125E-14CD-4E1B-A1CE-4BDE03805942}
{D609C4CF-FA5C-4D39-B12F-07A60FFE5E40} = {8712125E-14CD-4E1B-A1CE-4BDE03805942}
{A456D582-D910-4CA2-8620-6D8F63344B47} = {8712125E-14CD-4E1B-A1CE-4BDE03805942}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9AEC9B81-0222-4DE9-B642-D915C29222AC}


+ 9
- 0
WPFDemo/App.xaml View File

@@ -0,0 +1,9 @@
<Application x:Class="WPFDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFDemo"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

+ 17
- 0
WPFDemo/App.xaml.cs View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace WPFDemo
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

+ 10
- 0
WPFDemo/AssemblyInfo.cs View File

@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

+ 23
- 0
WPFDemo/MainWindow.xaml View File

@@ -0,0 +1,23 @@
<Window x:Class="WPFDemo.MainWindow"
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:WPFDemo"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Width="120" Height="30" Content="ADD" Click="Button_Click" />
<Button Width="120" Height="30" Content="DRAW LINE" Click="Button_Click_1" />
<Button Width="120" Height="30" Content="LOAD" Click="Button_Click_2" />
<Button Width="120" Height="30" Content="SAVE" Click="Button_Click_3" />
<Button Width="120" Height="30" Content="CLR" Click="Button_Click_4" />
</StackPanel>
<local:SiloPanel x:Name="sp" Grid.Row="1" PanelHeight="1030" PanelWidth="2000"/>
</Grid>
</Window>

+ 53
- 0
WPFDemo/MainWindow.xaml.cs View File

@@ -0,0 +1,53 @@
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 WPFDemo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
sp.AddSilo();
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
sp.AddLine();
}

private void Button_Click_2(object sender, RoutedEventArgs e)
{
sp.Load();
}

private void Button_Click_3(object sender, RoutedEventArgs e)
{
sp.Save();
}

private void Button_Click_4(object sender, RoutedEventArgs e)
{
sp.Clear();
}
}
}

+ 31
- 0
WPFDemo/Segment.cs View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Shapes;

namespace WPFDemo
{
public class Segment
{
public List<SimpleSilo> Silos { get; set; } = new List<SimpleSilo>();

public List<SimpleLine> Lines { get; set; } = new List<SimpleLine>();

public class SimpleSilo
{
public string Caption { get; set; }
public string Index { get; set; }
public double Top { get; set; }
public double Left { get; set; }
}

public class SimpleLine {
public double X1 { get; set; }
public double X2 { get; set; }
public double Y1 { get; set; }
public double Y2 { get; set; }
}
}
}

+ 36
- 0
WPFDemo/Silo.xaml View File

@@ -0,0 +1,36 @@
<UserControl x:Class="WPFDemo.Silo"
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:WPFDemo"
Width="120"
Height="150"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
>
<Border BorderBrush="#FF243654" Background="#FF79E8C7">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="35"></RowDefinition>
</Grid.RowDefinitions>
<Image Width="120" Height="120" Source="device.png"></Image>
<Grid Grid.Row="1" Margin="10,2">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="编号" Grid.Row="0" Grid.Column="0"></TextBlock>
<TextBlock Text="{Binding Index}" Grid.Row="0" Grid.Column="1"></TextBlock>

<TextBlock Text="编号" Grid.Row="1" Grid.Column="0"></TextBlock>
<TextBlock Text="{Binding Caption}" Grid.Row="1" Grid.Column="1"></TextBlock>
</Grid>
</Grid>
</Border>
</UserControl>

+ 60
- 0
WPFDemo/Silo.xaml.cs View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
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 WPFDemo
{
/// <summary>
/// Silo.xaml 的交互逻辑
/// </summary>
public partial class Silo : UserControl, INotifyPropertyChanged
{


public string Index
{
get { return (string)GetValue(IndexProperty); }
set { SetValue(IndexProperty, value);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Index"));
}
}

// Using a DependencyProperty as the backing store for Index. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IndexProperty =
DependencyProperty.Register("Index", typeof(string), typeof(Silo), new PropertyMetadata("Unkown"));



public string Caption
{
get { return (string)GetValue(CaptionProperty); }
set { SetValue(CaptionProperty, value);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Caption"));
}
}

// Using a DependencyProperty as the backing store for Caption. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CaptionProperty =
DependencyProperty.Register("Caption", typeof(string), typeof(Silo), new PropertyMetadata("Null"));


public Silo()
{
InitializeComponent();
}

public event PropertyChangedEventHandler? PropertyChanged;
}
}

+ 16
- 0
WPFDemo/SiloPanel.xaml View File

@@ -0,0 +1,16 @@
<UserControl x:Name="userControl" x:Class="WPFDemo.SiloPanel"
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:WPFDemo"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d" >
<Viewbox >
<Canvas Name="cvMain" Width="{Binding PanelWidth}" Height="{Binding PanelHeight}" Background="#B2C0E2E1">
<StackPanel Orientation="Horizontal" Canvas.Top="5" Canvas.Left="5">
<TextBlock FontSize="15" Text="{Binding Tips}"></TextBlock>
</StackPanel>
</Canvas>
</Viewbox>
</UserControl>

+ 288
- 0
WPFDemo/SiloPanel.xaml.cs View File

@@ -0,0 +1,288 @@
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
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;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPFDemo
{
/// <summary>
/// SiloPanel.xaml 的交互逻辑
/// </summary>
public partial class SiloPanel : UserControl, INotifyPropertyChanged
{
//料仓模块左键按下标识
bool siloIsMouseDown = false;
//画线标识
bool lineIsDraw = false;
//当前线条
private Line currentLine;
//线条集合
private List<Line> lines = new List<Line>();
//料仓集合
private List<Silo> silos = new List<Silo>();
//用于序列化
private Segment segment = new Segment();

//提示
private string tips = "常规模式";
/// <summary>
/// 提示
/// </summary>
public string Tips
{
get { return tips; }
set
{
tips = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Tips"));
}
}
/// <summary>
/// 当前选中的料仓
/// </summary>
public Silo CurrentSilo { get; private set; }

/// <summary>
/// 画布宽度
/// </summary>
public double PanelWidth
{
get { return (double)GetValue(PanelWidthProperty); }
set { SetValue(PanelWidthProperty, value); }
}

// Using a DependencyProperty as the backing store for PanelWidth. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PanelWidthProperty =
DependencyProperty.Register("PanelWidth", typeof(double), typeof(SiloPanel), new PropertyMetadata(1920d));


/// <summary>
/// 画布高度
/// </summary>
public double PanelHeight
{
get { return (double)GetValue(PanelHeightProperty); }
set { SetValue(PanelHeightProperty, value); }
}

// Using a DependencyProperty as the backing store for PanelHeight. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PanelHeightProperty =
DependencyProperty.Register("PanelHeight", typeof(double), typeof(SiloPanel), new PropertyMetadata(1080d));

public event PropertyChangedEventHandler? PropertyChanged;

public SiloPanel()
{
InitializeComponent();
cvMain.PreviewMouseLeftButtonDown += CvMain_PreviewMouseLeftButtonDown;
cvMain.PreviewMouseMove += CvMain_PreviewMouseMove;
cvMain.PreviewMouseLeftButtonUp += CvMain_PreviewMouseLeftButtonUp;
}

/// <summary>
/// 开始画线
/// </summary>
public void AddLine()
{
lineIsDraw = true;
Tips = "线条绘制";
}

/// <summary>
/// 添加料仓模块
/// </summary>
public void AddSilo()
{
if (lineIsDraw)
lineIsDraw = false;
newSilo(String.Empty, String.Empty);
}

/// <summary>
/// 保存文件
/// </summary>
public void Save()
{
segment.Silos.Clear();
segment.Lines.Clear();
lines.ForEach(line =>
{
segment.Lines.Add(new Segment.SimpleLine() { X1 = line.X1, X2 = line.X2, Y1 = line.Y1, Y2 = line.Y2 });
});
silos.ForEach(silo =>
{
segment.Silos.Add(new Segment.SimpleSilo()
{
Left = (double)silo.GetValue(Canvas.LeftProperty),
Top = (double)silo.GetValue(Canvas.TopProperty),
Caption = silo.Caption,
Index = silo.Index
});
});


string ResultJson = JsonConvert.SerializeObject(segment);
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "配置文件|*.json";
if (dialog.ShowDialog() == true)
{
File.WriteAllText(dialog.FileName, ResultJson);
}
}

/// <summary>
/// 加载文件
/// </summary>
public void Load()
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "配置文件|*.json";
if (dialog.ShowDialog() == true)
{
string content = File.ReadAllText(dialog.FileName);
try
{
segment = JsonConvert.DeserializeObject<Segment>(content);
lines.Clear();
silos.Clear();
cvMain.Children.Clear();
foreach (var line in segment.Lines)
{
newLine(line.X1, line.Y1, line.X2, line.Y2);
}
foreach (var temp in segment.Silos)
{
newSilo(temp.Caption, temp.Index,temp.Left,temp.Top);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}

/// <summary>
/// 清空画布
/// </summary>
public void Clear()
{
lines.Clear();
silos.Clear();
cvMain.Children.Clear();
}

private void newSilo(string caption, string index, double left = -1, double top = -1)
{
Silo silo = new Silo() { Caption = caption, Index = index };
if (left == -1)
silo.SetValue(Canvas.LeftProperty, cvMain.ActualWidth / 2 - silo.Width / 2);
else
silo.SetValue(Canvas.LeftProperty, left);

if (top == -1)
silo.SetValue(Canvas.TopProperty, cvMain.ActualHeight / 2 - silo.Height / 2);
else
silo.SetValue(Canvas.TopProperty, top);

silo.AllowDrop = true;
cvMain.Children.Add(silo);
silos.Add(silo);
silo.PreviewMouseLeftButtonDown += Silo_PreviewMouseLeftButtonDown;
silo.PreviewMouseMove += Silo_PreviewMouseMove;
silo.PreviewMouseLeftButtonUp += Silo_PreviewMouseLeftButtonUp;

CurrentSilo = silo;
}

private void newLine(double x1, double y1, double x2, double y2)
{
var temp = new Line();
temp.Stroke = Brushes.Green;
temp.StrokeThickness = 1;
temp.X1 = x1;
temp.Y1 = y1;
temp.X2 = x2;
temp.Y2 = y2;
cvMain.Children.Add(temp);
lines.Add(temp);

currentLine = temp;
}

private void CvMain_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
lineIsDraw = false;
Tips = "常规模式";
}

private void CvMain_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && lineIsDraw)
{
Point point = e.GetPosition(cvMain);
currentLine.X2 = point.X;
currentLine.Y2 = point.Y;
}
}

private void CvMain_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (!lineIsDraw)
return;
var point = e.GetPosition(cvMain);
newLine(point.X, point.Y, point.X, point.Y);

}



private void Silo_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
var c = sender as UIElement;
siloIsMouseDown = false;
c.ReleaseMouseCapture();
CurrentSilo = sender as Silo;
}

private void Silo_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (siloIsMouseDown)
{
var c = sender as UIElement;
var pos = e.GetPosition(this);
c.SetValue(Canvas.LeftProperty, pos.X);
c.SetValue(Canvas.TopProperty, pos.Y);
}
}

private void Silo_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var c = sender as UIElement;
siloIsMouseDown = true;
var transform = c.RenderTransform as TranslateTransform;
if (transform == null)
{
transform = new TranslateTransform();
c.RenderTransform = transform;
}
c.CaptureMouse();
}


}
}

+ 24
- 0
WPFDemo/WPFDemo.csproj View File

@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<None Remove="device.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
<Resource Include="device.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</ItemGroup>

</Project>

BIN
View File


Loading…
Cancel
Save