using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WallboardEmail
{
public static class ModMain
{
public static GlobalArgumentsStructure GlobalArguments = new GlobalArgumentsStructure();
public static void Main(string[] pArgs) //pass argument from command line by using the parameter
{
GetCommandLineArgs(pArgs);
StartApplication();
}
#region methods
private static void StartApplication()
{
if (GlobalArguments.DisplayArgs)
{
//do something here
Application.Exit();
}
else if (GlobalArguments.BatchMode)
{
//Launch a process that has no UI
//send email //same cProcess in orig code
Log.LogTrace("This line was added by a batch process. Email Sent");
}
else
{
//Launch the UI
Form1 form = new Form1();
Application.Run(form);
}
}
private static void GetCommandLineArgs(string[] pArgs)
{
//If no arguments are passed to the application, short-circuit the process
if ((pArgs.Length == 0))
{
GlobalArguments.DisplayArgs = true;
}
//Ensure all arguments are in upper case
for (Int32 intI = 0; intI <= pArgs.Length - 1; intI++)
{
pArgs[intI] = pArgs[intI].ToUpper();
}
//Search for expected arguments (all others being ignored)
var _with1 = GlobalArguments;
_with1.DisplayArgs = (Array.IndexOf(pArgs, "/?") >= 0);
_with1.BatchMode = (Array.IndexOf(pArgs, "/BATCH") >= 0);
if (Array.IndexOf(pArgs, "/ENV_DEV") >= 0)
{
_with1.Environment = GlobalArgumentsStructure.enuEnvironment.Dev;
}
else if (Array.IndexOf(pArgs, "/ENV_PRODUCTION") >= 0)
{
_with1.Environment = GlobalArgumentsStructure.enuEnvironment.Production;
}
else
{
_with1.Environment = GlobalArgumentsStructure.enuEnvironment.Dev;
}
}
#endregion
#region enum
public struct GlobalArgumentsStructure
{
public enum enuEnvironment
{
Unknown = 0,
Dev = 1,
Production = 3
}
public bool BatchMode;
public enuEnvironment Environment;
public bool DisplayArgs;
}
#endregion
}
}
if you want to send email using some data from sql server, it's good to add job to send emails. check this link to setup database mail on sql server 2005
http://www.databasejournal.com/features/mssql/article.php/3626056/Database-Mail-in-SQL-Server-2005.htm