/*
 * Created by SharpDevelop.
 * User: turugina
 * Date: 2009/06/15
 * Time: 23:05
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

namespace TwitterBlock
{
	/// <summary>
	/// Description of ListForm.
	/// </summary>
	public partial class ListForm : Form
	{
		AccountInfo account;
		Twitter twit;

		public ListForm(AccountInfo account)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			this.account = account;
			this.twit = new Twitter(account);
		}
		
		public void LoadList()
		{
			IList<UserInfo> userinfo = twit.GetFollowers();
			dataGridView1.Rows.Clear();
			foreach (UserInfo ui in userinfo) {
				dataGridView1.Rows.Add(
					false, ui.ScreenName, ui.Name, ui.Id
				);
			}
		}
		
		void BtnReloadClick(object sender, EventArgs e)
		{
			LoadList();
		}
		
		void BtnCloseClick(object sender, EventArgs e)
		{
			this.Close();
		}
		
		void BtnBlockClick(object sender, EventArgs e)
		{
			foreach (DataGridViewRow row in dataGridView1.Rows)
			{
				if ( row.IsNewRow || row.Cells["Checked"] == null )
					continue;
				if ( (bool)row.Cells["Checked"].Value )
				{
					DialogResult res = MessageBox.Show(
						row.Cells["ScreenName"].Value + "‚đBlock‚µ‚Ü‚·",
						"Blocking",
						MessageBoxButtons.YesNo,
						MessageBoxIcon.Question,
						MessageBoxDefaultButton.Button1);
					if ( res == DialogResult.Yes )
					{
						try {
							twit.BlockUser((string)row.Cells["UserId"].Value);
						}
						catch (Exception ex)
						{
							MessageBox.Show(ex.Message, "ERROR");
						}
					}
				}
			}
			
		}
	}
}
