using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Mail; using System.Net.Mime; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace Fuel01 { static class Program { #pragma warning disable S2223 // Non-constant static fields should not be visible public static int site = 1; public static string auteur = "Test"; public static bool okSignalR = false; public static string key_sta=""; public static string key_ope=""; public static string abrev_ope=""; public static string nom_ope=""; public static string folder = ""; public static string subfolder = ""; public static bool debug = false; public static bool isExcel= false; #pragma warning restore S2223 // Non-constant static fields should not be visible /// /// Point d'entrée principal de l'application. /// [STAThread] static void Main() { debug = ( Environment.MachineName=="PCPAT"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Main()); } public static bool sendMail(string fromEmail, string passwd, string smtpsrv, string toEmail, string subject, string body, string pj) { try { MailMessage message = new MailMessage(); message.From = new MailAddress(fromEmail); string[] emails = toEmail.Split(new Char[] { ',', ';' }); for (int i = 0; i < emails.Length; i++) message.To.Add(new MailAddress(emails[i])); message.Subject = subject; ContentType ct = new ContentType(); ct.MediaType = MediaTypeNames.Application.Octet; if (pj != null) { Attachment att = new Attachment(pj, ct); ContentDisposition cd = att.ContentDisposition; cd.FileName = pj.Substring(pj.LastIndexOf(@"\") + 1); //cd.FileName = "Traces_Erreurs_Race_Mngt.txt"; message.Attachments.Add(att); } message.Body = body; message.IsBodyHtml = false; SmtpClient smtp = null; smtp = new SmtpClient(smtpsrv); smtp.Credentials = new NetworkCredential(fromEmail, passwd); smtp.EnableSsl = false; smtp.Port = 587; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(message); //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"); return true; } catch (Exception ex) { MessageBox.Show(ex.Message, "E-Mail"); return false; } } public static DialogResult ShowInputDialog(string title,string message,ref string input,bool hidden) { System.Drawing.Size size = new System.Drawing.Size(220, 70 + 25 ); Form inputBox = new Form(); inputBox.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; inputBox.ClientSize = size; inputBox.StartPosition = FormStartPosition.CenterParent; inputBox.Text = title; System.Windows.Forms.Label label = new Label(); label.Size = new System.Drawing.Size(size.Width - 10, 23); label.Location = new System.Drawing.Point(5, 5); label.Text = message; inputBox.Controls.Add(label); System.Windows.Forms.TextBox textBox = new TextBox(); textBox.Size = new System.Drawing.Size(size.Width - 10, 23); textBox.Location = new System.Drawing.Point(5, 5 + 25 ); textBox.Text = input; if ( hidden) textBox.PasswordChar = '*'; inputBox.Controls.Add(textBox); Button okButton = new Button(); okButton.DialogResult = System.Windows.Forms.DialogResult.OK; okButton.Name = "okButton"; okButton.Size = new System.Drawing.Size(95, 23); okButton.Text = "&OK"; okButton.Location = new System.Drawing.Point(5 , 39 +25 ); inputBox.Controls.Add(okButton); Button cancelButton = new Button(); cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; cancelButton.Name = "cancelButton"; cancelButton.Size = new System.Drawing.Size(75, 23); cancelButton.Text = "&Cancel"; cancelButton.Location = new System.Drawing.Point(5 + 95 + 10 , 39 + 25); inputBox.Controls.Add(cancelButton); inputBox.AcceptButton = okButton; inputBox.CancelButton = cancelButton; DialogResult result = inputBox.ShowDialog(); input = textBox.Text; return result; } public static void traces(string fic,string datas) { bool done = false; int retry = 0; while (!done && retry < 5) { try { File.AppendAllText(fic, datas + "\r\n"); done = true; } catch (Exception ex) { datas += ( "\r\n Retry " + retry++.ToString() + " Ex:" + ex.Message ); } } } } }