/// <summary> /// metodo para abrir el popup de edicion de fecha /// </summary> /// <param name="obj">un objeto tipo grupo_horario o un objeto tipo datetime</param> private async void AbrirAgenda(object obj) { try { StaticSourcesViewModel.ShowMensajeProgreso("Abriendo Modal"); ListArea = ListArea ?? await StaticSourcesViewModel.CargarDatosAsync <ObservableCollection <AREA> >(() => new ObservableCollection <AREA>(new cArea().GetData().Where(w => w.ID_TIPO_AREA != 5))); ListEstatusGrupo = ListEstatusGrupo ?? await StaticSourcesViewModel.CargarDatosAsync <ObservableCollection <GRUPO_HORARIO_ESTATUS> >(() => new ObservableCollection <GRUPO_HORARIO_ESTATUS>(new cGrupoHorarioEstatus().GetData())); SelectedArea = null; SelectedEstatusGrupo = 1; EditFechaInicio = null; EditFechaFin = null; SelectedFecha = null; await TaskEx.Delay(1); EntityUpdate = null; AgregarFecha = Visibility.Collapsed; PopUpsViewModels.ShowPopUp(this, PopUpsViewModels.TipoPopUp.EDITAR_FECHA); if (obj == null) { return; } // se valida de que tipo es el objeto if (obj is GRUPO_HORARIO) { EntityUpdate = (GRUPO_HORARIO)obj; SelectedArea = EntityUpdate.ID_AREA; SelectedEstatusGrupo = EntityUpdate.ESTATUS; EditFechaInicio = EntityUpdate.HORA_INICIO; EditFechaFin = EntityUpdate.HORA_TERMINO; SelectedFecha = EntityUpdate.HORA_INICIO.Value.Date; } else { SelectedFecha = (DateTime)obj; } await TaskEx.Delay(1); if (ListInternosDia == null) { await TaskEx.Delay(1); } DatagridHorario.ItemsSource = ListInternosDia.Where(w => w.ListHorario.Any()); StaticSourcesViewModel.CloseMensajeProgreso(); } catch (Exception ex) { StaticSourcesViewModel.ShowMessageError("Algo pasó...", "Ocurrió un error al abrir agenda", ex); } }
/// <summary> /// Metodo auxiliar para ejecutar procesos asincronos /// </summary> /// <typeparam name="T">Objeto que regresa el proceso</typeparam> /// <param name="Mensaje">Mensaje para el usuario</param> /// <param name="predicade">Proceso</param> /// <param name="Tipo_Loader">Tipo de loading</param> /// <returns>Respuesta del Proceso</returns> public static async Task <T> OperacionesAsync <T>(string Mensaje, Func <T> predicade, TipoLoader Tipo_Loader = TipoLoader.PROGRESSRING) { T result = default(T); try { StaticSourcesViewModel.ShowMensajeProgreso(Mensaje, Tipo_Loader); result = await Task.Factory.StartNew <T>(predicade); } catch (Exception ex) { StaticSourcesViewModel.ShowMessageError("Algo pasó...", "Ocurrió un error en el proceso", ex); } finally { StaticSourcesViewModel.CloseMensajeProgreso(); } return(result); }
public DigitalizarDocumento(Window hook) { try { this.hook = hook; PDFViewer = PopUpsViewModels.MainWindow.DigitalizarDocumentos.pdfViewer; document = new PdfDocument(); limiteHojas = Parametro.LIMITES_HOJAS_ESCANER; EscaneoCompletado += delegate { }; _twain = new Twain(new WpfWindowMessageHook(this.hook)); _twain.TransferImage += delegate(Object sender, TransferImageEventArgs args) { //obtenemos el limite de hojas a escanear, en caso de haber sobrepasado utilizamos un return if (limiteHojas < (pagecount + 1)) { return; } var resultImage = args.Image; IntPtr hbitmap = new Bitmap(args.Image).GetHbitmap(); var imagen = Imaging.CreateBitmapSourceFromHBitmap( hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); document.Pages.Add(new PdfPage()); var xgr = XGraphics.FromPdfPage(document.Pages[pagecount]); var Ximg = XImage.FromBitmapSource(imagen); xgr.DrawImage(Ximg, 0, 0, 595, 842); pagecount++; Gdi32Native.DeleteObject(hbitmap); }; _twain.ScanningComplete += delegate(object sender, ScanningCompleteEventArgs e) { var s = e.Exception; StaticSourcesViewModel.CloseMensajeProgreso(); if (pagecount == 0) { StaticSourcesViewModel.Mensaje("Digitalización", "*- Hay problemas para conectarse con el escáner\n*- No tiene papel en el escáner.", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION); return; } else { pagecount = 0; } fileNamepdf = Path.GetTempPath() + Path.GetRandomFileName().Split('.')[0] + ".pdf"; document.Save(fileNamepdf); ScannedDocument = File.ReadAllBytes(fileNamepdf); Application.Current.Dispatcher.Invoke((System.Action)(delegate { obj.LoadFile(fileNamepdf); obj.Visibility = Visibility.Visible; })); EscaneoCompletado(this, null); }; } catch (TwainException) { } }
public Task <bool> Scann(bool Duplex, EscanerSources equipo, PdfViewer obj = null) { this.obj = obj; scannedDoc = new List <string>(); PDFViewer = this.obj; Application.Current.Dispatcher.Invoke((System.Action)(delegate { obj.Visibility = Visibility.Collapsed; })); try { if (_twain == null) { StaticSourcesViewModel.CloseMensajeProgreso(); Application.Current.Dispatcher.Invoke((System.Action)(delegate { StaticSourcesViewModel.Mensaje("Digitalización", "*- No tienes ningun escáner instalado.\n*- Revise que el escáner este encendido.\n*- Revise que el escáner esté bien conectado", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION); })); } else { StaticSourcesViewModel.ShowMensajeProgreso("Espere Por Favor, Escaneando..."); System.Threading.Thread.Sleep(1500); var SourceNames = _twain.SourceNames; Application.Current.Dispatcher.Invoke((System.Action)(delegate { try { if (equipo != null) { _twain.SelectSource(equipo.Source); } else { _twain.SelectSource(_twain.DefaultSourceName); } //ponemos los dpi que este es el mas bajo y optimo ResolutionSettings.ColourPhotocopier.Dpi = 100; _twain.StartScanning(new ScanSettings() { UseDuplex = Duplex, ShowTwainUI = false, Resolution = ResolutionSettings.ColourPhotocopier, ShouldTransferAllPages = true, Rotation = new RotationSettings() { AutomaticRotate = true } }); } catch (TwainException tw) { StaticSourcesViewModel.CloseMensajeProgreso(); if (tw.Message.ToUpper().Contains("ERROR OPENING DATA SOURCE")) { StaticSourcesViewModel.Mensaje("Digitalización", "*- No tienes ningun escáner instalado.\n*- Revise que el escáner este encendido.\n*- Revise que el escáner esté bien conectado", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION); } else { StaticSourcesViewModel.Mensaje("Algo pasó", tw.Message, StaticSourcesViewModel.enumTipoMensaje.MENSAJE_ERROR); } } })); } #region comentado //var morePages = true; //var commonDialogClass = new CommonDialog(); //var scannerDevice = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false); //var pagecount = 0; /*if (scannerDevice != null) * { * scannerDevice.Properties["Pages"].set_Value(1); * scannerDevice.Properties["Document Handling Select"].set_Value(5); * * var document = new PdfDocument(); * while (morePages) * { * try * { * var scannnerItem = scannerDevice.Items[1]; * AdjustScannerSettings(scannnerItem, 100, 0, 0, 850, 1400, 0, 0, WiaImageIntent.ColorIntent); * * var img = (ImageFile)scannnerItem.Transfer("{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"); * if (img != null) * { * * document.Pages.Add(new PdfPage()); * var xgr = XGraphics.FromPdfPage(document.Pages[pagecount]); * var Ximg = XImage.FromBitmapSource(ConvertScannedImage(img)); * * xgr.DrawImage(Ximg, 0, 0, 595, 842); * * pagecount++; * } * * WIA.Property documentHandlingSelect = null; * WIA.Property documentHandlingStatus = null; * * foreach (WIA.Property prop in scannerDevice.Properties) * { * if (prop.PropertyID == 3088) * documentHandlingSelect = prop; * * if (prop.PropertyID == 3087) * documentHandlingStatus = prop; * } * * morePages = false; * * if (documentHandlingSelect != null) * if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) & 0x00000001) != 0) * morePages = ((Convert.ToUInt32(documentHandlingStatus.get_Value()) & 0x00000001) != 0); * } * catch (Exception ex) * { * if (pagecount <= 0) * Application.Current.Dispatcher.Invoke((System.Action)(delegate * { * if (ex.Message == "Exception from HRESULT: 0x80210003") * StaticSourcesViewModel.Mensaje("Digitalización", "Revise que la bandeja tenga hojas", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION); * else * if (ex.Message == "Value does not fall within the expected range.") * StaticSourcesViewModel.Mensaje("Digitalización", "*- Revise que el escáner este encendido.\n*- Revise que el escáner este bien conectado", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION); * else * StaticSourcesViewModel.Mensaje("Digitalización", "Hay problemas para conectarse con el escaner", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION); * })); * * morePages = false; * } * } * * if (pagecount > 0) * { * fileNamepdf = Path.GetTempPath() + Path.GetRandomFileName().Split('.')[0] + ".pdf"; * * document.Save(fileNamepdf); * * ScannedDocument = File.ReadAllBytes(fileNamepdf); * * Application.Current.Dispatcher.Invoke((System.Action)(delegate * { * obj.LoadFile(fileNamepdf); * obj.Visibility = Visibility.Visible; * })); * } * }*/ #endregion } catch (Exception ex) { Application.Current.Dispatcher.Invoke((System.Action)(delegate { if (ex.Message.Contains("HRESULT: 0x80210015")) { StaticSourcesViewModel.Mensaje("Digitalización", "*- No tienes ningun escáner instalado.\n*- Revise que el escáner este encendido.\n*- Revise que el escáner esté bien conectado", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION); } if (ex.Message.Contains("HRESULT: 0x80070021")) { StaticSourcesViewModel.Mensaje("Digitalización", "Hay problemas para conectarse con el escáner", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION); } })); StaticSourcesViewModel.CloseMensajeProgreso(); } return(TaskEx.FromResult(true)); }