Advertisement
Guest User

Untitled

a guest
May 7th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  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.             // LAAD DE CONFIG FILE
  15.             StreamReader file = new StreamReader("/home/mickvdv/Projects/MySQL-Checker/MySQL-Checker/configfile.cfg");
  16.            
  17.             string line = file.ReadLine();
  18.             string server = line.Replace("server = ", "");
  19.            
  20.             line = file.ReadLine();
  21.             string database = line.Replace("database = ", "");
  22.            
  23.             line = file.ReadLine();
  24.             string user = line.Replace("user = ", "");
  25.              
  26.             line = file.ReadLine();
  27.             string password = line.Replace("password = ", "");
  28.            
  29.             line = file.ReadLine();
  30.             string table = line.Replace("table = ", "");
  31.            
  32.            
  33.             // debug!!
  34.             //string text = server +" "+ database +" "+ user +" "+password+" "+table;
  35.             //MessageBox.Show(text);
  36.            
  37.             // LAAD DE OUDE WAARDE
  38.             file = new StreamReader("/home/mickvdv/Projects/MySQL-Checker/MySQL-Checker/oldvalue.tmp");
  39.             line = file.ReadLine();
  40.             int oldValue = Convert.ToInt16(line);
  41.             int n = oldValue;
  42.            
  43.            
  44.             //Debug!!
  45.             //text = Convert.ToString(oldValue);
  46.             //MessageBox.Show(text);
  47.            
  48.            
  49.            
  50.             // VERBIND MET MYSQL
  51.             string MyConString = "SERVER="+server+";" +"DATABASE="+database+";" +"UID="+user+";" +"PASSWORD="+password+";";
  52.             MySqlConnection connection = new MySqlConnection(MyConString);
  53.             MySqlCommand command = connection.CreateCommand();
  54.             MySqlDataReader Reader;
  55.             string output;
  56.            
  57.             // Temporairly
  58.             string outputText = "Succesfully STARTED MySQL CHECKER";
  59.             MessageBox.Show(outputText, "SUCCES",
  60.                             MessageBoxButtons.OK,
  61.                             MessageBoxIcon.Information);
  62.            
  63.  
  64.    
  65.            
  66.  
  67.             while (true)
  68.             {
  69.                 command.CommandText = "select count(*) from "+table;
  70.                 connection.Open();
  71.                 Reader = command.ExecuteReader();
  72.                 Reader.Read();
  73.                
  74.                 output = Reader.GetValue(0).ToString();
  75.                 n = Convert.ToInt16(output);
  76.                 if (n > oldValue){
  77.                    
  78.                     MessageBox.Show(Convert.ToString(n), "New Table Entry",
  79.                             MessageBoxButtons.OK,
  80.                             MessageBoxIcon.Information);
  81.                     oldValue = n;
  82.                 }
  83.                
  84.                
  85.                 connection.Close();
  86.                 //Thread.Sleep(10000);
  87.             }
  88.            
  89.            
  90.         }
  91.            
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement