128 lines
3.4 KiB
C#
128 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SQLite;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PEP_Tool
|
|
{
|
|
public static class SQL
|
|
{
|
|
private static SQLiteConnection dbConnection;
|
|
public static SQLiteConnection DBConnection
|
|
{
|
|
get
|
|
{
|
|
if (dbConnection == null) ConnectDB();
|
|
return dbConnection;
|
|
}
|
|
set
|
|
{
|
|
dbConnection = value;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static async Task ConnectDB()
|
|
{
|
|
DBConnection = new SQLiteConnection("Data Source = PEP_DB.sqlite; Version = 3;");
|
|
DBConnection.Open();
|
|
}
|
|
|
|
|
|
|
|
public static async Task WriteDB(string WriteString)
|
|
{
|
|
if (DBConnection.State != System.Data.ConnectionState.Open) await ConnectDB();
|
|
|
|
SQLiteCommand command = new SQLiteCommand(WriteString, DBConnection);
|
|
await command.ExecuteNonQueryAsync();
|
|
}
|
|
|
|
|
|
|
|
public static void ReadDB()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void CloseDB()
|
|
{
|
|
dbConnection.Close();
|
|
}
|
|
|
|
|
|
public static async Task<SQLiteDataAdapter> CreateDataAdapter()
|
|
{
|
|
SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter("SELECT * FROM serial", DBConnection);
|
|
DataSet ds = new DataSet();
|
|
|
|
dataAdapter.FillSchema(ds, System.Data.SchemaType.Mapped);
|
|
return dataAdapter;
|
|
}
|
|
|
|
|
|
|
|
public static async void CreateDB()
|
|
{
|
|
SQLiteConnection.CreateFile("PEP_DB.sqlite");
|
|
|
|
await ConnectDB();
|
|
|
|
string tableinfo = "CREATE TABLE TableInfo(" +
|
|
"PersNummer TEXT, " +
|
|
"FilePath TEXT, " +
|
|
"Datum TEXT, " +
|
|
"Zuweisung TEXT," +
|
|
"Bemerkung TEXT, " +
|
|
"Telefon TEXT)";
|
|
|
|
SQLiteCommand Command = new SQLiteCommand(tableinfo, DBConnection);
|
|
Command.ExecuteNonQuery();
|
|
|
|
//Lizenzen list string
|
|
//Zuweisungsmöglichkeiten list string
|
|
}
|
|
}
|
|
|
|
public class SQLtoDataGrid
|
|
{
|
|
public DataView UserListView;
|
|
public DataView ZuweisungsMoeglichkeiten;
|
|
|
|
public SQLtoDataGrid()
|
|
{
|
|
SQLiteConnection con = new SQLiteConnection("Data Source = PEP_DB.sqlite; Version = 3;");
|
|
try
|
|
{
|
|
con.Open();
|
|
string Query = "select * from UserList";
|
|
SQLiteCommand cmdp = new SQLiteCommand(Query, con);
|
|
DataTable UserList = new DataTable();
|
|
using (SQLiteDataAdapter ap = new SQLiteDataAdapter(cmdp))
|
|
{
|
|
ap.Fill(UserList);
|
|
}
|
|
UserListView = UserList.DefaultView;
|
|
|
|
SQLiteCommand cmdc = new SQLiteCommand("select * from ZuweisungsMoeglichkeiten", con);
|
|
DataTable ZWDT = new DataTable();
|
|
using (SQLiteDataAdapter ac = new SQLiteDataAdapter(cmdc))
|
|
{
|
|
ac.Fill(ZWDT);
|
|
}
|
|
ZuweisungsMoeglichkeiten = ZWDT.DefaultView;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(ex);
|
|
}
|
|
}
|
|
}
|
|
}
|