using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TFSWrappers;
using Microsoft.TeamFoundation.Build.Proxy;
using Microsoft.TeamFoundation.Client;

namespace TFSBuildManager
{
    public partial class DeleteBuildsParametersForm : Form
    {
        public DeleteBuildsParametersForm(TeamFoundationServer tfs, TFSBuildType buildType, BuildData[] buildsData)
        {
            InitializeComponent();
            this.buildsData = buildsData;
            this.tfs = tfs;
            txtBackupDirectory.Text = buildType.DropLocation.PropertyValue;
            builds = new List<string>();
            foreach (BuildData buildData in buildsData)
            {
                builds.Add(buildData.BuildNumber);
                lvBuildsToDelete.Items.Add(buildData.BuildNumber);
            }
        }

        private TeamFoundationServer tfs;
        private BuildData[] buildsData;
        private List<string> builds;

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                txtBackupDirectory.Text = folderBrowserDialog.SelectedPath;
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure that you want to delete the selected builds?",
                "Delete Builds", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                BuildController buildController = (BuildController)tfs.GetService(typeof(BuildController));
                DeleteBuildsProgressForm frmDeleteBuildsProgress = new DeleteBuildsProgressForm(buildController,
                    buildsData, rbBackupToZipFile.Checked, txtBackupDirectory.Text);
                frmDeleteBuildsProgress.ShowDialog();
                DialogResult = DialogResult.OK;
            }
        }
    }
}