using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace CustomFormsPDA
{
	public partial class InputForm : Form
	{
		private readonly List<Control> CheckEnableContols = new List<Control>();
		private string Symbols = "";

		public InputForm()
		{
			InitializeComponent();

			Left = 40;
			Top = 100;
		}

		public bool Show(string Title, string Prompt, ref string Value)
		{
			Height = 260;
			BlackPanel.Height = 260;
			WhitePanel.Height = 252;
			OkBtn.Top = 180;
			CancelBtn.Top = 180;

			TitleLbl.Text = Title;

			PromptLbl.Text = Prompt;
			TextBox Box = new TextBox();
			Box.Left = PromptLbl.Left;
			Box.Top = PromptLbl.Top + PromptLbl.Height;
			Box.Width = WhitePanel.Width - Box.Left * 2;
			Box.Text = Value;
			WhitePanel.Controls.Add(Box);

			Box.GotFocus += Box_GotFocus;
			InputPanel.Enabled = true;
			DialogResult res = ShowDialog();
			InputPanel.Enabled = false;
			if (res == DialogResult.OK)
				Value = Box.Text;

			Box.Dispose();

			return (res == DialogResult.OK);
		}

		public bool Show(string Title, string Prompt, ref string Value, int MaxLen, string Symbols)
		{
			Height = 260;
			BlackPanel.Height = 260;
			WhitePanel.Height = 252;
			OkBtn.Top = 180;
			CancelBtn.Top = 180;

			TitleLbl.Text = Title;

			PromptLbl.Text = Prompt;
			TextBox Box = new TextBox();
			Box.Left = PromptLbl.Left;
			Box.Top = PromptLbl.Top + PromptLbl.Height;
			Box.Width = WhitePanel.Width - Box.Left * 2;
			Box.Text = Value;
			Box.MaxLength = MaxLen;
			Box.KeyPress += Box_KeyPress;
			this.Symbols = Symbols.ToUpper();
			WhitePanel.Controls.Add(Box);

			InputPanel.Enabled = true;
			DialogResult res = ShowDialog();
			InputPanel.Enabled = false;
			if (res == DialogResult.OK)
				Value = Box.Text;

			Box.Dispose();
			this.Symbols = "";
			return (res == DialogResult.OK);
		}

		public bool Show(string Title, string Prompt, ref string Value,
		                 string Prompt2, ref string Value2, int MaxLen, string Symbols)
		{
			Height = 370;
			BlackPanel.Height = 360;
			WhitePanel.Height = 352;
			OkBtn.Top = 270;
			CancelBtn.Top = 270;

			TitleLbl.Text = Title;

			PromptLbl.Text = Prompt;
			TextBox Box = new TextBox();
			Box.Left = PromptLbl.Left;
			Box.Top = PromptLbl.Top + PromptLbl.Height;
			Box.Width = WhitePanel.Width - Box.Left * 2;
			Box.Text = Value;
			Box.MaxLength = MaxLen;
			Box.KeyPress += Box_KeyPress;
			WhitePanel.Controls.Add(Box);

			Label Prompt2Lbl = new Label();
			Prompt2Lbl.Font = PromptLbl.Font;
			Prompt2Lbl.Left = PromptLbl.Left;
			Prompt2Lbl.Height = PromptLbl.Height;
			Prompt2Lbl.Top = Box.Top + Box.Height + 20;
			Prompt2Lbl.Text = Prompt2;
			WhitePanel.Controls.Add(Prompt2Lbl);

			TextBox Box2 = new TextBox();
			Box2.Left = Prompt2Lbl.Left;
			Box2.Top = Prompt2Lbl.Top + Prompt2Lbl.Height;
			Box2.Width = WhitePanel.Width - Box2.Left * 2;
			Box2.Text = Value2;
			Box2.MaxLength = MaxLen;
			Box2.KeyPress += Box_KeyPress;
			WhitePanel.Controls.Add(Box2);
			this.Symbols = Symbols;

			InputPanel.Enabled = true;
			DialogResult res = ShowDialog();
			InputPanel.Enabled = false;
			if (res == DialogResult.OK)
			{
				Value = Box.Text;
				Value2 = Box2.Text;
			}

			Box.Dispose();
			Box2.Dispose();
			Prompt2Lbl.Dispose();

			return (res == DialogResult.OK);
		}

		private void Box_KeyPress(object sender, KeyPressEventArgs e)
		{
			string s = e.KeyChar.ToString().ToUpper();
			if (Symbols.IndexOf(s) != -1)
				e.Handled = false;
			else
				e.Handled = true;
		}

		public bool Show(string Title, string Prompt, List<object> Values, ref int ValueIndex)
		{
			Height = 260;
			BlackPanel.Height = 260;
			WhitePanel.Height = 252;
			OkBtn.Top = 180;
			CancelBtn.Top = 180;

			TitleLbl.Text = Title;

			PromptLbl.Text = Prompt;
			ComboBox Box = new ComboBox();
			Box.Left = PromptLbl.Left;
			Box.Top = PromptLbl.Top + PromptLbl.Height;
			Box.Width = WhitePanel.Width - Box.Left * 2;
			for (int i = 0; i < Values.Count; i++)
				Box.Items.Add(Values[i]);
			Box.SelectedIndex = ValueIndex;
			WhitePanel.Controls.Add(Box);
			//InputPanel.Enabled = true;
			DialogResult res = ShowDialog();
			//InputPanel.Enabled = false;

			if (res == DialogResult.OK)
				ValueIndex = Box.SelectedIndex;

			Box.Dispose();

			return (res == DialogResult.OK);
		}

		public bool Show(string Title, string Prompt, ref string Value,
		                 string Prompt2, ref string Value2)
		{
			Height = 370;
			BlackPanel.Height = 360;
			WhitePanel.Height = 352;
			OkBtn.Top = 270;
			CancelBtn.Top = 270;

			TitleLbl.Text = Title;

			PromptLbl.Text = Prompt;
			TextBox Box = new TextBox();
			Box.Left = PromptLbl.Left;
			Box.Top = PromptLbl.Top + PromptLbl.Height;
			Box.Width = WhitePanel.Width - Box.Left * 2;
			Box.Text = Value;
			WhitePanel.Controls.Add(Box);

			Label Prompt2Lbl = new Label();
			Prompt2Lbl.Font = PromptLbl.Font;
			Prompt2Lbl.Left = PromptLbl.Left;
			Prompt2Lbl.Height = PromptLbl.Height;
			Prompt2Lbl.Top = Box.Top + Box.Height + 20;
			Prompt2Lbl.Text = Prompt2;
			WhitePanel.Controls.Add(Prompt2Lbl);

			TextBox Box2 = new TextBox();
			Box2.Left = Prompt2Lbl.Left;
			Box2.Top = Prompt2Lbl.Top + Prompt2Lbl.Height;
			Box2.Width = WhitePanel.Width - Box2.Left * 2;
			Box2.Text = Value2;
			WhitePanel.Controls.Add(Box2);

			InputPanel.Enabled = true;
			DialogResult res = ShowDialog();
			InputPanel.Enabled = false;
			if (res == DialogResult.OK)
			{
				Value = Box.Text;
				Value2 = Box2.Text;
			}

			Box.Dispose();
			Box2.Dispose();
			Prompt2Lbl.Dispose();

			return (res == DialogResult.OK);
		}

		public bool Show(string Title, string Prompt, ref string Value,
		                 string Prompt2, ref string Value2, string Prompt3, ref string Value3)
		{
			Top = 55;
			Height = 380;
			BlackPanel.Height = 380;
			WhitePanel.Height = 372;
			OkBtn.Top = 310;
			CancelBtn.Top = 310;

			TitleLbl.Text = Title;

			PromptLbl.Text = Prompt;
			TextBox Box = new TextBox();
			Box.GotFocus += Box_GotFocus;
			Box.Left = PromptLbl.Left;
			Box.Top = PromptLbl.Top + PromptLbl.Height;
			Box.Width = WhitePanel.Width - Box.Left * 2;
			Box.Text = Value;
			WhitePanel.Controls.Add(Box);

			Label Prompt2Lbl = new Label();
			Prompt2Lbl.Font = PromptLbl.Font;
			Prompt2Lbl.Left = PromptLbl.Left;
			Prompt2Lbl.Height = PromptLbl.Height;
			Prompt2Lbl.Top = Box.Top + Box.Height + 10;
			Prompt2Lbl.Text = Prompt2;
			WhitePanel.Controls.Add(Prompt2Lbl);

			TextBox Box2 = new TextBox();
			Box2.GotFocus += Box_GotFocus;
			Box2.Left = Prompt2Lbl.Left;
			Box2.Top = Prompt2Lbl.Top + Prompt2Lbl.Height;
			Box2.Width = WhitePanel.Width - Box2.Left * 2;
			Box2.Text = Value2;
			WhitePanel.Controls.Add(Box2);

			Label Prompt3Lbl = new Label();
			Prompt3Lbl.Font = PromptLbl.Font;
			Prompt3Lbl.Left = PromptLbl.Left;
			Prompt3Lbl.Height = PromptLbl.Height;
			Prompt3Lbl.Top = Box2.Top + Box2.Height + 10;
			Prompt3Lbl.Text = Prompt3;
			WhitePanel.Controls.Add(Prompt3Lbl);

			TextBox Box3 = new TextBox();
			Box3.GotFocus += Box_GotFocus;
			Box3.Left = Prompt3Lbl.Left;
			Box3.Top = Prompt3Lbl.Top + Prompt3Lbl.Height;
			Box3.Width = WhitePanel.Width - Box3.Left * 2;
			Box3.Text = Value3;
			WhitePanel.Controls.Add(Box3);

			InputPanel.Enabled = true;
			DialogResult res = ShowDialog();
			InputPanel.Enabled = false;
			if (res == DialogResult.OK)
			{
				Value = Box.Text;
				Value2 = Box2.Text;
				Value3 = Box3.Text;
			}

			Box.Dispose();
			Box2.Dispose();
			Box3.Dispose();
			Prompt2Lbl.Dispose();
			Prompt3Lbl.Dispose();

			return (res == DialogResult.OK);
		}

		public bool Show(string Title, string Prompt, ref string Value,
		                 string Prompt2, ref string Value2, string Prompt3, ref string Value3,
		                 string PromptChBox, ref bool Checked)
		{
			Top = 55;
			Height = 380;
			BlackPanel.Height = 380;
			WhitePanel.Height = 372;
			OkBtn.Top = 310;
			CancelBtn.Top = 310;

			TitleLbl.Text = Title;

			PromptLbl.Text = Prompt;
			TextBox Box = new TextBox();
			Box.GotFocus += Box_GotFocus;
			Box.Left = PromptLbl.Left;
			Box.Top = PromptLbl.Top + PromptLbl.Height;
			Box.Width = WhitePanel.Width - Box.Left * 2;
			Box.Text = Value;
			WhitePanel.Controls.Add(Box);

			Label Prompt2Lbl = new Label();
			Prompt2Lbl.Font = PromptLbl.Font;
			Prompt2Lbl.Left = PromptLbl.Left;
			Prompt2Lbl.Height = PromptLbl.Height;
			Prompt2Lbl.Top = Box.Top + Box.Height + 10;
			Prompt2Lbl.Text = Prompt2;
			WhitePanel.Controls.Add(Prompt2Lbl);

			TextBox Box2 = new TextBox();
			Box2.GotFocus += Box_GotFocus;
			Box2.Left = Prompt2Lbl.Left;
			Box2.Top = Prompt2Lbl.Top + Prompt2Lbl.Height;
			Box2.Width = WhitePanel.Width - Box2.Left * 2;
			Box2.Text = Value2;
			WhitePanel.Controls.Add(Box2);

			Label Prompt3Lbl = new Label();
			Prompt3Lbl.Font = PromptLbl.Font;
			Prompt3Lbl.Left = PromptLbl.Left;
			Prompt3Lbl.Height = PromptLbl.Height;
			Prompt3Lbl.Top = Box2.Top + Box2.Height + 10;
			Prompt3Lbl.Text = Prompt3;
			Prompt3Lbl.Width = WhitePanel.Width - Box.Left * 2;
			WhitePanel.Controls.Add(Prompt3Lbl);

			TextBox Box3 = new TextBox();
			Box3.GotFocus += Box_GotFocus;
			Box3.Left = Prompt3Lbl.Left;
			Box3.Top = Prompt3Lbl.Top + Prompt3Lbl.Height;
			//Box3.Width = WhitePanel.Width - Box3.Left * 2;
			Box3.Text = Value3;
			WhitePanel.Controls.Add(Box3);
			CheckEnableContols.Add(Box3);

			Graphics g = Graphics.FromImage(new Bitmap(1, 1));

			CheckBox ChBox = new CheckBox();
			ChBox.Top = Box3.Top;
			ChBox.Height = Box3.Height;
			ChBox.Text = PromptChBox;
			Size size = g.MeasureString(Box3.Text, Box3.Font).ToSize();
			if (size.Width < Box3.Height * 2)
				size.Width = Box3.Height * 2;
			Box3.Width = size.Width + 10; //WhitePanel.Width - Box3.Left - ChBox.Width*2;
			ChBox.Width = WhitePanel.Width - Box3.Left - Box3.Width;
			ChBox.Left = Box3.Left + Box3.Width + 10;
			ChBox.CheckStateChanged += ChBox_CheckStateChanged;
			ChBox.Checked = Checked;
			WhitePanel.Controls.Add(ChBox);


			InputPanel.Enabled = true;
			DialogResult res = ShowDialog();
			InputPanel.Enabled = false;
			if (res == DialogResult.OK)
			{
				Value = Box.Text;
				Value2 = Box2.Text;
				Value3 = Box3.Text;
				Checked = ChBox.Checked;
			}

			Box.Dispose();
			Box2.Dispose();
			Box3.Dispose();
			ChBox.Dispose();
			Prompt2Lbl.Dispose();
			Prompt3Lbl.Dispose();
			CheckEnableContols.Clear();

			return (res == DialogResult.OK);
		}

		public bool Show(string Title, string Prompt, ref string Value,
		                 string Prompt2, ref string Value2,
		                 string PromptChBox, ref bool Checked)
		{
			Top = 55;
			Height = 380;
			BlackPanel.Height = 380;
			WhitePanel.Height = 372;
			OkBtn.Top = 310;
			CancelBtn.Top = 310;

			TitleLbl.Text = Title;

			PromptLbl.Text = Prompt;
			TextBox Box = new TextBox();
			Box.GotFocus += Box_GotFocus;
			Box.Left = PromptLbl.Left;
			Box.Top = PromptLbl.Top + PromptLbl.Height;
			Box.Width = WhitePanel.Width - Box.Left * 2;
			Box.Text = Value;
			WhitePanel.Controls.Add(Box);

			Label Prompt2Lbl = new Label();
			Prompt2Lbl.Font = PromptLbl.Font;
			Prompt2Lbl.Left = PromptLbl.Left;
			Prompt2Lbl.Height = PromptLbl.Height;
			Prompt2Lbl.Top = Box.Top + Box.Height + 10;
			Prompt2Lbl.Text = Prompt2;
			WhitePanel.Controls.Add(Prompt2Lbl);

			TextBox Box2 = new TextBox();
			Box2.GotFocus += Box_GotFocus;
			Box2.Left = Prompt2Lbl.Left;
			Box2.Top = Prompt2Lbl.Top + Prompt2Lbl.Height;
			Box2.Width = WhitePanel.Width - Box2.Left * 2;
			Box2.Text = Value2;
			WhitePanel.Controls.Add(Box2);


			CheckBox ChBox = new CheckBox();
			ChBox.Top = Box2.Top + Box2.Height + 10;
			ChBox.Height = Box2.Height;
			ChBox.Text = PromptChBox;
			ChBox.Width = Box2.Width;
			ChBox.Left = Box2.Left;
			ChBox.CheckStateChanged += ChBox_CheckStateChanged;
			ChBox.Checked = Checked;
			WhitePanel.Controls.Add(ChBox);


			InputPanel.Enabled = true;
			DialogResult res = ShowDialog();
			InputPanel.Enabled = false;
			if (res == DialogResult.OK)
			{
				Value = Box.Text;
				Value2 = Box2.Text;
				Checked = ChBox.Checked;
			}

			Box.Dispose();
			Box2.Dispose();
			ChBox.Dispose();
			Prompt2Lbl.Dispose();
			CheckEnableContols.Clear();

			return (res == DialogResult.OK);
		}

		private void ChBox_CheckStateChanged(object sender, EventArgs e)
		{
			bool ch = ((CheckBox) sender).Checked;
			for (int i = 0; i < CheckEnableContols.Count; i++)
				CheckEnableContols[i].Enabled = !ch;
		}

		private void Box_GotFocus(object sender, EventArgs e)
		{
			InputPanel.Enabled = true;
		}

		private void OkBtn_Click(object sender, EventArgs e)
		{
		}

		private void CancelBtn_Click(object sender, EventArgs e)
		{
		}
	}
}