Program.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. string[] emails = toEmail.Split(new Char[] { ',', ';' });
  45. for (int i = 0; i < emails.Length; i++)
  46. message.To.Add(new MailAddress(emails[i]));
  47. message.Subject = subject;
  48. ContentType ct = new ContentType();
  49. ct.MediaType = MediaTypeNames.Application.Octet;
  50. if (pj != null)
  51. {
  52. Attachment att = new Attachment(pj, ct);
  53. ContentDisposition cd = att.ContentDisposition;
  54. cd.FileName = pj.Substring(pj.LastIndexOf(@"\") + 1);
  55. //cd.FileName = "Traces_Erreurs_Race_Mngt.txt";
  56. message.Attachments.Add(att);
  57. }
  58. message.Body = body;
  59. message.IsBodyHtml = false;
  60. SmtpClient smtp = null;
  61. smtp = new SmtpClient(smtpsrv);
  62. smtp.Credentials = new NetworkCredential(fromEmail, passwd);
  63. smtp.EnableSsl = false;
  64. smtp.Port = 587;
  65. smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
  66. smtp.Send(message);
  67. //MessageBox.Show("Un E-mail décrivant le problème a été envoyé.\r\n Nous cherchons à corriger l'erreur rencontrée.", "Gestion des erreurs");
  68. return true;
  69. }
  70. catch (Exception ex)
  71. {
  72. MessageBox.Show(ex.Message, "E-Mail");
  73. return false;
  74. }
  75. }
  76. public static DialogResult ShowInputDialog(string title,string message,ref string input,bool hidden)
  77. {
  78. System.Drawing.Size size = new System.Drawing.Size(220, 70 + 25 );
  79. Form inputBox = new Form();
  80. inputBox.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  81. inputBox.ClientSize = size;
  82. inputBox.StartPosition = FormStartPosition.CenterParent;
  83. inputBox.Text = title;
  84. System.Windows.Forms.Label label = new Label();
  85. label.Size = new System.Drawing.Size(size.Width - 10, 23);
  86. label.Location = new System.Drawing.Point(5, 5);
  87. label.Text = message;
  88. inputBox.Controls.Add(label);
  89. System.Windows.Forms.TextBox textBox = new TextBox();
  90. textBox.Size = new System.Drawing.Size(size.Width - 10, 23);
  91. textBox.Location = new System.Drawing.Point(5, 5 + 25 );
  92. textBox.Text = input;
  93. if ( hidden) textBox.PasswordChar = '*';
  94. inputBox.Controls.Add(textBox);
  95. Button okButton = new Button();
  96. okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  97. okButton.Name = "okButton";
  98. okButton.Size = new System.Drawing.Size(95, 23);
  99. okButton.Text = "&OK";
  100. okButton.Location = new System.Drawing.Point(5 , 39 +25 );
  101. inputBox.Controls.Add(okButton);
  102. Button cancelButton = new Button();
  103. cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  104. cancelButton.Name = "cancelButton";
  105. cancelButton.Size = new System.Drawing.Size(75, 23);
  106. cancelButton.Text = "&Cancel";
  107. cancelButton.Location = new System.Drawing.Point(5 + 95 + 10 , 39 + 25);
  108. inputBox.Controls.Add(cancelButton);
  109. inputBox.AcceptButton = okButton;
  110. inputBox.CancelButton = cancelButton;
  111. DialogResult result = inputBox.ShowDialog();
  112. input = textBox.Text;
  113. return result;
  114. }
  115. public static void traces(string fic,string datas)
  116. {
  117. bool done = false;
  118. int retry = 0;
  119. while (!done && retry < 5)
  120. {
  121. try
  122. {
  123. File.AppendAllText(fic, datas + "\r\n");
  124. done = true;
  125. }
  126. catch (Exception ex)
  127. {
  128. datas += ( "\r\n Retry " + retry++.ToString() + " Ex:" + ex.Message );
  129. }
  130. }
  131. }
  132. }
  133. }