Beispiel #1
0
        private void txtReg_userName_Leave(object sender, EventArgs e)
        {
            //当控件不再是活动空间时,检查用户名是否重复
            labRgs_username.Text = "";
            //
            string strName = txtReg_userName.Text.Trim();

            if (string.IsNullOrEmpty(strName))
            {
                TextBoxInputError("请输入用户名", labRgs_username, pic_username);
                return;
            }

            //
            int result = CarHomeMethod.CheckUserName(strName);

            if (result == 0)
            {
                TextBoxInputOk(pic_username);
            }
            else
            {
                TextBoxInputError("当前用户名已被注册", labRgs_username, pic_username);
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string uname = txtUserName.Text.Trim(); //Trim 只能移除首尾两端的空格
            //string uname = txtReg_userName.Text.Replace(" ", ""); //Replace 替换所有空格
            string upass = txtPassworld.Text.Trim();

            if (string.IsNullOrEmpty(uname) || string.IsNullOrEmpty(upass))
            {
                MessageBox.Show("请输入用户名和密码");
                return;
            }
            //
            #region 旧代码
            //string sql = "SELECT T_UserName,T_QQNum FROM Users WHERE T_UserName=@UserName and T_Password = @Password;";
            //SQLiteParameter[] parms = new SQLiteParameter[] {
            //    new SQLiteParameter("@UserName",uname),
            //    new SQLiteParameter("@Password",upass)
            //};
            //SQLiteDataReader dr = StaticInfo.SqliteHelper.ExecuteReader(sql, parms);
            //if(dr.HasRows)
            //{
            //    while (dr.Read())
            //    {
            //        StaticInfo.CarUserName = dr["T_UserName"].ToString();
            //        StaticInfo.CarUserQQ = dr["T_QQNum"].ToString();
            //    }
            //    this.Close();
            //}
            //else
            //{
            //    MessageBox.Show("没有数据,请注册");
            //    btnRegister_Click(sender, e);//打开注册窗口
            //}
            #endregion

            CarHomeMethod.Login(uname, upass);
            if (StaticInfo.CheckUserNameIsNull())
            {
                MessageBox.Show("没有数据,请注册");
                btnRegister_Click(sender, e);//打开注册窗口
            }
            else
            {
                this.Close();
            }
        }
Beispiel #3
0
        private void btnReg_Register_Click(object sender, EventArgs e)
        {
            //输入非空判断
            string uname = txtReg_userName.Text.Trim(); //Trim 只能移除首尾两端的空格
            //string uname = txtReg_userName.Text.Replace(" ", ""); //Replace 替换所有空格
            string upass  = txtReg_passwolrd.Text.Trim();
            string upass2 = txtReg_passwolrd2.Text.Trim();
            string uQQ    = txtReg_QQ.Text.Trim();

            if (string.IsNullOrEmpty(uname) || string.IsNullOrEmpty(upass) || string.IsNullOrEmpty(upass2))
            {
                MessageBox.Show("带*号为必填项");
                return;
            }

            //两次输入密码是否一致
            if (!upass.Equals(upass2))
            {
                MessageBox.Show("两次输入的密码不一致");
                return;
            }

            #region  安全的写法,容易找出sql注入
            //字符串拼接的方式 向数据库插入数据
            //string sql = string.Format("INSERT INTO CH_Users (CH_UserName, CH_Passworld, CH_QQ) VALUES({0}, {1}, {2});", uname, upass, uQQ);
            //int res= sqlHelper.ExecuteNonQuery(sql, null);
            //if (res > 0)
            //    MessageBox.Show("恭喜【" + uname + "】注册成功");
            //else
            //    MessageBox.Show("很遗憾【" + uname + "】注册失败");
            #endregion

            #region 旧代码  Ctrl K + S
            //安全写法
            //string sql = "INSERT INTO Users (T_UserName, T_Password, T_QQNum) VALUES(@T_UserName, @T_Password, @T_QQNum);";
            ////
            //SQLiteParameter[] parms = new SQLiteParameter[] {
            //    new SQLiteParameter( "@T_UserName", uname),
            //    new SQLiteParameter( "@T_Password", upass),
            //    new SQLiteParameter( "@T_QQNum", uQQ),
            //};
            //int res = sqlHelper.ExecuteNonQuery(sql, parms);

            //if (res > 0)
            //{
            //    MessageBox.Show("恭喜【" + uname + "】注册成功");
            //    carUserName = uname;
            //    carUserQQ = uQQ;
            //    this.Close();//关闭窗口
            //}
            //else
            //    MessageBox.Show("很遗憾【" + uname + "】注册失败");
            #endregion

            int res = CarHomeMethod.Register(uname, upass, uQQ);

            if (res > 0)
            {
                MessageBox.Show("恭喜【" + uname + "】注册成功");
                StaticInfo.CarUserName = uname;
                StaticInfo.CarUserQQ   = uQQ;
                this.Close();//关闭窗口
            }
            else
            {
                MessageBox.Show("很遗憾【" + uname + "】注册失败");
            }
        }