Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string sql1;
                dbConnection.Open();
                sql1 = string.Format("update people set no='{0}',name='{1}',sex='{2}',job='{3}',keyy='{4}',tel='{5}' where no='{6}';", textBox1.Text, textBox2.Text, comboBox1.Text, value4, textBox5.Text, textBox6.Text, no);

                lo_cmd1.CommandText = sql1;
                int count = lo_cmd1.ExecuteNonQuery();
                if (count > 0)
                {
                    MessageBox.Show("修改信息成功!", "修改成功", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (textBox1.Text != value1 || textBox5.Text != value5)
                    {
                        this.Close();
                        MessageBox.Show("您已修改了用户名或密码,请重新登录!");
                        //登录界面 mainForm = new 登录界面();
                        //mainForm.Show();
                    }
                    else
                    {
                        Form16 mainForm2 = new Form16(textBox1.Text, textBox2.Text);

                        this.Close();
                        mainForm2.Show();
                    }
                }
                else
                {
                    MessageBox.Show("修改信息失败!", "修改失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "操作数据库出错", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            dbConnection.Close();
        }
Exemplo n.º 2
0
        private void 登录_Click(object sender, EventArgs e)
        {
            try
            {
                dbConnection.Open();
                string UserName = textBox1.Text;
                string PassWord = textBox2.Text;
                string keyyy    = null;
                string jobb     = null;
                string namee    = null;



                lo_cmd.CommandText = string.Format("select keyy from people where no={0};", UserName);

                SqlDataAdapter dbAdapter = new SqlDataAdapter(lo_cmd);
                DataSet        ds        = new DataSet(); //创建数据集对象
                dbAdapter.Fill(ds);
                keyyy = ds.Tables[0].Rows[0][0].ToString();



                lo_cmd2.CommandText = string.Format("select job from people where no={0};", UserName);

                SqlDataAdapter dbAdapter2 = new SqlDataAdapter(lo_cmd2);
                DataSet        ds2        = new DataSet(); //创建数据集对象
                dbAdapter2.Fill(ds2);
                jobb = ds2.Tables[0].Rows[0][0].ToString();



                lo_cmd3.CommandText = string.Format("select name from people where no={0};", UserName);

                SqlDataAdapter dbAdapter3 = new SqlDataAdapter(lo_cmd3);
                DataSet        ds3        = new DataSet(); //创建数据集对象
                dbAdapter3.Fill(ds3);
                namee = ds3.Tables[0].Rows[0][0].ToString();


                if (PassWord == keyyy)
                {
                    if (/*jobb[0]=='s' */ jobb == "student")
                    {
                        string message;
                        message = string.Format("{0}同学你好!欢迎进入教室管理系统!", namee);
                        MessageBox.Show(message, "登陆成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Form5 mainForm = new Form5(UserName, namee);
                        mainForm.Show();
                        // this.Hide();
                    }
                    else if (jobb[0] == 't')
                    {
                        string message;
                        message = string.Format("{0}老师你好!欢迎进入教室管理系统!", namee);
                        MessageBox.Show(message, "登陆成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Form16 mainForm = new Form16(UserName, namee);
                        mainForm.Show();
                        // this.Hide();
                    }
                    else if (jobb[0] == 'm')
                    {
                        string message;
                        message = string.Format("{0}你好!欢迎进入教室管理系统!", namee);
                        MessageBox.Show(message, "登陆成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Form20 mainForm = new Form20(UserName, namee);
                        mainForm.Show();
                        // this.Hide();
                    }
                    else
                    //if(jobb=="admini ")
                    {
                        //MessageBox.Show(jobb);
                        //MessageBox.Show(PassWord);
                        string message;
                        message = string.Format("尊敬的管理员{0}欢迎进入教室管理系统!", namee);
                        MessageBox.Show(message, "登陆成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Form3 mainForm = new Form3();
                        mainForm.Show();
                        //  this.Hide();
                    }
                }
                else
                {
                    MessageBox.Show("您输入的用户名或密码错误1!", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }


            catch (Exception i)
            {
                MessageBox.Show("您输入的用户名或密码错误2!", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                MessageBox.Show(i.Message);
            }
            dbConnection.Close();
        }