Don't like ads? PRO users don't see any ads ;-)
Guest

mickvdv

By: a guest on Jun 3rd, 2009  |  syntax: C#  |  size: 2.39 KB  |  hits: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4. using MySql.Data.MySqlClient;
  5. using System.Threading;
  6.  
  7.  
  8. namespace MySQLChecker
  9. {
  10.         class MainClass
  11.         {      
  12.                 public static void Main(string[] args)
  13.                 {
  14.  
  15.  
  16.                         // LAAD DE CONFIG FILE
  17.                         StreamReader file = new StreamReader("/home/mickvdv/Projects/MySQL-Checker/MySQL-Checker/configfile.cfg");
  18.                        
  19.                         string line = file.ReadLine();
  20.                         string server = line.Replace("server = ", "");
  21.                        
  22.                         line = file.ReadLine();
  23.                         string database = line.Replace("database = ", "");
  24.                        
  25.                         line = file.ReadLine();
  26.                         string user = line.Replace("user = ", "");
  27.                          
  28.                         line = file.ReadLine();
  29.                         string password = line.Replace("password = ", "");
  30.                        
  31.                         line = file.ReadLine();
  32.                         string table = line.Replace("table = ", "");
  33.                        
  34.                        
  35.                         // debug!!
  36.                         //string text = server +" "+ database +" "+ user +" "+password+" "+table;
  37.                         //MessageBox.Show(text);
  38.                        
  39.                         // LAAD DE OUDE WAARDE
  40.                         file = new StreamReader("/home/mickvdv/Projects/MySQL-Checker/MySQL-Checker/oldvalue.tmp");
  41.                         line = file.ReadLine();
  42.                         int oldValue = Convert.ToInt16(line);
  43.                         int n = oldValue;
  44.                        
  45.                        
  46.                         //Debug!!
  47.                         //text = Convert.ToString(oldValue);
  48.                         //MessageBox.Show(text);
  49.                        
  50.                        
  51.                        
  52.                         // VERBIND MET MYSQL
  53.                         string MyConString = "SERVER="+server+";" +"DATABASE="+database+";" +"UID="+user+";" +"PASSWORD="+password+";";
  54.                         MySqlConnection connection = new MySqlConnection(MyConString);
  55.                         MySqlCommand command = connection.CreateCommand();
  56.                         MySqlDataReader Reader;
  57.                        
  58.                         string output;
  59.                        
  60.                         // Temporairly
  61.                         string outputText = "Succesfully STARTED MySQL CHECKER";
  62.                         MessageBox.Show(outputText, "SUCCES",
  63.                                                 MessageBoxButtons.OK,
  64.                             MessageBoxIcon.Information);
  65.                         Form form1 = new Form();
  66.                         form1.Show();
  67.                         form1.Hide();
  68.  
  69.                         while (true)
  70.                         {
  71.                                 command.CommandText = "select count(*) from "+table;
  72.                                 connection.Open();
  73.                                 Reader = command.ExecuteReader();
  74.                                 Reader.Read();
  75.                                
  76.                                 output = Reader.GetValue(0).ToString();
  77.                                 n = Convert.ToInt16(output);
  78.                                 if (n > oldValue){
  79.                                        
  80.                                         MessageBox.Show(Convert.ToString(n), "New Table Entry",
  81.                                                 MessageBoxButtons.OK,
  82.                             MessageBoxIcon.Information);
  83.                                         form1.Show();
  84.                                         form1.Hide();
  85.                                         oldValue = n;
  86.                                 }
  87.                                
  88.                                 connection.Close();
  89.                                 Thread.Sleep(100);
  90.                         }
  91.                        
  92.                        
  93.                 }
  94.                        
  95.         }
  96. }