/// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(RC403ZhangChenYang.Model.Tuser model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Tuser(");
            strSql.Append("QQId,Username,password,Sex,BirthDay,Address)");
            strSql.Append(" values (");
            strSql.Append("@QQId,@Username,@password,@Sex,@BirthDay,@Address)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@QQId",     SqlDbType.NVarChar,  16),
                new SqlParameter("@Username", SqlDbType.NVarChar,  20),
                new SqlParameter("@password", SqlDbType.NVarChar,  20),
                new SqlParameter("@Sex",      SqlDbType.NChar,      2),
                new SqlParameter("@BirthDay", SqlDbType.DateTime),
                new SqlParameter("@Address",  SqlDbType.NVarChar, 100)
            };
            parameters[0].Value = model.QQId;
            parameters[1].Value = model.Username;
            parameters[2].Value = model.password;
            parameters[3].Value = model.Sex;
            parameters[4].Value = model.BirthDay;
            parameters[5].Value = model.Address;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public RC403ZhangChenYang.Model.Tuser GetModel(string QQId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 QQId,Username,password,Sex,BirthDay,Address from Tuser ");
            strSql.Append(" where QQId=@QQId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@QQId", SqlDbType.NVarChar, 16)
            };
            parameters[0].Value = QQId;

            RC403ZhangChenYang.Model.Tuser model = new RC403ZhangChenYang.Model.Tuser();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["QQId"] != null && ds.Tables[0].Rows[0]["QQId"].ToString() != "")
                {
                    model.QQId = ds.Tables[0].Rows[0]["QQId"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Username"] != null && ds.Tables[0].Rows[0]["Username"].ToString() != "")
                {
                    model.Username = ds.Tables[0].Rows[0]["Username"].ToString();
                }
                if (ds.Tables[0].Rows[0]["password"] != null && ds.Tables[0].Rows[0]["password"].ToString() != "")
                {
                    model.password = ds.Tables[0].Rows[0]["password"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Sex"] != null && ds.Tables[0].Rows[0]["Sex"].ToString() != "")
                {
                    model.Sex = ds.Tables[0].Rows[0]["Sex"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BirthDay"] != null && ds.Tables[0].Rows[0]["BirthDay"].ToString() != "")
                {
                    model.BirthDay = DateTime.Parse(ds.Tables[0].Rows[0]["BirthDay"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Address"] != null && ds.Tables[0].Rows[0]["Address"].ToString() != "")
                {
                    model.Address = ds.Tables[0].Rows[0]["Address"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(RC403ZhangChenYang.Model.Tuser model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Tuser set ");
            strSql.Append("Username=@Username,");
            strSql.Append("password=@password,");
            strSql.Append("Sex=@Sex,");
            strSql.Append("BirthDay=@BirthDay,");
            strSql.Append("Address=@Address");
            strSql.Append(" where QQId=@QQId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Username", SqlDbType.NVarChar,   20),
                new SqlParameter("@password", SqlDbType.NVarChar,   20),
                new SqlParameter("@Sex",      SqlDbType.NChar,       2),
                new SqlParameter("@BirthDay", SqlDbType.DateTime),
                new SqlParameter("@Address",  SqlDbType.NVarChar,  100),
                new SqlParameter("@QQId",     SqlDbType.NVarChar, 16)
            };
            parameters[0].Value = model.Username;
            parameters[1].Value = model.password;
            parameters[2].Value = model.Sex;
            parameters[3].Value = model.BirthDay;
            parameters[4].Value = model.Address;
            parameters[5].Value = model.QQId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
        private void skinButtom1_Click(object sender, EventArgs e)
        {
            DAL.Tuser manage = new DAL.Tuser();
            if (manage.Exists(comboBox1.Text.ToString().Trim()))
            {
                if (comboBox1.Text == "" || textBox1.Text == "")
                {
                    MessageBox.Show("账号或密码不能为空.");
                    return;
                }

                RC403ZhangChenYang.DAL.Tuser lg_ck = new RC403ZhangChenYang.DAL.Tuser();
                //检测账号是否存在
                if (lg_ck.Exists(comboBox1.Text) == false)
                {
                    MessageBox.Show("账号不存在, 请注册.");
                    return;
                }

                //检测密码是否正确
                RC403ZhangChenYang.Model.Tuser get_data = lg_ck.GetModel(comboBox1.Text);
                if (get_data.password.Trim() != textBox1.Text.Trim())
                {
                    MessageBox.Show("密码或账号有误.");
                    return;
                }

                this.Close();
                new QQMain(get_data).Show();
            }


            //QQMain QQmain = new QQMain();
            //QQmain.Show();
            //this.Close();
        }
Exemple #5
0
 public QQMain(Model.Tuser data)
 {
     InitializeComponent();
     this.Data = data;
 }
        private void bt_register_Click(object sender, EventArgs e)
        {
            //创建用户类, 保存用户各种信息字段

            //判断输入是否合法 昵称和密码和确认密码不能为空
            if (tbNickname.Text == "" || tbPwcl.Text == "" || tb_confirm.Text == "")
            {
                MessageBox.Show("昵称或密码不能为空, 请重新输入信息.");
                return;
            }
            //判断密码是否相同
            if (tbPwcl.Text != tb_confirm.Text)
            {
                MessageBox.Show("两次输入密码不相同, 请重新输入密码.");
                return;
            }

            //创建qq用户对象,将信息保存到对象中,将对象传给ADD函数
            RC403ZhangChenYang.DAL.Tuser   A    = new RC403ZhangChenYang.DAL.Tuser();
            RC403ZhangChenYang.Model.Tuser data = new RC403ZhangChenYang.Model.Tuser();
            //昵称
            data.Username = tbNickname.Text;

            //随机生成ID
            Random rd_id = new Random();

            data.QQId = rd_id.Next(1000, 100000).ToString();
            while (A.Exists(data.QQId) == true)
            {
                data.QQId = rd_id.Next(1000, 100000).ToString();
            }

            //密码
            data.password = tb_confirm.Text;
            //性别
            if (ck_man.Checked == true)
            {
                data.Sex = "男";
            }
            else
            {
                data.Sex = "女";
            }
            //生日
            data.BirthDay = dtpBirthday.Value;
            //地址
            data.Address = tb_address.Text;

            try
            {
                A.Add(data);
            }
            catch  //(Exception error)
            {
                //MessageBox.Show(error.Message);
                MessageBox.Show("服务器错误, 插入失败, 请稍后重试.");
                return;
            }
            QQ2013 QQlogin = new QQ2013();

            MessageBox.Show("注册成功!您的QQ账号是:" + data.QQId + ".请妥善保管.");
            this.Close();
            QQlogin.Show();
        }