Program.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Mail;
  6. using System.Net.Mime;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. namespace Fuel01
  11. {
  12. static class Program
  13. {
  14. #pragma warning disable S2223 // Non-constant static fields should not be visible
  15. public static int site = 1;
  16. public static string auteur = "Test";
  17. public static bool okSignalR = false;
  18. public static string key_sta = "";
  19. public static string key_ope = "";
  20. public static string abrev_ope = "";
  21. public static string nom_ope = "";
  22. public static string folder = "";
  23. public static string subfolder = "";
  24. public static bool debug = false;
  25. public static bool isExcel = false;
  26. #pragma warning restore S2223 // Non-constant static fields should not be visible
  27. /// <summary>
  28. /// Point d'entrée principal de l'application.
  29. /// </summary>
  30. [STAThread]
  31. static void Main()
  32. {
  33. debug = (Environment.MachineName == "PCPAT");
  34. Application.EnableVisualStyles();
  35. Application.SetCompatibleTextRenderingDefault(false);
  36. Application.Run(new Main());
  37. }
  38. public static bool sendMail(string fromEmail, string passwd, string smtpsrv, string toEmail, string subject, string body, string pj)
  39. {
  40. try
  41. {
  42. MailMessage message = new MailMessage();
  43. message.From = new MailAddress(fromEmail);
  44. var seps = new Char[] { ',', ';' };
  45. string[] emails = toEmail.Split(seps);
  46. for (int i = 0; i < emails.Length; i++)
  47. {
  48. message.To.Add(new MailAddress(emails[i]));
  49. }
  50. message.Subject = subject;
  51. ContentType ct = new ContentType();
  52. ct.MediaType = MediaTypeNames.Application.Octet;
  53. if (pj != null)
  54. {
  55. Attachment att = new Attachment(pj, ct);
  56. ContentDisposition cd = att.ContentDisposition;
  57. cd.FileName = pj.Substring(pj.LastIndexOf(@"\") + 1);
  58. message.Attachments.Add(att);
  59. }
  60. message.Body = body;
  61. message.IsBodyHtml = false;
  62. SmtpClient smtp = null;
  63. smtp = new SmtpClient(smtpsrv);
  64. smtp.Credentials = new NetworkCredential(fromEmail, passwd);
  65. smtp.EnableSsl = false;
  66. smtp.Port = 587;
  67. smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
  68. smtp.Send(message);
  69. return true;
  70. }
  71. catch (Exception ex)
  72. {
  73. MessageBox.Show(ex.Message, "E-Mail");
  74. return false;
  75. }
  76. }
  77. public static DialogResult ShowInputDialog(string title, string message, ref string input, bool hidden)
  78. {
  79. System.Drawing.Size size = new System.Drawing.Size(220, 70 + 25);
  80. Form inputBox = new Form();
  81. inputBox.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  82. inputBox.ClientSize = size;
  83. inputBox.StartPosition = FormStartPosition.CenterParent;
  84. inputBox.Text = title;
  85. System.Windows.Forms.Label label = new Label();
  86. label.Size = new System.Drawing.Size(size.Width - 10, 23);
  87. label.Location = new System.Drawing.Point(5, 5);
  88. label.Text = message;
  89. inputBox.Controls.Add(label);
  90. System.Windows.Forms.TextBox textBox = new TextBox();
  91. textBox.Size = new System.Drawing.Size(size.Width - 10, 23);
  92. textBox.Location = new System.Drawing.Point(5, 5 + 25);
  93. textBox.Text = input;
  94. if (hidden) textBox.PasswordChar = '*';
  95. inputBox.Controls.Add(textBox);
  96. Button okButton = new Button();
  97. okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  98. okButton.Name = "okButton";
  99. okButton.Size = new System.Drawing.Size(95, 23);
  100. okButton.Text = "&OK";
  101. okButton.Location = new System.Drawing.Point(5, 39 + 25);
  102. inputBox.Controls.Add(okButton);
  103. Button cancelButton = new Button();
  104. cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  105. cancelButton.Name = "cancelButton";
  106. cancelButton.Size = new System.Drawing.Size(75, 23);
  107. cancelButton.Text = "&Cancel";
  108. cancelButton.Location = new System.Drawing.Point(5 + 95 + 10, 39 + 25);
  109. inputBox.Controls.Add(cancelButton);
  110. inputBox.AcceptButton = okButton;
  111. inputBox.CancelButton = cancelButton;
  112. DialogResult result = inputBox.ShowDialog();
  113. input = textBox.Text;
  114. return result;
  115. }
  116. public static void traces(string fic, string datas)
  117. {
  118. bool done = false;
  119. int retry = 0;
  120. while (!done && retry < 5)
  121. {
  122. try
  123. {
  124. File.AppendAllText(fic, datas + "\r\n");
  125. done = true;
  126. }
  127. catch (Exception ex)
  128. {
  129. datas += ("\r\n Retry " + retry++.ToString() + " Ex:" + ex.Message);
  130. }
  131. }
  132. }
  133. }
  134. }