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); } } }
public void LoadData_Admin() { dsAdmin = new Maticsoft.BLL.Administrators().GetList(""); dsAdmin.Tables["ds"].Columns["ID"].ColumnName = "ID"; dsAdmin.Tables["ds"].Columns["userName"].ColumnName = "用户名"; dgvAdmin.DataSource = dsAdmin.Tables["ds"]; int columnNumber = dgvAdmin.ColumnCount; foreach (DataGridViewColumn col in dgvAdmin.Columns) { col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; col.SortMode = DataGridViewColumnSortMode.NotSortable; col.FillWeight = 100 / columnNumber; } dgvAdmin.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvAdmin.AllowUserToAddRows = false; dgvAdmin.RowHeadersVisible = false; dgvAdmin.ReadOnly = true; }