Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. [SqlProcedure]
  2. public static int CustomMethod(int id_email, out string sError)
  3. {
  4. int mReturn = 0;
  5. DataSet ds = new DataSet();
  6. sError = string.Empty;
  7. Dictionary<int, string> ListFile = new Dictionary<int, string>();
  8. try
  9. {
  10. ds = retornarQuery(strQuery: "ZeusFW_Email_List " + id_email);
  11. if (ds.Tables[0].Rows.Count > 0)
  12. {
  13. for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
  14. {
  15. DataRow row = ds.Tables[0].Rows[i];
  16. string ds_to_name = (string)row["ds_to_name"];
  17. string ds_to_email = (string)row["ds_to_email"];
  18. string ds_cc_email = (string)row["ds_cc_email"];
  19. string ds_bcc_email = (string)row["ds_bcc_email"];
  20. string ds_idiom = (string)row["ds_idiom"];
  21. string ds_subject = (string)row["ds_subject"];
  22. string ds_body = (string)row["ds_body"];
  23. int am_sent_times = (int)row["am_sent_times"];
  24. int in_process = (int)row["in_process"];
  25. int am_email_port = (int)row["am_email_port"];
  26. string ds_email_host = (string)row["ds_email_host"];
  27. string ds_email_user = (string)row["ds_email_user"];
  28. string ds_email_password = (string)row["ds_email_password"];
  29. int am_email_html = (int)row["am_email_html"];
  30. int am_email_ssl = (int)row["am_email_ssl"];
  31. string ds_email_name = (string)row["ds_email_name"];
  32. string ds_email_xsl = (string)row["ds_email_xsl"];
  33. int in_email_log = (int)row["in_email_log"];
  34. DeliveryNotificationOptions am_notificationoptions = NotificationOptions((int)row["am_notificationoptions"]);
  35. MailPriority am_priority = Priority((int)row["am_priority"]);
  36. if (in_process == 0 && am_email_html == 1)
  37. {
  38. ds_body = DoXSLT(ds_body, ds_email_xsl);
  39. }
  40. ZeusFrameworkSmtp.ZeusFrameworkSmtp email = new ZeusFrameworkSmtp.ZeusFrameworkSmtp();
  41. email.AddFrom = ds_email_user;
  42. email.AddName = ds_email_name;
  43. email.AddTo.Add(ds_to_email);
  44. if (ds_cc_email != null || !ds_cc_email.Equals("")) email.AddCC = ds_cc_email;
  45. if (ds_bcc_email != null || !ds_bcc_email.Equals("")) email.AddBcc = ds_bcc_email;
  46. if (am_sent_times > 0) { ds_subject = "Re#" + am_sent_times + " " + ds_subject; }
  47. email.Subject = ds_subject;
  48. email.Body = ds_body;
  49. email.BodyHtml = (am_email_html == 0 ? false : true);
  50. email.Server = ds_email_host;
  51. email.Port = am_email_port;
  52. email.User = ds_email_user;
  53. email.Password = ds_email_password;
  54. email.EnableSsl = (am_email_ssl == 0 ? false : true); ;
  55. email.NotificationOptions = am_notificationoptions;
  56. email.Priority = am_priority;
  57. am_sent_times = am_sent_times + 1;
  58. if (ds.Tables[1].Rows.Count > 0)
  59. {
  60. for (int j = 0; j <= ds.Tables[1].Rows.Count - 1; j++)
  61. {
  62. DataRow rowAttachments = ds.Tables[1].Rows[j];
  63. if (id_email == (int)rowAttachments["id_email"])
  64. {
  65. if ((int)rowAttachments["in_delete_file"] == 1) ListFile.Add(j, (string)rowAttachments["ds_full_path"]);
  66. email.AddAttachments.Add((string)rowAttachments["ds_full_path"]);
  67. }
  68. }
  69. }
  70. bool bresult = email.Send(out sError);
  71. //if (bresult) { mReturn = 1; Database.ZeusFW_Email_Update(id_email, am_sent_times, sError, in_email_log).Run(); }
  72. if (string.IsNullOrEmpty(sError) || sError.Equals("ESTOY EJECUTANDO EL METODO")) sError = "Operación completada con éxito.";
  73. if (ListFile.Count > 0)
  74. {
  75. foreach (KeyValuePair<int, string> item in ListFile)
  76. {
  77. if (item.Key == 1) File.Delete(item.Value.ToString());
  78. }
  79. ListFile.Clear();
  80. }
  81. }
  82. }
  83. else sError = "No se encontró el ID";
  84. }
  85. catch (Exception ex)
  86. {
  87. StringBuilder s = new StringBuilder();
  88. //sError = sError + "-" + "Error executing SQL statement information: " + ex.Message + "id_email : " + id_email.ToString() + "Conn : " + Database.ConnectionString + ex.StackTrace.ToString();
  89.  
  90. LogWindows _LogWindows = new LogWindows();
  91. _LogWindows.Save("Zeus", sError, System.Diagnostics.EventLogEntryType.Error);
  92. //SqlContext.Pipe.Send("Error executing SQL statement information: " + ex.Message + "id_email> " + id_email_aux.ToString() + "Conn>" + Database.ConnectionString);
  93. }
  94. return mReturn;
  95. }
  96.  
  97. CREATE PROCEDURE [dbo].[CustomMethod]
  98. @id_email int
  99. ,@sError nvarchar(2000)=NULL OUTPUT
  100. WITH EXECUTE AS CALLER
  101. AS
  102. EXTERNAL NAME [AssemblyNamespace].[AssemblyNamespace.AssemblyNamespace1].[CustomMethod]
  103. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement