From 156989fc7c161e063bc630025d78bc32b7ac4e5d Mon Sep 17 00:00:00 2001 From: chenzhihao <1798906853@qq.com> Date: Tue, 6 Jan 2026 14:08:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4=E5=9B=BE?= =?UTF-8?q?=E5=BA=93=E5=8A=9F=E8=83=BD=E5=92=8C=E5=A2=9E=E5=8A=A0=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=9B=BE=E5=BA=93=E6=A3=80=E6=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/CorelDRAW/v16/.suo | Bin 212992 -> 212992 bytes CorelDRAW.Designer.vb | 28 ++- CorelDRAW.resx | 15 ++ CorelDRAW.vb | 451 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 483 insertions(+), 11 deletions(-) diff --git a/.vs/CorelDRAW/v16/.suo b/.vs/CorelDRAW/v16/.suo index 2621873661938de836cc8184a1caf60dd1e16566..430bf6e6189d93db8cd0cd545d89e6e0e8a6041d 100644 GIT binary patch delta 1325 zcmajeTTEO<7{KwF*-MwpwiH%M0NYh-17aE^mR2b3?y?lbrBYfHQ$*=3&P3X}d8XbjW$1^L4s9>hybJbbRJ! z&N=COf=(XVaY|+bb*-x`VNTk`U;&!Y20zwg2SRumgD|J{&~AkbCiXenLY%-@ZtMlx zop>Bi!^Bn6R^S*8!;MxU>cmkxFJTzR@h&Ft3a0Q3wj+Vf*l7Qex6YZ$|Le&BDGwrq zW`xm#eP~4++F_FT2yFx%*pElii38}uK^#Iijzjkp%z0m>GlK+@_U#Sd6y!;h7n6N` z?c1%^mBY$o->UFbrfxRtuhawXeaxJ3+wq%I(pC+1C2FtI+wUy3BORB+Z`aGKo*EXk zFAHV*T(Nw^)I~{kgh`XHv$Usi25%w`Gj6VW`a_vAnvE9O!#|&s>5GL6 zpEXMdRj2)z%B;S)^6A*;XVV`Srse{2Mc-Ah$?loEDAQLx7j`L?`fh%M7WK9)?H9;x&^WFWd`DgqP zqfzGlB1mQU#X$-t#{4Kz_jCW>sAy)_W2~zZ)g~gbX2`z>?I(C-jf1+FKf=ZXJVK1u ziHQ#SNBPUX#Qz_1i+Re-lVlzwM93KLH^A~ya#pObe{hd3Ukcf3dBvqq?cSq$g%$9S z+Z$mS&L+6To2@U??llRP@96QS8r>G$?A^hyshJIjOp5h~O|5cUZp&?Q+?KztQUF3& z=Nnap{^HMKJ-@q3_FC7&vNgMRJA0asXWGU!_TDL{^~r|Bg-R(mj`9(Ly!{}rRZaX; yxl<#l^U3rrw}+w3r9J6~HuQWs{b}i@<+psLKl~KcDHphtcH delta 543 zcmXYr(MwZN9LMkPc<$iz2xJ3S&^IH1NXp(&-a|)`JMCgyqM?3N;mn*AKkGO zC8j7!FX(i;T}UBN0DEB3pEhXdyIZ7yt*NY(t*x^%m7~#>1ys+`A(!kN#9rnBI1QeJ z`_G{b_%Rs9^P{j0t^(OJ2VVh`sLjJ;K)!ho=C0b`{|Z4~+=O3%yRuMGi|VWlDJ`Y1 zBHRMY{Gn!#N074MCCGzu@D!xL9Uuo^f=y5Xae2l+YRSwEB>9tEZ{#Vw25*B;;2Ds$ z>+nvPcSFCf{ndL_(PV*Dzr^c(8Iec`g9W$KHcwysB_8C&2ovuwe{d+z56*Nlj-ESo zK;oMzW|;V4ir-B9j0W*GF<0~d#i&DDoT@fA8!Pmvw$XTJi8c$G$C`hfq$x)ZGJ((E zg8gua`=MpccMOXAIfD|1u6eXz&=(S?5prwP>XK+N@t;*0G0~1xEn)>Ku&+H+7edgs AJ^%m! diff --git a/CorelDRAW.Designer.vb b/CorelDRAW.Designer.vb index 9cbcbd6..24b5dec 100644 --- a/CorelDRAW.Designer.vb +++ b/CorelDRAW.Designer.vb @@ -35,6 +35,8 @@ Partial Class CorelDRAW Me.ToolStripButton3 = New System.Windows.Forms.ToolStripButton() Me.ToolStripButton1 = New System.Windows.Forms.ToolStripButton() Me.ToolStripButton2 = New System.Windows.Forms.ToolStripButton() + Me.ToolStripComboBox1 = New System.Windows.Forms.ToolStripComboBox() + Me.ToolStripButton5 = New System.Windows.Forms.ToolStripButton() CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SplitContainer1.Panel2.SuspendLayout() Me.SplitContainer1.SuspendLayout() @@ -52,7 +54,7 @@ Partial Class CorelDRAW ' Me.SplitContainer1.Panel2.Controls.Add(Me.RichTextBox1) Me.SplitContainer1.Panel2.Controls.Add(Me.ToolStrip1) - Me.SplitContainer1.Size = New System.Drawing.Size(863, 655) + Me.SplitContainer1.Size = New System.Drawing.Size(1263, 655) Me.SplitContainer1.SplitterDistance = 287 Me.SplitContainer1.TabIndex = 0 ' @@ -61,16 +63,16 @@ Partial Class CorelDRAW Me.RichTextBox1.Dock = System.Windows.Forms.DockStyle.Fill Me.RichTextBox1.Location = New System.Drawing.Point(0, 25) Me.RichTextBox1.Name = "RichTextBox1" - Me.RichTextBox1.Size = New System.Drawing.Size(863, 630) + Me.RichTextBox1.Size = New System.Drawing.Size(1263, 630) Me.RichTextBox1.TabIndex = 1 Me.RichTextBox1.Text = "" ' 'ToolStrip1 ' - Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripLabel1, Me.ToolStripTextBox2, Me.ToolStripLabel2, Me.ToolStripTextBox1, Me.ToolStripButton4, Me.ToolStripButton3, Me.ToolStripButton1, Me.ToolStripButton2}) + Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripLabel1, Me.ToolStripTextBox2, Me.ToolStripLabel2, Me.ToolStripTextBox1, Me.ToolStripButton4, Me.ToolStripButton3, Me.ToolStripButton1, Me.ToolStripButton2, Me.ToolStripComboBox1, Me.ToolStripButton5}) Me.ToolStrip1.Location = New System.Drawing.Point(0, 0) Me.ToolStrip1.Name = "ToolStrip1" - Me.ToolStrip1.Size = New System.Drawing.Size(863, 25) + Me.ToolStrip1.Size = New System.Drawing.Size(1263, 25) Me.ToolStrip1.TabIndex = 0 Me.ToolStrip1.Text = "ToolStrip1" ' @@ -134,11 +136,25 @@ Partial Class CorelDRAW Me.ToolStripButton2.Size = New System.Drawing.Size(60, 22) Me.ToolStripButton2.Text = "显示步骤" ' + 'ToolStripComboBox1 + ' + Me.ToolStripComboBox1.Name = "ToolStripComboBox1" + Me.ToolStripComboBox1.Size = New System.Drawing.Size(300, 25) + ' + 'ToolStripButton5 + ' + Me.ToolStripButton5.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text + Me.ToolStripButton5.Image = CType(resources.GetObject("ToolStripButton5.Image"), System.Drawing.Image) + Me.ToolStripButton5.ImageTransparentColor = System.Drawing.Color.Magenta + Me.ToolStripButton5.Name = "ToolStripButton5" + Me.ToolStripButton5.Size = New System.Drawing.Size(72, 22) + Me.ToolStripButton5.Text = "删除素材库" + ' 'CorelDRAW ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(863, 655) + Me.ClientSize = New System.Drawing.Size(1263, 655) Me.Controls.Add(Me.SplitContainer1) Me.Name = "CorelDRAW" Me.Text = "Form1" @@ -163,4 +179,6 @@ Partial Class CorelDRAW Friend WithEvents SplitContainer1 As SplitContainer Friend WithEvents ToolStripButton1 As ToolStripButton Friend WithEvents ToolStripButton2 As ToolStripButton + Friend WithEvents ToolStripComboBox1 As ToolStripComboBox + Friend WithEvents ToolStripButton5 As ToolStripButton End Class diff --git a/CorelDRAW.resx b/CorelDRAW.resx index ec17109..b06dfe8 100644 --- a/CorelDRAW.resx +++ b/CorelDRAW.resx @@ -182,6 +182,21 @@ mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== diff --git a/CorelDRAW.vb b/CorelDRAW.vb index 77168eb..e5269b4 100644 --- a/CorelDRAW.vb +++ b/CorelDRAW.vb @@ -11,15 +11,15 @@ Imports VGCore Public Class CorelDRAW Public M_Redisip As String = "127.0.0.1" - Public M_Redisport As Integer = 10079 '6379 ' 10079 - Public M_Redispassword As String = "blw@redis-ser@123" ' "" ' + Public M_Redisport As Integer = 6379 '10079 ' 10079 + Public M_Redispassword As String = "" ' "blw@redis-ser@123" ' "" ' 'redis消息队列 Public M_RedisQueue As Queue '事件处理线程 Public M_EventThread As Thread '素材库路径 - Private M_MaterialPath As String = "R:\Canvas\material\" '"D:\Canvas\material\" ' + Private M_MaterialPath As String = "D:\Canvas\material\" ' "R:\Canvas\material\" ' '成平文件路径 Private M_TplPath As String = "D:\CorelDRAW\" Public G_RedisSub, G_Redislish As RedisSubscriber @@ -157,8 +157,6 @@ Public Class CorelDRAW InpotMessage1("3、打开模板库并创建新文件等待构建图像") - - InpotMessage1("2、酒店标题生成") Dim hotelName As String = "" If node.project IsNot Nothing AndAlso node.project.Count > 0 Then @@ -388,6 +386,286 @@ Public Class CorelDRAW End Try End Sub + ''' + ''' 检测图库文件命名及内容是否符合规范 + ''' + ''' 图库文件路径 + ''' 错误信息输出 + ''' 是否符合规范 + Public Function CheckLibraryFile(ByVal filePath As String, ByRef errorMessage As String) As Boolean + Dim srcDoc As Document + Try + ' 获取文件名(不含路径和扩展名) + Dim fileName As String = Path.GetFileNameWithoutExtension(filePath) + + ' 分割文件名 + Dim fileParts() As String = fileName.Split("_") + + ' 检查文件名基本格式 + If fileParts.Length < 5 Then + errorMessage = "文件名格式错误:必须包含公司_系列_库名_版本_备注" + Return False + End If + + ' 检查库名 + Dim libName As String = fileParts(2) + If libName <> "图标图库" AndAlso libName <> "模型图库" Then + errorMessage = "库名错误:只能为'图标图库'或'模型图库'" + Return False + End If + + ' 打开文件获取图像名称 + srcDoc = APP.OpenDocument(filePath, False) + Dim imageNames As New List(Of Shape) + + ' 遍历所有页、图层和形状获取图像名称 + For Each nPage As Page In srcDoc.Pages + For Each Layer As Layer In nPage.Layers + For Each Shape As Shape In Layer.Shapes + If Not String.IsNullOrEmpty(Shape.Name) Then + imageNames.Add(Shape) + End If + Next + Next + Next + + + + ' 遍历检查每个图像名称 + For Each imageName As Shape In imageNames + If Not CheckImageName(imageName, libName, errorMessage) Then + Return False + End If + Next + ' 关闭文件 + srcDoc.Close() + errorMessage = "" + Return True + Catch ex As Exception + ' 关闭文件 + If srcDoc IsNot Nothing Then + srcDoc.Close() + End If + + errorMessage = "文件处理错误:" & ex.Message + Return False + End Try + End Function + + ''' + ''' 检查单个图像名称是否符合规范 + ''' + ''' 图像名称 + ''' 图库类型 + ''' 错误信息输出 + ''' 是否符合规范 + Private Function CheckImageName(imageName As Shape, ByVal libName As String, ByRef errorMessage As String) As Boolean + ' 分割图像名称 + Dim parts() As String = imageName.Name.Split("_") + + If parts.Length < 2 Then + errorMessage = $"图像名称'{imageName.Name}'格式错误:缺少必要部分" + Return False + End If + + Dim imageType As String = parts(0).ToLower() + + Select Case libName + Case "模型图库" + Return CheckModelLibraryImage(imageType, parts, imageName, errorMessage) + Case "图标图库" + Return CheckIconLibraryImage(imageType, parts, imageName.Name, errorMessage) + Case Else + errorMessage = $"未知图库类型:{libName}" + Return False + End Select + End Function + + ''' + ''' 检查模型图库图像名称 + ''' + Private Function CheckModelLibraryImage(ByVal imageType As String, ByVal parts() As String, imageName As Shape, ByRef errorMessage As String) As Boolean + Dim snode As String() + Select Case imageType + Case "mode" + ' Mode_连体数_方向_颜色_宽_高 + If parts.Length < 6 Then + errorMessage = $"Mode图像'{imageName.Name}'格式错误:必须为Mode_N连体_方向_颜色_宽_高" + Return False + End If + ' 检查连体数格式 + If Not parts(1).EndsWith("连体") Then + errorMessage = $"Mode图像'{imageName.Name}'连体数格式错误:必须包含'连体'" + Return False + End If + ' 检查宽高是否为数字 + If Not IsNumeric(parts(4)) OrElse Not IsNumeric(parts(5)) Then + errorMessage = $"Mode图像'{imageName.Name}'宽高格式错误:必须为数字" + Return False + End If + + For Each imageNamenode As Shape In imageName.Shapes + snode = imageNamenode.Name.Split("_") + Select Case snode(0).ToLower() + Case "effect" + ' Effect_效果名称_w_h + If snode.Length < 4 Then + errorMessage = $"Effect图像'{imageNamenode.Name}'格式错误:必须为Effect_效果名称_w_h" + Return False + End If + ' 检查宽高是否为数字 + If Not IsNumeric(snode(snode.Length - 2)) OrElse Not IsNumeric(snode(snode.Length - 1)) Then + errorMessage = $"Effect图像'{imageNamenode.Name}'宽高格式错误:必须为数字" + Return False + End If + Return True + + Case "logo" + ' Logo_图像类型_左右_宽_高 + If snode.Length < 5 Then + errorMessage = $"Logo图像'{imageNamenode.Name}'格式错误:必须为Logo_图像类型_左右(L/R)_宽_高" + Return False + End If + ' 检查左右标识 + If snode(2) <> "L" AndAlso snode(2) <> "R" Then + errorMessage = $"Logo图像'{imageNamenode.Name}'左右标识错误:只能为L或R" + Return False + End If + ' 检查宽高是否为数字 + If Not IsNumeric(snode(3)) OrElse Not IsNumeric(snode(4)) Then + errorMessage = $"Logo图像'{imageNamenode.Name}'宽高格式错误:必须为数字" + Return False + End If + Return True + + Case "iconb" + ' IconB_N连体_方向_颜色_宽_高 + If snode.Length < 6 Then + errorMessage = $"IconB图像'{imageNamenode.Name}'格式错误:必须为IconB_N连体_方向_颜色_宽_高" + Return False + End If + ' 检查连体数格式 + If Not snode(1).EndsWith("连体") Then + errorMessage = $"IconB图像'{imageNamenode.Name}'连体数格式错误:必须包含'连体'" + Return False + End If + ' 检查宽高是否为数字 + If Not IsNumeric(snode(4)) OrElse Not IsNumeric(snode(5)) Then + errorMessage = $"IconB图像'{imageNamenode.Name}'宽高格式错误:必须为数字" + Return False + End If + Return True + + Case "trench" + ' Trench_槽位编号_w_h + If snode.Length < 4 Then + errorMessage = $"Trench图像'{imageNamenode.Name}'格式错误:必须为Trench_槽位编号_w_h" + Return False + End If + ' 检查槽位编号是否为数字 + If Not IsNumeric(snode(1)) Then + errorMessage = $"Trench图像'{imageNamenode.Name}'槽位编号错误:必须为数字" + Return False + End If + ' 检查宽高是否为数字 + If Not IsNumeric(snode(2)) OrElse Not IsNumeric(snode(3)) Then + errorMessage = $"Trench图像'{imageNamenode.Name}'宽高格式错误:必须为数字" + Return False + End If + + End Select + + Next + Return True + + Case "mono" + ' Mono_图像名称_w_h + If parts.Length < 4 Then + errorMessage = $"Mono图像'{imageName.Name}'格式错误:必须为Mono_图像名称_w_h" + Return False + End If + ' 检查宽高是否为数字 + If Not IsNumeric(parts(parts.Length - 2)) OrElse Not IsNumeric(parts(parts.Length - 1)) Then + errorMessage = $"Mono图像'{imageName.Name}'宽高格式错误:必须为数字" + Return False + End If + + For Each imageNamenode In imageName.Shapes + snode = imageNamenode.Name.Split("_") + Select Case snode(0) + Case "location" + ' location_图像类型_按键序号_w_h 或 location_图像类型_按键序号_w_h_行号 + If snode.Length < 5 OrElse snode.Length > 6 Then + errorMessage = $"Location图像'{imageNamenode.Name}'格式错误:必须为location_图像类型_按键序号_w_h[_行号]" + Return False + End If + ' 检查按键序号是否为数字 + If Not IsNumeric(snode(2)) Then + errorMessage = $"Location图像'{imageNamenode.Name}'按键序号错误:必须为数字" + Return False + End If + ' 检查宽高是否为数字 + If Not IsNumeric(snode(3)) OrElse Not IsNumeric(snode(4)) Then + errorMessage = $"Location图像'{imageNamenode.Name}'宽高格式错误:必须为数字" + Return False + End If + ' 如果有行号,检查是否为数字 + If snode.Length = 6 AndAlso Not IsNumeric(snode(5)) Then + errorMessage = $"Location图像'{imageNamenode.Name}'行号错误:必须为数字" + Return False + End If + + End Select + Next + + Return True + + + + Case Else + Return True + errorMessage = $"模型图库中包含未知图像类型:{imageType}" + Return False + End Select + End Function + + ''' + ''' 检查图标图库图像名称 + ''' + Private Function CheckIconLibraryImage(ByVal imageType As String, ByVal parts() As String, ByVal imageName As String, ByRef errorMessage As String) As Boolean + Select Case imageType + Case "icon" + ' Icon_图像名称_图像英文名称_w_h + If parts.Length < 5 Then + errorMessage = $"Icon图像'{imageName}'格式错误:必须为Icon_图像名称_图像英文名称_w_h" + Return False + End If + ' 检查宽高是否为数字 + If Not IsNumeric(parts(parts.Length - 2)) OrElse Not IsNumeric(parts(parts.Length - 1)) Then + errorMessage = $"Icon图像'{imageName}'宽高格式错误:必须为数字" + Return False + End If + Return True + + Case "logo" + ' Logo_图像名称_w_h + If parts.Length > 5 OrElse parts.Length < 4 Then + errorMessage = $"Logo图像'{imageName}'格式错误:必须为Logo_图像名称_图像英文名称_w_h" + Return False + End If + ' 检查宽高是否为数字 + If Not IsNumeric(parts(parts.Length - 2)) OrElse Not IsNumeric(parts(parts.Length - 1)) Then + errorMessage = $"Logo图像'{imageName}'宽高格式错误:必须为数字" + Return False + End If + Return True + + Case Else + errorMessage = $"图标图库中包含未知图像类型:{imageType}" + Return False + End Select + End Function + Public Function HandleNodeInformation1(node As RedisInfoNode) As Boolean Dim oldTime As DateTime = Now @@ -2184,6 +2462,48 @@ Public Class CorelDRAW End If End Sub + ' 用于存储文件名和对应id的字典 + Private M_FileIdDict As New Dictionary(Of String, Integer) + + Private Sub ToolStripComboBox1_DropDown(sender As Object, e As EventArgs) Handles ToolStripComboBox1.DropDown + ' 清空下拉列表和字典 + ToolStripComboBox1.Items.Clear() + M_FileIdDict.Clear() + + Dim npgsqldb As DbExecutor = New DbExecutor(DbExecutor.DbTypeEnum.Mysql, LocalConnString) + Dim gLogNode As LogNode + + ' 从tbl_cdr_file表查询图库文件名和文件对应id + Dim transStr As String = "select id, filename from `cdr_library`.`tbl_cdr_file`;" + + Dim dt As DataTable + + Try + npgsqldb.Open() + dt = npgsqldb.ExecuteDataTable(transStr) + + ' 将查询结果填充到ToolStripComboBox1下拉框中 + For Each row As DataRow In dt.Rows + Dim id As Integer = row("id") + Dim filename As String = row("filename") + ' 将id和filename存储到字典中 + M_FileIdDict.Add(filename, id) + ' 下拉框中只显示文件名 + ToolStripComboBox1.Items.Add(filename) + Next + + npgsqldb.Close() + Catch ex As Exception + If Not IsNothing(npgsqldb) Then + npgsqldb.Close() + End If + + gLogNode = New LogNode($"查询图库文件失败!{vbCrLf}{ex.Message}", RuningLog.LogType.e_Error, RuningLog.LogMode.e_fileandRichTextBox) + gLogNode.SetLogColor(System.Drawing.Color.Red) + G_Log.AddLogNode(gLogNode) + End Try + End Sub + Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click RichTextBox1.Clear() Dim dic As New Dictionary(Of String, String) @@ -2218,7 +2538,7 @@ Public Class CorelDRAW Private Sub ToolStripButton1_Click_1(sender As Object, e As EventArgs) Handles ToolStripButton1.Click '打开文件选择器 选择cDR后缀的文件 - Dim ServerFilePath As String = "R:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic" ' "D:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic" ' + Dim ServerFilePath As String = "D:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic" ' "R:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic" ' Dim OpenFileDialog1 As New OpenFileDialog() OpenFileDialog1.Filter = "CorelDRAW Files (*.cdr)|*.cdr" Dim srcDoc As Document '素材文件 @@ -2232,8 +2552,17 @@ Public Class CorelDRAW Dim gLogNode As LogNode Dim ProjectPath As String Dim SafeFileName As String + Dim errorMessage As String If OpenFileDialog1.ShowDialog() = DialogResult.OK Then + ' 上传前检查文件是否符合规范 + If Not CheckLibraryFile(OpenFileDialog1.FileName, errorMessage) Then + gLogNode = New LogNode($"图库文件检测失败:{errorMessage}{vbCrLf}", RuningLog.LogType.e_Error, RuningLog.LogMode.e_fileandRichTextBox) + gLogNode.SetLogColor(System.Drawing.Color.Red) + G_Log.AddLogNode(gLogNode) + MessageBox.Show(errorMessage, "文件检测失败", MessageBoxButtons.OK, MessageBoxIcon.Error) + Return + End If Dim fid As Integer = AddFileToSQL(OpenFileDialog1.SafeFileName) If fid = -1 Then @@ -2976,4 +3305,114 @@ Public Class CorelDRAW End Try End Sub + + + Private Sub ToolStripButton5_Click(sender As Object, e As EventArgs) Handles ToolStripButton5.Click + '删除素材库 + Try + + + ' 3. 检查是否选择了素材库 + If String.IsNullOrEmpty(ToolStripComboBox1.Text) Then + MsgBox("请先选择要删除的素材库!", vbExclamation, "错误") + Return + End If + + ' 4. 获取选中的素材库名称 + Dim selectedFileName As String = ToolStripComboBox1.Text + ' 1. 显示密码输入对话框 + Dim password As String = InputBox("请输入密码", $"即将删除:{vbCrLf}{selectedFileName}", "", -1, -1) + + ' 2. 验证密码 + If password <> "123456" Then + MsgBox("密码错误,删除失败!", vbExclamation, "错误") + Return + End If + ' 5. 从字典中获取对应的ID + If M_FileIdDict.ContainsKey(selectedFileName) Then + Dim fileId As Integer = M_FileIdDict(selectedFileName) + + ' 6. 执行数据库删除操作 + Dim npgsqldb As DbExecutor = New DbExecutor(DbExecutor.DbTypeEnum.Mysql, LocalConnString) + Try + npgsqldb.Open() + + ' 7. 开始事务 + npgsqldb.BeginTransaction() + + ' 8. 根据素材库类型执行不同的删除逻辑 + If selectedFileName.Contains("图标图库") Then + ' 删除图标素材库相关数据 + ' 删除tbl_iconlibrary中FID一致的数据 + Dim deleteIconSql As String = $"DELETE FROM `cdr_library`.`tbl_iconlibrary` WHERE `FID` = {fileId};" + npgsqldb.ExecuteNonQuery(deleteIconSql) + ElseIf selectedFileName.Contains("模型图库") Then + ' 删除模型素材库相关数据 + + ' 1. 处理tbl_model相关数据 + ' 查询tbl_model中FID等于fileId的数据 + Dim modelSql As String = $"SELECT `Id` FROM `cdr_library`.`tbl_model` WHERE `FID` = {fileId};" + Dim modelDt As DataTable = npgsqldb.ExecuteDataTable(modelSql) + + ' 遍历tbl_model表得到的ID + For Each modelRow As DataRow In modelDt.Rows + Dim modelId As Integer = modelRow("Id") + + ' 删除tbl_trench中MID符合的数据 + Dim deleteTrenchSql As String = $"DELETE FROM `cdr_library`.`tbl_trench` WHERE `MID` = {modelId};" + npgsqldb.ExecuteNonQuery(deleteTrenchSql) + + ' 删除tbl_model中对应ID的数据 + Dim deleteModelSql As String = $"DELETE FROM `cdr_library`.`tbl_model` WHERE `ID` = {modelId};" + npgsqldb.ExecuteNonQuery(deleteModelSql) + Next + + ' 2. 处理tbl_pattern相关数据 + ' 查询tbl_pattern中FID等于fileId的数据 + Dim patternSql As String = $"SELECT `Id` FROM `cdr_library`.`tbl_pattern` WHERE `FID` = {fileId};" + Dim patternDt As DataTable = npgsqldb.ExecuteDataTable(patternSql) + + ' 遍历tbl_pattern表得到的ID + For Each patternRow As DataRow In patternDt.Rows + Dim patternId As Integer = patternRow("Id") + + ' 删除tbl_location中MID符合的数据 + Dim deleteLocationSql As String = $"DELETE FROM `cdr_library`.`tbl_location` WHERE `PID` = {patternId};" + npgsqldb.ExecuteNonQuery(deleteLocationSql) + + ' 删除tbl_pattern中对应ID的数据 + Dim deletePatternSql As String = $"DELETE FROM `cdr_library`.`tbl_pattern` WHERE `ID` = {patternId};" + npgsqldb.ExecuteNonQuery(deletePatternSql) + Next + End If + + ' 9. 删除tbl_cdr_file中对应id的数据 + Dim deleteFileSql As String = $"DELETE FROM `cdr_library`.`tbl_cdr_file` WHERE `ID` = {fileId};" + npgsqldb.ExecuteNonQuery(deleteFileSql) + + ' 10. 提交事务 + npgsqldb.CommitTransaction() + + ' 11. 从下拉框中移除已删除的选项 + ToolStripComboBox1.Items.Remove(selectedFileName) + + ' 12. 清空选择 + ToolStripComboBox1.Text = "" + + ' 13. 显示成功消息 + MsgBox("素材库删除成功!", vbInformation, "成功") + Catch ex As Exception + ' 14. 回滚事务 + npgsqldb.RollbackTransaction() + MsgBox($"删除失败:{ex.Message}", vbExclamation, "错误") + Finally + npgsqldb.Close() + End Try + Else + MsgBox("未找到素材库对应的ID!", vbExclamation, "错误") + End If + Catch ex As Exception + MsgBox($"操作失败:{ex.Message}", vbExclamation, "错误") + End Try + End Sub End Class