using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using banco1.comunicaciones;

namespace banco1.presentacion.comunic
{
	/// <summary>
	/// Descripción breve de FServidor.
	/// </summary>
	public class FServidor : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox tbIP;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.NumericUpDown nudPuerto;
		private System.Windows.Forms.Button bInterruptor;
		/// <summary>
		/// Variable del diseñador requerida.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private Servidor mServidor;

		public FServidor()
		{
			//
			// Necesario para admitir el Diseñador de Windows Forms
			//
			InitializeComponent();

		}

		/// <summary>
		/// Limpiar los recursos que se estén utilizando.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Código generado por el Diseñador de Windows Forms
		/// <summary>
		/// Método necesario para admitir el Diseñador. No se puede modificar
		/// el contenido del método con el editor de código.
		/// </summary>
		private void InitializeComponent()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.bInterruptor = new System.Windows.Forms.Button();
			this.nudPuerto = new System.Windows.Forms.NumericUpDown();
			this.label2 = new System.Windows.Forms.Label();
			this.tbIP = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.nudPuerto)).BeginInit();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.bInterruptor);
			this.groupBox1.Controls.Add(this.nudPuerto);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.tbIP);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new System.Drawing.Point(16, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(240, 112);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Estado";
			// 
			// bInterruptor
			// 
			this.bInterruptor.Location = new System.Drawing.Point(160, 56);
			this.bInterruptor.Name = "bInterruptor";
			this.bInterruptor.Size = new System.Drawing.Size(40, 24);
			this.bInterruptor.TabIndex = 5;
			this.bInterruptor.Text = "On";
			this.bInterruptor.Click += new System.EventHandler(this.bInterruptor_Click);
			// 
			// nudPuerto
			// 
			this.nudPuerto.Location = new System.Drawing.Point(64, 56);
			this.nudPuerto.Maximum = new System.Decimal(new int[] {
																	  8000,
																	  0,
																	  0,
																	  0});
			this.nudPuerto.Name = "nudPuerto";
			this.nudPuerto.Size = new System.Drawing.Size(88, 20);
			this.nudPuerto.TabIndex = 4;
			this.nudPuerto.Value = new System.Decimal(new int[] {
																	1200,
																	0,
																	0,
																	0});
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 64);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 24);
			this.label2.TabIndex = 2;
			this.label2.Text = "Puerto:";
			// 
			// tbIP
			// 
			this.tbIP.Enabled = false;
			this.tbIP.Location = new System.Drawing.Point(64, 24);
			this.tbIP.Name = "tbIP";
			this.tbIP.Size = new System.Drawing.Size(136, 20);
			this.tbIP.TabIndex = 1;
			this.tbIP.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "IP:";
			// 
			// FServidor
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(592, 358);
			this.Controls.Add(this.groupBox1);
			this.Name = "FServidor";
			this.Text = "Monitorización del servidor";
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.nudPuerto)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void bInterruptor_Click(object sender, System.EventArgs e)
		{
			try 
			{
				if (this.bInterruptor.Text.Equals("On")) 
				{
					mServidor=new Servidor(this, 1200);
					this.bInterruptor.Text="Off";
				} 
				else 
				{
					
				}
			}
			catch (Exception ex) 
			{
				MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}

		public void logError(String msg) 
		{
			MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
		}
	}
}
