Exemplo n.º 1
0
        public bool EmitirPedido(int ocorrencia, long Usuario, out string mensagemRetorno)
        {
            try
            {
                mensagemRetorno = string.Empty;
                using (this.PedidosClient = new sapiens_Syncnutriplan_ven_pedidosClient())
                {
                    N0203REGDataAccess reg = new N0203REGDataAccess();

                    int codTra = reg.pegaTransportadoraOcorrencia(ocorrencia);

                    this.PedidosClient.InnerChannel.OperationTimeout = new TimeSpan(0, 10, 0);
                    var dadosPedido = new pedidosPedidoViaOcorrenciaIn();

                    DebugEmail email = new DebugEmail();

                    dadosPedido.codTra = codTra;

                    dadosPedido.codTraSpecified = true;

                    dadosPedido.flowInstanceID = "1";

                    dadosPedido.flowName = "1";

                    dadosPedido.numReg = ocorrencia;

                    dadosPedido.numRegSpecified = true;

                    var retorno = PedidosClient.PedidoViaOcorrencia("nworkflow.web", "!nfr@t1n", 0, dadosPedido);

                    string msg = "Ocorrência: " + ocorrencia.ToString() + " Mensagem Retorno: " + retorno.mensagemRetorno;

                    if (retorno.erroExecucao == null)
                    {
                        email.Email("Webservice Pedido", msg);
                    }

                    mensagemRetorno = retorno.mensagemRetorno;
                    if (mensagemRetorno == "OK")
                    {
                        reg.GravarTransacaoIndenizado(ocorrencia, Usuario);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public JsonResult AprovarRegistrosOcorrencia(string codigoRegistro, string operacao, string tipoOperacao, string tipoNota, string observacao, string msgRetornoSapiens)
        {
            if (this.Logado != ((char)Enums.Logado.Sim).ToString())
            {
                return(this.Json(new { redirectUrl = Url.Action("Login", "Login"), Logado = true }, JsonRequestBehavior.AllowGet));
            }
            try
            {
                var        N0203REGBusiness = new N0203REGBusiness();
                var        aprovadoSucesso  = true;
                string     msgRetorno       = "";
                string     msgRetornoPedido = "";
                DebugEmail email            = new DebugEmail();

                bool Motivo = N0203REGBusiness.ConsultarOrigem(Convert.ToInt32(codigoRegistro));
                email.Email("Email ", codigoRegistro);
                if (Motivo == true)
                {
                    N0203REGBusiness.PedidosViaOcorrencia(Convert.ToInt32(codigoRegistro), int.Parse(this.CodigoUsuarioLogado), out msgRetornoPedido);
                }

                if (msgRetornoPedido == "" || msgRetornoPedido == "OK")
                {
                    msgRetorno = N0203REGBusiness.AprovarRegistrosOcorrencia(long.Parse(codigoRegistro), long.Parse(this.CodigoUsuarioLogado), observacao, int.Parse(operacao), tipoOperacao);
                }
                else
                {
                    aprovadoSucesso = false;
                }

                if (msgRetorno.Contains("Operação não permitida, verifique se a ocorrência está com a situação integrado ou faturada.") || msgRetorno.Contains("Operação não permitida, verifique se a ocorrência está com a situação recebida") || msgRetorno.Contains("não está com a situação recebido") || msgRetorno.Contains("Registro de Ocorrência está vinculada a um agrupamento."))
                {
                    aprovadoSucesso = false;
                }
                else if (msgRetorno != "Registros de ocorrências agrupadas foram integradas com sucesso!")
                {
                    if (int.Parse(operacao) == (int)Enums.OperacaoAprovacaoFaturamento.Aprovar && int.Parse(tipoNota) == (int)Enums.TipoNotaDevolucao.Nutriplan)
                    {
                        var descNota = Attributes.KeyValueAttribute.GetFirst("Descricao", Enums.TipoNotaDevolucao.Nutriplan).GetValue <string>();
                        if (msgRetornoPedido != "")
                        {
                            msgRetorno += "<br></br> Retorno Sapiens: " + msgRetornoSapiens + "<br/>Tipo Nota: " + tipoNota + " - " + descNota + ". Obs Aprovação Faturamento: " + observacao + " <br/>Pedido Indenizado: " + msgRetornoPedido;
                        }
                        else
                        {
                            msgRetorno += "<br></br> Retorno Sapiens: " + msgRetornoSapiens + "<br/>Tipo Nota: " + tipoNota + " - " + descNota + ". Obs Aprovação Faturamento: " + observacao;
                        }
                    }

                    else if (int.Parse(operacao) == (int)Enums.OperacaoAprovacaoFaturamento.Aprovar && int.Parse(tipoNota) == (int)Enums.TipoNotaDevolucao.Cliente)
                    {
                        var descNota = Attributes.KeyValueAttribute.GetFirst("Descricao", Enums.TipoNotaDevolucao.Cliente).GetValue <string>();
                        if (msgRetornoPedido != "")
                        {
                            msgRetorno += "<br></br> Tipo Nota: " + tipoNota + " - " + descNota + ". Obs Aprovação Faturamento: " + observacao + " <br/>Pedido Indenizado: " + msgRetornoPedido;
                        }
                        else
                        {
                            msgRetorno += "<br></br> Tipo Nota: " + tipoNota + " - " + descNota + ". Obs Aprovação Faturamento: " + observacao;
                        }
                    }

                    if (int.Parse(tipoNota) == (int)Enums.TipoNotaDevolucao.Nutriplan)
                    {
                        if (msgRetornoPedido != "")
                        {
                            msgRetorno += msgRetorno + "<br/><br/>Retorno Sapiens: " + msgRetornoSapiens + "<br/> Pedido Indenizado: " + msgRetornoPedido;
                        }
                        else
                        {
                            msgRetorno += msgRetorno + "<br/><br/>Retorno Sapiens: " + msgRetornoSapiens;
                        }
                    }
                }

                return(this.Json(new { msgRetorno, AprovadoSucesso = aprovadoSucesso }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                this.Session["ExceptionErro"] = ex;
                return(this.Json(new { redirectUrl = Url.Action("ErroException", "Erro"), ErroExcecao = true }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
		/// <summary>
		/// Sends the email message.
		/// </summary>
		public void Send()
		{
			// Initialize the body from the email template if we don't have a body set
			// and a template filename has been specified.

			if ((Body.Length == 0) && (TemplateFilename.Length > 0))
			{
				string filename = GetPhysicalPath(TemplateFilename);

				if (!File.Exists(filename))
					throw new EmailTemplateNotFoundException(TemplateFilename);

				Body = XmlUtils.Transform(BodyXmlDoc.InnerXml, filename, BodyParameters);
			}

			// Initialize the email message
			MailMessage message = new MailMessage
			{
				From = GetMailAddress(FromEmail, FromName),
				Subject = Subject,
				Body = Body,
				BodyEncoding = Encoding.ASCII,
				IsBodyHtml = IsHtml
			};

			message.Headers.Add("x-sender-application", "FocusOPEN");

			if (HasDebugMode && IsDebugMode)
			{
				// Add debug email addresses
				foreach (string debugEmailAddress in DebugEmail.Split(';').Where(StringUtils.IsEmail))
					message.To.Add(new MailAddress(debugEmailAddress));

				// List of actual recipients
				JoinableList jList = new JoinableList();

				// To recipients
				foreach (string recipient in Recipients)
					jList.Add(recipient);

				// CC recipients
				foreach (string recipient in CC.Where(recipient => !Recipients.Contains(recipient)))
					jList.Add("CC:" + recipient);

				// BCC recipients
				foreach (string recipient in BCC.Where(recipient => !Recipients.Contains(recipient) && !BCC.Contains(recipient)))
					jList.Add("BCC:" + recipient);

				// Build our debug message
				StringBuilder sb = new StringBuilder();

				if (IsHtml)
				{
					// Wrap our debug message in a DIV for better viewing
					sb.Append("<div style='margin:30px 0px 30px 0px;border:2px solid red;background:#eee;padding:10px;color:#000;'>");
					sb.Append("<p><strong>This email has been sent in debug mode.</strong></p>");
					sb.Append("<p><strong>Actual Recipients:</strong></p>");
					sb.Append(jList);
					sb.Append("</div>");
				}
				else
				{
					// Just add a few line breaks for text email messages
					sb.AppendFormat("\n\n\nThis email has been sent in debug mode.  Actual recipients: {0}", jList);
				}

				// Add debug message to the email message body
				message.Body += sb.ToString();
			}
			else
			{
				//---------------------------------------------------
				// Add all recipients
				//---------------------------------------------------

				foreach (string emailaddress in Recipients)
				{
					try
					{
						message.To.Add(emailaddress);
					}
					catch (Exception ex)
					{
						Debug.WriteLine(ex.Message);
					}
				}

				//---------------------------------------------------
				// Add all CC recipients which haven't
				// already been added into the recipients list
				//---------------------------------------------------

				foreach (string emailaddress in CC.Where(emailaddress => !Recipients.Contains(emailaddress)))
				{
					try
					{
						message.CC.Add(emailaddress);
					}
					catch (Exception ex)
					{
						Debug.WriteLine(ex.Message);
					}
				}

				//---------------------------------------------------
				// Add all BCC recipients which haven't
				// already been added into the CC or recipients list
				//---------------------------------------------------

				foreach (string emailaddress in BCC.Where(emailaddress => !Recipients.Contains(emailaddress) && !CC.Contains(emailaddress)))
				{
					try
					{
						message.Bcc.Add(emailaddress);
					}
					catch (Exception ex)
					{
						Debug.WriteLine(ex.Message);
					}
				}

				//---------------------------------------------------
				// Add all static BCC recipients which haven't
				// already been added into any other lists
				//---------------------------------------------------

				if (IncludeStaticBccRecipients)
				{
					foreach (string bccEmailAddress in BccEmail.Split(';').Where(bccEmailAddress => !Recipients.Contains(bccEmailAddress) && !CC.Contains(bccEmailAddress) && !BCC.Contains(bccEmailAddress)))
					{
						try
						{
							message.Bcc.Add(bccEmailAddress);
						}
						catch (Exception ex)
						{
							Debug.WriteLine(ex.Message);
						}
					}
				}
			}

			// Add attachments
			foreach (Attachment attachment in Attachments)
				message.Attachments.Add(attachment);

			// Only send the email message if the email engine is actually enabled
			if (EngineEnabled)
			{
				// Initialize the smtp client to send the email
				SmtpClient client = new SmtpClient(MailServer);

				// Add credentials to authenticate to mail server if required
				if (!StringUtils.IsBlank(MailServerUsername) || !StringUtils.IsBlank(MailServerPassword))
					client.Credentials = new System.Net.NetworkCredential(MailServerUsername, MailServerPassword, MailServerLogonDomain);

				// Send the message
				client.Send(message);
			}
		}