-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormConfig.cs
267 lines (211 loc) · 8.22 KB
/
FormConfig.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
using Trace.entity;
namespace Trace
{
public partial class FormConfig : Form
{
String directory;
OleDbConnection mycon;
FileInfo sysConfig;
DataSet dataSetSource;
DataTable dataTableSource;
public FormConfig()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
}
private void FormConfig_Load(object sender, EventArgs e)
{
directory = Environment.CurrentDirectory.ToString();
//MessageBox.Show(directory);
//Step2: 连接数据库
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + directory + "/ncpzs.mdb;Jet OLEDB:Database Password=52586668";
mycon = new OleDbConnection(connStr);
mycon.Open();
//MessageBox.Show("数据打开成功!");
queryProduct();
querySource();
//tbxMaxLabelNum.Text = "18";
sysConfig = new FileInfo(directory + "/cfg_sys.txt");
if (!sysConfig.Exists)
{
sysConfig.Create();
}
StreamReader reader = new StreamReader(sysConfig.FullName);
cbxPort.SelectedItem = reader.ReadLine();
tbxMaxLabelNum.Text = reader.ReadLine();
cbxLabelSize.SelectedItem = reader.ReadLine();
//tbxCopFullName.Text = reader.ReadLine();
//tbxCopShortName.Text = reader.ReadLine();
//tbxCopNetAddress.Text = reader.ReadLine();
reader.Close();
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void tabProduct_Click(object sender, EventArgs e)
{
}
//取出产品列表
public void queryProduct()
{
string sql = "select SORT as 序号, NAME as 品名, ID as 编号 " +
"from PRODUCT order by SORT asc";
OleDbCommand cmd = new OleDbCommand(sql, mycon);
OleDbDataReader reader = cmd.ExecuteReader();
DataSet dateset = new DataSet();
DataTable dt = new DataTable();
dt.Load(reader);
dgvProduct.DataSource = dt;
dgvProduct.Columns[0].Width = 60;
dgvProduct.Columns[1].Width = 200;
dgvProduct.Columns[2].Visible = false;
}
//取出基地列表
public void querySource()
{
string sql = "select SORT as 序号, NAME as 基地名称, ADDRESS as 地址, PIC as 负责人, ID as 编号 " +
"from SOURCE order by SORT asc";
OleDbCommand cmd = new OleDbCommand(sql, mycon);
OleDbDataReader reader = cmd.ExecuteReader();
dataSetSource = new DataSet();
dataTableSource = new DataTable();
dataTableSource.Load(reader);
dgvSource.DataSource = dataTableSource;
dgvSource.Columns[0].Width = 60;
dgvSource.Columns[1].Width = 200;
dgvSource.Columns[2].Width = 200;
dgvSource.Columns[3].Visible = false;
}
private void tabsConfig_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void tabBase_Click(object sender, EventArgs e)
{
}
private void btnSavePrintConfig_Click(object sender, EventArgs e)
{
if (!sysConfig.Exists)
{
sysConfig.Create();
}
StreamWriter writer = new StreamWriter(sysConfig.FullName);
writer.WriteLine(cbxPort.SelectedItem.ToString());
writer.WriteLine(tbxMaxLabelNum.Text);
writer.WriteLine(cbxLabelSize.SelectedItem.ToString());
writer.Close();
MessageBox.Show("设置成功!");
}
private void btnSaveCopConfig_Click(object sender, EventArgs e)
{
}
private void btnSaveSource_Click(object sender, EventArgs e)
{
MessageBox.Show(dgvSource.NewRowIndex.ToString());
DataRow dr = dataTableSource.NewRow();
//MessageBox.Show(dr.);
dgvSource.Update();
MessageBox.Show("保存成功");
}
private void btnAddSource_Click(object sender, EventArgs e)
{
Form f = Application.OpenForms["FormAddSource"]; //查找是否打开过Form1窗体
if (f == null)
{
FormAddSource formAddSource = new FormAddSource("add", mycon, this, new Source());
formAddSource.Show();
}
else
{
f.Focus();
}
}
private void btnDeleteSource_Click(object sender, EventArgs e)
{
string id = dgvSource.SelectedRows[0].Cells[4].Value.ToString();
string sql = "delete from SOURCE where ID = " + id;
OleDbCommand cmd = new OleDbCommand(sql, mycon);
cmd.ExecuteNonQuery();
querySource();
}
private void btnEditSource_Click(object sender, EventArgs e)
{
Source source = new Source();
source.id = int.Parse(dgvSource.SelectedRows[0].Cells[4].Value.ToString());
source.name = dgvSource.SelectedRows[0].Cells[1].Value.ToString();
source.address = dgvSource.SelectedRows[0].Cells[2].Value.ToString();
source.pic = dgvSource.SelectedRows[0].Cells[3].Value.ToString();
source.sort = int.Parse(dgvSource.SelectedRows[0].Cells[0].Value.ToString());
Form f = Application.OpenForms["FormAddSource"]; //查找是否打开过Form1窗体
if (f == null)
{
FormAddSource formAddSource = new FormAddSource("edit", mycon, this, source);
formAddSource.Show();
}
else
{
f.Focus();
}
}
private void btnAddProduct_Click(object sender, EventArgs e)
{
Form f = Application.OpenForms["FormAddProduct"]; //查找是否打开过Form1窗体
if (f == null)
{
FormAddProduct formAddProduct = new FormAddProduct("add", mycon, this, new Product());
formAddProduct.Show();
}
else
{
f.Focus();
}
}
private void btnEditProduct_Click(object sender, EventArgs e)
{
Product product = new Product();
product.id = int.Parse(dgvProduct.SelectedRows[0].Cells[2].Value.ToString());
product.name = dgvProduct.SelectedRows[0].Cells[1].Value.ToString();
product.sort = int.Parse(dgvProduct.SelectedRows[0].Cells[0].Value.ToString());
Form f = Application.OpenForms["FormAddProduct"]; //查找是否打开过Form1窗体
if (f == null)
{
FormAddProduct formAddSource = new FormAddProduct("edit", mycon, this, product);
formAddSource.Show();
}
else
{
f.Focus();
}
}
private void btnDeleteProduct_Click(object sender, EventArgs e)
{
string id = dgvProduct.SelectedRows[0].Cells[2].Value.ToString();
string sql = "delete from PRODUCT where ID = " + id;
OleDbCommand cmd = new OleDbCommand(sql, mycon);
cmd.ExecuteNonQuery();
queryProduct();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void tabPageCompanyInfo_Click(object sender, EventArgs e)
{
}
private void dgvSource_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}