| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Mail;
- using System.Net.Mime;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- 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
- /// <summary>
- /// Point d'entrée principal de l'application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- debug = (Environment.MachineName == "PCPAT");
- var culture = CultureInfo.GetCultureInfo("en-US");
- // this may fail sometimes: (see Drachenkatze's comment below)
- // var culture = new CultureInfo("en-US");
- //Culture for any thread
- CultureInfo.DefaultThreadCurrentCulture = culture;
- //Culture for UI in any thread
- CultureInfo.DefaultThreadCurrentUICulture = culture;
- 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);
-
- var seps = new Char[] { ',', ';' };
- string[] emails = toEmail.Split(seps);
- 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);
- 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);
- 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);
- }
- }
- }
- }
- }
|