Exemplo n.º 1
0
Arquivo: MainForm.cs Projeto: Gqqq/-
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            int count = this.lvwStudent.SelectedItems.Count;//获取选中项数量

            if (count == 1)
            {
                //获取用户在列表视图中选择项的Tag值,即学生编号
                int stuid = Convert.ToInt32(this.lvwStudent.SelectedItems[0].Tag);
                //创建属性窗体对象时,用构造函数将学生编号传到属性窗体
                PropertyForm p = new PropertyForm(stuid);
                p.Owner = this;
                p.Show();
            }
            else if (count == 0)
            {
                MessageBox.Show("请选择一个学生查看属性");
                return;
            }
            else if (count > 1)
            {
                MessageBox.Show("不能查看多个学生属性,只能选一个");
                return;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 管理员权限登陆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string name = this.txtName.Text.Trim();
            string pass = this.txtPass.Text.Trim();

            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("请输入姓名");
                return;
            }
            if (string.IsNullOrEmpty(pass))
            {
                MessageBox.Show("请输入密码");
                return;
            }
            if (this.textBox1.Text.ToLower() != Ccode.ToLower())
            {
                CreateImage();
                MessageBox.Show("验证码输入错误");
                return;
            }
            //学生登陆
            StudentsModel stumodel = new StudentsModel();
            StudentsBLL   student  = new StudentsBLL();

            if (this.checkBox1.Checked)
            {
                stumodel.Student_Name = this.txtName.Text;
                try
                {
                    DataRow row = student.GetStudentByName(stumodel).Rows[0];

                    string num  = row["StudentNum"].ToString().Substring(10, 4);
                    string cnum = this.txtPass.Text;
                    if (num == cnum)
                    {
                        int          id = Convert.ToInt32(row["Student_ID"]);
                        PropertyForm fm = new PropertyForm(id);
                        fm.Show();
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误");
                        return;
                    }
                }
                catch
                {
                    MessageBox.Show("用户名或密码不匹配");
                }
            }
            else
            {
                AdminInfoModel adminmodel = new AdminInfoModel();
                AdminInfoBLL   admininfo  = new AdminInfoBLL();
                adminmodel.Admin_Name     = name;
                adminmodel.Admin_Password = pass;
                SqlDataReader dr = admininfo.AdminLogin(adminmodel);
                if (dr.Read())                            //如果登陆成功
                {
                    MainForm main = (MainForm)this.Owner; //实例化主窗体
                    //将管理员的ID和权限保存到主窗体全局字段
                    main.adminid = Convert.ToInt32(dr["Admin_ID"]);
                    main.level   = dr["Admin_Level"].ToString();
                    islog        = true; //将是否登陆成功的标识改为true
                    dr.Close();          //关闭阅读器
                    this.Close();        //关闭主窗体
                }
                else
                {
                    dr.Close();
                    MessageBox.Show("用户名或密码错误");
                    return;
                }
            }
        }