24 changed files with 1503 additions and 0 deletions
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<configuration> |
|||
<startup> |
|||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> |
|||
</startup> |
|||
</configuration> |
@ -0,0 +1,9 @@ |
|||
<Application x:Class="DyeingComputer.App" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:local="clr-namespace:DyeingComputer" |
|||
StartupUri="MainWindow.xaml"> |
|||
<Application.Resources> |
|||
|
|||
</Application.Resources> |
|||
</Application> |
@ -0,0 +1,114 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Configuration; |
|||
using System.Data; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using System.Windows; |
|||
|
|||
namespace DyeingComputer |
|||
{ |
|||
/// <summary>
|
|||
/// App.xaml 的交互逻辑
|
|||
/// </summary>
|
|||
public partial class App : Application |
|||
{ |
|||
|
|||
public App() |
|||
{ |
|||
this.Startup += new StartupEventHandler(App_Startup); |
|||
this.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException); |
|||
} |
|||
System.Threading.Mutex mutex; |
|||
void App_Startup(object sender, StartupEventArgs e) //程序只允许启动一次
|
|||
{ |
|||
bool ret; |
|||
mutex = new System.Threading.Mutex(true, "ElectronicNeedleTherapySystem", out ret); |
|||
if (!ret) |
|||
{ |
|||
MessageBox.Show("The program has been launched"); |
|||
Environment.Exit(0); |
|||
} |
|||
} |
|||
|
|||
protected override void OnStartup(StartupEventArgs e) //跟踪报错信息
|
|||
{ |
|||
base.OnStartup(e); |
|||
//UI线程的异常捕捉
|
|||
this.DispatcherUnhandledException += App_DispatcherUnhandledException; |
|||
} |
|||
|
|||
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) |
|||
{ |
|||
e.Handled = true; |
|||
if (e.Exception.InnerException == null) |
|||
{ |
|||
MessageBox.Show("发生了一个无法处理的错误!请联系SUNLIGHT处理!" |
|||
+ "(1)错误" + Environment.NewLine |
|||
+ "(2)错误源:" + e.Exception.Source + Environment.NewLine |
|||
// + (3)详细信息:" + e.Exception.Message + Environment.NewLine
|
|||
// + "(4)报错区域:" + e.Exception.StackTrace
|
|||
); |
|||
} |
|||
else |
|||
{ |
|||
MessageBox.Show("发生了一个无法处理的错误!请联系SUNLIGHT处理!" |
|||
+ "(1)错误" + Environment.NewLine |
|||
// + "(2)错误源:" + e.Exception.InnerException.Source + Environment.NewLine
|
|||
+ "(3)错误信息:" + e.Exception.Message + Environment.NewLine |
|||
// + "(4)详细信息:" + e.Exception.InnerException.Message + Environment.NewLine
|
|||
// + "(5)报错区域:" + e.Exception.InnerException.StackTrace
|
|||
); |
|||
} |
|||
|
|||
string Log_time = DateTime.Now.ToString("yyyy-MM-dd"); |
|||
string logpath = System.Environment.CurrentDirectory + "\\ERR";//日志文件目录
|
|||
//string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
|
|||
// System.IO.DirectoryInfo log = new System.IO.DirectoryInfo();//生成日志文件目录
|
|||
string log_path = logpath + "\\ERR" + Log_time + ".txt"; |
|||
string Log_timehms = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
|||
if (Directory.Exists(logpath))//检查日志路径
|
|||
{ |
|||
if (!File.Exists(log_path))//检查文件并写入
|
|||
{ |
|||
FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建文件
|
|||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
|||
wr.Close(); |
|||
FileStream fil = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
|
|||
StreamWriter wfil = new StreamWriter(fil);//创建文件
|
|||
wfil.WriteLine("[" + Log_timehms + "];[Error] ||" + Environment.NewLine.ToString()); |
|||
wfil.WriteLine("[" + Log_timehms + "];[Error source] ||" + e.Exception.Source.ToString() + Environment.NewLine.ToString()); |
|||
wfil.WriteLine("[" + Log_timehms + "];[Error message] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString()); |
|||
wfil.WriteLine("[" + Log_timehms + "];[Error area] ||" + e.Exception.StackTrace.ToString()); |
|||
wfil.Close(); |
|||
} |
|||
else |
|||
{ |
|||
FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
|
|||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
|||
wr.WriteLine("[" + Log_timehms + "];[Error] ||" + Environment.NewLine.ToString()); |
|||
wr.WriteLine("[" + Log_timehms + "];[Error source] ||" + e.Exception.Source.ToString() + Environment.NewLine.ToString()); |
|||
wr.WriteLine("[" + Log_timehms + "];[Error message] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString()); |
|||
wr.WriteLine("[" + Log_timehms + "];[Error area] ||" + e.Exception.StackTrace.ToString()); |
|||
wr.Close(); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
DirectoryInfo directoryInfo = new DirectoryInfo(logpath); |
|||
directoryInfo.Create(); |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 启动初始页面
|
|||
/// </summary>
|
|||
|
|||
private void Application_Startup(object sender, StartupEventArgs e) |
|||
{ |
|||
Application.Current.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);//和MainWindwo同一目录
|
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,112 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{18FD96BD-D3DD-46DA-BE92-CA942F27D4DD}</ProjectGuid> |
|||
<OutputType>WinExe</OutputType> |
|||
<RootNamespace>DyeingComputer</RootNamespace> |
|||
<AssemblyName>DyeingComputer</AssemblyName> |
|||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|||
<WarningLevel>4</WarningLevel> |
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
|||
<Deterministic>true</Deterministic> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<PlatformTarget>AnyCPU</PlatformTarget> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<PlatformTarget>AnyCPU</PlatformTarget> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Data" /> |
|||
<Reference Include="System.Management" /> |
|||
<Reference Include="System.Windows.Forms" /> |
|||
<Reference Include="System.Xml" /> |
|||
<Reference Include="Microsoft.CSharp" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Xml.Linq" /> |
|||
<Reference Include="System.Data.DataSetExtensions" /> |
|||
<Reference Include="System.Net.Http" /> |
|||
<Reference Include="System.Xaml"> |
|||
<RequiredTargetFramework>4.0</RequiredTargetFramework> |
|||
</Reference> |
|||
<Reference Include="WindowsBase" /> |
|||
<Reference Include="PresentationCore" /> |
|||
<Reference Include="PresentationFramework" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ApplicationDefinition Include="App.xaml"> |
|||
<Generator>MSBuild:Compile</Generator> |
|||
<SubType>Designer</SubType> |
|||
</ApplicationDefinition> |
|||
<Compile Include="UserClass\CRCcheck16.cs" /> |
|||
<Compile Include="UserClass\DataGridHelper.cs" /> |
|||
<Compile Include="UserClass\DataTableForToObservableCollection.cs" /> |
|||
<Compile Include="UserClass\get_local_ip_address.cs" /> |
|||
<Compile Include="UserClass\HardwareSN.cs" /> |
|||
<Compile Include="UserClass\IniFile.cs" /> |
|||
<Compile Include="UserClass\LogDataRead.cs" /> |
|||
<Compile Include="UserClass\LogGing.cs" /> |
|||
<Compile Include="UserClass\MD5check.cs" /> |
|||
<Compile Include="UserClass\PressKey.cs" /> |
|||
<Compile Include="UserClass\StrToInt.cs" /> |
|||
<Compile Include="UserClass\TCPServer.cs" /> |
|||
<Page Include="MainWindow.xaml"> |
|||
<Generator>MSBuild:Compile</Generator> |
|||
<SubType>Designer</SubType> |
|||
</Page> |
|||
<Compile Include="App.xaml.cs"> |
|||
<DependentUpon>App.xaml</DependentUpon> |
|||
<SubType>Code</SubType> |
|||
</Compile> |
|||
<Compile Include="MainWindow.xaml.cs"> |
|||
<DependentUpon>MainWindow.xaml</DependentUpon> |
|||
<SubType>Code</SubType> |
|||
</Compile> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="Properties\AssemblyInfo.cs"> |
|||
<SubType>Code</SubType> |
|||
</Compile> |
|||
<Compile Include="Properties\Resources.Designer.cs"> |
|||
<AutoGen>True</AutoGen> |
|||
<DesignTime>True</DesignTime> |
|||
<DependentUpon>Resources.resx</DependentUpon> |
|||
</Compile> |
|||
<Compile Include="Properties\Settings.Designer.cs"> |
|||
<AutoGen>True</AutoGen> |
|||
<DependentUpon>Settings.settings</DependentUpon> |
|||
<DesignTimeSharedInput>True</DesignTimeSharedInput> |
|||
</Compile> |
|||
<EmbeddedResource Include="Properties\Resources.resx"> |
|||
<Generator>ResXFileCodeGenerator</Generator> |
|||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> |
|||
</EmbeddedResource> |
|||
<None Include="Properties\Settings.settings"> |
|||
<Generator>SettingsSingleFileGenerator</Generator> |
|||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> |
|||
</None> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="App.config" /> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
</Project> |
@ -0,0 +1,25 @@ |
|||
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00 |
|||
# Visual Studio Version 17 |
|||
VisualStudioVersion = 17.10.35122.118 |
|||
MinimumVisualStudioVersion = 10.0.40219.1 |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DyeingComputer", "DyeingComputer.csproj", "{18FD96BD-D3DD-46DA-BE92-CA942F27D4DD}" |
|||
EndProject |
|||
Global |
|||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|||
Debug|Any CPU = Debug|Any CPU |
|||
Release|Any CPU = Release|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|||
{18FD96BD-D3DD-46DA-BE92-CA942F27D4DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{18FD96BD-D3DD-46DA-BE92-CA942F27D4DD}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{18FD96BD-D3DD-46DA-BE92-CA942F27D4DD}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{18FD96BD-D3DD-46DA-BE92-CA942F27D4DD}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(SolutionProperties) = preSolution |
|||
HideSolutionNode = FALSE |
|||
EndGlobalSection |
|||
GlobalSection(ExtensibilityGlobals) = postSolution |
|||
SolutionGuid = {23C27729-172E-4ACB-8978-76C890F41C29} |
|||
EndGlobalSection |
|||
EndGlobal |
@ -0,0 +1,12 @@ |
|||
<Window x:Class="DyeingComputer.MainWindow" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
xmlns:local="clr-namespace:DyeingComputer" |
|||
mc:Ignorable="d" |
|||
Title="SUNLIGHT 838 b0.0.1 (2024/08/10)" Height="450" Width="800"> |
|||
<Grid> |
|||
|
|||
</Grid> |
|||
</Window> |
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using System.Windows; |
|||
using System.Windows.Controls; |
|||
using System.Windows.Data; |
|||
using System.Windows.Documents; |
|||
using System.Windows.Input; |
|||
using System.Windows.Media; |
|||
using System.Windows.Media.Imaging; |
|||
using System.Windows.Navigation; |
|||
using System.Windows.Shapes; |
|||
|
|||
namespace DyeingComputer |
|||
{ |
|||
/// <summary>
|
|||
/// MainWindow.xaml 的交互逻辑
|
|||
/// </summary>
|
|||
public partial class MainWindow : Window |
|||
{ |
|||
public MainWindow() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,55 @@ |
|||
using System.Reflection; |
|||
using System.Resources; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
using System.Windows; |
|||
|
|||
// 有关程序集的一般信息由以下
|
|||
// 控制。更改这些特性值可修改
|
|||
// 与程序集关联的信息。
|
|||
[assembly: AssemblyTitle("DyeingComputer")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("DyeingComputer")] |
|||
[assembly: AssemblyCopyright("Copyright © 2024")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
|
|||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
|||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
|||
//请将此类型的 ComVisible 特性设置为 true。
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
//若要开始生成可本地化的应用程序,请设置
|
|||
//.csproj 文件中的 <UICulture>CultureYouAreCodingWith</UICulture>
|
|||
//在 <PropertyGroup> 中。例如,如果你使用的是美国英语。
|
|||
//使用的是美国英语,请将 <UICulture> 设置为 en-US。 然后取消
|
|||
//对以下 NeutralResourceLanguage 特性的注释。 更新
|
|||
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
|
|||
|
|||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
|||
|
|||
|
|||
[assembly: ThemeInfo( |
|||
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
|
|||
//(未在页面中找到资源时使用,
|
|||
//或应用程序资源字典中找到时使用)
|
|||
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
|
|||
//(未在页面中找到资源时使用,
|
|||
//、应用程序或任何主题专用资源字典中找到时使用)
|
|||
)] |
|||
|
|||
|
|||
// 程序集的版本信息由下列四个值组成:
|
|||
//
|
|||
// 主版本
|
|||
// 次版本
|
|||
// 生成号
|
|||
// 修订号
|
|||
//
|
|||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
|||
//通过使用 "*",如下所示:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
@ -0,0 +1,71 @@ |
|||
//------------------------------------------------------------------------------
|
|||
// <auto-generated>
|
|||
// 此代码由工具生成。
|
|||
// 运行时版本: 4.0.30319.42000
|
|||
//
|
|||
// 对此文件的更改可能导致不正确的行为,如果
|
|||
// 重新生成代码,则所做更改将丢失。
|
|||
// </auto-generated>
|
|||
//------------------------------------------------------------------------------
|
|||
|
|||
namespace DyeingComputer.Properties |
|||
{ |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 强类型资源类,用于查找本地化字符串等。
|
|||
/// </summary>
|
|||
// 此类是由 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() |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 返回此类使用的缓存 ResourceManager 实例。
|
|||
/// </summary>
|
|||
[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("DyeingComputer.Properties.Resources", typeof(Resources).Assembly); |
|||
resourceMan = temp; |
|||
} |
|||
return resourceMan; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 重写当前线程的 CurrentUICulture 属性,对
|
|||
/// 使用此强类型资源类的所有资源查找执行重写。
|
|||
/// </summary>
|
|||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] |
|||
internal static global::System.Globalization.CultureInfo Culture |
|||
{ |
|||
get |
|||
{ |
|||
return resourceCulture; |
|||
} |
|||
set |
|||
{ |
|||
resourceCulture = value; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,117 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<root> |
|||
<!-- |
|||
Microsoft ResX Schema |
|||
|
|||
Version 2.0 |
|||
|
|||
The primary goals of this format is to allow a simple XML format |
|||
that is mostly human readable. The generation and parsing of the |
|||
various data types are done through the TypeConverter classes |
|||
associated with the data types. |
|||
|
|||
Example: |
|||
|
|||
... ado.net/XML headers & schema ... |
|||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
|||
<resheader name="version">2.0</resheader> |
|||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
|||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
|||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
|||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
|||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
|||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
|||
</data> |
|||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
|||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
|||
<comment>This is a comment</comment> |
|||
</data> |
|||
|
|||
There are any number of "resheader" rows that contain simple |
|||
name/value pairs. |
|||
|
|||
Each data row contains a name, and value. The row also contains a |
|||
type or mimetype. Type corresponds to a .NET class that support |
|||
text/value conversion through the TypeConverter architecture. |
|||
Classes that don't support this are serialized and stored with the |
|||
mimetype set. |
|||
|
|||
The mimetype is used for serialized objects, and tells the |
|||
ResXResourceReader how to depersist the object. This is currently not |
|||
extensible. For a given mimetype the value must be set accordingly: |
|||
|
|||
Note - application/x-microsoft.net.object.binary.base64 is the format |
|||
that the ResXResourceWriter will generate, however the reader can |
|||
read any of the formats listed below. |
|||
|
|||
mimetype: application/x-microsoft.net.object.binary.base64 |
|||
value : The object must be serialized with |
|||
: System.Serialization.Formatters.Binary.BinaryFormatter |
|||
: and then encoded with base64 encoding. |
|||
|
|||
mimetype: application/x-microsoft.net.object.soap.base64 |
|||
value : The object must be serialized with |
|||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
|||
: and then encoded with base64 encoding. |
|||
|
|||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
|||
value : The object must be serialized into a byte array |
|||
: using a System.ComponentModel.TypeConverter |
|||
: and then encoded with base64 encoding. |
|||
--> |
|||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
|||
<xsd:element name="root" msdata:IsDataSet="true"> |
|||
<xsd:complexType> |
|||
<xsd:choice maxOccurs="unbounded"> |
|||
<xsd:element name="metadata"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" type="xsd:string" /> |
|||
<xsd:attribute name="type" type="xsd:string" /> |
|||
<xsd:attribute name="mimetype" type="xsd:string" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="assembly"> |
|||
<xsd:complexType> |
|||
<xsd:attribute name="alias" type="xsd:string" /> |
|||
<xsd:attribute name="name" type="xsd:string" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="data"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
|||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" /> |
|||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
|||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
<xsd:element name="resheader"> |
|||
<xsd:complexType> |
|||
<xsd:sequence> |
|||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
|||
</xsd:sequence> |
|||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
</xsd:choice> |
|||
</xsd:complexType> |
|||
</xsd:element> |
|||
</xsd:schema> |
|||
<resheader name="resmimetype"> |
|||
<value>text/microsoft-resx</value> |
|||
</resheader> |
|||
<resheader name="version"> |
|||
<value>2.0</value> |
|||
</resheader> |
|||
<resheader name="reader"> |
|||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
|||
</resheader> |
|||
<resheader name="writer"> |
|||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
|||
</resheader> |
|||
</root> |
@ -0,0 +1,30 @@ |
|||
//------------------------------------------------------------------------------
|
|||
// <auto-generated>
|
|||
// 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.
|
|||
// </auto-generated>
|
|||
//------------------------------------------------------------------------------
|
|||
|
|||
namespace DyeingComputer.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; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,7 @@ |
|||
<?xml version='1.0' encoding='utf-8'?> |
|||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)"> |
|||
<Profiles> |
|||
<Profile Name="(Default)" /> |
|||
</Profiles> |
|||
<Settings /> |
|||
</SettingsFile> |
@ -0,0 +1,190 @@ |
|||
using System; |
|||
using System.Text; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
/// <summary>
|
|||
/// CRC校验
|
|||
/// </summary>
|
|||
public class CRCcheck16 |
|||
{ |
|||
|
|||
#region CRC16
|
|||
public static byte[] CRC16(byte[] data) |
|||
{ |
|||
int len = data.Length; |
|||
if (len > 0) |
|||
{ |
|||
ushort crc = 0xFFFF; |
|||
|
|||
for (int i = 0; i < len; i++) |
|||
{ |
|||
crc = (ushort)(crc ^ (data[i])); |
|||
for (int j = 0; j < 8; j++) |
|||
{ |
|||
crc = (crc & 1) != 0 ? (ushort)((crc >> 1) ^ 0xA001) : (ushort)(crc >> 1); |
|||
} |
|||
} |
|||
byte hi = (byte)((crc & 0xFF00) >> 8); //高位置
|
|||
byte lo = (byte)(crc & 0x00FF); //低位置
|
|||
|
|||
return new byte[] { hi, lo }; |
|||
} |
|||
return new byte[] { 0, 0 }; |
|||
} |
|||
#endregion
|
|||
|
|||
#region ToCRC16
|
|||
public static string ToCRC16(string content) |
|||
{ |
|||
return ToCRC16(content, Encoding.UTF8); |
|||
} |
|||
|
|||
public static string ToCRC16(string content, bool isReverse) |
|||
{ |
|||
return ToCRC16(content, Encoding.UTF8, isReverse); |
|||
} |
|||
|
|||
public static string ToCRC16(string content, Encoding encoding) |
|||
{ |
|||
return ByteToString(CRC16(encoding.GetBytes(content)), true); |
|||
} |
|||
|
|||
public static string ToCRC16(string content, Encoding encoding, bool isReverse) |
|||
{ |
|||
return ByteToString(CRC16(encoding.GetBytes(content)), isReverse); |
|||
} |
|||
|
|||
public static string ToCRC16(byte[] data) |
|||
{ |
|||
return ByteToString(CRC16(data), true); |
|||
} |
|||
|
|||
public static string ToCRC16(byte[] data, bool isReverse) |
|||
{ |
|||
return ByteToString(CRC16(data), isReverse); |
|||
} |
|||
#endregion
|
|||
|
|||
#region ToModbusCRC16
|
|||
public static string ToModbusCRC16(string s) |
|||
{ |
|||
return ToModbusCRC16(s, true); |
|||
} |
|||
|
|||
public static string ToModbusCRC16(string s, bool isReverse) |
|||
{ |
|||
return ByteToString(CRC16(StringToHexByte(s)), isReverse); |
|||
} |
|||
|
|||
public static string ToModbusCRC16(byte[] data) |
|||
{ |
|||
return ToModbusCRC16(data, true); |
|||
} |
|||
|
|||
public static string ToModbusCRC16(byte[] data, bool isReverse) |
|||
{ |
|||
return ByteToString(CRC16(data), isReverse); |
|||
} |
|||
#endregion
|
|||
|
|||
#region ByteToString
|
|||
public static string ByteToString(byte[] arr, bool isReverse) |
|||
{ |
|||
try |
|||
{ |
|||
byte hi = arr[0], lo = arr[1]; |
|||
return Convert.ToString(isReverse ? hi + lo * 0x100 : hi * 0x100 + lo, 16).ToUpper().PadLeft(4, '0'); |
|||
} |
|||
catch (Exception ex) { throw (ex); } |
|||
} |
|||
|
|||
public static string ByteToString(byte[] arr) |
|||
{ |
|||
try |
|||
{ |
|||
return ByteToString(arr, true); |
|||
} |
|||
catch (Exception ex) { throw (ex); } |
|||
} |
|||
#endregion
|
|||
|
|||
#region StringToHexString
|
|||
public static string StringToHexString(string str) |
|||
{ |
|||
StringBuilder s = new StringBuilder(); |
|||
foreach (short c in str.ToCharArray()) |
|||
{ |
|||
s.Append(c.ToString("X4")); |
|||
} |
|||
return s.ToString(); |
|||
} |
|||
#endregion
|
|||
|
|||
#region StringToHexByte
|
|||
private static string ConvertChinese(string str) |
|||
{ |
|||
StringBuilder s = new StringBuilder(); |
|||
foreach (short c in str.ToCharArray()) |
|||
{ |
|||
if (c <= 0 || c >= 127) |
|||
{ |
|||
s.Append(c.ToString("X4")); |
|||
} |
|||
else |
|||
{ |
|||
s.Append((char)c); |
|||
} |
|||
} |
|||
return s.ToString(); |
|||
} |
|||
|
|||
private static string FilterChinese(string str) |
|||
{ |
|||
StringBuilder s = new StringBuilder(); |
|||
foreach (short c in str.ToCharArray()) |
|||
{ |
|||
if (c > 0 && c < 127) |
|||
{ |
|||
s.Append((char)c); |
|||
} |
|||
} |
|||
return s.ToString(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 字符串转16进制字符数组
|
|||
/// </summary>
|
|||
/// <param name="hex"></param>
|
|||
/// <returns></returns>
|
|||
public static byte[] StringToHexByte(string str) |
|||
{ |
|||
return StringToHexByte(str, false); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 字符串转16进制字符数组
|
|||
/// </summary>
|
|||
/// <param name="str"></param>
|
|||
/// <param name="isFilterChinese">是否过滤掉中文字符</param>
|
|||
/// <returns></returns>
|
|||
public static byte[] StringToHexByte(string str, bool isFilterChinese) |
|||
{ |
|||
string hex = isFilterChinese ? FilterChinese(str) : ConvertChinese(str); |
|||
|
|||
//清除所有空格
|
|||
hex = hex.Replace(" ", ""); |
|||
//若字符个数为奇数,补一个0
|
|||
hex += hex.Length % 2 != 0 ? "0" : ""; |
|||
|
|||
byte[] result = new byte[hex.Length / 2]; |
|||
for (int i = 0, c = result.Length; i < c; i++) |
|||
{ |
|||
result[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16); |
|||
} |
|||
return result; |
|||
} |
|||
#endregion
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
using System; |
|||
using System.Windows; |
|||
using System.Windows.Controls; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
/// <summary>
|
|||
/// 实时更新datagrid
|
|||
/// 调用示例:DataGridHelper.SetRealTimeCommit(Grid, true); Grid为对象控件名
|
|||
/// </summary>
|
|||
public static class DataGridHelper |
|||
{ |
|||
public static void SetRealTimeCommit(DataGrid dataGrid, bool isRealTime) |
|||
{ |
|||
dataGrid.SetValue(RealTimeCommitProperty, isRealTime); |
|||
} |
|||
|
|||
public static bool GetRealTimeCommit(DataGrid dataGrid) |
|||
{ |
|||
return (bool)dataGrid.GetValue(RealTimeCommitProperty); |
|||
} |
|||
|
|||
public static readonly DependencyProperty RealTimeCommitProperty = |
|||
DependencyProperty.RegisterAttached("RealTimeCommit", typeof(bool), |
|||
typeof(DataGridHelper), |
|||
new PropertyMetadata(false, RealTimeCommitCallBack)); |
|||
|
|||
private static void RealTimeCommitCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e) |
|||
{ |
|||
var dg = d as DataGrid; |
|||
if (dg == null) |
|||
return; |
|||
EventHandler<DataGridCellEditEndingEventArgs> ceHandler = delegate (object xx, DataGridCellEditEndingEventArgs yy) |
|||
{ |
|||
var flag = GetRealTimeCommit(dg); |
|||
if (!flag) |
|||
return; |
|||
var cellContent = yy.Column.GetCellContent(yy.Row); |
|||
if (cellContent != null && cellContent.BindingGroup != null) |
|||
cellContent.BindingGroup.CommitEdit(); |
|||
}; |
|||
dg.CellEditEnding += ceHandler; |
|||
RoutedEventHandler eh = null; |
|||
eh = (xx, yy) => |
|||
{ |
|||
dg.Unloaded -= eh; |
|||
dg.CellEditEnding -= ceHandler; |
|||
}; |
|||
dg.Unloaded += eh; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,59 @@ |
|||
using System; |
|||
using System.Collections.ObjectModel; |
|||
using System.Data; |
|||
using System.Reflection; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
internal class DataTableToObservableCollection //数据表到可观察集合
|
|||
{ |
|||
public ObservableCollection<T> ToObservableCollection<T>(DataTable dt) where T : class, new() |
|||
{ |
|||
Type t = typeof(T); |
|||
PropertyInfo[] propertys = t.GetProperties(); |
|||
ObservableCollection<T> lst = new ObservableCollection<T>(); |
|||
string typeName = string.Empty; |
|||
foreach (DataRow dr in dt.Rows) |
|||
{ |
|||
T entity = new T(); |
|||
foreach (PropertyInfo pi in propertys) |
|||
{ |
|||
typeName = pi.Name; |
|||
if (dt.Columns.Contains(typeName)) |
|||
{ |
|||
if (!pi.CanWrite) continue; |
|||
object value = dr[typeName]; |
|||
if (value == DBNull.Value) continue; |
|||
if (pi.PropertyType == typeof(string)) |
|||
{ |
|||
pi.SetValue(entity, value.ToString(), null); |
|||
} |
|||
else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(int?)) |
|||
{ |
|||
pi.SetValue(entity, int.Parse(value.ToString()), null); |
|||
} |
|||
else if (pi.PropertyType == typeof(DateTime?) || pi.PropertyType == typeof(DateTime)) |
|||
{ |
|||
pi.SetValue(entity, DateTime.Parse(value.ToString()), null); |
|||
} |
|||
else if (pi.PropertyType == typeof(float)) |
|||
{ |
|||
pi.SetValue(entity, float.Parse(value.ToString()), null); |
|||
} |
|||
else if (pi.PropertyType == typeof(double)) |
|||
{ |
|||
pi.SetValue(entity, double.Parse(value.ToString()), null); |
|||
} |
|||
else |
|||
{ |
|||
pi.SetValue(entity, value, null); |
|||
} |
|||
} |
|||
} |
|||
lst.Add(entity); |
|||
} |
|||
return lst; |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,95 @@ |
|||
using System.Management; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
/// <summary>
|
|||
/// 获取硬件SN
|
|||
/// </summary>
|
|||
internal class HardwareSN |
|||
{ |
|||
/// <summary>
|
|||
/// 获取cpuid
|
|||
/// </summary>
|
|||
public static string GetCPUSerialNumber() |
|||
{ |
|||
try |
|||
{ |
|||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor"); |
|||
string cpuSerialNumber = ""; |
|||
foreach (ManagementObject mo in searcher.Get()) |
|||
{ |
|||
cpuSerialNumber = mo["ProcessorId"].ToString().Trim(); |
|||
break; |
|||
} |
|||
return cpuSerialNumber; |
|||
} |
|||
catch |
|||
{ |
|||
return ""; |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 获取主板id
|
|||
/// </summary>
|
|||
public static string GetBIOSSerialNumber() |
|||
{ |
|||
try |
|||
{ |
|||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS"); |
|||
string biosSerialNumber = ""; |
|||
foreach (ManagementObject mo in searcher.Get()) |
|||
{ |
|||
biosSerialNumber = mo.GetPropertyValue("SerialNumber").ToString().Trim(); |
|||
break; |
|||
} |
|||
return biosSerialNumber; |
|||
} |
|||
catch |
|||
{ |
|||
return ""; |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 获取硬盘id
|
|||
/// </summary>
|
|||
public static string GetHardDiskSerialNumber() |
|||
{ |
|||
try |
|||
{ |
|||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia"); |
|||
string hardDiskSerialNumber = ""; |
|||
foreach (ManagementObject mo in searcher.Get()) |
|||
{ |
|||
hardDiskSerialNumber = mo["SerialNumber"].ToString().Trim(); |
|||
break; |
|||
} |
|||
return hardDiskSerialNumber; |
|||
} |
|||
catch |
|||
{ |
|||
return ""; |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 获取网卡id
|
|||
/// </summary>
|
|||
public static string GetNetCardMACAddress() |
|||
{ |
|||
try |
|||
{ |
|||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL) AND (Manufacturer <> 'Microsoft'))"); |
|||
string netCardMACAddress = ""; |
|||
foreach (ManagementObject mo in searcher.Get()) |
|||
{ |
|||
netCardMACAddress = mo["MACAddress"].ToString().Trim(); |
|||
break; |
|||
} |
|||
return netCardMACAddress; |
|||
} |
|||
catch |
|||
{ |
|||
return ""; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,52 @@ |
|||
using System.Runtime.InteropServices; |
|||
using System.Text; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
internal class IniFile |
|||
{ |
|||
public class IniFiles |
|||
{ |
|||
public string path; |
|||
[DllImport("kernel32")] //返回0表示失败,非0为成功
|
|||
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); |
|||
[DllImport("kernel32")] //返回取得字符串缓冲区的长度
|
|||
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); |
|||
/// <summary>
|
|||
/// 保存ini文件的路径
|
|||
/// 调用示例:var ini = IniFiles("C:\file.ini");
|
|||
/// </summary>
|
|||
/// <param name="INIPath"></param>
|
|||
public IniFiles(string iniPath) |
|||
{ |
|||
this.path = iniPath; |
|||
} |
|||
/// <summary>
|
|||
/// 写Ini文件
|
|||
/// 调用示例:ini.IniWritevalue("Server","name","localhost");
|
|||
/// </summary>
|
|||
/// <param name="Section">[缓冲区]</param>
|
|||
/// <param name="Key">键</param>
|
|||
/// <param name="value">值</param>
|
|||
public void IniWritevalue(string Section, string Key, string value) |
|||
{ |
|||
WritePrivateProfileString(Section, Key, value, this.path); |
|||
} |
|||
/// <summary>
|
|||
/// 读Ini文件
|
|||
/// 调用示例:ini.IniWritevalue("Server","name");
|
|||
/// </summary>
|
|||
/// <param name="Section">[缓冲区]</param>
|
|||
/// <param name="Key">键</param>
|
|||
/// <returns>值</returns>
|
|||
public string IniReadvalue(string Section, string Key) |
|||
{ |
|||
StringBuilder temp = new StringBuilder(255); |
|||
|
|||
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path); |
|||
return temp.ToString(); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,76 @@ |
|||
using System.Text; |
|||
using System.Windows.Controls; |
|||
using System.Windows.Documents; |
|||
using System.Windows.Media; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
public static class LogDataRead |
|||
{ |
|||
private const int MaxCount = 1000; |
|||
private static int Count = 0; |
|||
private static RichTextBox textControl; |
|||
private static InlineCollection inlines; |
|||
|
|||
//设置主控件
|
|||
public static void SetTextControl(RichTextBox _textBox) |
|||
{ |
|||
textControl = _textBox; |
|||
Paragraph graph = new Paragraph(); |
|||
inlines = graph.Inlines; |
|||
textControl.Document.Blocks.Add(graph); |
|||
} |
|||
|
|||
//输出黑色消息
|
|||
public static void Info(string format, params object[] args) |
|||
{ |
|||
AppendText(Brushes.Black, format, args); |
|||
} |
|||
|
|||
//输出绿色消息
|
|||
public static void Suc(string format, params object[] args) |
|||
{ |
|||
AppendText(Brushes.DarkGreen, format, args); |
|||
} |
|||
|
|||
//输出黄色消息
|
|||
public static void Warning(string format, params object[] args) |
|||
{ |
|||
AppendText(Brushes.DarkOrange, format, args); |
|||
} |
|||
|
|||
//输出红色消息
|
|||
public static void Error(string format, params object[] args) |
|||
{ |
|||
AppendText(Brushes.Red, format, args); |
|||
} |
|||
|
|||
//清除日志
|
|||
public static void Clear() |
|||
{ |
|||
Count = 0; |
|||
inlines.Clear(); |
|||
textControl.ScrollToEnd(); |
|||
} |
|||
|
|||
private static void AppendText(Brush color, string format, params object[] args) |
|||
{ |
|||
textControl.BeginChange(); |
|||
StringBuilder builder = new StringBuilder(); |
|||
builder.Append("["); |
|||
builder.Append(Count++); |
|||
builder.Append("] : "); |
|||
builder.Append(string.Format(format, (object[])args)); |
|||
builder.Append("\n"); |
|||
string str = builder.ToString(); |
|||
inlines.Add(new Run(str) { Foreground = color }); |
|||
if (inlines.Count > MaxCount) |
|||
{ |
|||
inlines.Remove(inlines.FirstInline); |
|||
} |
|||
textControl.ScrollToEnd(); |
|||
textControl.EndChange(); |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
using System; |
|||
using System.IO; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
public class LogGing |
|||
{ |
|||
public static void LogGingDATA(string dat) |
|||
{ |
|||
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
|
|||
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";//日志文件
|
|||
string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:"; |
|||
|
|||
if (Directory.Exists(logpath))//检查日志路径
|
|||
{ |
|||
if (!File.Exists(logPath))//检查日志文件并写入启动日志
|
|||
{ |
|||
FileStream fs = new FileStream(logPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
|||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
|||
wr.WriteLine(Log_time + dat); |
|||
wr.Close(); |
|||
} |
|||
else |
|||
{ |
|||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); |
|||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
|||
wr.WriteLine(Log_time + dat); |
|||
wr.Close(); } |
|||
} |
|||
else |
|||
{ |
|||
DirectoryInfo directoryInfo = new DirectoryInfo(logpath); |
|||
directoryInfo.Create();//创建日志路径
|
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,59 @@ |
|||
using System; |
|||
using System.Security.Cryptography; |
|||
using System.Text; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
/// <summary>
|
|||
/// MD5加密
|
|||
/// </summary>
|
|||
internal class MD5check |
|||
{ |
|||
/// <summary>
|
|||
/// 16位MD5加密
|
|||
/// </summary>
|
|||
/// <param name="password"></param>
|
|||
/// <returns></returns>
|
|||
public static string MD5Encrypt16(string password) |
|||
{ |
|||
var md5 = new MD5CryptoServiceProvider(); |
|||
string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(password)), 4, 8); |
|||
t2 = t2.Replace("-", ""); |
|||
return t2; |
|||
} |
|||
/// <summary>
|
|||
/// 32位MD5加密
|
|||
/// </summary>
|
|||
/// <param name="password"></param>
|
|||
/// <returns></returns>
|
|||
public static string MD5Encrypt32(string password) |
|||
{ |
|||
string cl = password; |
|||
string pwd = ""; |
|||
MD5 md5 = MD5.Create(); //实例化一个md5对像
|
|||
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
|||
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); |
|||
// 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
|
|||
for (int i = 0; i < s.Length; i++) |
|||
{ |
|||
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
|
|||
pwd = pwd + s[i].ToString("X"); |
|||
} |
|||
return pwd; |
|||
} |
|||
/// <summary>
|
|||
/// 64位MD5加密
|
|||
/// </summary>
|
|||
/// <param name="password"></param>
|
|||
/// <returns></returns>
|
|||
public static string MD5Encrypt64(string password) |
|||
{ |
|||
string cl = password; |
|||
//string pwd = "";
|
|||
MD5 md5 = MD5.Create(); //实例化一个md5对像
|
|||
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
|||
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); |
|||
return Convert.ToBase64String(s); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using System.Runtime.InteropServices; |
|||
using System.Windows.Forms; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
internal class PressKey |
|||
{ |
|||
/// <summary>
|
|||
/// 键盘模拟
|
|||
/// </summary>
|
|||
[DllImport("user32.dll", SetLastError = true)] |
|||
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); |
|||
public static void PressKeys(Keys key, bool up) |
|||
{ |
|||
const int KEYEVENTF_EXTENDEDKEY = 0x1; |
|||
const int KEYEVENTF_KEYUP = 0x2; |
|||
if (up) |
|||
{ |
|||
keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0); |
|||
} |
|||
else |
|||
{ |
|||
keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
using System; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
/// <summary>
|
|||
/// 字符串转数字
|
|||
/// </summary>
|
|||
internal class StrToInt |
|||
{ |
|||
/// <summary>
|
|||
/// 十六进制字符串转十进制
|
|||
/// </summary>
|
|||
/// <param name="str">十六进制字符</param>
|
|||
/// <returns></returns>
|
|||
public static int To16Convert10(string str) |
|||
{ |
|||
int res = 0; |
|||
try |
|||
{ |
|||
str = str.Trim().Replace(" ", ""); //移除空字符
|
|||
//方法1
|
|||
res = int.Parse(str, System.Globalization.NumberStyles.AllowHexSpecifier); |
|||
//方法2
|
|||
//int r2 = System.Int32.Parse(str, System.Globalization.NumberStyles.HexNumber);
|
|||
//Console.WriteLine(r2);
|
|||
//方法3
|
|||
//int r3 = Convert.ToInt32(str, 16);
|
|||
//Console.WriteLine(r3);
|
|||
} |
|||
catch (Exception) |
|||
{ |
|||
res = 0; |
|||
} |
|||
return res; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,186 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Linq; |
|||
using System.Net; |
|||
using System.Net.Sockets; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
public class TCPServer |
|||
{ |
|||
public static string infoR; |
|||
//第一步:调用socket()函数创建一个用于通信的套接字
|
|||
public static Socket listenSocket; |
|||
|
|||
//字典集合:存储IP和Socket的集合
|
|||
public static Dictionary<string, Socket> OnLineList = new Dictionary<string, Socket>(); |
|||
|
|||
|
|||
//当前时间
|
|||
private string CurrentTime |
|||
{ |
|||
get { return DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine; } |
|||
} |
|||
|
|||
//编码格式
|
|||
public static Encoding econding = Encoding.UTF8; |
|||
|
|||
public static void Start() |
|||
{ |
|||
//第一步:调用socket()函数创建一个用于通信的套接字
|
|||
listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
|||
//第二步:给已经创建的套接字绑定一个端口号,这一般通过设置网络套接口地址和调用Bind()函数来实现
|
|||
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(UserClass.get_local_ip_address.IP_Address()), int.Parse("11080")); |
|||
UserClass.LogGing.LogGingDATA("NativeIP = " + UserClass.get_local_ip_address.IP_Address()); |
|||
UserClass.LogGing.LogGingDATA("NativePORT = 11080"); |
|||
try |
|||
{ |
|||
listenSocket.Bind(endPoint); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
UserClass.LogGing.LogGingDATA("TCP_NotStart"); |
|||
UserClass.LogGing.LogGingDATA(ex.Message); |
|||
return; |
|||
} |
|||
//第三步:调用listen()函数使套接字成为一个监听套接字
|
|||
listenSocket.Listen(10); |
|||
//ShowMessage("服务器开启成功");
|
|||
|
|||
//开启一个线程监听
|
|||
Task.Run(new Action(() => { ListenConnection(); })); |
|||
} |
|||
|
|||
public static void ListenConnection() |
|||
{ |
|||
while (true) |
|||
{ |
|||
Socket clientSocket = listenSocket.Accept(); |
|||
string ip = clientSocket.RemoteEndPoint.ToString(); |
|||
//更新在线列表
|
|||
// AddOnLine(ip, true);
|
|||
//更新在线列表集合
|
|||
OnLineList.Add(ip, clientSocket); |
|||
UserClass.LogGing.LogGingDATA("IP_Online = " + ip); |
|||
// ShowMessage(ip + "上线了");
|
|||
Task.Run(() => ReceiveMsg(clientSocket)); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 接收方法
|
|||
/// </summary>
|
|||
/// <param name="clientSocket"></param>
|
|||
public static void ReceiveMsg(Socket clientSocket) |
|||
{ |
|||
while (true) |
|||
{ |
|||
//定义一个2M的缓冲区
|
|||
byte[] buffer = new byte[1024 * 1024 * 10]; |
|||
|
|||
int length = -1; |
|||
try |
|||
{ |
|||
length = clientSocket.Receive(buffer); |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
//客户端下线了
|
|||
//更新在线列表
|
|||
string ip = clientSocket.RemoteEndPoint.ToString(); |
|||
UserClass.LogGing.LogGingDATA("IP_Line = " + ip); |
|||
// AddOnLine(ip, false);
|
|||
OnLineList.Remove(ip); //移除ip
|
|||
break; //退出循环
|
|||
} |
|||
|
|||
if (length == 0) |
|||
{ |
|||
//客户端下线了
|
|||
//更新在线列表
|
|||
string ip = clientSocket.RemoteEndPoint.ToString(); |
|||
UserClass.LogGing.LogGingDATA("IP_Line = " + ip); |
|||
// AddOnLine(ip, false);
|
|||
OnLineList.Remove(ip); |
|||
break; |
|||
} |
|||
else |
|||
{ |
|||
infoR = econding.GetString(buffer, 0, length); |
|||
//ShowMessage(info);
|
|||
string ip = clientSocket.RemoteEndPoint.ToString(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
/* |
|||
/// <summary>
|
|||
/// 在线列表更新
|
|||
/// </summary>
|
|||
/// <param name="clientIp"></param>
|
|||
/// <param name="value"></param>
|
|||
private void AddOnLine(string clientIp, bool value) |
|||
{ |
|||
Invoke(new Action(() => |
|||
{ |
|||
if (value) |
|||
{ |
|||
this.lst_Online.Items.Add(clientIp); |
|||
} |
|||
else |
|||
{ |
|||
this.lst_Online.Items.Remove(clientIp); |
|||
} |
|||
|
|||
})); |
|||
|
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 更新接收区
|
|||
/// </summary>
|
|||
/// <param name="info"></param>
|
|||
private void ShowMessage(string info) |
|||
{ |
|||
Invoke(new Action(() => |
|||
{ |
|||
this.txt_Rcv.AppendText(CurrentTime + info + Environment.NewLine); |
|||
})); |
|||
|
|||
} |
|||
|
|||
*/ |
|||
/// <summary>
|
|||
/// 消息发送
|
|||
/// </summary>
|
|||
public static void Bn_Send(string IP, string DAT) |
|||
{ |
|||
if (OnLineList.ContainsKey(IP)) |
|||
{ |
|||
OnLineList[IP].Send(econding.GetBytes(DAT)); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 群发功能
|
|||
/// </summary>
|
|||
public static void Btn_SendAll(string DAT) |
|||
{ |
|||
foreach (string item in OnLineList.Keys.ToArray()) |
|||
{ |
|||
if (OnLineList.ContainsKey(item)) |
|||
{ |
|||
OnLineList[item].Send(econding.GetBytes(DAT)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
|
@ -0,0 +1,46 @@ |
|||
using System.Net.NetworkInformation; |
|||
using System.Net.Sockets; |
|||
|
|||
namespace formula_manage.UserClass |
|||
{ |
|||
public class get_local_ip_address |
|||
{ |
|||
public static string getLocalIPAddressWithNetworkInterface(NetworkInterfaceType _type)//获取本机ip并以字符串方式返回
|
|||
{ |
|||
string output = ""; |
|||
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces()) |
|||
{ |
|||
if (item.NetworkInterfaceType == _type && item.OperationalStatus == OperationalStatus.Up) |
|||
{ |
|||
foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses) |
|||
{ |
|||
if (ip.Address.AddressFamily == AddressFamily.InterNetwork) |
|||
{ |
|||
output = ip.Address.ToString(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return output; |
|||
} |
|||
|
|||
public static string IP_Address() |
|||
{ |
|||
string ip; |
|||
|
|||
ip = getLocalIPAddressWithNetworkInterface(NetworkInterfaceType.Ethernet); |
|||
if (ip == "") ip = getLocalIPAddressWithNetworkInterface(NetworkInterfaceType.Wireless80211); |
|||
if (ip == "") ip = getLocalIPAddressWithNetworkInterface(NetworkInterfaceType.Ppp); |
|||
if (ip == "") ip = getLocalIPAddressWithNetworkInterface(NetworkInterfaceType.Wwanpp); |
|||
if (ip == "") ip = getLocalIPAddressWithNetworkInterface(NetworkInterfaceType.TokenRing); |
|||
if (ip == "") ip = getLocalIPAddressWithNetworkInterface(NetworkInterfaceType.Fddi); |
|||
if (ip == "") ip = getLocalIPAddressWithNetworkInterface(NetworkInterfaceType.GenericModem); |
|||
if (ip == "") ip = getLocalIPAddressWithNetworkInterface(NetworkInterfaceType.IPOverAtm); |
|||
if (ip == "") ip = getLocalIPAddressWithNetworkInterface(NetworkInterfaceType.Tunnel); |
|||
if (ip == "") ip = getLocalIPAddressWithNetworkInterface(NetworkInterfaceType.Unknown); |
|||
|
|||
if (ip == "") ip = "127.0.0.1"; |
|||
return ip; |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue