请问如何用C#编写用户登陆界面,最好带一个简单的示例。谢谢!

解决方案 »

  1.   

    ?C/S?B/S?
    2个文本框输入用户名秘密,在BUTTON下查询两个输入结果,与数据库相应的字段匹配,如果匹配,。如果不匹配,提示错误,文本清空
      

  2.   

    可参考:http://www.cnblogs.com/KissKnife/archive/2006/09/10/500158.html
      

  3.   

    if (txtUser.Text == "" || txtPassword.Text == "")
                {
                    MessageBox.Show("请输入用户名和密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else 
                {
                    try
                    {
                        myConnection = new SqlConnection(Login.Connection);
                        SqlCommand myCommand = myConnection.CreateCommand();
                        myCommand.CommandText = "SELECT UserSort " +
                                                "From Users " +
                                                "Where UserID = '" + txtUser.Text +
                                                "' And UserPassword = '" + txtPassword.Text + "'";
                        myConnection.Open();
                        Sort = myCommand.ExecuteReader();
                        try
                        {
                            Sort.Read();
                            //如果由返回的项得到 “System”,则弹出完整功能界面
                            if (Sort.GetString(0) == "System")
                            {
                                this.Hide();
                                MMForm.ManageForm myMF = new MMForm.ManageForm(true);
                                myMF.ShowDialog();
                                this.Close();    //在主功能界面退出后同时关闭登录界面
                            }
                            //如果由返回的项得到 "User" ,则屏蔽用户信息维护功能
                            if (Sort.GetString(0) == "User")
                            {
                                this.Hide();
                                MMForm.ManageForm myMF = new MMForm.ManageForm(false);
                                myMF.ShowDialog();
                                this.Close();       //在主功能界面退出后同时关闭登录界面
                            }
                        }
                        catch
                        {
                            MessageBox.Show("请输入正确的用户名和密码!!!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                        }
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show("连接数据库错误:" + ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        myConnection.Close();   //释放数据库连接
                    }
      

  4.   

    if (txtUser.Text == "" || txtPassword.Text == "")
                {
                    MessageBox.Show("请输入用户名和密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else 
                {
                    try
                    {
                        myConnection = new SqlConnection(Login.Connection);
                        SqlCommand myCommand = myConnection.CreateCommand();
                        myCommand.CommandText = "SELECT UserSort " +
                                                "From Users " +
                                                "Where UserID = '" + txtUser.Text +
                                                "' And UserPassword = '" + txtPassword.Text + "'";
                        myConnection.Open();
                        Sort = myCommand.ExecuteReader();
                        try
                        {
                            Sort.Read();
                            //如果由返回的项得到 “System”,则弹出完整功能界面
                            if (Sort.GetString(0) == "System")
                            {
                                this.Hide();
                                MMForm.ManageForm myMF = new MMForm.ManageForm(true);
                                myMF.ShowDialog();
                                this.Close();    //在主功能界面退出后同时关闭登录界面
                            }
                            //如果由返回的项得到 "User" ,则屏蔽用户信息维护功能
                            if (Sort.GetString(0) == "User")
                            {
                                this.Hide();
                                MMForm.ManageForm myMF = new MMForm.ManageForm(false);
                                myMF.ShowDialog();
                                this.Close();       //在主功能界面退出后同时关闭登录界面
                            }
                        }
                        catch
                        {
                            MessageBox.Show("请输入正确的用户名和密码!!!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                        }
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show("连接数据库错误:" + ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        myConnection.Close();   //释放数据库连接
                    }