当前位置:编程学习 > C#/ASP.NET >>

C#开发开发登陆界面

麻烦问下有没有人用C#开发开发登陆界面 --------------------编程问答-------------------- ? --------------------编程问答-------------------- 当然开发过的 --------------------编程问答-------------------- 你想问什么? --------------------编程问答-------------------- 请说明你这个界面里面需要包含的功能。 --------------------编程问答-------------------- 就是很一般的登录界面,包含用户名、密码、验证码等,数据库用的是SQLServer --------------------编程问答-------------------- 如果有麻烦帮帮我吧,第一次接触,而且尽快要交,快急死我了!谢谢了! --------------------编程问答-------------------- 你问的真郁闷! --------------------编程问答-------------------- - -!!拖控件 --------------------编程问答-------------------- LZ 
开发过了  你自己多找找点书来看呀
书上到处都是呢。 --------------------编程问答-------------------- using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;




namespace 第n次
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Data.DataSet dataSet1;
protected System.Web.UI.WebControls.Label Message;
protected System.Web.UI.WebControls.TextBox nameTextBox;
protected System.Web.UI.WebControls.TextBox PasswordTextBox;
protected System.Web.UI.WebControls.Label Label3;
        
private void Page_Load(object sender, System.EventArgs e)
{   
// 在此处放置用户代码以初始化页面
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.dataSet1 = new System.Data.DataSet();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
// 
// dataSet1
// 
this.dataSet1.DataSetName = "NewDataSet";
this.dataSet1.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();

}
#endregion

private void Button2_Click(object sender, System.EventArgs e)

{
       Response.Redirect ("WebForm2.aspx?");
}

private void Button1_Click(object sender, System.EventArgs e)
{
string s_name= nameTextBox.Text .Trim ();
string s_Password =PasswordTextBox.Text .Trim ();
string strsel = "select name,Password from userdata where name = '"+s_name+"' and Password = '"+s_Password+"'";
//string strsel = "select User_Name,User_Password from Info_userdata where name = '"+s_name+"'";
            
SqlConnection cn = new SqlConnection("server=ED32E0D74620400;uid=sa;pwd=;database=kang");
SqlCommand cmd = new SqlCommand(strsel, cn);
cn.Open();
SqlDataReader myDr = cmd.ExecuteReader();
if(myDr.Read())
{         
this.Visible=false;
Response.Redirect ("WebForm3.aspx?");


}
else
{
  Response.Write("密码和用户不一致");
}
myDr.Close();
cn.Close();

         


}


}
} --------------------编程问答-------------------- 你说的这个功能都是最基本的功能,网上搜一下应该是现成的代码的 --------------------编程问答-------------------- 我也看了很多书,可是上面的程序总是调不通!郁闷阿! --------------------编程问答-------------------- using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.UI.Page.User; 

public partial class _Default : System.Web.UI.Page
    {
    
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

    }
    protected void rb1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, System.EventArgs e)
    {
        if (Page.IsValid == true)
        {
            User user = new User();
            string userid = "";
            SqlDataReader recs =
                user.GetUserButton(username.Text.Trim(),
                   UserDB.Encrypt(Password.text.Trim()));
            if (recs.Read())
            {
                userid = recs["User_id"].ToString();
            }
            recs.Close();
            if ((userid != null) && (userid != ""))
            {
            Session["UserID"]=userid;
                Response.Redirect("~/DesktopModules/index.aspx");
            }
else
            {
            Mseeage.Text=" 你输入的用户名称或者密码有误,请重新输入!";
            }


        }

    }
    pubic SqlDataReader GetUserButton(String sUsername,String sPassword)
    {
        Database db = new Database();
        SqlDataReader dr=null;
        SqlParameter[]param={
            db.CreateInParam("@username",SqlDbType.VarChar,50,sUsername),
            db.CreateInParam("@Password",SqlDbType.VarChar,255.sPassword)
        };
        db.RunProc("Pr_GetUserButton",param,out dr);
        return dr;
    }
    }
    }

}
这是我的程序,还没有加验证码那一块,结果出现了以下两个错误:
错误 1 应输入 ; D:\网站1\index.aspx.cs 56 25 D:\网站1\
错误 2 应输入类型、命名空间定义或文件尾 D:\网站1\index.aspx.cs 68 5 D:\网站1\
--------------------编程问答-------------------- 是不是文件的

}号少了 --------------------编程问答-------------------- 我对了一下,没有少啊! --------------------编程问答-------------------- 现在解决了第二个问题,可是第一个应输入;不知道在哪里缺啊! --------------------编程问答-------------------- 高手进来,不要走啊!麻烦帮一下阿!刚开始接触,实在是弄不懂,谢谢了!在线等! --------------------编程问答-------------------- 编译错误还是运行错误啊? --------------------编程问答-------------------- 这是我的程序,还没有加验证码那一块,结果出现了以下两个错误:
错误 1 应输入 ; D:\网站1\index.aspx.cs 56 25 D:\网站1\
这是运行后的错误!不知道是什么原因阿! --------------------编程问答-------------------- 这是论坛.不是补习区...

要交作业就自己多用用功... --------------------编程问答-------------------- db.CreateInParam("@Password",SqlDbType.VarChar,255.sPassword

255.sPassword ??? --------------------编程问答-------------------- 我日..连这个都看不懂..去幼儿园多学两年再来 --------------------编程问答-------------------- lz --------------------编程问答-------------------- 是学生吗? --------------------编程问答-------------------- 怎么没人进来阿?好着急啊! --------------------编程问答-------------------- 无语 --------------------编程问答-------------------- 给你个好用的代码,我以前开发的:

主函数你知道在哪,不用多说了吧:
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FrmLogin winLogin = new FrmLogin();
            winLogin.ShowDialog();
            if (ClsApp.blnLogin)    //ClsApp作全局对象用,包含静态Public变量和函数
            {
                Application.Run(new FrmMain());
            }

        }//end main

--------------------------------------------------------------
下面是Login窗口的登录代码:

//确定按钮处理事件
        private void btnOk_Click()
        {
            if (funLogin())
            {
... //其它处理代码
                this.Close();
            }
        }


System.Data.SqlClient.SqlConnection cnSql;

        //用户登录验证处理函数
        private bool funLogin()
        {
            if (txtUser.Text.Trim() == "")
            {
                MessageBox.Show("用户ID不能为空!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }

            labMessage.Text = "正在登录,请稍候...";
            Application.DoEvents();

            //下面是数据库连接函数(该会的吧)
            if (ClsApp.funSqlConnect(strServerName, strDatabase, strUser, strPass, cnSql)< 0)
            {
                labMessage.Text = "连接失败!";
                MessageBox.Show("Sorry!由于网络原因数据库联接失败!\r\n" + ClsApp.strErrMessage, "注意", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            string strPass, strTemp;
            System.Data.SqlClient.SqlCommand cmSql = new System.Data.SqlClient.SqlCommand();
            System.Data.SqlClient.SqlDataReader drSql;

            cmSql.Connection = cnSql;
            cmSql.CommandText = "SELECT * FROM user WHERE (userid = '" + txtUser.Text.Trim() + "')";
            try
            {
                if (cnSql.State == ConnectionState.Closed) ClsApp.cnSql.Open();
                drSql = cmSql.ExecuteReader();
                if (drSql.Read())
                {
                    strPass = drSql["password"].ToString();
                    //strTemp = ClsApp.funGetMD5Code(txtPass.Text.Trim(), txtUser.Text.Trim().ToUpper());//你暂时可以不用加密
    strTemp = txtPass.Text.Trim();
                    if (strTemp == strPass)
                    {
//ClsApp.strUserID和ClsApp.strUserName都是静态变量可供后面程序使用
                        ClsApp.blnLogin = true;
                        ClsApp.strUserID = txtUser.Text.Trim();
                        ClsApp.strUserName = drSql["named"].ToString();
                        labMessage.Text = "登录成功.";
                        drSql.Close();
                    }
                    else
                    {
                        drSql.Close();
                        ClsApp.blnLogin = false;
                        labMessage.Text = "登录失败!";
                        txtPass.Select(0, txtPass.Text.Length);
                        MessageBox.Show("密码验证错误!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return false;
                    }
                }
                else
                {
                    drSql.Close();
                    ClsApp.blnLogin = false;
                    labMessage.Text = "登录失败!";
                    txtUser.Select(0, txtUser.Text.Length);
                    MessageBox.Show("用户验证错误!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "注意", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            finally
            {
                cnSql.Close();
            }
            return true;

        }//end function


-------------------------------------------------------------------------------------
下面是ClsApp类里数据库连接函数(做成函数方便你以后调用):

        public static int funSqlConnect(string asServerName, string asDataBase, string asUserId, string asPassword, System.Data.SqlClient.SqlConnection acnSql)
        {
            //说明:连接SQL数据库
            //参数:asServerName(服务器名)、asDataBase(数据库名)、asUserId(用户ID)、asPassword(口令)、acnSql(保存SQL连接对象)
            //返回:0(成功)
            string lsCn;

            lsCn = "data source=" + asServerName + ";initial catalog=" + asDataBase + ";user id=" + asUserId + ";password=" + asPassword;
            try
            {
                if (acnSql == null)
                {
                    acnSql = new System.Data.SqlClient.SqlConnection(lsCn);
                }
                else
                {
                    acnSql.ConnectionString = lsCn;
                }
                acnSql.Open();
            }
            catch (Exception ex)
            {
                intActionCode = -1; //可省略
                strErrMessage = ex.Message; //可省略
                //MessageBox.Show(Err.Description, "注意", MessageBoxButtons.OK, MessageBoxIcon.Error)
                return intActionCode;
            }
            return 0;
        }
--------------------编程问答-------------------- 不懂你在说什么 --------------------编程问答-------------------- 用什么vs版本,如果是2005很好办啊,本身就自带了登录控件的,拖出来设置一下就OK了 --------------------编程问答-------------------- 谢谢啊!我用的就是2005,但是他的登陆控件,和我们的需求不太一样!而且数据库也不一致! --------------------编程问答-------------------- using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection my = new SqlConnection();
            my.ConnectionString = "server=localhost;uid=sa;database=pubs";
            my.Open();
            string se = "select * from userinfo where uid='" + this.textBox1.Text + "'and pwd='" + this.textBox2.Text + "'";
            SqlCommand cmd = new SqlCommand(se, my);
            SqlDataReader reader = cmd.ExecuteReader();
            reader.Read();

            try
            {
                if (textBox1.Text.Equals(reader.GetString(0)))
                {


                    Form2 f1 = new Form2();
                   this.Hide();
                    f1.ShowDialog();
                    this.Close();

                }
                

            }

            catch
            {
                MessageBox.Show("登陆失败!!!");//异常提示 
            }
            finally
            {
                my.Close();
                cmd.Dispose();
                my.Dispose();
            }
        }
    }
} --------------------编程问答-------------------- 用sql2000与vs2005. 建两个textbox 还有一个button与一个form2。。我也是初学,刚弄出来。。 --------------------编程问答-------------------- up
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,