using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using edoka_dms; using System.IO; using System.Xml.Linq; using Model; using System.Security.Cryptography; using System.Diagnostics.Eventing.Reader; using Logging; using System.Configuration; namespace Database { public class DB { public string connectionstring; public DataSet dsdaten = new DataSet(); private static DataTable SP_Parameters = new DataTable(); public DB(string connectionstring) { this.connectionstring = connectionstring; } public DB() { } public void add_parameter(string name, string value) { DataRow r = SP_Parameters.NewRow(); r[0] = name; r[1] = value; SP_Parameters.Rows.Add(r); } public void clear_parameter() { SP_Parameters.Columns.Clear(); SP_Parameters.Rows.Clear(); SP_Parameters.Clear(); SP_Parameters.Columns.Add("Paramname"); SP_Parameters.Columns.Add("Paramvalue"); } #region "Allgemein" public DataTable Get_Tabledata(string Tablename, bool StoredProc = false, bool is_SQL_String = false, DataTable sp_params = null) { try { if (sp_params == null && SP_Parameters.Rows.Count > 0) { sp_params = SP_Parameters.Copy(); } SqlConnection sqlconnect = new SqlConnection(); DataSet ds = new DataSet(); ds.Tables.Clear(); dsdaten.Tables.Clear(); sqlconnect.ConnectionString = connectionstring; 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; try { foreach (DataRow r in sp_params.Rows) { sqlcmd.Parameters.Add(r["Paramname"].ToString(), SqlDbType.VarChar); sqlcmd.Parameters[sqlcmd.Parameters.Count - 1].Value = r["Paramvalue"].ToString(); } } catch { }; } else { sqlcmd.CommandType = CommandType.Text; sqlcmd.CommandText = "Select * from " + Tablename; } if (is_SQL_String == true) sqlcmd.CommandText = Tablename; da.SelectCommand = sqlcmd; sqlconnect.Open(); da.Fill(dsdaten, "Daten1"); sqlconnect.Close(); Logging.Logging.Debug("", "EDOKA_DB:Get_Tabledata:" + Tablename, ""); return dsdaten.Tables[0]; } catch (Exception ex) { Logging.Logging.Error(ex.Message, "EDOKA_DB:Get_Tabledata:" + Tablename, ""); return null; } } public void Exec_SQL(string sql) { SqlConnection sqlconnect = new SqlConnection(); SqlCommand sqlcmd = new SqlCommand(); sqlcmd.Connection = sqlconnect; sqlconnect.ConnectionString = this.connectionstring; sqlcmd.CommandType = CommandType.Text; sqlcmd.CommandText = sql; sqlcmd.Connection.Open(); sqlcmd.ExecuteNonQuery(); sqlcmd.Connection.Close(); } private SqlDataAdapter da; private SqlCommandBuilder qb = new SqlCommandBuilder(); public DataSet daten = new DataSet(); public void Get_Tabledata_for_Update(string Tablename, bool StoredProc = false, bool is_SQL_String = false) { var sqlconnect = new SqlConnection(); var ds = new DataSet(); ds.Tables.Clear(); sqlconnect.ConnectionString = connectionstring; sqlconnect.Open(); da = new SqlDataAdapter("", sqlconnect); var sqlcmd = new SqlCommand(); sqlcmd.Connection = sqlconnect; if (StoredProc == true) { sqlcmd.CommandType = CommandType.StoredProcedure; 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(daten, "Daten"); qb = new SqlCommandBuilder(da); //return default; } public void Update_Data() { da.Update(daten, "Daten"); //SqlDataAdapter dadaten = new SqlDataAdapter(); //var cb = new SqlCommandBuilder(dadaten); //dadaten.Update(dsdaten, dsdaten.Tables[0].TableName); //cb.Dispose(); } #endregion public string get_dbkey(string Tablename) { clsMyKey_Tabelle myKey_Tabelle = new clsMyKey_Tabelle(); myKey_Tabelle.connectionstring = connectionstring; string dbkey = myKey_Tabelle.get_dbkey(Tablename).ToString(); if (Tablename == "Dokument") { string skey = "OFFEDK000"; string s = ""; s = DateTime.Now.Year.ToString().Trim(); string dt = s; skey = skey + s; while (dbkey.Length < 8) { dbkey = "0" + dbkey; } skey = skey + dbkey; s = Helper.DivFnkt.modulo10(dt + dbkey).ToString(); skey = skey + s; return skey; } else { return dbkey; } } public int Get_Mitarbeiternr(string mitarbeiter) { try { if (mitarbeiter == "") { return 0; } if (Helper.DivFnkt.IsNumeric(mitarbeiter)) { return Convert.ToInt32(mitarbeiter); } Get_Tabledata("Select * from mitarbeiter where tgnummer='" + mitarbeiter + "'", false, true); if (dsdaten.Tables[0].Rows.Count < 1) { return 0; } else { return Convert.ToInt32(dsdaten.Tables[0].Rows[0]["mitarbeiternr"].ToString()); } } catch { return 0; } } public int Get_Teamnr(string mitarbeiternr) { try { if (mitarbeiternr == "") { return 0; } Get_Tabledata("Select team from profil where standard=1 and aktiv=1 and mitarbeiternr=" + mitarbeiternr + "", false, true); if (dsdaten.Tables[0].Rows.Count < 1) { return 0; } else { return Convert.ToInt32(dsdaten.Tables[0].Rows[0]["team"].ToString()); } } catch { return 0; } } public DataTable Get_Vorlage_By_DokumentID(string dokumentid) { string sql = "Select dbo.BinaryToBase64(vorlage) as Data, dbo.office_vorlage_datei.office_vorlagenr as nr from dbo.Office_Vorlage_Datei INNER JOIN "; sql = sql + " dbo.office_vorlage ON dbo.Office_Vorlage_Datei.office_vorlage_dateinr = dbo.office_vorlage.office_vorlagenr INNER JOIN "; sql = sql + "dbo.dokumenttyp INNER JOIN "; sql = sql + "dbo.dokument ON dbo.dokumenttyp.dokumenttypnr = dbo.dokument.dokumenttypnr ON dbo.office_vorlage.office_vorlagenr = dbo.dokumenttyp.office_vorlagenr "; sql = sql + "WHERE dbo.dokument.dokumentid = '" + dokumentid + "' "; Get_Tabledata(sql, false, true); return dsdaten.Tables[0]; } public string Get_Office_Vorlage_asBase64(string nr) { string sql = "Select dbo.BinaryToBase64(vorlage) as Data from office_vorlage_datei where office_vorlage_dateinr=" + nr; Get_Tabledata(sql, false, true); return dsdaten.Tables[0].Rows[0][0].ToString(); } 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(); SqlDataReader sqldr = sc.ExecuteReader(); while (sqldr.Read()) { string filename = tempdir + @"\" + dokumentid; byte[] attachment = (byte[])sqldr.GetValue(0); FileStream fs = new FileStream(filename, FileMode.Create); fs.Write(attachment, 0, attachment.Length); fs.Close(); } conn.Close(); return ""; } public DataTable Get_ApplicationType_from_Vorlage(int vorlagenr) { string sql = "SELECT RIGHT(dbo.anwendung.bezeichnung, CHARINDEX(' ', REVERSE(dbo.anwendung.bezeichnung)) - 1) AS ApplType, "; sql = sql + " RIGHT(dbo.Office_Vorlage_Datei.dateiname, CHARINDEX('.', REVERSE(dbo.Office_Vorlage_Datei.dateiname)) - 1) as Extension"; sql = sql + " FROM dbo.office_vorlage INNER JOIN dbo.anwendung ON dbo.office_vorlage.anwendungnr = dbo.anwendung.anwendungnr INNER JOIN"; sql = sql + " dbo.Office_Vorlage_Datei ON dbo.office_vorlage.office_vorlagenr = dbo.Office_Vorlage_Datei.office_vorlagenr "; sql = sql + "WHERE dbo.office_vorlage.office_vorlagenr = " + vorlagenr.ToString(); // string sql = "Select RIGHT(dbo.anwendung.bezeichnung, CHARINDEX(' ', REVERSE(dbo.anwendung.bezeichnung)) - 1) AS Expr1 FROM dbo.office_vorlage INNER JOIN dbo.anwendung ON dbo.office_vorlage.anwendungnr = dbo.anwendung.anwendungnr where dbo.office_vorlage.office_vorlagenr=" + vorlagenr.ToString(); Get_Tabledata(sql, false, true); return dsdaten.Tables[0]; } #region "EDOKA_Datenbank" public string Create_EDOKA_Doc(clsDocData DocData) { DB db = new DB(connectionstring); string dokumentid = ""; dokumentid = db.get_dbkey("Dokument"); clsDokument dok = new clsDokument(); clsDokumenttyp doktyp = new clsDokumenttyp(); clsConnectionProvider edoka_conn = new clsConnectionProvider(); edoka_conn.sConnectionString = this.connectionstring; doktyp.cpMainConnectionProvider = edoka_conn; doktyp.iDokumenttypnr = Convert.ToInt32(DocData.DokumenttypNr); doktyp.SelectOne(); dok.cpMainConnectionProvider = edoka_conn; dok.sDokumentid = dokumentid; dok.bAktiv = true; dok.bAmsdokument = false; dok.bAuserstuebernahme = false; dok.bAusgangsarchiviert = false; dok.daTermin = Convert.ToDateTime("1900.01.01"); dok.bBereit_zur_archivierung = false; dok.bEingangsarchiviert = false; dok.bGesperrt = false; 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"; } dok.iUnterschriftlinks = Convert.ToInt32(DocData.Unterschrift_Links); dok.iUnterschriftrechts = Convert.ToInt32(DocData.Unterschrift_Rechts); //db.Get_Mitarbeiternr(DocData.Unterschrift_Links); //dok.iUnterschriftrechts = db.Get_Mitarbeiternr(DocData.Unterschrift_Rechts); dok.iErsteller = Convert.ToInt32(DocData.Ersteller); dok.iVerantwortlich = Convert.ToInt32(DocData.Verantwortlich); dok.sBezeichnung = DocData.Bezeichnung; dok.bVertraulich = false; dok.sZustelladresse = ""; dok.sAnredezustelladresse = ""; dok.iZustaendiger = Convert.ToInt32(DocData.Zustaendig); dok.iPostzustellung = 0; dok.bZustaendig_kube = false; dok.iMa_ausgangsarchivierung = 0; dok.iMa_eingangsarchivierung = 0; dok.sBemerkung = ""; dok.sColddokumentid = ""; dok.iDokdurchkubeweitergegeben = 0; dok.sBedRDokumentid = ""; dok.iDokumenttypnr = doktyp.iDokumenttypnr; dok.bZu_retournieren = doktyp.bZu_retournieren; dok.iAufbewahrung_elektronisch = doktyp.iAufbewahrungsfrist_elektronisch; dok.iAufbewahrung_phaysisch = doktyp.iAufbewahrungsfrist_physisch; dok.iBearbeitung_nach_abschluss = doktyp.iTage_mutation; dok.iBearbeitungszeit_in_minuten = doktyp.iDbearbeitungszeit; dok.iMonierung_in_tagen = doktyp.iAnzahl_tage; dok.sBezeichnung = doktyp.sBezeichnung; dok.iNrpar00 = Convert.ToInt32(DocData.PartnerNr); dok.iMutierer = dok.iErsteller; dok.iMitarbeiternr = dok.iErsteller; dok.daMutiertam = DateTime.Now; dok.daErstelltam = DateTime.Now; dok.iMutiererteam = Convert.ToInt32(DocData.Team); dok.iMutierertieam = Convert.ToInt32(DocData.Team); dok.iErstellerteam = Convert.ToInt32(DocData.Team); ; dok.daErstellungsdatum = Convert.ToDateTime(DocData.DokumentDatum); if (doktyp.bElDokImport == true) { dok.iColdstatus = 1; } else { dok.iColdstatus = 0; } 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 4: { ext = ".docx"; break; } case 5: { ext = ".docm"; break; } case 6: { ext = ".dotx"; break; } case 7: { ext = ".dotm"; break; } case 8: { ext = ".xlsx"; break; } case 9: { ext = ".xlsm"; break; } case 10: { ext = ".xltx"; break; } case 11: { ext = ".xltm"; break; } case 12: { ext = ".pdf"; break; } case 13: { ext = ".pdf"; break; } } if (DocData.Result_as_PDF == "True") { ext = ".pdf"; } dokumentname = db.dsdaten.Tables[0].Rows[0]["Prefix_Dokumentname"].ToString() + dokumentid + ext; dok.sDokumentname = dokumentname; dok.cpMainConnectionProvider = edoka_conn; edoka_conn.OpenConnection(); dok.Insert(); edoka_conn.CloseConnection(true); COLD_Index_Sichern(1, dokumentid); if (dok.bZu_retournieren == true) { COLD_Index_Sichern(2, dokumentid); } Status_Erstellen(dokumentid, false); dok.iStatusnr = Convert.ToInt32(get_current_Status(dokumentid).ToString()); edoka_conn.OpenConnection(); dok.Update(); edoka_conn.CloseConnection(true); return dokumentid; } public DataTable COLD_Index_Sichern(int indextyp, string dokumentid) { SqlCommand scmCmdToExecute = new SqlCommand(); scmCmdToExecute.CommandText = "dbo.SP_Dokument_Cold_Index"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; DataTable dtToReturn = new DataTable(); SqlDataAdapter sdaAdapter = new SqlDataAdapter(scmCmdToExecute); SqlConnection conn = new SqlConnection(connectionstring); scmCmdToExecute.Connection = conn; try { scmCmdToExecute.Parameters.Add(new SqlParameter("@dokumentid", SqlDbType.VarChar, 22, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, dokumentid)); scmCmdToExecute.Parameters.Add(new SqlParameter("@indextyp", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, indextyp)); sdaAdapter.Fill(dtToReturn); return dtToReturn; } catch (Exception ex) { throw new Exception("Dokumenterstellung::Generic_Select::" + scmCmdToExecute.CommandText + "::Error occured." + ex.Message, ex); } finally { scmCmdToExecute.Dispose(); sdaAdapter.Dispose(); } } public object Status_Erstellen(string dokumentid, bool blsequenz) { // Status_Erstellen_Overwrite(dokumentid, 0) var scmCmdToExecute = new SqlCommand(); var dtToReturn = new DataTable(); var sdaAdapter = new SqlDataAdapter(scmCmdToExecute); scmCmdToExecute.CommandText = "dbo.sp_dokumentberabeigung_status_erstellen"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; SqlConnection conn = new SqlConnection(connectionstring); scmCmdToExecute.Connection = conn; try { scmCmdToExecute.Parameters.Add(new SqlParameter("@dokumentid", SqlDbType.VarChar, 22, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, dokumentid)); scmCmdToExecute.Parameters.Add(new SqlParameter("@bck", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); scmCmdToExecute.Parameters.Add(new SqlParameter("@blsequenz", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); sdaAdapter.Fill(dtToReturn); return dtToReturn; } catch (Exception ex) { // // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("Dokument_Information_Wert::" + scmCmdToExecute.CommandText + "::Error occured." + ex.Message, ex); } finally { scmCmdToExecute.Dispose(); sdaAdapter.Dispose(); } } private long get_current_Status(string dokumentid) { long get_current_StatusRet = default; var scmCmdToExecute = new SqlCommand(); scmCmdToExecute.CommandText = "dbo.SP_Dokumentbearbeitung_current_status"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; var dtToReturn = new DataTable(); var sdaAdapter = new SqlDataAdapter(scmCmdToExecute); SqlConnection conn = new SqlConnection(connectionstring); scmCmdToExecute.Connection = conn; try { scmCmdToExecute.Parameters.Add(new SqlParameter("@statustext", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, "In Bearbeitung")); scmCmdToExecute.Parameters.Add(new SqlParameter("@dokumentid", SqlDbType.VarChar, 22, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, dokumentid)); scmCmdToExecute.Parameters.Add(new SqlParameter("@currentstatus", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, 0)); sdaAdapter.Fill(dtToReturn); get_current_StatusRet = Convert.ToInt64(scmCmdToExecute.Parameters[2].Value); return get_current_StatusRet; } catch (Exception ex) { // // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("Dokumenterstellung::Generic_Select::" + scmCmdToExecute.CommandText + "::Error occured." + ex.Message, ex); } finally { scmCmdToExecute.Dispose(); sdaAdapter.Dispose(); } } #endregion public DataTable Get_Partnerstruktur(int partnernr, bool partnerlist, int mitarbeiternr, int profilnr) { SqlConnection conn = new SqlConnection(connectionstring); var scmCmdToExecute = new SqlCommand(); scmCmdToExecute.Connection = conn; scmCmdToExecute.CommandText = "dbo.[sp_trefferliste_getdata_new_relaunch]"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; var dtToReturn = new DataTable(); var sdaAdapter = new SqlDataAdapter(scmCmdToExecute); scmCmdToExecute.Connection.ConnectionString = connectionstring; try { if (partnernr == -1) { partnernr = 0; } scmCmdToExecute.Parameters.Add(new SqlParameter("@profilnr", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, profilnr)); scmCmdToExecute.Parameters.Add(new SqlParameter("@inrpar00", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, partnernr)); scmCmdToExecute.Parameters.Add(new SqlParameter("@isprache", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); scmCmdToExecute.Parameters.Add(new SqlParameter("@imandant", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); scmCmdToExecute.Parameters.Add(new SqlParameter("@doklist", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); scmCmdToExecute.Parameters.Add(new SqlParameter("@partnerlist", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); scmCmdToExecute.Parameters.Add(new SqlParameter("@doklistdokumentartnr", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); scmCmdToExecute.Parameters.Add(new SqlParameter("@doklistpartnernr", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); if (partnernr == 0) { scmCmdToExecute.Parameters.Add(new SqlParameter("@vollstaendig", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); } else { scmCmdToExecute.Parameters.Add(new SqlParameter("@vollstaendig", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); } if (partnerlist && partnernr != 0) { scmCmdToExecute.Parameters.Add(new SqlParameter("@partnereingegeben", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); } else { scmCmdToExecute.Parameters.Add(new SqlParameter("@partnereingegeben", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); } scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, 0)); scmCmdToExecute.Parameters.Add(new SqlParameter("@ihasmessage", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, 0)); scmCmdToExecute.Parameters.Add(new SqlParameter("@firstentry", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); scmCmdToExecute.Parameters.Add(new SqlParameter("@lastentry", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1000000)); scmCmdToExecute.Parameters.Add(new SqlParameter("@pagedirection", SqlDbType.Int, 4, ParameterDirection.InputOutput, true, 10, 0, "", DataRowVersion.Proposed, 0)); scmCmdToExecute.Parameters.Add(new SqlParameter("@searchstring", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, "")); scmCmdToExecute.Parameters.Add(new SqlParameter("@fanummer3", SqlDbType.VarChar, 128, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, "")); conn.Open(); sdaAdapter.Fill(dtToReturn); return dtToReturn; } catch (Exception ex) { try { //MessageBox.Show(ex.Message, "Fehler Partnerstruktur", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch { } } finally { conn.Close(); scmCmdToExecute.Dispose(); sdaAdapter.Dispose(); } return default; } public DataTable Get_Dokumente(int partnernr, int dokumentartnr, int profilnr, int ForMa, bool alleDokumente = false) { int i; SqlConnection conn = new SqlConnection(connectionstring); var scmCmdToExecute = new SqlCommand(); scmCmdToExecute.Connection = conn; scmCmdToExecute.CommandText = "dbo.SP_Trefferliste_getdata_new_relaunch"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; var dtToReturn = new DataTable(); var sdaAdapter = new SqlDataAdapter(scmCmdToExecute); scmCmdToExecute.Connection.ConnectionString = connectionstring; try { scmCmdToExecute.Parameters.Add(new SqlParameter("@profilnr", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, profilnr)); scmCmdToExecute.Parameters.Add(new SqlParameter("@inrpar00", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, partnernr)); scmCmdToExecute.Parameters.Add(new SqlParameter("@iforMA", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, ForMa)); // ObjPerson - fehler bei der Partnernr scmCmdToExecute.Parameters.Add(new SqlParameter("@isprache", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); scmCmdToExecute.Parameters.Add(new SqlParameter("@imandant", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); scmCmdToExecute.Parameters.Add(new SqlParameter("@doklist", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); scmCmdToExecute.Parameters.Add(new SqlParameter("@partnerlist", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); scmCmdToExecute.Parameters.Add(new SqlParameter("@doklistdokumentartnr", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, dokumentartnr)); scmCmdToExecute.Parameters.Add(new SqlParameter("@doklistpartnernr", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, partnernr)); // if (this.txtnrpar00.Text != "") // { scmCmdToExecute.Parameters.Add(new SqlParameter("@vollstaendig", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); // } // else // { // scmCmdToExecute.Parameters.Add(new SqlParameter("@vollstaendig", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); // } scmCmdToExecute.Parameters.Add(new SqlParameter("@partnereingegeben", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); if (alleDokumente == true) { scmCmdToExecute.Parameters.Add(new SqlParameter("@alledokumente", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); } else { scmCmdToExecute.Parameters.Add(new SqlParameter("@alledokumente", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 0)); } scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, 0)); //if (this.txtnrpar00.Text.Length > 0) //{ // if (this.LblSearch.Text == this.MenuItemValorSuche.Text + ":" & this.txtnrpar00.Text != "") // { // scmCmdToExecute.Parameters.Add(new SqlParameter("@searchstring", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, "VA:" + this.txtnrpar00.Text)); // } // if (this.LblSearch.Text == this.MenuItemISINSUche.Text + ":" & this.txtnrpar00.Text != "") // { // scmCmdToExecute.Parameters.Add(new SqlParameter("@searchstring", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, "IS:" + this.txtnrpar00.Text)); // } // if (this.LblSearch.Text == this.MenuItemVVSuche.Text + ":" & this.txtnrpar00.Text != "") // { // scmCmdToExecute.Parameters.Add(new SqlParameter("@searchstring", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, "VV:" + this.txtnrpar00.Text)); // } //} //else //{ scmCmdToExecute.Parameters.Add(new SqlParameter("@searchstring", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, "")); // } scmCmdToExecute.Parameters.Add(new SqlParameter("@fanummer3", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, "")); sdaAdapter.Fill(dtToReturn); return dtToReturn; } catch (Exception ex) { // MsgBox(ex.Message) // ' // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("Dokumente lesen::" + scmCmdToExecute.CommandText + "::Error occured." + ex.Message, ex); } finally { scmCmdToExecute.Dispose(); sdaAdapter.Dispose(); } } public clsdok GetDocumentAsBase64(string dokumentid) { try { string sql = "Select dbo.BinaryToBase64(dokument) as Data, isnull(doktype,'') as doktype from doks "; sql = sql + "WHERE dbo.doks.dokumentid = '" + dokumentid + "' "; sql = "Select * from View_Get_Base64Doc where dokumentid='" + dokumentid + "' "; Get_Tabledata(sql, false, true); if (dsdaten.Tables[0].Rows.Count < 1) { return new clsdok("", "", ""); } else { if (dsdaten.Tables[0].Rows[0][1].ToString() == "") { try { dsdaten.Tables[0].Rows[0][1] = dsdaten.Tables[0].Rows[0][2].ToString().Substring(0, 1).ToUpper(); } catch { } } return new clsdok(dsdaten.Tables[0].Rows[0][0].ToString(), dsdaten.Tables[0].Rows[0][1].ToString(), dsdaten.Tables[0].Rows[0][2].ToString()); } } catch { return new clsdok("", "", ""); } finally { } } public bool Save_To_DB(string sDokumentID, string sDokumentName, string base64document = "") { try { string DokumentID = sDokumentID; string Dokumentname = sDokumentName; SqlConnection Connection = new SqlConnection(); SqlDataAdapter DA = new SqlDataAdapter("select * from doks where dokumentid='" + DokumentID + "'", Connection); SqlCommandBuilder cb = new SqlCommandBuilder(DA); DataSet ds = new DataSet(); byte [] mydata = null; if (base64document == "") { FileStream fs = new FileStream(Dokumentname, FileMode.Open, FileAccess.Read); mydata = new byte[fs.Length]; fs.Read(mydata, 0, Convert.ToInt32(fs.Length)); fs.Close(); fs = null; } else { mydata = System.Convert.FromBase64String(base64document); } try { Connection.ConnectionString = connectionstring; Connection.Open(); DA.Fill(ds, "docs"); DataRow myRow; if (ds.Tables[0].Rows.Count == 0) { myRow = ds.Tables[0].NewRow(); myRow[0] = DokumentID; myRow[1] = mydata; ds.Tables[0].Rows.Add(myRow); DA.Update(ds, "docs"); } else { myRow = ds.Tables[0].Rows[0]; myRow[1] = mydata; DA.Update(ds, "docs"); } } catch (Exception ex) { return false; } finally { //fs = null; cb = null; ds = null; DA = null; Connection.Close(); Connection = null; } return true; } catch (Exception EX) { return false; } } public Boolean save_vorlage_to_db(string filename, string office_vorlage_nr) { 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); DataSet ds = new DataSet(); FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); byte[] mydata = new byte[fs.Length]; try { fs.Read(mydata, 0, Convert.ToInt32(fs.Length)); fs.Close(); Connection.ConnectionString = connectionstring; Connection.Open(); DA.Fill(ds, "vorlage"); DataRow myRow; if (ds.Tables[0].Rows.Count == 0) { myRow = ds.Tables[0].NewRow(); myRow[0] = ""; myRow[1] = mydata; ds.Tables[0].Rows.Add(myRow); DA.Update(ds, "docs"); } else { myRow = ds.Tables[0].Rows[0]; myRow["vorlage"] = mydata; DA.Update(ds, "vorlage"); } } catch (Exception ex) { return false; } finally { fs = null; cb = null; ds = null; DA = null; Connection.Close(); Connection = null; } return true; } catch (Exception EX) { return false; } return true; } 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; scmCmdToExecute.CommandText = "dbo.SP_Dokumentbearbeitung_Dokumentwerte"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; scmCmdToExecute.Connection = Connection; try { scmCmdToExecute.Parameters.Add(new SqlParameter("@dokumentid", SqlDbType.VarChar, 22, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, dokumentid)); scmCmdToExecute.Parameters.Add(new SqlParameter("@dokumenttypnr", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, dokumenttypnr)); scmCmdToExecute.Parameters.Add(new SqlParameter("@CreateNew", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, 1)); sdaAdapter.Fill(dtToReturn); // Release 4.0 KC 01.06.2007 XMl Daten berücksichtigen (DokumentBearbeitung.edka) //var objDokumentWert = default(AvaloqDokumentWert); //for (int i = 0, loopTo = dtToReturn.Rows.Count - 1; i <= loopTo; i++) //{ // if (!object.ReferenceEquals(dtToReturn.Rows[i][0], DBNull.Value)) // { // // objperson // // objDokumentWert = avqwerte.getAvaloqDokumentWertByName(dtToReturn.Rows(i).Item(0)) // try // { // objDokumentWert = avqwerte.getAvaloqDokumentWertByName(avqwerte.ADokumentwerte, this.DokWertList.Item(i, 0), this.DokWertList.Item(i, 12)); // } // catch // { // } // // objDokumentWert = objAvaloqDokumentWerte.getAvaloqDokumentWertByName(dtToReturn.Rows(i).Item(0)) // } // if (objDokumentWert is null == false) // { // dtToReturn.Rows[i][2] = objDokumentWert.value; // } // objDokumentWert = default; //} return dtToReturn; } catch (Exception ex) { // // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("Dokument_Information_Wert::" + scmCmdToExecute.CommandText + "::Error occured." + ex.Message, ex); } finally { scmCmdToExecute.Dispose(); sdaAdapter.Dispose(); } } // Returns a string containing all the fields in the table public string BuildAllFieldsSQL(DataTable table) { string sql = ""; foreach (DataColumn column in table.Columns) { if (sql.Length > 0) sql += ", "; sql += column.ColumnName; } return sql; } // Returns a SQL INSERT command. Assumes autoincrement is identity (optional) 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) { if (column.AutoIncrement) { 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; } } else { if (bFirst) bFirst = false; else { sql.Append(", "); values.Append(", "); } sql.Append(column.ColumnName); values.Append("@"); values.Append(column.ColumnName); } } sql.Append(") "); sql.Append(values.ToString()); 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(); } } 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(); } } }