登录错误自动退出,而且锁定

其他属性同登录,在前文 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Data.SqlClient;

 

namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        int falsesTimes = 0;

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

 

        }

 

        private void btnEsc_Click(object sender, EventArgs e)

        {

            // Application.Exit();直接结束整个应用程序

            this.Close();//只关闭当前窗口,不关闭应用程序

        }

 

        private void btnLogin_Click(object sender, EventArgs e)

        {

            string name = txtName.Text.Trim();

            string pwd = txtPwd.Text;

            string connectionString = "server=.;database=Test;integrated security=true";

            #region 超过三次,退出

            //using (SqlConnection connection = new SqlConnection(connectionString))

            //{

 

            //    connection.Open();

            //    string sql = "select count(1) from UserInfo where name='{0}' and pwd='{1}'";

            //    sql = String.Format(sql, name, pwd);

            //    using (SqlCommand cmd = new SqlCommand(sql, connection))

            //    {

            //        int count = Convert.ToInt32(cmd.ExecuteScalar());

            //        if (count > 0)

            //        {

            //            MessageBox.Show("登陆成功");

            //        }

            //        else

            //        {

            //            MessageBox.Show("登录失败");

            //            falsesTimes++;

            //            if (falsesTimes >= 3)

            //            {

            //                MessageBox.Show("登录失败次数过多,系统自动关闭");

            //                this.Close();

            //            }

            //        }

            //    }

            //}

            #endregion

 

            #region 锁定账号

            using (SqlConnection connection = new SqlConnection(connectionString))

            {

 

                connection.Open();

                string sql = "select count(1) from UserInfo where name='{0}' and pwd='{1}'and DATEDIFF(hour,lockTime,GETDATE())>=24";

                sql = String.Format(sql, name, pwd);

                using (SqlCommand cmd = new SqlCommand(sql, connection))

                {

                    int count = Convert.ToInt32(cmd.ExecuteScalar());//??

                    if (count > 0)

                    {

                        MessageBox.Show("登陆成功");

                    }

                    else

                    {

 

                        sql = "select count(1) from UserInfo where name='{0}' and pwd='{1}'";

                        sql = String.Format(sql, name, pwd);

                        cmd.CommandText = sql;

                        count = Convert.ToInt32(cmd.ExecuteScalar());

                        if (count > 0)

                        {

                            MessageBox.Show("被锁定");

                        }

                        else

                        {

                            falsesTimes++;

                            MessageBox.Show("登录失败,你还有" + (3 - falsesTimes) + "次机会");

 

                            if (falsesTimes >= 3)

                            {

                                MessageBox.Show("登录失败次数过多,系统自动关闭");

                                sql = "update UnserInfo set lockTime=getdate() where name='{0}'";

                                sql = String.Format(sql, name);

                                cmd.CommandText = sql;

                                cmd.ExecuteNonQuery();

 

                                Application.Exit();

                            }

                        }

 

                    }

                }

            }

            #endregion

        }

    }

}

 

全部评论

相关推荐

03-03 23:12
已编辑
北京邮电大学 Java
书海为家:我来给一点点小建议,因为毕竟还在学校不像工作几年的老鸟有丰富的项目经验,面试官在面试在校生的时候更关注咱们同学的做事逻辑和思路,所以最好在简历中描述下自己做过项目的完整过程,比如需求怎么来的,你对需求的解读,你想到的解决办法,遇到困难如何找人求助,最终项目做成了什么程度,你从中收获了哪些技能,你有什么感悟。
你的简历改到第几版了
点赞 评论 收藏
分享
03-26 13:04
已编辑
电子科技大学 算法工程师
xiaowl:你这个简历“条目上”都比较有深度性,但是实际上面试官又没法很好的评估你是怎么达到很多看上去很厉害的结果的。要避免一些看上去很厉害的包装,比如高效的内存复用策略的表达,如果仅是简单的一些内存共享机制,而且面试上也没有深挖的空间,就不要这样表达。比如,工程化模式本质上可能就是定义了一些abstract class,那也就没特别多值得讲的内容。建议简历上应该侧重那些你花了大量时间和精力解决、研究的问题,不要过分追求“丰富”,而是关注在技术深入度、问题解决能力的表现上。
没有实习经历,还有机会进...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务