From 094120a9f57b9a04be5f1b77a9490644a104962e Mon Sep 17 00:00:00 2001 From: ddlucky Date: Thu, 25 May 2023 11:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=A8=8B=E5=BA=8F=E6=9B=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestForm/TestForm/Form1.Designer.cs | 26 +++++++++++- ToolProject/TestForm/TestForm/Form1.cs | 42 +++++++++++++++++++ ToolProject/TestForm/TestForm/TestForm.csproj | 13 ++++++ ToolProject/TestForm/TestForm/packages.config | 2 + 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/ToolProject/TestForm/TestForm/Form1.Designer.cs b/ToolProject/TestForm/TestForm/Form1.Designer.cs index 0730a89e..2eae5bfe 100644 --- a/ToolProject/TestForm/TestForm/Form1.Designer.cs +++ b/ToolProject/TestForm/TestForm/Form1.Designer.cs @@ -35,6 +35,8 @@ this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); + this.button6 = new System.Windows.Forms.Button(); + this.textBox2 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // button1 @@ -103,11 +105,31 @@ this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // + // button6 + // + this.button6.Location = new System.Drawing.Point(249, 174); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(106, 23); + this.button6.TabIndex = 8; + this.button6.Text = "消息队列发送"; + this.button6.UseVisualStyleBackColor = true; + this.button6.Click += new System.EventHandler(this.button6_Click); + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(12, 176); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(231, 21); + this.textBox2.TabIndex = 9; + this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(294, 181); + this.ClientSize = new System.Drawing.Size(704, 585); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.button6); this.Controls.Add(this.button5); this.Controls.Add(this.button4); this.Controls.Add(this.button3); @@ -131,6 +153,8 @@ private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; private System.Windows.Forms.Button button5; + private System.Windows.Forms.Button button6; + private System.Windows.Forms.TextBox textBox2; } } diff --git a/ToolProject/TestForm/TestForm/Form1.cs b/ToolProject/TestForm/TestForm/Form1.cs index 4a4610fc..14bfb024 100644 --- a/ToolProject/TestForm/TestForm/Form1.cs +++ b/ToolProject/TestForm/TestForm/Form1.cs @@ -24,6 +24,9 @@ using System.Windows.Forms; using static System.Net.Mime.MediaTypeNames; using Rectangle = System.Drawing.Rectangle; //using D7MqClient; +using Topshelf; +using RabbitMQ.Client; +using RabbitMQ.Client.Events; namespace TestForm @@ -424,6 +427,45 @@ namespace TestForm //Console.ReadKey(); } + + private IConnection mqConn; + + private void button6_Click(object sender, EventArgs e) + { + textBox2.Text= SetLength(textBox2.Text, 20); + } + + public static string SetLength(string oldstr, int length) + { + var str = string.IsNullOrWhiteSpace(oldstr) ? "" : (len(oldstr) > length) ? SubString2(oldstr, 0, length) : oldstr; + return str; + } + public static int len(string str) + { + System.Text.ASCIIEncoding n = new System.Text.ASCIIEncoding(); + byte[] b = n.GetBytes(str); + int length = 0; // l 为字符串的实际长度 + for (int i = 0; i <= b.Length - 1; i++) + { + if (b[i] == 63) //判断是否为汉字或全脚符号 + { + length++; + } + length++; + } + return length; + } + + public static string SubString2(string str, int startIndex, int length) + { + byte[] b = System.Text.Encoding.Default.GetBytes(str); + return System.Text.Encoding.Default.GetString(b, startIndex, length); + } + + private void textBox2_TextChanged(object sender, EventArgs e) + { + + } } class Test diff --git a/ToolProject/TestForm/TestForm/TestForm.csproj b/ToolProject/TestForm/TestForm/TestForm.csproj index eed81320..217c5e39 100644 --- a/ToolProject/TestForm/TestForm/TestForm.csproj +++ b/ToolProject/TestForm/TestForm/TestForm.csproj @@ -87,11 +87,15 @@ ..\..\..\packages\Quartz.2.6.2\lib\net40\Quartz.dll + + ..\..\..\packages\RabbitMQ.Client.6.2.2\lib\net461\RabbitMQ.Client.dll + ..\..\..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll + ..\..\..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll @@ -103,6 +107,12 @@ ..\..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + + ..\..\..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + True + + @@ -112,6 +122,9 @@ + + ..\..\..\packages\Topshelf.4.3.0\lib\net452\Topshelf.dll + diff --git a/ToolProject/TestForm/TestForm/packages.config b/ToolProject/TestForm/TestForm/packages.config index a64c1b94..19335d12 100644 --- a/ToolProject/TestForm/TestForm/packages.config +++ b/ToolProject/TestForm/TestForm/packages.config @@ -19,4 +19,6 @@ + + \ No newline at end of file