在winform程序中实现按照不同的角色或用户展现不同的页面

 SqlConnection cn = new SqlConnection(); 
            cn.ConnectionString = "Data Source=192.168.16.71;Initial Catalog=myWork;User ID=sa;Password=sa";
           
            try
            {
                cn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
               
                string sql2 = "select * from dbo.工作微博 where 姓名='" + this.textBox1.Text + "' and 密码='" + this.textBox2.Text + "'";
                cmd.CommandText = sql2; 
                cmd.CommandType = CommandType.Text;
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read()) //如果找到用户信息,说明登录成功
                {

                   
                    switch ("select 权限 from dbo.工作微博 where 姓名='" + this.textBox1.Text + "'")
                    { 
                        case"0":
                            Form2 newForm = new Form2();

                            newForm.Show(); //弹出主窗体

                            
                            break;
                        case "1":
                            Form3 f3 = new Form3();

                            f3.Show(); //弹出主窗体

                            
                            break;
                        case "2":
                            Form1 f1 = new Form1();
                            f1.Show(); //弹出主窗体
                            break;
                            
                            



                    }

posted @ 2013-07-26 13:57  早晚会飞的懒猪  阅读(586)  评论(2编辑  收藏  举报