Mqq查找好友

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MyQQ
{
    public partial class PersonalInfoForm : Form
    {
        public PictureBox picture = null;
        public PersonalInfoForm()
        {
            InitializeComponent();
        }
        //个人资料
        private void a_Click(object sender, EventArgs e)
        {
            pnlBaseInfo.Visible = true;
            pnlSecurity.Visible = false;
            btnBaseInfo.Visible = false;
            btnSecurity.Visible = true;
        }
        //安全设置
        private void b_Click(object sender, EventArgs e)
        {
            pnlBaseInfo.Visible = false;
            pnlSecurity.Visible = true;
            btnBaseInfo.Visible = true;
            btnSecurity.Visible = false;
        }
        //退出
        private void TsmiExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //跳转头像
        private void btnNext_Click(object sender, EventArgs e)
        {
            FacesForm fom = new FacesForm();
            fom.pic = this.picHead;
            fom.Show();

        }
        //窗体加载
        private void PersonalInfoForm_Load(object sender, EventArgs e)
        {
            pnlBaseInfo.Location = pnlSecurity.Location;
            btnBaseInfo.Visible = false;
            //使显示“个人资料”的Panel可见
            pnlBaseInfo.Visible = true;
            //使显示“安全设置”的按钮可见
            btnSecurity.Visible = true;
            //使显示“安全设置”的Panel不可见
            pnlSecurity.Visible = false;
            try
            {
                //加载星座
                string sql = "select star from star";
                SqlCommand command = new SqlCommand(sql, DBHelper.connection);
                DBHelper.connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    cboStar.Items.Add(reader["star"].ToString());
                }
                reader.Close();
                //加载血型
                command.CommandText = "select BloodType from BloodType";
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    cboBloodType.Items.Add(reader["BloodType"].ToString());
                }
                reader.Close();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBHelper.connection.Close();
            }
            try
            {
             
                string sqll = string.Format("select * from users  where id = {0} and loginpwd='{1}'", UserHeper.loginId, UserHeper.loginPwd);
                SqlCommand com = new SqlCommand(sqll, DBHelper.connection);
                DBHelper.connection.Open();
                SqlDataReader datar = com.ExecuteReader();
                if (datar.Read())
                {
                    txtOldPwd.Text = datar["loginpwd"].ToString();
                    txtUserId.Text = datar["id"].ToString();
                    txtUserNickName.Text = datar["nickname"].ToString();
                    cboSex.Text = datar["sex"].ToString();
                    txtAge.Text = datar["age"].ToString();
                    int i = Convert.ToInt32(datar["faceid"]);
                    picHead.Image = Ivface.Images[i];
                    if (!(datar["name"] is DBNull))
                    {
                        txtName.Text = datar["name"].ToString();
                    }
                    if (!(datar["starid"] is DBNull))
                    {
                        UserHeper.starid = Convert.ToInt32(datar["starid"]);
                    }
                    if (!(datar["bloodtypeid"] is DBNull))
                    {
                        UserHeper.bloodtypeid = Convert.ToInt32(datar["bloodtypeid"]);
                    }

                }
                datar.Close();
                //星座id
                sqll = string.Format("select star from star where id={0}", UserHeper.starid);
                com.CommandText = sqll;
                datar = com.ExecuteReader();
                if (datar.Read())
                {
                    cboStar.Text = datar["star"].ToString();
                }
                datar.Close();
                //血型id
                sqll = string.Format("select bloodtype from  bloodtype  where id={0}", UserHeper.bloodtypeid);
                com.CommandText = sqll;
                datar = com.ExecuteReader();
                if (datar.Read())
                {
                    cboBloodType.Text = datar["bloodtype"].ToString();
                }
                datar.Close();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBHelper.connection.Close();
            }
        }
        //获取 星座Id
        private int StarId()
        {
            int starId = 0;  //星座Id值
            string sql = string.Format("select Id from Star where Star='{0}'", cboStar.Text);
            try
            {
                //定义 Command 对象
                SqlCommand command = new SqlCommand(sql, DBHelper.connection);
                DBHelper.connection.Open();                           //打开数据库连接
                SqlDataReader dataReader = command.ExecuteReader();    //执行查询
                //读取班级 Id
                if (dataReader.Read())
                {
                    starId = (int)dataReader[0];
                }
                dataReader.Close();                 //关闭 DataReader 对象

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBHelper.connection.Close();    //关闭数据库连接
            }

            return starId;
        }
        //血型ID
        private int bloodtype()
        {
            int bloodid = 0;
            string sql = string.Format("select id from bloodtype where bloodtype ='{0}' ", cboBloodType.Text);
            try
            {
                //定义 Command 对象
                SqlCommand command = new SqlCommand(sql, DBHelper.connection);
                DBHelper.connection.Open();                           //打开数据库连接
                SqlDataReader dataReader = command.ExecuteReader();    //执行查询
                //读取班级 Id
                if (dataReader.Read())
                {
                    bloodid = (int)dataReader[0];
                }
                dataReader.Close();                 //关闭 DataReader 对象

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBHelper.connection.Close();
            }
            return bloodid;
        }
        //验证密码
        private bool input()
        {

            if (txtNewPwd.Text != txtNewRePwd.Text)
            {
                MessageBox.Show("您修改后的密码不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //清空
                txtNewPwd.Text = "";
                txtNewRePwd.Text = "";
                return false;
            }
            else
            {
                return true;
            }

        }

        //确定
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            int starId = StarId();
            int bloodid = bloodtype();

            if (input())
            {
                string sql = "";
                if (txtNewPwd.Text != "" && txtNewRePwd.Text != "")
                {
                    sql = string.Format("update users set nickname='{0}',sex='{1}',name='{2}',starid='{3}',age='{4}',bloodtypeid='{5}',loginpwd='{6}',faceid ={7}  where id={8} ", txtUserNickName.Text, cboSex.Text, txtName.Text, starId, txtAge.Text, bloodid, txtNewPwd.Text,UserHeper.pictureid, UserHeper.loginId);
                }
                else
                {
                    sql = string.Format("update users set nickname='{0}',sex='{1}',name='{2}',starid='{3}',age='{4}',bloodtypeid='{5}',faceid ={6}  where id={7} ", txtUserNickName.Text, cboSex.Text, txtName.Text, starId, txtAge.Text, bloodid,UserHeper.pictureid, UserHeper.loginId);
                }

                int result = 0;
                try
                {
                    SqlCommand com = new SqlCommand(sql, DBHelper.connection);
                    DBHelper.connection.Open();
                    result = com.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    DBHelper.connection.Close();
                }
                if (result < 1)
                {
                    MessageBox.Show("添加修改失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("服务器已接受你的请求!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (Ivface.Images.Count != 0)
                    {
                        this.picture.Image = Ivface.Images[UserHeper.id];
                    }
                    this.Close();
                }
            }
        }

        private void pnlBaseInfo_Paint(object sender, PaintEventArgs e)
        {

        }


    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

武江伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值