C# – The better basic

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.

At vero eos et accusam et justo duo dolores et ea rebum.

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Data;
using System.IO;
namespace QuickstartMenu
{
/// <summary>
/// XMLSettingProvider-Klasse
/// </summary>
public static class XMLSettingProvider
{
public enum SettingTables
{
Settings
}
private static string inifile;
private static DataSet dsSettings = null;
private static DataTable dtSettings = null;
private static char[] seperator1 = new char[] { ',' };
private static char[] seperator2 = new char[] { '=' };
private static char[] trimmer = new char[] { '{', '}' };
public static void Initialize(string INIFile)
{
inifile = INIFile;
if (dsSettings == null)
{
dsSettings = new DataSet("Settings");
dtSettings = new DataTable("Settings");
DataColumn col0 = new DataColumn("Description", System.Type.GetType("System.String"));
DataColumn col1 = new DataColumn("Value", System.Type.GetType("System.String"));
dtSettings.Columns.AddRange(new DataColumn[] { col0, col1 });
dsSettings.Tables.AddRange(new DataTable[] { dtSettings });
}
if(!Directory.Exists(Path.GetDirectoryName(inifile)))
{
Directory.CreateDirectory(Path.GetDirectoryName(inifile));
}
if (!File.Exists(inifile))
{                
SaveSettings();
}
LoadSettings();
}
/// <summary>
/// Lädt die Benutzereinstellungen
/// </summary>
public static void LoadSettings()
{
dtSettings.Clear();
try
{
if (File.Exists(inifile))
{
dsSettings.ReadXml(inifile);
}
else
{
SaveSettings();
dsSettings.ReadXml(inifile);
}
}
catch
{ }
}
public static void SaveSettings()
{
dsSettings.WriteXml(inifile);
}
public static bool ExistsExportTypeProperty()
{
bool giveback = false;
DataRow[] res = dsSettings.Tables[SettingTables.Settings.ToString()].Select("Description = 'ExportAsZIP'");
if (res.Length == 1)
{
giveback = true;
}
else
{
giveback = false;
}
return giveback;
}
public static void Write(SettingTables Table, string Setting, string Value)
{
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
res[0][1] = Value;
}
else if (res.Length == 0)
{
DataRow dr = dsSettings.Tables[Table.ToString()].NewRow();
dr[0] = Setting;
dr[1] = Value;
dsSettings.Tables[Table.ToString()].Rows.Add(dr);
}
SaveSettings();
}
public static void Write(SettingTables Table, string Setting, int Value)
{
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
res[0][1] = Value;
}
else if (res.Length == 0)
{
DataRow dr = dsSettings.Tables[Table.ToString()].NewRow();
dr[0] = Setting;
dr[1] = Value;
dsSettings.Tables[Table.ToString()].Rows.Add(dr);
}
SaveSettings();
}
public static void Write(SettingTables Table, string Setting, double Value)
{
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
res[0][1] = Value;
}
else if (res.Length == 0)
{
DataRow dr = dsSettings.Tables[Table.ToString()].NewRow();
dr[0] = Setting;
dr[1] = Value;
dsSettings.Tables[Table.ToString()].Rows.Add(dr);
}
SaveSettings();
}
public static void Write(SettingTables Table, string Setting, decimal Value)
{
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
res[0][1] = Value;
}
else if (res.Length == 0)
{
DataRow dr = dsSettings.Tables[Table.ToString()].NewRow();
dr[0] = Setting;
dr[1] = Value;
dsSettings.Tables[Table.ToString()].Rows.Add(dr);
}
SaveSettings();
}
public static void Write(SettingTables Table, string Setting, bool Value)
{
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
res[0][1] = Value;
}
else if (res.Length == 0)
{
DataRow dr = dsSettings.Tables[Table.ToString()].NewRow();
dr[0] = Setting;
dr[1] = Value;
dsSettings.Tables[Table.ToString()].Rows.Add(dr);
}
SaveSettings();
}
public static void Write(SettingTables Table, string Setting, System.Drawing.Point Value)
{
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "_Location'");
if (res.Length == 1)
{
res[0][1] = Value;
}
else if (res.Length == 0)
{
DataRow dr = dsSettings.Tables[Table.ToString()].NewRow();
dr[0] = Setting + "_Location";
dr[1] = Value;
dsSettings.Tables[Table.ToString()].Rows.Add(dr);
}
SaveSettings();
}
public static void Write(SettingTables Table, string Setting, System.Drawing.Size Value)
{
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "_Size'");
if (res.Length == 1)
{
res[0][1] = Value;
}
else if (res.Length == 0)
{
DataRow dr = dsSettings.Tables[Table.ToString()].NewRow();
dr[0] = Setting + "_Size";
dr[1] = Value;
dsSettings.Tables[Table.ToString()].Rows.Add(dr);
}
SaveSettings();
}
public static string Read(SettingTables Table, string Setting, string Default)
{
string giveback = Default;
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
giveback = res[0][1].ToString();
}
return giveback;
}
public static int Read(SettingTables Table, string Setting, int Default)
{
int giveback = Default;
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
try
{
giveback = Convert.ToInt32(res[0][1]);
}
catch
{
}
}
return giveback;
}
public static double Read(SettingTables Table, string Setting, double Default)
{
double giveback = Default;
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
try
{
giveback = Convert.ToDouble(res[0][1]);
}
catch
{
}
}
return giveback;
}
public static decimal Read(SettingTables Table, string Setting, decimal Default)
{
decimal giveback = Default;
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
try
{
giveback = Convert.ToDecimal(res[0][1]);
}
catch
{
}
}
return giveback;
}
public static bool Read(SettingTables Table, string Setting, bool Default)
{
bool giveback = Default;
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
try
{
giveback = Convert.ToBoolean(res[0][1]);
}
catch
{
}
}
return giveback;
}
public static Point Read(SettingTables Table, string Setting, Point Default)
{
Point giveback = Default;
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
try
{
int[] xy = new int[2];
string[] arry1 = (res[0][1]).ToString().Split(seperator1);
xy[0] = Convert.ToInt32(arry1[0].Split(seperator2)[1].Trim(trimmer));
xy[1] = Convert.ToInt32(arry1[1].Split(seperator2)[1].Trim(trimmer));
giveback = new Point(xy[0], xy[1]);
}
catch
{
}
}
return giveback;
}
public static Size Read(SettingTables Table, string Setting, Size Default)
{
Size giveback = Default;
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
try
{
int[] xy = new int[2];
string[] arry1 = (res[0][1]).ToString().Split(seperator1);
xy[0] = Convert.ToInt32(arry1[0].Split(seperator2)[1].Trim(trimmer));
xy[1] = Convert.ToInt32(arry1[1].Split(seperator2)[1].Trim(trimmer));
giveback = new Size(xy[0], xy[1]);
}
catch
{
}
}
return giveback;
}
public static void Delete(SettingTables Table, string Setting)
{
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length == 1)
{
try
{
res[0].Delete();
SaveSettings();
}
catch
{
}
}
}
public static bool Contains(SettingTables Table, string Setting)
{
bool result = false;
DataRow[] res = dsSettings.Tables[Table.ToString()].Select("Description = '" + Setting + "'");
if (res.Length > 0)
{
result = true;
}
return result;
}
public static DataTable GetDataTable(SettingTables Table)
{
DataTable dtUserCopy = new DataTable("User");
DataColumn col5 = new DataColumn("Description", System.Type.GetType("System.String"));
DataColumn col6 = new DataColumn("Value", System.Type.GetType("System.String"));
dtUserCopy.Columns.AddRange(new DataColumn[] { col5, col6 });
foreach (DataRow dr in dsSettings.Tables[Table.ToString()].Rows)
{
DataRow ndr = dtUserCopy.NewRow();
ndr["Description"] = dr["Description"].ToString();
ndr["Value"] = dr["Value"].ToString();
dtUserCopy.Rows.Add(ndr);
}
return dtUserCopy;
}
}
}