private void STbj1_Load(object sender, EventArgs e) { if (TempData.flag == 1) //新增学生记录 { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox5.Text = ""; textBox4.Text = ""; radioButton1.Checked = false; radioButton1.Checked = false; } else //修改选题记录 { DataTable mytable = new DataTable(); mytable.Clear(); mytable = CommDbOp.Exesql("SELECT * FROM S_T WHERE 学号='" + TempData.no + "'"); textBox1.Text = mytable.Rows[0]["学号"].ToString().Trim(); textBox2.Text = mytable.Rows[0]["姓名"].ToString().Trim(); if (mytable.Rows[0]["性别"].ToString() == "男") { radioButton1.Checked = true; } else if (mytable.Rows[0]["性别"].ToString() == "女") { radioButton2.Checked = true; } textBox3.Text = mytable.Rows[0]["年龄"].ToString().Trim(); textBox4.Text = mytable.Rows[0]["班级"].ToString().Trim(); textBox5.Text = mytable.Rows[0]["专业"].ToString().Trim(); textBox1.Enabled = false; //不允许修改编号 textBox2.Focus(); } }
private void TMbj_Load(object sender, EventArgs e) { mytable.Clear(); if (condstr != "") { mytable = CommDbOp.Exesql("SELECT * FROM X_T WHERE " + condstr); } else { mytable = CommDbOp.Exesql("SELECT * FROM X_T"); } mydv = mytable.DefaultView; //获得DataView对象mydv //以下设置dataGridView1的属性 dataGridView1.DataSource = mydv; dataGridView1.ReadOnly = true; //只读 dataGridView1.AllowUserToAddRows = false; //去掉最后空白行 dataGridView1.GridColor = Color.Gray; dataGridView1.ScrollBars = ScrollBars.Vertical; dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12); dataGridView1.DefaultCellStyle.Font = new Font("微软雅黑", 10); dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single; //行高,列宽调整到适合位于屏幕上当前显示的行中的列的所有单元格(包括标头单元格)的内容。 dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; }
private void button6_Click(object sender, EventArgs e) //确认修改密码按钮 { if (textBox1.Text == "") { MessageBox.Show("请输入密码", "错误提示"); } else { if (textBox1.Text == textBox2.Text) { try { string mysql; DataTable mytable1 = new DataTable(); mysql = "UPDATE S_T SET 密码 = '" + textBox1.Text.Trim() + "' WHERE 学号='" + Pass.LoginRule.username + "'"; mytable1 = CommDbOp.Exesql(mysql); MessageBox.Show("恭喜你,密码修改成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "错误提示"); } } else { MessageBox.Show("两次输入的密码不同,请重新输入"); textBox1.Text = ""; textBox2.Text = ""; } } }
private void XTcx1_Load(object sender, EventArgs e) { mytable.Clear(); if (condstr != "") { mytable = CommDbOp.Exesql("SELECT X_T.选题编号, 选题名称, 学号, 姓名 " + "FROM X_T LEFT OUTER JOIN S_T ON(S_T.选题编号 = X_T.选题编号) WHERE " + condstr); } else { mytable = CommDbOp.Exesql("SELECT X_T.选题编号, 选题名称, 学号, 姓名 " + "FROM X_T LEFT OUTER JOIN S_T ON(S_T.选题编号 = X_T.选题编号)"); } mydv = mytable.DefaultView; //获得DataView对象mydv //以下设置dataGridView1的属性 dataGridView1.DataSource = mydv; dataGridView1.ReadOnly = true; //只读 dataGridView1.GridColor = Color.Gray; dataGridView1.ScrollBars = ScrollBars.Vertical; dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12); dataGridView1.DefaultCellStyle.Font = new Font("微软雅黑", 10); dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single; //行高,列宽调整到适合位于屏幕上当前显示的行中的列的所有单元格(包括标头单元格)的内容。 dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; }
private void button1_Click(object sender, EventArgs e) { DataTable mytable; DataTable mytable2; DataTable mytable3; string mysql = "SELECT * FROM S_A WHERE 用户名='" + textBox1.Text + "' AND 密码='" + textBox2.Text + "'"; mytable = CommDbOp.Exesql(mysql); if (mytable.Rows.Count == 0) { mysql = "SELECT * FROM S_T WHERE 学号='" + textBox1.Text + "' AND 密码='" + textBox2.Text + "'"; mytable2 = CommDbOp.Exesql(mysql); if (mytable2.Rows.Count == 0) { mysql = "SELECT * FROM S_T WHERE 学号='" + textBox1.Text + "' AND 密码='" + textBox2.Text + "'"; mytable3 = CommDbOp.Exesql(mysql); if (mytable3.Rows.Count == 0) { MessageBox.Show("用户名或密码错误"); textBox2.Text = ""; } } else { TempData.userlevel = "用户"; LoginRule.username = textBox1.Text.Trim(); this.Hide(); Form myform = new mainA(); myform.ShowDialog(); this.Close(); } } else { TempData.userlevel = "管理员"; this.Hide(); Form myform = new mainA(); myform.ShowDialog(); this.Close(); } }
private void STgrxx_Load(object sender, EventArgs e) { mytable.Clear(); mytable = CommDbOp.Exesql("SELECT 学号,姓名,性别,年龄,班级,专业,X_T.选题编号,选题名称" + " FROM S_T LEFT OUTER JOIN X_T ON(S_T.选题编号 = X_T.选题编号) WHERE 学号 = '" + Pass.LoginRule.username + "'"); mydv = mytable.DefaultView; //获得DataView对象mydv //以下设置dataGridView1的属性 dataGridView1.DataSource = mydv; dataGridView1.ReadOnly = true; //只读 dataGridView1.GridColor = Color.Gray; dataGridView1.ScrollBars = ScrollBars.Vertical; dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12); dataGridView1.DefaultCellStyle.Font = new Font("微软雅黑", 10); dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single; //行高,列宽调整到适合位于屏幕上当前显示的行中的列的所有单元格(包括标头单元格)的内容。 dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; }
private void TMbj1_Load(object sender, EventArgs e) { if (TempData.flag == 1) //新增选题记录 { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; } else //修改选题记录 { DataTable mytable = new DataTable(); mytable.Clear(); mytable = CommDbOp.Exesql("SELECT * FROM X_T WHERE 选题编号='" + TempData.no + "'"); textBox1.Text = mytable.Rows[0]["选题编号"].ToString().Trim(); textBox2.Text = mytable.Rows[0]["选题名称"].ToString().Trim(); textBox3.Text = mytable.Rows[0]["关键词"].ToString().Trim(); textBox4.Text = mytable.Rows[0]["实现技术"].ToString().Trim(); textBox1.Enabled = false; //不允许修改编号 textBox2.Focus(); } }
private void button2_Click(object sender, EventArgs e) //确认选课 { string mysql; DataTable mytable1 = new DataTable(); try { mysql = "UPDATE S_T SET 选题编号 = '" + TempData.no + "' WHERE 学号='" + Pass.LoginRule.username + "'"; mytable1 = CommDbOp.Exesql(mysql); MessageBox.Show("恭喜你,选题'" + TempData.no + "'成功!"); } catch (Exception) { MessageBox.Show("请先单击选择你要选的课程", "错误提示"); } condstr = ""; this.STxt_Load(sender, e); //重载数据 }
private void button3_Click(object sender, EventArgs e) //删除确认按钮 { TempData.flag = 3; if (TempData.no != "") { if (MessageBox.Show("真的要删除学号为" + TempData.no + "的学生记录吗?", "删除确认", MessageBoxButtons.OKCancel) == DialogResult.OK) { TempData.flag = 3; string mysql = "DELETE S_T WHERE 学号='" + TempData.no.Trim() + "'"; mytable1 = CommDbOp.Exesql(mysql); this.STbj_Load(sender, e); } } else { MessageBox.Show("先选择要删除的选题记录", "错误提示"); } condstr = ""; this.STbj_Load(sender, e); //重载数据 }
private void XTtj_Load(object sender, EventArgs e) { mytable.Clear(); if (condstr != "") { mytable = CommDbOp.Exesql("select X_T.选题编号, COUNT(X_T.选题编号)人员数 from S_T, X_T where S_T.选题编号 = X_T.选题编号 group by X_T.选题编号 HAVING " + condstr); } else { mytable = CommDbOp.Exesql("select X_T.选题编号, COUNT(X_T.选题编号)人员数 from S_T, X_T where S_T.选题编号 = X_T.选题编号 group by X_T.选题编号"); } mydv = mytable.DefaultView; //获得DataView对象mydv //以下设置dataGridView1的属性 dataGridView1.DataSource = mydv; dataGridView1.ReadOnly = true; //只读 dataGridView1.GridColor = Color.Gray; dataGridView1.ScrollBars = ScrollBars.Vertical; dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12); dataGridView1.DefaultCellStyle.Font = new Font("微软雅黑", 10); dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single; //行高,列宽调整到适合位于屏幕上当前显示的行中的列的所有单元格(包括标头单元格)的内容。 dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; }
private void button1_Click(object sender, EventArgs e) { string Sex, mysql; DataTable mytable1 = new DataTable(); if (textBox1.Text.ToString() == "") { MessageBox.Show("必须输入学号", "错误提示"); return; } if (textBox2.Text.ToString() == "") { MessageBox.Show("必须输入姓名", "错误提示"); return; } if (textBox3.Text.ToString() == "") { MessageBox.Show("必须输入年龄", "错误提示"); return; } if (textBox4.Text.Trim() == "") { MessageBox.Show("必须输入班级", "错误提示"); return; } if (textBox5.Text.Trim() == "") { MessageBox.Show("必须输入专业", "错误提示"); return; } if (radioButton1.Checked) { Sex = "男"; } else if (radioButton2.Checked) { Sex = "女"; } else { Sex = ""; } try { if (TempData.flag == 1) //新增学生记录 { mytable1 = CommDbOp.Exesql("SELECT * FROM S_T WHERE 学号='" + textBox1.Text + "'"); if (mytable1.Rows.Count == 1) { MessageBox.Show("输入的学号重复,不能新增学生记录", "错误提示"); textBox1.Focus(); return; } else //不重复时插入学生记录 { mysql = "INSERT INTO S_T (学号,姓名,性别,年龄,班级,专业,密码) VALUES( '" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + Sex + "','" + textBox3.Text.Trim() + "','" + textBox4.Text.Trim() + "','" + textBox5.Text.Trim() + "','" + textBox1.Text.Trim() + "')"; //初始密码学号 mytable1 = CommDbOp.Exesql(mysql); this.Close(); } } else //修改选题记录 { mysql = "UPDATE S_T SET 姓名='" + textBox2.Text.Trim() + "',性别='" + Sex + "',年龄='" + textBox3.Text.Trim() + "',班级='" + textBox4.Text.Trim() + "',专业='" + textBox5.Text.Trim() + "' WHERE 学号='" + textBox1.Text.Trim() + "'"; mytable1 = CommDbOp.Exesql(mysql); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "错误提示"); } }
private void button1_Click(object sender, EventArgs e) { string mysql; DataTable mytable1 = new DataTable(); if (textBox1.Text.ToString() == "") { MessageBox.Show("必须输入选题编号", "错误提示"); return; } if (textBox2.Text.ToString() == "") { MessageBox.Show("必须输入选题名称", "错误提示"); return; } if (textBox3.Text.ToString() == "") { MessageBox.Show("必须输入关键词", "错误提示"); return; } if (textBox4.Text.Trim() == "") { MessageBox.Show("必须输入实现技术", "错误提示"); return; } try { if (TempData.flag == 1) //新增选题记录 { mytable1 = CommDbOp.Exesql("SELECT * FROM X_T WHERE 选题编号='" + textBox1.Text + "'"); if (mytable1.Rows.Count == 1) { MessageBox.Show("输入的编号重复,不能新增选题记录", "错误提示"); textBox1.Focus(); return; } else //不重复时插入选题记录 { mysql = "INSERT INTO X_T VALUES( '" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "','" + textBox4.Text.Trim() + "')"; mytable1 = CommDbOp.Exesql(mysql); this.Close(); } } else //修改选题记录 { mysql = "UPDATE X_T SET 选题名称='" + textBox2.Text.Trim() + "',关键词='" + textBox3.Text.Trim() + "',实现技术='" + textBox4.Text.Trim() + "' WHERE 选题编号='" + textBox1.Text.Trim() + "'"; mytable1 = CommDbOp.Exesql(mysql); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "错误提示"); //捕获错误 } }