commit 322f16bb34c2d602d256f395be055f319b86c3ef Author: forget-the-bright Date: Thu Jul 6 11:34:16 2023 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca1c7a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,400 @@ +# ---> VisualStudio +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + diff --git a/DatabasetoEntityclass/App.config b/DatabasetoEntityclass/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/DatabasetoEntityclass/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DatabasetoEntityclass/Class1.cs b/DatabasetoEntityclass/Class1.cs new file mode 100644 index 0000000..674e89e --- /dev/null +++ b/DatabasetoEntityclass/Class1.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WindowsFormsApp1 +{ + internal class Class1 + { + + } +} diff --git a/DatabasetoEntityclass/DatabasetoEntityclass.csproj b/DatabasetoEntityclass/DatabasetoEntityclass.csproj new file mode 100644 index 0000000..a0425dd --- /dev/null +++ b/DatabasetoEntityclass/DatabasetoEntityclass.csproj @@ -0,0 +1,91 @@ + + + + + Debug + AnyCPU + {7D7B530A-23A4-4024-B263-A942AA53DCC5} + WinExe + WindowsFormsApp1 + WindowsFormsApp1 + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + D:\mes_db\NCA_MES_Models\CommonLibary\MySql.Data.dll + + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + \ No newline at end of file diff --git a/DatabasetoEntityclass/DbHelper.cs b/DatabasetoEntityclass/DbHelper.cs new file mode 100644 index 0000000..267be8d --- /dev/null +++ b/DatabasetoEntityclass/DbHelper.cs @@ -0,0 +1,1014 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MySql.Data.MySqlClient; +using System.Configuration; +using System.Xml; +using System.Text.RegularExpressions; + +namespace WindowsFormsApp1 +{ + public class DbHelperMySQL + { + /// + /// 数据访问抽象基础类 + /// Copyright (C) 2004-2008 By zzzili + /// + + //数据库连接字符串(web.config来配置),可以动态更改connectionString支持多数据库. + /// + /// 获取连接字符串 + /// + + public static string connectionString = "server=10.164.1.169;port=3306;user=root;password=3687988; database=mesdb_nca;";//GetConnectionStringFromXml("./SystemConfig.xml"); + + public static string DbName = getDbName();//"mesdb_nca"; + + public static string getDbName() { + // 使用正则表达式提取数据库名称 + string pattern = "database=([^;]+)"; + Match match = Regex.Match(connectionString, pattern); + if (match.Success) + { + string databaseName = match.Groups[1].Value; + //Console.WriteLine(databaseName); // 输出: mesdb_nca + return databaseName; + } + System.Windows.Forms.MessageBox.Show("获取数据库失败"); + return ""; + } + + private MySqlConnection connection; + + /// + /// DbHelperMySQL无参数构造函数 + /// + private DbHelperMySQL(MySqlConnection connection) + { + this.connection = connection; + } + + public static string GetConnectionStringFromXml(string xmlFilePath) + { + try + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(xmlFilePath); + XmlNodeList connectionNodes = xmlDoc.SelectNodes("//config"); + foreach (XmlNode configNode in connectionNodes) + { + string name = configNode.Attributes["name"].Value; + string ivalue = configNode.Attributes["ivalue"].Value; + if (name.Equals("ConnString")) return ivalue; + } + throw new Exception("No connection string found in the XML file."); + } + catch (Exception ex) + { + throw new Exception("Error reading XML file: " + ex.Message); + } + } + + #region 公用方法 + /// + /// 获取表中最大的Id值 + /// + /// 列名 + /// 表名 + /// + public static int GetMaxID(string FieldName, string TableName) + { + string strsql = "select max(" + FieldName + ")+1 from " + TableName; + object obj = GetSingle(strsql); + if (obj == null) + { + return 1; + } + else + { + return int.Parse(obj.ToString()); + } + } + /// + /// 返回查询是否存在 + /// + /// 要查询的Sql语句 + /// + public static bool Exists(string strSql) + { + object obj = GetSingle(strSql); + int cmdresult; + if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value))) + { + cmdresult = 0; + } + else + { + cmdresult = int.Parse(obj.ToString()); + } + if (cmdresult == 0) + { + return false; + } + else + { + return true; + } + } + /// + /// 返回查询是否存在 + /// + /// 查询语句 + /// 参数互列表 + /// + public static bool Exists(string strSql, params MySqlParameter[] cmdParms) + { + object obj = GetSingle(strSql, cmdParms); + int cmdresult; + if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value))) + { + cmdresult = 0; + } + else + { + cmdresult = int.Parse(obj.ToString()); + } + if (cmdresult == 0) + { + return false; + } + else + { + return true; + } + } + #endregion + + #region 执行简单SQL语句 + + /// + /// 返回新增加数据的Primary Key + /// + /// 要执行的INSERT SQL语句 + /// 表名 + /// 字段名 + /// + public static int ExecuteSqlReturnLastRowId(string SQLString, string TableName, string FieldName) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + using (MySqlCommand cmd = new MySqlCommand(SQLString, connection)) + { + try + { + connection.Open();//int rows = + cmd.ExecuteNonQuery(); + int a = GetMaxID(FieldName, TableName); + return a; + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + connection.Close(); + throw new Exception(e.Message); + } + } + } + } + + + /// + /// 执行SQL语句,返回影响的记录数 + /// + /// SQL语句 + /// 影响的记录数 + public static int ExecuteSql(string SQLString) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + using (MySqlCommand cmd = new MySqlCommand(SQLString, connection)) + { + try + { + connection.Open(); + int rows = cmd.ExecuteNonQuery(); + return rows; + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + connection.Close(); + throw e; + } + } + } + } + /// + /// 指定时间执行 + /// + /// 执行语句 + /// 时间 + /// + public static int ExecuteSqlByTime(string SQLString, int Times) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + using (MySqlCommand cmd = new MySqlCommand(SQLString, connection)) + { + try + { + connection.Open(); + cmd.CommandTimeout = Times; + int rows = cmd.ExecuteNonQuery(); + return rows; + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + connection.Close(); + throw e; + } + } + } + } + + /// + /// 执行多条SQL语句,实现数据库事务。 + /// + /// 多条SQL语句 + public static int ExecuteSqlTran(List SQLStringList) + { + using (MySqlConnection conn = new MySqlConnection(connectionString)) + { + conn.Open(); + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + MySqlTransaction tx = conn.BeginTransaction(); + cmd.Transaction = tx; + try + { + int count = 0; + for (int n = 0; n < SQLStringList.Count; n++) + { + string strsql = SQLStringList[n]; + if (strsql.Trim().Length > 1) + { + cmd.CommandText = strsql; + count += cmd.ExecuteNonQuery(); + } + } + tx.Commit(); + return count; + } + catch + { + tx.Rollback(); + return 0; + } + } + } + /// + /// 执行带一个存储过程参数的的SQL语句。 + /// + /// SQL语句 + /// 参数内容,比如一个字段是格式复杂的文章,有特殊符号,可以通过这个方式添加 + /// 影响的记录数 + public static int ExecuteSql(string SQLString, string content) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + MySqlCommand cmd = new MySqlCommand(SQLString, connection); + MySql.Data.MySqlClient.MySqlParameter myParameter = new MySql.Data.MySqlClient.MySqlParameter("@content", SqlDbType.NText); + myParameter.Value = content; + cmd.Parameters.Add(myParameter); + try + { + connection.Open(); + int rows = cmd.ExecuteNonQuery(); + return rows; + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + throw e; + } + finally + { + cmd.Dispose(); + connection.Close(); + } + } + } + /// + /// 执行带一个存储过程参数的的SQL语句。 + /// + /// SQL语句 + /// 参数内容,比如一个字段是格式复杂的文章,有特殊符号,可以通过这个方式添加 + /// 影响的记录数 + public static object ExecuteSqlGet(string SQLString, string content) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + MySqlCommand cmd = new MySqlCommand(SQLString, connection); + MySql.Data.MySqlClient.MySqlParameter myParameter = new MySql.Data.MySqlClient.MySqlParameter("@content", SqlDbType.NText); + myParameter.Value = content; + cmd.Parameters.Add(myParameter); + try + { + connection.Open(); + object obj = cmd.ExecuteScalar(); + if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value))) + { + return null; + } + else + { + return obj; + } + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + throw e; + } + finally + { + cmd.Dispose(); + connection.Close(); + } + } + } + /// + /// 向数据库里插入图像格式的字段(和上面情况类似的另一种实例) + /// + /// SQL语句 + /// 图像字节,数据库的字段类型为image的情况 + /// 影响的记录数 + public static int ExecuteSqlInsertImg(string strSQL, byte[] fs) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + MySqlCommand cmd = new MySqlCommand(strSQL, connection); + MySql.Data.MySqlClient.MySqlParameter myParameter = new MySql.Data.MySqlClient.MySqlParameter("@fs", SqlDbType.Image); + myParameter.Value = fs; + cmd.Parameters.Add(myParameter); + try + { + connection.Open(); + int rows = cmd.ExecuteNonQuery(); + return rows; + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + throw e; + } + finally + { + cmd.Dispose(); + connection.Close(); + } + } + } + + //执行单条插入语句,并返回id,不需要返回id的用ExceuteNonQuery执行。 + /// + /// 执行插入语句并返回Id,不需返回Id的用其它执行方法 + /// + /// Sql语句 + /// 此参数为Null时进行 + /// + public static int ExecuteInsert(string sql, MySqlParameter[] parameters) + { + //Debug.WriteLine(sql); + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + MySqlCommand cmd = new MySqlCommand(sql, connection); + try + { + connection.Open(); + if (parameters != null) cmd.Parameters.AddRange(parameters); + cmd.ExecuteNonQuery(); + cmd.CommandText = @"select LAST_INSERT_ID()"; + //此方法估计也可直接用 select @@identity 获得,两值基本都是全局服务,使用时不能关闭Connection + int value = Int32.Parse(cmd.ExecuteScalar().ToString()); + return value; + } + catch (Exception e) + { + throw e; + } + } + } + /// + /// 执行一条计算查询结果语句,返回查询结果(object)。 + /// + /// 计算查询结果语句 + /// 查询结果(object) + public static object GetSingle(string SQLString) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + using (MySqlCommand cmd = new MySqlCommand(SQLString, connection)) + { + try + { + connection.Open(); + object obj = cmd.ExecuteScalar(); + if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value))) + { + return null; + } + else + { + return obj; + } + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + connection.Close(); + throw e; + } + } + } + } + /// + /// 获取单一值 + /// + /// Sql语句 + /// 时间 + /// Object类型 + public static object GetSingle(string SQLString, int Times) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + using (MySqlCommand cmd = new MySqlCommand(SQLString, connection)) + { + try + { + connection.Open(); + cmd.CommandTimeout = Times; + object obj = cmd.ExecuteScalar(); + if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value))) + { + return null; + } + else + { + return obj; + } + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + connection.Close(); + throw e; + } + } + } + } + /// + /// 执行查询语句,返回MySqlDataReader ( 注意:调用该方法后,一定要对MySqlDataReader进行Close ) + /// + /// 查询语句 + /// MySqlDataReader + public static MySqlDataReader ExecuteReader(string strSQL) + { + MySqlConnection connection = new MySqlConnection(connectionString); + MySqlCommand cmd = new MySqlCommand(strSQL, connection); + try + { + connection.Open(); + MySqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection); + return myReader; + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + throw e; + } + + } + /// + /// 执行查询语句,返回DataTable + /// + /// 查询语句 + /// DataTable + public static DataTable Query(string SQLString) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + DataSet ds = new DataSet(); + DataTable dt = new DataTable(); + try + { + connection.Open(); + MySqlDataAdapter command = new MySqlDataAdapter(SQLString, connection); + command.Fill(ds, "ds"); + dt = ds.Tables[0]; + } + catch (MySqlException ex) + { + throw new Exception(ex.Message); + } + return dt; + } + } + + /// + /// 执行事务委托lambda语句,参数是DbHelperMySQL对象,通过执行对象的方法可以在事务的控制内 + /// + /// lambda语句 + /// void + public static void ExecuteTransaction(Action transactionAction) + { + + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + connection.Open(); + using (MySqlTransaction transaction = connection.BeginTransaction()) + { + try + { + transactionAction.Invoke(new DbHelperMySQL(connection)); + transaction.Commit(); + } + catch (Exception ex) + { + transaction.Rollback(); + throw new Exception("Transaction failed: " + ex.Message); + } + } + } + } + + /// + /// 执行SQL语句,返回影响的记录数 + /// + /// SQL语句 + /// 影响的记录数 + public static int ExecuteSql(MySqlConnection connection, string SQLString) + { + using (MySqlCommand cmd = new MySqlCommand(SQLString, connection)) + { + int rows = cmd.ExecuteNonQuery(); + return rows; + } + } + + /// + /// 执行SQL语句,返回影响的记录数 + /// + /// SQL语句 + /// 影响的记录数 + public int executeSql(string SQLString) + { + using (MySqlCommand cmd = new MySqlCommand(SQLString, this.connection)) + { + int rows = cmd.ExecuteNonQuery(); + return rows; + } + } + + + + /// + /// 执行语句,返回DataSet + /// + /// Sql语句 + /// 时间 + /// + public static DataSet Query(string SQLString, int Times) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + DataSet ds = new DataSet(); + try + { + connection.Open(); + MySqlDataAdapter command = new MySqlDataAdapter(SQLString, connection); + command.SelectCommand.CommandTimeout = Times; + command.Fill(ds, "ds"); + } + catch (MySql.Data.MySqlClient.MySqlException ex) + { + throw new Exception(ex.Message); + } + return ds; + } + } + + #endregion + + #region 执行带参数的SQL语句 + + /// + /// 执行SQL语句,返回影响的记录数 + /// + /// SQL语句 + /// 准备好的参数列表 + /// 影响的记录数 + public static int ExecuteSql(string SQLString, params MySqlParameter[] cmdParms) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + using (MySqlCommand cmd = new MySqlCommand()) + { + try + { + PrepareCommand(cmd, connection, null, SQLString, cmdParms); + int rows = cmd.ExecuteNonQuery(); + cmd.Parameters.Clear(); + return rows; + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + throw e; + } + } + } + } + + + /// + /// 执行多条SQL语句,实现数据库事务。 + /// + /// SQL语句的哈希表(key为sql语句,value是该语句的MySqlParameter[]) + public static void ExecuteSqlTran(Hashtable SQLStringList) + { + using (MySqlConnection conn = new MySqlConnection(connectionString)) + { + conn.Open(); + using (MySqlTransaction trans = conn.BeginTransaction()) + { + MySqlCommand cmd = new MySqlCommand(); + try + { + //循环 + foreach (DictionaryEntry myDE in SQLStringList) + { + string cmdText = myDE.Key.ToString(); + MySqlParameter[] cmdParms = (MySqlParameter[])myDE.Value; + PrepareCommand(cmd, conn, trans, cmdText, cmdParms); + int val = cmd.ExecuteNonQuery(); + cmd.Parameters.Clear(); + } + trans.Commit(); + } + catch + { + trans.Rollback(); + throw; + } + } + } + } + + /// + /// 执行多条SQL语句,实现数据库事务。 + /// + /// SQL语句的哈希表(key为sql语句,value是该语句的MySqlParameter[]) + public static void ExecuteSqlTranWithIndentity(Hashtable SQLStringList) + { + using (MySqlConnection conn = new MySqlConnection(connectionString)) + { + conn.Open(); + using (MySqlTransaction trans = conn.BeginTransaction()) + { + MySqlCommand cmd = new MySqlCommand(); + try + { + int indentity = 0; + //循环 + foreach (DictionaryEntry myDE in SQLStringList) + { + string cmdText = myDE.Key.ToString(); + MySqlParameter[] cmdParms = (MySqlParameter[])myDE.Value; + foreach (MySqlParameter q in cmdParms) + { + if (q.Direction == ParameterDirection.InputOutput) + { + q.Value = indentity; + } + } + PrepareCommand(cmd, conn, trans, cmdText, cmdParms); + int val = cmd.ExecuteNonQuery(); + foreach (MySqlParameter q in cmdParms) + { + if (q.Direction == ParameterDirection.Output) + { + indentity = Convert.ToInt32(q.Value); + } + } + cmd.Parameters.Clear(); + } + trans.Commit(); + } + catch + { + trans.Rollback(); + throw; + } + } + } + } + /// + /// 执行一条计算查询结果语句,返回查询结果(object)。 + /// + /// 计算查询结果语句 + /// 准备好的参数列表 + /// 查询结果(object) + public static object GetSingle(string SQLString, params MySqlParameter[] cmdParms) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + using (MySqlCommand cmd = new MySqlCommand()) + { + try + { + PrepareCommand(cmd, connection, null, SQLString, cmdParms); + object obj = cmd.ExecuteScalar(); + cmd.Parameters.Clear(); + if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value))) + { + return null; + } + else + { + return obj; + } + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + throw e; + } + } + } + } + + /// + /// 执行查询语句,返回MySqlDataReader ( 注意:调用该方法后,一定要对MySqlDataReader进行Close ) + /// + /// 查询语句 + /// 参数列表 + /// + public static MySqlDataReader ExecuteReader(string SQLString, params MySqlParameter[] cmdParms) + { + MySqlConnection connection = new MySqlConnection(connectionString); + MySqlCommand cmd = new MySqlCommand(); + try + { + PrepareCommand(cmd, connection, null, SQLString, cmdParms); + MySqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection); + cmd.Parameters.Clear(); + return myReader; + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + throw e; + } + // finally + // { + // cmd.Dispose(); + // connection.Close(); + // } + + } + + /// + /// 执行查询语句,返回DataSet + /// + /// 查询语句 + /// 参数列表 + /// DataSet + public static DataSet Query(string SQLString, params MySqlParameter[] cmdParms) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + MySqlCommand cmd = new MySqlCommand(); + PrepareCommand(cmd, connection, null, SQLString, cmdParms); + using (MySqlDataAdapter da = new MySqlDataAdapter(cmd)) + { + DataSet ds = new DataSet(); + try + { + da.Fill(ds, "ds"); + cmd.Parameters.Clear(); + } + catch (MySql.Data.MySqlClient.MySqlException ex) + { + throw new Exception(ex.Message); + } + return ds; + } + } + } + + /// + /// 准备命令语句 + /// + /// Command命令 + /// Connection对象 + /// 是否是事务 + /// 语句 + /// 参数列表 + private static void PrepareCommand(MySqlCommand cmd, MySqlConnection conn, MySqlTransaction trans, string cmdText, MySqlParameter[] cmdParms) + { + if (conn.State != ConnectionState.Open) + conn.Open(); + cmd.Connection = conn; + cmd.CommandText = cmdText; + if (trans != null) + cmd.Transaction = trans; + cmd.CommandType = CommandType.Text;//cmdType; + if (cmdParms != null) + { + foreach (MySqlParameter parameter in cmdParms) + { + if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) && + (parameter.Value == null)) + { + parameter.Value = DBNull.Value; + } + cmd.Parameters.Add(parameter); + } + } + } + + #endregion + + #region 参数转换 + /// + /// 准备MysqlCommad参数 + /// + /// MySqlCommand cmd对象 + /// MySqlConnection conn对象 + /// 数据库事务 + /// text or StoredProcedure + /// 存储过程名 + /// SqlCommand的参数 + private static void PrepareMySqlCommand(MySql.Data.MySqlClient.MySqlCommand cmd, MySql.Data.MySqlClient.MySqlConnection conn, MySqlTransaction trans, CommandType cmdType, string cmdText, MySqlParameter[] cmdParms) + { + //连接状态是否打开 + if (conn.State != ConnectionState.Open) + conn.Open(); + + cmd.Connection = conn; + cmd.CommandText = cmdText; + + //Transact-SQL 事务 + if (trans != null) + cmd.Transaction = trans; + cmd.CommandType = cmdType; + if (cmdParms != null) + { + foreach (MySqlParameter parm in cmdParms) + cmd.Parameters.Add(parm); + } + } + /// + /// 放回一个MakeMySqlParameter + /// + /// 参数名字 + /// 参数类型 + /// 参数大小 + /// 参数值 + /// SQLiteParameter的值 + public static MySqlParameter MakeMySqlParameter(string name, MySqlDbType type, int size, object value) + { + MySqlParameter parm = new MySqlParameter(name, type, size); + parm.Value = value; + return parm; + } + /// + /// 创建MysqlParameter + /// + /// 字段名称 + /// 数据类型 + /// 字段值 + /// 返回类型为MySqlParameter + public static MySqlParameter MakeMySqlParameter(string name, MySqlDbType type, object value) + { + MySqlParameter parm = new MySqlParameter(name, type); + parm.Value = value; + return parm; + } + #endregion + + #region C#调用Mysql的存储过程--自修改 + #region 简单存储过程,返回结果中第一行第一列的值,要求第一行第一列有返回 + /// + /// 简单存储过程,返回结果中第一行第一列的值,要求第一行第一列有返回 + /// + /// 存储过程名 + /// + public static int ExecuteProc(string ProcName) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + using (MySqlCommand cmd = new MySqlCommand(ProcName, connection)) + { + try + { + cmd.CommandType = CommandType.StoredProcedure; + connection.Open();//int rows = + int result = int.Parse(cmd.ExecuteScalar().ToString()); + return result; + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + connection.Close(); + throw new Exception(e.Message); + } + } + } + } + #endregion + + #region 执行带参数的存储过程 + /// + /// 执行带参数的存储过程 + /// + /// 存储过程名 + /// 参数MySqlParameter[] cmdParms + /// + public static string ExecuteProc(string ProcName, params MySqlParameter[] cmdParms) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + using (MySqlCommand cmd = new MySqlCommand()) + { + try + { + cmd.CommandType = CommandType.StoredProcedure; + //cmd.CommandText = ProcName; + PrepareMySqlCommand(cmd, connection, null, CommandType.StoredProcedure, ProcName, cmdParms); + // PrepareCommand(cmd, connection, null, ProcName, cmdParms); + //connection.Open();//int rows = + string result = cmd.ExecuteScalar().ToString(); + return result; + } + catch (MySql.Data.MySqlClient.MySqlException e) + { + connection.Close(); + throw new Exception(e.Message); + } + } + } + } + #endregion + + #region 执行带参数的存储过程(返回DateSet) + /// + /// 执行带参数的存储过程 + /// + /// 存储过程名 + /// 参数MySqlParameter[] cmdParms + /// + public static DataSet ExecuteProcDataset(string ProcName, params MySqlParameter[] cmdParms) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + MySqlCommand cmd = new MySqlCommand(); + PrepareMySqlCommand(cmd, connection, null, CommandType.StoredProcedure, ProcName, cmdParms); + using (MySqlDataAdapter da = new MySqlDataAdapter(cmd)) + { + DataSet ds = new DataSet(); + try + { + da.Fill(ds, "ds"); + cmd.Parameters.Clear(); + } + catch (MySql.Data.MySqlClient.MySqlException ex) + { + throw new Exception(ex.Message); + } + return ds; + } + } + } + + + public static DataSet ExecuteProcDataset(string ProcName) + { + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + MySqlCommand cmd = new MySqlCommand(); + PrepareMySqlCommand(cmd, connection, null, CommandType.StoredProcedure, ProcName, null); + using (MySqlDataAdapter da = new MySqlDataAdapter(cmd)) + { + DataSet ds = new DataSet(); + try + { + da.Fill(ds, "ds"); + cmd.Parameters.Clear(); + } + catch (MySql.Data.MySqlClient.MySqlException ex) + { + throw new Exception(ex.Message); + } + return ds; + } + } + } + #endregion + #endregion + } +} diff --git a/DatabasetoEntityclass/Form1.Designer.cs b/DatabasetoEntityclass/Form1.Designer.cs new file mode 100644 index 0000000..f9715e9 --- /dev/null +++ b/DatabasetoEntityclass/Form1.Designer.cs @@ -0,0 +1,135 @@ +namespace WindowsFormsApp1 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.txt_ret = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.namespace_name = new System.Windows.Forms.TextBox(); + this.lable2 = new System.Windows.Forms.Label(); + this.txt_tablename = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(81, 322); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 0; + this.button1.Text = "开始"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(70, 120); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(41, 12); + this.label2.TabIndex = 4; + this.label2.Text = "表名:"; + // + // txt_ret + // + this.txt_ret.Font = new System.Drawing.Font("宋体", 11F); + this.txt_ret.Location = new System.Drawing.Point(453, 61); + this.txt_ret.Multiline = true; + this.txt_ret.Name = "txt_ret"; + this.txt_ret.Size = new System.Drawing.Size(335, 341); + this.txt_ret.TabIndex = 68; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(453, 43); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(53, 12); + this.label3.TabIndex = 69; + this.label3.Text = "生成后:"; + // + // namespace_name + // + this.namespace_name.Location = new System.Drawing.Point(117, 155); + this.namespace_name.Name = "namespace_name"; + this.namespace_name.Size = new System.Drawing.Size(218, 21); + this.namespace_name.TabIndex = 70; + this.namespace_name.Text = "default_namespace"; + // + // lable2 + // + this.lable2.AutoSize = true; + this.lable2.Location = new System.Drawing.Point(53, 160); + this.lable2.Name = "lable2"; + this.lable2.Size = new System.Drawing.Size(59, 12); + this.lable2.TabIndex = 71; + this.lable2.Text = "名称空间:"; + // + // txt_tablename + // + this.txt_tablename.FormattingEnabled = true; + this.txt_tablename.Location = new System.Drawing.Point(117, 116); + this.txt_tablename.Name = "txt_tablename"; + this.txt_tablename.Size = new System.Drawing.Size(218, 20); + this.txt_tablename.TabIndex = 72; + this.txt_tablename.Text = "请选择"; + this.txt_tablename.TextUpdate += new System.EventHandler(this.orderId_TextUpdate); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.txt_tablename); + this.Controls.Add(this.lable2); + this.Controls.Add(this.namespace_name); + this.Controls.Add(this.label3); + this.Controls.Add(this.txt_ret); + this.Controls.Add(this.label2); + this.Controls.Add(this.button1); + this.Name = "Form1"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Form1_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txt_ret; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox namespace_name; + private System.Windows.Forms.Label lable2; + private System.Windows.Forms.ComboBox txt_tablename; + } +} + diff --git a/DatabasetoEntityclass/Form1.cs b/DatabasetoEntityclass/Form1.cs new file mode 100644 index 0000000..8e8a947 --- /dev/null +++ b/DatabasetoEntityclass/Form1.cs @@ -0,0 +1,216 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WindowsFormsApp1 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + string folderName = "GenFolder"; // 文件夹名称 + private void Form1_Load(object sender, EventArgs e) + { + this.txt_tablename.Items.AddRange(GetTableName().ToArray()); + } + /// + /// 将数据库字段转换为驼峰命名 + /// + /// + /// + public static string ToCamelCase(string dbField) + { + string[] words = dbField.Split('_'); + for (int i = 1; i < words.Length; i++) + { + words[i] = char.ToUpper(words[i][0]) + words[i].Substring(1); + } + return string.Join("", words); + } + + // 根据数据库表名生成实体类名称 + static string GenerateClassName(string tableName) + { + string[] words = tableName.Split('_'); + + StringBuilder sb = new StringBuilder(); + foreach (string word in words) + { + sb.Append(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(word.ToLower())); + } + + return sb.ToString(); + } + + private void button1_Click(object sender, EventArgs e) + { + //string constr = txt_constr.Text.Trim();//数据库链接字符串 + txt_ret.Text = ""; + string tbname = txt_tablename.Text.Trim();//要生成的表名 + if (tbname.Equals("请选择") || tbname.Equals("")) { + MessageBox.Show("请选择表"); + return; + }; + string namespaceName = namespace_name.Text.Trim(); + var dt = GetDbTableInfo(tbname); + var list = new List(); + txt_ret.Text += "using System;\n" + + "using NCA_MES_Models.CommonUtils.DB.DBAttribute;\n\n"; + txt_ret.Text += "namespace "+ namespaceName + "{\n\n"; + txt_ret.Text += "[TableName(\"" + tbname + "\")]" + "\n"+"public class " + GenerateClassName(tbname) + " {"; + for (int i = 0; i < dt.Rows.Count; i++) + { + var Name = dt.Rows[i]["Name"].ToString(); + var Type = dt.Rows[i]["Type"].ToString(); + var IsNullable = dt.Rows[i]["COMMENT"].ToString(); + + + Type type = DbTypeStr_To_CsharpType(Type); + //txt_ret.Text += @"/// " + "\n" + "///" + IsNullable + "\n" + " /// \n" +""+ " public " + type.Name +" "+ Name + " { get; set; }" + "\n";//不加注释版本 + txt_ret.Text += "\n\t" + @"/// " + + "\n\t" + "///" + IsNullable + + "\n\t" + "/// " + + "\n\t" + "[TableField(\""+ Name + "\")]" + + "\n\t"+ " public " + type.Name +" "+ ToCamelCase(Name) + " { get; set; }"; + //加注释记得引用using + } + txt_ret.Text += "\n}\n}"; + // 创建文件夹 + string folderPath = Path.Combine(Environment.CurrentDirectory, folderName); + Directory.CreateDirectory(folderPath); + + // 创建文件并写入内容 + string filePath = Path.Combine(folderPath, GenerateClassName(tbname)+".cs"); + File.WriteAllText(filePath, txt_ret.Text); + + // 打开文件夹 + System.Diagnostics.Process.Start(folderPath); + } + + + //订单下拉模糊搜索 + private void orderId_TextUpdate(object sender, EventArgs e) //不要用TextChanged + { + string s = this.txt_tablename.Text; //获取输入内容 + List sList = GetTableName(s); //存放数据库查询结果 + //提前下拉,以显示搜索结果(必须要在添加项之前下拉,否则会将第一项自动添加到编辑框内 覆盖掉输入的内容) + this.txt_tablename.DroppedDown = true; //显示下拉列表,但是显示后鼠标指针就不见了 + Cursor.Current = Cursors.Default; //将指针显示出来 + + //在表中已录入名字中寻找包含输入内容的项 有则添加到comboBox项中 + this.txt_tablename.Items.Clear(); + this.txt_tablename.Items.AddRange(sList.ToArray()); + this.txt_tablename.Select(this.txt_tablename.Text.Length, 0); + } + + /// + /// 根据参数,获取数据表信息 + /// + /// + public static DataTable GetDbTableInfo(string tabname) + { + string str = string.Format(@"SELECT COLUMN_NAME AS Name, COLUMN_TYPE AS Type,COLUMN_COMMENT AS COMMENT +FROM INFORMATION_SCHEMA.COLUMNS +WHERE TABLE_NAME = '{0}';", tabname); + + var dt = DbHelperMySQL.Query(str); + return dt; + } + + + public static List GetTableName(string tableName) + { + string sql = $"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{DbHelperMySQL.DbName}' AND TABLE_NAME LIKE '{tableName}%' limit 10;"; + var dt = DbHelperMySQL.Query(sql); + //查询数据库表中所有已录入人员 + List sList = new List(); //存放数据库查询结果 + for (int i = 0; i < dt.Rows.Count; i++) + { + sList.Add(dt.Rows[i]["TABLE_NAME"].ToString()); + } + return sList; + //return dt; + } + public static List GetTableName() + { + string sql = $"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{DbHelperMySQL.DbName}';"; + var dt = DbHelperMySQL.Query(sql); + //查询数据库表中所有已录入人员 + List sList = new List(); //存放数据库查询结果 + for (int i = 0; i < dt.Rows.Count; i++) + { + sList.Add(dt.Rows[i]["TABLE_NAME"].ToString()); + } + return sList; + //return dt; + } + + /// + /// 类型转换枚举 + /// + protected Dictionary DbTypeDic { get; } = new Dictionary() + { + { "int", typeof(Int32) }, + { "text", typeof(string) }, + { "bigint", typeof(Int64) }, + { "binary", typeof(byte[]) }, + { "bit", typeof(bool) }, + { "char", typeof(string) }, + { "date", typeof(DateTime) }, + { "datetime", typeof(DateTime) }, + { "datetime2", typeof(DateTime) }, + { "decimal", typeof(decimal) }, + { "float", typeof(double) }, + { "image", typeof(byte[]) }, + { "money", typeof(decimal) }, + { "nchar", typeof(string) }, + { "ntext", typeof(string) }, + { "numeric", typeof(decimal) }, + { "nvarchar", typeof(string) }, + { "real", typeof(Single) }, + { "smalldatetime", typeof(DateTime) }, + { "smallint", typeof(Int16) }, + { "smallmoney", typeof(decimal) }, + { "timestamp", typeof(DateTime) }, + { "tinyint", typeof(byte) }, + { "varbinary", typeof(byte[]) }, + { "varchar", typeof(string) }, + { "variant", typeof(object) }, + { "uniqueidentifier", typeof(Guid) }, + }; + /// + /// 获取字段类型 + /// + /// + /// + public virtual Type DbTypeStr_To_CsharpType(string dbTypeStr) + { + if (dbTypeStr.Contains('(')) + { + string[] strings = dbTypeStr.Split('('); + dbTypeStr = strings[0]; + } + string _dbTypeStr = dbTypeStr.ToLower(); + Type type = null; + if (DbTypeDic.ContainsKey(_dbTypeStr)) + type = DbTypeDic[_dbTypeStr]; + else + type = typeof(string); + + return type; + } + + + } +} diff --git a/DatabasetoEntityclass/Form1.resx b/DatabasetoEntityclass/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/DatabasetoEntityclass/Form1.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/DatabasetoEntityclass/Program.cs b/DatabasetoEntityclass/Program.cs new file mode 100644 index 0000000..389dad4 --- /dev/null +++ b/DatabasetoEntityclass/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WindowsFormsApp1 +{ + internal static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/DatabasetoEntityclass/Properties/AssemblyInfo.cs b/DatabasetoEntityclass/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5df7b87 --- /dev/null +++ b/DatabasetoEntityclass/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("WindowsFormsApp1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WindowsFormsApp1")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("7d7b530a-23a4-4024-b263-a942aa53dcc5")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DatabasetoEntityclass/Properties/Resources.Designer.cs b/DatabasetoEntityclass/Properties/Resources.Designer.cs new file mode 100644 index 0000000..8b479b7 --- /dev/null +++ b/DatabasetoEntityclass/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace WindowsFormsApp1.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("WindowsFormsApp1.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/DatabasetoEntityclass/Properties/Resources.resx b/DatabasetoEntityclass/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/DatabasetoEntityclass/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/DatabasetoEntityclass/Properties/Settings.Designer.cs b/DatabasetoEntityclass/Properties/Settings.Designer.cs new file mode 100644 index 0000000..438df21 --- /dev/null +++ b/DatabasetoEntityclass/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 WindowsFormsApp1.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/DatabasetoEntityclass/Properties/Settings.settings b/DatabasetoEntityclass/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/DatabasetoEntityclass/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/DatabasetoEntityclass/SystemConfig.xml b/DatabasetoEntityclass/SystemConfig.xml new file mode 100644 index 0000000..54b03cd --- /dev/null +++ b/DatabasetoEntityclass/SystemConfig.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/GenerateClass.sln b/GenerateClass.sln new file mode 100644 index 0000000..5ba0276 --- /dev/null +++ b/GenerateClass.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33815.320 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabasetoEntityclass", "DatabasetoEntityclass\DatabasetoEntityclass.csproj", "{7D7B530A-23A4-4024-B263-A942AA53DCC5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7D7B530A-23A4-4024-B263-A942AA53DCC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7D7B530A-23A4-4024-B263-A942AA53DCC5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7D7B530A-23A4-4024-B263-A942AA53DCC5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7D7B530A-23A4-4024-B263-A942AA53DCC5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EDE01A82-38C5-440C-8052-A786E37CB799} + EndGlobalSection +EndGlobal