public void LoadData_Student() { if (Maticsoft.Common.StaticDataClass.userType.Equals("管理员")) { dsStudent = new Maticsoft.BLL.Students().GetList(""); } else { dsStudent = new Maticsoft.BLL.Students().GetList(String.Format("ID = '{0}'", Maticsoft.Common.StaticDataClass.loginStudentID)); } dsStudent.Tables["ds"].Columns["ID"].ColumnName = "学号"; dsStudent.Tables["ds"].Columns["stuName"].ColumnName = "姓名"; dsStudent.Tables["ds"].Columns["stuSex"].ColumnName = "性别"; dsStudent.Tables["ds"].Columns["stuCollege"].ColumnName = "学院"; dsStudent.Tables["ds"].Columns["stuMajor"].ColumnName = "专业"; dsStudent.Tables["ds"].Columns["stuClass"].ColumnName = "班级"; dgvStudent.DataSource = dsStudent.Tables["ds"]; int columnNumber = dgvStudent.ColumnCount; foreach (DataGridViewColumn col in dgvStudent.Columns) { col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; col.SortMode = DataGridViewColumnSortMode.NotSortable; col.FillWeight = 100 / columnNumber; } dgvStudent.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvStudent.AllowUserToAddRows = false; dgvStudent.RowHeadersVisible = false; dgvStudent.ReadOnly = true; }
private void btLogin_Click(object sender, EventArgs e) { string userName = tbUserName.Text.Trim(), passwd = tbPasswd.Text.Trim(), userType = combUserType.SelectedItem.ToString().Trim(); if (userName == "" || userName == null || passwd == "" || passwd == null || userType == "" || userType == null) { MessageBox.Show("不能有空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { int n = 0; switch (userType) { case "管理员": n = new Maticsoft.BLL.Administrators().GetRecordCount(String.Format("userName = '******' and passwd = '{1}'", userName, passwd)); break; case "学生": n = new Maticsoft.BLL.Students().GetRecordCount(String.Format("ID = '{0}' and passwd = '{1}'", userName, passwd)); Maticsoft.Common.StaticDataClass.loginStudentID = userName; break; case "教师": n = new Maticsoft.BLL.Teachers().GetRecordCount(String.Format("ID = '{0}' and passwd = '{1}'", userName, passwd)); Maticsoft.Common.StaticDataClass.loginTeacherID = userName; break; } if (n > 0) { MessageBox.Show("登录成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); Maticsoft.Common.StaticDataClass.userType = userType; this.Hide(); new Main().ShowDialog(this); } else { MessageBox.Show("用户名或密码错误!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void btSearchByStuID_Click(object sender, EventArgs e) { Maticsoft.Common.StaticDataClass.student.ID = ""; string ID = tbStuID.Text.Trim(); if (ID == null || ID == "") { MessageBox.Show("不能有空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { DataSet ds = new Maticsoft.BLL.Students().GetList(String.Format("ID = '{0}'", ID)); if (ds.Tables.Count > 0 && ds.Tables["ds"].Rows.Count > 0) { ds.Tables["ds"].Columns["ID"].ColumnName = "学号"; ds.Tables["ds"].Columns["stuName"].ColumnName = "姓名"; ds.Tables["ds"].Columns["stuSex"].ColumnName = "性别"; ds.Tables["ds"].Columns["stuCollege"].ColumnName = "学院"; ds.Tables["ds"].Columns["stuMajor"].ColumnName = "专业"; ds.Tables["ds"].Columns["stuClass"].ColumnName = "班级"; dgvStudent.DataSource = ds.Tables["ds"]; int columnNumber = dgvStudent.ColumnCount; foreach (DataGridViewColumn col in dgvStudent.Columns) { col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; col.SortMode = DataGridViewColumnSortMode.NotSortable; col.FillWeight = 100 / columnNumber; } dgvStudent.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvStudent.AllowUserToAddRows = false; dgvStudent.RowHeadersVisible = false; dgvStudent.ReadOnly = true; } else { MessageBox.Show("查无此人!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }