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 FacesForm : Form
    {
        public PersonalInForm Person;
        public MainForm Person2;
        public FacesForm()
        {
            InitializeComponent();
        }

        DataBase mydatabase = new DataBase();

        private void button1_Click(object sender, EventArgs e)
        {
            if (lvfases.SelectedItems.Count == 0)
            {
                MessageBox.Show("请选择一个头像", "提示");
            }
            else
            {
                int faceid = lvfases.SelectedItems[0].ImageIndex;
                try
                {
                    string sql = string.Format("Update Users set FaceId={0} where Id={1}", faceid, Convert.ToInt32(UserHelper.Loginld));

                    int count = mydatabase.ExecuteSQL(sql);
                    if (count < 1)
                    {
                        MessageBox.Show("对不起，选择失败！", "提示");
                    }
                    else
                    {
                        MessageBox.Show("服务器接受了的请求！", "提示");
                        Person.picture(faceid);
                        Person2.picture(faceid);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                this.Close();
            }
        }

        //显示皮肤的方法
        public void ShowSkin()
        {
            int i = 0;
            string sql = string.Format("select skinId from Users where Id={0}", UserHelper.Loginld);
            try
            {
                SqlDataReader dataReader = mydatabase.GetDataReader(sql);
                if (dataReader.Read())
                {
                    i = Convert.ToInt32(dataReader["skinId"]);
                }
                dataReader.Close();
                if (i == 1)
                {
                    this.skinEngine.SkinFile = "Wave.ssk";
                }
                else if (i == 2)
                {
                    this.skinEngine.SkinFile = "WaveColor1.ssk";
                }
                else if (i == 3)
                {
                    this.skinEngine.SkinFile = "WaveColor1.ssk";
                }
                else if (i == 4)
                {
                    this.skinEngine.SkinFile = "SportsBlack.ssk";
                }
                else if (i == 5)
                {
                    this.skinEngine.SkinFile = "SportsBlue.ssk";
                }
                else if (i == 6)
                {
                    this.skinEngine.SkinFile = "SportsCyan.ssk";
                }
                else if (i == 7)
                {
                    this.skinEngine.SkinFile = "SportsGreen.ssk";
                }
                else
                {
                    this.skinEngine.SkinFile = "MP10.ssk";
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }
        // 显示图片窗口
        private void FacesForm_Load(object sender, EventArgs e)
        {
            ShowSkin();
            lvfases.View = View.LargeIcon;
            lvfases.LargeImageList = ILfaces;
            ListViewItem lviInfo = null;
            for (int i = 0; i < 100; i++)
            {
                lviInfo = new ListViewItem(i.ToString(), i);

                lviInfo.SubItems.Add(i.ToString());

                lvfases.Items.Add(lviInfo);
            }
        }
        //关闭当前窗口
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}