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;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;

namespace UniversalEditor
{
    public partial class columnDeletion : XtraForm
    {
        frmMain mainfrm;
        public columnDeletion(frmMain main)
        {
            this.mainfrm = main;
            InitializeComponent();
        }

        public void init()
        {
            if (mainfrm.file.table == null) return;
            comboBox1.Properties.Items.Clear();
            
            for (int i = 0; i < mainfrm.file.table.Columns.Count; i++)
            {
                comboBox1.Properties.Items.Add(mainfrm.file.table.Columns[i].ColumnName);
                txtList.Text += mainfrm.file.table.Columns[i].ColumnName + "\r\n";
            }

            comboBox1.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = XtraMessageBox.Show("Are you sure you want to delete this column? It can't be undone!", "SHN", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (result == DialogResult.Yes)
                {
                    mainfrm.file.DeleteColumn(comboBox1.SelectedItem.ToString());
                    mainfrm.dataGrid.MainView.PopulateColumns();
                    string t = mainfrm.FileTabs.SelectedTabPage.Text;
                    string n = t.Replace("*", String.Empty);
                    mainfrm.FileTabs.SelectedTabPage.Text = n;
                    mainfrm.FileTabs.SelectedTabPage.Text = mainfrm.FileTabs.SelectedTabPage.Text + "*";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //this.Close();
        }
    }
}
