Project files for the Acumatica Import for United Rentals
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

114 rader
4.8 KiB

  1. using System.Net;
  2. using System;
  3. using System.Collections.Generic;
  4. using Independentsoft.Exchange;
  5. using uri_import.FClasses;
  6. using Acumatica.Default_20_200_001.Model;
  7. using Acumatica.Manufacturing_21_200_001.Model;
  8. namespace uri_import.EClasses
  9. {
  10. public class Ex365
  11. {
  12. private NetworkCredential _credential;
  13. private Service _service;
  14. private StandardFolder _folder;
  15. public NetworkCredential Credential { get { return _credential; } set { _credential = value; } }
  16. public Service service { get { return _service; } set { _service = value; } }
  17. public StandardFolder Folder { get { return _folder; } set { _folder = value; } }
  18. public Ex365() { }
  19. public Ex365(string username, string password)
  20. {
  21. _credential = new NetworkCredential(username, password);
  22. _service = new Service(Program.Cmn.Email.Url, _credential);
  23. }
  24. public Ex365(string username, string password, string url)
  25. {
  26. _credential = new NetworkCredential(username, password);
  27. _service = new Service(url, _credential);
  28. }
  29. public Ex365(string username, string password, string url, StandardFolder folder)
  30. {
  31. _credential = new NetworkCredential(username, password);
  32. _service = new Service(url, _credential);
  33. Folder inbox = _service.GetFolder(folder);
  34. }
  35. public List<EmailAttachment> GetPOs(string filter, bool hasAttachment = true)
  36. {
  37. int index = 1;
  38. List<EmailAttachment> list = new List<EmailAttachment>();
  39. IsEqualTo restriction = new IsEqualTo(MessagePropertyPath.HasAttachments, hasAttachment);
  40. Contains subFilter = new Contains(MessagePropertyPath.Subject, Program.Cmn.Email.Filter, ContainmentMode.Prefixed, ContainmentComparison.IgnoreCase);
  41. ItemShape itemShape = new ItemShape(ShapeType.Id);
  42. FindItemResponse response = _service.FindItem(StandardFolder.Inbox, itemShape, subFilter);
  43. for (int i = 0; i < response.Items.Count; i++)
  44. {
  45. if (response.Items[i] is Message)
  46. {
  47. ItemId itemId = response.Items[i].ItemId;
  48. Message message = service.GetMessage(itemId);
  49. Console.WriteLine(message.Subject);
  50. IList<AttachmentInfo> attachmentsInfo = message.Attachments;
  51. for (int j = 0; j < attachmentsInfo.Count; j++)
  52. {
  53. Attachment attachment = _service.GetAttachment(attachmentsInfo[j].Id);
  54. if (attachment is FileAttachment && attachment.Name.ToUpper().EndsWith(".PDF"))
  55. {
  56. EmailAttachment ea = new EmailAttachment();
  57. FileAttachment fileAttachment = (FileAttachment)attachment;
  58. ea.Content = fileAttachment.Content;
  59. ea.FileName = fileAttachment.Name.ToUpper().Replace(".PDF", string.Format("{0}.PDF", index));
  60. index = index + 1;
  61. ea.Sender = message.From.EmailAddress;
  62. list.Add(ea);
  63. }
  64. }
  65. }
  66. }
  67. return list;
  68. }
  69. }
  70. public class EmailSettings
  71. {
  72. public string Username { get; set; }
  73. public string Password { get; set; }
  74. public string Url { get; set; }
  75. public StandardFolder Folder { get; set; }
  76. }
  77. public class EmailAttachment
  78. {
  79. private List<ProductionOrder> _productionOrders;
  80. private List<string> _errors;
  81. private bool _released = false;
  82. private bool _linked = false;
  83. public EmailAttachment()
  84. {
  85. _productionOrders = new List<ProductionOrder>();
  86. _errors = new List<string>();
  87. }
  88. public byte[] Content { get; set; }
  89. public string Sender { get; set; }
  90. public string FileName { get; set; }
  91. public string FilePath
  92. {
  93. get
  94. {
  95. string path = System.IO.Path.Combine(
  96. FileActions.ExecFile,
  97. "attachments",
  98. this.FileName);
  99. return path;
  100. }
  101. }
  102. public SalesOrder SalesOrder { get; set; }
  103. public string SalesOrderNumber { get; set; }
  104. public List<ProductionOrder> ProductionOrders { get { return _productionOrders; } set { _productionOrders = value; } }
  105. public bool Released { get { return _released; } set { _released = value; } }
  106. public bool Linked { get { return _linked; } set { _linked = value; } }
  107. public List<string> Errors { get { return _errors; } set { _errors = value; } }
  108. }
  109. }