基本信息
源码名称:C# 实现 登陆注册/省市联动选择 实例源码(sqlite数据库)
源码大小:2.75M
文件格式:.zip
开发语言:C#
更新时间:2017-01-23
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 3 元 
   源码介绍
运用的是sqlite数据库可以进行省市选择,适合初学者使用

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 省市选择
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void addUpdatecmd()
        {
            string constr = ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString;
            using (SQLiteConnection conn = new SQLiteConnection(constr))
            {
                conn.Open();
                using (SQLiteCommand Updatecmd = conn.CreateCommand())
                {

                    Updatecmd.CommandText = "update  T_User set errortime =errortime  1 where UserName=@UserName";
                    Updatecmd.Parameters.Add(new SQLiteParameter("UserName", textBox1.Text));
                    Updatecmd.ExecuteNonQuery();
                }

            }
        }
        private void resetUpdatecmd()
        {
            string constr = ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString;
            using (SQLiteConnection conn = new SQLiteConnection(constr))
            {
                conn.Open();
                using (SQLiteCommand Updatecmd = conn.CreateCommand())
                {

                    Updatecmd.CommandText = "update  T_User set errortime = 0 where UserName=@UserName";
                    Updatecmd.Parameters.Add(new SQLiteParameter("UserName", textBox1.Text));
                    Updatecmd.ExecuteNonQuery();
                }

            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            bool error = false;
            string constr = ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString;
            using (SQLiteConnection conn = new SQLiteConnection(constr))
            {
                conn.Open();
                using (SQLiteCommand cmd = conn.CreateCommand())
                {

                    cmd.CommandText = "select * from T_User where UserName=@UserName";
                    cmd.Parameters.Add(new SQLiteParameter("UserName", textBox1.Text));
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            int errortime = reader.GetInt32(reader.GetOrdinal("errortime"));
                            if (errortime > 3)
                            {
                                MessageBox.Show("登陆次数过多,禁止登陆");
                                return;
                            }

                            string dbpassword = reader.GetString(reader.GetOrdinal("password"));
                            if (dbpassword == textBox2.Text)

                            {
                                MessageBox.Show("登入成功");

                                error = true;

                                this.Close();
                            }
                            else
                            {/*
                                //同一个连接中,如果sqldatareader未关闭,是不能进行update之类的语句

                                using (SqlCommand Updatecmd = conn.CreateCommand())
                                {
                                    Updatecmd.CommandText = "update  T_User set errortime = errortime 1 where UserName=@UserName";
                                    Updatecmd.Parameters.Add(new SqlParameter("UserName", textBox1.Text));
                                    Updatecmd.ExecuteNonQuery();
                                }*/

                                MessageBox.Show("密码错误,登陆失败");
                                error = false;
                            }
                        }
                        else
                        {
                            MessageBox.Show("用户名不存在");
                        }

                    }

                }

            }
            if (error)
            {
                resetUpdatecmd();
              
            }
            else
                addUpdatecmd();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string constr = ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString;
            using (SQLiteConnection conn = new SQLiteConnection(constr))
            {
                bool has = false;
                conn.Open();
                using (SQLiteCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "Insert into T_User(UserName,password)values('"   textBox1.Text   "','"   textBox2.Text   "')  ";
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("注册成功");
                    cmd.CommandText = "select * from T_User where UserName='"   textBox1.Text   "'";
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                            has = true;
                    }

                }

                if (has)
                    resetUpdatecmd();
            }
        }
    }
}