Click here to Skip to main content
15,893,814 members
Articles / Programming Languages / SQL

SQL Editor for Database Developers

Rate me:
Please Sign up or sign in to vote.
4.55/5 (65 votes)
10 Mar 2010GPL317 min read 251.9K   9K   236  
SQL editor with syntax parser, direct editing, code execution, database backup, table comparison, script generation, time measurement
/*
SqlBuilder - an intelligent database tool
 
This file is part of SqlBuilder.
www.netcult.ch/elmue

This program is free software; you can redistribute it and/or modify it 
under the terms of the GNU General Public License as published by the 
Free Software Foundation; either version 2 of the License, or 
(at your option) any later version. 
 
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
GNU General Public License for more details. 
 
You find the GNU General Public License in the subfolder GNU
if not, write to the Free Software Foundation, 
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/


using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Diagnostics;
using SqlBuilder.Forms;

namespace SqlBuilder
{
	/// <summary>
	/// Checks for a new version on the update server and displays a messagebox
	/// An updatecheck happens only once every X days (Defaults.UpdateInterval)
	/// </summary>
	public class UpdateCheck
	{
		int ms32_Today;

		public UpdateCheck()
		{
			// Get a value which increments every day (days which elapsed since 01.Jan.0001)
			// Convert nanoseconds -> days:          /micro/milli / sec  /min /hour/day
			ms32_Today   = (int)(DateTime.Today.Ticks / 10 / 1000 / 1000 / 60 / 60 / 24);
			int s32_Last = (int)Functions.RegistryRead(eReg.Main,"LastUpdateCheck", 0);

			if (s32_Last + Defaults.UpdateInterval <= ms32_Today)
			{
				Thread i_Thread = new Thread(new ThreadStart(WorkThread));
				i_Thread.Start();
			}
		}

		private void WorkThread()
		{
			try
			{
				string s_Version = GetLatestVersion();
				if (s_Version != Defaults.Version)
				{
					if (frmMsgBox.Ask(frmMain.Instance, "SqlBuilder version "+s_Version+" is available on the server.\nDo you want to download the latest version?"))
						Functions.OpenFile(frmMain.Instance, Defaults.DownloadUrl, ProcessWindowStyle.Normal);
				}
				
				// If success --> write date to XML file
				Functions.RegistryWrite(eReg.Main,"LastUpdateCheck", ms32_Today);
			}
			catch {}
		}

		/// <summary>
		/// Reads the text file from the server which contains the version string e.g. "4.1"
		/// </summary>
		public string GetLatestVersion()
		{
			WebRequest i_Request = WebRequest.Create(Defaults.UpdateUrl);
			i_Request.Method = "GET";
			WebResponse  i_Response = i_Request.GetResponse();
			StreamReader i_Reader   = new StreamReader(i_Response.GetResponseStream());
			return i_Reader.ReadToEnd();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior) ElmüSoft
Chile Chile
Software Engineer since 40 years.

Comments and Discussions