uupdate 20240829
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
284
Database/db.cs
284
Database/db.cs
@@ -11,7 +11,8 @@ using System.Xml.Linq;
|
||||
using Model;
|
||||
using System.Security.Cryptography;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using Logging;
|
||||
using Logging;
|
||||
using System.Configuration;
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +38,7 @@ namespace Database
|
||||
{
|
||||
DataRow r = SP_Parameters.NewRow();
|
||||
r[0] = name;
|
||||
r[1]=value;
|
||||
r[1] = value;
|
||||
SP_Parameters.Rows.Add(r);
|
||||
}
|
||||
public void clear_parameter()
|
||||
@@ -107,7 +108,7 @@ namespace Database
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
|
||||
Logging.Logging.Error(ex.Message, "EDOKA_DB:Get_Tabledata:" + Tablename, "");
|
||||
return null;
|
||||
}
|
||||
@@ -168,7 +169,7 @@ namespace Database
|
||||
//var cb = new SqlCommandBuilder(dadaten);
|
||||
//dadaten.Update(dsdaten, dsdaten.Tables[0].TableName);
|
||||
//cb.Dispose();
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -248,7 +249,7 @@ namespace Database
|
||||
}
|
||||
public string get_vorlage_to_file(string nr, string tempdir, string dokumentid)
|
||||
{
|
||||
|
||||
|
||||
SqlConnection conn = new SqlConnection(connectionstring);
|
||||
SqlCommand sc = new SqlCommand("Select vorlage from office_vorlage_datei where dbo.office_vorlage_datei.office_vorlage_dateinr=" + nr, conn);
|
||||
conn.Open();
|
||||
@@ -293,7 +294,7 @@ namespace Database
|
||||
clsConnectionProvider edoka_conn = new clsConnectionProvider();
|
||||
edoka_conn.sConnectionString = this.connectionstring;
|
||||
|
||||
|
||||
|
||||
doktyp.cpMainConnectionProvider = edoka_conn;
|
||||
doktyp.iDokumenttypnr = Convert.ToInt32(DocData.DokumenttypNr);
|
||||
doktyp.SelectOne();
|
||||
@@ -313,8 +314,8 @@ namespace Database
|
||||
dok.bUnvollstaendig = false;
|
||||
dok.iBck = 0;
|
||||
dok.iColdstatus = 0;
|
||||
if (DocData.Unterschrift_Links=="") { DocData.Unterschrift_Links = "0"; }
|
||||
if (DocData.Unterschrift_Rechts=="") { DocData.Unterschrift_Rechts = "0"; }
|
||||
if (DocData.Unterschrift_Links == "") { DocData.Unterschrift_Links = "0"; }
|
||||
if (DocData.Unterschrift_Rechts == "") { DocData.Unterschrift_Rechts = "0"; }
|
||||
dok.iUnterschriftlinks = Convert.ToInt32(DocData.Unterschrift_Links);
|
||||
dok.iUnterschriftrechts = Convert.ToInt32(DocData.Unterschrift_Rechts);
|
||||
//db.Get_Mitarbeiternr(DocData.Unterschrift_Links);
|
||||
@@ -360,16 +361,16 @@ namespace Database
|
||||
{
|
||||
dok.iColdstatus = 0;
|
||||
}
|
||||
|
||||
|
||||
db.Get_Tabledata("Select * from office_vorlage where office_vorlagenr=" + doktyp.iOffice_vorlagenr.ToString(),false,true);
|
||||
|
||||
|
||||
db.Get_Tabledata("Select * from office_vorlage where office_vorlagenr=" + doktyp.iOffice_vorlagenr.ToString(), false, true);
|
||||
string dokumentname = "";
|
||||
string ext = "";
|
||||
switch (Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["Anwendungnr"]))
|
||||
{
|
||||
case 1: { ext = ".doc"; break; }
|
||||
case 2: { ext = ".xls"; break; }
|
||||
case 3: { ext= ".pdf"; break; }
|
||||
case 3: { ext = ".pdf"; break; }
|
||||
case 4: { ext = ".docx"; break; }
|
||||
case 5: { ext = ".docm"; break; }
|
||||
case 6: { ext = ".dotx"; break; }
|
||||
@@ -683,7 +684,7 @@ namespace Database
|
||||
|
||||
|
||||
}
|
||||
public bool Save_To_DB(string sDokumentID, string sDokumentName)
|
||||
public bool Save_To_DB(string sDokumentID, string sDokumentName)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -744,7 +745,7 @@ namespace Database
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
SqlConnection Connection = new SqlConnection();
|
||||
SqlDataAdapter DA = new SqlDataAdapter("select top 1 * from office_vorlage_datei where office_vorlage_dateinr='" + office_vorlage_nr + "'", Connection);
|
||||
SqlCommandBuilder cb = new SqlCommandBuilder(DA);
|
||||
@@ -798,15 +799,15 @@ namespace Database
|
||||
|
||||
public DataTable Get_DokumentWertList(string dokumentid, int dokumenttypnr)
|
||||
{
|
||||
|
||||
|
||||
var scmCmdToExecute = new SqlCommand();
|
||||
var dtToReturn = new DataTable();
|
||||
var sdaAdapter = new SqlDataAdapter(scmCmdToExecute);
|
||||
SqlConnection Connection = new SqlConnection();
|
||||
Connection.ConnectionString=connectionstring;
|
||||
Connection.ConnectionString = connectionstring;
|
||||
scmCmdToExecute.CommandText = "dbo.SP_Dokumentbearbeitung_Dokumentwerte";
|
||||
scmCmdToExecute.CommandType = CommandType.StoredProcedure;
|
||||
scmCmdToExecute.Connection=Connection;
|
||||
scmCmdToExecute.Connection = Connection;
|
||||
try
|
||||
{
|
||||
scmCmdToExecute.Parameters.Add(new SqlParameter("@dokumentid", SqlDbType.VarChar, 22, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, dokumentid));
|
||||
@@ -853,137 +854,154 @@ namespace Database
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Returns a string containing all the fields in the table
|
||||
|
||||
public string BuildAllFieldsSQL(DataTable table)
|
||||
// Returns a string containing all the fields in the table
|
||||
|
||||
public string BuildAllFieldsSQL(DataTable table)
|
||||
{
|
||||
string sql = "";
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
string sql = "";
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
if (sql.Length > 0)
|
||||
sql += ", ";
|
||||
sql += column.ColumnName;
|
||||
}
|
||||
return sql;
|
||||
if (sql.Length > 0)
|
||||
sql += ", ";
|
||||
sql += column.ColumnName;
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
// Returns a SQL INSERT command. Assumes autoincrement is identity (optional)
|
||||
// Returns a SQL INSERT command. Assumes autoincrement is identity (optional)
|
||||
|
||||
public string BuildInsertSQL(DataTable table)
|
||||
public string BuildInsertSQL(DataTable table)
|
||||
{
|
||||
StringBuilder sql = new StringBuilder("INSERT INTO " + table.TableName + " (");
|
||||
StringBuilder values = new StringBuilder("VALUES (");
|
||||
bool bFirst = true;
|
||||
bool bIdentity = false;
|
||||
string identityType = null;
|
||||
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
StringBuilder sql = new StringBuilder("INSERT INTO " + table.TableName + " (");
|
||||
StringBuilder values = new StringBuilder("VALUES (");
|
||||
bool bFirst = true;
|
||||
bool bIdentity = false;
|
||||
string identityType = null;
|
||||
|
||||
foreach (DataColumn column in table.Columns)
|
||||
if (column.AutoIncrement)
|
||||
{
|
||||
if (column.AutoIncrement)
|
||||
{
|
||||
bIdentity = true;
|
||||
bIdentity = true;
|
||||
|
||||
switch (column.DataType.Name)
|
||||
{
|
||||
case "Int16":
|
||||
identityType = "smallint";
|
||||
break;
|
||||
case "SByte":
|
||||
identityType = "tinyint";
|
||||
break;
|
||||
case "Int64":
|
||||
identityType = "bigint";
|
||||
break;
|
||||
case "Decimal":
|
||||
identityType = "decimal";
|
||||
break;
|
||||
default:
|
||||
identityType = "int";
|
||||
break;
|
||||
}
|
||||
switch (column.DataType.Name)
|
||||
{
|
||||
case "Int16":
|
||||
identityType = "smallint";
|
||||
break;
|
||||
case "SByte":
|
||||
identityType = "tinyint";
|
||||
break;
|
||||
case "Int64":
|
||||
identityType = "bigint";
|
||||
break;
|
||||
case "Decimal":
|
||||
identityType = "decimal";
|
||||
break;
|
||||
default:
|
||||
identityType = "int";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bFirst)
|
||||
bFirst = false;
|
||||
else
|
||||
{
|
||||
if (bFirst)
|
||||
bFirst = false;
|
||||
else
|
||||
{
|
||||
sql.Append(", ");
|
||||
values.Append(", ");
|
||||
}
|
||||
|
||||
sql.Append(column.ColumnName);
|
||||
values.Append("@");
|
||||
values.Append(column.ColumnName);
|
||||
sql.Append(", ");
|
||||
values.Append(", ");
|
||||
}
|
||||
|
||||
sql.Append(column.ColumnName);
|
||||
values.Append("@");
|
||||
values.Append(column.ColumnName);
|
||||
}
|
||||
sql.Append(") ");
|
||||
sql.Append(values.ToString());
|
||||
}
|
||||
sql.Append(") ");
|
||||
sql.Append(values.ToString());
|
||||
sql.Append(")");
|
||||
|
||||
if (bIdentity)
|
||||
{
|
||||
sql.Append("; SELECT CAST(scope_identity() AS ");
|
||||
sql.Append(identityType);
|
||||
sql.Append(")");
|
||||
|
||||
if (bIdentity)
|
||||
{
|
||||
sql.Append("; SELECT CAST(scope_identity() AS ");
|
||||
sql.Append(identityType);
|
||||
sql.Append(")");
|
||||
}
|
||||
|
||||
return sql.ToString(); ;
|
||||
}
|
||||
|
||||
|
||||
// Creates a SqlParameter and adds it to the command
|
||||
|
||||
public void InsertParameter(SqlCommand command,
|
||||
string parameterName,
|
||||
string sourceColumn,
|
||||
object value)
|
||||
{
|
||||
SqlParameter parameter = new SqlParameter(parameterName, value);
|
||||
|
||||
parameter.Direction = ParameterDirection.Input;
|
||||
parameter.ParameterName = parameterName;
|
||||
parameter.SourceColumn = sourceColumn;
|
||||
parameter.SourceVersion = DataRowVersion.Current;
|
||||
|
||||
command.Parameters.Add(parameter);
|
||||
}
|
||||
|
||||
// Creates a SqlCommand for inserting a DataRow
|
||||
public SqlCommand CreateInsertCommand(DataRow row)
|
||||
{
|
||||
DataTable table = row.Table;
|
||||
string sql = BuildInsertSQL(table);
|
||||
SqlCommand command = new SqlCommand(sql);
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
if (!column.AutoIncrement)
|
||||
{
|
||||
string parameterName = "@" + column.ColumnName;
|
||||
InsertParameter(command, parameterName,
|
||||
column.ColumnName,
|
||||
row[column.ColumnName]);
|
||||
}
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
// Inserts the DataRow for the connection, returning the identity
|
||||
public object InsertDataRow(DataRow row, string connectionString)
|
||||
{
|
||||
SqlCommand command = CreateInsertCommand(row);
|
||||
|
||||
using (SqlConnection connection = new SqlConnection(connectionString))
|
||||
{
|
||||
command.Connection = connection;
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
connection.Open();
|
||||
return command.ExecuteScalar();
|
||||
}
|
||||
}
|
||||
|
||||
return sql.ToString(); ;
|
||||
}
|
||||
|
||||
|
||||
// Creates a SqlParameter and adds it to the command
|
||||
|
||||
public void InsertParameter(SqlCommand command,
|
||||
string parameterName,
|
||||
string sourceColumn,
|
||||
object value)
|
||||
{
|
||||
SqlParameter parameter = new SqlParameter(parameterName, value);
|
||||
|
||||
parameter.Direction = ParameterDirection.Input;
|
||||
parameter.ParameterName = parameterName;
|
||||
parameter.SourceColumn = sourceColumn;
|
||||
parameter.SourceVersion = DataRowVersion.Current;
|
||||
|
||||
command.Parameters.Add(parameter);
|
||||
}
|
||||
|
||||
// Creates a SqlCommand for inserting a DataRow
|
||||
public SqlCommand CreateInsertCommand(DataRow row)
|
||||
{
|
||||
DataTable table = row.Table;
|
||||
string sql = BuildInsertSQL(table);
|
||||
SqlCommand command = new SqlCommand(sql);
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
if (!column.AutoIncrement)
|
||||
{
|
||||
string parameterName = "@" + column.ColumnName;
|
||||
InsertParameter(command, parameterName,
|
||||
column.ColumnName,
|
||||
row[column.ColumnName]);
|
||||
}
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
// Inserts the DataRow for the connection, returning the identity
|
||||
public object InsertDataRow(DataRow row, string connectionString)
|
||||
{
|
||||
SqlCommand command = CreateInsertCommand(row);
|
||||
|
||||
using (SqlConnection connection = new SqlConnection(connectionString))
|
||||
{
|
||||
command.Connection = connection;
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
connection.Open();
|
||||
return command.ExecuteScalar();
|
||||
}
|
||||
}
|
||||
|
||||
public void insert_note(int ersteller, string gbetreff, string note, string dokumentid)
|
||||
{
|
||||
Get_Tabledata_for_Update("Select top 1 * from notizen where notiznr=-1", false, true);
|
||||
DataRow dr = daten.Tables[0].NewRow();
|
||||
dr["dokumentid"] = dokumentid;
|
||||
dr["betreff"] = gbetreff;
|
||||
dr["notiz"] = note;
|
||||
dr["mandantnr"] = 1;
|
||||
dr["aktiv"] = 1;
|
||||
dr["erstellt_am"] = DateTime.Now;
|
||||
dr["mutiert_am"] = DateTime.Now;
|
||||
dr["mutierer"] = ersteller;
|
||||
dr["ersteller"] = ersteller;
|
||||
daten.Tables[0].Rows.Add(dr);
|
||||
Update_Data();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user