Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members

frmSendComm.cs

Go to the documentation of this file.
00001 /*
00002 SimImmuno version 1.0
00003 Copyright (C) 2005 sebeuh.ajsinfo.net
00004 
00005 SimImmuno est libre, vous pouvez le redistribuer et/ou le modifier
00006 selon les termes de la Licence Publique Générale GNU publiée par la
00007 Free Software Foundation (version 2).
00008 
00009 SimImmuno est distribué car potentiellement utile, mais SANS AUCUNE GARANTIE,
00010 ni explicite ni implicite, y compris les garanties de commercialisation
00011 ou d'adaptation dans un but spécifique. Reportez-vous à la
00012 Licence Publique Générale GNU pour plus de détails.
00013 
00014 Texte de la license officielle (anglais) :
00015 http://simimmuno.ajsinfo.net/text.aspx?code=no&txt_file=GPL.txt
00016 Traduction francaise (non-officielle) :
00017 http://simimmuno.ajsinfo.net/text.aspx?code=no&txt_file=GPL-fr.txt
00018 */
00019 using System;
00020 using System.Drawing;
00021 using System.Collections;
00022 using System.ComponentModel;
00023 using System.Windows.Forms;
00024 using System.Web.Mail;
00025 using System.Management;
00026 using System.Reflection;
00027 using System.Net;
00028 
00029 namespace SimImmuno
00030 {
00031         public class frmSendComm : System.Windows.Forms.Form
00032         {
00033                 #region Déclaration et Initialisation
00034                 private System.Windows.Forms.Button button1;
00035                 private System.Windows.Forms.Label label1;
00036                 private System.Windows.Forms.Label label2;
00037                 private System.Windows.Forms.Label label3;
00038                 private System.Windows.Forms.Label label4;
00039                 private System.Windows.Forms.TextBox txtNom;
00040                 private System.Windows.Forms.TextBox txtEmail;
00041                 private System.Windows.Forms.TextBox txtMessage;
00042                 private System.Windows.Forms.Button button2;
00043                 private System.ComponentModel.Container components = null;
00044 
00045                 public frmSendComm()
00046                 {
00047                         InitializeComponent();
00048                 }
00049                 #endregion
00050 
00051                 #region Fonctions de base .NET
00052                 protected override void Dispose( bool disposing )
00053                 {
00054                         if( disposing )
00055                         {
00056                                 if(components != null)
00057                                 {
00058                                         components.Dispose();
00059                                 }
00060                         }
00061                         base.Dispose( disposing );
00062                 }
00063 
00064                 #region Windows Form Designer generated code
00069                 private void InitializeComponent()
00070                 {
00071                         System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmSendComm));
00072                         this.button1 = new System.Windows.Forms.Button();
00073                         this.label1 = new System.Windows.Forms.Label();
00074                         this.label2 = new System.Windows.Forms.Label();
00075                         this.label3 = new System.Windows.Forms.Label();
00076                         this.label4 = new System.Windows.Forms.Label();
00077                         this.txtNom = new System.Windows.Forms.TextBox();
00078                         this.txtEmail = new System.Windows.Forms.TextBox();
00079                         this.txtMessage = new System.Windows.Forms.TextBox();
00080                         this.button2 = new System.Windows.Forms.Button();
00081                         this.SuspendLayout();
00082                         // 
00083                         // button1
00084                         // 
00085                         this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
00086                         this.button1.Location = new System.Drawing.Point(240, 224);
00087                         this.button1.Name = "button1";
00088                         this.button1.Size = new System.Drawing.Size(104, 24);
00089                         this.button1.TabIndex = 5;
00090                         this.button1.Text = "Fermer";
00091                         this.button1.Click += new System.EventHandler(this.button1_Click);
00092                         // 
00093                         // label1
00094                         // 
00095                         this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
00096                                 | System.Windows.Forms.AnchorStyles.Right)));
00097                         this.label1.Location = new System.Drawing.Point(8, 5);
00098                         this.label1.Name = "label1";
00099                         this.label1.Size = new System.Drawing.Size(352, 40);
00100                         this.label1.TabIndex = 1;
00101                         this.label1.Text = "Servez-vous de cette fenêtre pour m\'envoyer directement un message  pour toutes r" +
00102                                 "emarques, bugs, critiques, idées ou sugestions.";
00103                         // 
00104                         // label2
00105                         // 
00106                         this.label2.Location = new System.Drawing.Point(8, 56);
00107                         this.label2.Name = "label2";
00108                         this.label2.Size = new System.Drawing.Size(112, 16);
00109                         this.label2.TabIndex = 2;
00110                         this.label2.Text = "Votre nom :";
00111                         // 
00112                         // label3
00113                         // 
00114                         this.label3.Location = new System.Drawing.Point(8, 80);
00115                         this.label3.Name = "label3";
00116                         this.label3.Size = new System.Drawing.Size(120, 16);
00117                         this.label3.TabIndex = 3;
00118                         this.label3.Text = "Votre email :";
00119                         // 
00120                         // label4
00121                         // 
00122                         this.label4.Location = new System.Drawing.Point(8, 104);
00123                         this.label4.Name = "label4";
00124                         this.label4.Size = new System.Drawing.Size(112, 16);
00125                         this.label4.TabIndex = 4;
00126                         this.label4.Text = "Votre message :";
00127                         // 
00128                         // txtNom
00129                         // 
00130                         this.txtNom.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
00131                                 | System.Windows.Forms.AnchorStyles.Left) 
00132                                 | System.Windows.Forms.AnchorStyles.Right)));
00133                         this.txtNom.Location = new System.Drawing.Point(96, 56);
00134                         this.txtNom.Name = "txtNom";
00135                         this.txtNom.Size = new System.Drawing.Size(184, 20);
00136                         this.txtNom.TabIndex = 0;
00137                         this.txtNom.Text = "";
00138                         // 
00139                         // txtEmail
00140                         // 
00141                         this.txtEmail.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
00142                                 | System.Windows.Forms.AnchorStyles.Left) 
00143                                 | System.Windows.Forms.AnchorStyles.Right)));
00144                         this.txtEmail.Location = new System.Drawing.Point(96, 80);
00145                         this.txtEmail.Name = "txtEmail";
00146                         this.txtEmail.Size = new System.Drawing.Size(184, 20);
00147                         this.txtEmail.TabIndex = 1;
00148                         this.txtEmail.Text = "";
00149                         // 
00150                         // txtMessage
00151                         // 
00152                         this.txtMessage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
00153                                 | System.Windows.Forms.AnchorStyles.Left) 
00154                                 | System.Windows.Forms.AnchorStyles.Right)));
00155                         this.txtMessage.Location = new System.Drawing.Point(96, 104);
00156                         this.txtMessage.Multiline = true;
00157                         this.txtMessage.Name = "txtMessage";
00158                         this.txtMessage.ScrollBars = System.Windows.Forms.ScrollBars.Both;
00159                         this.txtMessage.Size = new System.Drawing.Size(264, 112);
00160                         this.txtMessage.TabIndex = 3;
00161                         this.txtMessage.Text = "";
00162                         // 
00163                         // button2
00164                         // 
00165                         this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
00166                         this.button2.Location = new System.Drawing.Point(112, 224);
00167                         this.button2.Name = "button2";
00168                         this.button2.Size = new System.Drawing.Size(104, 24);
00169                         this.button2.TabIndex = 4;
00170                         this.button2.Text = "Envoyer";
00171                         this.button2.Click += new System.EventHandler(this.button2_Click);
00172                         // 
00173                         // frmSendComm
00174                         // 
00175                         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
00176                         this.ClientSize = new System.Drawing.Size(368, 253);
00177                         this.Controls.Add(this.button2);
00178                         this.Controls.Add(this.txtMessage);
00179                         this.Controls.Add(this.txtEmail);
00180                         this.Controls.Add(this.txtNom);
00181                         this.Controls.Add(this.label4);
00182                         this.Controls.Add(this.label3);
00183                         this.Controls.Add(this.label2);
00184                         this.Controls.Add(this.label1);
00185                         this.Controls.Add(this.button1);
00186                         this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
00187                         this.MaximizeBox = false;
00188                         this.Name = "frmSendComm";
00189                         this.ShowInTaskbar = false;
00190                         this.Text = "Envoyer un commentaire";
00191                         this.ResumeLayout(false);
00192 
00193                 }
00194                 #endregion
00195 
00196                 #endregion
00197 
00198                 #region Fonctions SendComm
00199 
00200                 private void button1_Click(object sender, System.EventArgs e)
00201                 {
00202                         //Fermer
00203                         this.Close();
00204                 }
00205 
00206                 private void button2_Click(object sender, System.EventArgs e)
00207                 {
00208                         // send mail
00209                         try
00210                         {
00211                                 if(ValidForm())
00212                                 {
00213                                         this.Text = "Envoi du message, merci de patienter....";
00214                                         button1.Enabled = false;
00215                                         button2.Enabled = false;
00216                                         string nom = txtNom.Text.ToString();
00217                                         string email = txtEmail.Text.ToString();
00218                                         string message_user = txtMessage.Text.ToString();
00219                                         string message_info = GenMsgInfo();
00220                                         string message_send = "Message de " + nom + ":\n\n" + message_user + "\n\n----------------------------------------------\n\nInformations:\n\n" + message_info;
00221                                         MailMessage mail = new MailMessage();
00222                                         mail.To = "sebeuh@ajsinfo.net";
00223                                         mail.From = email;
00224                                         mail.Subject = "MESSAGE SIMIMMUNO";
00225                                         mail.Body = message_send;
00226                                         SmtpMail.SmtpServer = "mail.ajsinfo.net";
00227                                         SmtpMail.Send(mail);
00228                                         button1.Enabled = true;
00229                                         this.Text = "Message envoyé";
00230                                         MessageBox.Show("Message envoyé.\nMerci....","SimImmuno",MessageBoxButtons.OK,MessageBoxIcon.Information);
00231                                 }
00232                         }
00233                         catch(Exception exx)
00234                         {
00235                                 this.Text = "Erreur lors de l'envoi du message !!";
00236                                 MessageBox.Show("Erreur: " + exx.Message.ToString(),"SimImmuno",MessageBoxButtons.OK,MessageBoxIcon.Error);
00237                                 button1.Enabled = true;
00238                                 button2.Enabled = true;
00239                                 button2.Text = "Réessayer";
00240                         }
00241                 }
00242 
00243                 private string GenMsgInfo()
00244                 {
00245                         Assembly myAppVer = Assembly.Load("simimmuno");
00246                         string SIversion = "SimImmuno version: " + myAppVer.GetName().Version.Major.ToString() + "." + myAppVer.GetName().Version.Minor.ToString() + " Revision " + myAppVer.GetName().Version.Revision.ToString() + " (Build : " + myAppVer.GetName().Version.Build.ToString() + ")";
00247                         string date = "Date: " + DateTime.Now.ToShortDateString().ToString() + " " + DateTime.Now.ToLongTimeString().ToString();
00248                         string net = "Réseau: " + SystemInformation.Network.ToString();
00249                         string domain = "Domaine: " + SystemInformation.UserDomainName .ToString();
00250                         string user = "Utilisateur: " + SystemInformation.UserName.ToString();
00251                         string resol = "Résolution: " + SystemInformation.WorkingArea.ToString();
00252                         ManagementObjectSearcher query1 = new  ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem") ;
00253                         ManagementObjectCollection queryCollection1 = query1.Get();
00254                         string name = "";
00255                         string ver = "";
00256                         string manu = "";
00257                         string comp_name = "";
00258                         string windir = "";
00259                         string model = "";
00260                         string systype = "";
00261                         string mem = "";
00262                         string proc = "";
00263                         string bios = "";
00264                         foreach( ManagementObject mo in queryCollection1 )
00265                         {
00266                                 name = "OS: " + mo["name"].ToString();
00267                                 ver = "OS Version: " + mo["version"].ToString();
00268                                 manu = "Fabriquant: " + mo["Manufacturer"].ToString();
00269                                 comp_name = "Nom du PC: " +mo["csname"].ToString();
00270                                 windir = "Répertoire Windows: " + mo["WindowsDirectory"].ToString();
00271                         }                 
00272 
00273                         query1 = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem") ;
00274                         queryCollection1 = query1.Get();
00275                         foreach( ManagementObject mo in queryCollection1 )
00276                         {
00277                                 manu = "Fabriquant: " + mo["manufacturer"].ToString();
00278                                 model = "Modèle: " + mo["model"].ToString();
00279                                 systype = "Type système: " + mo["systemtype"].ToString();
00280                                 mem = "Mémoire physique: " + mo["totalphysicalmemory"].ToString();
00281                         } 
00282 
00283                         query1 = new ManagementObjectSearcher("SELECT * FROM Win32_processor") ;
00284                         queryCollection1 = query1.Get();
00285                         foreach( ManagementObject mo in queryCollection1 )
00286                         {
00287                                 proc = "Processeur: " + mo["caption"].ToString();
00288                         }                      
00289 
00290                         query1 = new ManagementObjectSearcher("SELECT * FROM Win32_bios") ;
00291                         queryCollection1 = query1.Get();
00292                         foreach( ManagementObject mo in queryCollection1 )
00293                         {
00294                                 bios = "BIOS: " + mo["version"].ToString();
00295                         }  
00296                         string strHostName = Dns.GetHostName();
00297                         string hostname = "Host Name: " + strHostName;
00298                         IPHostEntry iphostentry = Dns.GetHostByName(strHostName);
00299                         string listip = "IP(s): ";
00300                         foreach(IPAddress ipaddress in iphostentry.AddressList)
00301                         {
00302                                 listip = listip + "\n" + ipaddress.ToString();
00303                         }                                        
00304                         return SIversion + "\n" + date + "\n" + net + "\n" + domain + "\n" + user + "\n" + resol + "\n" + name + "\n" + ver + "\n" + manu + "\n" + comp_name + "\n" + windir + "\n" + model + "\n" + systype + "\n" + mem + "\n" + proc + "\n" + bios + "\n" + hostname + "\n" + listip;
00305                 }
00306 
00307                 private bool ValidForm()
00308                 {
00309                         if (txtNom.Text.Length == 0)
00310                         {
00311                                 MessageBox.Show("Erreur: champ 'nom' vide !","SimImmuno",MessageBoxButtons.OK,MessageBoxIcon.Error);
00312                                 return false;
00313                         }
00314 
00315                         if (txtMessage.Text.Length == 0)
00316                         {
00317                                 MessageBox.Show("Erreur: champ 'message' vide !","SimImmuno",MessageBoxButtons.OK,MessageBoxIcon.Error);
00318                                 return false;
00319                         }
00320 
00321                         if (txtEmail.Text.Length == 0)
00322                         {
00323                                 MessageBox.Show("Erreur: champ 'email' vide !","SimImmuno",MessageBoxButtons.OK,MessageBoxIcon.Error);
00324                                 return false;
00325                         }
00326                         else
00327                         {
00328                                 System.Text.RegularExpressions.Regex emailReg = 
00329                                         new System.Text.RegularExpressions.Regex(
00330                                         @"^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$", 
00331                                         System.Text.RegularExpressions.RegexOptions.CultureInvariant);
00332                                 System.Text.RegularExpressions.MatchCollection results = 
00333                                         emailReg.Matches(txtEmail.Text, 0);
00334                                 
00335                                 if (results.Count == 0)
00336                                 {
00337                                         MessageBox.Show("Erreur: champ 'email' incorrecte !","SimImmuno",MessageBoxButtons.OK,MessageBoxIcon.Error);
00338                                         return false;
00339                                 }
00340                         }
00341                         return true;
00342                 }
00343 
00344                 #endregion
00345         }
00346 }

Generated on Sat Jun 4 15:03:41 2005 for SimImmuno by  doxygen 1.4.2