首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >QQ项目四之注册界面

QQ项目四之注册界面

作者头像
张哥编程
发布2024-12-13 10:40:30
发布2024-12-13 10:40:30
59500
代码可运行
举报
文章被收录于专栏:云计算linux云计算linux
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
运行
复制
/// <summary>
        /// 第一步:登陆验证方法;7章178页,参考;过滤不正确的数据.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public bool ValidateInput()
        {
            if (txtNickName.Text.Trim().Equals("")) //去除两端空格.
            {
                MessageBox.Show("昵称不能为空","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                txtNickName.Focus();
                return false;
            }
            if (txtLoginPwd.Text.Trim().Equals(""))
            {
                MessageBox.Show("密码不能为空", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtLoginPwd.Focus();
                return false;
            }
            if (!txtLoginPwd.Text.Trim().Equals(txtLoginPwdAgain.Text.Trim()))
            {
                MessageBox.Show("两次密码不一致", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtLoginPwd.Focus();
                return false;
            }

代码语言:javascript
代码运行次数:0
运行
复制
<span style="white-space:pre">  </span>//可以加入不允许输入'和--等SQL 字符,此处省略了
            return true;
        }

        /// <summary>
        /// 第三部,插入数据代码;下面三项是可选项!
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRegist_Click(object sender, EventArgs e)
        {
            string star, bloodtype;
            int qqNum; //申请的QQ号;
            string message; //消息变量

            if (ValidateInput()) //第3步:Ok,数据都符合
            {//执行插入语句
                if (cboStar.Text != "" && cboBloodType.Text != "") //全插入命令
                {
                    star = (cboStar.SelectedIndex + 1).ToString();
                    bloodtype = (cboBloodType.SelectedIndex + 1).ToString();
                }
                else if (cboStar.Text != "" && cboBloodType.Text != "")
                {
                    star = (cboStar.SelectedIndex + 1).ToString();
                    bloodtype = "null";
                }
                else if (cboStar.Text == "" && cboBloodType.Text != "")
                {
                    star = "null";
                    bloodtype = (cboBloodType.SelectedIndex + 1).ToString();
                }
                else
                {
                    star = "null";
                    bloodtype = "null";
                }
                string sql = string.Format("insert users(LoginPwd, NickName, Sex, Age, Name, StarId, BloodTypeId) values('{0}','{1}','{2}',{3},'{4}',{5},{6})",
                    txtLoginPwd.Text.Trim(),
                    txtNickName.Text.Trim(), rdoMale.Checked ? "男" : "女", nudAge.Value,txtName.Text.Trim(),star,
                    bloodtype);
                SqlCommand comm = new SqlCommand(sql, DBHelper.conn); //将sql语句调出,看下出了问题没有
                DBHelper.conn.Open();
                int count = comm.ExecuteNonQuery(); //执行增 删 改
                if (count > 0)
                {
                    sql = "select @@Identity from users"; //执行insert之后,会在内存当中出来一个变量
                    comm.CommandText = sql;
                    qqNum = Convert.ToInt32(comm.ExecuteScalar());
                    message = string.Format("您申请的QQ号码是:{0}",qqNum);
                }
                else {
                    message = "注册失败";
                }
                MessageBox.Show(message,"提示信息");
              
            }
        }
        /// <summary>
        /// 第2步:窗体加载代码,写一段代码,从数据库里面,把数据读取到两个下拉框;
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RegisterForm_Load(object sender, EventArgs e)
        {//考察知识点:SqlDataReader
            string sql = string.Format("select * from star");
            DBHelper.conn.Open();
            SqlCommand comm = new SqlCommand(sql,DBHelper.conn);
            SqlDataReader sdr = comm.ExecuteReader(); //sdr:临时表
            while(sdr.Read()){
                //cboStar.Items.Add(sdr[1].ToString());
                cboStar.Items.Add(sdr.GetString(1)); //两种方式都可以
            }//end。结束while
            sdr.Close();
            DBHelper.conn.Close();
            //*********************************添加血型表数据
代码语言:javascript
代码运行次数:0
运行
复制
//可以使用断开式连接,在此没有使用!
            sql = "select * from BloodType";
            comm.CommandText = sql;
            DBHelper.conn.Open();
            sdr = comm.ExecuteReader();
            while (sdr.Read())
            {
                //cboStar.Items.Add(sdr[1].ToString());
                cboBloodType.Items.Add(sdr.GetString(1)); //两种方式都可以
            }//end。结束while
            sdr.Close();
            DBHelper.conn.Close();
            //**************************************
        }

跳转到选择头像窗体

代码语言:javascript
代码运行次数:0
运行
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MYQQ
{
    /// <summary>
    /// 头像选择窗体
    /// </summary>
    public partial class FacesForm : Form
    {
        //1个人信息窗体,作为要回传的对象;
        public PersonalInfoForm personalInfoForm;   // 个人信息窗体,成员变量,将来回传数据 pif
        //*****************************别动
        public FacesForm()
        {
            InitializeComponent();
        }
        //*****************************星号内别动
        //2窗体加载时显示头像图片,窗体加载事件。
        private void FacesForm_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < ilFaces.Images.Count; i++)
            {
                lvFaces.Items.Add(i.ToString());    //0 1 2 3 4 5
                lvFaces.Items[i].ImageIndex = i;   //每一项的图片索引是i
                //ListViewItem lvi = new ListViewItem(); // listView的每一项,是一个ListViewItem
                //lvi.Tag = i; //隐藏标志
                //lvi.ImageIndex = i;
                //lvFaces.Items.Add(lvi);
            }
        }

        //3确定选择头像,单击Ok按钮代码;
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (lvFaces.SelectedItems.Count == 0)
            {
                MessageBox.Show("请选择一个头像!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                int faceId = lvFaces.SelectedItems[0].ImageIndex;  // 获得当前选中的头像的索引
                personalInfoForm.ShowFace(faceId);  // 设置 个人信息窗体 中显示的头像
                this.Close();
            }
        }         
        //5关闭窗体
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //4双击时选择头像
        private void lvFaces_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int faceId = lvFaces.SelectedItems[0].ImageIndex;  // 获得当前选中的头像的索引
            personalInfoForm.ShowFace(faceId);  // 设置个人信息窗体中显示的头像
            this.Close();
        }
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-04-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档