重新学c#,发现自己什么都不会了
想用c#写一个WinFrom登陆界面,包括C#代码,和SQL的存储过程
求高手指点。

解决方案 »

  1.   

    项目太多了。
    怎么给你啊。
    建议去  www.51aspx.com
           或者去下载区 下载个项目 就可以了。
      

  2.   

    去网上搜个winform的管理程序  像学生管理系统 工资管理系统 一般都带登录模块的  
      

  3.   

        public void RunText(string SqlText, string SqlCount, int PageId, int PageSize, out ITable Table)
        {
            int num = (PageId > 0) ? PageId : 1;
            int num2 = (PageSize > 0) ? PageSize : 12;
            int num3 = 0;
            int num4 = 0;
            int num5 = (num - 1) * num2;
            int num6 = num5 + num2;
            Table = new ITable();
            num4 = (int) this.CreateCommand(SqlCount, CommandType.Text).ExecuteScalar();
            Table.PageId = num;
            Table.PageSize = num2;
            Table.RecordCount = num4;
            SqlDataReader reader = this.CreateCommand(SqlText, CommandType.Text).ExecuteReader(CommandBehavior.CloseConnection);
            string[] strArray = new string[reader.FieldCount];
            int index = 0;
            while (index < reader.FieldCount)
            {
                strArray[index] = reader.GetName(index);
                index++;
            }
            Table.Columns = strArray;
            while (reader.Read())
            {
                if ((num3 >= num5) && (num3 < num6))
                {
                    IHash record = new IHash();
                    for (index = 0; index < strArray.Length; index++)
                    {
                        record.Add(strArray[index], reader.GetValue(index));
                    }
                    Table.Add(record);
                }
                num3++;
            }
            this.Close();
        }    public void RunText(string SqlText, string SqlCount, SqlParameter[] Parameters, int PageId, int PageSize, out ITable Table)
        {
            int num7;
            int num = (PageId > 0) ? PageId : 1;
            int num2 = (PageSize > 0) ? PageSize : 12;
            int num3 = 0;
            int num4 = 0;
            int num5 = (num - 1) * num2;
            int num6 = num5 + num2;
            Table = new ITable();
            SqlParameter[] parameters = new SqlParameter[Parameters.Length];
            SqlParameter[] parameterArray2 = new SqlParameter[Parameters.Length];
            for (num7 = 0; num7 < Parameters.Length; num7++)
            {
                parameters[num7] = new SqlParameter(Parameters[num7].ParameterName, Parameters[num7].Value);
                parameterArray2[num7] = new SqlParameter(Parameters[num7].ParameterName, Parameters[num7].Value);
            }
            num4 = (int) this.CreateCommand(SqlCount, parameters, CommandType.Text).ExecuteScalar();
            Table.PageId = num;
            Table.PageSize = num2;
            Table.RecordCount = num4;
            SqlDataReader reader = this.CreateCommand(SqlText, parameterArray2, CommandType.Text).ExecuteReader(CommandBehavior.CloseConnection);
            string[] strArray = new string[reader.FieldCount];
            num7 = 0;
            while (num7 < reader.FieldCount)
            {
                strArray[num7] = reader.GetName(num7);
                num7++;
            }
            Table.Columns = strArray;
            while (reader.Read() && (num3 < num6))
            {
                if (num3 >= num5)
                {
                    IHash record = new IHash();
                    for (num7 = 0; num7 < strArray.Length; num7++)
                    {
                        record.Add(strArray[num7], reader.GetValue(num7));
                    }
                    Table.Add(record);
                }
                num3++;
            }
            this.Close();
        }    public IResult RunUpdate(string TableName, bool AllowDbNull, bool Conversion, IHash Record)
        {
            string str = string.Empty;
            string str2 = string.Empty;
            IResult result = new IResult(4, "未执行");
            ArrayList list = new ArrayList();
            ArrayList list2 = new ArrayList();
            this._Conn.Open();
            SqlCommand command = new SqlCommand("SELECT * FROM " + TableName, this._Conn);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.KeyInfo);
            DataTable schemaTable = reader.GetSchemaTable();
            reader.Close();
            this.Close();
            foreach (string str3 in Record.Keys)
            {
                if (this.ColumnIndexOf(schemaTable, str3, true) != string.Empty)
                {
                    bool changeResult = false;
                    object obj2 = this.ColumnChangeType(schemaTable, str3, Record[str3], ref changeResult, true);
                    if (!this.ColumnIsAutoIncrement(schemaTable, str3, true) && !this.ColumnIsKey(schemaTable, str3, true))
                    {
                        if (!(!AllowDbNull && Base.IsNull(obj2)))
                        {
                            string str4 = str;
                            str = str4 + (Base.IsNull(str) ? "[" : ",[") + str3 + "]=@" + str3;
                            list2.Add(new SqlParameter(str3, obj2));
                        }
                    }
                    else
                    {
                        str2 = (Base.IsNull(str2) ? "" : " And ") + "[" + str3 + "]=@" + str3;
                        list.Add(new SqlParameter(str3, obj2));
                    }
                    if (!(Conversion || changeResult))
                    {
                        return new IResult(3, "字段 [" + str3 + "] 值类型不正确");
                    }
                }
            }
            if (list.Count > 0)
            {
                command = new SqlCommand("Update " + TableName + " Set " + str + " Where " + str2, this._Conn);
                foreach (SqlParameter parameter in list2)
                {
                    command.Parameters.Add(parameter);
                }
                foreach (SqlParameter parameter in list)
                {
                    command.Parameters.Add(parameter);
                }
                this._Conn.Open();
                if (command.ExecuteNonQuery() > 0)
                {
                    result = new IResult(0, "更新记录成功");
                }
                else
                {
                    result = new IResult(1, "更新记录失败");
                }
            }
            else
            {
                result = new IResult(2, "没有设定更新记录的条件");
            }
            this.Close();
            return result;
        }
    }
      

  4.   

    使用sqlite给你写了一个多层的登录实例。
    http://download.csdn.net/source/3110088
    在sqlhelper你可以使用其他数据库的。
    我平时用sqlite保存一些驱动配置信息;部署简单方便
      

  5.   

    我上传了个北大青鸟常用的一个winform学生管理系统,它包含登陆界面,以及最基本的增删改查很适合新手,http://download.csdn.net/source/2877120
      

  6.   


            /// <summary>
            ///建立连接Access 
            /// </summary>
            OleDbConnection oledbcon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\HomeGPdb.mdb");        /// <summary>
            /// 建立查询命令
            /// </summary>
            OleDbCommand oledbcom;        /// <summary>
            /// 设置最高登陆次数,错误的时候
            /// </summary>
            const int DenglCi = 3;        /// <summary>
            /// 读取返回的数据集和
            /// </summary>
            OleDbDataReader oledatar;        private void button1登陆_Click(object sender, EventArgs e)
            {            oledbcom = new OleDbCommand();
                oledbcom.CommandText = "select * from PassandUser";
                oledbcom.Connection = oledbcon;           
                if (CheckSafe())
                {                GetUserFdb(oledbcom);
                  int mush=getpower.Length;                //获取如果不是户主,那么就是客户
                    int tag=this.radioButton1户主.Checked?0:1;                     int i = 0;
                    ///其实我这里能的饿比较麻烦了因为我想的是在,提示用户输入的户名不存在。如果用户输入的户名是存在的话,那么就应该提示说,密码错误,,所以,
                    ///虽然可以有比较简单的写法,但是我还是想尝试一下,
                    ///如,一个while选好,怎样控制输出信息 ,
                    ///么就可以直接判断,如果到了最后的末尾了,那么就可以了;
                         while (i < mush)
                         {                         if (this.textBoxUser.Text.Trim() == getuser[i] && this.textBoxPassword.Text.Trim() == getpass[i] && tag.ToString() == getpower[i])
                             {
                                                            
                                 
                                 StreamWriter sw = new StreamWriter(Environment.CurrentDirectory + @"\" + "us.fxl"); 
                                 sw.AutoFlush = true;
                                 sw.WriteLine(this.textBoxUser.Text.Trim());
                                 sw.WriteLine(this.textBoxPassword.Text.Trim());
                               
                                 sw.Close();
                             
                                 
                                 Thread thread = new Thread(new ThreadStart(delegate { new Form1().ShowDialog(); }));
                                 thread.Start();
                                 this.Close();
                                 //表示迫使其停止,F循环
                                 break;
                             }
                             else if (this.textBoxUser.Text.Trim() != getuser[i] || this.textBoxPassword.Text.Trim() != getpass[i] || tag.ToString() != getpower[i])
                             {
                                 i++;
                                 //表示如果搜寻到了最后了还没有的找到的话,就提示错误
                                 if (i ==mush)
                                 {
                                     MessageBox.Show("用户名或密码,权限错误,");
                                 }
                             }
                             
                                             }
                 
                    
                   
                }        }        /// <summary>
            /// 检查用户名和密码的安全性,以及非空等
            /// </summary>
            /// <returns></returns>
            private bool CheckSafe()
            {
                //这里还要防止非空和限制字符数
                if (this.textBoxUser.Text.Trim() != ""&& this.textBoxPassword.Text.Trim() != ""&&this.radioButton1户主.Checked!=false||this.radioButton2成员.Checked!=false)
                {
                    return true;
                }
                else
                {
                    MessageBox.Show("用户名和密码不能为空,必须选择登陆类型");
                    return false;
                }
            }
      

  7.   

    利用三层实现,代码如下:数据访问层public class UserService
        {
            private readonly string connString = ConfigurationManager.ConnectionStrings["LoginConnectionString"].ToString();        public Users GetUsersByNameAndPassWord(string name, string password) 
            {
                Users users = null; ;            using (SqlConnection connection = new SqlConnection(connString)) 
                {
                    string sql = "select * from userinfo where Name = @Name and PassWord = @PassWord";                using (SqlCommand objCommand = new SqlCommand(sql, connection)) 
                    {
                        connection.Open();                    objCommand.Parameters.Add(new SqlParameter("@Name",name));
                        objCommand.Parameters.Add(new SqlParameter("@PassWord",password));                    using (SqlDataReader objReader = objCommand.ExecuteReader()) 
                        {
                            if (objReader.HasRows) 
                            {
                                if (objReader.Read()) 
                                {
                                    users = new Users(objReader["Name"].ToString(),objReader["PassWord"].ToString());
                                }
                            }
                        }
                    }
                }            return users;
            }
        }
    业务逻辑层:
    public class UserManager
        {
            private UserService userservice = new UserService();        public bool IsUsers(string name, string password) 
            {
                if (userservice.GetUsersByNameAndPassWord(name, password) == null)
                {
                    return false;
                }
                else 
                {
                    return true;
                }
            }
        }
    UI层:public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private UserManager usermanager = new UserManager();        public bool checkinfo() 
            {
                if (string.IsNullOrWhiteSpace(this.txtName.Text)) 
                {
                    return false;
                }
                if (string.IsNullOrWhiteSpace(this.txtPassWord.Text)) 
                {
                    return false;
                }            return true;
            }        private void btnLogin_Click(object sender, EventArgs e)
            {
                string name = this.txtName.Text.Trim();
                string password = this.txtPassWord.Text.Trim();            if (checkinfo()) 
                {
                    if (usermanager.IsUsers(name, password))
                    {
                        MessageBox.Show("正确用户!");
                    }
                    else 
                    {
                        MessageBox.Show("错误用户!");
                    }
                }
            }
        }
    此登录界面,我并没有用到SQL存储过程,只是用一些简单的SQL语句来进行的查询,我把
    SQL创建数据库和表的SQL脚本贴出来 
    use master
    go
    if exists(select * from sysdatabases where name = 'Users')
    drop database Users
    go
    create database Users
    on
    (
       name = 'Users'
      ,filename = 'D:\User.mdf'
      ,size = 3mb
      ,maxsize = unlimited
      ,filegrowth = 10%
    )
    log on
    (
       name = 'Users_log'
      ,filename = 'D:\Users_log.ldf'
      ,size = 1mb
      ,maxsize = unlimited
      ,filegrowth = 10%
    )
    gouse Users
    go
    if exists(select * from sysobjects where name = 'userinfo')
    drop table userinfo
    go
    create table userinfo
    (
     Name varchar(50) not null
    ,PassWord varchar(50) not null
    )insert into userinfo(Name,PassWord) values('admin','123456')
    希望楼主采纳!