/// <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> 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]; } } }