private void delete(String courseID) { try { string strCon = "server=127.0.0.1;uid=sa;pwd=123456;database=ClassAttendanceManageSystem"; SqlConnection myconn = new SqlConnection(strCon); DataSet myDataSet = new DataSet(); string strcom = "Select *from courseInfo"; string str = "DELETE FROM courseInfo WHERE courseID ='" + courseID + "'"; myconn.Open(); SqlCommand xg; xg = new SqlCommand(str, myconn); if (xg.ExecuteNonQuery() > 0) //判断是否成功 { //执行要操作的语句 SqlDataAdapter mycommand = new SqlDataAdapter(strcom, myconn); myDataSet.Clear(); mycommand.Fill(myDataSet, "courseInfo"); //adminMain.dataGridView1.DataSource = myDataSet.Tables["systemStudent"]; MessageBox.Show("删除成功"); Close(); Form_teacherMain teacher = new Form_teacherMain(); teacher.ShowDialog(); } myconn.Close(); } catch (Exception x) { MessageBox.Show("error!" + x.ToString()); } }
private void button2_Click(object sender, EventArgs e) { this.Close(); Form_teacherMain teacherMain = new Form_teacherMain(); teacherMain.ShowDialog(); }
private void button1_Click(object sender, EventArgs e) { if (!judge()) { MessageBox.Show("请正确输入信息"); } try { string strCon = "server=127.0.0.1;uid=sa;pwd=123456;database=ClassAttendanceManageSystem"; SqlConnection connection = new SqlConnection(strCon); DataSet myDataSet = new DataSet(); string sql = "Select *from courseInfo"; string str = "insert into courseInfo VALUES ('" + CourseNumber.Text.Trim() + "','" + courseName.Text.Trim() + "','" + CourseTime.Text.Trim() + "','" + ClassRoom.Text.Trim() + "','" + CourseNote.Text.Trim() + "')"; connection.Open(); SqlCommand xg; xg = new SqlCommand(str, connection); if (xg.ExecuteNonQuery() > 0) //判断是否成功 { //执行要操作的语句 SqlDataAdapter mycommand = new SqlDataAdapter(sql, connection); myDataSet.Clear(); mycommand.Fill(myDataSet, "courseInfo"); MessageBox.Show("添加成功!请刷新!"); this.Close(); Form_teacherMain teacherMain = new Form_teacherMain(); teacherMain.ShowDialog(); // Form_teacherMain.dataGridView1.DataSource = myDataSet.Tables["courseInfo"]; } connection.Close(); } catch (Exception x) { MessageBox.Show("error!" + x.ToString()); } }
private void button_login_Click(object sender, EventArgs e) { //这里写入刚刚的判断语句 if (!judge()) { MessageBox.Show("账号或密码为空,请正确输入信息", "提示"); return; } try { string strCon = "server=127.0.0.1;uid=sa;pwd=123456;database=ClassAttendanceManageSystem"; SqlConnection connection = new SqlConnection(strCon); DataSet myDataSet = new DataSet(); if (flag == 1) //radioButton1_stu 判断是否为学生用户 { string sql = "Select *from studentInfo where stuID ='" + textBox1.Text.Trim() + "' and stuPassword='******'"; connection.Open(); SqlDataAdapter mycommand = new SqlDataAdapter(sql, connection); myDataSet.Clear(); mycommand.Fill(myDataSet, "studentInfo"); connection.Close(); if (myDataSet.Tables["studentInfo"].Rows.Count > 0) { MessageBox.Show("登录成功!", "提示"); this.Visible = false; Form_studentMain stu = new Form_studentMain(); str = textBox1.Text; //注意,这句不能放在stu.Show();的后面,否则将传值不到其他窗体;会先执行textBox2.Text =stu.str;再执行str = textBox1.Text; str1 = textBox2.Text; //保存密码 stu.Show(); } else { MessageBox.Show("用户名或密码错误!", "提示"); } } else if (flag == 2) { string sql = "Select *from teacherInfo where teacherID ='" + textBox1.Text.Trim() + "' and teacherPassword='******'"; connection.Open(); SqlDataAdapter mycommand = new SqlDataAdapter(sql, connection); myDataSet.Clear(); mycommand.Fill(myDataSet, "teacherInfo"); connection.Close(); if (myDataSet.Tables["teacherInfo"].Rows.Count > 0) { MessageBox.Show("登录成功!", "提示"); this.Visible = false; Form_teacherMain a = new Form_teacherMain(); str = textBox1.Text; //注意,这句不能放在f2.ShowDialog();的后面,否则会先执行textBox2.Text = f1.str;再执行str = textBox1.Text; str1 = textBox2.Text; //保存密码 a.ShowDialog(); } else { MessageBox.Show("用户名或密码错误!", "提示"); } } else if (flag == 3) { string sql = "Select *from adminInfo where adminID ='" + textBox1.Text.Trim() + "' and adminPassword='******'"; connection.Open(); SqlDataAdapter mycommand = new SqlDataAdapter(sql, connection); myDataSet.Clear(); mycommand.Fill(myDataSet, "adminInfo"); connection.Close(); if (myDataSet.Tables["adminInfo"].Rows.Count > 0) { MessageBox.Show("登录成功!", "提示"); this.Visible = false; Form_adminMain a = new Form_adminMain(); str = textBox1.Text; //注意,这句不能放在f2.ShowDialog();的后面,否则会先执行textBox2.Text = f1.str;再执行str = textBox1.Text; str1 = textBox2.Text; //保存密码 a.ShowDialog(); } else { MessageBox.Show("用户名或密码错误!", "提示"); } } else { MessageBox.Show("请选择用户类型!", "提示"); } } catch (Exception x) { MessageBox.Show("error!" + x.ToString()); } }