从Windows窗体中的登录页面重定向

时间:2015-01-12 06:04:11

标签: c# winforms

好的伙计我有2个页面一个登录和一个页面是表单注册我希望登录页面首先出现,并且只有在登录成功后它才会重定向到注册页面。在Web方法中使用Session变量很容易,但是当我尝试在Windows应用程序中执行时,注册页面首先出现,只有在从注册页面注销后才能完成我的整个工作正常。但我希望在启动时本身就应该登录。

这是我写的代码

//----THIS IS IN THE REGISTRATION PAGE
        public static string Admin="";
protected override void OnVisibleChanged(EventArgs e)
    {
        base.OnVisibleChanged(e);
        this.Visible = false;
    }
    private void Form1_Load(object sender, EventArgs e)
    {
        //--------------------------WORKS WHEN FORM IS LOADED
        //this.Visible=false;
        if (Admin == "")
        {
            this.Hide();
            LoginObject.Show();
            //this.Close();
        }
        else
        {
            Admin = LoginObject.AdminId();
            this.Show();
            FormLoaded();
        }
//--------------THIS IS IN LOGIN PAGE

public static string Admin="";
private void ButtonLogIn_Click(object sender, EventArgs e)
    {
        string AdminUserName = TextUserName.Text;
        string AdminPassword = TextPassword.Text;

        //--------------------------------VERIFY ADMIN 

        GetSetAdmin.AdminUserName = AdminUserName;
        GetSetAdmin.AdminPassword = AdminPassword;
        BusinessClassAdminLogin BusniessObject = new BusinessClassAdminLogin();
        string AdminAuthorised = BusniessObject.ValidateAdmin(GetSetAdmin);
        if (!AdminAuthorised.Contains("-1"))
        {
            //Session["Admin"] = AdminAuthorised;
            //Response.Redirect("EmpRegistration.aspx");
            Admin = AdminAuthorised;
            EmpRegistration EmpRegObject = new EmpRegistration();
            this.Hide();
            EmpRegObject.Show();
        }
        else
        {
            MessageBox.Show("UserName or Passowrd Dont Match");
        }
    }
//---------------------MAIN FUNCTIOn 
   static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        //Application.Run(new EmpRegistration());
        Application.Run(new Login());
    }

1 个答案:

答案 0 :(得分:0)

在主页面而不是默认设置登录页面作为起始页面。您可以使用基本表单或单例类来存储登录信息。