├── README.md
├── SQLLangCreateTooling.zip
├── SQLLangCreateTooling
├── ExcelPackage.dll
├── ExcelPackageBinary.zip
├── NPOI 2.2.0.0.zip
├── NPOI.dll
├── SQLLangCreateTooling.sln
├── SQLLangCreateTooling.suo
├── SQLLangCreateTooling
│ ├── CreateTextFromExcelNow.cs
│ ├── FormMain.Designer.cs
│ ├── FormMain.cs
│ ├── FormMain.resx
│ ├── NPOIExcelDataTrim.cs
│ ├── NPOIExcelFilesRead.cs
│ ├── Program.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ └── SQLLangCreateTooling.csproj
└── readme.docx
└── view.png
/README.md:
--------------------------------------------------------------------------------
1 | __帮助说明__
2 | ----------------------
3 | #####a.
4 | 程序适用于向已有数据库表中增删改一定的数据,通常情形下数据内容已经确定,然而并没有合适的方法快速添加到数据库;
5 | 实际工作中,我们习惯将收集的数据用EXCEL表来暂时保存,然后更多的时候我们并没有好的机制快速将Excel表中的内容直接导入到数据库中,SQLLangCreateTooling是一个Windows应用程序源码项目,方便大家使用Windows应用程序,快速生成SQL语言语句。
6 |
7 | 作者本人在大型项目中得到了实际的应用:
8 | + 1.业务人员习惯于用EXCEL快速的收集和保存各种数据。我们不能强制要求业务人员每次手动到某个平台上填写这样那样的资料。
9 | + 2.如果说业务人员到某个平台上填写数据,而数据本身要求比较详尽,开发或提供这样的平台对于小公司来说需要一定的成本;
10 | + 3.业务人员不一定能随时随地上平台操作。
11 |
而我们这样一个小小的工具可以起到很大的作用:
12 | + 1.业务人员只需要将数据井然有序的保存即可。
13 | + 2.拿到的数据只需要简单的表格列的处理,比如说按符合数据库表设计的要求处理,然后用我们的工具即可生成SQL语言。
14 | + 3.SQL语言文档甚至可以直接修改成*.sql文件,直接导入数据库。
15 |
16 |
17 | #####b.
18 | 您可以先将数据有序的加入到EXCEL表中,软件帮您生成Structured Query Language
19 | [Structured Query Language介绍](http://baike.baidu.com/link?url=Cpq9E0ee28w2onlnqJh_f3qJdviVvBM3vyizpoW9OYRImp_n2ZC4oRM9PywjRLtLA7qpFgBU4co70ceuHExDyziKMYubvyKZbimr_p0DykmvYgUM4fXVxmF45SfcyiSKHXMNhpGubp83CrlMFr4f7nKQLix-OSAQByqo8LlAW_7"百度地址")
20 |
21 |
22 | #####c.
23 | 支持2003/2007+版EXCEL文件,后缀名*.xls/*.xlsx!。
24 |
25 |
26 | #####d.
27 | 支持选择第几张表格的内容,表格中不要有间隙单元格或不整齐非空单元格(如果确实有未填表,仍然建议采用数据库默认字段填充,以免生成语句语法不合要求)。
28 |
29 |
30 | #####e.
31 | 手动输入数字1~9,分别表示第一张表至第9张表,实际证明Excel文件中Sheet表的排序与所见的顺序可能不一样,但软件有会将表的名称显示出来供您比对!
32 |
33 |
34 | #####f.
35 | 文件名、表名尽量使用英文+数字;因为有可能编码无法被程序识别。(本程序在Microsoft Visual Studio 2008版IDE上调试通过,实际测试系统为简体中文版64位Win7电脑)
36 |
37 |
38 | #####g.
39 | 本程序开源代码首发地址:[Github查看代码](https://github.com/YamazakyLau/SQLLangCreateTooling.git"Github")
40 |
41 |
42 | #####h.
43 | 程序引用开源组件NPOI、ExcelPackage ,理论上不需要您的电脑上安装EXCEL阅读软件也能使用,软件抛弃原来的OleDbConnection(或叫OLEDB)程序接口,但仍保留代码痕迹。
44 |
45 | #####g.
46 | 原型预览:
47 | 
48 |
49 | #####h.
50 | 工具安装下载[SQLLangCreateTooling.zip](https://github.com/YamazakyLau/SQLLangCreateTooling/edit/master/SQLLangCreateTooling.zip "下载")
51 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YamazakyLau/SQLLangCreateTooling/9b3597a23b07e3eea343583f4aadb504919ae52a/SQLLangCreateTooling.zip
--------------------------------------------------------------------------------
/SQLLangCreateTooling/ExcelPackage.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YamazakyLau/SQLLangCreateTooling/9b3597a23b07e3eea343583f4aadb504919ae52a/SQLLangCreateTooling/ExcelPackage.dll
--------------------------------------------------------------------------------
/SQLLangCreateTooling/ExcelPackageBinary.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YamazakyLau/SQLLangCreateTooling/9b3597a23b07e3eea343583f4aadb504919ae52a/SQLLangCreateTooling/ExcelPackageBinary.zip
--------------------------------------------------------------------------------
/SQLLangCreateTooling/NPOI 2.2.0.0.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YamazakyLau/SQLLangCreateTooling/9b3597a23b07e3eea343583f4aadb504919ae52a/SQLLangCreateTooling/NPOI 2.2.0.0.zip
--------------------------------------------------------------------------------
/SQLLangCreateTooling/NPOI.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YamazakyLau/SQLLangCreateTooling/9b3597a23b07e3eea343583f4aadb504919ae52a/SQLLangCreateTooling/NPOI.dll
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 10.00
3 | # Visual Studio 2008
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLLangCreateTooling", "SQLLangCreateTooling\SQLLangCreateTooling.csproj", "{AF8270A2-7B18-45C1-9FEF-F28251475E6C}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {AF8270A2-7B18-45C1-9FEF-F28251475E6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {AF8270A2-7B18-45C1-9FEF-F28251475E6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {AF8270A2-7B18-45C1-9FEF-F28251475E6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {AF8270A2-7B18-45C1-9FEF-F28251475E6C}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YamazakyLau/SQLLangCreateTooling/9b3597a23b07e3eea343583f4aadb504919ae52a/SQLLangCreateTooling/SQLLangCreateTooling.suo
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/CreateTextFromExcelNow.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Data.OleDb;
6 | using System.ComponentModel;
7 | using System.Data;
8 | using System.Drawing;
9 | using System.Windows.Forms;
10 | using System.IO;
11 |
12 | namespace SQLLangCreateTooling
13 | {
14 | /*
15 | * 新版本统一改成getDataSet.Tables[0],因为该方法虽然引用了第N张表,但转成DataSet后只认为是第0张表!
16 | * getDataSet.Tables[tb]是错误的!
17 | */
18 | class CreateTextFromExcelNow
19 | {
20 | ///
21 | /// DataSet方法生成Insert语句。
22 | ///
23 | /// 引用getDataSet数据内容,并将SQL语法语句写入Insert.txt文件中。
24 | ///
25 | public static void printSQLLangInsert(DataSet getDataSet)
26 | {
27 | int hangY, lieXX;
28 | string basicStr = "INSERT INTO ";
29 |
30 | hangY = getDataSet.Tables[0].Rows.Count;//建议不要出现无效数据列,如有部分单元格空白!
31 | lieXX = getDataSet.Tables[0].Columns.Count;
32 |
33 | if (hangY < 2 || lieXX < 2)
34 | {
35 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
36 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
37 | return; //如果行列太少,那么直接无视!
38 | }
39 |
40 | try
41 | {
42 | FileStream aFile = new FileStream("Insert.txt", FileMode.Append);
43 | StreamWriter sw = new StreamWriter(aFile);
44 |
45 | /*
46 | * INSERT INTO `kswiki2`.`wish` (id,user_id,title,text,created_at,votes_count) VALUES
47 | * ('526','17','我想','你好啊','2014-09-20 21:33:25','230'),
48 | * ('527','18','不想','我好啊','2014-09-21 21:34:26','231');
49 | */
50 |
51 | for (int i = 0; i < hangY; i++)
52 | {
53 | string outPrint = "";
54 |
55 | if (i == 0)
56 | {
57 | outPrint = basicStr + getDataSet.Tables[0].Rows[1][0].ToString() + " (";
58 | }
59 | else
60 | {
61 | outPrint = outPrint + "(";
62 | }
63 | for (int j = 1; j < lieXX; j++)
64 | {
65 | if (i == 0)
66 | {
67 | if (j != lieXX - 1)
68 | outPrint = outPrint + getDataSet.Tables[0].Rows[0][j].ToString() + ",";
69 | else
70 | outPrint = outPrint + getDataSet.Tables[0].Rows[0][j].ToString() + ") VALUES ";
71 | }
72 | else
73 | {
74 | outPrint = outPrint + "'" + getDataSet.Tables[0].Rows[i][j].ToString() + "'";
75 | if (j != lieXX - 1)
76 | {
77 | outPrint = outPrint + ",";
78 | }
79 | else
80 | {
81 | if (i != hangY - 1)
82 | {
83 | outPrint = outPrint + "),";
84 | }
85 | else
86 | { //末行加分号,表示所有插入语句结束
87 | outPrint = outPrint + ");";
88 | }
89 | }
90 | }
91 |
92 | }
93 |
94 | // Write data to file.
95 | sw.WriteLine(outPrint);
96 | }
97 |
98 | //结束写入
99 | sw.Close();
100 | }
101 | catch (Exception ex)
102 | {
103 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
104 | MessageBoxButtons.OK, MessageBoxIcon.Information);
105 | return;
106 | }
107 | }
108 |
109 | ///
110 | /// DataSet方法生成Delete语句。
111 | ///
112 | /// 引用getDataSet数据内容,并将SQL语法语句写入Delete.txt文件中。
113 | ///
114 | public static void printSQLLangDelete(DataSet getDataSet)
115 | {
116 | int hangY, lieXX;
117 | string basicStr = "DELETE FROM ";
118 |
119 | hangY = getDataSet.Tables[0].Rows.Count;//建议不要出现无效数据列,如有部分单元格空白!
120 | lieXX = getDataSet.Tables[0].Columns.Count;
121 |
122 | if (hangY < 2 || lieXX < 2)
123 | {
124 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
125 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
126 | return; //如果行列太少,那么直接无视!
127 | }
128 |
129 | try
130 | {
131 | FileStream aFile = new FileStream("Delete.txt", FileMode.Append);
132 | StreamWriter sw = new StreamWriter(aFile);
133 |
134 | /*
135 | * delete from tableA where statusB='12'and textC='dsf';
136 | */
137 | for (int i = 1; i < hangY; i++)
138 | {
139 | string outPrint;
140 |
141 | if (lieXX == 2)
142 | {
143 | outPrint = basicStr + getDataSet.Tables[0].Rows[i][0].ToString() + " where "
144 | + getDataSet.Tables[0].Rows[0][1].ToString() + "='" + getDataSet.Tables[0].Rows[i][1].ToString() + "';";
145 | }
146 | else//如果大于2,就用3列的,大于3列的表格也只考虑3列数据!
147 | {
148 | outPrint = basicStr + getDataSet.Tables[0].Rows[i][0].ToString() + " where "
149 | + getDataSet.Tables[0].Rows[0][1].ToString() + "='" + getDataSet.Tables[0].Rows[i][1].ToString()
150 | + "' AND " + getDataSet.Tables[0].Rows[0][2].ToString() + "='" + getDataSet.Tables[0].Rows[i][2].ToString()
151 | + "';";
152 | }
153 |
154 | // Write data to file.
155 | sw.WriteLine(outPrint);
156 | }
157 |
158 | //结束写入
159 | sw.Close();
160 | }
161 | catch (Exception ex)
162 | {
163 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
164 | MessageBoxButtons.OK, MessageBoxIcon.Information);
165 | return;
166 | }
167 |
168 |
169 | /* *调试过程!
170 | String testStr = getDataSet.Tables[0].Rows[0][0].ToString();
171 | testStr = getDataSet.Tables[0].Rows[0][1].ToString();
172 | testStr = getDataSet.Tables[0].Rows[0][2].ToString();
173 |
174 | testStr = getDataSet.Tables[0].Rows[1][0].ToString();
175 | testStr = getDataSet.Tables[0].Rows[1][1].ToString();
176 | testStr = getDataSet.Tables[0].Rows[1][2].ToString();
177 |
178 | testStr = getDataSet.Tables[0].Rows[2][0].ToString();
179 | testStr = getDataSet.Tables[0].Rows[2][1].ToString();
180 | testStr = getDataSet.Tables[0].Rows[2][2].ToString();*/
181 |
182 | }
183 |
184 | ///
185 | /// DataSet方法生成Update语句。
186 | ///
187 | /// 引用getDataSet数据内容,并将SQL语法语句写入Update.txt文件中。
188 | ///
189 | public static void printSQLLangUpdate(DataSet getDataSet)
190 | {
191 | int hangY, lieXX;
192 | string basicStr = "UPDATE ";
193 |
194 | hangY = getDataSet.Tables[0].Rows.Count;//建议不要出现无效数据列,如有部分单元格空白!
195 | lieXX = getDataSet.Tables[0].Columns.Count;
196 |
197 | if (hangY < 2 || lieXX < 3)
198 | {
199 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
200 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
201 | return; //如果行列太少,那么直接无视!
202 | }
203 |
204 | try
205 | {
206 | FileStream aFile = new FileStream("Update.txt", FileMode.Append);
207 | StreamWriter sw = new StreamWriter(aFile);
208 |
209 | /*
210 | * UPDATE `kswiki2`.`wish` SET status='12',text='dsf' WHERE id='1';
211 | */
212 | for (int i = 1; i < hangY; i++)
213 | {
214 | string outPrint;
215 | outPrint = basicStr + getDataSet.Tables[0].Rows[i][0].ToString() + " SET ";
216 | for (int j = 2; j < lieXX; j++)
217 | {
218 | outPrint = outPrint + getDataSet.Tables[0].Rows[0][j].ToString() + "=" + "'" + getDataSet.Tables[0].Rows[i][j].ToString() + "'";
219 | if (j != lieXX - 1)
220 | {
221 | outPrint = outPrint + ",";
222 | }
223 | else
224 | {
225 | outPrint = outPrint + " ";
226 | }
227 | }
228 | outPrint = outPrint + "WHERE " + getDataSet.Tables[0].Rows[0][1].ToString() + "=" + "'" + getDataSet.Tables[0].Rows[i][1].ToString() + "';";
229 |
230 | // Write data to file.
231 | sw.WriteLine(outPrint);
232 | }
233 |
234 | //结束写入
235 | sw.Close();
236 | }
237 | catch (Exception ex)
238 | {
239 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
240 | MessageBoxButtons.OK, MessageBoxIcon.Information);
241 | return;
242 | }
243 | }
244 |
245 | ///
246 | /// DataSet方法生成Update语句。(方法未完全正确,仅实现Update)
247 | ///
248 | /// 引用getDataSet数据内容,并将SQL语法语句写入UpdateOnly.txt文件中。
249 | ///
250 | public static void printSQLLangUpdateOnly(DataSet getDataSet)
251 | {
252 | int hangY, lieXX;
253 | string basicStr = "UPDATE ";
254 |
255 | hangY = getDataSet.Tables[0].Rows.Count;//建议不要出现无效数据列,如有部分单元格空白!
256 | lieXX = getDataSet.Tables[0].Columns.Count;
257 |
258 | if (hangY < 2 || lieXX < 3)
259 | {
260 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
261 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
262 | return; //如果行列太少,那么直接无视!
263 | }
264 |
265 | try
266 | {
267 | FileStream aFile = new FileStream("UpdateOnly.txt", FileMode.Append);
268 | StreamWriter sw = new StreamWriter(aFile);
269 |
270 | /*
271 | * Excel File Likes:(Sheet Name = DataBase Table name = String "update_only")
272 | tables_name name age sex
273 | video_category 张松溪 22 1
274 | video_category 宋远桥 33 2
275 | video_category 俞岱岩 44 1
276 | video_category 张三丰 55 1
277 | video_category 殷梨亭 66 2
278 | * UPDATE `update_only`.`video_category` SET age='22',sex='1' WHERE 'id'=
279 | * (SELECT 'id' FROM `update_only`.`video_category` WHERE 'name'='张松溪');
280 | * 减少部分语句,假设已经切换到当前数据库:
281 | * UPDATE `video_category` SET age='22',sex='1' WHERE 'id'=
282 | * (SELECT 'id' FROM `video_category` WHERE 'name'='张松溪');
283 | */
284 | for (int i = 1; i < hangY; i++)
285 | {
286 | string outPrint;
287 | outPrint = basicStr + getDataSet.Tables[0].Rows[i][0].ToString() + " SET ";
288 | for (int j = 2; j < lieXX; j++)
289 | {
290 | outPrint = outPrint + getDataSet.Tables[0].Rows[0][j].ToString() + "=" + "'" + getDataSet.Tables[0].Rows[i][j].ToString() + "'";
291 | if (j != lieXX - 1)
292 | {
293 | outPrint = outPrint + ",";
294 | }
295 | else
296 | {
297 | outPrint = outPrint + " ";
298 | }
299 | }
300 | //假设主键名称为'id'
301 | outPrint = outPrint + "WHERE " + getDataSet.Tables[0].Rows[0][1].ToString() +
302 | "=" + "'" + getDataSet.Tables[0].Rows[i][1].ToString() + "';";
303 |
304 | // Write data to file.
305 | sw.WriteLine(outPrint);
306 | }
307 |
308 | //结束写入
309 | sw.Close();
310 | }
311 | catch (Exception ex)
312 | {
313 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
314 | MessageBoxButtons.OK, MessageBoxIcon.Information);
315 | return;
316 | }
317 | }
318 |
319 |
320 | }
321 | }
322 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/FormMain.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace SQLLangCreateTooling
2 | {
3 | partial class FormMain
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows 窗体设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.buttonCreate = new System.Windows.Forms.Button();
32 | this.groupBoxExcel = new System.Windows.Forms.GroupBox();
33 | this.radioButtonInsertPerLine = new System.Windows.Forms.RadioButton();
34 | this.textBoxUpdateOnly = new System.Windows.Forms.TextBox();
35 | this.label_Only = new System.Windows.Forms.Label();
36 | this.labelSheetName = new System.Windows.Forms.Label();
37 | this.radioButtonUpdateOnly = new System.Windows.Forms.RadioButton();
38 | this.textBoxTableNum = new System.Windows.Forms.NumericUpDown();
39 | this.labelTableNum = new System.Windows.Forms.Label();
40 | this.labelSqlType = new System.Windows.Forms.Label();
41 | this.radioButtonDelete = new System.Windows.Forms.RadioButton();
42 | this.radioButtonUpdate = new System.Windows.Forms.RadioButton();
43 | this.radioButtonInsert = new System.Windows.Forms.RadioButton();
44 | this.labelVersion = new System.Windows.Forms.Label();
45 | this.labelInfo = new System.Windows.Forms.Label();
46 | this.textBoxSelect = new System.Windows.Forms.TextBox();
47 | this.groupBoxTxt = new System.Windows.Forms.GroupBox();
48 | this.buttonGroupMixedOne = new System.Windows.Forms.Button();
49 | this.buttonDataTrim = new System.Windows.Forms.Button();
50 | this.linkLabelHelpInfo = new System.Windows.Forms.LinkLabel();
51 | this.numericUpDownGroupRules = new System.Windows.Forms.NumericUpDown();
52 | this.labelGroupRules = new System.Windows.Forms.Label();
53 | this.labelNewData = new System.Windows.Forms.Label();
54 | this.labelRawData = new System.Windows.Forms.Label();
55 | this.numericUpDownNewData = new System.Windows.Forms.NumericUpDown();
56 | this.numericUpDownRawData = new System.Windows.Forms.NumericUpDown();
57 | this.button1 = new System.Windows.Forms.Button();
58 | this.groupBoxExcel.SuspendLayout();
59 | ((System.ComponentModel.ISupportInitialize)(this.textBoxTableNum)).BeginInit();
60 | this.groupBoxTxt.SuspendLayout();
61 | ((System.ComponentModel.ISupportInitialize)(this.numericUpDownGroupRules)).BeginInit();
62 | ((System.ComponentModel.ISupportInitialize)(this.numericUpDownNewData)).BeginInit();
63 | ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRawData)).BeginInit();
64 | this.SuspendLayout();
65 | //
66 | // buttonCreate
67 | //
68 | this.buttonCreate.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
69 | this.buttonCreate.Location = new System.Drawing.Point(478, 134);
70 | this.buttonCreate.Name = "buttonCreate";
71 | this.buttonCreate.Size = new System.Drawing.Size(80, 40);
72 | this.buttonCreate.TabIndex = 8;
73 | this.buttonCreate.Text = "生 成";
74 | this.buttonCreate.UseVisualStyleBackColor = true;
75 | this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
76 | //
77 | // groupBoxExcel
78 | //
79 | this.groupBoxExcel.Controls.Add(this.radioButtonInsertPerLine);
80 | this.groupBoxExcel.Controls.Add(this.buttonCreate);
81 | this.groupBoxExcel.Controls.Add(this.textBoxUpdateOnly);
82 | this.groupBoxExcel.Controls.Add(this.label_Only);
83 | this.groupBoxExcel.Controls.Add(this.labelSheetName);
84 | this.groupBoxExcel.Controls.Add(this.radioButtonUpdateOnly);
85 | this.groupBoxExcel.Controls.Add(this.textBoxTableNum);
86 | this.groupBoxExcel.Controls.Add(this.labelTableNum);
87 | this.groupBoxExcel.Controls.Add(this.labelSqlType);
88 | this.groupBoxExcel.Controls.Add(this.radioButtonDelete);
89 | this.groupBoxExcel.Controls.Add(this.radioButtonUpdate);
90 | this.groupBoxExcel.Controls.Add(this.radioButtonInsert);
91 | this.groupBoxExcel.Controls.Add(this.labelVersion);
92 | this.groupBoxExcel.Controls.Add(this.labelInfo);
93 | this.groupBoxExcel.Controls.Add(this.textBoxSelect);
94 | this.groupBoxExcel.Location = new System.Drawing.Point(12, 12);
95 | this.groupBoxExcel.Name = "groupBoxExcel";
96 | this.groupBoxExcel.Size = new System.Drawing.Size(564, 180);
97 | this.groupBoxExcel.TabIndex = 0;
98 | this.groupBoxExcel.TabStop = false;
99 | this.groupBoxExcel.Text = "Excel表格处理";
100 | //
101 | // radioButtonInsertPerLine
102 | //
103 | this.radioButtonInsertPerLine.AutoSize = true;
104 | this.radioButtonInsertPerLine.Location = new System.Drawing.Point(339, 122);
105 | this.radioButtonInsertPerLine.Name = "radioButtonInsertPerLine";
106 | this.radioButtonInsertPerLine.Size = new System.Drawing.Size(89, 16);
107 | this.radioButtonInsertPerLine.TabIndex = 5;
108 | this.radioButtonInsertPerLine.TabStop = true;
109 | this.radioButtonInsertPerLine.Text = "Insert-Each";
110 | this.radioButtonInsertPerLine.UseVisualStyleBackColor = true;
111 | this.radioButtonInsertPerLine.CheckedChanged += new System.EventHandler(this.radioButtonInsertPerLine_CheckedChanged);
112 | //
113 | // textBoxUpdateOnly
114 | //
115 | this.textBoxUpdateOnly.ForeColor = System.Drawing.Color.DarkViolet;
116 | this.textBoxUpdateOnly.Location = new System.Drawing.Point(200, 151);
117 | this.textBoxUpdateOnly.MaxLength = 20;
118 | this.textBoxUpdateOnly.Name = "textBoxUpdateOnly";
119 | this.textBoxUpdateOnly.Size = new System.Drawing.Size(202, 21);
120 | this.textBoxUpdateOnly.TabIndex = 0;
121 | this.textBoxUpdateOnly.Text = "id";
122 | //
123 | // label_Only
124 | //
125 | this.label_Only.AutoSize = true;
126 | this.label_Only.ForeColor = System.Drawing.Color.DarkViolet;
127 | this.label_Only.Location = new System.Drawing.Point(117, 155);
128 | this.label_Only.Name = "label_Only";
129 | this.label_Only.Size = new System.Drawing.Size(77, 12);
130 | this.label_Only.TabIndex = 0;
131 | this.label_Only.Text = "表主键名称:";
132 | //
133 | // labelSheetName
134 | //
135 | this.labelSheetName.AutoSize = true;
136 | this.labelSheetName.ForeColor = System.Drawing.Color.Red;
137 | this.labelSheetName.Location = new System.Drawing.Point(208, 73);
138 | this.labelSheetName.Name = "labelSheetName";
139 | this.labelSheetName.Size = new System.Drawing.Size(95, 12);
140 | this.labelSheetName.TabIndex = 0;
141 | this.labelSheetName.Text = "“未选择Sheet”";
142 | //
143 | // radioButtonUpdateOnly
144 | //
145 | this.radioButtonUpdateOnly.AutoSize = true;
146 | this.radioButtonUpdateOnly.ForeColor = System.Drawing.Color.DarkViolet;
147 | this.radioButtonUpdateOnly.Location = new System.Drawing.Point(6, 153);
148 | this.radioButtonUpdateOnly.Name = "radioButtonUpdateOnly";
149 | this.radioButtonUpdateOnly.Size = new System.Drawing.Size(89, 16);
150 | this.radioButtonUpdateOnly.TabIndex = 6;
151 | this.radioButtonUpdateOnly.TabStop = true;
152 | this.radioButtonUpdateOnly.Text = "Update-Only";
153 | this.radioButtonUpdateOnly.UseVisualStyleBackColor = true;
154 | this.radioButtonUpdateOnly.CheckedChanged += new System.EventHandler(this.radioButtonUpdateOnly_CheckedChanged);
155 | //
156 | // textBoxTableNum
157 | //
158 | this.textBoxTableNum.Location = new System.Drawing.Point(164, 68);
159 | this.textBoxTableNum.Maximum = new decimal(new int[] {
160 | 9,
161 | 0,
162 | 0,
163 | 0});
164 | this.textBoxTableNum.Minimum = new decimal(new int[] {
165 | 1,
166 | 0,
167 | 0,
168 | 0});
169 | this.textBoxTableNum.Name = "textBoxTableNum";
170 | this.textBoxTableNum.Size = new System.Drawing.Size(38, 21);
171 | this.textBoxTableNum.TabIndex = 0;
172 | this.textBoxTableNum.Value = new decimal(new int[] {
173 | 1,
174 | 0,
175 | 0,
176 | 0});
177 | //
178 | // labelTableNum
179 | //
180 | this.labelTableNum.AutoSize = true;
181 | this.labelTableNum.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
182 | this.labelTableNum.ForeColor = System.Drawing.Color.Blue;
183 | this.labelTableNum.Location = new System.Drawing.Point(6, 69);
184 | this.labelTableNum.Name = "labelTableNum";
185 | this.labelTableNum.Size = new System.Drawing.Size(152, 16);
186 | this.labelTableNum.TabIndex = 0;
187 | this.labelTableNum.Text = "-请选择第1~9张表:";
188 | //
189 | // labelSqlType
190 | //
191 | this.labelSqlType.AutoSize = true;
192 | this.labelSqlType.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
193 | this.labelSqlType.ForeColor = System.Drawing.SystemColors.ControlText;
194 | this.labelSqlType.Location = new System.Drawing.Point(6, 107);
195 | this.labelSqlType.Name = "labelSqlType";
196 | this.labelSqlType.Size = new System.Drawing.Size(155, 12);
197 | this.labelSqlType.TabIndex = 0;
198 | this.labelSqlType.Text = "-请选择要生成的语句类型:";
199 | this.labelSqlType.TextAlign = System.Drawing.ContentAlignment.TopRight;
200 | //
201 | // radioButtonDelete
202 | //
203 | this.radioButtonDelete.AutoSize = true;
204 | this.radioButtonDelete.Location = new System.Drawing.Point(240, 122);
205 | this.radioButtonDelete.Name = "radioButtonDelete";
206 | this.radioButtonDelete.Size = new System.Drawing.Size(59, 16);
207 | this.radioButtonDelete.TabIndex = 4;
208 | this.radioButtonDelete.TabStop = true;
209 | this.radioButtonDelete.Text = "Delete";
210 | this.radioButtonDelete.UseVisualStyleBackColor = true;
211 | this.radioButtonDelete.CheckedChanged += new System.EventHandler(this.radioButtonDelete_CheckedChanged);
212 | //
213 | // radioButtonUpdate
214 | //
215 | this.radioButtonUpdate.AutoSize = true;
216 | this.radioButtonUpdate.Location = new System.Drawing.Point(141, 122);
217 | this.radioButtonUpdate.Name = "radioButtonUpdate";
218 | this.radioButtonUpdate.Size = new System.Drawing.Size(59, 16);
219 | this.radioButtonUpdate.TabIndex = 3;
220 | this.radioButtonUpdate.TabStop = true;
221 | this.radioButtonUpdate.Text = "Update";
222 | this.radioButtonUpdate.UseVisualStyleBackColor = true;
223 | this.radioButtonUpdate.CheckedChanged += new System.EventHandler(this.radioButtonUpdate_CheckedChanged);
224 | //
225 | // radioButtonInsert
226 | //
227 | this.radioButtonInsert.AutoSize = true;
228 | this.radioButtonInsert.Location = new System.Drawing.Point(6, 122);
229 | this.radioButtonInsert.Name = "radioButtonInsert";
230 | this.radioButtonInsert.Size = new System.Drawing.Size(95, 16);
231 | this.radioButtonInsert.TabIndex = 2;
232 | this.radioButtonInsert.TabStop = true;
233 | this.radioButtonInsert.Text = "Insert-Multi";
234 | this.radioButtonInsert.UseVisualStyleBackColor = true;
235 | this.radioButtonInsert.CheckedChanged += new System.EventHandler(this.radioButtonInsert_CheckedChanged);
236 | //
237 | // labelVersion
238 | //
239 | this.labelVersion.AutoSize = true;
240 | this.labelVersion.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
241 | this.labelVersion.ForeColor = System.Drawing.Color.Red;
242 | this.labelVersion.Location = new System.Drawing.Point(252, 17);
243 | this.labelVersion.Name = "labelVersion";
244 | this.labelVersion.Size = new System.Drawing.Size(120, 16);
245 | this.labelVersion.TabIndex = 0;
246 | this.labelVersion.Text = "“未选取文件”";
247 | //
248 | // labelInfo
249 | //
250 | this.labelInfo.AutoSize = true;
251 | this.labelInfo.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
252 | this.labelInfo.ForeColor = System.Drawing.Color.Blue;
253 | this.labelInfo.Location = new System.Drawing.Point(6, 17);
254 | this.labelInfo.Name = "labelInfo";
255 | this.labelInfo.Size = new System.Drawing.Size(248, 16);
256 | this.labelInfo.TabIndex = 0;
257 | this.labelInfo.Text = "-请选择您想要引用的EXCEL文件:";
258 | //
259 | // textBoxSelect
260 | //
261 | this.textBoxSelect.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
262 | this.textBoxSelect.Location = new System.Drawing.Point(3, 43);
263 | this.textBoxSelect.MaxLength = 255;
264 | this.textBoxSelect.Name = "textBoxSelect";
265 | this.textBoxSelect.Size = new System.Drawing.Size(555, 23);
266 | this.textBoxSelect.TabIndex = 1;
267 | this.textBoxSelect.MouseClick += new System.Windows.Forms.MouseEventHandler(this.textBox_TextChanged);
268 | //
269 | // groupBoxTxt
270 | //
271 | this.groupBoxTxt.Controls.Add(this.button1);
272 | this.groupBoxTxt.Controls.Add(this.buttonGroupMixedOne);
273 | this.groupBoxTxt.Controls.Add(this.buttonDataTrim);
274 | this.groupBoxTxt.Controls.Add(this.linkLabelHelpInfo);
275 | this.groupBoxTxt.Controls.Add(this.numericUpDownGroupRules);
276 | this.groupBoxTxt.Controls.Add(this.labelGroupRules);
277 | this.groupBoxTxt.Controls.Add(this.labelNewData);
278 | this.groupBoxTxt.Controls.Add(this.labelRawData);
279 | this.groupBoxTxt.Controls.Add(this.numericUpDownNewData);
280 | this.groupBoxTxt.Controls.Add(this.numericUpDownRawData);
281 | this.groupBoxTxt.Location = new System.Drawing.Point(12, 210);
282 | this.groupBoxTxt.Name = "groupBoxTxt";
283 | this.groupBoxTxt.Size = new System.Drawing.Size(564, 107);
284 | this.groupBoxTxt.TabIndex = 0;
285 | this.groupBoxTxt.TabStop = false;
286 | this.groupBoxTxt.Text = "excel数据二维化集中";
287 | //
288 | // buttonGroupMixedOne
289 | //
290 | this.buttonGroupMixedOne.Location = new System.Drawing.Point(9, 78);
291 | this.buttonGroupMixedOne.Name = "buttonGroupMixedOne";
292 | this.buttonGroupMixedOne.Size = new System.Drawing.Size(160, 23);
293 | this.buttonGroupMixedOne.TabIndex = 3;
294 | this.buttonGroupMixedOne.Text = "数据同类合并(反)";
295 | this.buttonGroupMixedOne.UseVisualStyleBackColor = true;
296 | this.buttonGroupMixedOne.Click += new System.EventHandler(this.buttonGroupMixedOne_Click);
297 | //
298 | // buttonDataTrim
299 | //
300 | this.buttonDataTrim.Location = new System.Drawing.Point(398, 78);
301 | this.buttonDataTrim.Name = "buttonDataTrim";
302 | this.buttonDataTrim.Size = new System.Drawing.Size(160, 23);
303 | this.buttonDataTrim.TabIndex = 2;
304 | this.buttonDataTrim.Text = "开始数据整理(正)";
305 | this.buttonDataTrim.UseVisualStyleBackColor = true;
306 | this.buttonDataTrim.Click += new System.EventHandler(this.buttonDataTrim_Click);
307 | //
308 | // linkLabelHelpInfo
309 | //
310 | this.linkLabelHelpInfo.AutoSize = true;
311 | this.linkLabelHelpInfo.Location = new System.Drawing.Point(385, 52);
312 | this.linkLabelHelpInfo.Name = "linkLabelHelpInfo";
313 | this.linkLabelHelpInfo.Size = new System.Drawing.Size(173, 12);
314 | this.linkLabelHelpInfo.TabIndex = 0;
315 | this.linkLabelHelpInfo.TabStop = true;
316 | this.linkLabelHelpInfo.Text = "请先选择文档并指定第几张表格";
317 | this.linkLabelHelpInfo.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabelHelpInfo_LinkClicked);
318 | //
319 | // numericUpDownGroupRules
320 | //
321 | this.numericUpDownGroupRules.Location = new System.Drawing.Point(284, 50);
322 | this.numericUpDownGroupRules.Maximum = new decimal(new int[] {
323 | 5,
324 | 0,
325 | 0,
326 | 0});
327 | this.numericUpDownGroupRules.Minimum = new decimal(new int[] {
328 | 1,
329 | 0,
330 | 0,
331 | 0});
332 | this.numericUpDownGroupRules.Name = "numericUpDownGroupRules";
333 | this.numericUpDownGroupRules.ReadOnly = true;
334 | this.numericUpDownGroupRules.Size = new System.Drawing.Size(38, 21);
335 | this.numericUpDownGroupRules.TabIndex = 0;
336 | this.numericUpDownGroupRules.Value = new decimal(new int[] {
337 | 1,
338 | 0,
339 | 0,
340 | 0});
341 | //
342 | // labelGroupRules
343 | //
344 | this.labelGroupRules.AutoSize = true;
345 | this.labelGroupRules.Location = new System.Drawing.Point(9, 52);
346 | this.labelGroupRules.Name = "labelGroupRules";
347 | this.labelGroupRules.Size = new System.Drawing.Size(269, 12);
348 | this.labelGroupRules.TabIndex = 0;
349 | this.labelGroupRules.Text = "处理数据依据基准列(维持与原始数据列一致):";
350 | //
351 | // labelNewData
352 | //
353 | this.labelNewData.AutoSize = true;
354 | this.labelNewData.Location = new System.Drawing.Point(295, 22);
355 | this.labelNewData.Name = "labelNewData";
356 | this.labelNewData.Size = new System.Drawing.Size(125, 12);
357 | this.labelNewData.TabIndex = 0;
358 | this.labelNewData.Text = "处理结束新数据列数:";
359 | //
360 | // labelRawData
361 | //
362 | this.labelRawData.AutoSize = true;
363 | this.labelRawData.Location = new System.Drawing.Point(9, 22);
364 | this.labelRawData.Name = "labelRawData";
365 | this.labelRawData.Size = new System.Drawing.Size(185, 12);
366 | this.labelRawData.TabIndex = 0;
367 | this.labelRawData.Text = "原始数据列数统计(限30以内):";
368 | //
369 | // numericUpDownNewData
370 | //
371 | this.numericUpDownNewData.Location = new System.Drawing.Point(426, 20);
372 | this.numericUpDownNewData.Maximum = new decimal(new int[] {
373 | 9,
374 | 0,
375 | 0,
376 | 0});
377 | this.numericUpDownNewData.Minimum = new decimal(new int[] {
378 | 2,
379 | 0,
380 | 0,
381 | 0});
382 | this.numericUpDownNewData.Name = "numericUpDownNewData";
383 | this.numericUpDownNewData.ReadOnly = true;
384 | this.numericUpDownNewData.Size = new System.Drawing.Size(38, 21);
385 | this.numericUpDownNewData.TabIndex = 0;
386 | this.numericUpDownNewData.Value = new decimal(new int[] {
387 | 2,
388 | 0,
389 | 0,
390 | 0});
391 | //
392 | // numericUpDownRawData
393 | //
394 | this.numericUpDownRawData.Location = new System.Drawing.Point(200, 20);
395 | this.numericUpDownRawData.Maximum = new decimal(new int[] {
396 | 30,
397 | 0,
398 | 0,
399 | 0});
400 | this.numericUpDownRawData.Minimum = new decimal(new int[] {
401 | 3,
402 | 0,
403 | 0,
404 | 0});
405 | this.numericUpDownRawData.Name = "numericUpDownRawData";
406 | this.numericUpDownRawData.Size = new System.Drawing.Size(38, 21);
407 | this.numericUpDownRawData.TabIndex = 0;
408 | this.numericUpDownRawData.Value = new decimal(new int[] {
409 | 3,
410 | 0,
411 | 0,
412 | 0});
413 | //
414 | // button1
415 | //
416 | this.button1.Location = new System.Drawing.Point(175, 78);
417 | this.button1.Name = "button1";
418 | this.button1.Size = new System.Drawing.Size(23, 23);
419 | this.button1.TabIndex = 4;
420 | this.button1.Text = "?";
421 | this.button1.UseVisualStyleBackColor = true;
422 | this.button1.Click += new System.EventHandler(this.button1_Click);
423 | //
424 | // FormMain
425 | //
426 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
427 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
428 | this.ClientSize = new System.Drawing.Size(588, 328);
429 | this.Controls.Add(this.groupBoxTxt);
430 | this.Controls.Add(this.groupBoxExcel);
431 | this.Name = "FormMain";
432 | this.Text = "Excel表格自转SQL增删改语句工具";
433 | this.HelpRequested += new System.Windows.Forms.HelpEventHandler(this.showHelpForTools);
434 | this.groupBoxExcel.ResumeLayout(false);
435 | this.groupBoxExcel.PerformLayout();
436 | ((System.ComponentModel.ISupportInitialize)(this.textBoxTableNum)).EndInit();
437 | this.groupBoxTxt.ResumeLayout(false);
438 | this.groupBoxTxt.PerformLayout();
439 | ((System.ComponentModel.ISupportInitialize)(this.numericUpDownGroupRules)).EndInit();
440 | ((System.ComponentModel.ISupportInitialize)(this.numericUpDownNewData)).EndInit();
441 | ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRawData)).EndInit();
442 | this.ResumeLayout(false);
443 |
444 | }
445 |
446 | #endregion
447 |
448 | private System.Windows.Forms.Button buttonCreate;
449 | private System.Windows.Forms.GroupBox groupBoxExcel;
450 | private System.Windows.Forms.RadioButton radioButtonInsertPerLine;
451 | private System.Windows.Forms.TextBox textBoxUpdateOnly;
452 | private System.Windows.Forms.Label label_Only;
453 | private System.Windows.Forms.Label labelSheetName;
454 | private System.Windows.Forms.RadioButton radioButtonUpdateOnly;
455 | private System.Windows.Forms.NumericUpDown textBoxTableNum;
456 | private System.Windows.Forms.Label labelTableNum;
457 | private System.Windows.Forms.Label labelSqlType;
458 | private System.Windows.Forms.RadioButton radioButtonDelete;
459 | private System.Windows.Forms.RadioButton radioButtonUpdate;
460 | private System.Windows.Forms.RadioButton radioButtonInsert;
461 | private System.Windows.Forms.Label labelVersion;
462 | private System.Windows.Forms.Label labelInfo;
463 | private System.Windows.Forms.TextBox textBoxSelect;
464 | private System.Windows.Forms.GroupBox groupBoxTxt;
465 | private System.Windows.Forms.NumericUpDown numericUpDownRawData;
466 | private System.Windows.Forms.NumericUpDown numericUpDownNewData;
467 | private System.Windows.Forms.Label labelRawData;
468 | private System.Windows.Forms.Label labelNewData;
469 | private System.Windows.Forms.Label labelGroupRules;
470 | private System.Windows.Forms.NumericUpDown numericUpDownGroupRules;
471 | private System.Windows.Forms.LinkLabel linkLabelHelpInfo;
472 | private System.Windows.Forms.Button buttonDataTrim;
473 | private System.Windows.Forms.Button buttonGroupMixedOne;
474 | private System.Windows.Forms.Button button1;
475 | }
476 | }
477 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/FormMain.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Windows.Forms;
9 | using System.Data.OleDb;
10 | using System.IO;
11 |
12 |
13 | namespace SQLLangCreateTooling
14 | {
15 | public partial class FormMain : Form
16 | {
17 | ///
18 | /// defaultSqlType当前选择的SQL语句类别,3214分别表示Update、Delete、Insert、Up-Only
19 | ///
20 | private static int defaultSqlType = 1;
21 |
22 | ///
23 | /// thisYourFirstTap记录用户操作次数。
24 | ///
25 | private static int thisYourFirstTap = 1;
26 |
27 | ///
28 | /// defaultTables默认引用第几张Sheet表的数据,可理解为用户引用第0张表默认。
29 | ///
30 | public static int defaultTables = 0;
31 |
32 | ///
33 | /// selectTableName当前选中的Sheet表的表名,如“Sheet1”。
34 | ///
35 | public static string selectTableName = "";
36 |
37 | ///
38 | /// primaryKeyName手动定义数据库某表主键名,仅在Up-Only方法中用到该字段。
39 | ///
40 | public static string primaryKeyName = "";
41 |
42 | ///
43 | /// isSqlLangCreatedSuccessful默认为生成语句失败,当成功后全局变量值变为1。
44 | ///
45 | public static bool isSqlLangCreatedSuccessful = false;
46 |
47 |
48 | public FormMain()
49 | {
50 | InitializeComponent();
51 | this.radioButtonInsert.Checked = true;
52 | this.textBoxUpdateOnly.ReadOnly = true;
53 | }
54 |
55 |
56 | private void textBox_TextChanged(object sender, MouseEventArgs e)
57 | {
58 | OpenFileDialog ofd = new OpenFileDialog(); //new一个方法
59 |
60 | //"(*.et;*.xls;*.xlsx)|*.et;*.xls;*.xlsx|all|*.*"---------------如果要多种选择
61 | ofd.Filter = "(*.xls;*.xlsx)|*.xls;*.xlsx";//删选、设定文件显示类型
62 | ofd.ShowDialog(); //显示打开文件的窗口
63 | this.textBoxSelect.Text = ofd.FileName; //获得选择的文件路径
64 |
65 | #region //修改 labelVersion 的字串显示
66 |
67 | int filesType = fileTypesOrExcelTypes(this.textBoxSelect.Text);
68 | if (filesType > 0)
69 | {
70 | if (filesType == 2003)
71 | this.labelVersion.Text = "Excel-2003格式";
72 | else if (filesType == 2007)
73 | {
74 | this.labelVersion.Text = "Excel-2007格式";
75 | }
76 | else
77 | this.labelVersion.Text = "\"不可识别文件\"";
78 | }
79 | else
80 | this.labelVersion.Text = "\"未选取文件\"";
81 | #endregion
82 | }
83 |
84 |
85 | private void buttonCreate_Click(object sender, EventArgs e)
86 | {
87 | whichTablesSelect();
88 |
89 | int fileTypes = fileTypesOrExcelTypes(this.textBoxSelect.Text);
90 | primaryKeyName = this.textBoxUpdateOnly.Text;
91 |
92 | if (fileTypes > 0)
93 | {
94 | try
95 | {
96 | NPOIExcelFilesRead.npoiPrintSQLLangTypesAndMethods(this.textBoxSelect.Text, fileTypes, defaultSqlType);
97 |
98 | this.labelSheetName.Text = "表格名为:“" + selectTableName + "”";
99 |
100 | if (isSqlLangCreatedSuccessful)
101 | {
102 | MessageBox.Show("语句生成成功,程序处理完毕!", "温馨提示",
103 | MessageBoxButtons.OK, MessageBoxIcon.Information);
104 | }
105 | }
106 | catch
107 | {
108 | }
109 |
110 | }
111 | else
112 | #region //调戏用户的提示框,前面两次会提醒用户需要引入文件,后续不再提醒
113 | {
114 | if (thisYourFirstTap == 1)
115 | {
116 | MessageBox.Show("亲,您给哥选一个EXCEL文件再戳好不-,-!!!", "重要提醒",
117 | MessageBoxButtons.OK, MessageBoxIcon.Information);
118 | thisYourFirstTap += 1;
119 | }
120 | else if (thisYourFirstTap == 2)
121 | {
122 | MessageBox.Show("亲,再戳不理你了,哼~~ -,-!!!", "重要警告",
123 | MessageBoxButtons.OK, MessageBoxIcon.Information);
124 | thisYourFirstTap += 1;
125 | }
126 | }
127 | #endregion //调戏动作结束
128 | }
129 |
130 |
131 | ///
132 | /// 判断当前文件的类型,是否为Excel文件、判定excel版本。
133 | ///
134 | /// 文件完整的路径名,“D:\\test.xls”
135 | /// int整型类型;2003表示2003及以前Office版Excel文件。2007表示2007及以后Office版Excel文件,后缀名通常为“.xlsx”。0其它文件类型,-1表示非有效文件或路径名。
136 | private int fileTypesOrExcelTypes(string str)
137 | {
138 | if (str != "")
139 | {
140 | FileInfo files = new FileInfo(str);
141 |
142 | if (files.Exists == true)
143 | {
144 | //string matchExcel = ".xls$|.xlsx$";//正则表达式方法
145 | if (str.EndsWith(".xls"))
146 | return 2003;
147 | else if (str.EndsWith(".xlsx"))
148 | return 2007;
149 | else
150 | return 0;
151 | }
152 | else
153 | return -1;
154 | }
155 | else
156 | return -1;
157 | }
158 |
159 |
160 | private void radioButtonInsert_CheckedChanged(object sender, EventArgs e)
161 | {
162 | defaultSqlType = 1;
163 | this.textBoxUpdateOnly.ReadOnly = true;
164 | }
165 |
166 |
167 | private void radioButtonUpdate_CheckedChanged(object sender, EventArgs e)
168 | {
169 | defaultSqlType = 3;
170 | this.textBoxUpdateOnly.ReadOnly = true;
171 | }
172 |
173 |
174 | private void radioButtonDelete_CheckedChanged(object sender, EventArgs e)
175 | {
176 | defaultSqlType = 2;
177 | this.textBoxUpdateOnly.ReadOnly = true;
178 |
179 | }
180 |
181 |
182 | private void radioButtonUpdateOnly_CheckedChanged(object sender, EventArgs e)
183 | {
184 | defaultSqlType = 4;
185 | this.textBoxUpdateOnly.ReadOnly = false;
186 | }
187 |
188 |
189 | #region //旧的代码,OleDbConnection方式,OLEDB方法打开Excel文档;已经弃用的代码。
190 | private void createLangByType(int num, DataSet getDataSet)
191 | {
192 | switch (defaultSqlType)
193 | {
194 | case 1:
195 | CreateTextFromExcelNow.printSQLLangInsert(getDataSet);
196 | break;
197 | case 2:
198 | CreateTextFromExcelNow.printSQLLangDelete(getDataSet);
199 | break;
200 | case 3:
201 | CreateTextFromExcelNow.printSQLLangUpdate(getDataSet);
202 | break;
203 | case 4:
204 | CreateTextFromExcelNow.printSQLLangUpdateOnly(getDataSet);
205 | break;
206 | default:
207 | break;
208 |
209 | }
210 | }
211 |
212 |
213 | private void whichTablesSelect()
214 | {
215 | if (this.textBoxTableNum.Text == "")
216 | {
217 | defaultTables = 0;
218 | }
219 | else
220 | {
221 | try
222 | {
223 | System.Text.RegularExpressions.Regex rex =
224 | new System.Text.RegularExpressions.Regex(@"^\d{1}$");
225 |
226 | if (rex.IsMatch(this.textBoxTableNum.Text))
227 | {
228 | defaultTables = Convert.ToInt32(this.textBoxTableNum.Text);
229 | if (defaultTables > 0)
230 | {
231 | defaultTables = defaultTables - 1;//传统意义上认为最前面的为第一张表!
232 | }
233 | }
234 | }
235 | catch
236 | {
237 | //报错就报错吧,哥懒得理它。
238 | }
239 | }
240 | }
241 |
242 |
243 | private void testToExcel(string filePath)
244 | {
245 | try
246 | {
247 | string strConn;
248 | if (filePath.EndsWith(".xls")) //Excel格式为2003版本
249 | {
250 | strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath +
251 | ";Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1\""; //HDR=YES;那么第一行数据获取不到!
252 | }
253 | else if (filePath.EndsWith(".xlsx")) //Excel格式为2007或以上版本
254 | {
255 | strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath +
256 | ";Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1\"";
257 | }
258 | else
259 | {
260 | return;// null;//如果走到这里干脆自杀掉 -,-!!!.反正不知道怎么处理.
261 | }
262 |
263 | OleDbConnection oleConn = new OleDbConnection(strConn);
264 | oleConn.Open();
265 |
266 | System.Data.DataTable schemaTable = oleConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables,
267 | new object[] { null, null, null, "TABLE" });
268 | string tableName = schemaTable.Rows[1]["TABLE_NAME"].ToString().Trim();//这里表示第几张表格!
269 |
270 | String sql = "SELECT * FROM [" + tableName + "]";//可以是更改Sheet名称,比如sheet2,等等
271 | OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, oleConn);
272 |
273 | DataSet OleDsExcle = new DataSet();
274 | OleDaExcel.Fill(OleDsExcle, tableName);
275 |
276 | oleConn.Close();
277 |
278 | int hangY = OleDsExcle.Tables[1].Rows.Count;
279 | hangY = OleDsExcle.Tables[1].Rows.Count;
280 | hangY = OleDsExcle.Tables[2].Rows.Count;
281 |
282 | return;// OleDsExcle;
283 | }
284 | catch (Exception err)
285 | {
286 | MessageBox.Show("数据绑定Excel失败!失败原因:" + err.Message, "提示信息",
287 | MessageBoxButtons.OK, MessageBoxIcon.Information);
288 | return;// null;
289 | }
290 | }
291 |
292 |
293 | //如果连接字符串不对,有可能出现"Could not find installable ISAM ” Exception
294 | private string GetConnectionString(string fileName)
295 | {
296 | string connectString = "";
297 | //xls文件的连接字符串
298 | if (fileName.EndsWith(".xls")) //Excel格式为2003版本
299 | {
300 | connectString =
301 | @" Provider=Microsoft.Jet.OLEDB.4.0;" +
302 | @" Data Source=" + fileName + ";" +
303 | @" Extended Properties=" + Convert.ToChar(34).ToString() +
304 | @" Excel 8.0;" + Convert.ToChar(34).ToString();
305 | }
306 | //xlsx,Excel 2007文件的连接字符串
307 | else if (fileName.EndsWith(".xlsx")) //Excel格式为2007或以上版本
308 | {
309 | connectString =
310 | @" Provider=Microsoft.ACE.OLEDB.12.0;" +
311 | @" Data Source=" + fileName + ";" +
312 | @" Extended Properties=" + Convert.ToChar(34).ToString() +
313 | @" Excel 12.0;" + Convert.ToChar(34).ToString();
314 | }
315 | /* 旧的写法可能有问题,见:
316 | * private void testToExcel(string filePath)
317 | */
318 |
319 | return connectString;
320 | }
321 |
322 |
323 | private DataSet created_SQL_Lang_FromExcelFile(string filePath)
324 | {
325 | /**
326 | * filePath = "E:\\QQ_File\\10.22.xls";
327 | * filePath = filePath.Replace("\\","\\\\");//这里原字串中已经有两道杠了
328 | **/
329 | try
330 | {
331 | string strConn;
332 | string tableName;
333 |
334 | strConn = GetConnectionString(filePath);
335 |
336 | OleDbConnection oleConn = new OleDbConnection(strConn);
337 | oleConn.Open();//开启SQL服务还是报错.....
338 |
339 | System.Data.DataTable schemaTable = oleConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables,
340 | new object[] { null, null, null, "TABLE" });
341 | try
342 | {
343 | tableName = schemaTable.Rows[defaultTables]["TABLE_NAME"].ToString().Trim();
344 |
345 | String sql = "SELECT * FROM [" + tableName + "]";//可以是更改Sheet名称,比如sheet2,等等
346 | OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, oleConn);
347 |
348 | DataSet OleDsExcle = new DataSet();
349 | OleDaExcel.Fill(OleDsExcle, tableName);
350 |
351 | createLangByType(defaultSqlType, OleDsExcle);
352 |
353 | oleConn.Close();
354 |
355 | //提醒用户已经生成数据完毕!
356 | MessageBox.Show("文件已经生成或追加完毕,请注意查看!", "完成提示",
357 | MessageBoxButtons.OK, MessageBoxIcon.Information);
358 |
359 | //return OleDsExcle;
360 | return null;
361 | }
362 | catch
363 | {
364 | int trueTables = defaultTables + 1;
365 | MessageBox.Show("第" + trueTables + "张表不存在或无法读取!", "温馨提示",
366 | MessageBoxButtons.OK, MessageBoxIcon.Information);
367 | return null;
368 | }
369 | }
370 | catch
371 | {
372 | MessageBox.Show("读取Excel数据失败!表格内容为空或无法识别。\n请确认数据有效性!", "温馨提示",
373 | MessageBoxButtons.OK, MessageBoxIcon.Information);
374 | return null;
375 | }
376 | }
377 | #endregion //旧的代码结束
378 |
379 |
380 | private void showHelpForTools(object sender, HelpEventArgs hlpevent)
381 | {
382 | MessageBox.Show("软件如有问题,请与我联系,https://github.com/YamazakyLau/SQLLangCreateTooling.git \n非诚勿扰!", "亲,哥终于找到你了!",
383 | MessageBoxButtons.OK, MessageBoxIcon.Information);
384 | }
385 |
386 |
387 | private void textBoxTableNum_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
388 | {
389 | e.Handled = true;//阻止输入
390 |
391 | //例外情形,数字或删除键
392 | if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar == (char)8))
393 | {
394 | e.Handled = false;
395 | }
396 | }
397 |
398 |
399 | private void radioButtonInsertPerLine_CheckedChanged(object sender, EventArgs e)
400 | {
401 | defaultSqlType = 5;
402 | this.textBoxUpdateOnly.ReadOnly = true;
403 | }
404 |
405 |
406 | private void linkLabelHelpInfo_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
407 | {
408 | this.textBoxTableNum.Focus();
409 | }
410 |
411 |
412 | private void buttonDataTrim_Click(object sender, EventArgs e)
413 | {
414 | whichTablesSelect();
415 | //因为我将允许表格不齐整,且允许行中间出现无数据内容单元格,所以先要表明最大列数!
416 | NPOIExcelDataTrim.whichDataTrimStyle(this.numericUpDownRawData.Text);
417 |
418 | int fileTypes = fileTypesOrExcelTypes(this.textBoxSelect.Text);
419 |
420 | if (fileTypes > 0)
421 | {
422 | try
423 | {
424 | NPOIExcelDataTrim.npoiTrimTypesAndMethods(this.textBoxSelect.Text, fileTypes, defaultTables);
425 |
426 | this.labelSheetName.Text = "表格名为:“" + selectTableName + "”";
427 |
428 | if (isSqlLangCreatedSuccessful)
429 | {
430 | MessageBox.Show("数据整理成功,程序处理完毕!", "温馨提示",
431 | MessageBoxButtons.OK, MessageBoxIcon.Information);
432 | }
433 | }
434 | catch { }
435 | }
436 | }
437 |
438 |
439 | private void buttonGroupMixedOne_Click(object sender, EventArgs e)
440 | {
441 | whichTablesSelect();
442 | //因为我将允许表格不齐整,且允许行中间出现无数据内容单元格,所以先要表明最大列数!
443 | NPOIExcelDataTrim.whichDataTrimStyle(this.numericUpDownRawData.Text);
444 |
445 | int fileTypes = fileTypesOrExcelTypes(this.textBoxSelect.Text);
446 |
447 | if (fileTypes > 0)
448 | {
449 | try
450 | {
451 | NPOIExcelDataTrim.npoiGroupMixedOneMethods(this.textBoxSelect.Text, fileTypes, defaultTables);
452 |
453 | this.labelSheetName.Text = "表格名为:“" + selectTableName + "”";
454 |
455 | if (isSqlLangCreatedSuccessful)
456 | {
457 | MessageBox.Show("数据整理成功,程序处理完毕!", "温馨提示",
458 | MessageBoxButtons.OK, MessageBoxIcon.Information);
459 | }
460 | }
461 | catch { }
462 | }
463 | }
464 |
465 |
466 | private void button1_Click(object sender, EventArgs e)
467 | {
468 | MessageBox.Show("数据合并帮助:\n1.合并时只针对第一列和第二列数据;\n2.请不要出现空白行单元格,否则过程会被中断;"
469 | + "\n3.结果会存储为TXT文档。", "使用帮助",MessageBoxButtons.OK, MessageBoxIcon.Information);
470 | }
471 |
472 |
473 | }
474 | }
475 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/FormMain.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/NPOIExcelDataTrim.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.IO;
6 | using System.Data;
7 | using NPOI.HSSF.UserModel;
8 | using NPOI.SS.UserModel;
9 | using NPOI.HSSF.Extractor;
10 | using NPOI.HPSF.Extractor;
11 | using OfficeOpenXml;
12 | using System.Windows.Forms;
13 |
14 | namespace SQLLangCreateTooling
15 | {
16 | class NPOIExcelDataTrim
17 | {
18 | ///
19 | /// rawDataTableMaxRows需要用户手动数一数该最大列数是多少。
20 | ///
21 | private static int rawDataTableMaxRows = 0;
22 |
23 |
24 | public static void npoiTrimTypesAndMethods(string filePath, int fileTypes, int defaultTables)
25 | {
26 | if (fileTypes == 2003)
27 | {
28 | try
29 | {
30 | FileStream fs = new FileStream(filePath, FileMode.Open);
31 |
32 | HSSFWorkbook HBook = new HSSFWorkbook(fs);
33 | ISheet isheet = HBook.GetSheetAt(FormMain.defaultTables);
34 |
35 | #region //回传当前读取的Sheet表名!
36 | FormMain.selectTableName = isheet.SheetName;
37 | #endregion
38 |
39 | npoiDataTrimMerge(isheet);
40 |
41 | //释放过程中使用的资源!
42 | HBook.Close();
43 | fs.Close();
44 | FormMain.isSqlLangCreatedSuccessful = true;
45 | }
46 | catch (Exception ex)
47 | {
48 | FormMain.isSqlLangCreatedSuccessful = false;
49 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
50 | MessageBoxButtons.OK, MessageBoxIcon.Information);
51 | return;
52 | }
53 | }
54 | else if (fileTypes == 2007)
55 | {
56 | try
57 | {
58 | ExcelPackage excelPackage;
59 |
60 | FileInfo newFile = new FileInfo(filePath);
61 | excelPackage = new ExcelPackage(newFile);
62 |
63 | ExcelWorkbook myWorkbook = excelPackage.Workbook;
64 | ExcelWorksheet myWorksheet = myWorkbook.Worksheets[FormMain.defaultTables + 1];
65 |
66 | #region //回传当前读取的Sheet表名!
67 | FormMain.selectTableName = myWorksheet.Name;
68 | #endregion
69 |
70 | excelPackageDataTrimMerge(myWorksheet);
71 |
72 | //貌似很有必要释放内存,不然没法连续执行,不关掉程序文档打不开。
73 | excelPackage.Dispose();
74 | FormMain.isSqlLangCreatedSuccessful = true;
75 | }
76 | catch (Exception ex)
77 | {
78 | FormMain.isSqlLangCreatedSuccessful = false;
79 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
80 | MessageBoxButtons.OK, MessageBoxIcon.Information);
81 | return;
82 | }
83 | }
84 |
85 | }
86 |
87 |
88 | public static void whichDataTrimStyle(string text)
89 | {
90 | if (text == "")
91 | {
92 | rawDataTableMaxRows = 0;
93 | }
94 | else
95 | {
96 | try
97 | {
98 | System.Text.RegularExpressions.Regex rex =
99 | new System.Text.RegularExpressions.Regex(@"\d{2}$|\d{1}$");
100 |
101 | if (rex.IsMatch(text))
102 | {
103 | rawDataTableMaxRows = Convert.ToInt32(text);
104 | }
105 | }
106 | catch
107 | {
108 | //报错就报错吧,哥懒得理它。
109 | }
110 | }
111 | }
112 |
113 |
114 | ///
115 | /// ExcelPackage组件方法生成将多列集合成两列。
116 | ///
117 | /// 引用ExcelPackage组件的某张Sheet表的数据内容
118 | ///
119 | private static void excelPackageDataTrimMerge(ExcelWorksheet myWorksheet)
120 | {
121 | int hangY = 1, lieXX = 1;
122 | string eStrHang = "", eStrLie = "";
123 |
124 | try
125 | {
126 | FileStream aFile = new FileStream("excelPackage-dataTrimMerge.txt", FileMode.Append);
127 | StreamWriter sw = new StreamWriter(aFile);
128 |
129 | /*
130 | * * line A likes; 小胖A 男 20岁 宅 木讷
131 | * output likes:
132 | * 小胖A 男
133 | * 小胖A 20岁
134 | * 小胖A 宅
135 | * 小胖A 木讷
136 | */
137 | eStrHang = myWorksheet.Cell(hangY, 1).Value;
138 | while (eStrHang != null && eStrHang != "")
139 | {
140 | string outPrint = "";
141 |
142 | while (lieXX <= rawDataTableMaxRows)
143 | {
144 | eStrLie = myWorksheet.Cell(hangY, lieXX).Value;
145 | if (eStrLie != null && eStrLie != "")
146 | {
147 | outPrint += eStrHang + "\t" + eStrLie + "\n"; //每行写一次不算多!
148 | }
149 | lieXX++;
150 | }
151 |
152 | hangY++;
153 | lieXX = 1;
154 | eStrHang = myWorksheet.Cell(hangY, 1).Value;
155 |
156 | // Write data to file.
157 | sw.WriteLine(outPrint);
158 | //清空缓冲区
159 | sw.Flush();
160 | }
161 |
162 | //结束写入
163 | sw.Close();
164 | aFile.Close();
165 | }
166 | catch
167 | {
168 | throw new ApplicationException();
169 | }
170 | }
171 |
172 |
173 | ///
174 | /// NPOI组件方法生成将多列集合成两列。
175 | ///
176 | /// 引用NPOI组件的某张Sheet表的数据内容
177 | ///
178 | private static void npoiDataTrimMerge(ISheet isheet)
179 | {
180 | int hangY = 0, lieXX = 1;
181 | string eStrHang = "", eStrLie = "";
182 |
183 | try
184 | {
185 | FileStream aFile = new FileStream("npoi-dataTrimMerge.txt", FileMode.Append);
186 | StreamWriter sw = new StreamWriter(aFile);
187 |
188 | /*
189 | * * line A likes; 小胖B 男 20岁 宅 木讷
190 | * output likes:
191 | * 小胖B 男
192 | * 小胖B 20岁
193 | * 小胖B 宅
194 | * 小胖B 木讷
195 | */
196 | while (hangY <= isheet.LastRowNum)
197 | {
198 | string outPrint = "";
199 |
200 | eStrHang = isheet.GetRow(hangY).Cells[0].ToString();
201 | while (lieXX < rawDataTableMaxRows)
202 | {
203 | eStrLie = isheet.GetRow(hangY).Cells[lieXX].ToString();
204 | if (eStrLie != null && eStrLie != "")
205 | {
206 | outPrint += eStrHang + "\t" + eStrLie + "\n"; //每行写一次不算多!
207 | }
208 | lieXX++;
209 | }
210 |
211 | hangY++;
212 | lieXX = 1;
213 |
214 | // Write data to file.
215 | sw.WriteLine(outPrint);
216 | //清空缓冲区
217 | sw.Flush();
218 | }
219 |
220 | //结束写入
221 | sw.Close();
222 | aFile.Close();
223 | }
224 | catch
225 | {
226 | throw new ApplicationException();
227 | }
228 | }
229 |
230 |
231 | public static void npoiGroupMixedOneMethods(string filePath, int fileTypes, int defaultTables)
232 | {
233 | if (fileTypes == 2003)
234 | {
235 | try
236 | {
237 | FileStream fs = new FileStream(filePath, FileMode.Open);
238 |
239 | HSSFWorkbook HBook = new HSSFWorkbook(fs);
240 | ISheet isheet = HBook.GetSheetAt(FormMain.defaultTables);
241 |
242 | #region //回传当前读取的Sheet表名!
243 | FormMain.selectTableName = isheet.SheetName;
244 | #endregion
245 |
246 | npoiDataGroupMixedOne(isheet);
247 |
248 | //释放过程中使用的资源!
249 | HBook.Close();
250 | fs.Close();
251 | FormMain.isSqlLangCreatedSuccessful = true;
252 | }
253 | catch (Exception ex)
254 | {
255 | FormMain.isSqlLangCreatedSuccessful = false;
256 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
257 | MessageBoxButtons.OK, MessageBoxIcon.Information);
258 | return;
259 | }
260 | }
261 | else if (fileTypes == 2007)
262 | {
263 | try
264 | {
265 | ExcelPackage excelPackage;
266 |
267 | FileInfo newFile = new FileInfo(filePath);
268 | excelPackage = new ExcelPackage(newFile);
269 |
270 | ExcelWorkbook myWorkbook = excelPackage.Workbook;
271 | ExcelWorksheet myWorksheet = myWorkbook.Worksheets[FormMain.defaultTables + 1];
272 |
273 | #region //回传当前读取的Sheet表名!
274 | FormMain.selectTableName = myWorksheet.Name;
275 | #endregion
276 |
277 | excelPackageDataGroupMixedOne(myWorksheet);
278 |
279 | //貌似很有必要释放内存,不然没法连续执行,不关掉程序文档打不开。
280 | excelPackage.Dispose();
281 | FormMain.isSqlLangCreatedSuccessful = true;
282 | }
283 | catch (Exception ex)
284 | {
285 | FormMain.isSqlLangCreatedSuccessful = false;
286 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
287 | MessageBoxButtons.OK, MessageBoxIcon.Information);
288 | return;
289 | }
290 | }
291 |
292 | }
293 |
294 |
295 | private static void excelPackageDataGroupMixedOne(ExcelWorksheet myWorksheet)
296 | {
297 | int hangY = 1;
298 | string eStrHang = "", eStrNext = "";
299 |
300 | try
301 | {
302 | FileStream aFile = new FileStream("excelPackage-dataGroupMixedOne.txt", FileMode.Append);
303 | StreamWriter sw = new StreamWriter(aFile);
304 |
305 | /*
306 | * raw datas like:
307 | * 小胖B 男
308 | * 小胖B 20岁
309 | * 小胖B 宅
310 | * 小胖B 木讷
311 | * After mix like:
312 | * 小胖B 男 20岁 宅 木讷
313 | */
314 | eStrNext = myWorksheet.Cell(hangY, 1).Value;
315 |
316 | while (eStrNext != null && eStrNext != "")
317 | {
318 | string outPrint = "";
319 |
320 | if (eStrNext == eStrHang)
321 | {
322 | outPrint += "\t" + myWorksheet.Cell(hangY, 2).Value;
323 | hangY++;
324 |
325 | // Write data to file.
326 | sw.Write(outPrint);
327 |
328 | if (myWorksheet.Cell(hangY, 1).Value != null)
329 | {
330 | eStrNext = myWorksheet.Cell(hangY, 1).Value;
331 | }
332 | else
333 | break;
334 | }
335 | else
336 | {
337 | eStrHang = myWorksheet.Cell(hangY, 1).Value;
338 | outPrint += "\t" + myWorksheet.Cell(hangY, 2).Value;
339 | hangY++;
340 |
341 | // Write data to file.
342 | sw.Write("\n" + eStrHang + outPrint);
343 |
344 | if (myWorksheet.Cell(hangY, 1).Value != null)
345 | {
346 | eStrNext = myWorksheet.Cell(hangY, 1).Value;
347 | }
348 | else
349 | continue;
350 | }
351 |
352 | //清空缓冲区
353 | sw.Flush();
354 | }
355 |
356 | //结束写入
357 | sw.Close();
358 | aFile.Close();
359 | }
360 | catch
361 | {
362 | throw new ApplicationException();
363 | }
364 | }
365 |
366 |
367 | private static void npoiDataGroupMixedOne(ISheet isheet)
368 | {
369 | int hangY = 0;
370 | string eStrHang = "", eStrNext = "";
371 |
372 | try
373 | {
374 | FileStream aFile = new FileStream("npoi-dataGroupMixedOne.txt", FileMode.Append);
375 | StreamWriter sw = new StreamWriter(aFile);
376 |
377 | /*
378 | * raw datas like:
379 | * 小胖B 男
380 | * 小胖B 20岁
381 | * 小胖B 宅
382 | * 小胖B 木讷
383 | * After mix like:
384 | * 小胖B 男 20岁 宅 木讷
385 | */
386 | eStrNext = isheet.GetRow(0).Cells[0].ToString();
387 |
388 | while (hangY <= isheet.LastRowNum)
389 | {
390 | string outPrint = "";
391 |
392 | if (eStrNext == eStrHang)
393 | {
394 | outPrint += "\t" + isheet.GetRow(hangY).Cells[1].ToString();
395 | hangY++;
396 |
397 | // Write data to file.
398 | sw.Write(outPrint);
399 |
400 | if (isheet.GetRow(hangY).Cells[0].ToString() != null)
401 | {
402 | eStrNext = isheet.GetRow(hangY).Cells[0].ToString();
403 | }
404 | else
405 | continue;
406 | }
407 | else
408 | {
409 | eStrHang = isheet.GetRow(hangY).Cells[0].ToString();
410 | outPrint += "\t" + isheet.GetRow(hangY).Cells[1].ToString();
411 | hangY++;
412 |
413 | // Write data to file.
414 | sw.Write("\n" + eStrHang + outPrint);
415 |
416 | if (hangY <= isheet.LastRowNum)
417 | {
418 | eStrNext = isheet.GetRow(hangY).Cells[0].ToString();
419 | }
420 | else
421 | break;
422 | }
423 |
424 | //清空缓冲区
425 | sw.Flush();
426 | }
427 |
428 | //结束写入
429 | sw.Close();
430 | aFile.Close();
431 | }
432 | catch
433 | {
434 | throw new ApplicationException();
435 | }
436 | }
437 | }
438 | }
439 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/NPOIExcelFilesRead.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.IO;
6 | using System.Data;
7 | using NPOI.HSSF.UserModel;
8 | using NPOI.SS.UserModel;
9 | using NPOI.HSSF.Extractor;
10 | using NPOI.HPSF.Extractor;
11 | using OfficeOpenXml;
12 | using System.Windows.Forms;
13 |
14 | namespace SQLLangCreateTooling
15 | {
16 | #region //推荐学习的注释
17 | /*
18 | *
19 | * 本例中只是简单的读取Excel文件并获取字符串,推荐扩展学习NPOI:
20 | * http://www.dotblogs.com.tw/killysss/archive/2010/01/27/13344.aspx
21 | * http://tonyqus.sinaapp.com/
22 | * ExcelPackage扩展:
23 | * http://excelpackage.codeplex.com/releases/view/1456
24 | * http://excelpackage.codeplex.com/
25 | */
26 | #endregion
27 |
28 | class NPOIExcelFilesRead
29 | {
30 | #region //测试读取Excel成功与否的方法代码
31 | ///
32 | /// 测试NPOI组件方法得到*.xls文件第一张‘Sheet’的内容;未被用到的方法。
33 | ///
34 | /// 文件完整的路径名,如D:\\test.xls
35 | /// 返回FileName第一张‘Sheet’的内容
36 | public static string npoiExtractStringTesting(string FileName)
37 | {
38 | try
39 | {
40 | FileInfo files = new FileInfo(FileName);
41 | using (FileStream fs = files.Open(FileMode.Open))
42 | {
43 | HSSFWorkbook HBook = new HSSFWorkbook(fs);
44 | ExcelExtractor extractor = new ExcelExtractor(HBook);
45 | return extractor.Text;
46 | }
47 |
48 | }
49 | catch
50 | {
51 | FormMain.isSqlLangCreatedSuccessful = false;
52 | return null;
53 | }
54 | }
55 |
56 | ///
57 | /// 测试ExcelPackage组件方法得到*.xlsx文件‘Sheet1’表中的第二行二列单元格内容;未被用到的方法。
58 | ///
59 | /// 文件完整的路径名,D:\\test.xls
60 | /// 返回FileName文件‘Sheet1’表中第二行二列单元格的内容
61 | public static string excelPackageExtractStringTesting(string FileName)
62 | {
63 | try
64 | {
65 | ExcelPackage excelPackage;
66 | string text = "";
67 |
68 | FileInfo template = new FileInfo(FileName);
69 | FileInfo newFile = new FileInfo(@"Test.xlsx");
70 | excelPackage = new ExcelPackage(newFile, template);
71 |
72 | ExcelWorkbook myWorkbook = excelPackage.Workbook;
73 | ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Sheet1"];
74 |
75 | //excelPackage.Save();
76 | text = myWorksheet.Cell(2, 2).Value;
77 |
78 | return text;
79 |
80 | }
81 | catch
82 | {
83 | FormMain.isSqlLangCreatedSuccessful = false;
84 | return null;
85 | }
86 | }
87 | #endregion //测试代码End
88 |
89 | ///
90 | /// 依据参数,选择生成SQL语言的方法。
91 | ///
92 | /// 文件完整的路径名,如D:\\test.xls
93 | /// 文件类型,如*.xls将会引用NPOI组件
94 | /// SQL语言类别,如Insert、Update、Delete、Up-Only
95 | ///
96 | public static void npoiPrintSQLLangTypesAndMethods(string filesPath, int filesTypes, int sqlLangTypes)
97 | {
98 | if(filesTypes == 2003)
99 | {
100 | #region //xls文件的处理
101 | try
102 | {
103 | FileStream fs = new FileStream(filesPath, FileMode.Open);
104 |
105 | HSSFWorkbook HBook = new HSSFWorkbook(fs);
106 | ISheet isheet = HBook.GetSheetAt(FormMain.defaultTables);
107 |
108 | #region //回传当前读取的Sheet表名!
109 | FormMain.selectTableName = isheet.SheetName;
110 | #endregion
111 |
112 | switch (sqlLangTypes)
113 | {
114 | case 1:
115 | npoiPrintSQLLangInsertMulti(isheet);
116 | break;
117 | case 2:
118 | npoiPrintSQLLangDelete(isheet);
119 | break;
120 | case 3:
121 | npoiPrintSQLLangUpdate(isheet);
122 | break;
123 | case 4:
124 | npoiPrintSQLLangUpdateOnly(isheet);
125 | break;
126 | case 5:
127 | npoiPrintSQLLangInsertEachLineASentence(isheet);
128 | break;
129 | default:
130 | break;
131 |
132 | }
133 |
134 | //释放过程中使用的资源!
135 | HBook.Close();
136 | fs.Close();
137 | FormMain.isSqlLangCreatedSuccessful = true;
138 | }
139 | catch (Exception ex)
140 | {
141 | FormMain.isSqlLangCreatedSuccessful = false;
142 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
143 | MessageBoxButtons.OK, MessageBoxIcon.Information);
144 | return;
145 | }
146 | #endregion
147 | }
148 | else if (filesTypes == 2007) //*.XLSX
149 | {
150 | try
151 | {
152 | ExcelPackage excelPackage;
153 |
154 | FileInfo newFile = new FileInfo(filesPath);
155 | excelPackage = new ExcelPackage(newFile);
156 |
157 | ExcelWorkbook myWorkbook = excelPackage.Workbook;
158 | ExcelWorksheet myWorksheet = myWorkbook.Worksheets[FormMain.defaultTables + 1];
159 |
160 | #region //回传当前读取的Sheet表名!
161 | FormMain.selectTableName = myWorksheet.Name;
162 | #endregion
163 |
164 | switch (sqlLangTypes)
165 | {
166 | case 1:
167 | excelPackagePrintSQLLangInsertMulti(myWorksheet);
168 | break;
169 | case 2:
170 | excelPackagePrintSQLLangDelete(myWorksheet);
171 | break;
172 | case 3:
173 | excelPackagePrintSQLLangUpdate(myWorksheet);
174 | break;
175 | case 4:
176 | excelPackagePrintSQLLangUpdateOnly(myWorksheet);
177 | break;
178 | case 5:
179 | excelPackagePrintSQLLangInsertEachLineASentence(myWorksheet);
180 | break;
181 | default:
182 | break;
183 |
184 | }
185 |
186 | //貌似很有必要释放内存,不然没法连续执行,不关掉程序文档打不开。
187 | excelPackage.Dispose();
188 | FormMain.isSqlLangCreatedSuccessful = true;
189 | }
190 | catch (Exception ex)
191 | {
192 | FormMain.isSqlLangCreatedSuccessful = false;
193 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
194 | MessageBoxButtons.OK, MessageBoxIcon.Information);
195 | return;
196 | }
197 | }
198 | }
199 |
200 |
201 | #region //excelPackage读取数据库的方法--start--
202 | ///
203 | /// ExcelPackage组件方法生成UpdateOnly语句。
204 | ///
205 | /// 引用ExcelPackage组件的某张Sheet表的数据内容
206 | ///
207 | private static void excelPackagePrintSQLLangUpdateOnly(ExcelWorksheet myWorksheet)
208 | {
209 | int hangY = 1, lieXX = 1;
210 | string eCellStr = "";
211 | string basicStr = "UPDATE ";
212 |
213 | eCellStr = myWorksheet.Cell(1, 1).Value;
214 |
215 | while (eCellStr != null && eCellStr != "")
216 | {
217 | lieXX++;
218 | eCellStr = myWorksheet.Cell(1, lieXX).Value;
219 | }
220 |
221 | eCellStr = myWorksheet.Cell(1, 1).Value;
222 | while (eCellStr != null && eCellStr != "")
223 | {
224 | hangY++;
225 | eCellStr = myWorksheet.Cell(hangY, 1).Value;
226 | }
227 |
228 | if (hangY < 3 || lieXX < 4)
229 | {
230 | FormMain.isSqlLangCreatedSuccessful = false;
231 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
232 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
233 | return; //如果行列太少,那么直接无视!
234 | }
235 |
236 | try
237 | {
238 | FileStream aFile = new FileStream("UpdateOnly.txt", FileMode.Append);
239 | StreamWriter sw = new StreamWriter(aFile);
240 |
241 | /*
242 | * Excel File Likes:(Sheet Name = DataBase Table name = String "update_only")
243 | tables_name name age sex
244 | video_category 张松溪 22 1
245 | video_category 宋远桥 33 2
246 | video_category 俞岱岩 44 1
247 | video_category 张三丰 55 1
248 | video_category 殷梨亭 66 2
249 | * UPDATE `update_only`.`video_category` SET age='22',sex='1' WHERE 'id'=
250 | * (SELECT 'id' FROM `update_only`.`video_category` WHERE 'name'='张松溪');
251 | * 减少部分语句,假设已经切换到当前数据库:
252 | * UPDATE `video_category` SET age='22',sex='1' WHERE 'id'=
253 | * (SELECT 'id' FROM `video_category` WHERE 'name'='张松溪');
254 | */
255 | for (int i = 2; i < hangY; i++)
256 | {
257 | string outPrint;
258 | outPrint = basicStr + myWorksheet.Cell(i, 1).Value + " SET ";
259 | for (int j = 3; j < lieXX; j++)
260 | {
261 | outPrint = outPrint + myWorksheet.Cell(1, j).Value + "=" + "'" + myWorksheet.Cell(i, j).Value + "'";
262 | if (j != lieXX - 1)
263 | {
264 | outPrint = outPrint + ",";
265 | }
266 | else
267 | {
268 | outPrint = outPrint + " ";
269 | }
270 | }
271 | //假设主键名称为'id'
272 | outPrint = outPrint + "WHERE '" + FormMain.primaryKeyName +
273 | "'=" + "(SELECT '" + FormMain.primaryKeyName + "' FROM '" + myWorksheet.Cell(i, 1).Value + "' WHERE '"
274 | + myWorksheet.Cell(1, 2).Value + "'='" + myWorksheet.Cell(i, 2).Value + "');";
275 |
276 | // Write data to file.
277 | sw.WriteLine(outPrint);
278 | //清空缓冲区
279 | sw.Flush();
280 | }
281 |
282 | //结束写入
283 | sw.Close();
284 | aFile.Close();
285 | }
286 | catch (Exception ex)
287 | {
288 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
289 | MessageBoxButtons.OK, MessageBoxIcon.Information);
290 | return;
291 | }
292 | }
293 |
294 | ///
295 | /// ExcelPackage组件方法生成Update语句。
296 | ///
297 | /// 引用ExcelPackage组件的某张Sheet表的数据内容
298 | ///
299 | private static void excelPackagePrintSQLLangUpdate(ExcelWorksheet myWorksheet)
300 | {
301 | int hangY = 1, lieXX = 1;
302 | string eCellStr = "";
303 | string basicStr = "UPDATE ";
304 |
305 | eCellStr = myWorksheet.Cell(1, 1).Value;
306 |
307 | while (eCellStr != null && eCellStr != "")
308 | {
309 | lieXX++;
310 | eCellStr = myWorksheet.Cell(1, lieXX).Value;
311 | }
312 |
313 | eCellStr = myWorksheet.Cell(1, 1).Value;
314 | while (eCellStr != null && eCellStr != "")
315 | {
316 | hangY++;
317 | eCellStr = myWorksheet.Cell(hangY, 1).Value;
318 | }
319 |
320 | if (hangY < 3 || lieXX < 4)
321 | {
322 | FormMain.isSqlLangCreatedSuccessful = false;
323 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
324 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
325 | return; //如果行列太少,那么直接无视!
326 | }
327 |
328 | try
329 | {
330 | FileStream aFile = new FileStream("Update.txt", FileMode.Append);
331 | StreamWriter sw = new StreamWriter(aFile);
332 |
333 | /*
334 | * UPDATE `kswiki2`.`wish` SET status='12',text='dsf' WHERE id='1';
335 | */
336 | for (int i = 2; i < hangY; i++)
337 | {
338 | string outPrint;
339 | outPrint = basicStr + myWorksheet.Cell(i, 1).Value + " SET ";
340 | for (int j = 3; j < lieXX; j++)
341 | {
342 | outPrint = outPrint + myWorksheet.Cell(1, j).Value + "=" + "'" + myWorksheet.Cell(i, j).Value + "'";
343 | if (j != lieXX - 1)
344 | {
345 | outPrint = outPrint + ",";
346 | }
347 | else
348 | {
349 | outPrint = outPrint + " ";
350 | }
351 | }
352 | outPrint = outPrint + "WHERE " + myWorksheet.Cell(1, 2).Value + "=" + "'" + myWorksheet.Cell(i, 2).Value + "';";
353 |
354 | // Write data to file.
355 | sw.WriteLine(outPrint);
356 | //清空缓冲区
357 | sw.Flush();
358 | }
359 |
360 | //结束写入
361 | sw.Close();
362 | aFile.Close();
363 | }
364 | catch (Exception ex)
365 | {
366 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
367 | MessageBoxButtons.OK, MessageBoxIcon.Information);
368 | return;
369 | }
370 | }
371 |
372 | ///
373 | /// ExcelPackage组件方法生成Delete语句。
374 | ///
375 | /// 引用ExcelPackage组件的某张Sheet表的数据内容
376 | ///
377 | private static void excelPackagePrintSQLLangDelete(ExcelWorksheet myWorksheet)
378 | {
379 | int hangY = 1, lieXX = 1;
380 | string eCellStr = "";
381 | string basicStr = "DELETE FROM ";
382 |
383 | eCellStr = myWorksheet.Cell(1, 1).Value;
384 |
385 | while (eCellStr != null && eCellStr != "")
386 | {
387 | lieXX++;
388 | eCellStr = myWorksheet.Cell(1, lieXX).Value;
389 | }
390 |
391 | eCellStr = myWorksheet.Cell(1, 1).Value;
392 | while (eCellStr != null && eCellStr != "")
393 | {
394 | hangY++;
395 | eCellStr = myWorksheet.Cell(hangY, 1).Value;
396 | }
397 |
398 | if (hangY < 3 || lieXX < 2)
399 | {
400 | FormMain.isSqlLangCreatedSuccessful = false;
401 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
402 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
403 | return; //如果行列太少,那么直接无视!
404 | }
405 |
406 | try
407 | {
408 | FileStream aFile = new FileStream("Delete.txt", FileMode.Append);
409 | StreamWriter sw = new StreamWriter(aFile);
410 |
411 | /*
412 | * delete from tableA where statusB='12'and textC='dsf';
413 | */
414 | for (int i = 2; i < hangY; i++)
415 | {
416 | string outPrint;
417 |
418 | if (lieXX == 2)
419 | {
420 | outPrint = basicStr + myWorksheet.Cell(i, 1).Value + " where "
421 | + myWorksheet.Cell(1, 2).Value + "='" + myWorksheet.Cell(i, 2).Value + "';";
422 | }
423 | else//如果大于2,就用3列的,大于3列的表格也只考虑3列数据!
424 | {
425 | outPrint = basicStr + myWorksheet.Cell(i, 1).Value + " where "
426 | + myWorksheet.Cell(1, 2).Value + "='" + myWorksheet.Cell(i, 2).Value
427 | + "' AND " + myWorksheet.Cell(1, 3).Value + "='" + myWorksheet.Cell(i, 3).Value
428 | + "';";
429 | }
430 |
431 | // Write data to file.
432 | sw.WriteLine(outPrint);
433 | //清空缓冲区
434 | sw.Flush();
435 | }
436 |
437 | //结束写入
438 | sw.Close();
439 | aFile.Close();
440 | }
441 | catch (Exception ex)
442 | {
443 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
444 | MessageBoxButtons.OK, MessageBoxIcon.Information);
445 | return;
446 | }
447 |
448 | }
449 |
450 | ///
451 | /// ExcelPackage组件方法生成Insert语句。
452 | ///
453 | /// 引用ExcelPackage组件的某张Sheet表的数据内容
454 | ///
455 | public static void excelPackagePrintSQLLangInsertMulti(ExcelWorksheet myWorksheet)
456 | {
457 | int hangY = 1, lieXX = 1;
458 | string eCellStr = "";
459 | string basicStr = "INSERT INTO ";
460 |
461 | eCellStr = myWorksheet.Cell(1, 1).Value;
462 |
463 | while (eCellStr != null && eCellStr != "")
464 | {
465 | lieXX++;
466 | eCellStr = myWorksheet.Cell(1, lieXX).Value;
467 | }
468 |
469 | eCellStr = myWorksheet.Cell(1, 1).Value;
470 | while (eCellStr != null && eCellStr != "")
471 | {
472 | hangY++;
473 | eCellStr = myWorksheet.Cell(hangY, 1).Value;
474 | }
475 |
476 | if (hangY < 3 || lieXX < 3)
477 | {
478 | FormMain.isSqlLangCreatedSuccessful = false;
479 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
480 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
481 | return; //如果行列太少,那么直接无视!
482 | }
483 |
484 | FileStream aFile = new FileStream("InsertMulti.txt", FileMode.Append);
485 | StreamWriter sw = new StreamWriter(aFile);
486 |
487 | /*
488 | * INSERT INTO `kswiki2`.`wish` (id,user_id,title,text,created_at,votes_count) VALUES
489 | * ('526','17','我想','你好啊','2014-09-20 21:33:25','230'),
490 | * ('527','18','不想','我好啊','2014-09-21 21:34:26','231');
491 | */
492 |
493 | for (int i = 1; i < hangY; i++)
494 | {
495 | string outPrint = "";
496 |
497 | if (i == 1)
498 | {
499 | outPrint = basicStr + myWorksheet.Cell(2, 1).Value + " (";
500 | }
501 | else
502 | {
503 | outPrint = outPrint + "(";
504 | }
505 | for (int j = 2; j < lieXX; j++)
506 | {
507 | if (i == 1)
508 | {
509 | if (j != lieXX - 1)
510 | outPrint = outPrint + myWorksheet.Cell(1, j).Value + ",";
511 | else
512 | outPrint = outPrint + myWorksheet.Cell(1, j).Value + ") VALUES ";
513 | }
514 | else
515 | {
516 | outPrint = outPrint + "'" + myWorksheet.Cell(i, j).Value + "'";
517 | if (j != lieXX - 1)
518 | {
519 | outPrint = outPrint + ",";
520 | }
521 | else
522 | {
523 | if (i != hangY - 1)
524 | {
525 | outPrint = outPrint + "),";
526 | }
527 | else
528 | { //末行加分号,表示所有插入语句结束
529 | outPrint = outPrint + ");";
530 | }
531 | }
532 | }
533 |
534 | }
535 |
536 | // Write data to file.
537 | sw.WriteLine(outPrint);
538 | //清空缓冲区
539 | sw.Flush();
540 | }
541 |
542 | //结束写入
543 | sw.Close();
544 | aFile.Close();
545 | }
546 |
547 |
548 | ///
549 | /// ExcelPackage组件方法生成Insert语句。
550 | ///
551 | /// 引用ExcelPackage组件的某张Sheet表的数据内容
552 | ///
553 | private static void excelPackagePrintSQLLangInsertEachLineASentence(ExcelWorksheet myWorksheet)
554 | {
555 | int hangY = 0, lieXX = 0;
556 | string eCellStr = "", langTop = "";
557 | string basicStr = "INSERT INTO ";
558 |
559 | eCellStr = myWorksheet.Cell(1, 1).Value;
560 |
561 | while (eCellStr != null && eCellStr != "")
562 | {
563 | lieXX++;
564 | eCellStr = myWorksheet.Cell(1, lieXX).Value;
565 | }
566 |
567 | eCellStr = myWorksheet.Cell(1, 1).Value;
568 | while (eCellStr != null && eCellStr != "")
569 | {
570 | hangY++;
571 | eCellStr = myWorksheet.Cell(hangY, 1).Value;
572 | }
573 |
574 | if (hangY < 3 || lieXX < 3)
575 | {
576 | FormMain.isSqlLangCreatedSuccessful = false;
577 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
578 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
579 | return; //如果行列太少,那么直接无视!
580 | }
581 |
582 | FileStream aFile = new FileStream("InsertEach.txt", FileMode.Append);
583 | StreamWriter sw = new StreamWriter(aFile);
584 |
585 | /**
586 | * INSERT INTO `kswiki2`.`wish` (id,user_id,title,text,created_at,votes_count) VALUES
587 | ('526','17','我想','你好啊','2014-09-20 21:33:25','230');
588 | * INSERT INTO `kswiki2`.`wish` (id,user_id,title,text,created_at,votes_count) VALUES
589 | ('527','18','不想','我好啊','2014-09-21 21:34:26','231');
590 | * 同一个表中插入,每行只写一句话,并以分号结束,方便大量的数据多次、多进程处理。
591 | **/
592 | langTop = basicStr + myWorksheet.Cell(2, 1).Value + " (";
593 |
594 | for (int j = 2; j < lieXX; j++)
595 | {
596 | langTop += myWorksheet.Cell(1, j).Value;
597 | if (j != lieXX - 1)
598 | {
599 | langTop = langTop + ",";
600 | }
601 | }
602 | //固定部分无须带入循环中生成
603 | langTop += ") VALUES ("; //langTop = INSERT INTO `kswiki2`.`wish` (id,user_id,title,text,created_at,votes_count) VALUES (
604 |
605 | for (int i = 2; i < hangY; i++)
606 | {
607 | string outPrint = "";
608 |
609 | for (int j = 2; j < lieXX; j++)
610 | {
611 | outPrint += "'" + myWorksheet.Cell(i, j).Value + "'";
612 |
613 | if (j != lieXX - 1)
614 | {
615 | outPrint = outPrint + ",";
616 | }
617 | }
618 | //outPrint = '526','17','我想','你好啊','2014-09-20 21:33:25','230'
619 | outPrint = langTop + outPrint + ");";
620 |
621 | // Write data to file.
622 | sw.WriteLine(outPrint);
623 | //清空缓冲区
624 | sw.Flush();
625 | }
626 |
627 | //结束写入
628 | sw.Close();
629 | aFile.Close();
630 | }
631 |
632 | #endregion //excelPackage读取数据库的方法结束--END--
633 |
634 |
635 |
636 | #region //npoi读取数据库的方法--start--
637 | ///
638 | /// NPOI组件方法生成UpdateOnly语句。
639 | ///
640 | /// 引用NPOI组件的某张Sheet表的数据内容
641 | ///
642 | private static void npoiPrintSQLLangUpdateOnly(ISheet isheet)
643 | {
644 | int hangY, lieXX;
645 | string basicStr = "UPDATE ";
646 |
647 | hangY = isheet.LastRowNum;//建议不要出现无效数据列,如有部分单元格空白!
648 | lieXX = isheet.GetRow(0).LastCellNum;
649 |
650 | if (hangY < 2 || lieXX < 3)
651 | {
652 | FormMain.isSqlLangCreatedSuccessful = false;
653 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
654 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
655 | return; //如果行列太少,那么直接无视!
656 | }
657 |
658 | try
659 | {
660 | FileStream aFile = new FileStream("UpdateOnly.txt", FileMode.Append);
661 | StreamWriter sw = new StreamWriter(aFile);
662 |
663 | /*
664 | * Excel File Likes:(Sheet Name = DataBase Table name = String "update_only")
665 | tables_name name age sex
666 | video_category 张松溪 22 1
667 | video_category 宋远桥 33 2
668 | video_category 俞岱岩 44 1
669 | video_category 张三丰 55 1
670 | video_category 殷梨亭 66 2
671 | * UPDATE `update_only`.`video_category` SET age='22',sex='1' WHERE 'id'=
672 | * (SELECT 'id' FROM `update_only`.`video_category` WHERE 'name'='张松溪');
673 | * 减少部分语句,假设已经切换到当前数据库:
674 | * UPDATE `video_category` SET age='22',sex='1' WHERE 'id'=
675 | * (SELECT 'id' FROM `video_category` WHERE 'name'='张松溪');
676 | */
677 | for (int i = 1; i <= hangY; i++)
678 | {
679 | string outPrint;
680 | outPrint = basicStr + isheet.GetRow(i).Cells[0].ToString() + " SET ";
681 | for (int j = 2; j < lieXX; j++)
682 | {
683 | outPrint = outPrint + isheet.GetRow(0).Cells[j].ToString() + "=" + "'" + isheet.GetRow(i).Cells[j].ToString() + "'";
684 | if (j != lieXX - 1)
685 | {
686 | outPrint = outPrint + ",";
687 | }
688 | else
689 | {
690 | outPrint = outPrint + " ";
691 | }
692 | }
693 | //假设主键名称为'id'
694 | outPrint = outPrint + "WHERE '" + FormMain.primaryKeyName +
695 | "'=" + "(SELECT '" + FormMain.primaryKeyName + "' FROM '" + isheet.GetRow(i).Cells[0].ToString() + "' WHERE '"
696 | + isheet.GetRow(0).Cells[1].ToString() + "'='" + isheet.GetRow(i).Cells[1].ToString() + "');";
697 |
698 | // Write data to file.
699 | sw.WriteLine(outPrint);
700 | //清空缓冲区
701 | sw.Flush();
702 | }
703 |
704 | //结束写入
705 | sw.Close();
706 | aFile.Close();
707 | }
708 | catch (Exception ex)
709 | {
710 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
711 | MessageBoxButtons.OK, MessageBoxIcon.Information);
712 | return;
713 | }
714 | }
715 |
716 | ///
717 | /// NPOI组件方法生成Update语句。
718 | ///
719 | /// 引用NPOI组件的某张Sheet表的数据内容
720 | ///
721 | private static void npoiPrintSQLLangUpdate(ISheet isheet)
722 | {
723 | int hangY, lieXX;
724 | string basicStr = "UPDATE ";
725 |
726 | hangY = isheet.LastRowNum;//建议不要出现无效数据列,如有部分单元格空白!
727 | lieXX = isheet.GetRow(0).LastCellNum;
728 |
729 | if (hangY < 2 || lieXX < 3)
730 | {
731 | FormMain.isSqlLangCreatedSuccessful = false;
732 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
733 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
734 | return; //如果行列太少,那么直接无视!
735 | }
736 |
737 | try
738 | {
739 | FileStream aFile = new FileStream("Update.txt", FileMode.Append);
740 | StreamWriter sw = new StreamWriter(aFile);
741 |
742 | /*
743 | * UPDATE `kswiki2`.`wish` SET status='12',text='dsf' WHERE id='1';
744 | */
745 | for (int i = 1; i <= hangY; i++)
746 | {
747 | string outPrint;
748 | outPrint = basicStr + isheet.GetRow(i).Cells[0].ToString() + " SET ";
749 | for (int j = 2; j < lieXX; j++)
750 | {
751 | outPrint = outPrint + isheet.GetRow(0).Cells[j].ToString() + "=" + "'" + isheet.GetRow(i).Cells[j].ToString() + "'";
752 | if (j != lieXX - 1)
753 | {
754 | outPrint = outPrint + ",";
755 | }
756 | else
757 | {
758 | outPrint = outPrint + " ";
759 | }
760 | }
761 | outPrint = outPrint + "WHERE " + isheet.GetRow(0).Cells[1].ToString() + "=" + "'" + isheet.GetRow(i).Cells[1].ToString() + "';";
762 |
763 | // Write data to file.
764 | sw.WriteLine(outPrint);
765 | //清空缓冲区
766 | sw.Flush();
767 | }
768 |
769 | //结束写入
770 | sw.Close();
771 | aFile.Close();
772 | }
773 | catch (Exception ex)
774 | {
775 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
776 | MessageBoxButtons.OK, MessageBoxIcon.Information);
777 | return;
778 | }
779 | }
780 |
781 |
782 | ///
783 | /// NPOI组件方法生成Delete语句。
784 | ///
785 | /// 引用NPOI组件的某张Sheet表的数据内容
786 | ///
787 | private static void npoiPrintSQLLangDelete(ISheet isheet)
788 | {
789 | int hangY, lieXX;
790 | string basicStr = "DELETE FROM ";
791 |
792 | hangY = isheet.LastRowNum;//建议不要出现无效数据列,如有部分单元格空白!
793 | lieXX = isheet.GetRow(0).LastCellNum;
794 |
795 | if (hangY < 2 || lieXX < 2)
796 | {
797 | FormMain.isSqlLangCreatedSuccessful = false;
798 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
799 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
800 | return; //如果行列太少,那么直接无视!
801 | }
802 |
803 | try
804 | {
805 | FileStream aFile = new FileStream("Delete.txt", FileMode.Append);
806 | StreamWriter sw = new StreamWriter(aFile);
807 |
808 | /*
809 | * delete from tableA where statusB='12'and textC='dsf';
810 | */
811 | for (int i = 1; i <= hangY; i++)
812 | {
813 | string outPrint;
814 |
815 | if (lieXX == 2)
816 | {
817 | outPrint = basicStr + isheet.GetRow(i).Cells[0].ToString() + " where "
818 | + isheet.GetRow(0).Cells[1].ToString() + "='" + isheet.GetRow(i).Cells[1].ToString() + "';";
819 | }
820 | else//如果大于2,就用3列的,大于3列的表格也只考虑3列数据!
821 | {
822 | outPrint = basicStr + isheet.GetRow(i).Cells[0].ToString() + " where "
823 | + isheet.GetRow(0).Cells[1].ToString() + "='" + isheet.GetRow(i).Cells[1].ToString()
824 | + "' AND " + isheet.GetRow(0).Cells[2].ToString() + "='" + isheet.GetRow(i).Cells[2].ToString()
825 | + "';";
826 | }
827 |
828 | // Write data to file.
829 | sw.WriteLine(outPrint);
830 | //清空缓冲区
831 | sw.Flush();
832 | }
833 |
834 | //结束写入
835 | sw.Close();
836 | aFile.Close();
837 | }
838 | catch (Exception ex)
839 | {
840 | MessageBox.Show("过程出现异常错误" + ex.ToString(), "重要提示",
841 | MessageBoxButtons.OK, MessageBoxIcon.Information);
842 | return;
843 | }
844 |
845 | }
846 |
847 | ///
848 | /// NPOI组件方法生成Insert语句。
849 | ///
850 | /// 引用NPOI组件的某张Sheet表的数据内容
851 | ///
852 | public static void npoiPrintSQLLangInsertMulti(ISheet isheet)
853 | {
854 | int hangY, lieXX;
855 | string basicStr = "INSERT INTO ";
856 |
857 | hangY = isheet.LastRowNum;//建议不要出现无效数据列,如有部分单元格空白!
858 | lieXX = isheet.GetRow(0).LastCellNum;
859 |
860 | if (hangY < 2 || lieXX < 2)
861 | {
862 | FormMain.isSqlLangCreatedSuccessful = false;
863 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
864 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
865 | return; //如果行列太少,那么直接无视!
866 | }
867 |
868 | FileStream aFile = new FileStream("InsertMulti.txt", FileMode.Append);
869 | StreamWriter sw = new StreamWriter(aFile);
870 |
871 | /*
872 | * INSERT INTO `kswiki2`.`wish` (id,user_id,title,text,created_at,votes_count) VALUES
873 | * ('526','17','我想','你好啊','2014-09-20 21:33:25','230'),
874 | * ('527','18','不想','我好啊','2014-09-21 21:34:26','231');
875 | * 能否减少计算次数???如果是理论上其它方法也采用这种代码样式才行。
876 | */
877 |
878 | for (int i = 0; i <= hangY; i++)
879 | {
880 | string outPrint = "";
881 |
882 | if (i == 0)
883 | {
884 | outPrint = basicStr + isheet.GetRow(1).Cells[0].ToString() + " (";
885 | }
886 | else
887 | {
888 | outPrint = outPrint + "(";
889 | }
890 | for (int j = 1; j < lieXX; j++)
891 | {
892 | if (i == 0)
893 | {
894 | if (j != lieXX - 1)
895 | outPrint = outPrint + isheet.GetRow(0).Cells[j].ToString() + ",";
896 | else
897 | outPrint = outPrint + isheet.GetRow(0).Cells[j].ToString() + ") VALUES ";
898 | }
899 | else
900 | {
901 | outPrint = outPrint + "'" + isheet.GetRow(i).Cells[j].ToString() + "'";
902 | if (j != lieXX - 1)
903 | {
904 | outPrint = outPrint + ",";
905 | }
906 | else
907 | {
908 | if (i != hangY)
909 | {
910 | outPrint = outPrint + "),";
911 | }
912 | else
913 | { //末行加分号,表示所有插入语句结束
914 | outPrint = outPrint + ");";
915 | }
916 | }
917 | }
918 |
919 | }
920 |
921 | // Write data to file.
922 | sw.WriteLine(outPrint);
923 | //清空缓冲区
924 | sw.Flush();
925 | }
926 |
927 | //结束写入
928 | sw.Close();
929 | aFile.Close();
930 | }
931 |
932 |
933 | ///
934 | /// NPOI组件方法生成Insert语句。
935 | ///
936 | /// 引用NPOI组件的某张Sheet表的数据内容
937 | ///
938 | private static void npoiPrintSQLLangInsertEachLineASentence(ISheet isheet)
939 | {
940 | int hangY, lieXX;
941 | string basicStr = "INSERT INTO ";
942 | string langTop = "";
943 |
944 | hangY = isheet.LastRowNum;//建议不要出现无效数据列,如有部分单元格空白!
945 | lieXX = isheet.GetRow(0).LastCellNum;
946 |
947 | if (hangY < 2 || lieXX < 2)
948 | {
949 | FormMain.isSqlLangCreatedSuccessful = false;
950 | MessageBox.Show("表格内容太少,无进行语句生成!确认返回并重新选择文件?", "提醒",
951 | MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
952 | return; //如果行列太少,那么直接无视!
953 | }
954 |
955 | FileStream aFile = new FileStream("InsertEach.txt", FileMode.Append);
956 | StreamWriter sw = new StreamWriter(aFile);
957 |
958 | /*
959 | * INSERT INTO `kswiki2`.`wish` (id,user_id,title,text,created_at,votes_count) VALUES
960 | ('526','17','我想','你好啊','2014-09-20 21:33:25','230');
961 | * INSERT INTO `kswiki2`.`wish` (id,user_id,title,text,created_at,votes_count) VALUES
962 | ('527','18','不想','我好啊','2014-09-21 21:34:26','231');
963 | * 同一个表中插入,每行只写一句话,并以分号结束,方便大量的数据多次、多进程处理。
964 | */
965 | langTop = basicStr + isheet.GetRow(1).Cells[0].ToString() + " (";
966 |
967 | for (int j = 1; j < lieXX; j++)
968 | {
969 | langTop += isheet.GetRow(0).Cells[j].ToString();
970 | if (j != lieXX - 1)
971 | {
972 | langTop = langTop + ",";
973 | }
974 | }
975 | //固定部分无须带入循环中生成
976 | langTop += ") VALUES ("; //langTop = INSERT INTO `kswiki2`.`wish` (id,user_id,title,text,created_at,votes_count) VALUES (
977 |
978 | for (int i = 1; i <= hangY; i++)
979 | {
980 | string outPrint = "";
981 |
982 | for (int j = 1; j < lieXX; j++)
983 | {
984 | outPrint += "'" + isheet.GetRow(i).Cells[j].ToString() + "'";
985 |
986 | if (j != lieXX - 1)
987 | {
988 | outPrint = outPrint + ",";
989 | }
990 | }
991 | //outPrint = '526','17','我想','你好啊','2014-09-20 21:33:25','230'
992 | outPrint = langTop + outPrint + ");";
993 |
994 | // Write data to file.
995 | sw.WriteLine(outPrint);
996 | //清空缓冲区
997 | sw.Flush();
998 | }
999 |
1000 | //结束写入
1001 | sw.Close();
1002 | aFile.Close();
1003 | }
1004 |
1005 | #endregion //npoi读取数据库的方法结束--END--
1006 |
1007 |
1008 | }
1009 | }
1010 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Windows.Forms;
5 |
6 | namespace SQLLangCreateTooling
7 | {
8 | static class Program
9 | {
10 | ///
11 | /// 应用程序的主入口点。
12 | ///
13 | [STAThread]
14 | static void Main()
15 | {
16 | Application.EnableVisualStyles();
17 | Application.SetCompatibleTextRenderingDefault(false);
18 | Application.Run(new FormMain());
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过下列属性集
6 | // 控制。更改这些属性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("SQLLangCreateTooling")]
9 | [assembly: AssemblyDescription("Windows平台读取EXCEL表即时生成数据库语言工具")]
10 | [assembly: AssemblyConfiguration("Personal")]
11 | [assembly: AssemblyCompany("小刘工作室")]
12 | [assembly: AssemblyProduct("SQLLangCreateTooling")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("粤ICP备15065555号")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 属性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("d5a1ca84-def9-4bb3-b585-facc80f988c1")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 内部版本号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行库版本:2.0.50727.5485
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SQLLangCreateTooling.Properties
12 | {
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 返回此类使用的、缓存的 ResourceManager 实例。
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SQLLangCreateTooling.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 为所有资源查找重写当前线程的 CurrentUICulture 属性,
56 | /// 方法是使用此强类型资源类。
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:2.0.50727.5485
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SQLLangCreateTooling.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/SQLLangCreateTooling/SQLLangCreateTooling.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.21022
7 | 2.0
8 | {AF8270A2-7B18-45C1-9FEF-F28251475E6C}
9 | WinExe
10 | Properties
11 | SQLLangCreateTooling
12 | SQLLangCreateTooling
13 | v3.5
14 | 512
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | False
36 | ..\ExcelPackage.dll
37 |
38 |
39 | False
40 | ..\NPOI.dll
41 |
42 |
43 |
44 | 3.5
45 |
46 |
47 | 3.5
48 |
49 |
50 | 3.5
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | Form
62 |
63 |
64 | FormMain.cs
65 |
66 |
67 |
68 |
69 |
70 |
71 | FormMain.cs
72 | Designer
73 |
74 |
75 | ResXFileCodeGenerator
76 | Resources.Designer.cs
77 | Designer
78 |
79 |
80 | True
81 | Resources.resx
82 |
83 |
84 | SettingsSingleFileGenerator
85 | Settings.Designer.cs
86 |
87 |
88 | True
89 | Settings.settings
90 | True
91 |
92 |
93 |
94 |
95 |
96 |
97 |
104 |
105 |
--------------------------------------------------------------------------------
/SQLLangCreateTooling/readme.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YamazakyLau/SQLLangCreateTooling/9b3597a23b07e3eea343583f4aadb504919ae52a/SQLLangCreateTooling/readme.docx
--------------------------------------------------------------------------------
/view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YamazakyLau/SQLLangCreateTooling/9b3597a23b07e3eea343583f4aadb504919ae52a/view.png
--------------------------------------------------------------------------------