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

namespace CSGBuilder {
    public partial class NewCuboid : Form {
        public double width, height, depth;
        public double cx, cy, cz;

        public NewCuboid() {
            InitializeComponent();
        }

        private void cbCenter_CheckedChanged(object sender, EventArgs e) {
            if (!cbCenter.Checked) gbCenter.Enabled = true; else gbCenter.Enabled = false;
        }

        private void NewBox_FormClosing(object sender, FormClosingEventArgs e) {
            if (this.DialogResult == DialogResult.OK) {
                // Üres mezőket nem enged meg
                if (tbWidth.Text == "" || tbHeight.Text == "" || tbDepth.Text == "") {
                    MessageBox.Show("Empty parameter fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
                if (gbCenter.Enabled && (tbCX.Text == "" || tbCY.Text == "" || tbCZ.Text == "")) {
                    MessageBox.Show("Empty parameter fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;                
                }
                // Jól vannak megadva az értékek?
                if (gbCenter.Enabled && (!Double.TryParse(tbCX.Text, out cx) || !Double.TryParse(tbCY.Text, out cy) || !Double.TryParse(tbCZ.Text, out cz))) {
                    MessageBox.Show("Incorrect number format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
                if (!Double.TryParse(tbWidth.Text, out width) || !Double.TryParse(tbHeight.Text, out height) || !Double.TryParse(tbDepth.Text, out depth)) {
                    MessageBox.Show("Incorrect number format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true; return;
                }
            }
        }
    }
}