using System;
using System.Windows.Forms;

namespace Truffles
{
    public partial class moveColumn : Form
    {
        frmMain main;
        public moveColumn(frmMain mainfrm)
        {
            main = mainfrm;
            InitializeComponent();
            init(); 
        }

        public void init()
        {
            if (main.file.table == null) return;
            cmbToMove.Items.Clear();
            for (int i = 0; i < main.file.table.Columns.Count; i++)
            {
                cmbToMove.Items.Add(main.file.table.Columns[i].ColumnName);
                cmbMoveAfter.Items.Add(main.file.table.Columns[i].ColumnName);
            }
            cmbToMove.SelectedIndex = 0;
        }

        private void btnMove_Click(object sender, EventArgs e)
        {
            int toListID = main.file.getColIndex(cmbToMove.Text);
            int toSearchID = main.file.getColIndex(cmbMoveAfter.Text);

            for (int i = 0; i < main.file.table.Rows.Count; i++)
            {
                if (main.file.table.Rows[i][toSearchID].ToString().Contains(txtSearch.Text))
                    txtOutput.Text += main.file.table.Rows[i][toListID].ToString() + "\r\n";
            }
            main.SQLStatus.Text = "Output list done.";
        }
    }
}