private void Guardar() { try { var pl = new AutoFacturacionPL(); var result = pl.Guardar(imagenInfo); if (result == 0) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.RegistrarAutoFacturacion_ErrorGuardar, MessageBoxButton.OK, MessageImage.Error); } else { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], string.Format(Properties.Resources.RegistrarAutoFacturacion_ExitoGuardar, result), MessageBoxButton.OK, MessageImage.Correct); Close(); } } catch (Exception ex) { Logger.Error(ex); SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.RegistrarAutoFacturacion_ErrorGuardar, MessageBoxButton.OK, MessageImage.Error); } }
private void GuardarImagenes(string guardarEn) { try { var pl = new AutoFacturacionPL(); var ruta = string.Format("{0}\\{1}", Properties.Resources.ProcesarAutoFacturacion_CarpetaPrimaria, Properties.Resources.ProcesarAutoFacturacion_CarpetaSecundaria); var result = pl.ObtenerImagenes(Contexto); if (result.Any()) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], string.Format(Properties.Resources.ProcesarAutoFacturacion_MsgCantidadImagenes, result.Count), MessageBoxButton.OK, MessageImage.Warning); if (!Directory.Exists(ruta)) { Directory.CreateDirectory(ruta); } else { Directory.Delete(ruta, true); } var contador = 1; var orgIdAnterior = 0; var folioIdAnterior = 0; foreach (var img in result.OrderBy(item => item.OrganizacionId).ThenBy(item => item.FolioCompra)) { var nuevaCarpeta = string.Format("{0}\\{1}", ruta, img.Organizacion); if (!Directory.Exists(nuevaCarpeta)) { Directory.CreateDirectory(nuevaCarpeta); } var nuevaCarpetaFolio = string.Format("{0}\\{1}", nuevaCarpeta, img.FolioCompra); if (!Directory.Exists(nuevaCarpetaFolio)) { Directory.CreateDirectory(nuevaCarpetaFolio); } if (orgIdAnterior == img.OrganizacionId) { if (folioIdAnterior == img.FolioCompra) { contador++; } else { contador = 1; } } else { contador = 1; } if (!File.Exists(string.Format("{0}\\Imagen{1}.jpg", nuevaCarpetaFolio, img.FolioCompra))) { var miImagen = byteArrayToImage(img.ImgDocmento); miImagen.Save(string.Format("{0}\\Imagen{1}.jpg", nuevaCarpetaFolio, contador)); } orgIdAnterior = img.OrganizacionId; folioIdAnterior = img.FolioCompra; } SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.ProcesarAutoFacturacion_MsgZip, MessageBoxButton.OK, MessageImage.Warning); ZipFile zip = new ZipFile(); zip.AddDirectory(ruta); zip.Save(guardarEn); } else { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.ProcesarAutoFacturacion_MsgSinImagenes, MessageBoxButton.OK, MessageImage.Warning); } } catch (Exception ex) { Logger.Error(ex); SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.ProcesarAutoFacturacion_MsgErrorExportar, MessageBoxButton.OK, MessageImage.Error); } finally { if (Directory.Exists(Properties.Resources.ProcesarAutoFacturacion_CarpetaPrimaria)) { Directory.Delete(Properties.Resources.ProcesarAutoFacturacion_CarpetaPrimaria, true); } } }