You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

693 lines
25 KiB

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class clsDB
{
public string Connectionstring = "";
public DataSet dsdaten = new DataSet();
private SqlDataAdapter dadaten;
public clsDB()
{
// Me.Connectionstring = Get_Connectionstring(parcoursnr)
if (this.Connectionstring == "")
this.Connectionstring = Get_Connectionstring();
}
public string Get_Connectionstring()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["QWToolConnectionString"].ConnectionString;
}
public string Get_Option(int onr)
{
try
{
SqlConnection sqlconnect = new SqlConnection();
DataSet ds = new DataSet();
ds.Tables.Clear();
sqlconnect.ConnectionString = this.Connectionstring;
sqlconnect.Open();
SqlDataAdapter da = new SqlDataAdapter("", sqlconnect);
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection = sqlconnect;
sqlcmd.CommandType = CommandType.Text;
sqlcmd.CommandText = "Select * from optionen where optionnr=" + onr.ToString();
// sqlcmd.CommandText = "Select * from optionen where mandantnr=" + mandantnr.ToString + " and optionnr=" + onr.ToString
da.SelectCommand = sqlcmd;
da.Fill(ds, "Daten");
// If ds.Tables(0).Rows.Count = 0 Then
// sqlcmd.CommandText = "Select * from optionen where mandantnr=1 and optionnr=" + onr.ToString
// da.Fill(ds, "Daten")
// End If
return ds.Tables[0].Rows[0]["Inhalt"].ToString();
}
catch (Exception ex)
{
return "";
}
}
public DataSet Get_Tabledata(int sqlscriptnumber, string vereinnr, int userid)
{
Get_Tabledata("Select sqlscript from sqlqueries where sqlscriptnumber=" + sqlscriptnumber.ToString(),false,true);
string sql = dsdaten.Tables[0].Rows[0][0].ToString();
dsdaten.Tables.Clear();
sql = sql.Replace("@vereinnr", vereinnr);
sql = sql.Replace("@userid", userid.ToString());
Get_Tabledata(sql, false, true);
return dsdaten;
}
public DataSet Get_Tabledata(string Tablename, bool StoredProc = false, bool is_SQL_String = false)
{
SqlConnection sqlconnect = new SqlConnection();
DataSet ds = new DataSet();
ds.Tables.Clear();
sqlconnect.ConnectionString = this.Connectionstring;
sqlconnect.Open();
SqlDataAdapter da = new SqlDataAdapter("", sqlconnect);
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection = sqlconnect;
if (StoredProc == true)
{
sqlcmd.CommandType = CommandType.StoredProcedure;
if (Tablename.IndexOf("@@Mandantnr@@") > 0)
Tablename = Tablename.Replace("@@Mandantnr@@", "");
sqlcmd.CommandText = Tablename;
}
else
{
sqlcmd.CommandType = CommandType.Text;
sqlcmd.CommandText = "Select * from " + Tablename;
}
if (is_SQL_String == true)
sqlcmd.CommandText = Tablename;
// sqlcmd.CommandType = CommandType.StoredProcedure
// sqlcmd.CommandText = "Berufsliste"
da.SelectCommand = sqlcmd;
da.Fill(dsdaten, "Daten");
sqlconnect.Close();
return dsdaten;
}
public void Get_Tabledata(string tablename, string wherestatement = "", string SQL = "", string args = "", bool SP = false, DataTable SP_Params = null/* TODO Change to default(_) if this is not a reference type */)
{
if (SP == true)
{
}
try
{
dsdaten.Clear();
dsdaten.Tables.Clear();
dadaten = new SqlDataAdapter(SQL, this.Connectionstring);
if (SP == true)
{
SqlCommand sqlcmd = new SqlCommand();
SqlConnection sqlconnect = new SqlConnection();
sqlconnect.ConnectionString = this.Connectionstring;
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.CommandText = tablename;
foreach (DataRow r in SP_Params.Rows)
{
sqlcmd.Parameters.Add(r["Paramname"].ToString(), SqlDbType.VarChar);
sqlcmd.Parameters[sqlcmd.Parameters.Count - 1].Value = r["Paramvalue"];
}
sqlcmd.Connection = sqlconnect;
try
{
dadaten.SelectCommand = sqlcmd;
dadaten.Fill(dsdaten, tablename);
return;
}
catch (Exception ex)
{
sqlconnect.Open();
sqlcmd.ExecuteNonQuery();
sqlconnect.Close();
}
}
if (SQL != "")
{
SQL = SQL.Replace("&ARGS&", args);
dadaten = new SqlDataAdapter(SQL, this.Connectionstring);
}
else
dadaten = new SqlDataAdapter("select * from [" + tablename + "] " + wherestatement, this.Connectionstring);
dadaten.Fill(dsdaten, tablename);
}
catch (Exception ex)
{
int a = 1;
}
}
public void Get_Tabeldata_for_Update(string Tablename, bool StoredProc = false, bool is_SQL_String = false)
{
dsdaten.Clear();
dsdaten.Tables.Clear();
dadaten = new SqlDataAdapter(Tablename, this.Connectionstring);
dadaten.Fill(dsdaten, Tablename);
}
public void Update_Tabeldata()
{
SqlCommandBuilder cb = new SqlCommandBuilder(dadaten);
dadaten.Update(dsdaten, dsdaten.Tables[0].TableName);
}
public DataTable Get_Menu(string Menutype, bool loggedoffmenu)
{
SqlConnection SQLconnect = new SqlConnection();
DataSet ds = new DataSet();
ds.Tables.Clear();
SQLconnect.ConnectionString = this.Connectionstring;
SQLconnect.Open();
SqlDataAdapter da = new SqlDataAdapter("", SQLconnect);
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection = SQLconnect;
sqlcmd.CommandType = CommandType.Text;
clsDB dh = new clsDB();
// ds = dh.Get_Tabledata("Select Mandanttype from mandant where mandantnr=" + mandantnr.ToString, False, True)
// Dim mandanttyp As Integer
// mandanttyp = ds.Tables(0).Rows(0).Item(0)
// ds.Tables.Clear()
// If Get_Option(11, mandantnr) = "1/2" And
// Menutype = 3 Then
// sqlcmd.CommandText = "Select * from web_menu where mandanttype>=" + mandanttyp.ToString + " and aktiv=1 and menutext<>'Schüler' and ( menutype=10 or menutype=1 or menutype = " + Menutype.ToString + ") order by menutype, sort"
// Else
if (loggedoffmenu==true)
{
sqlcmd.CommandText = "Select * from web_menu where aktiv=1 and ( menutype=100 or menutype=1 or menutype = " + Menutype.ToString() + ") order by menutype, sort";
}
else
{
sqlcmd.CommandText = "Select * from web_menu where aktiv=1 and ( menutype <> 100 and menutype=10 or menutype=1 or menutype = " + Menutype.ToString() + ") order by menutype, sort";
}
// End If
da.SelectCommand = sqlcmd;
da.Fill(ds, "Daten");
sqlcmd.Dispose();
SQLconnect.Close();
return ds.Tables[0];
}
public void add_user()
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("add_user", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
//return null;
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
//return 0;
}
public void generate_password(string usernr, int pwgen)
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("Generate_Password", myConnection);
myCommand.Parameters.Add(new SqlParameter("@usernr", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, usernr));
myCommand.Parameters.Add(new SqlParameter("@nurpw", SqlDbType.Int, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, pwgen));
myCommand.CommandType = CommandType.StoredProcedure;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
//return null;
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
//return 0;
}
public void insert_log(int loglevel, int userid, string description)
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("sp_insert_logentry", myConnection);
myCommand.Parameters.Add(new SqlParameter("@userid", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, userid));
myCommand.Parameters.Add(new SqlParameter("@entrydescription", SqlDbType.VarChar, 4096, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, description));
myCommand.Parameters.Add(new SqlParameter("@level", SqlDbType.VarChar, 4096, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, loglevel));
myCommand.CommandType = CommandType.StoredProcedure;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
//return null;
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
//return 0;
}
public void add_new_mannschaft(string verein, string usernr)
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("add_mannschaft", myConnection);
myCommand.Parameters.Add(new SqlParameter("@vereinnr", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, verein));
myCommand.Parameters.Add(new SqlParameter("@usernr", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, usernr));
myCommand.CommandType = CommandType.StoredProcedure;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
//return null;
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
//return 0;
}
public int Add_New_Teilnehmer(string vereinnr, string usernr)
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("add_Teilnehmer", myConnection);
myCommand.Parameters.Add(new SqlParameter("@vereinnr", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, vereinnr));
myCommand.Parameters.Add(new SqlParameter("@usernr", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, usernr));
myCommand.CommandType = CommandType.StoredProcedure;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
return 0;
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
return 0;
}
public int Check_Teilnehmer(string vereinnr, string usernr)
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("chk_Teilnehmer", myConnection);
myCommand.Parameters.Add(new SqlParameter("@vereinnr", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, vereinnr));
myCommand.Parameters.Add(new SqlParameter("@usernr", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, usernr));
myCommand.CommandType = CommandType.StoredProcedure;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
return 0;
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
return 0;
}
public int Add_Athlet(string Vereinnr, int Athlete_id, string user)
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("add_athlet", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add(new SqlParameter("@vereinnr", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, Vereinnr));
myCommand.Parameters.Add(new SqlParameter("@athletid", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, Athlete_id));
myCommand.Parameters.Add(new SqlParameter("@usernr", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, user));
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
return 0;
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
return 0;
}
public void Add_Nicht_angemeldete_Teilnehmer(string vereinnr, string usernr)
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("add_all_Teilnehmer", myConnection);
myCommand.Parameters.Add(new SqlParameter("@vereinnr", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, vereinnr));
myCommand.Parameters.Add(new SqlParameter("@usernr", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, usernr));
myCommand.CommandType = CommandType.StoredProcedure;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
}
public void truncate_table(string tablename)
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("truncate table " + tablename, myConnection);
myCommand.CommandType = CommandType.Text;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
}
public string migrate_taf_resultate(string ortnr, string deldata)
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("[dbo].[Migrate_TAF_Import]", myConnection);
// if (deldata == "False") ortnr = "0";
myCommand.Parameters.Add(new SqlParameter("@ortnr", SqlDbType.Int, 3, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, ortnr));
myCommand.Parameters.Add(new SqlParameter("@return", SqlDbType.Int, 3, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, 0));
myCommand.Parameters.Add(new SqlParameter("@statistics", SqlDbType.VarChar, 8096, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, ""));
myCommand.CommandType = CommandType.StoredProcedure;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
return myCommand.Parameters["@statistics"].Value.ToString();
}
catch (Exception ex)
{
return "Fehler:"+ex.Message;
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
}
public void update_verein(string targetfolder)
{
truncate_table("base_account_import");
String Filter = ConfigurationSettings.AppSettings["VereinFilter"];
string[] filters = Filter.Split(',');
Get_Tabeldata_for_Update ("Select * from base_account_import",false,true);
DataSet verein = new DataSet();
verein.ReadXml(targetfolder + "\\verein.xml");
foreach (DataRow r in verein.Tables[0].Rows)
{
DataRow rn = dsdaten.Tables[0].NewRow();
Boolean useit;
useit = false;
foreach(var filt in filters)
{
if (r["accountcode"].ToString().IndexOf(filt) > 0) useit = true;
}
if (useit == true)
{
rn["account_code"] = r["accountCode"];
rn["account_name"] = r["accountName"];
rn["account_short"] = r["accountShort"];
rn["account_type"] = r["accountType"];
rn["lg"] = r["lg"];
dsdaten.Tables[0].Rows.Add(rn);
}
}
Update_Tabeldata();
}
public string get_unicode(string inputstring, DataTable unicodes)
{
string res = "";
string res1 = "";
char[] characters = inputstring.ToCharArray();
foreach (char c in characters)
{
res1 = "";
foreach (DataRow r in unicodes.Rows)
{
int ascii = (int)c;
if (ascii == Convert.ToInt32(r[0]))
{
res1 = r[1].ToString();
}
}
if (res1=="")
{
res = res + c.ToString();
}
else
{
res = res + res1;
}
}
return res;
}
public void update_athlete(string targetfolder)
{
dsdaten.Tables.Clear();
Get_Tabledata("Select * from charconvert", false, true);
DataTable unicodes = new DataTable();
unicodes = dsdaten.Tables[0].Copy();
dsdaten.Tables.Clear();
String Filter = ConfigurationSettings.AppSettings["VereinFilter"];
string[] filters = Filter.Split(',');
DataSet athlete = new DataSet();
athlete.ReadXml(targetfolder + "\\athlete.xml");
foreach (DataRow r in athlete.Tables[0].Rows)
{
Boolean useit;
useit = false;
foreach (var filt in filters)
{
if (r["accountcode"].ToString().IndexOf(filt) > 0) useit = true;
}
if (useit == true)
{
Get_Tabeldata_for_Update("Select * from base_athlete where license=" + r["license"].ToString(), false, true);
if (dsdaten.Tables[0].Rows.Count == 0)
{
DataRow rn = dsdaten.Tables[0].NewRow();
//string a = "";
//ASCIIEncoding ascii = new ASCIIEncoding();
//Byte[] bytes = ascii.GetBytes(r["Lastname"].ToString());
//String decoded = ascii.GetString(bytes);
//if (decoded.IndexOf("o?in") > -1)
//{
// decoded = decoded.Replace("o?in", "ošin");
// r["Lastname"] = decoded;
//}
r["lastname"] = get_unicode(r["lastname"].ToString(),unicodes);
r["firstname"] = get_unicode(r["firstname"].ToString(),unicodes);
rn["lastname"] = r["lastname"];
rn["firstname"] = r["firstname"];
rn["birth_date"] = r["birthdate"].ToString().Substring(3,2)+"."+ r["birthdate"].ToString().Substring(0, 2) + "."+r["birthdate"].ToString().Substring(6, 4);
rn["sex"] = r["sex"];
rn["nationality"] = r["nationality"];
rn["account_code"] = r["accountcode"];
rn["second_account_code"] = r["secondaccountcode"];
rn["account_info"] = r["lastKnownAccountInfo"];
rn["license_Paid"] = r["licensepaid"];
rn["license_Cat"] = r["licensecat"];
rn["license"] = r["license"];
dsdaten.Tables[0].Rows.Add(rn);
Update_Tabeldata();
}
else
{
DataRow rn = dsdaten.Tables[0].NewRow();
//string a = "";
//ASCIIEncoding ascii = new ASCIIEncoding();
//Byte[] bytes = ascii.GetBytes(r["Lastname"].ToString());
//String decoded = ascii.GetString(bytes);
//if (decoded.IndexOf("o?in")>-1)
//{
// decoded = decoded.Replace("o?in", "ošin");
// r["Lastname"] = decoded;
//}
if (r["License"].ToString() == "173471")
{
string a = "";
}
r["lastname"] = get_unicode(r["lastname"].ToString(),unicodes);
r["firstname"] = get_unicode(r["firstname"].ToString(),unicodes);
dsdaten.Tables[0].Rows[0]["lastname"] = r["lastname"];
dsdaten.Tables[0].Rows[0]["firstname"] = r["firstname"];
dsdaten.Tables[0].Rows[0]["birth_date"] = r["birthdate"].ToString().Substring(3, 2) + "." + r["birthdate"].ToString().Substring(0, 2) + "." + r["birthdate"].ToString().Substring(6, 4); ;
dsdaten.Tables[0].Rows[0]["sex"] = r["sex"];
dsdaten.Tables[0].Rows[0]["nationality"] = r["nationality"];
dsdaten.Tables[0].Rows[0]["account_code"] = r["accountcode"];
dsdaten.Tables[0].Rows[0]["second_account_code"] = r["secondaccountcode"];
dsdaten.Tables[0].Rows[0]["account_info"] = r["lastKnownAccountInfo"];
dsdaten.Tables[0].Rows[0]["license_paid"] = r["licensepaid"];
dsdaten.Tables[0].Rows[0]["license_cat"] = r["licensecat"];
//dsdaten.Tables[0].AcceptChanges();
Update_Tabeldata();
}
}
}
}
public DataSet Get_Reportdata(string Orte, string U1012, string erdgas, string vierkampf, int ortnr)
{
SqlConnection myConnection = new SqlConnection(this.Connectionstring);
SqlCommand myCommand = new SqlCommand("dbo.res_resultate_aufbereiten", myConnection);
myCommand.Parameters.Add("@orte", SqlDbType.VarChar, 1024);
myCommand.Parameters.Add("@U10U12", SqlDbType.VarChar, 1);
if (vierkampf == "J")
{
myCommand.Parameters.Add("@resqw", SqlDbType.Int, 4);
myCommand.Parameters.Add("@resew", SqlDbType.Int, 4);
myCommand.Parameters.Add("@resortnr", SqlDbType.Int, 4);
myCommand.Parameters[4].Value = ortnr;
myCommand.Parameters[3].Value = 0;
myCommand.Parameters[2].Value = 1;
}
if (erdgas == "J")
{
myCommand.Parameters.Add("@resqw", SqlDbType.Int, 4);
myCommand.Parameters.Add("@resew", SqlDbType.Int, 4);
myCommand.Parameters.Add("@resortnr", SqlDbType.Int, 4);
myCommand.Parameters[4].Value = ortnr;
myCommand.Parameters[3].Value = 1;
myCommand.Parameters[2].Value = 0;
}
myCommand.Parameters[0].Value = Orte;
myCommand.Parameters[1].Value = U1012;
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandTimeout = 600;
SqlDataAdapter da = new SqlDataAdapter(myCommand);
try
{
myConnection.Open();
da.Fill(dsdaten, "Daten");
//myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}
return dsdaten;
}
public void Insert_Disziplin_select(int ortnr)
{
}
}