Advertisement
onzulin

FormPacientes

Apr 16th, 2012
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Data.Objects;
  11. namespace dentalclinic
  12. {
  13.     public partial class FormPacientes : FormPlantilla
  14.     {
  15.        
  16.         private dentalclinicEntities contextoClinic = new dentalclinicEntities();
  17.  
  18.         private bool visible = false;
  19.  
  20.         public bool Visible
  21.         {
  22.             get { return visible; }
  23.             set { visible = value; }
  24.         }
  25.  
  26.         public FormPacientes()
  27.         {
  28.             InitializeComponent();
  29.         }
  30.  
  31.         private void FormPacientes_Load(object sender, EventArgs e)
  32.         {
  33.  
  34.            
  35.             //inicializo el contexto de entity framework
  36.             using (dentalclinicEntities contextoClinic = new dentalclinicEntities())
  37.             {
  38.                 //comboBoxDentistas.DisplayMember = "Nombre";
  39.                 //comboBoxDentistas.ValueMember = "Nombre";
  40.                 //comboBoxDentistas.DataSource = contextoClinic.dentistas;
  41.                 bindingSourcePacientes.DataSource = contextoClinic.pacientes;
  42.                 dentistasBindingSource.DataSource = contextoClinic.dentistas;
  43.                
  44.                 //this.comboBoxDentistas.DisplayMember = "nombre";
  45.                 //this.comboBoxDentistas.DataSource = ((ObjectQuery)dentista).Execute(MergeOption.AppendOnly);
  46.             }
  47.  
  48.         }
  49.  
  50.         private void guardarToolStripButton_Click(object sender, EventArgs e)
  51.         {
  52.             try
  53.             {
  54.                 //para terminar los cambios antes de salvarlos y asi no haya problemas probando a verf como tira
  55.                 bindingSourcePacientes.EndEdit();
  56.                 contextoClinic.SaveChanges();
  57.             }
  58.             catch (Exception ex)
  59.             {
  60.                 MessageBox.Show(ex.Message);
  61.             }
  62.         }
  63.  
  64.         private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
  65.         {
  66.             DialogResult respuesta;
  67.             respuesta = MessageBox.Show("¿Desea borrar al paciente?", "Pregunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  68.             if (respuesta == DialogResult.Yes)
  69.             {
  70.                 bindingSourcePacientes.RemoveCurrent();
  71.                 this.bindingSourcePacientes.EndEdit();
  72.                 contextoClinic.SaveChanges();
  73.             }
  74.         }
  75.  
  76.         private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
  77.         {
  78.             tbNumero.Focus();
  79.             tbNumero.Text = "Introduzca un numero";
  80.             tbNumero.SelectAll();
  81.         }
  82.  
  83.        
  84.  
  85.         private void pictureBoxPaciente_DoubleClick(object sender, EventArgs e)
  86.         {
  87.             OpenFileDialog dlgAbrir = new OpenFileDialog();
  88.             dlgAbrir.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  89.             dlgAbrir.Filter = "imagenes jpg (*.jpg) | *.jpg |imagenes png (*.png)| *.png |imagenes bmp (*.bmp)| *.bmp | todos (*.*)| *.*";
  90.             dlgAbrir.FilterIndex = 4;
  91.             dlgAbrir.RestoreDirectory = true;
  92.             //mostrar el cuadro de dialogo
  93.             if (dlgAbrir.ShowDialog() == DialogResult.OK)
  94.             {
  95.                 //ruta completa donde esta el fichero elegido
  96.                 string ruta = dlgAbrir.FileName;
  97.                 FileInfo fileInfo = new FileInfo(ruta);
  98.  
  99.                 if (fileInfo.Length > 1 * 1024 * 1024)
  100.                 {
  101.                     MessageBox.Show("No se puede almacenar imagenes de mas de 1 MB", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
  102.                     return;
  103.                 }
  104.             }
  105.         }
  106.  
  107.         private void pictureBoxPaciente_MouseEnter(object sender, EventArgs e)
  108.         {
  109.             toolTipPacientes.Show("doble click para insertar una imagen" + Environment.NewLine + "no puede ser mayor de 1 MB", pictureBoxPaciente);
  110.         }
  111.  
  112.         private void buttonMas_Click(object sender, EventArgs e)
  113.         {
  114.             //este boton lo usaremos para poner o no visible el apartado de la 2ª direccion
  115.             if (Visible == false)
  116.             {
  117.                 lbDireccion2.Visible = true;
  118.                 tbDireccion2.Visible = true;
  119.                 buttonMas.Text = "-";
  120.                 visible = true;
  121.             }
  122.             else
  123.             {
  124.                 lbDireccion2.Visible = false;
  125.                 tbDireccion2.Visible = false;
  126.                 buttonMas.Text = "+";
  127.                 Visible = false;
  128.             }
  129.         }
  130.  
  131.         private void comboBoxDentistas_Click(object sender, EventArgs e)
  132.         {
  133.             //consulta
  134.             var dentista = from dentistas in contextoClinic.dentistas
  135.                            select dentistas;
  136.             try
  137.             {
  138.                 this.comboBoxDentistas.DisplayMember = "nombre";
  139.                 this.comboBoxDentistas.DataSource = ((ObjectQuery)dentista).Execute(MergeOption.AppendOnly);
  140.             }
  141.             catch (Exception ex)
  142.             {
  143.                 MessageBox.Show(ex.Message);
  144.             }
  145.         }
  146.  
  147.        
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement