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

namespace iTripLog.WeatherF
{
    public partial class FrmWeather : Form
    {

        private DataSet dsRegion = new DataSet();
        private DataSet dsCity = new DataSet();
        private string appFilePath = null;

        private string[] weather;
        private Bitmap myImage1 = null;
        private Bitmap myImage2 = null;


        public FrmWeather()
        {
            InitializeComponent();
        }



        private void FrmWeather_Load(object sender, EventArgs e)
        {


            if (!File.Exists(Common.AppFilePath + "\\Province.xml"))
            {
                dsRegion = Common.GetWebService().getRegionDataset();
                dsRegion.WriteXml(appFilePath + "\\Province.xml");
            }
            else
            {
                dsRegion.ReadXml(appFilePath + "\\Province.xml");

            }

            cbProvince.DisplayMember = "RegionName";
            cbProvince.ValueMember = "RegionID";
            cbProvince.DataSource = dsRegion.Tables["Province"];

        }

        private void cbProvince_SelectedIndexChanged(object sender, EventArgs e)
        {

            dsCity = Common.GetWebService().getSupportCityDataset(cbProvince.SelectedValue.ToString());

            //

            cbCity.DisplayMember = "CityName";
            cbCity.ValueMember = "CityId";
            cbCity.DataSource = dsCity.Tables[0];


        }

        private void cbCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            weather = Common.GetWebService().getWeather(cbCity.SelectedValue.ToString(), "");

            int index = weather[0].IndexOf(' ');
            lblRegion.Text = weather[0].Trim().Substring(index + 1);
            lbltem.Text = weather[8].Trim();
            lblWeather.Text = weather[7].Trim();

            ////
            myImage1 = new Bitmap(appFilePath + "\\images\\b_" + weather[10].Trim());
            pictureBox1.Image = (Image)myImage1;

            myImage2 = new Bitmap(appFilePath + "\\images\\b_" + weather[11].Trim());
            pictureBox2.Image = (Image)myImage2;

            lblCityCode.Text = cbCity.Text + ":" + cbCity.SelectedValue.ToString();
        }

    }
}