lekarze1

Kolorwanie:
Status:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
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.IO;
using System.Xml.Serialization;

namespace Lab9_po
{
    public partial class Main : Form
    {
        private List<Pacjent1> pacjenci = new List<Pacjent1>();

        public Main()
        {
            InitializeComponent();
        }

        private void DodajPacjenta(Pacjent1 p)
        {
            pacjenci.Add(p);
        }

        private void DodajPacjentaDoDataGridView(Pacjent1 p)
        {
            dataGridView1.Rows.Add(p.Imie, p.DataUrodzenia, p.Pesel, p.Ubezpieczenie, p.Lekarz);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" ||
                textBox4.Text == "" || textBox5.Text == "")
                MessageBox.Show("Uzupelnij wszystkie pola");
            else
            {
                try
                {
                   // Pacjent p = new Pacjent(textBox1.Text, textBox2.Text, 
                       // Convert.ToInt32(textBox3.Text), textBox4.Text, Convert.ToInt32(textBox5.Text));


                    Pacjent1 p = new Pacjent1(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text,
                         textBox5.Text);
                    
                    
                    DodajPacjenta(p);
                    DodajPacjentaDoDataGridView(p);
                    textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = "";
                    this.DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Blad: " + ex.Message);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = "";
            dataGridView1.Rows.Clear();
            pacjenci.Clear();
            MessageBox.Show("Wyczyszczono wszystko");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.InitialDirectory = "";
            saveFileDialog1.Filter = "Plik tekstowy (*.txt)|*.txt|Wszystkie pliki (*.*)|*.*";
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.FileName = "pacjenci";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);
                StreamWriter sw = new StreamWriter(fs);
                for (int i = 0; i < pacjenci.Count; i++)
                {
                    sw.WriteLine("[PACJENT]");
                    sw.WriteLine("[" + dataGridView1.Columns[0].Name + "]");
                    sw.WriteLine(pacjenci[i].Imie);
                    sw.WriteLine("[" + dataGridView1.Columns[1].Name + "]");
                    sw.WriteLine(pacjenci[i].DataUrodzenia);
                    sw.WriteLine("[" + dataGridView1.Columns[2].Name + "]");
                    sw.WriteLine(pacjenci[i].Pesel);
                    sw.WriteLine("[" + dataGridView1.Columns[3].Name + "]");
                    sw.WriteLine(pacjenci[i].Ubezpieczenie);
                    sw.WriteLine("[" + dataGridView1.Columns[4].Name + "]");
                    sw.WriteLine(pacjenci[i].Lekarz);
                    sw.WriteLine("[END PACJENT]");
                    sw.WriteLine();
                }
                sw.Close();
                fs.Close();
                MessageBox.Show("Zapisano do pliku \"pacjenci.txt\"");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //if (File.Exists("./pacjenci.txt"))
            //{
                    OpenFileDialog openFileDialog1 = new OpenFileDialog();
                    openFileDialog1.InitialDirectory = "";
                    openFileDialog1.Filter = "Plik tekstowy (*.txt)|*.txt|Wszystkie pliki (*.*)|*.*";
                    openFileDialog1.RestoreDirectory = true;
                    openFileDialog1.FileName = "pacjenci";
                    if (openFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open);
                        StreamReader sr = new StreamReader(fs);
                        dataGridView1.Rows.Clear();
                        pacjenci.Clear();
                        string linia;
                        Pacjent1 p;
                        try
                        {
                            while ((linia = sr.ReadLine()) != null)
                            {
                                if (linia == "[PACJENT]")
                                {
                                    p = new Pacjent1();
                                    while ((linia = sr.ReadLine()) != "[END PACJENT]")
                                    {
                                        if (linia == ("[" + dataGridView1.Columns[0].Name + "]"))
                                        {
                                            p.Imie = sr.ReadLine();
                                            continue;
                                        }
                                        if (linia == ("[" + dataGridView1.Columns[1].Name + "]"))
                                        {
                                            p.DataUrodzenia = sr.ReadLine();
                                            continue;
                                        }
                                        if (linia == ("[" + dataGridView1.Columns[2].Name + "]"))
                                        {
                                            p.Pesel = sr.ReadLine();
                                            continue;
                                        }
                                        if (linia == ("[" + dataGridView1.Columns[3].Name + "]"))
                                        {
                                            p.Ubezpieczenie = sr.ReadLine();
                                            continue;
                                        }
                                        if (linia == ("[" + dataGridView1.Columns[4].Name + "]"))
                                        {
                                            p.Lekarz = sr.ReadLine();
                                        }
                                    }
                                    DodajPacjenta(p);
                                    DodajPacjentaDoDataGridView(p);
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Blad: " + ex.Message);
                        }
                        finally
                        {
                            sr.Close();
                            fs.Close();
                            if (this.DialogResult == DialogResult.OK)
                                MessageBox.Show("Odczytano z pliku \"pacjenci.txt\"");
                        }
                    }
            //}
        }

        private void button4_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.InitialDirectory = "";
            saveFileDialog1.Filter = "Plik xml (*.xml)|*.xml|Wszystkie pliki (*.*)|*.*";
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.FileName = "pacjenci";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);
                XmlSerializer serializer = new XmlSerializer(typeof(List<Pacjent1>));
                serializer.Serialize(fs, pacjenci);
                fs.Close();
                MessageBox.Show("Zserializowano do pliku \"pacjenci.xml\"");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //if (File.Exists("./pacjenci .xml"))
            //{
                    OpenFileDialog openFileDialog1 = new OpenFileDialog();
                    openFileDialog1.InitialDirectory = "";
                    openFileDialog1.Filter = "Plik xml (*.xml)|*.xml|Wszystkie pliki (*.*)|*.*";
                    openFileDialog1.RestoreDirectory = true;
                    openFileDialog1.FileName = "pacjenci";
                    if (openFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open);
                        XmlSerializer serializer = new XmlSerializer(typeof(List<Pacjent1>));
                        dataGridView1.Rows.Clear();
                        try
                        {
                            pacjenci = (List<Pacjent1>)serializer.Deserialize(fs);
                            for (int i = 0; i < pacjenci.Count; i++)
                            {
                                DodajPacjentaDoDataGridView(pacjenci[i]);
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Blad: " + ex.Message);
                        }
                        finally
                        {
                            fs.Close();
                            if (this.DialogResult == DialogResult.OK)
                                MessageBox.Show("Deserializowano z pliku \"pacjenci.xml\"");
                        }
                    }
            //}
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void lekarzeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Lekarze addLekarzform = new Lekarze(this);
            DialogResult lekarz = addLekarzForm.ShowDialog();
            this.DialogResult = DialogResult.OK;
        }

    }
}


Copyrights 2014-2018 © Wklejaj.pl Wszelkie prawa zastrzeżone.