namespace SHNDecrypt
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class columnCreate : Form
    {
        private Button button1;
        private ComboBox cmbTypes;
        private IContainer components;
        private Label label1;
        private Label label2;
        private Label label3;
        private Label label4;
        private frmMain mainfrm;
        private TextBox txtColName;
        private TextBox txtDefault;
        private Label txtInfo;
        private TextBox txtLen;

        public columnCreate(frmMain main)
        {
            this.mainfrm = main;
            this.InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int len = int.Parse(this.txtLen.Text);
                if (len < 0)
                {
                    MessageBox.Show("Please enter a valid length");
                }
                else
                {
                    this.mainfrm.file.CreateColumn(this.txtColName.Text, len, uint.Parse(this.cmbTypes.Text.Substring(0, 2)), this.txtDefault.Text);
                    base.Close();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void cmbTypes_TextChanged(object sender, EventArgs e)
        {
            byte type = byte.Parse(this.cmbTypes.Text.Substring(0, 2));
            this.txtLen.Text = this.GetDefLen(type).ToString();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        public int GetDefLen(int type)
        {
            switch (type)
            {
                case 1:
                    return 1;

                case 2:
                    return 2;

                case 3:
                    return 4;

                case 13:
                    return 2;
            }
            return -1;
        }

        public void init()
        {
            if (this.mainfrm.file.table != null)
            {
                this.txtInfo.Text = (this.mainfrm.file.table.Rows.Count - 1) + " cell(s) will be created.";
                this.cmbTypes.Items.Clear();
                this.cmbTypes.Items.Add("24: String (Enter Length)");
                this.cmbTypes.Items.Add("13: Short");
                this.cmbTypes.Items.Add("03: uInt");
                this.cmbTypes.Items.Add("02: uShort");
                this.cmbTypes.Items.Add("01: Byte");
                this.cmbTypes.SelectedIndex = this.cmbTypes.Items.Count - 1;
            }
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(columnCreate));
            this.label1 = new Label();
            this.label2 = new Label();
            this.label3 = new Label();
            this.txtColName = new TextBox();
            this.txtDefault = new TextBox();
            this.txtInfo = new Label();
            this.button1 = new Button();
            this.label4 = new Label();
            this.txtLen = new TextBox();
            this.cmbTypes = new ComboBox();
            base.SuspendLayout();
            this.label1.AutoSize = true;
            this.label1.Location = new Point(12, 13);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x4c, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Column Name:";
            this.label2.AutoSize = true;
            this.label2.Location = new Point(0x10, 0x27);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x48, 13);
            this.label2.TabIndex = 1;
            this.label2.Text = "Column Type:";
            this.label3.AutoSize = true;
            this.label3.Location = new Point(14, 0x42);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x4a, 13);
            this.label3.TabIndex = 2;
            this.label3.Text = "Default Value:";
            this.txtColName.Location = new Point(0x5e, 10);
            this.txtColName.Name = "txtColName";
            this.txtColName.Size = new Size(0x99, 20);
            this.txtColName.TabIndex = 1;
            this.txtDefault.Location = new Point(0x5e, 0x3f);
            this.txtDefault.Name = "txtDefault";
            this.txtDefault.Size = new Size(0x99, 20);
            this.txtDefault.TabIndex = 3;
            this.txtInfo.AutoSize = true;
            this.txtInfo.Location = new Point(0x5f, 0x98);
            this.txtInfo.Name = "txtInfo";
            this.txtInfo.Size = new Size(0x99, 13);
            this.txtInfo.TabIndex = 6;
            this.txtInfo.Text = "0000000 cell(s) will be created.";
            this.txtInfo.TextAlign = ContentAlignment.MiddleCenter;
            this.button1.Location = new Point(0x5e, 0x73);
            this.button1.Name = "button1";
            this.button1.Size = new Size(0x99, 30);
            this.button1.TabIndex = 5;
            this.button1.Text = "Create";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new EventHandler(this.button1_Click);
            this.label4.AutoSize = true;
            this.label4.Location = new Point(7, 0x5c);
            this.label4.Name = "label4";
            this.label4.Size = new Size(0x51, 13);
            this.label4.TabIndex = 10;
            this.label4.Text = "Column Length:";
            this.txtLen.Location = new Point(0x5e, 0x59);
            this.txtLen.Name = "txtLen";
            this.txtLen.Size = new Size(0x99, 20);
            this.txtLen.TabIndex = 4;
            this.txtLen.Text = "1";
            this.txtLen.TextAlign = HorizontalAlignment.Right;
            this.cmbTypes.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbTypes.FormattingEnabled = true;
            this.cmbTypes.Location = new Point(0x5e, 0x24);
            this.cmbTypes.Name = "cmbTypes";
            this.cmbTypes.Size = new Size(0x99, 0x15);
            this.cmbTypes.TabIndex = 2;
            this.cmbTypes.TextChanged += new EventHandler(this.cmbTypes_TextChanged);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(260, 0xae);
            base.Controls.Add(this.cmbTypes);
            base.Controls.Add(this.txtLen);
            base.Controls.Add(this.label4);
            base.Controls.Add(this.button1);
            base.Controls.Add(this.txtInfo);
            base.Controls.Add(this.txtDefault);
            base.Controls.Add(this.txtColName);
            base.Controls.Add(this.label3);
            base.Controls.Add(this.label2);
            base.Controls.Add(this.label1);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "columnCreate";
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "Column Creation";
            base.ResumeLayout(false);
            base.PerformLayout();
        }
    }
}

