using System;
using System.Windows.Forms;

namespace BulkPrinting
{
    public partial class PrinterSettingsForm : Form
    {
        public PrinterSettingsForm()
        {
            InitializeComponent();
        }

        public string InitString
        {
            get { return initStringTextBox.Text.Trim(); }
            set { initStringTextBox.Text = value; }
        }

        private void PrinterSettingsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                try
                {
                    Utility.HexStringToBytes(InitString);
                }
                catch (FormatException)
                {
                    MessageBox.Show("Printer init string is not a valid hex string.", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true;
                }
            }
        }

        private void resetButton_Click(object sender, EventArgs e)
        {
            initStringTextBox.Text = Globals.DefaultPrinterInitString;
        }
    }
}
