Guest User

Untitled

a guest
May 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. function mostraImagem(img) {
  2. var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
  3. if ($.inArray($(img).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
  4. swal('', 'Formato do arquivo inválido! Somente JPG, JPEG, PNG, BMP são permitidos.', 'warning');
  5. return false;
  6. }
  7. else {
  8. sizes = img.files[0].size;
  9. if (parseInt(sizes) > 100000) {
  10. swal("", "Tamanho do arquivo inválido! Tamanho máximo permitido 100 KB", 'warning');
  11. return false;
  12. }
  13. else {
  14. if (img.files && img.files[0]) {
  15. var reader = new FileReader();
  16.  
  17. reader.onload = function (e) {
  18. var imagem = document.getElementById("imgImage");
  19. imagem.src = e.target.result;
  20. imgConvertida = imagem.src;
  21. imgConvertida = 'data:image;base64,' + reader.result.replace('data:image/' + $(img).val().split('.').pop().toLowerCase().replace('jpg', 'jpeg') + ';base64,', '');
  22. SetarImagem(imgConvertida);
  23. };
  24. reader.readAsDataURL(img.files[0]);
  25. }
  26. }
  27. }
  28. }
  29.  
  30. function SetarImagem(imgConvertida) {
  31. var vData = {
  32. img2: imgConvertida
  33. };
  34.  
  35. $.post("/MeusDados/SetarImagem", { 'img': imgConvertida }, function (data) {
  36. swal('', 'Foto alterada com sucesso.', 'success');
  37. setTimeout(recarregarPagina, 2300);
  38. });
  39. }
  40. function recarregarPagina() {
  41. window.location.reload();
  42. }
  43.  
  44. Hashtable hash = new Hashtable();
  45. hash.Add("codigo", clientes.CliCodigo);
  46. hash.Add("nome", (!string.IsNullOrEmpty(clientes.CliApelido) ? clientes.CliApelido : primeiro + " " + ultimo));
  47. hash.Add("nome2", (!string.IsNullOrEmpty(clientes.CliApelido) ? clientes.CliApelido : clientes.CliNome));
  48. if (fotos != null)
  49. {
  50. if (fotos.CliFoto != null)
  51. {
  52. hash.Add("foto", System.Text.Encoding.UTF8.GetString(fotos.CliFoto, 0, fotos.CliFoto.Length));
  53. }
  54. }
  55. return JsonConvert.SerializeObject(hash);
  56.  
  57. $.get("/Home/ConsultarDadosUsuario", null, function (data) {
  58. if (data != null && data != undefined) {
  59. var objeto = JSON.parse(data);
  60. $("#nome").text(objeto.nome);
  61. $("#nome2").text(objeto.nome2);
  62. if (objeto.foto != null) {
  63. $("#imgpequena").attr("src", "data:image;base64," + objeto.foto);
  64. $("#fotoGrande").attr("src", "data:image;base64," + objeto.foto);
  65. }
  66. }
  67. });
Add Comment
Please, Sign In to add comment