From 44d277ec414a9223619730646f99ec16df78a451 Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周三, 07 5月 2025 17:59:33 +0800 Subject: [PATCH] 支持 导出模板 --- Weben_CMS专用代码生成器/Code/Const/TemplateConst.cs | 13 + Weben_CMS专用代码生成器/Code/MainForm.cs | 6 Weben_CMS专用代码生成器/Code/File/ExcelTemplateFile/CommonTemplate.xlsx | 0 Weben_CMS专用代码生成器/Code/Utility/ImportTemplteHelper.cs | 204 +++++++++++++++++++++++++++++ Weben_CMS专用代码生成器/Code/packages.config | 28 ++++ Weben_CMS专用代码生成器/Code/App.config | 24 +++ Weben_CMS专用代码生成器/Code/GenerateCode_WeiBen_CMS.csproj | 110 +++++++++++++++ 7 files changed, 384 insertions(+), 1 deletions(-) diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/App.config" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/App.config" index 25af00c..3654ec7 100644 --- "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/App.config" +++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/App.config" @@ -22,6 +22,30 @@ <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Security.Cryptography.Pkcs" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /> + </dependentAssembly> </assemblyBinding> </runtime> </configuration> diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Const/TemplateConst.cs" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Const/TemplateConst.cs" new file mode 100644 index 0000000..d7f103a --- /dev/null +++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Const/TemplateConst.cs" @@ -0,0 +1,13 @@ +锘縰sing System; + +namespace GenerateCode_WeiBen_WMS.Const +{ + public class TemplateConst + { + /// <summary> + /// 鐢熸垚瀵煎叆妯℃澘鐨凟xcel鏂囦欢璺緞(鍏叡) + /// </summary> + public static string EXCEL_TEMPLATEFILE_瀵煎叆妯$増璺緞 = AppDomain.CurrentDomain.BaseDirectory + @"\File\ExcelTemplateFile"; + public static string EXCEL_TEMPLATEFILE_瀵煎叆妯$増鍚嶇О鍚庣紑 = "瀵煎嚭妯℃澘"; + } +} diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/File/ExcelTemplateFile/CommonTemplate.xlsx" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/File/ExcelTemplateFile/CommonTemplate.xlsx" new file mode 100644 index 0000000..b814a7d --- /dev/null +++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/File/ExcelTemplateFile/CommonTemplate.xlsx" Binary files differ diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/GenerateCode_WeiBen_CMS.csproj" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/GenerateCode_WeiBen_CMS.csproj" index 5447997..1a67be7 100644 --- "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/GenerateCode_WeiBen_CMS.csproj" +++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/GenerateCode_WeiBen_CMS.csproj" @@ -28,6 +28,8 @@ <UseApplicationTrust>false</UseApplicationTrust> <BootstrapperEnabled>true</BootstrapperEnabled> <TargetFrameworkProfile /> + <NuGetPackageImportStamp> + </NuGetPackageImportStamp> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PlatformTarget>x86</PlatformTarget> @@ -54,14 +56,47 @@ <ApplicationIcon>Robot.ico</ApplicationIcon> </PropertyGroup> <ItemGroup> + <Reference Include="EPPlus.Interfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=a694d7f3b0907a61, processorArchitecture=MSIL"> + <HintPath>packages\EPPlus.Interfaces.8.0.0\lib\net462\EPPlus.Interfaces.dll</HintPath> + </Reference> + <Reference Include="Magicodes.IE.EPPlus, Version=2.7.5.2, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>packages\Magicodes.IE.EPPlus.2.7.5.2\lib\netstandard2.0\Magicodes.IE.EPPlus.dll</HintPath> + </Reference> <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <HintPath>packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath> + </Reference> + <Reference Include="Microsoft.Extensions.Configuration, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>packages\Microsoft.Extensions.Configuration.3.1.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll</HintPath> + </Reference> + <Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>packages\Microsoft.Extensions.Configuration.Abstractions.3.1.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath> + </Reference> + <Reference Include="Microsoft.Extensions.Configuration.FileExtensions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>packages\Microsoft.Extensions.Configuration.FileExtensions.3.1.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.FileExtensions.dll</HintPath> + </Reference> + <Reference Include="Microsoft.Extensions.Configuration.Json, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>packages\Microsoft.Extensions.Configuration.Json.3.1.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Json.dll</HintPath> </Reference> <Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.2, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> <HintPath>packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.2\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath> </Reference> + <Reference Include="Microsoft.Extensions.FileProviders.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>packages\Microsoft.Extensions.FileProviders.Abstractions.3.1.0\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Abstractions.dll</HintPath> + </Reference> + <Reference Include="Microsoft.Extensions.FileProviders.Physical, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>packages\Microsoft.Extensions.FileProviders.Physical.3.1.0\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Physical.dll</HintPath> + </Reference> + <Reference Include="Microsoft.Extensions.FileSystemGlobbing, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>packages\Microsoft.Extensions.FileSystemGlobbing.3.1.0\lib\netstandard2.0\Microsoft.Extensions.FileSystemGlobbing.dll</HintPath> + </Reference> <Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.2, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> <HintPath>packages\Microsoft.Extensions.Logging.Abstractions.8.0.2\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll</HintPath> + </Reference> + <Reference Include="Microsoft.Extensions.Primitives, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>packages\Microsoft.Extensions.Primitives.3.1.0\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll</HintPath> + </Reference> + <Reference Include="Microsoft.IO.RecyclableMemoryStream, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>packages\Microsoft.IO.RecyclableMemoryStream.3.0.1\lib\netstandard2.0\Microsoft.IO.RecyclableMemoryStream.dll</HintPath> </Reference> <Reference Include="MySqlConnector, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92, processorArchitecture=MSIL"> <HintPath>packages\MySqlConnector.2.4.0\lib\net48\MySqlConnector.dll</HintPath> @@ -69,14 +104,31 @@ <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <HintPath>packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> </Reference> + <Reference Include="PresentationCore" /> + <Reference Include="SixLabors.ImageSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d998eea7b14cab13, processorArchitecture=MSIL"> + <HintPath>packages\SixLabors.ImageSharp.1.0.4\lib\net472\SixLabors.ImageSharp.dll</HintPath> + </Reference> + <Reference Include="SkiaSharp, Version=2.88.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL"> + <HintPath>packages\SkiaSharp.2.88.6\lib\net462\SkiaSharp.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath> </Reference> + <Reference Include="System.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath> + </Reference> + <Reference Include="System.ComponentModel.Composition" /> + <Reference Include="System.ComponentModel.DataAnnotations" /> <Reference Include="System.configuration" /> <Reference Include="System.Core" /> <Reference Include="System.Diagnostics.DiagnosticSource, Version=8.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <HintPath>packages\System.Diagnostics.DiagnosticSource.8.0.1\lib\net462\System.Diagnostics.DiagnosticSource.dll</HintPath> + </Reference> + <Reference Include="System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath> + <Private>True</Private> + <Private>True</Private> </Reference> <Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <HintPath>packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath> @@ -85,13 +137,57 @@ <Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath> </Reference> + <Reference Include="System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath> + <Private>True</Private> + <Private>True</Private> + </Reference> <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath> + </Reference> + <Reference Include="System.Security" /> + <Reference Include="System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll</HintPath> + <Private>True</Private> + <Private>True</Private> + </Reference> + <Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath> + <Private>True</Private> + <Private>True</Private> + </Reference> + <Reference Include="System.Security.Cryptography.Pkcs, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>packages\System.Security.Cryptography.Pkcs.4.7.0\lib\net461\System.Security.Cryptography.Pkcs.dll</HintPath> + </Reference> + <Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath> + <Private>True</Private> + <Private>True</Private> + </Reference> + <Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath> + <Private>True</Private> + <Private>True</Private> + </Reference> + <Reference Include="System.Security.Cryptography.Xml, Version=8.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> + <HintPath>packages\System.Security.Cryptography.Xml.8.0.2\lib\net462\System.Security.Cryptography.Xml.dll</HintPath> + </Reference> + <Reference Include="System.Text.Encoding.CodePages, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>packages\System.Text.Encoding.CodePages.4.7.0\lib\net461\System.Text.Encoding.CodePages.dll</HintPath> + </Reference> + <Reference Include="System.Text.Encodings.Web, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> + <HintPath>packages\System.Text.Encodings.Web.4.7.0\lib\netstandard2.0\System.Text.Encodings.Web.dll</HintPath> + </Reference> + <Reference Include="System.Text.Json, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> + <HintPath>packages\System.Text.Json.4.7.0\lib\net461\System.Text.Json.dll</HintPath> </Reference> <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <HintPath>packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath> </Reference> <Reference Include="System.Transactions" /> + <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> + <HintPath>packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath> + </Reference> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data" /> @@ -102,6 +198,7 @@ </ItemGroup> <ItemGroup> <Compile Include="Const\SystemConst.cs" /> + <Compile Include="Const\TemplateConst.cs" /> <Compile Include="DataBaseFactory\DataBaseServiceHandle.cs" /> <Compile Include="DataBaseFactory\DataBaseServiceFactory.cs" /> <Compile Include="DataBaseFactory\Default\SqlServerDataBaseServiceHandle.cs" /> @@ -163,6 +260,7 @@ <Compile Include="Generate\Model_Generate.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Utility\ImportTemplteHelper.cs" /> <Compile Include="Utility\ListHelper.cs" /> <Compile Include="Utility\MySqlHelper.cs" /> <Compile Include="Utility\SQLHelper.cs" /> @@ -188,6 +286,9 @@ <DependentUpon>MainForm.cs</DependentUpon> </EmbeddedResource> <None Include="App.config" /> + <None Include="File\ExcelTemplateFile\CommonTemplate.xlsx"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> <None Include="packages.config" /> <None Include="Properties\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> @@ -378,6 +479,15 @@ </ItemGroup> <ItemGroup /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="packages\SkiaSharp.NativeAssets.macOS.2.88.6\build\net462\SkiaSharp.NativeAssets.macOS.targets" Condition="Exists('packages\SkiaSharp.NativeAssets.macOS.2.88.6\build\net462\SkiaSharp.NativeAssets.macOS.targets')" /> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> + <PropertyGroup> + <ErrorText>杩欏彴璁$畻鏈轰笂缂哄皯姝ら」鐩紩鐢ㄧ殑 NuGet 绋嬪簭鍖呫�備娇鐢ㄢ�淣uGet 绋嬪簭鍖呰繕鍘熲�濆彲涓嬭浇杩欎簺绋嬪簭鍖呫�傛湁鍏虫洿澶氫俊鎭紝璇峰弬瑙� http://go.microsoft.com/fwlink/?LinkID=322105銆傜己灏戠殑鏂囦欢鏄� {0}銆�</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('packages\SkiaSharp.NativeAssets.macOS.2.88.6\build\net462\SkiaSharp.NativeAssets.macOS.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\SkiaSharp.NativeAssets.macOS.2.88.6\build\net462\SkiaSharp.NativeAssets.macOS.targets'))" /> + <Error Condition="!Exists('packages\SkiaSharp.NativeAssets.Win32.2.88.6\build\net462\SkiaSharp.NativeAssets.Win32.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\SkiaSharp.NativeAssets.Win32.2.88.6\build\net462\SkiaSharp.NativeAssets.Win32.targets'))" /> + </Target> + <Import Project="packages\SkiaSharp.NativeAssets.Win32.2.88.6\build\net462\SkiaSharp.NativeAssets.Win32.targets" Condition="Exists('packages\SkiaSharp.NativeAssets.Win32.2.88.6\build\net462\SkiaSharp.NativeAssets.Win32.targets')" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.cs" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.cs" index e0fe64c..aa960f0 100644 --- "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.cs" +++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/MainForm.cs" @@ -8,6 +8,7 @@ using GenerateCode_WeiBen_WMS.DataBaseFactory; using GenerateCode_WeiBen_WMS.Const; using GenerateCode_WeiBen_WMS.Model; +using GenerateCode_WeiBen_WMS.Utility; namespace GenerateCode_GEBrilliantFactory { @@ -270,7 +271,7 @@ //鐢熸垚Model //CreateModelFile(columnList, tableName, filePrefixName, wcf_NameSpacePath, createPerson, chinaComment, entityName, modulelogo); //CreateModelParamFile(columnList, tableName, filePrefixName, wcf_NameSpacePath, createPerson, chinaComment, entityName, modulelogo); - genCodeRootPath = tbPath.Text + @"\" + tb_WCF_NameSpacePath.Text.Trim(); + genCodeRootPath = tbPath.Text + @"\" + tb_WCF_NameSpacePath.Text.Trim(); var webFolerPath = (tb_WCF_NameSpacePath.Text.Trim() + "_Web").ToLower(); #region 瀹炰綋绫� var entityFilePath = genCodeRootPath + @"\server\src\CMS.Plugin." + tb_WCF_NameSpacePath.Text.Trim() + @".Application.Contracts\Dtos\" + tb_EntityName.Text.Trim(); @@ -461,6 +462,9 @@ str_generate = AutoMapperProfile_Generate.CreateText(param); tf = TextHelper.Export2File_V2(autoMapFilePath, param.EntityName + $"AutoMapperProfile.cs", tableName, str_generate, FileType.InputModel, filePrefixName, entityName, modulelogo); + //37銆佺敓鎴� 瀵煎嚭妯℃澘Excel鏂囦欢 + List<ColumnModel> newColumnNameList = ListHelper.RemoveForPageTableListQueryAttributes(param.ColumnNameList); + ImportTemplteHelper.CreateImportTemplte(param, newColumnNameList, genCodeRootPath); ////鐢熸垚 OutputModel 鏂囦欢 diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Utility/ImportTemplteHelper.cs" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Utility/ImportTemplteHelper.cs" new file mode 100644 index 0000000..e44afdf --- /dev/null +++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Utility/ImportTemplteHelper.cs" @@ -0,0 +1,204 @@ +锘縰sing GenerateCode_GEBrilliantFactory; +using GenerateCode_WeiBen_WMS.Const; +using GenerateCode_WeiBen_WMS.Model; +using OfficeOpenXml; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GenerateCode_WeiBen_WMS.Utility +{ + + public class ImportTemplteHelper + { + + /// <summary> + /// 鏍规嵁琛ㄥ悕鍒涘缓瀵煎叆妯$増 + /// </summary> + /// <param name="input"></param> + public static void CreateImportTemplte(GenerateCodeParam input, List<ColumnModel> tableFieldList, string genCodeRootPath) + { + string errMsg = string.Empty; + //涓氬姟鍚� + string _busName = input.EntityName; + var copayPath = TemplateConst.EXCEL_TEMPLATEFILE_瀵煎叆妯$増璺緞 + "\\CommonTemplate.xlsx"; + + var fileFolderPath = genCodeRootPath + "\\server\\src\\CMS.Plugin." + input.NameSpacePath + "\\Resources\\Templates"; + if (!Directory.Exists(fileFolderPath)) + { + Directory.CreateDirectory(fileFolderPath); + } + string newPath = fileFolderPath + $"\\{_busName}{TemplateConst.EXCEL_TEMPLATEFILE_瀵煎叆妯$増鍚嶇О鍚庣紑}.xlsx"; + + CreatExcel(tableFieldList, copayPath, newPath); + } + + /// <summary> + /// 鏍规嵁瀹炰綋绫诲悕 鐢熸垚瀵煎叆excel妯$増 + /// </summary> + /// <param name="tableFieldList">浠g爜鐢熸垚閫夋嫨閰嶇疆琛ㄧ殑瀛楁</param> + /// <param name="copayPath"></param> + /// <param name="newPath"></param> + private static void CreatExcel(List<ColumnModel> tableFieldList, string copayPath, string newPath) + { + string errMsg = string.Empty; + try + { + #region 楠岃瘉鍘熷瀵煎叆妯℃澘鏂囦欢鏄惁瀛樺湪 + if (!File.Exists(copayPath)) + { + errMsg = $"鐢ㄦ潵澶嶅埗鐢熸垚妯$増鐨凟XCEL鏂囦欢涓嶅瓨鍦�"; + throw new Exception($"鐢熸垚瀵煎叆妯$増鏂囦欢寮傚父锛歿errMsg}"); + } + #endregion + + //鑾峰彇妯℃澘鏂囦欢 + FileInfo copyFile = new FileInfo(copayPath); + + // 妫�鏌ユ柊鐢熸垚鐨勫鍏ユā鐗堟枃浠舵槸鍚﹀瓨鍦紝瀛樺湪灏卞垹闄わ紝浠ラ伩鍏嶅彲鑳界殑寮傚父銆� + if (File.Exists(newPath)) + { + File.Delete(newPath); // 鍒犻櫎鏂囦欢 + } + //澶嶅埗鍘熷瀵煎叆妯$増锛屽垱寤烘柊鐨勫鍏ユā鐗堟枃浠� + copyFile.CopyTo(newPath, true); + FileInfo existingFile = new FileInfo(newPath); + using (ExcelPackage package = new ExcelPackage(existingFile)) + { + //鑾峰彇妯℃澘鍐呭 + ExcelWorksheet worksheet = package.Workbook.Worksheets[0];//鑾峰彇绗竴涓獁orksheet + //琛屽拰鍒楅兘鏄粠1寮�濮嬶紝鑰屼笉鏄粠0寮�濮嬶紒锛侊紒 + int _remarkRowIndex = 1;//worksheet 琛岀储寮曪紙璇存槑锛� 娉ㄦ剰锛氶粯璁ゆ槸绗竴琛屾槸瀵煎叆妯$増鐨勮鏄� + int _mergeRowCount = _remarkRowIndex;//鍚堝苟琛� 锛堝繀濉瓧娈垫暟閲忥級 榛樿鏄涓�琛屽悎骞� + int _titleRowIndex = 1;//worksheet 琛岀储寮曪紙鏍囬锛夋敞鎰忥細榛樿鏄涓�琛屾槸瀵煎叆妯$増鐨勬爣棰� + int _cellIndex = 1;//worksheet 鍒楃储寮� 娉ㄦ剰锛氶粯璁ゆ槸绗竴鍒楀紑濮嬭缃鍏ユā鐗堢殑鏍囬 + + //妯$増绗竴鍒椾綔涓烘ā鐗堜娇鐢紝鎵�鏈夋柊澧炵殑鍒楁牱寮忔姤閿欎竴鑷� + var templateCell = worksheet.Cells[_titleRowIndex, _cellIndex]; + + string _remark = string.Empty; //绗竴琛屾坊鍔犺鏄庯紝娉ㄦ剰鎹㈣銆� + + //鑾峰彇瑕佸鐞嗙殑浠g爜鐢熸垚閰嶇疆鐨勬槸澧炴敼鐨勬ā鐗堝瓧娈� + var showCodeGenConfigs = tableFieldList.Where(w => 1 == 1).ToList(); + showCodeGenConfigs = showCodeGenConfigs.Where(x => 1 == 1).ToList(); + + /* + int _mergeCellsCount = showCodeGenConfigs.Count();//鍚堝苟鍒楋紙妯$増璧嬪�肩殑鏍囬鍒楁暟锛� + //鑾峰彇蹇呭~瀛楁 + + //鍒涘缓妯$増璇存槑 + StringBuilder _remarkContentBuilder = GetParseTemplateHint(showCodeGenConfigs); + string _remarkContent = _remarkContentBuilder.ToString(); + + #region 鍚堝苟鍗曞厓鏍� + //鍚堝苟鍗曞厓鏍硷紝鍚堝苟琛屽拰鍒椼�傞粯璁ゆ槸鍚堝苟绗竴琛岀殑鎵�鏈夋爣棰樺垪 + var cellRange = worksheet.Cells[1, 1, _mergeRowCount, _mergeCellsCount]; + + cellRange.Value = _remarkContent;//鍚堝苟鍗曞厓鏍煎悗鐨勫唴瀹硅祴鍊� + var mergeCell = cellRange.Merge = true;//鍚堝苟 + int rowHeight = GetRowHeightBasedOnContent(showCodeGenConfigs.Count()); // 鏍规嵁鍐呭璁$畻琛岄珮锛堣繖閲岄渶瑕佷綘鑷繁瀹炵幇閫昏緫锛� + worksheet.Row(_remarkRowIndex).Height = rowHeight; // 璁剧疆琛岄珮锛屾敞鎰廍PPlus鐨勫崟浣嶄笉鍚岋紝闇�瑕佽浆鎹� + + #endregion + //*/ + + //寰幆鍒涘缓妯$増鏍囬鍒� + foreach (var item in showCodeGenConfigs) + { + var currentCell = worksheet.Cells[_titleRowIndex, _cellIndex]; + //缁欐柊妯$増鍒楁爣棰樿祴鍊� + currentCell.Value = item.Description; + //澶嶅埗鎷疯礉鐨別xcel妯$増鍒楋紝缁欐柊妯$増鍒楁牱寮忚祴鍊� + currentCell.StyleID = templateCell.StyleID; + // worksheet.Column(_cellIndex).AutoFit();//瀹藉害鑷�傚簲 + + //缁欑浜岃璧嬪�� + var currentCell2 = worksheet.Cells[2, _cellIndex]; + //缁欐柊妯$増鍒楁爣棰樿祴鍊� + currentCell2.Value = "{{閰嶇疆." + item.ColumnName + "}}"; + //澶嶅埗鎷疯礉鐨別xcel妯$増鍒楋紝缁欐柊妯$増鍒楁牱寮忚祴鍊� + currentCell2.StyleID = templateCell.StyleID; + // worksheet.Column(_cellIndex).AutoFit();//瀹藉害鑷�傚簲 + + _cellIndex++; + } + + + package.Save();//淇濆瓨 + } + } + catch (Exception ex) + { + throw new Exception($"鐢熸垚瀵煎叆妯$増鏂囦欢寮傚父锛岃鏌ョ湅绯荤粺鏃ュ織:" + ex.Message); + } + finally { } + } + + // 杩欓噷鏄竴涓亣璁剧殑鏂规硶锛岀敤浜庢牴鎹崟鍏冩牸鍐呭璁$畻琛岄珮銆備綘闇�瑕佹牴鎹疄闄呮儏鍐垫潵瀹炵幇杩欎釜閫昏緫銆� + private static int GetRowHeightBasedOnContent(int lineCount) + { + // 杩欓噷鍙槸涓�涓ず渚嬮�昏緫锛屼綘鍙兘闇�瑕佹洿澶嶆潅鐨勭畻娉曟潵鍐冲畾鍚堥�傜殑琛岄珮銆� + + return (lineCount + 3) * 20; // + } + + private static StringBuilder GetParseTemplateHint(List<ColumnModel> requiredTableFieldList) + { + StringBuilder _remarkContentBuilder = new StringBuilder(); + _remarkContentBuilder.AppendLine(""); + _remarkContentBuilder.AppendLine("1.鏀寔Excel2007鍙婁互涓婄増鏈枃浠躲��"); + _remarkContentBuilder.AppendLine("2.瀵煎叆鏁版嵁鏃朵笉鑳借秴杩�5000琛屻��"); + _remarkContentBuilder.AppendLine(""); + _remarkContentBuilder.AppendLine(""); + + Dictionary<string, string> typeNameDict = new Dictionary<string, string>() + { + { "string", "杈撳叆鏂囨湰銆�"}, + { "int", "杈撳叆鏁板瓧銆�"}, + { "long", "杈撳叆鏁板瓧銆�"}, + { "decimal", "杈撳叆灏忔暟銆�"}, + { "bool", "鏄�,鍚︺��"}, + + }; + Dictionary<string, string> effectTypeDict = new Dictionary<string, string>() + { + { "datepicker", "鏃ユ湡銆� 绀轰緥: 2023/3/1銆�"}, + { "datetimepicker", "鏃ユ湡鏃堕棿銆傜ず渚�: 2023/3/1 12:00:00銆�"}, + + }; + + requiredTableFieldList.ForEach(x => + { + string text = ""; + text += x.Description + "(" + (x.IsNullable ? "蹇呭~" : "闈炲繀濉�") + "): "; + var _dataType = x.DataType.Replace("?", "").ToLower(); + //if (effectTypeDict.ContainsKey(x.EffectType.ToLower())) + //{ + // text += effectTypeDict[x.EffectType.ToLower()]; + //} + //else if (x.EffectType.ToLower() == "enumselector") + //{//娉ㄦ剰锛氳繖涓垽鏂鏀惧湪鍒ゆ柇_dataType鍓嶉潰锛屼富瑕佹槸鑰冭檻鏋氫妇鍜宨nt绫诲瀷鐨勬贩娣� + // var queryValue = x.NetType.Split('.').Last(); + // var enumStr = _sysEnumService.GetEnumDataListStr(new EnumDataInput() { EnumName = queryValue }); + // text += enumStr + "銆�"; + //} + if (typeNameDict.ContainsKey(_dataType)) + { + text += typeNameDict[_dataType]; + } + else + { + text += ("娉ㄦ剰锛氱被鍨嬫湭鑳借瘑鍒嚭鏉ワ紝闇�瑕佽嚜宸辩淮鎶わ紒锛侊紒銆�"); + } + _remarkContentBuilder.AppendLine(text); + }); + + return _remarkContentBuilder; + + } + + } +} diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/packages.config" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/packages.config" index d58da6f..2f980aa 100644 --- "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/packages.config" +++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/packages.config" @@ -1,14 +1,42 @@ 锘�<?xml version="1.0" encoding="utf-8"?> <packages> + <package id="EPPlus.Interfaces" version="8.0.0" targetFramework="net48" /> + <package id="Magicodes.IE.EPPlus" version="2.7.5.2" targetFramework="net48" /> <package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net48" /> + <package id="Microsoft.Extensions.Configuration" version="3.1.0" targetFramework="net48" /> + <package id="Microsoft.Extensions.Configuration.Abstractions" version="3.1.0" targetFramework="net48" /> + <package id="Microsoft.Extensions.Configuration.FileExtensions" version="3.1.0" targetFramework="net48" /> + <package id="Microsoft.Extensions.Configuration.Json" version="3.1.0" targetFramework="net48" /> <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.2" targetFramework="net48" /> + <package id="Microsoft.Extensions.FileProviders.Abstractions" version="3.1.0" targetFramework="net48" /> + <package id="Microsoft.Extensions.FileProviders.Physical" version="3.1.0" targetFramework="net48" /> + <package id="Microsoft.Extensions.FileSystemGlobbing" version="3.1.0" targetFramework="net48" /> <package id="Microsoft.Extensions.Logging.Abstractions" version="8.0.2" targetFramework="net48" /> + <package id="Microsoft.Extensions.Primitives" version="3.1.0" targetFramework="net48" /> + <package id="Microsoft.IO.RecyclableMemoryStream" version="3.0.1" targetFramework="net48" /> <package id="MySqlConnector" version="2.4.0" targetFramework="net48" /> <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net451" /> + <package id="SixLabors.ImageSharp" version="1.0.4" targetFramework="net48" /> + <package id="SkiaSharp" version="2.88.6" targetFramework="net48" /> + <package id="SkiaSharp.NativeAssets.macOS" version="2.88.6" targetFramework="net48" /> + <package id="SkiaSharp.NativeAssets.Win32" version="2.88.6" targetFramework="net48" /> <package id="System.Buffers" version="4.5.1" targetFramework="net48" /> + <package id="System.ComponentModel.Annotations" version="5.0.0" targetFramework="net48" /> <package id="System.Diagnostics.DiagnosticSource" version="8.0.1" targetFramework="net48" /> + <package id="System.IO" version="4.3.0" targetFramework="net48" /> <package id="System.Memory" version="4.5.5" targetFramework="net48" /> <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" /> + <package id="System.Runtime" version="4.3.0" targetFramework="net48" /> <package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" /> + <package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net48" /> + <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net48" /> + <package id="System.Security.Cryptography.Pkcs" version="4.7.0" targetFramework="net48" /> + <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net48" /> + <package id="System.Security.Cryptography.X509Certificates" version="4.3.2" targetFramework="net48" /> + <package id="System.Security.Cryptography.Xml" version="8.0.2" targetFramework="net48" /> + <package id="System.Text.Encoding.CodePages" version="4.7.0" targetFramework="net48" /> + <package id="System.Text.Encodings.Web" version="4.7.0" targetFramework="net48" /> + <package id="System.Text.Json" version="4.7.0" targetFramework="net48" /> <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" /> + <package id="System.ValueTuple" version="4.5.0" targetFramework="net48" /> </packages> \ No newline at end of file -- Gitblit v1.9.3