想请各位大神帮忙把这段代码注释下!
程序代码:
public partial class FrmMain : Form { private SqlConnection sqlConn; public FrmMain() { InitializeComponent(); sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConn"].ConnectionString); } private void btnSearchUser_Click(object sender, EventArgs e)//查询 { StringBuilder strSql = new StringBuilder("select * from test where 1=1 "); if (!string.IsNullOrEmpty(txtGonoSelect.Text)) { strSql.Append(" and gono='" + txtGonoSelect.Text.Replace("'", "''") + "'"); } if (!string.IsNullOrEmpty(txtNameSelect.Text)) { strSql.Append(" and name='" + txtNameSelect.Text.Replace("'", "''") + "'"); } using (SqlDataAdapter da = new SqlDataAdapter(strSql.ToString(), sqlConn)) { DataTable dt = new DataTable(); da.Fill(dt); dgvSelect.DataSource = dt; } } private void btnInsertUser_Click(object sender, EventArgs e)//新增 { if (string.IsNullOrEmpty(txtGonoInsert.Text)) { MessageBox.Show("工号信息不能为空!", "系统提示:", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = sqlConn; = CommandType.Text; = "insert into test(gono,name) values(@gono,@name)"; cmd.Parameters.Add("@gono", SqlDbType.Char, 6).Value = txtGonoInsert.Text.Replace("'", "''"); cmd.Parameters.Add("@name", SqlDbType.Char, 10).Value = txtNameInsert.Text.Replace("'", "''"); try { sqlConn.Open(); cmd.ExecuteNonQuery(); } catch (SqlException) { throw new ApplicationException(); } finally { sqlConn.Close(); } dgvInsert.DataSource = userInfoGet(); } } private DataTable userInfoGet() { SqlDataAdapter da = new SqlDataAdapter("select id,gono,name from test", sqlConn); DataTable dt = new DataTable(); da.Fill(dt); return dt; } private void btnUserDelete_Click(object sender, EventArgs e)//删除 { if (dgvDelete.SelectedRows.Count == 0) { MessageBox.Show("请选择要删除的行!"); return; } foreach (DataGridViewRow dr in dgvDelete.SelectedRows) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = sqlConn; = CommandType.Text; = "delete from test where id='"+ dr.Cells["idDelete"].Value +"'"; try { sqlConn.Open(); cmd.ExecuteNonQuery(); } catch (SqlException) { throw new ApplicationException(); } finally { sqlConn.Close(); } } } dgvDelete.DataSource = userInfoGet(); } private void btnSelect_Click(object sender, EventArgs e)//1 { tbMain.SelectedIndex = 1; } private void btnInsert_Click(object sender, EventArgs e)//2 { tbMain.SelectedIndex = 2; } private void btnUpdate_Click(object sender, EventArgs e)//3 { tbMain.SelectedIndex = 3; dgvUpdate.DataSource = userInfoGet(); } private void btnDelete_Click(object sender, EventArgs e)//4 { dgvDelete.DataSource = userInfoGet(); tbMain.SelectedIndex = 4; } private void dgvUpdate_CellDoubleClick(object sender, DataGridViewCellEventArgs e)//更新 { string id = dgvUpdate.CurrentRow.Cells["idUpdate"].Value.ToString(); string gono = dgvUpdate.CurrentRow.Cells["gonoUpdate"].Value.ToString(); string name = dgvUpdate.CurrentRow.Cells["nameUpdate"].Value.ToString(); string returnBlag = string.Empty; using (FrmUserUpdate frmUserUpdate = new FrmUserUpdate(id, gono, name, sqlConn)) { frmUserUpdate.ShowDialog(this); returnBlag = frmUserUpdate.ReturnBlag; } if (returnBlag == "Confirm") { //dgvUpdate.DataSource = userInfoGet(); } dgvUpdate.DataSource = userInfoGet(); }