/// <summary> /// 静态方法,获取表中所有数据 /// </summary> /// <returns></returns> static public List <DataEntity> Get() { SqlEntity sqlEntity = new SqlEntity(); if (sqlEntity.Cnt == null) { return(null); } else { string sql = "select * from " + tablename + ";"; try { MySqlCommand cmd = new MySqlCommand(sql, sqlEntity.Cnt); var reader = cmd.ExecuteReader(); if (reader == null) { sqlEntity.close(); return(null); } List <DataEntity> dataList = new List <DataEntity>(); while (reader.Read()) { DataEntity dataEntity = new DataEntity(); dataEntity.userid = reader.GetString("userid"); dataEntity.username = reader.GetString("username"); dataEntity.sex = (int)reader.GetDouble("sex"); dataEntity.grade = (int)reader.GetDouble("grade"); dataEntity.chinese = reader.GetDouble("chinese"); dataEntity.math = reader.GetDouble("math"); dataEntity.english = reader.GetDouble("english"); if (!reader.IsDBNull(7)) { dataEntity.remark = reader.GetString("remark"); } else { dataEntity.remark = ""; } dataList.Add(dataEntity); } sqlEntity.close(); return(dataList); } catch { sqlEntity.close(); return(null); } } }
/// <summary> /// 静态方法,根据id获取对象 /// </summary> /// <param name="userid"></param> /// <returns>查询所得的datainfo对象</returns> static public DataEntity GetByID(string userid) { SqlEntity sqlEntity = new SqlEntity(); if (sqlEntity.Cnt == null) { return(null); } else { string sql = "select * from " + tablename + " where userid='" + userid + "';"; try { MySqlCommand cmd = new MySqlCommand(sql, sqlEntity.Cnt); var reader = cmd.ExecuteReader(); if (reader == null) { sqlEntity.close(); return(null); } DataEntity dataEntity = new DataEntity(); while (reader.Read()) { dataEntity.userid = reader.GetString("userid"); dataEntity.username = reader.GetString("username"); dataEntity.sex = reader.GetInt16("sex"); dataEntity.grade = reader.GetInt16("grade"); dataEntity.chinese = reader.GetDouble("chinese"); dataEntity.math = reader.GetDouble("math"); dataEntity.english = reader.GetDouble("english"); if (!reader.IsDBNull(6)) { dataEntity.remark = reader.GetString("remark"); } else { dataEntity.remark = ""; } } sqlEntity.close(); return(dataEntity); } catch { sqlEntity.close(); return(null); } } }
/// <summary> /// 登陆按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { string username = Username.Text.ToString(); string userpwd = Userpwd.Text.ToString(); SqlEntity entity = new SqlEntity(); if (entity.Cnt == null) { Form2 f2 = new Form2(); f2.ShowDialog(); } //查询数据库是否有该用户密码信息 var user = DataSystem.UserEntity.GetByID(username); if (user.Userid == null) { Form3 f3 = new Form3(); f3.ShowDialog(); } else if (!userpwd.Equals(user.Userpwd)) { Form3 f3 = new Form3(); f3.ShowDialog(); } else { DataSystem.Customer.Userid = user.Userid; DataSystem.Customer.Job = user.Job; if (Customer.isAdmin()) { changeFormToAdmin(); } else { changeFormToStd(); } } }