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


namespace iTripLog.WeatherF
{
    public partial class FrmDefaultCityWeather : Form
    {
        public FrmDefaultCityWeather()
        {
            InitializeComponent();
        }

        private void FrmDefaultCityWeather_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Common.CityCode))
            {
                FrmAddCity frm = new FrmAddCity();
                frm.Show();
                this.Hide();
            }


        
            ShowWeather();

        }

        private void ShowWeather()
        {

            Cursor.Current = Cursors.WaitCursor;
            Cursor.Show();
            string[] weather = Common.GetWeatherByCityCode(Common.CityCode);

            //今天
            Bitmap myImage = null;
            int hour = DateTime.Now.Hour;
            if ((hour >= 6) && (hour <= 18))
                myImage = new Bitmap(Common.AppFilePath + "\\images\\a_" + weather[10].Trim());
            else
                myImage = new Bitmap(Common.AppFilePath + "\\images\\a_" + weather[11].Trim());

            pbWeather.Image = (Image)myImage;

            string month = weather[3].Substring(5, 2);
            string day = weather[3].Substring(8, 2);
            string strdate = month + "月" + day + "日";
            int index = weather[0].IndexOf(' ');
            lblCityName.Text = weather[0].Trim().Substring(index + 1) + " " + strdate;
            lblTemp.Text = weather[8].Trim();

            DateTime Today = DateTime.Parse(weather[3].Substring(0, 10));

            //明天
            DateTime tomorrow = Today.Date.AddDays(1);
            lblWeekday.Text = tomorrow.Date.Month.ToString() + "月" + tomorrow.Date.Day.ToString() + "日";

            Bitmap myImage1 = null;
            if ((hour >= 6) && (hour <= 18))
                myImage1 = new Bitmap(Common.AppFilePath + "\\images\\b_" + weather[15].Trim());
            else
                myImage1 = new Bitmap(Common.AppFilePath + "\\images\\b_" + weather[16].Trim());

            pbWeekDay.Image = (Image)myImage1;

            lblWeekDayTemp.Text = weather[13].Trim();


            //后天
            DateTime nextDay = Today.Date.AddDays(2);
            lblNextWeek.Text = nextDay.Date.Month.ToString() + "月" + nextDay.Date.Day.ToString() + "日";

            Bitmap myImage2 = null;
            if ((hour >= 6) && (hour <= 18))
                myImage2 = new Bitmap(Common.AppFilePath + "\\images\\b_" + weather[20].Trim());
            else
                myImage2 = new Bitmap(Common.AppFilePath + "\\images\\b_" + weather[21].Trim());

            pbNext.Image = (Image)myImage2;

           lblNextTemp.Text   = weather[18].Trim();


           Cursor.Current = Cursors.Default;


        }



        private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
        {
            switch (e.Button.ImageIndex)
            {
                case 0://刷新
                    ShowWeather();
                    break;
                case 1: //列表
                    FrmCityList frm = new FrmCityList();
                    frm.Show();
                    this.Hide();
                    break;
                case 2: //关闭
                    Application.Exit();
                    break;
            }

        }

        private void lblTemp_ParentChanged(object sender, EventArgs e)
        {

        }

        private void lblCityName_ParentChanged(object sender, EventArgs e)
        {

        }

        private void lblWeekday_ParentChanged(object sender, EventArgs e)
        {

        }

        private void lblWeekDayTemp_ParentChanged(object sender, EventArgs e)
        {

        }

        private void lblNextWeek_ParentChanged(object sender, EventArgs e)
        {

        }

        private void lblNextTemp_ParentChanged(object sender, EventArgs e)
        {

        }


    }
}