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;
using MyQQ;
namespace qq
{
public partial class RegisterFrm : Form
{
public RegisterFrm()
{
InitializeComponent();
}
//获得星座
public void GetStarName()
{
SqlCommand cmd = new SqlCommand("SELECT STAR FROM STAR", DbHelper.conn);
SqlDataReader reader = null;
try
{
DbHelper.opendb();
reader = cmd.ExecuteReader();
while (reader.Read())
{
this.cboStar.Items.Add(reader[0]);
}
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
DbHelper.closedb();
}
}
//获的血型
public void GetBloodName()
{
SqlCommand cmd = new SqlCommand("select BloodType from BloodType", DbHelper.conn);
SqlDataReader reader = null;
try
{
DbHelper.opendb();
reader = cmd.ExecuteReader();
while (reader.Read())
{
this.cboBlood.Items.Add(reader[0]);
}
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
DbHelper.closedb();
}
}
//保存头像ID
int faceid;
private void RegisterFrm_Load(object sender, EventArgs e)
{
this.cboStar.Items.Add("--请选择--");
this.cboBlood.Items.Add("--请选择--");
this.cboBlood.Text = "--请选择--";
this.cboStar.Text = "--请选择--";
GetStarName();
GetBloodName();
//靠随机数生成头像
Random rd = new Random();
faceid = rd.Next(0, 100);
}
//获得星座ID
public int GetStarIdByName()
{
int starId = 0;
string sql = string.Format("select id from star where Star = '{0}'",this.cboStar.Text);
SqlCommand cmd=new SqlCommand (sql,DbHelper.conn);
try
{
DbHelper.opendb();
starId = Convert.ToInt32(cmd.ExecuteScalar());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
QQ注册窗体代码
最新推荐文章于 2021-11-28 12:24:29 发布
这是一个使用C#编写的QQ注册窗体代码,包括获取星座和血型的数据库操作,头像随机生成,以及用户输入验证。注册时会检查昵称、年龄、密码等必填项,并对输入进行限制,确保符合格式要求。
摘要由CSDN通过智能技术生成