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

namespace ExcelToCsvToDbCommon.Gamen
{
    public partial class NameForm : Form
    {
        public string LogicalName { get; set; }

        public NameForm(string logicalName)
        {
            InitializeComponent();

            if (logicalName.IndexOf("(") >= 0)
            {
                LogicalNameText.Text = logicalName.Split('(')[0].Trim();
                TableColumnName.Text = logicalName.Split('(')[1].Trim(')').Trim();
            }
            else
            {
                LogicalNameText.Text = logicalName.Trim();
                TableColumnName.Text = string.Empty;
            }
            LogicalNameText_TextChanged(null, null);
        }

        private void LogicalNameText_TextChanged(object sender, EventArgs e)
        {
            OkButton.Enabled = LogicalNameText.Text != "";
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            LogicalName = LogicalNameText.Text +
                (string.IsNullOrEmpty(TableColumnName.Text.Trim()) ? "" : $"({TableColumnName.Text})");
            DialogResult = DialogResult.OK;
        }
    }
}
