/// <summary> /// 查询指定考勤信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button5_Click(object sender, EventArgs e) { if (comboBox2.Text == "" || comboBox3.Text == "" || comboBox4.Text == "") { MessageBox.Show("请选择日期时间!"); } else if (comboBox6.Text == "") { MessageBox.Show("请选择查询的课程!"); } else if (comboBox7.Text == "") { MessageBox.Show("请选择查询的时段!"); } else { string date = comboBox2.Text + "/" + comboBox3.Text + "/" + comboBox4.Text; string time = comboBox7.Text; DataSet ds = new DataSet(); string sqlCommand = "select * from AttendanceRecord where date='" + date + "' and time='" + time + "' and cNum in (select cNum from Course where cName='" + comboBox6.Text + "')"; SqlDataAdapter da = SqlTool.DataAdapter(User.Student.sqlConStr, sqlCommand); da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } }
private void Button1_Click(object sender, EventArgs e) { if (RegiLogin.Login(textBox1.Text, textBox2.Text)) { //判断用户身份 string sqlcommand = "select permission from AccountOwner where account='" + textBox1.Text + "'"; DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(User.Student.sqlConStr, sqlcommand); da.Fill(ds); string permission = ds.Tables[0].Rows[0][0].ToString(); //隐藏登录界面 this.Hide(); //显示用户界面 if (String.Equals(permission, "学生"))//学生用户 { Form3 f3 = new Form3(textBox1.Text); this.textBox1.Text = ""; this.textBox2.Text = ""; f3.form1 = this; f3.Show(); } else//教师用户 { Form2 f2 = new Form2(textBox1.Text); this.textBox1.Text = ""; this.textBox2.Text = ""; f2.form1 = this; f2.Show(); } } else { MessageBox.Show("登录失败!"); } }
/// <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 Button6_Click(object sender, EventArgs e) { string sqlcommand = "select s1.cNum,s2.cName from (select * from Class)s1 join (select * from Course)s2 on s1.cNum=s2.cNum where sNum='" + toolStripStatusLabel2.Text + "'"; DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(User.Student.sqlConStr, sqlcommand); da.Fill(ds); dataGridView2.DataSource = ds.Tables[0]; }
/// <summary> /// 查询课程信息 /// </summary> /// <returns>包含此用户的所有课程名的数据集</returns> public DataSet GetCourseInfo() { string SqlCommand = "select cName from Course where cNum in (select cNum from Class where sNum='" + this.StdNum + "')"; DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(sqlConStr, SqlCommand); da.Fill(ds); da.Dispose(); return(ds); }
/// <summary> /// 查询考勤统计信息(某个课程的某个日期的全部考勤信息) /// </summary> /// <param name="cNum">课程号</param> /// <param name="date">日期</param> /// <returns>包含指定考勤信息的数据集</returns> public DataSet GetCsAtdInfo(int cNum, string date) { string SqlCommand = "select * from AttendanceRecord where cNum=" + cNum.ToString() + " and date='" + date + "'"; DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(sqlConStr, SqlCommand); da.Fill(ds); da.Dispose(); return(ds); }
/// <summary> /// 查询考勤信息 /// </summary> /// <returns>包含指定考勤信息的数据集</returns> public DataSet GetAtdInfo() { string SqlCommand = "select * from AttendanceRecord where sNum='" + this.StdNum + "'"; DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(sqlConStr, SqlCommand); da.Fill(ds); da.Dispose(); return(ds); }
/// <summary> /// 选择查询课程 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ComboBox6_DropDown(object sender, EventArgs e) { string sqlCommand = "select cName from Course where tNum='" + toolStripStatusLabel2.Text + "'"; DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(User.Teacher.sqlConStr, sqlCommand); da.Fill(ds, "cName"); da.Dispose(); this.comboBox6.DataSource = ds.Tables["cName"]; this.comboBox6.DisplayMember = "cName"; this.comboBox6.ValueMember = "cName"; }
/// <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="sender"></param> /// <param name="e"></param> private void Button5_Click(object sender, EventArgs e) { if (comboBox6.SelectedItem == null) { MessageBox.Show("请选择查询的课程!"); } else { string sqlcommand = "select * from AttendanceRecord where sNum='" + toolStripStatusLabel2.Text + "' and cNum in (select cNum from Course where cName='" + comboBox6.Text + "')"; DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(User.Student.sqlConStr, sqlcommand); da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } }
/// <summary> /// 查看指定课程信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button6_Click(object sender, EventArgs e) { if (comboBox5.Text == "") { MessageBox.Show("请选择要查询的课程!"); } else { DataSet ds = new DataSet(); string sqlCommand = "select * from Class where cNum in (select cNum from Course where cName='" + comboBox5.Text + "')"; SqlDataAdapter da = SqlTool.DataAdapter(User.Student.sqlConStr, sqlCommand); da.Fill(ds, "course"); da.Dispose(); dataGridView2.DataSource = ds.Tables["course"]; } }
/// <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="Account">账号名</param> /// <param name="Password">密码</param> /// <returns>返回一个表示登陆是否成功的布尔值</returns> public static bool Login(string Account, string Password) { //查询账号是否存在 string sqlCommand = "select password from AccountOwner where account='" + Account + "'"; if (SqlTool.ExecuteReader(Sql, sqlCommand)) { //账号存在检查密码是否正确 DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(Sql, sqlCommand); da.Fill(ds); bool ifSuccess = String.Equals(Password, ds.Tables[0].Rows[0][0].ToString().Trim()); da.Dispose(); return(ifSuccess); } else { //账号不存在 return(false); } }
/// <summary> /// 停止考勤 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Button2_Click(object sender, EventArgs e) { if (isStart) { isStart = false; MessageBox.Show("已停止考勤!"); pictureBox1.Image = null; //查询本次考勤信息 string sqlCommand = "select * from AttendanceRecord where date='" + c_date + "' and time='" + c_time + "' and cNum in (select cNum from Course where cName='" + comboBox1.Text + "')"; DataSet ds = new DataSet(); SqlDataAdapter da = SqlTool.DataAdapter(User.Student.sqlConStr, sqlCommand); da.Fill(ds); da.Dispose(); //创建窗口显示本次考勤信息 本次考勤信息 msg = new 本次考勤信息(ds); msg.Show(); } else { MessageBox.Show("未开始考勤!"); } }
/// <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); }