/// <summary> /// 修改密码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button3_Click(object sender, EventArgs e) { if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "") { if (string.Equals(textBox2.Text, textBox3.Text)) { if (RegiLogin.Login(toolStripStatusLabel2.Text, textBox1.Text)) { string sqlCommand = "Update AccountOwner set password='******' where account='" + toolStripStatusLabel2.Text + "'"; if (SqlTool.ExecuteNonQuery(User.Student.sqlConStr, sqlCommand) == 1) { MessageBox.Show("修改成功,请重新登录!"); form1.Show(); this.Close(); } else { MessageBox.Show("修改失败!"); } } else { MessageBox.Show("原密码错误!"); } } else { MessageBox.Show("两次密码不一致!"); } } else { MessageBox.Show("请将信息填写完整!"); } }
/// <summary> /// 开始考勤,显示二维码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button1_Click(object sender, EventArgs e) { if (isStart) { MessageBox.Show("正在考勤中!"); } else if (comboBox1.SelectedItem == null) { MessageBox.Show("请选择要考勤的课程!"); } else { isStart = true; //生成初始化考勤记录(全为缺勤) string cNum = ""; //List<string> sNum = new List<string>(); //查询课程号 string sqlCommand_cNum = "select cNum from Course where cName='" + comboBox1.Text + "' and tNum='" + toolStripStatusLabel2.Text + "'"; DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(User.Student.sqlConStr, sqlCommand_cNum); da.Fill(ds); da.Dispose(); cNum = ds.Tables[0].Rows[0][0].ToString(); ds.Dispose(); //查询对应课程的学生学号 string sqlCommand_sNum = "select sNum from Class where cNum='" + cNum + "'"; DataSet ds_sNum = new DataSet(); SqlDataAdapter Da = SqlTool.DataAdapter(User.Student.sqlConStr, sqlCommand_sNum); Da.Fill(ds_sNum); //获取时间 string localtime = DateTime.Now.ToLocalTime().ToString(); // 2019/6/14 20:12:12 string date = localtime.Split(' ')[0]; string time = localtime.Split(' ')[1].Split(':')[0]; c_date = date; c_time = time; foreach (DataRow dr in ds_sNum.Tables[0].Rows) { string sqlCmd = "insert into AttendanceRecord values('" + cNum + "','" + dr[0].ToString() + "','" + "缺勤" + "','" + date + "','" + time + "')"; SqlTool.ExecuteNonQuery(User.Student.sqlConStr, sqlCmd); } MessageBox.Show("考勤开始,请扫描屏幕二维码进行签到!"); //显示二维码 string url = string.Format(@"http://123.207.221.113:8080/home/qiandao.png"); System.Net.WebRequest webreq = System.Net.WebRequest.Create(url); System.Net.WebResponse webres = webreq.GetResponse(); using (System.IO.Stream stream = webres.GetResponseStream()) { pictureBox1.Image = Image.FromStream(stream); } } }
/// <summary> /// 注册账号 /// </summary> /// <param name="Account">账号名</param> /// <param name="Password">密码</param> /// <param name="Owner">账号身份</param> /// <returns>返回一个表示注册是否成功的布尔值</returns> public static bool Regi(string Account, string Password, string Owner, string Name) { //检查账号名是否存在 string sqlCommand = "select * from AccountOwner where account='" + Account + "'"; if (SqlTool.ExecuteReader(Sql, sqlCommand)) { //若账号已存在 return(false); } else { //账号不存在则注册写入数据库 string sqlCommamd_w = "insert into AccountOwner values('" + Account + "','" + Password + "','" + Owner + "','" + Name + "')"; int a = SqlTool.ExecuteNonQuery(Sql, sqlCommamd_w); return(a >= 1); } }
/// <summary> /// 导入新的课程信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button4_Click(object sender, EventArgs e) { if (textBox5.Text == "") { MessageBox.Show("请输入课程号!"); } else if (textBox6.Text == "") { MessageBox.Show("请输入课程名!"); } else if (textBox4.Text == null) { MessageBox.Show("请输入学生信息文件位置!"); } else { string path = @textBox4.Text; //确定文件路径是否存在问题 bool path_isRight = true; try { StreamReader SR = new StreamReader(path, Encoding.Default); } catch (Exception Ex) { path_isRight = false; MessageBox.Show(Ex.Message + "*" + path + "*"); } //文件路径确认无误 if (path_isRight) { StreamReader sr = new StreamReader(path, Encoding.Default); //path为文件路径 string line = ""; //确定此课程信息是否已经存在 string sqlCmd = "select * from Course where cNum='" + textBox5.Text + "'"; //课程信息已存在 if (SqlTool.ExecuteReader(User.Student.sqlConStr, sqlCmd)) { //更新信息 string sqlcmd = "updata Course set cName='" + textBox6.Text + "' where cNum='" + textBox5.Text + "'"; } else { //写入课程号,课程名和教师教工号 String sqlCommand1 = "insert into Course values('" + textBox5.Text + "','" + textBox6.Text + "','" + toolStripStatusLabel2.Text + "')"; SqlTool.ExecuteNonQuery(User.Student.sqlConStr, sqlCommand1); } //写入对应课程的学生信息 string sqlCommand2; while ((line = sr.ReadLine()) != null)//按行读取 line为每行的数据 { sqlCommand2 = "insert into Class values('" + textBox5.Text + "','" + line.Trim() + "')"; SqlTool.ExecuteNonQuery(User.Student.sqlConStr, sqlCommand2); } MessageBox.Show("导入成功,导入信息如表中所示!"); //导入成功后显示导入的信息 string sqlCommand3 = "select * from Class where cNum='" + textBox5.Text + "'"; DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(User.Student.sqlConStr, sqlCommand3); da.Fill(ds); da.Dispose(); dataGridView2.DataSource = ds.Tables[0]; } } }
/// <summary> /// 修改密码 /// </summary> /// <param name="AccountName">账号名</param> /// <param name="Pswd">修改后密码</param> /// <returns>修改是否成功</returns> public bool ChangePswd(string AccountName, string Pswd) { string SqlCommand = "Update Attendance set password='******' where account='" + AccountName + "'"; return(SqlTool.ExecuteNonQuery(sqlConStr, SqlCommand) >= 1); }