erste anpassungen für neue impementierte connection der verschiedenen sql server
This commit is contained in:
parent
19b63d6c27
commit
00176a2d83
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.12.35527.113 d17.12
|
VisualStudioVersion = 17.12.35527.113
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProgrammList", "ProgrammList\ProgrammList.csproj", "{06D431CD-A938-4DFD-8D77-4C612FDAD914}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProgrammList", "ProgrammList\ProgrammList.csproj", "{06D431CD-A938-4DFD-8D77-4C612FDAD914}"
|
||||||
EndProject
|
EndProject
|
||||||
@ -15,8 +15,8 @@ Global
|
|||||||
Release|x64 = Release|x64
|
Release|x64 = Release|x64
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.ActiveCfg = Release|Any CPU
|
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.Build.0 = Release|Any CPU
|
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|x64.ActiveCfg = Debug|x64
|
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|x64.Build.0 = Debug|x64
|
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|x64.Build.0 = Debug|x64
|
||||||
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.PrgmList|Any CPU.ActiveCfg = PrgmList|Any CPU
|
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.PrgmList|Any CPU.ActiveCfg = PrgmList|Any CPU
|
||||||
|
@ -1,17 +1,35 @@
|
|||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
|
|
||||||
namespace ProgrammList.ConfigManager {
|
namespace ProgrammList.ConfigManager {
|
||||||
public class ConfigManager {
|
public static class PrmListConfigManager {
|
||||||
|
|
||||||
public static string GetSetting(string key) {
|
public static string GetSetting(string key) {
|
||||||
return ConfigurationManager.AppSettings[key];
|
try {
|
||||||
|
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
||||||
|
Console.WriteLine("Loading " + Directory.GetCurrentDirectory() + "\\app.conf");
|
||||||
|
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
|
||||||
|
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
|
||||||
|
return config.AppSettings.Settings[key].Value;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
Console.WriteLine("Error on Key " + key + ": " + e.ToString());
|
||||||
|
Console.WriteLine(e.ToString());
|
||||||
|
}
|
||||||
|
return "13";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetSetting(string key, string value) {
|
public static void SetSetting(string key, string value) {
|
||||||
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
try {
|
||||||
configuration.AppSettings.Settings[key].Value = value;
|
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
||||||
configuration.Save(ConfigurationSaveMode.Full, true);
|
Console.WriteLine("Loading " + Directory.GetCurrentDirectory() + "\\app.conf");
|
||||||
ConfigurationManager.RefreshSection("appSettings");
|
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
|
||||||
|
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
|
||||||
|
config.AppSettings.Settings["key"].Value = value;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
Console.WriteLine("Error on Key " + key + ": " + e.ToString());
|
||||||
|
Console.WriteLine(e.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ using ProgrammList.ListPrograms;
|
|||||||
class Program {
|
class Program {
|
||||||
public static void Main(string[] args) {
|
public static void Main(string[] args) {
|
||||||
|
|
||||||
string dbType = ConfigManager.GetSetting("DB_Type");
|
string dbType = PrmListConfigManager.GetSetting("DB_Type");
|
||||||
ListPrograms list = new ListPrograms(dbType);
|
ListPrograms list = new ListPrograms(dbType);
|
||||||
|
|
||||||
Console.WriteLine("Deleting old data");
|
Console.WriteLine("Deleting old data");
|
||||||
|
63
ProgrammList/Properties/Resources.Designer.cs
generated
Normal file
63
ProgrammList/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Runtime Version:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace ProgrammList.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||||
|
/// </summary>
|
||||||
|
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||||
|
// class via a tool like ResGen or Visual Studio.
|
||||||
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
|
// with the /str option, or rebuild your VS project.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
internal class Resources {
|
||||||
|
|
||||||
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
|
internal Resources() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the cached ResourceManager instance used by this class.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
|
get {
|
||||||
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProgrammList.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Overrides the current thread's CurrentUICulture property for all
|
||||||
|
/// resource lookups using this strongly typed resource class.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get {
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
101
ProgrammList/Properties/Resources.resx
Normal file
101
ProgrammList/Properties/Resources.resx
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 1.3
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">1.3</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1">this is my long string</data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
[base64 mime encoded serialized .NET Framework object]
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
[base64 mime encoded string representing a byte array form of the .NET Framework object]
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>1.3</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -9,7 +9,7 @@ namespace ProgrammList.ListPrograms {
|
|||||||
string[] keyvaluenames = { "DisplayName", "DisplayVersion", "InstallDate" };
|
string[] keyvaluenames = { "DisplayName", "DisplayVersion", "InstallDate" };
|
||||||
private SqlBase sql = null;
|
private SqlBase sql = null;
|
||||||
|
|
||||||
internal ListPrograms(string sqlType) {
|
internal ListPrograms(string sqlType, params string[] filename) {
|
||||||
if (sqlType == null) {
|
if (sqlType == null) {
|
||||||
Console.WriteLine("SQL Database not defined in app.conf, allowed types:");
|
Console.WriteLine("SQL Database not defined in app.conf, allowed types:");
|
||||||
Console.WriteLine("MYSQL");
|
Console.WriteLine("MYSQL");
|
||||||
@ -25,8 +25,12 @@ namespace ProgrammList.ListPrograms {
|
|||||||
else if (sqlType.Equals("MSSQL", StringComparison.OrdinalIgnoreCase)) {
|
else if (sqlType.Equals("MSSQL", StringComparison.OrdinalIgnoreCase)) {
|
||||||
sql = new Mssql();
|
sql = new Mssql();
|
||||||
}
|
}
|
||||||
else if (sqlType.Equals("SQLITE", StringComparison.OrdinalIgnoreCase)) {
|
else if (sqlType.Equals("SQLITE", StringComparison.OrdinalIgnoreCase) && filename != null) {
|
||||||
sql = new Sqlite(prgm_path);
|
sql = new Sqlite(prgm_path, filename[0]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Default sqlite im gleichen ordner
|
||||||
|
sql = new Sqlite(prgm_path, "sqllite.db");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,13 @@
|
|||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
|
|
||||||
namespace ProgrammList.sql {
|
namespace ProgrammList.sql {
|
||||||
public class Mssql : SqlBaseAbstract {
|
public class Mssql : SqlBase {
|
||||||
|
|
||||||
|
public string[] valuenames = { "PCID", "DisplayName", "DisplayVersion", "InstallDate", "update_date", "APP_Architecture" };
|
||||||
|
public string connstring = null;
|
||||||
|
string constring = null;
|
||||||
|
|
||||||
|
SqlConnection mssqlcon = null;
|
||||||
|
|
||||||
//private static Dbconnection instance;
|
//private static Dbconnection instance;
|
||||||
public Mssql() {
|
public Mssql() {
|
||||||
@ -15,12 +21,22 @@ namespace ProgrammList.sql {
|
|||||||
TrustServerCertificate = true
|
TrustServerCertificate = true
|
||||||
};
|
};
|
||||||
|
|
||||||
connstring = builder.ToString();
|
constring = builder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void Open() {
|
||||||
|
mssqlcon.Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close() {
|
||||||
|
mssqlcon.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetAllData() {
|
public void GetAllData() {
|
||||||
Open(DB.MSSQL);
|
Open();
|
||||||
var command = sqlcon.CreateCommand();
|
var command = mssqlcon.CreateCommand();
|
||||||
command.CommandText = @"SELECT * FROM list";
|
command.CommandText = @"SELECT * FROM list";
|
||||||
|
|
||||||
using (var reader = command.ExecuteReader()) {
|
using (var reader = command.ExecuteReader()) {
|
||||||
@ -31,8 +47,8 @@ namespace ProgrammList.sql {
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
public bool GetSingleLine(string pcid, string program, string version) {
|
public bool GetSingleLine(string pcid, string program, string version) {
|
||||||
Open(DB.MSSQL);
|
Open();
|
||||||
var command = sqlcon.CreateCommand();
|
var command = mssqlcon.CreateCommand();
|
||||||
command.CommandText = @"SELECT * FROM list where PCID like "
|
command.CommandText = @"SELECT * FROM list where PCID like "
|
||||||
+ pcid + " and DisplayName like "
|
+ pcid + " and DisplayName like "
|
||||||
+ program + " and DisplayVersion like " + version + ";";
|
+ program + " and DisplayVersion like " + version + ";";
|
||||||
@ -43,8 +59,8 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void CheckTableExists() {
|
public void CheckTableExists() {
|
||||||
Open(DB.MSSQL);
|
Open();
|
||||||
var command = sqlcon.CreateCommand();
|
var command = mssqlcon.CreateCommand();
|
||||||
command.CommandText = "select case when exists (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'prgmlist' AND TABLE_NAME = 'list') then 1 else 0 end";
|
command.CommandText = "select case when exists (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'prgmlist' AND TABLE_NAME = 'list') then 1 else 0 end";
|
||||||
var returncode = command.ExecuteScalar();
|
var returncode = command.ExecuteScalar();
|
||||||
if (returncode != null) {
|
if (returncode != null) {
|
||||||
@ -71,8 +87,8 @@ namespace ProgrammList.sql {
|
|||||||
|
|
||||||
|
|
||||||
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
||||||
Open(DB.MSSQL);
|
Open();
|
||||||
var transaction = sqlcon.BeginTransaction();
|
var transaction = mssqlcon.BeginTransaction();
|
||||||
|
|
||||||
string result = "";
|
string result = "";
|
||||||
for (int i = 0; i < valuenames.Length; i++) {
|
for (int i = 0; i < valuenames.Length; i++) {
|
||||||
@ -88,7 +104,7 @@ namespace ProgrammList.sql {
|
|||||||
|
|
||||||
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
|
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
|
||||||
|
|
||||||
var command = new SqlCommand(sqlCommand, sqlcon, transaction);
|
var command = new SqlCommand(sqlCommand, mssqlcon, transaction);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
Console.WriteLine(sqlCommand);
|
Console.WriteLine(sqlCommand);
|
||||||
@ -105,8 +121,8 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteOldData(string hostname) {
|
public void DeleteOldData(string hostname) {
|
||||||
Open(DB.MSSQL);
|
Open();
|
||||||
var command = sqlcon.CreateCommand();
|
var command = mssqlcon.CreateCommand();
|
||||||
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
||||||
command.CommandText = sqlCommand;
|
command.CommandText = sqlCommand;
|
||||||
command.ExecuteReader();
|
command.ExecuteReader();
|
||||||
@ -114,8 +130,8 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateData(Dictionary<string, string> value) {
|
public void UpdateData(Dictionary<string, string> value) {
|
||||||
Open(DB.MSSQL);
|
Open();
|
||||||
var transaction = sqlcon.BeginTransaction();
|
var transaction = mssqlcon.BeginTransaction();
|
||||||
string sqlCommand = @"Update list ";
|
string sqlCommand = @"Update list ";
|
||||||
|
|
||||||
string result = "set ";
|
string result = "set ";
|
||||||
@ -133,7 +149,7 @@ namespace ProgrammList.sql {
|
|||||||
" and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
|
" and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
|
||||||
|
|
||||||
|
|
||||||
var command = new SqlCommand(sqlCommand, sqlcon, transaction);
|
var command = new SqlCommand(sqlCommand, mssqlcon, transaction);
|
||||||
for (int i = 0; i < valuenames.Length; i++) {
|
for (int i = 0; i < valuenames.Length; i++) {
|
||||||
if (valuenames[i] != "PCID") {
|
if (valuenames[i] != "PCID") {
|
||||||
command.Parameters.AddWithValue("$" + valuenames[i], value.GetValueOrDefault(valuenames[i]));
|
command.Parameters.AddWithValue("$" + valuenames[i], value.GetValueOrDefault(valuenames[i]));
|
||||||
|
@ -3,11 +3,14 @@
|
|||||||
namespace ProgrammList.sql {
|
namespace ProgrammList.sql {
|
||||||
|
|
||||||
|
|
||||||
internal class Mysql : SqlBaseAbstract {
|
internal class Mysql {
|
||||||
|
public string[] valuenames = { "PCID", "DisplayName", "DisplayVersion", "InstallDate", "update_date", "APP_Architecture" };
|
||||||
|
public string connstring = null;
|
||||||
|
public MySqlConnection mysqlcon = null;
|
||||||
|
|
||||||
|
|
||||||
public Boolean GetSingleLine(string pcid, string program, string version) {
|
public Boolean GetSingleLine(string pcid, string program, string version) {
|
||||||
Open(DB.MYSQL);
|
Open();
|
||||||
var command = mysqlcon.CreateCommand();
|
var command = mysqlcon.CreateCommand();
|
||||||
command.CommandText = @"SELECT * FROM list where PCID like "
|
command.CommandText = @"SELECT * FROM list where PCID like "
|
||||||
+ pcid + " and DisplayName like "
|
+ pcid + " and DisplayName like "
|
||||||
@ -18,8 +21,17 @@ namespace ProgrammList.sql {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Open() {
|
||||||
|
mysqlcon.Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close() {
|
||||||
|
mysqlcon.Close();
|
||||||
|
}
|
||||||
|
|
||||||
public void CheckTableExists() {
|
public void CheckTableExists() {
|
||||||
Open(DB.MYSQL);
|
Open();
|
||||||
var command = mysqlcon.CreateCommand();
|
var command = mysqlcon.CreateCommand();
|
||||||
command.CommandText = @"SHOW TABLES LIKE 'list';";
|
command.CommandText = @"SHOW TABLES LIKE 'list';";
|
||||||
var name = command.ExecuteScalar();
|
var name = command.ExecuteScalar();
|
||||||
@ -35,7 +47,7 @@ namespace ProgrammList.sql {
|
|||||||
|
|
||||||
|
|
||||||
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
||||||
Open(DB.MYSQL);
|
Open();
|
||||||
var transaction = mysqlcon.BeginTransaction();
|
var transaction = mysqlcon.BeginTransaction();
|
||||||
|
|
||||||
string result = "";
|
string result = "";
|
||||||
@ -69,7 +81,7 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateData(Dictionary<string, string> value) {
|
public void UpdateData(Dictionary<string, string> value) {
|
||||||
Open(DB.MYSQL);
|
Open();
|
||||||
var transaction = mysqlcon.BeginTransaction();
|
var transaction = mysqlcon.BeginTransaction();
|
||||||
string sqlCommand = @"Update list ";
|
string sqlCommand = @"Update list ";
|
||||||
|
|
||||||
@ -102,7 +114,7 @@ namespace ProgrammList.sql {
|
|||||||
|
|
||||||
|
|
||||||
public void DeleteOldData(string hostname) {
|
public void DeleteOldData(string hostname) {
|
||||||
Open(DB.MYSQL);
|
Open();
|
||||||
var command = mysqlcon.CreateCommand();
|
var command = mysqlcon.CreateCommand();
|
||||||
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
||||||
command.CommandText = sqlCommand;
|
command.CommandText = sqlCommand;
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
interface SqlBase {
|
interface SqlBase {
|
||||||
|
|
||||||
|
internal void Open();
|
||||||
|
internal void Close();
|
||||||
internal bool GetSingleLine(string pcid, string program, string version);
|
internal bool GetSingleLine(string pcid, string program, string version);
|
||||||
|
|
||||||
internal void CheckTableExists();
|
internal void CheckTableExists();
|
||||||
|
@ -1,86 +0,0 @@
|
|||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using Microsoft.Data.Sqlite;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
namespace ProgrammList.sql {
|
|
||||||
|
|
||||||
public abstract class SqlBaseAbstract : SqlBase {
|
|
||||||
|
|
||||||
|
|
||||||
public string[] valuenames = { "PCID", "DisplayName", "DisplayVersion", "InstallDate", "update_date", "APP_Architecture" };
|
|
||||||
public string connstring = null;
|
|
||||||
public MySqlConnection mysqlcon = null;
|
|
||||||
public SqlConnection sqlcon = null;
|
|
||||||
public SqliteConnection sqlitecon = null;
|
|
||||||
|
|
||||||
public void Close() {
|
|
||||||
if (mysqlcon != null) {
|
|
||||||
mysqlcon.Close();
|
|
||||||
}
|
|
||||||
else if (sqlcon != null) {
|
|
||||||
sqlcon.Close();
|
|
||||||
}
|
|
||||||
else if (sqlitecon != null) {
|
|
||||||
sqlitecon.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void Open(DB type) {
|
|
||||||
switch (type) {
|
|
||||||
case DB.MYSQL:
|
|
||||||
case DB.MARIADB:
|
|
||||||
mysqlcon = new MySqlConnection(connstring);
|
|
||||||
try {
|
|
||||||
mysqlcon.Open();
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Console.Write(ex.ToString());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DB.MSSQL:
|
|
||||||
sqlcon = new SqlConnection(connstring);
|
|
||||||
try {
|
|
||||||
mysqlcon.Open();
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Console.Write(ex.ToString());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DB.SQLITE:
|
|
||||||
sqlitecon = new SqliteConnection(connstring);
|
|
||||||
try {
|
|
||||||
mysqlcon.Open();
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Console.Write(ex.ToString());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SqlBase.GetSingleLine(string pcid, string program, string version) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SqlBase.CheckTableExists() {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SqlBase.InsertData(Dictionary<string, string> valuesqlCommand) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SqlBase.InsertOrUpdateData(Dictionary<string, string> value) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SqlBase.DeleteOldData(string hostname) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SqlBase.UpdateData(Dictionary<string, string> value) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +1,43 @@
|
|||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
using System.Configuration;
|
|
||||||
|
|
||||||
namespace ProgrammList.sql {
|
namespace ProgrammList.sql {
|
||||||
public class Sqlite : SqlBaseAbstract {
|
public class Sqlite : SqlBase {
|
||||||
|
|
||||||
string filename;
|
string filename;
|
||||||
|
SqliteConnection sqlitecon;
|
||||||
|
|
||||||
|
public string[] valuenames = { "PCID", "DisplayName", "DisplayVersion", "InstallDate", "update_date", "APP_Architecture" };
|
||||||
|
public string connstring = null;
|
||||||
|
|
||||||
|
public Sqlite(string prm_path, string filename) {
|
||||||
|
sqlitecon = new SqliteConnection("Data Source=" + prm_path + filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Open() {
|
||||||
|
sqlitecon.Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close() {
|
||||||
|
sqlitecon.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Open(DB type) {
|
||||||
|
sqlitecon = new SqliteConnection(connstring);
|
||||||
|
sqlitecon.Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Sqlite(string prm_path) {
|
public Sqlite(string prm_path) {
|
||||||
sqlitecon = new SqliteConnection("Data Source=" + prm_path + ConfigurationManager.AppSettings["filename"]);
|
string setting = ConfigManager.PrmListConfigManager.GetSetting("filename");
|
||||||
|
if (setting != null && setting != "") {
|
||||||
|
Console.WriteLine("using db filename " + setting);
|
||||||
|
sqlitecon = new SqliteConnection("Data Source=" + prm_path + setting);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("reverting to default db, sqlite filename sqlite.db");
|
||||||
|
sqlitecon = new SqliteConnection("Data Source=" + prm_path + "sqlite.db");
|
||||||
|
}
|
||||||
sqlitecon.Open();
|
sqlitecon.Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user