FrmGetRosterSQLServer.cs
6.52 KB
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
using GeneralLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SunVoteARSPPT
{
internal partial class FrmGetRosterSQLServer : Form
{
internal FrmGetRosterSQLServer()
{
InitializeComponent();
}
DBOper DBOperation = null;
private void Form1_Load(object sender, EventArgs e)
{
DBOperation = new DBOper();
cboMode.Items.Clear();
cboMode.Items.Add("SQL Server");
cboMode.Items.Add("Windows");
//cboMode.Items.Add("集成的Windows");
cboMode.SelectedIndex = 0;
btnSelect.Enabled = false;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
DBOperation.CloseConn();
}
private void cboMode_SelectedIndexChanged(object sender, EventArgs e)
{
txtUid.Enabled = txtPwd.Enabled = (cboMode.SelectedIndex < 2);
}
private void btnConnect_Click(object sender, EventArgs e)
{
Stopwatch t = Stopwatch.StartNew();
Action<object> a = (obj) =>
{
try
{
this.Invoke((MethodInvoker)delegate
{
this.Cursor = Cursors.WaitCursor;
btnConnect.Enabled = cboMode.Enabled = false;
dgvClass.DataSource = null;
dgvData.DataSource = null;
if (cboMode.SelectedIndex == 0)
DBOperation.InitConnStrSQLServerSQL(txtServer.Text, txtDataBase.Text, txtUid.Text, txtPwd.Text);
if (cboMode.SelectedIndex == 1)
DBOperation.InitConnStrSQLServerWin(txtServer.Text, txtDataBase.Text, txtUid.Text, txtPwd.Text);
else if (cboMode.SelectedIndex == 2)
DBOperation.InitConnStrSQLServerWinSSPI(txtServer.Text, txtDataBase.Text);
});
if (DBOperation.OpenConn())
{
this.Invoke((MethodInvoker)delegate
{
ShowClass();
});
}
//this.Text = t.ElapsedMilliseconds + "";
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
this.Invoke((MethodInvoker)delegate
{
this.Cursor = Cursors.Default;
btnConnect.Enabled = cboMode.Enabled = true;
});
};
a.BeginInvoke(this, ar => a.EndInvoke(ar), null);
}
private void ShowClass()
{
try
{
dgvClass.DataSource = null;
string sql = "select * from HZ_Base_Station";
DataSet ds = DBOperation.OpenDataSet(sql);
if ((ds == null) || (ds.Tables.Count < 1))
return;
var tab = ds.Tables[0];
dgvClass.DataSource = tab;
for (int i = 0; i < tab.Rows.Count; i++)
{
dgvClass.Rows[i].Tag = tab.Rows[i]["bjid"] + "";
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, "ShowClass");
}
}
DataTable DataTableRoster = null;
private void btnNameList_Click(object sender, EventArgs e)
{
try
{
dgvData.DataSource = null;
if (dgvClass.SelectedCells.Count < 1)
return;
string classID = dgvClass.SelectedCells[0].OwningRow.Tag + "";
string sql = "select HZ_Student_Keybroad.KID as KeyID,HZ_Student.xm as SName,HZ_Student.kh as SKH from" +
" HZ_Student_Keybroad left join HZ_Student on HZ_Student_Keybroad.sid=HZ_Student.sid" +
" where HZ_Student.bjid='" + classID + "'" +
" order by HZ_Student.kh";
DataSet ds = DBOperation.OpenDataSet(sql);
if ((ds == null) || (ds.Tables.Count < 1))
return;
DataTableRoster = ds.Tables[0];
dgvData.DataSource = ds.Tables[0];
int rows = DataTableRoster.Rows.Count;
int cols = DataTableRoster.Columns.Count;
btnSelect.Enabled = ((rows > 0) && (cols > 0));
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
private void btnSelect_Click(object sender, EventArgs e)
{
int rows = DataTableRoster.Rows.Count;
int cols = DataTableRoster.Columns.Count;
if ((rows < 1) || (cols < 1))
return;
if (MessageBox.Show(GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "WarningInfo1", "此操作将清空现有名单!是否继续?"),
GlobalInfo.SysLanguage.LPT.ReadString("rbSunVoteARS", "Warning", "警告"), MessageBoxButtons.YesNo, MessageBoxIcon.None) == DialogResult.No)
{
return;
}
Dictionary<string, string> DicCol = new Dictionary<string, string>();
DicCol.Add("KeyID", "键盘编号");
DicCol.Add("SName", "姓名");
DicCol.Add("SKH", "考号");
string[,] aryData = new string[rows + 1, cols];
for (int n = 0; n < DataTableRoster.Columns.Count; n++)
{
string colName = DataTableRoster.Columns[n].ColumnName;
if (DicCol.ContainsKey(colName))
colName = DicCol[colName];
aryData[0, n] = colName;
}
for (int i = 0; i < DataTableRoster.Rows.Count; i++)
{
for (int n = 0; n < DataTableRoster.Columns.Count; n++)
{
int row = i + 1;
aryData[row, n] = DataTableRoster.Rows[row][n] + "";
}
}
this.Close();
new FrmVoterList().ShowImportList("", aryData);
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}