Flexcorp PERÚ
Compañía

Examen

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.IO;
using System.Xml.Serialization;
 
namespace EL3_Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        List<Medico> Meds = new List<Medico>();
        Medicos Med = new Medicos();
 
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }

        private void btAgregar_Click(object sender, EventArgs e)
        {
            var reg = (from x in Meds where x.NumColegiatura == txtColegiatura.Text select x).FirstOrDefault();
            if (reg != null)
            {
                MessageBox.Show("Numero de Colegiatura ya existe");
            }
            MemoryStream ms = new MemoryStream();
            StreamWriter fs = new StreamWriter(ms);
            fs.Write(txtPass.Text);
            fs.Flush();
            SHA1CryptoServiceProvider crypto = new SHA1CryptoServiceProvider();
            byte[] datos = crypto.ComputeHash(ms.GetBuffer());
            string cifrado = "";
            foreach (byte b in datos) 
            {
                cifrado += b.ToString();
            }
            reg = new Medico(txtColegiatura.Text, txtLogin.Text, cifrado);
            Meds.Add(reg);
            Med.listadao.Add(reg);

            dataGridView1.DataSource = null;
            dataGridView1.DataSource = Med.listadao;

        }

        private void btGuardar_Click(object sender, EventArgs e)
        {
            SaveFileDialog sdf = new SaveFileDialog();
            sdf.Filter = "Archivo XML|*.xml";
            if (sdf.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(sdf.FileName, FileMode.Create, FileAccess.Write);
                XmlSerializer xml = new XmlSerializer(typeof(Medicos));
                xml.Serialize(fs, Med);
                fs.Close();
            }
        }
 
        private void btAbrir_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            op.Filter = "Archivo XML|*.xml";
            if (op.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(op.FileName, FileMode.Open, FileAccess.Read);
                XmlSerializer xml = new XmlSerializer(typeof(Medicos));
                Med = (Medicos)xml.Deserialize(fs);
                fs.Close();

                dataGridView1.DataSource = null;
                dataGridView1.DataSource = Med.listadao;
            }
        }
    }
}
 

copyright 2015 Flexcorp PERÚ
Este sitio web fue creado de forma gratuita con PaginaWebGratis.es. ¿Quieres también tu sitio web propio?
Registrarse gratis