Imports BDtelefonos
Imports System.ComponentModel
Imports Microsoft.Win32
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging

Class PagFunAgregarTelefono
  Inherits PageFunction(Of telefono)
  Private nuevoObjTfno As New telefono()

  Public Sub New()
    InitializeComponent()
    Me.DataContext = nuevoObjTfno
  End Sub

  Private Sub PagFAgregarTelefono_Loaded(sender As Object, e As RoutedEventArgs)
    nuevoObjTfno.nombre = "Nombre"
    nuevoObjTfno.direccion = "Dirección"
    nuevoObjTfno.telefono1 = "000000000"
    nuevoObjTfno.observaciones = "Observaciones"
    Dim fotoFicticia As Bitmap = My.Resources.Resources.unafoto
    Dim ms As New MemoryStream()
    fotoFicticia.Save(ms, ImageFormat.Jpeg)
    nuevoObjTfno.foto = ms.ToArray()
  End Sub

  Private Sub imFoto_MouseDown(sender As Object, e As MouseButtonEventArgs)
    Dim dlg As New OpenFileDialog()
    dlg.Filter = "ficheros jpg (*.jpg)|*.jpg|" &
                 "ficheros jpeg (*.jpeg)|*.jpeg|" &
                 "ficheros png (*.png)|*.png|" &
                 "Todos (*.*)|*.*"
    dlg.ShowDialog()

    If dlg.FileName IsNot Nothing AndAlso dlg.FileName.Length > 0 Then
      nuevoObjTfno.foto = File.ReadAllBytes(dlg.FileName)
    End If
  End Sub

  Private Sub btAceptar_Click(sender As Object, e As RoutedEventArgs)
    ' Aceptar la información introducida
    OnReturn(New ReturnEventArgs(Of telefono)(nuevoObjTfno))
  End Sub

  Private Sub btCancelar_Click(sender As Object, e As RoutedEventArgs)
    ' Operación cancelada
    OnReturn(Nothing)
  End Sub
End Class
