From 7e384366ce353a1822b81977146b95fe224d963c Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Wed, 23 Aug 2023 14:40:44 +0800 Subject: [PATCH] =?UTF-8?q?troubleshooting=E9=A1=B5=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E5=AE=8C=E5=B7=A5=EF=BC=8C=E8=87=AA=E5=8A=A8=E6=A0=A1=E6=97=B6?= =?UTF-8?q?=E6=B2=A1=E7=A9=BA=E5=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OTP/App.config | 8 +++ OTP/Form1.Designer.cs | 29 +++++----- OTP/Form1.cs | 10 ++++ OTP/Form2.Designer.cs | 1 + OTP/Form4.Designer.cs | 118 +++++++++++++++++++++++++++++++++++++++++ OTP/Form4.cs | 89 +++++++++++++++++++++++++++++++ OTP/Form4.resx | 120 ++++++++++++++++++++++++++++++++++++++++++ OTP/OTP.csproj | 26 ++++++++- OTP/packages.config | 5 ++ 9 files changed, 393 insertions(+), 13 deletions(-) create mode 100644 OTP/Form4.Designer.cs create mode 100644 OTP/Form4.cs create mode 100644 OTP/Form4.resx diff --git a/OTP/App.config b/OTP/App.config index 90c1718..7279368 100644 --- a/OTP/App.config +++ b/OTP/App.config @@ -19,4 +19,12 @@ + + + + + + + + \ No newline at end of file diff --git a/OTP/Form1.Designer.cs b/OTP/Form1.Designer.cs index 14bb647..7bcef7b 100644 --- a/OTP/Form1.Designer.cs +++ b/OTP/Form1.Designer.cs @@ -41,10 +41,12 @@ // // listBox1 // + this.listBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.listBox1.FormattingEnabled = true; + this.listBox1.ItemHeight = 20; this.listBox1.Location = new System.Drawing.Point(42, 38); this.listBox1.Name = "listBox1"; - this.listBox1.Size = new System.Drawing.Size(473, 368); + this.listBox1.Size = new System.Drawing.Size(473, 364); this.listBox1.TabIndex = 0; this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); // @@ -63,9 +65,9 @@ // button1 // this.button1.Enabled = false; - this.button1.Location = new System.Drawing.Point(556, 294); + this.button1.Location = new System.Drawing.Point(549, 294); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(85, 23); + this.button1.Size = new System.Drawing.Size(92, 23); this.button1.TabIndex = 3; this.button1.Text = "Generate"; this.button1.UseVisualStyleBackColor = true; @@ -76,7 +78,7 @@ this.button2.Enabled = false; this.button2.Location = new System.Drawing.Point(647, 294); this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(85, 111); + this.button2.Size = new System.Drawing.Size(99, 111); this.button2.TabIndex = 3; this.button2.Text = "Copy"; this.button2.UseVisualStyleBackColor = true; @@ -130,9 +132,9 @@ // // button3 // - this.button3.Location = new System.Drawing.Point(556, 323); + this.button3.Location = new System.Drawing.Point(549, 323); this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(85, 23); + this.button3.Size = new System.Drawing.Size(92, 23); this.button3.TabIndex = 7; this.button3.Text = "Manage"; this.button3.UseVisualStyleBackColor = true; @@ -140,21 +142,23 @@ // // button4 // - this.button4.Location = new System.Drawing.Point(556, 352); + this.button4.Location = new System.Drawing.Point(549, 352); this.button4.Name = "button4"; - this.button4.Size = new System.Drawing.Size(85, 23); + this.button4.Size = new System.Drawing.Size(92, 23); this.button4.TabIndex = 8; this.button4.Text = "Refresh"; this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); // // button5 // - this.button5.Location = new System.Drawing.Point(556, 382); + this.button5.Location = new System.Drawing.Point(549, 382); this.button5.Name = "button5"; - this.button5.Size = new System.Drawing.Size(85, 23); + this.button5.Size = new System.Drawing.Size(92, 23); this.button5.TabIndex = 9; - this.button5.Text = "About"; + this.button5.Text = "Troubleshooting"; this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.button5_Click); // // Form1 // @@ -170,8 +174,9 @@ this.Controls.Add(this.label1); this.Controls.Add(this.listBox1); this.Controls.Add(this.circularProgressBar1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "Form1"; - this.Text = "Main Window"; + this.Text = "TOTP"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Load += new System.EventHandler(this.Form1_Load); this.VisibleChanged += new System.EventHandler(this.Form1_VisibleChanged); diff --git a/OTP/Form1.cs b/OTP/Form1.cs index 85c608c..962ab1c 100644 --- a/OTP/Form1.cs +++ b/OTP/Form1.cs @@ -225,5 +225,15 @@ namespace OTP } } + private void button4_Click(object sender, EventArgs e) + { + LoadTitlesToListBox(); + } + + private void button5_Click(object sender, EventArgs e) + { + Form4 form4 = new Form4(); + form4.Show(); + } } } diff --git a/OTP/Form2.Designer.cs b/OTP/Form2.Designer.cs index 615c1f1..e6e5f0e 100644 --- a/OTP/Form2.Designer.cs +++ b/OTP/Form2.Designer.cs @@ -116,6 +116,7 @@ this.Controls.Add(this.panel1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "Form2"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Data Manage"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form2_FormClosing); this.panel1.ResumeLayout(false); diff --git a/OTP/Form4.Designer.cs b/OTP/Form4.Designer.cs new file mode 100644 index 0000000..954cc7f --- /dev/null +++ b/OTP/Form4.Designer.cs @@ -0,0 +1,118 @@ +namespace OTP +{ + partial class Form4 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.Location = new System.Drawing.Point(12, 64); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(152, 55); + this.label2.TabIndex = 1; + this.label2.Text = "label2"; + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label3 + // + this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label3.Location = new System.Drawing.Point(12, 119); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(216, 55); + this.label3.TabIndex = 2; + this.label3.Text = "网络时间"; + this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label1 + // + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(360, 55); + this.label1.TabIndex = 3; + this.label1.Text = "计算机本地时间"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // label4 + // + this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label4.Location = new System.Drawing.Point(12, 174); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(152, 55); + this.label4.TabIndex = 4; + this.label4.Text = "label4"; + this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // Form4 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(705, 242); + this.Controls.Add(this.label2); + this.Controls.Add(this.label3); + this.Controls.Add(this.label1); + this.Controls.Add(this.label4); + this.Name = "Form4"; + this.Text = "Troubleshooting"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form4_FormClosing); + this.Load += new System.EventHandler(this.Form4_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label4; + } +} \ No newline at end of file diff --git a/OTP/Form4.cs b/OTP/Form4.cs new file mode 100644 index 0000000..308d0cf --- /dev/null +++ b/OTP/Form4.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using GuerrillaNtp; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; + +namespace OTP +{ + public partial class Form4 : Form + { + private NtpClient ntpClient; + private NtpClock clock; + private Timer timer; + + public Form4() + { + InitializeComponent(); + ntpClient = new NtpClient("time.pool.aliyun.com"); + + // Create and configure the timer + timer = new Timer(); + timer.Interval = 1000; // 1 second interval + timer.Tick += Timer_Tick; + } + + private async void Form4_Load(object sender, EventArgs e) + { + try + { + // Display local time + UpdateLocalTimeLabel(); + + // Query time from NTP server + clock = await ntpClient.QueryAsync(); + + // Display network time from NTP server + UpdateNetworkTimeLabel(); + + // Start the timer to update network time periodically + timer.Start(); + } + catch (Exception ex) + { + // Handle any exceptions that might occur during NTP query + label4.Text = "NTP Error: " + ex.Message; + } + } + + private void Timer_Tick(object sender, EventArgs e) + { + // Update the time label + UpdateLocalTimeLabel(); + UpdateNetworkTimeLabel(); + } + private void UpdateLocalTimeLabel() + { + DateTime localTime = DateTime.Now; + label2.Text = localTime.ToString(); + } + private void UpdateNetworkTimeLabel() + { + if (clock != null) + { + DateTimeOffset networkTime = clock.UtcNow; + + // Convert network time to user's local time zone + TimeZoneInfo localTimeZone = TimeZoneInfo.Local; + DateTimeOffset localTime = TimeZoneInfo.ConvertTime(networkTime, localTimeZone); + + label4.Text = localTime.ToString(); + } + } + + + // Form4 closing event + private void Form4_FormClosing(object sender, FormClosingEventArgs e) + { + // Stop the timer when the form is closing + timer.Stop(); + } + } +} + diff --git a/OTP/Form4.resx b/OTP/Form4.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/OTP/Form4.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/OTP/OTP.csproj b/OTP/OTP.csproj index dae8ba7..917115b 100644 --- a/OTP/OTP.csproj +++ b/OTP/OTP.csproj @@ -54,6 +54,9 @@ ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll + + ..\packages\GuerrillaNtp.3.1.0\lib\netstandard2.0\GuerrillaNtp.dll + ..\packages\Otp.NET.1.3.0\lib\net45\Otp.NET.dll @@ -70,6 +73,9 @@ ..\packages\SharpDX.DXGI.4.2.0\lib\net45\SharpDX.DXGI.dll + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + @@ -89,6 +95,16 @@ True True + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + @@ -127,6 +143,12 @@ Form3.cs + + Form + + + Form4.cs + @@ -138,6 +160,9 @@ Form3.cs + + Form4.cs + ResXFileCodeGenerator Resources.Designer.cs @@ -148,7 +173,6 @@ Resources.resx - SettingsSingleFileGenerator diff --git a/OTP/packages.config b/OTP/packages.config index 1bf25ae..5f23a0c 100644 --- a/OTP/packages.config +++ b/OTP/packages.config @@ -5,18 +5,23 @@ + + + + + \ No newline at end of file