Merge pull request 'dev' (#4) from dev into master

Reviewed-on: #4
master
wenjy 7 months ago
commit 756d5dff46

@ -0,0 +1,113 @@
using SlnMesnac.Generate.Templates.Service;
using SlnMesnac.Generate.Templates.Service.Impl;
using SqlSugar;
using System;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Generate
* 78595105-fab6-40f0-97b4-1272dc3e0e86
*
* WenJY
* wenjy@mesnac.com
* 2024-04-11 13:35:01
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Generate
{
/// <summary>
/// 生成代码
/// </summary>
public class GenerateCode
{
private readonly ISqlSugarClient _sqlSugarClient;
public GenerateCode(ISqlSugarClient sqlSugarClient)
{
_sqlSugarClient = sqlSugarClient;
}
public bool CreateCode(string configId,string tableName,string savePath,string nameSpace)
{
if (string.IsNullOrEmpty(configId))
{
throw new ArgumentNullException($"代码生成异常:configId参数为空");
}
if (string.IsNullOrEmpty(tableName))
{
throw new ArgumentNullException($"代码生成异常:表格名称参数为空");
}
if (string.IsNullOrEmpty(savePath))
{
throw new ArgumentNullException($"代码生成异常:文件存储路径参数为空");
}
if (string.IsNullOrEmpty(nameSpace))
{
throw new ArgumentNullException($"代码生成异常:命名空间参数为空");
}
try
{
savePath += $"\\{tableName}";
var scope = _sqlSugarClient.AsTenant().GetConnectionScope(configId);
scope.DbFirst.IsCreateAttribute()
.FormatPropertyName(it=> ToCamelCase(it)).Where(p => p == tableName).CreateClassFile($"{savePath}\\Entity", nameSpace);
var isc = new IServiceCreate();
bool iscRes = isc.Create(tableName, nameSpace, savePath);
if (!iscRes)
{
throw new InvalidOperationException($"Service接口生成失败");
}
var sc = new ServiceCreate();
var scRes = sc.Create(tableName, nameSpace, savePath);
if (!scRes)
{
throw new InvalidOperationException($"Service实现类生成失败");
}
return true;
}catch (Exception ex)
{
throw new InvalidOperationException($"代码生成异常:{ex.Message}");
}
}
private static string ToCamelCase(string input)
{
// 将字符串转换为驼峰格式,但保持每个单词的首字母大写
string[] words = input.Split('_');
for (int i = 0; i < words.Length; i++)
{
if (i > 0)
{
words[i] = char.ToUpper(words[i][0]) + words[i].Substring(1).ToLower();
}
else
{
words[i] = words[i].ToLower();
}
}
return string.Join("", words);
}
}
}

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NVelocity" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,78 @@
using Commons.Collections;
using NVelocity.App;
using NVelocity.Runtime;
using NVelocity;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Generate.Templates
* 4dbafd45-d689-4d1a-b54d-b936dae7d17c
*
* WenJY
* wenjy@mesnac.com
* 2024-04-11 13:28:04
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Generate.Templates.Service
{
public class IServiceCreate
{
private static readonly string templateDir = @"E:\桌面\SlnMesnac\SlnMesnac.Generate\Templates\Service\";
public bool Create(string tableName, string NameSpace, string outdir)
{
try
{
VelocityEngine velocityEngine = new VelocityEngine();
ExtendedProperties props = new ExtendedProperties();
props.AddProperty(RuntimeConstants.RESOURCE_LOADER, @"file");
props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir);
props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
//模板的缓存设置
props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true); //是否缓存
props.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)30); //缓存时间(秒)
velocityEngine.Init(props);
//为模板变量赋值
VelocityContext context = new VelocityContext();
context.Put("tableName", tableName);
context.Put("NameSpace", NameSpace);
context.Put("outdir", outdir);
//从文件中读取模板
Template template = velocityEngine.GetTemplate(@"\IServices.vm");
if (!Directory.Exists(outdir + "\\IServices"))
{
Directory.CreateDirectory(outdir + "\\IServices");
}
//合并模板
using (StreamWriter writer = new StreamWriter(outdir + $"\\IServices\\I{tableName.Substring(0, 1).ToUpper()}{tableName.Substring(1)}Service.cs", false))
{
template.Merge(context, writer);
}
return true;
}catch(Exception ex)
{
throw new InvalidOperationException($"Service接口模板创建异常:{ex.Message}");
}
}
}
}

@ -0,0 +1,13 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Text;
namespace ${NameSpace}.service
{
public interface I${tableName}Services: IBaseService<${tableName}>
{
}
}

@ -0,0 +1,75 @@
using Commons.Collections;
using NVelocity.App;
using NVelocity.Runtime;
using NVelocity;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Generate.Templates
* 4acc596a-6223-4156-b16c-952c225eff25
*
* WenJY
* wenjy@mesnac.com
* 2024-04-11 13:27:33
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Generate.Templates.Service.Impl
{
public class ServiceCreate
{
private static readonly string templateDir = @"E:\桌面\SlnMesnac\SlnMesnac.Generate\Templates\Service\Impl\";
public bool Create(string tableName, string NameSpace, string outdir)
{
try
{
VelocityEngine velocityEngine = new VelocityEngine();
ExtendedProperties props = new ExtendedProperties();
props.AddProperty(RuntimeConstants.RESOURCE_LOADER, @"file");
props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir);
props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
//模板的缓存设置
props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true); //是否缓存
props.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)30); //缓存时间(秒)
velocityEngine.Init(props);
//为模板变量赋值
VelocityContext context = new VelocityContext();
context.Put("tableName", tableName);
context.Put("NameSpace", NameSpace);
context.Put("outdir", outdir);
//从文件中读取模板
Template template = velocityEngine.GetTemplate(@"\Services.vm");
if (!Directory.Exists(outdir + "\\Services"))
{
Directory.CreateDirectory(outdir + "\\Services");
}
//合并模板
using (StreamWriter writer = new StreamWriter(outdir + $"\\Services\\{tableName.Substring(0, 1).ToUpper()}{tableName.Substring(1)}ServiceImpl.cs", false))
{
template.Merge(context, writer);
}
return true;
}catch(Exception ex)
{
throw new InvalidOperationException($"Service实现类模板创建异常:{ex.Message}");
}
}
}
}

@ -0,0 +1,14 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
namespace ${NameSpace}.service.Impl
{
public class ${tableName}ServiceImpl : BaseServiceImpl<${tableName}>, I${tableName}Service
{
public ${tableName}ServiceImpl(Repository<${tableName}> repository):base(repository)
{
}
}
}

@ -60,6 +60,9 @@ namespace SlnMesnac.Ioc
//注入业务类 //注入业务类
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Business.dll")); RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Business.dll"));
//注入代码生成
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Generate.dll"));
} }

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.WPF.Converter.Generate
* 38e34c93-1c10-4a1c-83b0-c545affdc224
*
* WenJY
* wenjy@mesnac.com
* 2024-04-11 10:27:10
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.Converter.Generate
{
internal class RowToIndexConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var item = values[0];
var dataGrid = values[1] as DataGrid;
if (item == null || dataGrid == null)
return null;
var index = dataGrid.Items.IndexOf(item) + 1;
return index;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

@ -62,6 +62,7 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Horizontal"> <StackPanel Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Horizontal">
<Button Content="首 页" x:Name="Index" Command="{Binding ControlOnClickCommand}" CommandParameter="{Binding Name,ElementName=Index}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="10,0,10,0"/> <Button Content="首 页" x:Name="Index" Command="{Binding ControlOnClickCommand}" CommandParameter="{Binding Name,ElementName=Index}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="10,0,10,0"/>
<Button Content="代码生成" x:Name="Generate" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=Generate}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="0,0,10,0"/>
<Button Content="键 盘" Command="{Binding OpenSystemKeyboardCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="0,0,10,0"/> <Button Content="键 盘" Command="{Binding OpenSystemKeyboardCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="0,0,10,0"/>
<Button Content="最小化" x:Name="Minimized" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=Minimized}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF9900" BorderBrush="#FF9900" Margin="0,0,10,0"/> <Button Content="最小化" x:Name="Minimized" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=Minimized}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF9900" BorderBrush="#FF9900" Margin="0,0,10,0"/>
<Button Content="退 出" x:Name="Exit" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=Exit}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF0033" BorderBrush="#FF0033" Margin="0,0,10,0"/> <Button Content="退 出" x:Name="Exit" Command="{Binding FormControlCommand}" CommandParameter="{Binding Name,ElementName=Exit}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF0033" BorderBrush="#FF0033" Margin="0,0,10,0"/>

@ -0,0 +1,56 @@
<UserControl x:Class="SlnMesnac.WPF.Page.Generate.GenerateControl"
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:SlnMesnac.WPF.Page.Generate"
xmlns:local1="clr-namespace:SlnMesnac.WPF.Converter.Generate"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Background="Transparent">
<Control.Resources>
<local1:RowToIndexConverter x:Key="RowToIndexConverter" />
</Control.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="8*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="Green" BorderThickness="2" CornerRadius="5" Margin="0,0,0,10">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
<TextBlock Text="数据库连接:" FontSize="20" Foreground="White" VerticalAlignment="Center" Margin="10,0,10,0"/>
<ComboBox Width="200" Height="35" FontSize="18" VerticalAlignment="Center" Name="comboBox1" ItemsSource="{Binding Options}" SelectedItem="{Binding SelectedOption, Mode=TwoWay}" DisplayMemberPath="."/>
<TextBlock Text="表名:" FontSize="20" Foreground="White" VerticalAlignment="Center" Margin="30,0,10,0"/>
<TextBox x:Name="queryParam" Foreground="White" FontSize="18" Width="200" Height="35"/>
<Button Content="查 询" FontSize="16" Style="{StaticResource BUTTON_AGREE}" Width="120" Height="35" Background="#007DFA" BorderBrush="#007DFA" Margin="20,0,10,0" Command="{Binding QuerySearchCommand}" CommandParameter="{Binding Text, ElementName=queryParam}" />
</StackPanel>
</Border>
<Border Grid.Row="1" BorderBrush="Green" BorderThickness="2" CornerRadius="5" Margin="0,0,0,10">
<DataGrid x:Name="datagrid" Grid.Row="0" ItemsSource="{Binding TablesDataGrid}" Background="Transparent"
FontSize="15" ColumnHeaderHeight="35"
RowHeight="31" AutoGenerateColumns="False" RowHeaderWidth="0"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="0" CanUserAddRows="False" HorizontalAlignment="Center"
Foreground="#FFFFFF" >
<!--resourceStyle 399行修改选中字体颜色-->
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Header="表名" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Description}" Header="说明" Width="3*" IsReadOnly="True"/>
<DataGridTemplateColumn Header="操作" Width="2*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Content="生成代码" CommandParameter="{Binding Name}" Background="#009999" Foreground="White" Margin="10,0,0,0" Height="25" BorderBrush="#009999" BorderThickness="0" Width="100" Command="{Binding DataContext.CreateCodeCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid }}"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Border>
</Grid>
</UserControl>

@ -0,0 +1,30 @@
using SlnMesnac.WPF.ViewModel.Generate;
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 SlnMesnac.WPF.Page.Generate
{
/// <summary>
/// GenerateControl.xaml 的交互逻辑
/// </summary>
public partial class GenerateControl : UserControl
{
public GenerateControl()
{
InitializeComponent();
this.DataContext = new GenerateControlViewModel();
}
}
}

@ -22,6 +22,7 @@
<ProjectReference Include="..\SlnMesnac.Business\SlnMesnac.Business.csproj" /> <ProjectReference Include="..\SlnMesnac.Business\SlnMesnac.Business.csproj" />
<ProjectReference Include="..\SlnMesnac.Common\SlnMesnac.Common.csproj" /> <ProjectReference Include="..\SlnMesnac.Common\SlnMesnac.Common.csproj" />
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" /> <ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
<ProjectReference Include="..\SlnMesnac.Generate\SlnMesnac.Generate.csproj" />
<ProjectReference Include="..\SlnMesnac.Ioc\SlnMesnac.Ioc.csproj" /> <ProjectReference Include="..\SlnMesnac.Ioc\SlnMesnac.Ioc.csproj" />
<ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" /> <ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" />
<ProjectReference Include="..\SlnMesnac.Mqtt\SlnMesnac.Mqtt.csproj" /> <ProjectReference Include="..\SlnMesnac.Mqtt\SlnMesnac.Mqtt.csproj" />
@ -33,15 +34,12 @@
<ProjectReference Include="..\SlnMesnac.TouchSocket\SlnMesnac.TouchSocket.csproj" /> <ProjectReference Include="..\SlnMesnac.TouchSocket\SlnMesnac.TouchSocket.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Page\" />
<Folder Include="Converter\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" /> <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Lierda.WPFHelper" Version="1.0.3" /> <PackageReference Include="Lierda.WPFHelper" Version="1.0.3" />
<PackageReference Include="MvvmLightLibs" Version="5.4.1.1" /> <PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
<PackageReference Include="NVelocity" Version="1.2.0" />
<PackageReference Include="WindowsAPICodePack-Shell" Version="1.1.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -0,0 +1,163 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HslCommunication.LogNet;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.WindowsAPICodePack.Dialogs;
using SlnMesnac.Config;
using SlnMesnac.Generate;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Windows;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.WPF.ViewModel.Generate
* 7f1ddac5-3ff3-4974-ac90-d6eb684167c8
*
* WenJY
* wenjy@mesnac.com
* 2024-04-11 09:31:46
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.ViewModel.Generate
{
internal class GenerateControlViewModel : ViewModelBase
{
private readonly AppConfig _appConfig;
private readonly GenerateCode _generateCode;
public GenerateControlViewModel()
{
_appConfig = App.ServiceProvider.GetService<AppConfig>();
_generateCode = App.ServiceProvider.GetService<GenerateCode>();
var configIds = _appConfig.sqlConfig.Select(x=>x.configId).ToList();
// 初始化选项列表
Options = new ObservableCollection<string>();
foreach(var configId in configIds)
{
Options.Add(configId);
}
QuerySearchCommand = new RelayCommand<string>(Query);
CreateCodeCommand = new RelayCommand<string>(CreateCode);
}
#region 参数定义
private ObservableCollection<string> _options;
public ObservableCollection<string> Options
{
get { return _options; }
set
{
_options = value;
RaisePropertyChanged(nameof(Options));
}
}
private string _selectedOption;
public string SelectedOption
{
get { return _selectedOption; }
set
{
_selectedOption = value;
RaisePropertyChanged(nameof(SelectedOption));
}
}
private ObservableCollection<DbTableInfo> tablesDataGrid;
public ObservableCollection<DbTableInfo> TablesDataGrid
{
get { return tablesDataGrid; }
set { tablesDataGrid = value; RaisePropertyChanged(() => TablesDataGrid); }
}
#endregion
#region 事件定义
public RelayCommand<string> QuerySearchCommand { get; set; }
public RelayCommand<string> CreateCodeCommand { get;set; }
#endregion
/// <summary>
/// 查询事件
/// </summary>
/// <param name="search"></param>
private void Query(string search)
{
var configId = _selectedOption;
if (!string.IsNullOrEmpty(configId))
{
var db = App.ServiceProvider.GetService<ISqlSugarClient>();
var scope = db.AsTenant().GetConnectionScope(configId);
List<DbTableInfo> tables = scope.DbMaintenance.GetTableInfoList(false);
if(tables != null)
{
TablesDataGrid = new ObservableCollection<DbTableInfo>();
tables.ForEach(t => { TablesDataGrid.Add(t); });
}
}
}
private void CreateCode(string tableName)
{
var info = tableName;
var configId = _selectedOption;
string nameSpace = "SlnMesnac.Repository";
try
{
using (CommonOpenFileDialog dialog = new CommonOpenFileDialog())
{
dialog.IsFolderPicker = true; // 设置为选择文件夹
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
string selectedPath = dialog.FileName;
var res = _generateCode.CreateCode(configId, tableName, selectedPath, nameSpace);
if (res)
{
MessageBox.Show($"{tableName}代码生成成功");
}
}
}
}catch(Exception ex)
{
MessageBox.Show($"{tableName}代码生成失败:{ex.Message}");
}
}
}
}

@ -1,26 +1,20 @@
using GalaSoft.MvvmLight; using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Command;
using HslCommunication.Enthernet;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Logging; using SlnMesnac.WPF.Page.Generate;
using SlnMesnac.Mqtt;
using SlnMesnac.TouchSocket;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using SlnMesnac.Rfid;
namespace SlnMesnac.WPF.ViewModel namespace SlnMesnac.WPF.ViewModel
{ {
public class MainWindowViewModel: ViewModelBase public class MainWindowViewModel: ViewModelBase
{ {
private readonly ILogger<MainWindowViewModel> _logger; private readonly ILogger<MainWindowViewModel> _logger;
//代码生成
private readonly GenerateControl generateControl = new GenerateControl();
#region 参数定义 #region 参数定义
/// <summary> /// <summary>
/// PLC设备状态 /// PLC设备状态
@ -108,7 +102,9 @@ namespace SlnMesnac.WPF.ViewModel
//Environment.Exit(0); //Environment.Exit(0);
Application.Current.Shutdown(); Application.Current.Shutdown();
break; break;
case "Generate":
UserContent = generateControl;
break;
// 还原 或者 最大化当前窗口 // 还原 或者 最大化当前窗口
case "Normal": case "Normal":
if (Application.Current.MainWindow.WindowState == WindowState.Normal) if (Application.Current.MainWindow.WindowState == WindowState.Normal)

@ -36,7 +36,7 @@
"plcIp": "127.0.0.1", "plcIp": "127.0.0.1",
"plcPort": 6000, "plcPort": 6000,
"plcKey": "cwss", "plcKey": "cwss",
"isFlage": true "isFlage": false
} }
], ],
"RfidConfig": [ "RfidConfig": [
@ -52,7 +52,7 @@
"equipIp": "127.0.0.1", "equipIp": "127.0.0.1",
"equipPort": 6009, "equipPort": 6009,
"equipKey": "test2", "equipKey": "test2",
"isFlage": true "isFlage": false
} }
] ]
} }

@ -29,7 +29,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Mqtt", "SlnMesnac
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Rfid", "SlnMesnac.Rfid\SlnMesnac.Rfid.csproj", "{40D23A4B-8372-4145-936C-08AE63C6D1F9}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Rfid", "SlnMesnac.Rfid\SlnMesnac.Rfid.csproj", "{40D23A4B-8372-4145-936C-08AE63C6D1F9}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Ioc", "SlnMesnac.Ioc\SlnMesnac.Ioc.csproj", "{30A3F86B-774E-4153-9A00-FD3173C710EB}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Ioc", "SlnMesnac.Ioc\SlnMesnac.Ioc.csproj", "{30A3F86B-774E-4153-9A00-FD3173C710EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Generate", "SlnMesnac.Generate\SlnMesnac.Generate.csproj", "{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -93,6 +95,10 @@ Global
{30A3F86B-774E-4153-9A00-FD3173C710EB}.Debug|Any CPU.Build.0 = Debug|Any CPU {30A3F86B-774E-4153-9A00-FD3173C710EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30A3F86B-774E-4153-9A00-FD3173C710EB}.Release|Any CPU.ActiveCfg = Release|Any CPU {30A3F86B-774E-4153-9A00-FD3173C710EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30A3F86B-774E-4153-9A00-FD3173C710EB}.Release|Any CPU.Build.0 = Release|Any CPU {30A3F86B-774E-4153-9A00-FD3173C710EB}.Release|Any CPU.Build.0 = Release|Any CPU
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save