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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace ExcelToCsvToDbCommon.Gamen
{
    public partial class ColMappingForm : Form
    {
        public string Retsu { get; set; }

        public ColMappingForm(string retsu)
        {
            InitializeComponent();

            // 例：AからZZ（702列）まで追加
            for (int i = 1; i <= 702; i++)
            {
                RetsuCombo.Items.Add(GetExcelColumnName(i));
            }
            RetsuCombo.Text = retsu; // デフォルトで "A" を選択

            RetsuCombo_SelectedIndexChanged(null, null);
        }

        // 数値をExcel形式の列名（A, B... AA...）に変換するメソッド
        private string GetExcelColumnName(int columnNumber)
        {
            string columnName = "";
            while (columnNumber > 0)
            {
                int modulo = (columnNumber - 1) % 26;
                columnName = Convert.ToChar('A' + modulo) + columnName;
                columnNumber = (columnNumber - modulo) / 26;
            }
            return columnName;
        }

        private void RetsuCombo_SelectedIndexChanged(object sender, EventArgs e)
        {
            OkButton.Enabled = RetsuCombo.SelectedIndex != -1;
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            this.Retsu = RetsuCombo.Text;
            this.DialogResult = DialogResult.OK;
        }
    }
}
