viernes, 26 de agosto de 2011

Interfaz Ficha

1-creamos el formulario padre:


que tendra el siguiente codigo que esta en color rojo:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace InterfazFicha
{
    class Form_Padre:Form
    {
        public Cficha[] elementos;
        public int indice, tamaño;
        public Form_Padre()
        {
            indice=0;
            tamaño=20;
            elementos = new Cficha[20];
            elementos[indice]=new Cficha();
        }


        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // Form_Padre
            // 
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Name = "Form_Padre";
           
            this.ResumeLayout(false);


        }


        
    }
}



2-Luego debemos realizar 
la  siguiente  interfaz  gráfica  la  cual  nos  va  a  permitir  la  entrada  de  datos  correspondientes  a objetos de tipo Ficha:


cuando introduzcamos datos y le demos en guardar se deberan almacenar los datos de esa persona en un arreglo de objetos de tipo ficha;  Una  vez  guardado los datos  se  debera  limpiar  las  cajas  de  texto  para  permitir  la  entrada  de  una  nueva  ficha  dando  clic  en  el  botón 
Limpiar.  


Este seria el codigo del boton guardar:



 private void btguardar_Click(object sender, EventArgs e)
        {


int h, m, s;
            string f;
            char sex;
            if (ctnombre.Text == "" && ctsexo.Text == "" && ((cthora.Text.Substring(0, 2) == "  ") || (cthora.Text.Substring(3, 2) == "  ") || (cthora.Text.Substring(6, 2) == "  ") || (cthora.Text.Substring(9, 2) == "  ")))
            {
                MessageBox.Show("El campo Nombre, Sexo Y Hora de nacimieno deben contener algun valor", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else if (ctnombre.Text == "")
            {
                MessageBox.Show("El campo Nombre debe contener algun valor", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else if (ctsexo.Text == "")
            {
                MessageBox.Show("El campo Sexo debe contener algun valor", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else if (ctsexo.Text != "M" && ctsexo.Text != "F")
            {
                MessageBox.Show("El campo Sexo contiene un valor erroneo", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else if (cthora.Text.Substring(0, 1) == " " || cthora.Text.Substring(1, 1) == " " || cthora.Text.Substring(3, 1) == " " || cthora.Text.Substring(4, 1) == " " || cthora.Text.Substring(6, 1) == " " || cthora.Text.Substring(7, 1) == " " || cthora.Text.Substring(9, 1) == " " || cthora.Text.Substring(10, 1) == " ")
            {
                MessageBox.Show("Es necesario escribir valores sobre todos los caracteres de subrayado que aparecen en el campo Hora de nacimiento", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                sex = ctsexo.Text[0];
                h = (((int)cthora.Text[0] - 48) * 10) + ((int)cthora.Text[1] - 48);
                m = (((int)cthora.Text[3] - 48) * 10) + ((int)cthora.Text[4] - 48);
                s = (((int)cthora.Text[6] - 48) * 10) + ((int)cthora.Text[7] - 48);
                f = cthora.Text.Substring(9, 2);
                if (indice == 20)
                {
                    MessageBox.Show("No se pueden insertar mas elementos ARREGLO LLENO", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    elementos[indice] = new Cficha();
                    if (!(elementos[indice].set_ficha(ctnombre.Text, sex, h, m, s, f)))
                    {
                        MessageBox.Show("El campo Hora de nacimiento contiene algun valor erroneo", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        elementos[indice] = null;
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Elemento Guardado con exito", "Guardar", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                        indice++;
                        btlimpiar_Click(sender, e);
                    }
                }
            }
        }
Este seria el codigo del boton buscar:



private void btbuscar_Click(object sender, EventArgs e)
        {
            frmbuscar formulario;
            formulario = new frmbuscar(this);
            formulario.Show();
            btguardar.Visible = false;
        }



Este seria el codigo del boton Limpiar:



 private void btlimpiar_Click(object sender, EventArgs e)
        {
            ctsexo.Text = "";
            ctnombre.Text = "";
            cthora.Text = "";
        }


3-Al dar clic en el botón “Buscar” debe aparecer el siguiente formulario:


Después de introducir el nombre a buscar y pulsar el botón “Buscar” debe aparecer el resultado de la búsqueda 
en la etiqueta “Resultado”. Si la persona se encuentra debe aparecer el mensaje “La persona xxxxxx se encuentra 
registrada” y si no el mensaje “No se ha encontrado xxxxxx”

Este seria el codigo de el formulario lo que esta en color rojo:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace InterfazFicha
{
    class frmbuscar:Form_Padre
    {
        private string texto_inicial;
        private Label etnombre;
        private Label etresultado;
        private Label etmensaje;
        private TextBox ctnombre;
        private Button bttruco;
        private Button btbuscar;
        public frmbuscar()
        {
            InitializeComponent();
        }
        public frmbuscar(Form_Padre obj)
        {
            InitializeComponent();
            indice = obj.indice;
            tamaño = obj.tamaño;
            elementos = new Cficha[tamaño];
            for (int i = 0; i < indice; i++)
                elementos[i] = new Cficha(obj.elementos[i].clonar());
        }
        private void InitializeComponent()
        {
            this.etnombre = new System.Windows.Forms.Label();
            this.etresultado = new System.Windows.Forms.Label();
            this.etmensaje = new System.Windows.Forms.Label();
            this.ctnombre = new System.Windows.Forms.TextBox();
            this.btbuscar = new System.Windows.Forms.Button();
            this.bttruco = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // etnombre
            // 
            this.etnombre.AutoSize = true;
            this.etnombre.Location = new System.Drawing.Point(58, 24);
            this.etnombre.Name = "etnombre";
            this.etnombre.Size = new System.Drawing.Size(47, 13);
            this.etnombre.TabIndex = 0;
            this.etnombre.Text = "Nombre:";
            // 
            // etresultado
            // 
            this.etresultado.AutoSize = true;
            this.etresultado.Location = new System.Drawing.Point(58, 61);
            this.etresultado.Name = "etresultado";
            this.etresultado.Size = new System.Drawing.Size(58, 13);
            this.etresultado.TabIndex = 1;
            this.etresultado.Text = "Resultado:";
            // 
            // etmensaje
            // 
            this.etmensaje.AutoSize = true;
            this.etmensaje.Location = new System.Drawing.Point(170, 63);
            this.etmensaje.Name = "etmensaje";
            this.etmensaje.Size = new System.Drawing.Size(0, 13);
            this.etmensaje.TabIndex = 4;
            // 
            // ctnombre
            // 
            this.ctnombre.Location = new System.Drawing.Point(132, 17);
            this.ctnombre.Name = "ctnombre";
            this.ctnombre.Size = new System.Drawing.Size(176, 20);
            this.ctnombre.TabIndex = 2;
            this.ctnombre.Text = "Ingrese el nombre a buscar";
            
            this.ctnombre.Enter += new System.EventHandler(this.ctnombre_Enter);
            // 
            // btbuscar
            // 
            this.btbuscar.Location = new System.Drawing.Point(315, 15);
            this.btbuscar.Name = "btbuscar";
            this.btbuscar.Size = new System.Drawing.Size(75, 23);
            this.btbuscar.TabIndex = 3;
            this.btbuscar.Text = "&Buscar";
            this.btbuscar.UseVisualStyleBackColor = true;
            this.btbuscar.Click += new System.EventHandler(this.btbuscar_Click);
            // 
            // bttruco
            // 
            this.bttruco.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.bttruco.Location = new System.Drawing.Point(353, 24);
            this.bttruco.Name = "bttruco";
            this.bttruco.Size = new System.Drawing.Size(10, 10);
            this.bttruco.TabIndex = 5;
            this.bttruco.UseVisualStyleBackColor = true;
            this.bttruco.Click += new System.EventHandler(this.bttruco_Click);
            // 
            // frmbuscar
            // 
            this.AcceptButton = this.btbuscar;
            this.CancelButton = this.bttruco;
            this.ClientSize = new System.Drawing.Size(418, 128);
            this.Controls.Add(this.btbuscar);
            this.Controls.Add(this.ctnombre);
            this.Controls.Add(this.etmensaje);
            this.Controls.Add(this.etresultado);
            this.Controls.Add(this.etnombre);
            this.Controls.Add(this.bttruco);
            this.Name = "frmbuscar";
            this.Text = "Buscar";
            this.Load += new System.EventHandler(this.frmbuscar_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        private void frmbuscar_Load(object sender, EventArgs e)
        {
            etresultado.Visible = false;
        }
        private void ctnombre_Enter(object sender, EventArgs e)
        {
            texto_inicial = ctnombre.Text;
            TextBox obj = (TextBox)sender;
            obj.SelectAll();
           ctnombre.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            etmensaje.Visible = false;
            etresultado.Visible = false;
        }
        private void btbuscar_Click(object sender, EventArgs e)
        {
            string texto_a_buscar = ctnombre.Text;
            ctnombre.Text = texto_inicial;
            ctnombre.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            etresultado.Visible = Visible;
            etmensaje.Visible = Visible;
            for (int j = 0; j < indice; j++)
            {
                if (elementos[j].get_nombre()== texto_a_buscar)
                {
                    etmensaje.Text = "La persona " + texto_a_buscar + " se encuentra registrada";
                    return;
                }
                else
                    continue;
            }
            etmensaje.Text = "No se ha encontrado "+texto_a_buscar;
            return;
        }
        private void bttruco_Click(object sender, EventArgs e)
  
        {
            this.Close();
  
        }
        
    }
      
}
 ESTE SERIA EL RESULTADO FINAL:

      

No hay comentarios:

Publicar un comentario