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

namespace pcd_g1
{
    public partial class EditFlag : Form
    {
        public EditFlag()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (this.textBox1.Text == "") return;
            int val = StageManager.CurrentDataSet.GetInt(this.textBox1.Text);
            if (val != 0 && this.textBox2.Text == "0") this.textBox2.Text = val.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int val;
            if (this.textBox1.Text != "")
            {
                if (int.TryParse(this.textBox2.Text, out val))
                {
                    StageManager.CurrentDataSet.Set(this.textBox1.Text, val);
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
                else
                {
                    this.textBox2.Focus();
                    this.textBox2.SelectAll();
                    MessageBox.Show("Cannot convert the value to Integer.");
                }
            }
            else
            {
                MessageBox.Show("Flag Name must not be null.");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }
    }
}
