diff --git a/Test/Form1.Designer.cs b/Test/Form1.Designer.cs new file mode 100644 index 0000000..2bb4656 --- /dev/null +++ b/Test/Form1.Designer.cs @@ -0,0 +1,108 @@ +namespace Test +{ + partial class Form1 + { + /// + /// 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() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.uButton1 = new WinFormControl.UButton(); + this.uScanPanel1 = new WinFormControl.UScanPanel(); + this.uWeightControl1 = new WinFormControl.UWeightControl(); + this.SuspendLayout(); + // + // comboBox1 + // + this.comboBox1.Font = new System.Drawing.Font("宋体", 15F); + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(53, 239); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(121, 28); + this.comboBox1.TabIndex = 3; + // + // uButton1 + // + this.uButton1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("uButton1.BackgroundImage"))); + this.uButton1.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(155)))), ((int)(((byte)(214))))); + this.uButton1.FlatAppearance.BorderSize = 0; + this.uButton1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.uButton1.ForeColor = System.Drawing.Color.Black; + this.uButton1.Location = new System.Drawing.Point(254, 239); + this.uButton1.Name = "uButton1"; + this.uButton1.PlaySound = true; + this.uButton1.Size = new System.Drawing.Size(130, 47); + this.uButton1.SoundType = WinFormControl.SoundType.Di; + this.uButton1.TabIndex = 2; + this.uButton1.Text = "uButton1"; + this.uButton1.UseVisualStyleBackColor = true; + this.uButton1.Click += new System.EventHandler(this.uButton1_Click); + // + // uScanPanel1 + // + this.uScanPanel1.BackColor = System.Drawing.Color.Transparent; + this.uScanPanel1.Location = new System.Drawing.Point(101, 182); + this.uScanPanel1.Name = "uScanPanel1"; + this.uScanPanel1.Size = new System.Drawing.Size(303, 32); + this.uScanPanel1.TabIndex = 1; + this.uScanPanel1.BeforeScan += new System.Action(this.uScanPanel1_BeforeScan); + this.uScanPanel1.AfterScan += new System.Action(this.uScanPanel1_AfterScan); + // + // uWeightControl1 + // + this.uWeightControl1.BackColor = System.Drawing.Color.Transparent; + this.uWeightControl1.Location = new System.Drawing.Point(2, 12); + this.uWeightControl1.Name = "uWeightControl1"; + this.uWeightControl1.Size = new System.Drawing.Size(348, 78); + this.uWeightControl1.TabIndex = 0; + this.uWeightControl1.WeightFalg = "Test"; + this.uWeightControl1.ReceivedValue += new System.Action(this.uWeightControl1_ReceivedValue); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.White; + this.ClientSize = new System.Drawing.Size(604, 363); + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.uButton1); + this.Controls.Add(this.uScanPanel1); + this.Controls.Add(this.uWeightControl1); + this.KeyPreview = true; + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + + } + + #endregion + + private WinFormControl.UWeightControl uWeightControl1; + private WinFormControl.UScanPanel uScanPanel1; + private WinFormControl.UButton uButton1; + private System.Windows.Forms.ComboBox comboBox1; + } +} \ No newline at end of file diff --git a/Test/Form1.cs b/Test/Form1.cs new file mode 100644 index 0000000..9fd8ac9 --- /dev/null +++ b/Test/Form1.cs @@ -0,0 +1,44 @@ +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 WinFormControl; + +namespace Test +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + comboBox1.DataSource = Enum.GetNames(typeof(SoundType)); + } + + private void uWeightControl1_ReceivedValue(decimal obj) + { + MessageBox.Show(obj.ToString()); + } + + private void uScanPanel1_BeforeScan() + { + //throw new Exception("dddddd"); + } + + private void uScanPanel1_AfterScan() + { + MessageBox.Show(uScanPanel1.TextBox.Text); + } + + private void uButton1_Click(object sender, EventArgs e) + { + //SoundType sy; + //if (Enum.TryParse(comboBox1.SelectedValue.ToString(), out sy)) + // SoundPalyUtil.PlaySound(sy); + } + } +} diff --git a/Test/Form1.resx b/Test/Form1.resx new file mode 100644 index 0000000..681c9a5 --- /dev/null +++ b/Test/Form1.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + iVBORw0KGgoAAAANSUhEUgAAAGAAAAAwCAIAAABhdOiYAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAHNJREFUaEPt0AENACAMwDAkowVB14aDz0CTKui5b1gICoKCoCAoCAqCgqAgKAgK + goKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAg + KAgKgoKg1ZsPvpCB0hBohjQAAAAASUVORK5CYII= + + + \ No newline at end of file diff --git a/Test/Program.cs b/Test/Program.cs new file mode 100644 index 0000000..d312a51 --- /dev/null +++ b/Test/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Test +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Test/Properties/AssemblyInfo.cs b/Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..494943f --- /dev/null +++ b/Test/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Test")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("82822c1e-a8f4-41db-8045-0e447500b163")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Test/Properties/Resources.Designer.cs b/Test/Properties/Resources.Designer.cs new file mode 100644 index 0000000..5b30e42 --- /dev/null +++ b/Test/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace Test.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Test/Properties/Resources.resx b/Test/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Test/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Test/Properties/Settings.Designer.cs b/Test/Properties/Settings.Designer.cs new file mode 100644 index 0000000..e50003a --- /dev/null +++ b/Test/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Test.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Test/Properties/Settings.settings b/Test/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Test/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Test/Test.csproj b/Test/Test.csproj new file mode 100644 index 0000000..88f27b0 --- /dev/null +++ b/Test/Test.csproj @@ -0,0 +1,92 @@ + + + + + Debug + AnyCPU + {19454EB5-F255-4A8C-A925-9A43A0E92264} + WinExe + Properties + Test + Test + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {5f1ac749-68db-43e2-8895-886ecc04d7da} + WinFormControl + + + + + \ No newline at end of file diff --git a/WinFormControl.sln b/WinFormControl.sln index 8597204..57a6593 100644 --- a/WinFormControl.sln +++ b/WinFormControl.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 VisualStudioVersion = 12.0.40629.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormControl", "WinFormControl\WinFormControl.csproj", "{45A6C56B-C815-4AEA-B0C4-68C122FD3139}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{19454EB5-F255-4A8C-A925-9A43A0E92264}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormControl", "WinFormControl\WinFormControl.csproj", "{5F1AC749-68DB-43E2-8895-886ECC04D7DA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,10 +13,14 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {45A6C56B-C815-4AEA-B0C4-68C122FD3139}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {45A6C56B-C815-4AEA-B0C4-68C122FD3139}.Debug|Any CPU.Build.0 = Debug|Any CPU - {45A6C56B-C815-4AEA-B0C4-68C122FD3139}.Release|Any CPU.ActiveCfg = Release|Any CPU - {45A6C56B-C815-4AEA-B0C4-68C122FD3139}.Release|Any CPU.Build.0 = Release|Any CPU + {19454EB5-F255-4A8C-A925-9A43A0E92264}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {19454EB5-F255-4A8C-A925-9A43A0E92264}.Debug|Any CPU.Build.0 = Debug|Any CPU + {19454EB5-F255-4A8C-A925-9A43A0E92264}.Release|Any CPU.ActiveCfg = Release|Any CPU + {19454EB5-F255-4A8C-A925-9A43A0E92264}.Release|Any CPU.Build.0 = Release|Any CPU + {5F1AC749-68DB-43E2-8895-886ECC04D7DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F1AC749-68DB-43E2-8895-886ECC04D7DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F1AC749-68DB-43E2-8895-886ECC04D7DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F1AC749-68DB-43E2-8895-886ECC04D7DA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WinFormControl/NetStateWatch.Designer.cs b/WinFormControl/NetStateWatch.Designer.cs new file mode 100644 index 0000000..e6e3d06 --- /dev/null +++ b/WinFormControl/NetStateWatch.Designer.cs @@ -0,0 +1,79 @@ +namespace WinFormControl +{ + partial class NetStateWatch + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region 组件设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.uLabel1 = new WinFormControl.ULabel(); + this.picNetStatus = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.picNetStatus)).BeginInit(); + this.SuspendLayout(); + // + // uLabel1 + // + this.uLabel1.AutoSize = true; + this.uLabel1.BackColor = System.Drawing.Color.Transparent; + this.uLabel1.Font = new System.Drawing.Font("宋体", 15F); + this.uLabel1.ForeColor = System.Drawing.Color.Black; + this.uLabel1.Location = new System.Drawing.Point(3, 9); + this.uLabel1.Name = "uLabel1"; + this.uLabel1.Size = new System.Drawing.Size(49, 20); + this.uLabel1.TabIndex = 44; + this.uLabel1.Text = "网络"; + // + // picNetStatus + // + this.picNetStatus.ErrorImage = null; + this.picNetStatus.Image = global::WinFormControl.Properties.Resources.redCircle; + this.picNetStatus.InitialImage = null; + this.picNetStatus.Location = new System.Drawing.Point(52, 2); + this.picNetStatus.Name = "picNetStatus"; + this.picNetStatus.Size = new System.Drawing.Size(34, 34); + this.picNetStatus.TabIndex = 43; + this.picNetStatus.TabStop = false; + // + // NetStateWatch + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Transparent; + this.Controls.Add(this.uLabel1); + this.Controls.Add(this.picNetStatus); + this.Name = "NetStateWatch"; + this.Size = new System.Drawing.Size(90, 39); + ((System.ComponentModel.ISupportInitialize)(this.picNetStatus)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ULabel uLabel1; + private System.Windows.Forms.PictureBox picNetStatus; + } +} diff --git a/WinFormControl/NetStateWatch.cs b/WinFormControl/NetStateWatch.cs new file mode 100644 index 0000000..e9c622a --- /dev/null +++ b/WinFormControl/NetStateWatch.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Threading; + +namespace WinFormControl +{ + /// + /// Must Give Func GetConnectState A Value; + /// + public partial class NetStateWatch : UserControl + { + private Thread _tcCheckNetStatus; + public NetStateWatch() + { + InitializeComponent(); + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + if (GetConnectState == null) + return; + _tcCheckNetStatus = new Thread(CheckNetStatus); + _tcCheckNetStatus.Start(); + ParentForm.FormClosing += delegate + { + if (_tcCheckNetStatus != null && _tcCheckNetStatus.IsAlive) + { + _tcCheckNetStatus.Abort(); + } + }; + } + + [Browsable(true)] + public Func GetConnectState; + + [Browsable(false)] + public bool NetState { get; private set; } + + [Browsable(true), Description("连接状态改变事件")] + public event Action NetStateChanged; + + private bool laseConnection = false; + private void CheckNetStatus() + { + while (true) + { + try + { + NetState = GetConnectState(); + if (NetState && laseConnection) + { + Thread.Sleep(1000); + continue; + } + if (NetStateChanged != null) + NetStateChanged(NetState); + var img = Properties.Resources.redCircle; + if (NetState) + img = Properties.Resources.greenCircle; + this.Invoke(new Action(delegate() + { + picNetStatus.Image = img; + picNetStatus.Refresh(); + })); + laseConnection = NetState; + } + catch + { + + } + + Thread.Sleep(1000); + } + } + } +} diff --git a/WinFormControl/NetStateWatch.resx b/WinFormControl/NetStateWatch.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WinFormControl/NetStateWatch.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/WinFormControl/Properties/AssemblyInfo.cs b/WinFormControl/Properties/AssemblyInfo.cs index 828d9b8..e1face9 100644 --- a/WinFormControl/Properties/AssemblyInfo.cs +++ b/WinFormControl/Properties/AssemblyInfo.cs @@ -20,7 +20,7 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID -[assembly: Guid("747dea7e-a712-427e-ac75-fe1b69ec9b42")] +[assembly: Guid("7f771e26-f0d0-4d1d-885d-642fe81c06ae")] // 程序集的版本信息由下面四个值组成: // diff --git a/WinFormControl/Properties/Resources.Designer.cs b/WinFormControl/Properties/Resources.Designer.cs index b681aba..cbaeec9 100644 --- a/WinFormControl/Properties/Resources.Designer.cs +++ b/WinFormControl/Properties/Resources.Designer.cs @@ -60,6 +60,26 @@ namespace WinFormControl.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap disable { + get { + object obj = ResourceManager.GetObject("disable", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap greenCircle { + get { + object obj = ResourceManager.GetObject("greenCircle", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// @@ -70,6 +90,16 @@ namespace WinFormControl.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap redCircle { + get { + object obj = ResourceManager.GetObject("redCircle", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// diff --git a/WinFormControl/Properties/Resources.resx b/WinFormControl/Properties/Resources.resx index 73d94a9..1f3583a 100644 --- a/WinFormControl/Properties/Resources.resx +++ b/WinFormControl/Properties/Resources.resx @@ -118,9 +118,18 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\disable.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\greenCircle.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\onclickBtn.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\redCircle.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\simpleBtn.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/WinFormControl/Resources/disable.png b/WinFormControl/Resources/disable.png new file mode 100644 index 0000000..bbab9d8 Binary files /dev/null and b/WinFormControl/Resources/disable.png differ diff --git a/WinFormControl/Resources/greenCircle.png b/WinFormControl/Resources/greenCircle.png new file mode 100644 index 0000000..95c703d Binary files /dev/null and b/WinFormControl/Resources/greenCircle.png differ diff --git a/WinFormControl/Resources/redCircle.png b/WinFormControl/Resources/redCircle.png new file mode 100644 index 0000000..f6b1ddc Binary files /dev/null and b/WinFormControl/Resources/redCircle.png differ diff --git a/WinFormControl/Sounds/click.wav b/WinFormControl/Sounds/click.wav new file mode 100644 index 0000000..baedf71 Binary files /dev/null and b/WinFormControl/Sounds/click.wav differ diff --git a/WinFormControl/Sounds/di.wav b/WinFormControl/Sounds/di.wav new file mode 100644 index 0000000..736d9d6 Binary files /dev/null and b/WinFormControl/Sounds/di.wav differ diff --git a/WinFormControl/Sounds/error.wav b/WinFormControl/Sounds/error.wav new file mode 100644 index 0000000..e5751ee Binary files /dev/null and b/WinFormControl/Sounds/error.wav differ diff --git a/WinFormControl/Sounds/longSucc.wav b/WinFormControl/Sounds/longSucc.wav new file mode 100644 index 0000000..95e24cf Binary files /dev/null and b/WinFormControl/Sounds/longSucc.wav differ diff --git a/WinFormControl/Sounds/shotSucc.wav b/WinFormControl/Sounds/shotSucc.wav new file mode 100644 index 0000000..046eb76 Binary files /dev/null and b/WinFormControl/Sounds/shotSucc.wav differ diff --git a/WinFormControl/UButton.cs b/WinFormControl/UButton.cs index 36072d9..48e46d3 100644 --- a/WinFormControl/UButton.cs +++ b/WinFormControl/UButton.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Drawing; using System.Linq; using System.Text; @@ -16,26 +17,54 @@ namespace WinFormControl base.InitLayout(); this.BackgroundImage = Resources.simpleBtn; this.ForeColor = Color.Black; - this.BackColor = Color.Transparent; this.FlatStyle = FlatStyle.Flat; this.FlatAppearance.BorderSize = 0; + this.FlatAppearance.BorderColor = Color.FromArgb(45, 155, 214); + } + + + [Browsable(true), Category("Sound"), Description("是否播放声音")] + public bool PlaySound { get; set; } + + [Browsable(true), Category("Sound"), Description("声音类型")] + public SoundType SoundType { get; set; } + + protected override void OnMouseDown(MouseEventArgs mevent) + { + if (mevent.Button == MouseButtons.Left) + { + this.BackgroundImage = Resources.onclickBtn; + this.ForeColor = Color.White; + } + base.OnMouseDown(mevent); } protected override void OnClick(EventArgs e) { - this.BackgroundImage = Resources.onclickBtn; - this.ForeColor = Color.White; - this.Refresh(); try { + this.Enabled = false; + if (PlaySound) + SoundPalyUtil.PlaySound(SoundType); base.OnClick(e); } finally { - System.Threading.Thread.Sleep(200); + this.Enabled = true; + } + } + + protected override void OnEnabledChanged(EventArgs e) + { + base.OnEnabledChanged(e); + if (Enabled) + { this.BackgroundImage = Resources.simpleBtn; this.ForeColor = Color.Black; - this.Refresh(); + } + else + { + this.BackgroundImage = Resources.disable; } } } diff --git a/WinFormControl/UDataGridView.cs b/WinFormControl/UDataGridView.cs new file mode 100644 index 0000000..60b3741 --- /dev/null +++ b/WinFormControl/UDataGridView.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WinFormControl +{ + public class UDataGridView : DataGridView + { + public UDataGridView() + { + this.AllowUserToAddRows = false; + this.AllowUserToDeleteRows = false; + this.AllowUserToResizeColumns = false; + this.AllowUserToResizeRows = false; + this.BackgroundColor = System.Drawing.Color.White; + this.ColumnHeadersHeight = 24; + this.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; + this.MultiSelect = false; + + this.RowHeadersVisible = false; + this.RowTemplate.Height = 23; + this.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + + this.AlternatingRowsDefaultCellStyle = new DataGridViewCellStyle() { BackColor = System.Drawing.Color.FromArgb(235, 235, 235) }; + + this.ColumnHeadersDefaultCellStyle = new DataGridViewCellStyle() + { + Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter, + Font = new System.Drawing.Font("宋体", 12F), + ForeColor = System.Drawing.Color.White, + WrapMode = System.Windows.Forms.DataGridViewTriState.True, + }; + this.RowsDefaultCellStyle = new DataGridViewCellStyle() + { + SelectionBackColor = System.Drawing.Color.FromArgb(66, 163, 218), + Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134) + }; + } + } +} diff --git a/WinFormControl/UScanPanel.Designer.cs b/WinFormControl/UScanPanel.Designer.cs new file mode 100644 index 0000000..03afd57 --- /dev/null +++ b/WinFormControl/UScanPanel.Designer.cs @@ -0,0 +1,73 @@ +namespace WinFormControl +{ + partial class UScanPanel + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region 组件设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.textBox1 = new System.Windows.Forms.TextBox(); + this.uLabel1 = new WinFormControl.ULabel(); + this.SuspendLayout(); + // + // textBox1 + // + this.textBox1.Font = new System.Drawing.Font("宋体", 15F); + this.textBox1.Location = new System.Drawing.Point(64, 1); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(235, 30); + this.textBox1.TabIndex = 0; + // + // uLabel1 + // + this.uLabel1.AutoSize = true; + this.uLabel1.BackColor = System.Drawing.Color.Transparent; + this.uLabel1.Font = new System.Drawing.Font("宋体", 15F); + this.uLabel1.Location = new System.Drawing.Point(3, 4); + this.uLabel1.Name = "uLabel1"; + this.uLabel1.Size = new System.Drawing.Size(69, 20); + this.uLabel1.TabIndex = 1; + this.uLabel1.Text = "扫码:"; + // + // UScanPanel + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Transparent; + this.Controls.Add(this.textBox1); + this.Controls.Add(this.uLabel1); + this.Name = "UScanPanel"; + this.Size = new System.Drawing.Size(303, 32); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBox1; + private ULabel uLabel1; + } +} diff --git a/WinFormControl/UScanPanel.cs b/WinFormControl/UScanPanel.cs new file mode 100644 index 0000000..4930267 --- /dev/null +++ b/WinFormControl/UScanPanel.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WinFormControl +{ + public partial class UScanPanel : UserControl + { + [Browsable(true), Description("标签")] + public ULabel Label { get { return uLabel1; } } + + [Browsable(true), Description("文本框")] + public TextBox TextBox { get { return textBox1; } } + + [Browsable(true), Description("扫码前的动作")] + public event Action BeforeScan; + + [Browsable(true), Description("扫码后的动作")] + public event Action AfterScan; + + public UScanPanel() + { + InitializeComponent(); + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + if (!ParentForm.KeyPreview) + ParentForm.KeyPreview = true; + ParentForm.KeyPress += ParentForm_KeyPress; + } + + bool reading = false; + private void ParentForm_KeyPress(object sender, KeyPressEventArgs e) + { + if (!reading) + { + if (BeforeScan != null) + BeforeScan(); + textBox1.Text = string.Empty; + } + + if (!textBox1.Focused) + { + textBox1.Focus(); + textBox1.Text = e.KeyChar.ToString(); + textBox1.Select(textBox1.TextLength, 0); + } + + if (e.KeyChar == (char)Keys.Enter) + { + e.Handled = true; + var code = ParseCode(textBox1.Text); + textBox1.Text = code; + textBox1.Select(textBox1.TextLength, 0); + reading = false; + if (AfterScan != null) + AfterScan(); + } + else + reading = true; + } + + static string ParseCode(string url) + { + if (url.Contains("?")) + { + var arr = url.Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries); + if (arr.Length > 1) + { + var list = arr[1].Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var item in list) + { + var l = item.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); + if (l.Length == 2 && l[0].ToUpper() == "CODE") + return l[1].Trim(); + } + return string.Empty; + } + return string.Empty; + } + return url.Trim(); + } + } +} diff --git a/WinFormControl/UScanPanel.resx b/WinFormControl/UScanPanel.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WinFormControl/UScanPanel.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/WinFormControl/UWeightControl.Designer.cs b/WinFormControl/UWeightControl.Designer.cs new file mode 100644 index 0000000..7b7e393 --- /dev/null +++ b/WinFormControl/UWeightControl.Designer.cs @@ -0,0 +1,113 @@ +namespace WinFormControl +{ + partial class UWeightControl + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region 组件设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UWeightControl)); + this.weightSwitch = new System.Windows.Forms.Button(); + this.panel2 = new System.Windows.Forms.Panel(); + this.lblChengZhong = new System.Windows.Forms.Label(); + this.settingBtn = new WinFormControl.UButton(); + this.panel2.SuspendLayout(); + this.SuspendLayout(); + // + // weightSwitch + // + this.weightSwitch.BackColor = System.Drawing.Color.Transparent; + this.weightSwitch.BackgroundImage = global::WinFormControl.Properties.Resources.simpleBtn; + this.weightSwitch.FlatAppearance.BorderSize = 0; + this.weightSwitch.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.weightSwitch.Font = new System.Drawing.Font("宋体", 15F); + this.weightSwitch.Location = new System.Drawing.Point(231, 43); + this.weightSwitch.Name = "weightSwitch"; + this.weightSwitch.Size = new System.Drawing.Size(111, 34); + this.weightSwitch.TabIndex = 2; + this.weightSwitch.Text = "启用称重"; + this.weightSwitch.UseVisualStyleBackColor = false; + this.weightSwitch.Click += new System.EventHandler(this.weightSwitch_Click); + // + // panel2 + // + this.panel2.BackColor = System.Drawing.Color.Black; + this.panel2.Controls.Add(this.lblChengZhong); + this.panel2.Location = new System.Drawing.Point(0, 0); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(224, 78); + this.panel2.TabIndex = 33; + // + // lblChengZhong + // + this.lblChengZhong.AutoSize = true; + this.lblChengZhong.Font = new System.Drawing.Font("宋体", 30F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.lblChengZhong.ForeColor = System.Drawing.Color.Red; + this.lblChengZhong.Location = new System.Drawing.Point(15, 18); + this.lblChengZhong.Name = "lblChengZhong"; + this.lblChengZhong.Size = new System.Drawing.Size(97, 40); + this.lblChengZhong.TabIndex = 0; + this.lblChengZhong.Text = "0.00"; + // + // settingBtn + // + this.settingBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("settingBtn.BackgroundImage"))); + this.settingBtn.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(155)))), ((int)(((byte)(214))))); + this.settingBtn.FlatAppearance.BorderSize = 0; + this.settingBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.settingBtn.Font = new System.Drawing.Font("宋体", 15F); + this.settingBtn.ForeColor = System.Drawing.Color.Black; + this.settingBtn.Location = new System.Drawing.Point(231, 0); + this.settingBtn.Name = "settingBtn"; + this.settingBtn.Size = new System.Drawing.Size(111, 34); + this.settingBtn.TabIndex = 41; + this.settingBtn.Text = "称 设 置"; + this.settingBtn.UseVisualStyleBackColor = true; + this.settingBtn.Click += new System.EventHandler(this.settingBtn_Click); + // + // UWeightControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Transparent; + this.Controls.Add(this.settingBtn); + this.Controls.Add(this.panel2); + this.Controls.Add(this.weightSwitch); + this.Name = "UWeightControl"; + this.Size = new System.Drawing.Size(349, 78); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button weightSwitch; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Label lblChengZhong; + private UButton settingBtn; + } +} diff --git a/WinFormControl/UWeightControl.cs b/WinFormControl/UWeightControl.cs new file mode 100644 index 0000000..5107448 --- /dev/null +++ b/WinFormControl/UWeightControl.cs @@ -0,0 +1,286 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using WinFormControl.Properties; +using System.Threading; +using System.IO.Ports; +using System.Collections.Concurrent; + +namespace WinFormControl +{ + public partial class UWeightControl : UserControl + { + WeightConfig config; + SerialPort weightPort; + IDataFormat _dataFormat; + Thread _inQueryThread; + private bool _mainProcessIsRun; + readonly StringBuilder _dataStrBuilder = new StringBuilder(); + private bool switchOn; + + [Browsable(true), Description("称设置标识")] + public string WeightFalg { get; set; } + + [Browsable(true), Description("读取到值的事件")] + public event Action ReceivedValue; + + public UWeightControl() + { + InitializeComponent(); + weightSwitch.FlatAppearance.BorderColor = Color.FromArgb(45, 155, 214); + } + + [Browsable(false)] + public decimal Weight { get { return decimal.Parse(lblChengZhong.Text); } } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + ParentForm.FormClosing += delegate + { + if (_inQueryThread != null && _inQueryThread.IsAlive) + { + DisableWeight(); + } + }; + } + + private void settingBtn_Click(object sender, EventArgs e) + { + if (new WeightSettingFrom(WeightFalg).ShowDialog() == DialogResult.OK) + config = WeightConfig.Init(WeightFalg); + } + + private void weightSwitch_Click(object sender, EventArgs e) + { + try + { + if (config == null) + { + config = WeightConfig.Init(WeightFalg); + WeighAvgControl.config = config; + } + settingBtn.Enabled = switchOn; + switchOn = !switchOn; + if (switchOn) + { + weightSwitch.BackgroundImage = Resources.onclickBtn; + weightSwitch.ForeColor = Color.White; + weightSwitch.Text = "停止称重"; + + OpenSerialPort(); + _mainProcessIsRun = true; + ReadData(); + } + else + { + weightSwitch.BackgroundImage = Resources.simpleBtn; + weightSwitch.ForeColor = Color.Black; + weightSwitch.Text = "启用称重"; + DisableWeight(); + } + } + catch + { + settingBtn.Enabled = !switchOn; + switchOn = !switchOn; + } + } + + void OpenSerialPort() + { + if (!switchOn) + return; + if (config.RateSet == null) + throw new Exception("请先配置称相关信息"); + weightPort = new SerialPort(); + weightPort.PortName = config.ComSet; + weightPort.BaudRate = config.RateSet.Value; + weightPort.DataBits = config.BitSet.Value; + weightPort.ReadBufferSize = 4096 * 100; + if (!string.IsNullOrEmpty(config.Format)) + format = "{0:{format}}".Replace("{format}", config.Format); + + switch (config.WeightSet) + { + case "IND560": + _dataFormat = new IND560DataFormat(); + break; + case "Xk3124": + case "IND231": + _dataFormat = new Xk3124DataFormat(); + break; + case "Xk3190A9": + _dataFormat = new Xk3190A9DataFormat(); + break; + default: + _dataFormat = new Xk3190D10DataFormat(); + break; + } + if (!weightPort.IsOpen) + { + try + { + weightPort.Open(); + } + catch (InvalidOperationException) + { + throw new Exception("指定的端口已打开"); + } + catch (UnauthorizedAccessException) + { + throw new Exception("对端口的访问被拒绝"); + } + } + } + + void ReadData() + { + _inQueryThread = new Thread(InQuery); + _inQueryThread.Start(); + } + + string format = "{0:0.00}"; + + private void InQuery() + { + while (_mainProcessIsRun) + { + int availableCount = weightPort.BytesToRead; + if (availableCount == 0) + { + Thread.Sleep(10); + } + char[] buffer = new char[availableCount]; + if (!weightPort.IsOpen) + { + continue; + } + weightPort.Read(buffer, 0, availableCount); + foreach (var c in buffer) + { + if (c == _dataFormat.Beginchar) + { + _dataStrBuilder.Clear(); + _dataStrBuilder.Append(c); + } + else if (c == _dataFormat.Endchar && _dataStrBuilder.Length == _dataFormat.DataLength - 1) + { + _dataStrBuilder.Append(c); + bool isStatic; + string str; + if (_dataFormat.ParseAscii(_dataStrBuilder.ToString(), out str, out isStatic)) + { + if (config.WeightType == 0) + { + if (string.IsNullOrEmpty(str)) + str = "0"; + this.Invoke(new Action(delegate() + { + var v = decimal.Parse(str); + lblChengZhong.Text = string.Format(format, v); + if (str != "0") + { + if (ReceivedValue != null) + ReceivedValue(v); + } + })); + } + else + { + decimal num = 0; + if (decimal.TryParse(str, out num)) + { + this.Invoke(new Action(delegate() + { + lblChengZhong.Text = string.Format(format, num); + })); + WeighAvgControl.Add(num, isStatic); + } + if (WeighAvgControl.TryGetValue(out num)) + { + this.Invoke(new Action(delegate() + { + if (str != "0") + { + if (ReceivedValue != null) + ReceivedValue(num); + } + })); + } + } + } + _dataStrBuilder.Clear(); + } + else if (_dataStrBuilder.Length != 0) + { + _dataStrBuilder.Append(c); + } + } + } + } + + private class WeighAvgControl + { + public static WeightConfig config; + public static bool TryGetValue(out decimal result) + { + List> list; + if (mWeighList.TryDequeue(out list)) + { + var r = list.Where(x => x.Item2).Select(x => x.Item1).GroupBy(x => x); + var firstOrDefault = r.OrderByDescending(x => x.Count()).FirstOrDefault(); + if (firstOrDefault != null) + { + result = firstOrDefault.Key; + return true; + } + result = 0; + return false; + } + result = 0; + return false; + } + + static ConcurrentQueue>> mWeighList = new ConcurrentQueue>>(); + + static List> _list = new List>(); + + public static void Add(decimal value, bool isStatic) + { + if (value >= config.MinWeight && value <= config.MaxWeight) + { + _list.Add(new Tuple(value, isStatic)); + } + else + { + if (_list.Count > 0) + { + mWeighList.Enqueue(_list); + _list = new List>(); + } + } + } + } + + void DisableWeight() + { + _mainProcessIsRun = false; + lblChengZhong.Text = string.Format(format, 0); + format = "{0:0.00}"; + Thread.Sleep(10); + if (_inQueryThread.IsAlive) + { + _inQueryThread.Abort(); + } + if (weightPort.IsOpen) + weightPort.Close(); + } + } +} diff --git a/WinFormControl/UWeightControl.resx b/WinFormControl/UWeightControl.resx new file mode 100644 index 0000000..75fda3d --- /dev/null +++ b/WinFormControl/UWeightControl.resx @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + + + + iVBORw0KGgoAAAANSUhEUgAAAGAAAAAwCAIAAABhdOiYAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAHNJREFUaEPt0AENACAMwDAkowVB14aDz0CTKui5b1gICoKCoCAoCAqCgqAgKAgK + goKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAg + KAgKgoKg1ZsPvpCB0hBohjQAAAAASUVORK5CYII= + + + + True + + \ No newline at end of file diff --git a/WinFormControl/ControlUtil.cs b/WinFormControl/Utils/ControlUtil.cs similarity index 100% rename from WinFormControl/ControlUtil.cs rename to WinFormControl/Utils/ControlUtil.cs diff --git a/WinFormControl/Utils/DataFormatBase.cs b/WinFormControl/Utils/DataFormatBase.cs new file mode 100644 index 0000000..bcaf82b --- /dev/null +++ b/WinFormControl/Utils/DataFormatBase.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormControl +{ + interface IDataFormat + { + char Beginchar { get; } + char Endchar { get; } + int DataLength { get; } + bool ParseAscii(string buf, out string weight, out bool isStatic); + bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr); + } + + internal abstract class DataFormatBase : IDataFormat + { + public abstract int DataLength + { + get; + } + + public abstract char Beginchar + { + get; + } + + public abstract char Endchar + { + get; + } + + + public const short BUFSIZE = 36; + // 根据开始字符找出 一个完整的数据帧 + public string FindDataFrame(string buf, int fSize) + { + var bufSize = buf.Length; + if (fSize > bufSize) + { + return string.Empty; + } + + int index = buf.IndexOf(Beginchar); // 查找开始字符的索引 + + if (index < 0 || (index + fSize) > bufSize) + { + return string.Empty; + } + + string data = buf.Substring(index, fSize); + + // 检查结束字符 + if (data[fSize - 1] != Endchar) + { + return string.Empty; + } + + return data; + } + + public abstract string ParseData(string buf, out bool isStatic); + + public abstract bool ParseAscii(string buf, out string weight, out bool isStatic); + public abstract bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr); + } +} diff --git a/WinFormControl/Utils/IND560DataFormat.cs b/WinFormControl/Utils/IND560DataFormat.cs new file mode 100644 index 0000000..412544e --- /dev/null +++ b/WinFormControl/Utils/IND560DataFormat.cs @@ -0,0 +1,36 @@ +namespace WinFormControl +{ + internal class IND560DataFormat : DataFormatBase { + public override int DataLength { + get { return 10; } + } + + public override char Beginchar { + get { return (char)0x0A; }//ûй̶Ŀʼ־ + } + + public override char Endchar { + get { return (char)0x0D; } + } + + public override string ParseData(string buf, out bool isStatic) + { + isStatic = false; + return string.Empty; + } + + public override bool ParseAscii(string buf, out string weight, out bool isStatic) { + isStatic = true; + weight = buf.Replace("kg", "").Replace((char)0x0D, (char)0x20).Replace((char)0x0A, (char)0x20); + weight = weight.Trim(); + return true; + } + + public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr) { + weight = ""; + isStatic = false; + subStr = ""; + return false; + } + } +} \ No newline at end of file diff --git a/WinFormControl/Utils/SoundPalyUtil.cs b/WinFormControl/Utils/SoundPalyUtil.cs new file mode 100644 index 0000000..9d45b6f --- /dev/null +++ b/WinFormControl/Utils/SoundPalyUtil.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Media; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormControl +{ + public static class SoundPalyUtil + { + static SoundPlayer player = new SoundPlayer(); + public static void PlaySound(SoundType type) + { + var fileName = Path.Combine(Directory.GetCurrentDirectory(), string.Format(@"Sounds\{0}.wav", type.ToString())); + if (!File.Exists(fileName)) + return; + player.SoundLocation = fileName; + player.Load(); + player.Play(); + } + } + + public enum SoundType + { + Click, + Di, + Error, + ShotSucc, + LongSucc, + } +} diff --git a/WinFormControl/Utils/Xk3124DataFormat.cs b/WinFormControl/Utils/Xk3124DataFormat.cs new file mode 100644 index 0000000..bfbb805 --- /dev/null +++ b/WinFormControl/Utils/Xk3124DataFormat.cs @@ -0,0 +1,100 @@ +using System.Text; + +namespace WinFormControl +{ + internal class Xk3124DataFormat : DataFormatBase + { + public override int DataLength { + get { return 17; } + } + + public override char Beginchar + { + get { return (char)0x02; } + } + + public override char Endchar + { + get { return (char)0x0D; ; } + } + + public override string ParseData(string buf, out bool isStatic) { + StringBuilder str = new StringBuilder(); + + char swa = buf[1]; // 状态字A + char swb = buf[2]; // 状态字B + + int dotIndex = (swa & 0x07) - 2; // 小数点位置 + + bool isPositive = (((swb >> 1) & 0x01) == 0); // 符号:是否为正数 + isStatic = (((swb >> 3) & 0x01) == 0); + + char[] num = new char[6]; + + for (int i = 0; i < 6; i++) { + num[i] = buf[i + 4]; + } + + if (dotIndex < 0) { // 不考虑精确到十,百位 + return str.ToString(); + } + + for (int i = 0; i < 6 - dotIndex; i++) { + str.Append(num[i]); + } + + str.Append('.'); + + for (int i = 0; i < dotIndex; i++) { + str.Append(num[6 - dotIndex + i]); + } + + // 去掉空格 + string result = str.ToString().Trim(); + + // 取消前面多余的0 + for (int i = 0; i < result.Length; i++) { + if (result[i] != '0') { + result = result.Substring(i, result.Length - i); + break; + } + } + + if (result.IndexOf('.') == 0) { + result = result.Insert(0, "0"); + } + + if (result.IndexOf('.') == result.Length - 1) { + result = result.Remove(result.IndexOf('.'), 1); + } + + if (!isPositive) { // 负数 + result = result.Insert(0, "-"); + } + + return result; + } + + public override bool ParseAscii(string buf, out string weight, out bool isStatic) { + isStatic = false; + weight = FindDataFrame(buf, DataLength ); + + if (string.IsNullOrEmpty(weight)) { + return false; + } + + weight = ParseData(weight, out isStatic); + + return true; + } + + public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr) { + weight = ""; + isStatic = false; + subStr = ""; + return false; + } + } + + //IND560单次读入 +} diff --git a/WinFormControl/Utils/Xk3190A9DataFormat.cs b/WinFormControl/Utils/Xk3190A9DataFormat.cs new file mode 100644 index 0000000..bc959e8 --- /dev/null +++ b/WinFormControl/Utils/Xk3190A9DataFormat.cs @@ -0,0 +1,107 @@ +namespace WinFormControl +{ + internal class Xk3190A9DataFormat : DataFormatBase + { + + public override int DataLength { + get { return 12; } + } + + public override char Beginchar { + get { return (char)0x02; } + } + + public override char Endchar { + get { return (char)0x03;} + } + + public override string ParseData(string buf, out bool isStatic) { + string weight; + // Сλ0-4 + int dot = (short)(0x0F & buf[8]); + weight = buf.Substring(2, 6).Trim(); + + // insert dot + weight = InsertDot(weight, dot); + isStatic = true; // Ĭ Ϊ ȶ + + // buffer[1] λ + if (buf[1] == '-') { + weight = weight.Insert(0, "-"); + } + + return weight; + } + + public override bool ParseAscii(string buf, out string weight, out bool isStatic) { + isStatic = false; + weight = FindDataFrame(buf, DataLength ); + + if (string.IsNullOrEmpty(weight)) { + return false; + } + + weight = ParseData(weight, out isStatic); + + return true; + } + + private static string InsertDot(string weight, int dotBits) { + string str = weight.TrimStart(new[] { + '0' + }); + str = str.Trim(); + + if (dotBits > 0) { + //str = str.Insert(str.Length - dotBits, "."); + if (string.IsNullOrEmpty(str)) { + str = "0"; + str = str.Insert(str.Length, "."); + for (int i = 0; i < dotBits; i++) { + str = str.Insert(str.Length, "0"); + } + } else + str = str.Insert(str.Length - dotBits, "."); + } + + if (str.IndexOf(".") == 0) { + str = str.Insert(0, "0"); + } + + return str; + } + + public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr) { + isStatic = false; + weight = FindDataFrame(buf, DataLength , out subStr); + + if (string.IsNullOrEmpty(weight)) { + return false; + } + + weight = ParseData(weight, out isStatic); + + + return true; + } + // ݿʼַҳ һ֡ + public string FindDataFrame(string buf, int fSize , out string subStr) { + var bufSize = buf.Length; + subStr = ""; + int index = buf.IndexOf(Beginchar); // ҿʼַ + + if (index < 0 || (index + fSize) > bufSize) { + return string.Empty; + } + + string data = buf.Substring(index, fSize); + subStr = buf.Substring(index + fSize); + // ַ + if (data[fSize - 1] != Endchar) { + return string.Empty; + } + + return data; + } + } +} \ No newline at end of file diff --git a/WinFormControl/Utils/Xk3190D10DataFormat.cs b/WinFormControl/Utils/Xk3190D10DataFormat.cs new file mode 100644 index 0000000..bdc11f0 --- /dev/null +++ b/WinFormControl/Utils/Xk3190D10DataFormat.cs @@ -0,0 +1,102 @@ +namespace WinFormControl +{ + internal class Xk3190D10DataFormat : DataFormatBase + { + + public override int DataLength { + get { return 12; } + } + public override char Beginchar { + get { return (char)0x02; } + } + + public override char Endchar { + get { return (char)0x0D; ; } + } + + public override string ParseData(string buf, out bool isStatic) { + string weight; + // Сλ0-4 + int dot = (short)(0x0F & buf[8]); + weight = buf.Substring(2, 6).Trim(); + + // insert dot + weight = InsertDot(weight, dot); + isStatic = true; // Ĭ Ϊ ȶ + + // buffer[1] λ + if (buf[1] == '-') { + weight = weight.Insert(0, "-"); + } else { + + } + return weight; + } + + public override bool ParseAscii(string buf, out string weight, out bool isStatic) { + isStatic = false; + weight = FindDataFrame(buf, DataLength); + + if (string.IsNullOrEmpty(weight)) { + return false; + } + + weight = ParseData(weight, out isStatic); + + return true; + } + + private static string InsertDot(string weight, int dotBits) { + string str = weight.TrimStart(new[] { + '0' + }); + str = str.Trim(); + + if (dotBits > 0) { + //str = str.Insert(str.Length - dotBits, "."); + if (string.IsNullOrEmpty(str)) { + str = "0"; + str = str.Insert(str.Length, "."); + for (int i = 0; i < dotBits; i++) { + str = str.Insert(str.Length, "0"); + } + } else + str = str.Insert(str.Length - dotBits, "."); + } + + if (str.IndexOf(".") == 0) { + str = str.Insert(0, "0"); + } + + return str; + } + + public override bool ParseAscii(string buf, out string weight, out bool isStatic, out string subStr) { + isStatic = false; + weight = FindDataFrame(buf, DataLength ); + subStr = ""; + if (string.IsNullOrEmpty(weight)) { + return false; + } + + weight = ParseData(weight, out isStatic); + + return true; + } + + #region 1.3 ֤intż + /// + /// 1.3 ֤intż + /// + /// + /// + public bool isJO(int num) { + int a = num % 2; + if (a == 0) + return true; + else + return false; + } + #endregion + } +} \ No newline at end of file diff --git a/WinFormControl/Utils/XmlUtil.cs b/WinFormControl/Utils/XmlUtil.cs new file mode 100644 index 0000000..54dac32 --- /dev/null +++ b/WinFormControl/Utils/XmlUtil.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace WinFormControl +{ + internal static class XmlUtil + { + static string currentPath = Directory.GetCurrentDirectory(); + public static void SerializerObjToFile(object obj, string fileName) + { + fileName = Path.Combine(currentPath, fileName + ".xml"); + var ser = new XmlSerializer(obj.GetType()); + using (var stream = File.Open(fileName, FileMode.Create)) + { + ser.Serialize(stream, obj); + } + } + + public static T DeserializeFromFile(string fileName) + where T : new() + { + fileName = Path.Combine(currentPath, fileName + ".xml"); + if (!File.Exists(fileName)) + { + return new T(); + } + using (var reader = new StreamReader(fileName)) + { + var xs = new XmlSerializer(typeof(T)); + object obj = xs.Deserialize(reader); + reader.Close(); + return (T)obj; + } + } + } +} diff --git a/WinFormControl/WeightContext.cs b/WinFormControl/WeightContext.cs new file mode 100644 index 0000000..dbdc7b9 --- /dev/null +++ b/WinFormControl/WeightContext.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormControl +{ + public class WeightConfig + { + public string WeightSet { get; set; } + + public string ComSet { get; set; } + + public int? RateSet { get; set; } + + public int? BitSet { get; set; } + + public string Format { get; set; } + + public decimal? Discont { get; set; } + + public int WeightType { get; set; } + + public decimal MinWeight { get; set; } + + public decimal MaxWeight { get; set; } + + public static WeightConfig Init(string flag) + { + return XmlUtil.DeserializeFromFile(flag + "WeightConfig"); + } + + public void Save(string flag) + { + XmlUtil.SerializerObjToFile(this, flag + "WeightConfig"); + } + } +} diff --git a/WinFormControl/WeightSettingFrom.cs b/WinFormControl/WeightSettingFrom.cs new file mode 100644 index 0000000..7126c54 --- /dev/null +++ b/WinFormControl/WeightSettingFrom.cs @@ -0,0 +1,104 @@ +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; + +namespace WinFormControl +{ + public partial class WeightSettingFrom : Form + { + List weight = new List { "IND560", "Xk3124", "Xk3190A9", "Xk3190D10", "IND231" }; + List com = new List { "COM1", "COM2", "COM3", "COM4", "COM5" }; + List rate = new List { "1200", "2400", "4800", "7200", "9600" }; + List bit = new List { "5", "6", "7", "8" }; + List weightRead = new List { "稳定读取", "连续发送" }; + string _flag; + WeightConfig config; + + public WeightSettingFrom(string flag) + { + this._flag = flag; + InitializeComponent(); + weightSet.DataSource = weight; + comSet.DataSource = com; + rateSet.DataSource = rate; + bitSet.DataSource = bit; + weightReadType.DataSource = weightRead; + config = WeightConfig.Init(flag); + if (!string.IsNullOrEmpty(config.WeightSet)) + weightSet.SelectedIndex = weight.IndexOf(config.WeightSet); + else + weightSet.SelectedIndex = 0; + if (!string.IsNullOrEmpty(config.ComSet)) + comSet.SelectedIndex = com.IndexOf(config.ComSet); + else + comSet.SelectedIndex = 0; + if (config.RateSet.HasValue) + rateSet.SelectedIndex = rate.IndexOf(config.RateSet.ToString()); + else + rateSet.SelectedIndex = 2; + if (config.BitSet.HasValue) + bitSet.SelectedIndex = bit.IndexOf(config.BitSet.ToString()); + else + bitSet.SelectedIndex = 3; + if (string.IsNullOrEmpty(config.Format)) + format.Text = "0.00"; + else + format.Text = config.Format; + if (config.Discont == null) + discont.Text = "0.00"; + else + discont.Text = config.Discont.ToString(); + weightReadType.SelectedIndex = config.WeightType; + minInput.Text = config.MinWeight.ToString(); + maxInput.Text = config.MaxWeight.ToString(); + } + + bool changed; + private void saveBtn_Click(object sender, EventArgs e) + { + config.WeightSet = weight[this.weightSet.SelectedIndex]; + config.ComSet = com[this.comSet.SelectedIndex]; + config.RateSet = int.Parse(rate[this.rateSet.SelectedIndex]); + config.BitSet = int.Parse(bit[this.bitSet.SelectedIndex]); + config.Format = format.Text; + config.WeightType = weightReadType.SelectedIndex; + if (config.WeightType == 1) + { + decimal min = 0; + decimal max = 0; + if (!decimal.TryParse(minInput.Text.Trim(), out min)) + throw new Exception("连续发送时 必须输入有效区间"); + if (!decimal.TryParse(maxInput.Text.Trim(), out max)) + throw new Exception("连续发送时 必须输入有效区间"); + config.MinWeight = min; + config.MaxWeight = max; + } + if (!string.IsNullOrEmpty(discont.Text)) + { + decimal v; + if (decimal.TryParse(discont.Text, out v)) + config.Discont = v; + else + throw new Exception("扣重格式输入不正确"); + } + else + config.Discont = 0; + config.Save(_flag); + changed = true; + UMessageBox.Show("保存成功!"); + } + + private void closeBtn_Click(object sender, EventArgs e) + { + if (changed) + DialogResult = DialogResult.OK; + Close(); + } + } +} diff --git a/WinFormControl/WeightSettingFrom.designer.cs b/WinFormControl/WeightSettingFrom.designer.cs new file mode 100644 index 0000000..2a331ef --- /dev/null +++ b/WinFormControl/WeightSettingFrom.designer.cs @@ -0,0 +1,310 @@ +namespace WinFormControl +{ + partial class WeightSettingFrom + { + /// + /// 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() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WeightSettingFrom)); + this.maxInput = new WinFormControl.UTextBoxWithPad(); + this.minInput = new WinFormControl.UTextBoxWithPad(); + this.label8 = new WinFormControl.ULabel(); + this.weightReadType = new System.Windows.Forms.ComboBox(); + this.label7 = new WinFormControl.ULabel(); + this.discont = new WinFormControl.UTextBoxWithPad(); + this.format = new WinFormControl.UTextBoxWithPad(); + this.label6 = new WinFormControl.ULabel(); + this.label5 = new WinFormControl.ULabel(); + this.closeBtn = new WinFormControl.UButton(); + this.saveBtn = new WinFormControl.UButton(); + this.bitSet = new System.Windows.Forms.ComboBox(); + this.rateSet = new System.Windows.Forms.ComboBox(); + this.comSet = new System.Windows.Forms.ComboBox(); + this.weightSet = new System.Windows.Forms.ComboBox(); + this.label4 = new WinFormControl.ULabel(); + this.label3 = new WinFormControl.ULabel(); + this.label2 = new WinFormControl.ULabel(); + this.label1 = new WinFormControl.ULabel(); + this.SuspendLayout(); + // + // maxInput + // + this.maxInput.Font = new System.Drawing.Font("宋体", 12F); + this.maxInput.Location = new System.Drawing.Point(262, 370); + this.maxInput.Name = "maxInput"; + this.maxInput.Size = new System.Drawing.Size(55, 26); + this.maxInput.TabIndex = 67; + this.maxInput.Type = WinFormControl.UTextBoxWithPad.TextBoxType.Number; + // + // minInput + // + this.minInput.Font = new System.Drawing.Font("宋体", 12F); + this.minInput.Location = new System.Drawing.Point(196, 370); + this.minInput.Name = "minInput"; + this.minInput.Size = new System.Drawing.Size(55, 26); + this.minInput.TabIndex = 66; + this.minInput.Type = WinFormControl.UTextBoxWithPad.TextBoxType.Number; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.BackColor = System.Drawing.Color.Transparent; + this.label8.Font = new System.Drawing.Font("宋体", 15F); + this.label8.Location = new System.Drawing.Point(74, 370); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(109, 20); + this.label8.TabIndex = 65; + this.label8.Text = "有效区间:"; + // + // weightReadType + // + this.weightReadType.Font = new System.Drawing.Font("宋体", 15F); + this.weightReadType.FormattingEnabled = true; + this.weightReadType.Location = new System.Drawing.Point(196, 323); + this.weightReadType.Name = "weightReadType"; + this.weightReadType.Size = new System.Drawing.Size(121, 28); + this.weightReadType.TabIndex = 64; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.BackColor = System.Drawing.Color.Transparent; + this.label7.Font = new System.Drawing.Font("宋体", 15F); + this.label7.Location = new System.Drawing.Point(74, 326); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(109, 20); + this.label7.TabIndex = 63; + this.label7.Text = "读取方式:"; + // + // discont + // + this.discont.Font = new System.Drawing.Font("宋体", 14F); + this.discont.Location = new System.Drawing.Point(196, 274); + this.discont.Name = "discont"; + this.discont.Size = new System.Drawing.Size(121, 29); + this.discont.TabIndex = 62; + this.discont.Type = WinFormControl.UTextBoxWithPad.TextBoxType.Number; + // + // format + // + this.format.Font = new System.Drawing.Font("宋体", 14F); + this.format.Location = new System.Drawing.Point(196, 226); + this.format.Name = "format"; + this.format.Size = new System.Drawing.Size(121, 29); + this.format.TabIndex = 61; + this.format.Type = WinFormControl.UTextBoxWithPad.TextBoxType.Number; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.BackColor = System.Drawing.Color.Transparent; + this.label6.Font = new System.Drawing.Font("宋体", 15F); + this.label6.Location = new System.Drawing.Point(74, 283); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(69, 20); + this.label6.TabIndex = 60; + this.label6.Text = "扣重:"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.BackColor = System.Drawing.Color.Transparent; + this.label5.Font = new System.Drawing.Font("宋体", 15F); + this.label5.Location = new System.Drawing.Point(74, 232); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(109, 20); + this.label5.TabIndex = 59; + this.label5.Text = "显示格式:"; + // + // closeBtn + // + this.closeBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("closeBtn.BackgroundImage"))); + this.closeBtn.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(155)))), ((int)(((byte)(214))))); + this.closeBtn.FlatAppearance.BorderSize = 0; + this.closeBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.closeBtn.Font = new System.Drawing.Font("宋体", 15F); + this.closeBtn.ForeColor = System.Drawing.Color.Black; + this.closeBtn.Location = new System.Drawing.Point(218, 416); + this.closeBtn.Name = "closeBtn"; + this.closeBtn.Size = new System.Drawing.Size(90, 34); + this.closeBtn.TabIndex = 58; + this.closeBtn.Text = "关闭"; + this.closeBtn.UseVisualStyleBackColor = true; + this.closeBtn.Click += new System.EventHandler(this.closeBtn_Click); + // + // saveBtn + // + this.saveBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("saveBtn.BackgroundImage"))); + this.saveBtn.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(155)))), ((int)(((byte)(214))))); + this.saveBtn.FlatAppearance.BorderSize = 0; + this.saveBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.saveBtn.Font = new System.Drawing.Font("宋体", 15F); + this.saveBtn.ForeColor = System.Drawing.Color.Black; + this.saveBtn.Location = new System.Drawing.Point(105, 416); + this.saveBtn.Name = "saveBtn"; + this.saveBtn.Size = new System.Drawing.Size(90, 34); + this.saveBtn.TabIndex = 57; + this.saveBtn.Text = "保存"; + this.saveBtn.UseVisualStyleBackColor = true; + this.saveBtn.Click += new System.EventHandler(this.saveBtn_Click); + // + // bitSet + // + this.bitSet.Font = new System.Drawing.Font("宋体", 15F); + this.bitSet.FormattingEnabled = true; + this.bitSet.Location = new System.Drawing.Point(196, 179); + this.bitSet.Name = "bitSet"; + this.bitSet.Size = new System.Drawing.Size(121, 28); + this.bitSet.TabIndex = 54; + // + // rateSet + // + this.rateSet.Font = new System.Drawing.Font("宋体", 15F); + this.rateSet.FormattingEnabled = true; + this.rateSet.Location = new System.Drawing.Point(196, 127); + this.rateSet.Name = "rateSet"; + this.rateSet.Size = new System.Drawing.Size(121, 28); + this.rateSet.TabIndex = 55; + // + // comSet + // + this.comSet.Font = new System.Drawing.Font("宋体", 15F); + this.comSet.FormattingEnabled = true; + this.comSet.Location = new System.Drawing.Point(196, 77); + this.comSet.Name = "comSet"; + this.comSet.Size = new System.Drawing.Size(121, 28); + this.comSet.TabIndex = 56; + // + // weightSet + // + this.weightSet.Font = new System.Drawing.Font("宋体", 15F); + this.weightSet.FormattingEnabled = true; + this.weightSet.Location = new System.Drawing.Point(196, 29); + this.weightSet.Name = "weightSet"; + this.weightSet.Size = new System.Drawing.Size(121, 28); + this.weightSet.TabIndex = 53; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.BackColor = System.Drawing.Color.Transparent; + this.label4.Font = new System.Drawing.Font("宋体", 15F); + this.label4.Location = new System.Drawing.Point(74, 182); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(89, 20); + this.label4.TabIndex = 52; + this.label4.Text = "数据位:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.BackColor = System.Drawing.Color.Transparent; + this.label3.Font = new System.Drawing.Font("宋体", 15F); + this.label3.Location = new System.Drawing.Point(74, 130); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(89, 20); + this.label3.TabIndex = 51; + this.label3.Text = "波特率:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.BackColor = System.Drawing.Color.Transparent; + this.label2.Font = new System.Drawing.Font("宋体", 15F); + this.label2.Location = new System.Drawing.Point(74, 80); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(89, 20); + this.label2.TabIndex = 50; + this.label2.Text = "端口号:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.BackColor = System.Drawing.Color.Transparent; + this.label1.Font = new System.Drawing.Font("宋体", 15F); + this.label1.Location = new System.Drawing.Point(74, 32); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(89, 20); + this.label1.TabIndex = 49; + this.label1.Text = "称型号:"; + // + // WeightSettingFrom + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.White; + this.ClientSize = new System.Drawing.Size(391, 481); + this.ControlBox = false; + this.Controls.Add(this.maxInput); + this.Controls.Add(this.minInput); + this.Controls.Add(this.label8); + this.Controls.Add(this.weightReadType); + this.Controls.Add(this.label7); + this.Controls.Add(this.discont); + this.Controls.Add(this.format); + this.Controls.Add(this.label6); + this.Controls.Add(this.label5); + this.Controls.Add(this.closeBtn); + this.Controls.Add(this.saveBtn); + this.Controls.Add(this.bitSet); + this.Controls.Add(this.rateSet); + this.Controls.Add(this.comSet); + this.Controls.Add(this.weightSet); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "WeightSettingFrom"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "称设置"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private UTextBoxWithPad maxInput; + private UTextBoxWithPad minInput; + private ULabel label8; + private System.Windows.Forms.ComboBox weightReadType; + private ULabel label7; + private UTextBoxWithPad discont; + private UTextBoxWithPad format; + private ULabel label6; + private ULabel label5; + private UButton closeBtn; + private UButton saveBtn; + private System.Windows.Forms.ComboBox bitSet; + private System.Windows.Forms.ComboBox rateSet; + private System.Windows.Forms.ComboBox comSet; + private System.Windows.Forms.ComboBox weightSet; + private ULabel label4; + private ULabel label3; + private ULabel label2; + private ULabel label1; + } +} \ No newline at end of file diff --git a/WinFormControl/WeightSettingFrom.resx b/WinFormControl/WeightSettingFrom.resx new file mode 100644 index 0000000..8419036 --- /dev/null +++ b/WinFormControl/WeightSettingFrom.resx @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + iVBORw0KGgoAAAANSUhEUgAAAGAAAAAwCAIAAABhdOiYAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAHNJREFUaEPt0AENACAMwDAkowVB14aDz0CTKui5b1gICoKCoCAoCAqCgqAgKAgK + goKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAg + KAgKgoKg1ZsPvpCB0hBohjQAAAAASUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAAGAAAAAwCAIAAABhdOiYAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAHNJREFUaEPt0AENACAMwDAkowVB14aDz0CTKui5b1gICoKCoCAoCAqCgqAgKAgK + goKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAg + KAgKgoKg1ZsPvpCB0hBohjQAAAAASUVORK5CYII= + + + \ No newline at end of file diff --git a/WinFormControl/WinFormControl.csproj b/WinFormControl/WinFormControl.csproj index e336ccb..bbecdec 100644 --- a/WinFormControl/WinFormControl.csproj +++ b/WinFormControl/WinFormControl.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {45A6C56B-C815-4AEA-B0C4-68C122FD3139} + {5F1AC749-68DB-43E2-8895-886ECC04D7DA} Library Properties WinFormControl @@ -34,72 +34,143 @@ + - - - - - NumberPad.xaml - + + UserControl + + + NetStateWatch.cs + True True Resources.resx + + UserControl + + + UScanPanel.cs + + + + NumberPad.xaml + Component + + Component + Component Form - + UMessageBox.cs Component + + + + + + + + UserControl + + + UWeightControl.cs + VirtualKeyPad.xaml + + + Form + + + WeightSettingFrom.cs + + - + + NetStateWatch.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + + + UMessageBox.cs + + + UScanPanel.cs + + + UWeightControl.cs + + + WeightSettingFrom.cs + + + + - Designer MSBuild:Compile + Designer - Designer MSBuild:Compile + Designer - - ResXFileCodeGenerator - Resources.Designer.cs - - - UMessageBox.cs - + + + + + + + + + + + + + + + + + + + + + + +