-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.cs
434 lines (371 loc) · 17.5 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using Excel = Microsoft.Office.Interop.Excel;
using System.Collections;
namespace Venn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ElementButtonType = 3; SetVisible();
button2.BackgroundImage = Venn.Properties.Resources.button_on;
textBox2.BackgroundImage = textBox3.BackgroundImage= textBox5.BackgroundImage
= textBox7.BackgroundImage= textBox9.BackgroundImage=
Venn.Properties.Resources.blank;
textBox1.Text = "set A";
textBox4.Text = "set B";
textBox6.Text = "set C";
textBox8.Text = "set D";
textBox10.Text = "set E";
}
private void GroupBox1_Enter(object sender, EventArgs e)
{
}
private void CheckedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Button1_Click(object sender, EventArgs e)
{
ResetButtonBackground();
ElementButtonType = 2;
button1.BackgroundImage = Venn.Properties.Resources.button_on;
SetVisible();
}
private void Button2_Click(object sender, EventArgs e)
{
ResetButtonBackground();
ElementButtonType = 3;
button2.BackgroundImage = Venn.Properties.Resources.button_on;
SetVisible();
}
private void ResetButtonBackground() {
button1.BackgroundImage = Venn.Properties.Resources.button_off;
button2.BackgroundImage = Venn.Properties.Resources.button_off;
button3.BackgroundImage = Venn.Properties.Resources.button_off;
button4.BackgroundImage = Venn.Properties.Resources.button_off;
}
static int ElementButtonType;
private void Button3_Click(object sender, EventArgs e)
{
ResetButtonBackground();
ElementButtonType = 4;
button3.BackgroundImage = Venn.Properties.Resources.button_on;
SetVisible();
}
private void Button4_Click(object sender, EventArgs e)
{
ResetButtonBackground();
ElementButtonType = 5;
button4.BackgroundImage = Venn.Properties.Resources.button_on;
SetVisible();
}
private void Label1_Click(object sender, EventArgs e)
{
}
private void FlowLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(flowLayoutPanel1.BackColor);
e.Graphics.DrawString("Set 1 ", flowLayoutPanel1.Font, Brushes.DodgerBlue, 18, 18);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, 7, 8, 7);
e.Graphics.DrawLine(Pens.DodgerBlue, e.Graphics.MeasureString(flowLayoutPanel1.Text, flowLayoutPanel1.Font).Width + 8, 7, flowLayoutPanel1.Width - 2, 7);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, 7, 1, flowLayoutPanel1.Height - 2);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, flowLayoutPanel1.Height - 2, flowLayoutPanel1.Width - 2, flowLayoutPanel1.Height - 2);
e.Graphics.DrawLine(Pens.DodgerBlue, flowLayoutPanel1.Width - 2, 7, flowLayoutPanel1.Width - 2, flowLayoutPanel1.Height - 2);
}
private void FlowLayoutPanel2_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(flowLayoutPanel1.BackColor);
e.Graphics.DrawString("Set 2 ", flowLayoutPanel1.Font, Brushes.DarkRed, 18, 18);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, 7, 8, 7);
e.Graphics.DrawLine(Pens.DodgerBlue, e.Graphics.MeasureString(flowLayoutPanel1.Text, flowLayoutPanel1.Font).Width + 8, 7, flowLayoutPanel1.Width - 2, 7);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, 7, 1, flowLayoutPanel1.Height - 2);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, flowLayoutPanel1.Height - 2, flowLayoutPanel1.Width - 2, flowLayoutPanel1.Height - 2);
e.Graphics.DrawLine(Pens.DodgerBlue, flowLayoutPanel1.Width - 2, 7, flowLayoutPanel1.Width - 2, flowLayoutPanel1.Height - 2);
}
private void FlowLayoutPanel3_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(flowLayoutPanel1.BackColor);
e.Graphics.DrawString("Set 3 ", flowLayoutPanel1.Font, Brushes.ForestGreen, 18, 18);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, 7, 8, 7);
e.Graphics.DrawLine(Pens.DodgerBlue, e.Graphics.MeasureString(flowLayoutPanel1.Text, flowLayoutPanel1.Font).Width + 8, 7, flowLayoutPanel1.Width - 2, 7);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, 7, 1, flowLayoutPanel1.Height - 2);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, flowLayoutPanel1.Height - 2, flowLayoutPanel1.Width - 2, flowLayoutPanel1.Height - 2);
e.Graphics.DrawLine(Pens.DodgerBlue, flowLayoutPanel1.Width - 2, 7, flowLayoutPanel1.Width - 2, flowLayoutPanel1.Height - 2);
}
private void FlowLayoutPanel4_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(flowLayoutPanel1.BackColor);
e.Graphics.DrawString("Set 4 ", flowLayoutPanel1.Font, Brushes.RosyBrown, 18, 18);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, 7, 8, 7);
e.Graphics.DrawLine(Pens.DodgerBlue, e.Graphics.MeasureString(flowLayoutPanel1.Text, flowLayoutPanel1.Font).Width + 8, 7, flowLayoutPanel1.Width - 2, 7);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, 7, 1, flowLayoutPanel1.Height - 2);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, flowLayoutPanel1.Height - 2, flowLayoutPanel1.Width - 2, flowLayoutPanel1.Height - 2);
e.Graphics.DrawLine(Pens.DodgerBlue, flowLayoutPanel1.Width - 2, 7, flowLayoutPanel1.Width - 2, flowLayoutPanel1.Height - 2);
}
private void FlowLayoutPanel5_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(flowLayoutPanel1.BackColor);
e.Graphics.DrawString("Set 5 ", flowLayoutPanel1.Font, Brushes.MediumPurple, 18, 18);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, 7, 8, 7);
e.Graphics.DrawLine(Pens.DodgerBlue, e.Graphics.MeasureString(flowLayoutPanel1.Text, flowLayoutPanel1.Font).Width + 8, 7, flowLayoutPanel1.Width - 2, 7);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, 7, 1, flowLayoutPanel1.Height - 2);
e.Graphics.DrawLine(Pens.DodgerBlue, 1, flowLayoutPanel1.Height - 2, flowLayoutPanel1.Width - 2, flowLayoutPanel1.Height - 2);
e.Graphics.DrawLine(Pens.DodgerBlue, flowLayoutPanel1.Width - 2, 7, flowLayoutPanel1.Width - 2, flowLayoutPanel1.Height - 2);
}
private void Button5_Click(object sender, EventArgs e)
{
button5.BackgroundImage = Venn.Properties.Resources.button_on;
List<string> Names =new List<string>();
List<string> Texts =new List<string>();
Names.Clear();Texts.Clear();
Names.Add(textBox1.Text);
Names.Add(textBox4.Text);
Texts.Add(textBox2.Text);
Texts.Add(textBox3.Text);
switch (ElementButtonType)
{
case 2:
Venn2Set f2 = new Venn2Set(Names,Texts);
f2.Show();
break;
case 3:
Names.Add(textBox6.Text);
Texts.Add(textBox5.Text);
Venn3Set f3 = new Venn3Set(Names, Texts);
f3.Show();
break;
case 4:
Names.Add(textBox6.Text);
Texts.Add(textBox5.Text);
Names.Add(textBox8.Text);
Texts.Add(textBox7.Text);
Venn4Set f4 = new Venn4Set(Names, Texts);
f4.Show();
break;
case 5:
Names.Add(textBox6.Text);
Texts.Add(textBox5.Text);
Names.Add(textBox8.Text);
Texts.Add(textBox7.Text);
Names.Add(textBox10.Text);
Texts.Add(textBox9.Text);
Venn5Set f5 = new Venn5Set(Names, Texts);
f5.Show();
break;
}
button5.BackgroundImage = Venn.Properties.Resources.button_off;
Names.Clear(); Texts.Clear();
}
private void SetVisible() {
flowLayoutPanel3.Visible = false;
flowLayoutPanel4.Visible = false;
flowLayoutPanel5.Visible = false;
if (ElementButtonType>2)
flowLayoutPanel3.Visible = true;
if (ElementButtonType > 3)
flowLayoutPanel4.Visible = true;
if (ElementButtonType > 4)
flowLayoutPanel5.Visible = true;
}
private void Label11_Click(object sender, EventArgs e)
{
}
private void Panel1_Paint(object sender, PaintEventArgs e)
{
}
private void Button6_Click(object sender, EventArgs e)
{
textBox1.Text = "set A";
textBox4.Text = "set B";
textBox6.Text = "set C";
textBox8.Text = "set D";
textBox10.Text = "set E";
textBox2.Text=" ";
textBox3.Text=" ";
textBox7.Text=" ";
textBox9.Text=" ";
textBox5.Text=" ";
}
private void FlowLayoutPanel6_Paint(object sender, PaintEventArgs e)
{
}
}
public class SaveToPNG
{
public void OutputAsPNGFile(Bitmap bit)
{
string filePath = "";
SaveFileDialog s = new SaveFileDialog();
s.Title = "Save PNG picture";
s.Filter = "PNG picture(*.png)|*.png";
s.FilterIndex = 1;
if (s.ShowDialog() == DialogResult.OK)
filePath = s.FileName;
else
return;
bit.Save(filePath);//默认保存格式为PNG,保存成jpg格式质量不是很好
MessageBox.Show("Export Succeed!", "CAPION", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
public class ExportToExcel
{
public Excel.Application m_xlApp = null;
public void OutputAsExcelFile(DataGridView dataGridView)
{
if (dataGridView.Rows.Count <= 0)
{
MessageBox.Show("No Data!", "CAPION", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
}
string filePath = "";
SaveFileDialog s = new SaveFileDialog();
s.Title = "Save Excel file";
s.Filter = "Excel file(*.xls)|*.xls";
s.FilterIndex = 1;
if (s.ShowDialog() == DialogResult.OK)
filePath = s.FileName;
else
return;
//第一步:将dataGridView转化为dataTable,这样可以过滤掉dataGridView中的隐藏列
DataTable tmpDataTable = new DataTable("tmpDataTable");
DataTable modelTable = new DataTable("ModelTable");
for (int column = 0; column < dataGridView.Columns.Count; column++)
{
if (dataGridView.Columns[column].Visible == true)
{
DataColumn tempColumn = new DataColumn(dataGridView.Columns[column].HeaderText, typeof(string));
tmpDataTable.Columns.Add(tempColumn);
DataColumn modelColumn = new DataColumn(dataGridView.Columns[column].Name, typeof(string));
modelTable.Columns.Add(modelColumn);
}
}
for (int row = 0; row < dataGridView.Rows.Count; row++)
{
if (dataGridView.Rows[row].Visible == false)
continue;
DataRow tempRow = tmpDataTable.NewRow();
for (int i = 0; i < tmpDataTable.Columns.Count; i++)
tempRow[i] = dataGridView.Rows[row].Cells[modelTable.Columns[i].ColumnName].Value;
tmpDataTable.Rows.Add(tempRow);
}
if (tmpDataTable == null)
{
return;
}
//第二步:导出dataTable到Excel
long rowNum = tmpDataTable.Rows.Count;//行数
int columnNum = tmpDataTable.Columns.Count;//列数
Excel.Application m_xlApp = new Excel.Application();
m_xlApp.DisplayAlerts = false;//不显示更改提示
m_xlApp.Visible = false;
Excel.Workbooks workbooks = m_xlApp.Workbooks;
Excel.Workbook workbook = workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1];//取得sheet1
try
{
string[,] datas = new string[rowNum + 1, columnNum];
for (int i = 0; i < columnNum; i++) //写入字段
datas[0, i] = tmpDataTable.Columns[i].Caption;
//Excel.Range range = worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, columnNum]);
Excel.Range range = m_xlApp.Range[worksheet.Cells[1, 1], worksheet.Cells[1, columnNum]];
range.Interior.ColorIndex = 15;//15代表灰色
range.Font.Bold = true;
range.Font.Size = 10;
int r = 0;
for (r = 0; r < rowNum; r++)
{
for (int i = 0; i < columnNum; i++)
{
object obj = tmpDataTable.Rows[r][tmpDataTable.Columns[i].ToString()];
datas[r + 1, i] = obj == null ? "" : "'" + obj.ToString().Trim();//在obj.ToString()前加单引号是为了防止自动转化格式
}
System.Windows.Forms.Application.DoEvents();
//添加进度条
}
//Excel.Range fchR = worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[rowNum + 1, columnNum]);
Excel.Range fchR = m_xlApp.Range[worksheet.Cells[1, 1], worksheet.Cells[rowNum + 1, columnNum]];
fchR.Value2 = datas;
worksheet.Columns.EntireColumn.AutoFit();//列宽自适应。
//worksheet.Name = "dd";
//m_xlApp.WindowState = Excel.XlWindowState.xlMaximized;
m_xlApp.Visible = false;
// = worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[rowNum + 1, columnNum]);
range = m_xlApp.Range[worksheet.Cells[1, 1], worksheet.Cells[rowNum + 1, columnNum]];
//range.Interior.ColorIndex = 15;//15代表灰色
range.Font.Size = 9;
range.RowHeight = 14.25;
range.Borders.LineStyle = 1;
range.HorizontalAlignment = 1;
workbook.Saved = true;
workbook.SaveCopyAs(filePath);
}
catch (Exception ex)
{
MessageBox.Show("Export Error:" + ex.Message, "Export Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
EndReport();
}
m_xlApp.Workbooks.Close();
m_xlApp.Workbooks.Application.Quit();
m_xlApp.Application.Quit();
m_xlApp.Quit();
MessageBox.Show("Export Succeed!", "CAPION", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void EndReport()
{
object missing = System.Reflection.Missing.Value;
try
{
//m_xlApp.Workbooks.Close();
//m_xlApp.Workbooks.Application.Quit();
//m_xlApp.Application.Quit();
//m_xlApp.Quit();
}
catch { }
finally
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_xlApp.Workbooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_xlApp.Application);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_xlApp);
m_xlApp = null;
}
catch { }
try
{
//清理垃圾进程
this.killProcessThread();
}
catch { }
GC.Collect();
}
}
private void killProcessThread()
{
ArrayList myProcess = new ArrayList();
for (int i = 0; i < myProcess.Count; i++)
{
try
{
System.Diagnostics.Process.GetProcessById(int.Parse((string)myProcess[i])).Kill();
}
catch { }
}
}
}
}