Soyez le premier à donner votre avis sur cette source.
Snippet vu 15 656 fois - Téléchargée 32 fois
using System; using System.Windows.Forms; using System.IO; using System.Diagnostics; namespace DefaultNamespace { /// <summary> /// Description of MainForm. /// </summary> public class MainForm : System.Windows.Forms.Form { private System.Windows.Forms.TextBox txtSQL; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button cmdReset; private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox txtUser; private System.Windows.Forms.Button cmdCreer; public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } #region Windows Forms Designer generated code /// <summary> /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might /// not be able to load this method if it was changed manually. /// </summary> private void InitializeComponent() { this.cmdCreer = new System.Windows.Forms.Button(); this.txtUser = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); this.cmdReset = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); this.txtSQL = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // cmdCreer // this.cmdCreer.Location = new System.Drawing.Point(408, 240); this.cmdCreer.Name = "cmdCreer"; this.cmdCreer.TabIndex = 7; this.cmdCreer.Text = "&Créer"; this.cmdCreer.Click += new System.EventHandler(this.CmdCreerClick); // // txtUser // this.txtUser.Location = new System.Drawing.Point(104, 8); this.txtUser.Name = "txtUser"; this.txtUser.Size = new System.Drawing.Size(160, 20); this.txtUser.TabIndex = 3; this.txtUser.Text = ""; this.txtUser.WordWrap = false; // // label3 // this.label3.Location = new System.Drawing.Point(8, 8); this.label3.Name = "label3"; this.label3.TabIndex = 2; this.label3.Text = "Utilisateur :"; // // cmdReset // this.cmdReset.Location = new System.Drawing.Point(328, 240); this.cmdReset.Name = "cmdReset"; this.cmdReset.TabIndex = 8; this.cmdReset.Text = "&Reset"; this.cmdReset.Click += new System.EventHandler(this.CmdResetClick); // // label2 // this.label2.Location = new System.Drawing.Point(8, 32); this.label2.Name = "label2"; this.label2.TabIndex = 6; this.label2.Text = "Requêtes :"; // // txtSQL // this.txtSQL.Location = new System.Drawing.Point(8, 56); this.txtSQL.Multiline = true; this.txtSQL.Name = "txtSQL"; this.txtSQL.Size = new System.Drawing.Size(472, 176); this.txtSQL.TabIndex = 5; this.txtSQL.Text = ""; // // MainForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(488, 270); this.Controls.Add(this.cmdReset); this.Controls.Add(this.cmdCreer); this.Controls.Add(this.label2); this.Controls.Add(this.txtSQL); this.Controls.Add(this.txtUser); this.Controls.Add(this.label3); this.Location = new System.Drawing.Point(-21, 0); this.Name = "MainForm"; this.Text = "MainForm"; this.Load += new System.EventHandler(this.MainFormLoad); this.ResumeLayout(false); } #endregion void MainFormLoad(object sender, System.EventArgs e) { this.folderBrowserDialog.Description = "Sélectionnez le répertoire où vous désirez enregistrer les fichiers.\n(Conseil : mettez les dans un répertoire à eux pour les retrouver plus facilement.)"; } void CmdCreerClick(object sender, System.EventArgs e) { string sFichierBatch; string sFichierSQL; string sCommande; if((this.txtUser.Text != "") && (this.txtSQL.Text!="")) { if((this.folderBrowserDialog.ShowDialog() == DialogResult.OK)&&((MessageBox.Show("Si des fichiers ont déjà été créés à cet emplacement, ils seront perdus.\nEtes-vous sûr de vouloir sélectionner ce dossier ?","Attention",MessageBoxButtons.YesNo, MessageBoxIcon.Hand)) == DialogResult.Yes)) { string sChemin = this.folderBrowserDialog.SelectedPath ; if(sChemin[sChemin.Length-1].ToString() != "\\") sChemin += "\\"; sFichierBatch = sChemin + "Executable.bat"; sFichierSQL = sChemin + "Requete.sql"; StreamWriter fBatch = File.CreateText(sFichierBatch); StreamWriter fSQL = File.CreateText(sFichierSQL); sCommande = "mysql -u " + this.txtUser.Text + " -p < Requete.sql"; fBatch.WriteLine(sCommande); fBatch.Close(); fSQL.Write(this.txtSQL.Text); fSQL.Close(); if(MessageBox.Show("Création des fichiers terminée.\nVoulez vous exécuter les requêtes maintenant ?","Création terminée",MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Process pBatch = new Process(); pBatch.StartInfo = new ProcessStartInfo(); pBatch.StartInfo.FileName = sFichierBatch; pBatch.Start(); } } } else MessageBox.Show("Vous devez saisir un nom d'utilisateur (enregistré dans MySQL avec les droits nécessaires de préférence) et des requêtes à exécutées !","Erreur de saisie",MessageBoxButtons.OK, MessageBoxIcon.Error); } void CmdResetClick(object sender, System.EventArgs e) { if(MessageBox.Show("Etes-vous sûr de vouloir effacer tous les champs ?","Confirmation",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes) { this.txtUser.Text = ""; this.txtSQL.Text = ""; } } } }
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.