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.
896 lines
42 KiB
896 lines
42 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web.Http;
|
|
using DOCGEN;
|
|
using Model;
|
|
using Database;
|
|
using Newtonsoft.Json;
|
|
using API_NetFramework.Models;
|
|
using System.Runtime.Remoting.Messaging;
|
|
using System.IO;
|
|
using System.Web;
|
|
using System.Net.Mime;
|
|
using System.Security.Policy;
|
|
using System.Text;
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
using System.Security.Cryptography;
|
|
using System.Net.Http.Headers;
|
|
using SecuringWebApiUsingApiKey.Middleware;
|
|
using DOCGEN.Klassen;
|
|
using CSVNET;
|
|
using System.Data;
|
|
using Helper;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Web.UI.WebControls;
|
|
using edoka_dms;
|
|
using Microsoft.Ajax.Utilities;
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
|
|
namespace API_NetFramework.Controllers
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <remarks></remarks>
|
|
///
|
|
public class ILResponse
|
|
{
|
|
public int StatusCode;
|
|
public int senderror { get; set; } = 0;
|
|
public string response { get; set; } = "";
|
|
}
|
|
|
|
public enum uploadtype
|
|
{
|
|
fast = 1,
|
|
slow = 2,
|
|
docupload = 3,
|
|
revision = 4
|
|
|
|
}
|
|
|
|
public class ArchivController : ApiController
|
|
{
|
|
// GET: OnBase
|
|
string tokenfunction = "Archiv";
|
|
string connectionstring = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["EDOKAConnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
|
|
|
private void Update_IL_Log(ref ILResponse ilr, string dokumentid)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start Update IL_Log: DokumentID:" + dokumentid, LogLevelType.Debug);
|
|
|
|
DB dB = new DB(StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["JournalConnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm"));
|
|
string sql = "Insert OnDoc_IL_Log (dokumentid, ilresponse,error, erstellt_am) values ('" + dokumentid + "',";
|
|
sql = sql + "'" + ilr.response.ToString() + "',";
|
|
if (ilr.senderror != 0) { sql = sql + "1,"; } else { sql = sql + "0,"; }
|
|
sql = sql + "getdate() )";
|
|
dB.Exec_SQL(sql);
|
|
dB = null;
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Update IL_Log: DokumentID:" + dokumentid, LogLevelType.Debug);
|
|
}
|
|
|
|
private void update_dokumentstatus(string dokumentid)
|
|
{
|
|
DB db = new DB(connectionstring);
|
|
db.dokument_abschliessen(dokumentid);
|
|
db = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// CheckDocID prüft auf eine vorhandene DokumentID in OnDoc (DokumentID OFFEDK... / Barcode-Klenber-Nr)
|
|
/// </summary>
|
|
/// <param name="DokumentID"></param>
|
|
/// <returns>
|
|
/// 200: OK
|
|
/// </returns>
|
|
/// <remarks></remarks>
|
|
[HttpGet]
|
|
[Route("API/CheckDocID")]
|
|
|
|
public IHttpActionResult CheckDocID(string DokumentID)
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start Check DokumentID: DokumentID:" + DokumentID, LogLevelType.Debug);
|
|
Database.DB db = new Database.DB(connectionstring);
|
|
//db.Get_Tabledata("Select * from dokument where dokumentid = '" + DokumentID + "'", false, true);
|
|
|
|
string SQL = "Select * from dokument where dokumentid = @DokumentID";
|
|
db.clear_parameter();
|
|
db.add_parameter("@DokumentID", DokumentID);
|
|
db.Get_Tabledata_Addvar(SQL, false, true);
|
|
if (db.dsdaten.Tables[0].Rows.Count > 0)
|
|
{
|
|
return Ok(DokumentID);
|
|
}
|
|
// db.Get_Tabledata("Select barcodenr from barcodeetikette where dokumentid='" + DokumentID + "'", false, true);
|
|
SQL = "Select barcodenr from barcodeetikette where dokumentid=@DokumentID";
|
|
db.clear_parameter();
|
|
db.add_parameter("@DokumentID", DokumentID);
|
|
db.Get_Tabledata_Addvar(SQL, false, true);
|
|
|
|
if (db.dsdaten.Tables[0].Rows.Count > 0)
|
|
{
|
|
return Ok(DokumentID);
|
|
}
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Check DokumentID: DokumentID:" + DokumentID, LogLevelType.Debug);
|
|
|
|
return Content(HttpStatusCode.NotFound, DokumentID);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// Archiviert das Dokument aus OnDoc in OnBase
|
|
/// </summary>
|
|
/// <param name="DokumentID"></param>
|
|
/// <returns>
|
|
/// Returncode: 200 (OK)
|
|
/// Dokumenthandle aus OnBase
|
|
/// </returns>
|
|
/// <remarks></remarks>
|
|
[HttpGet]
|
|
[Route("API/ArchiveDocFromDatabase")]
|
|
|
|
public IHttpActionResult ArchivDocFromDatabase(string DokumentID, string pdfdoc = "")
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
string ArchivAktiv;
|
|
ArchivAktiv= System.Configuration.ConfigurationManager.AppSettings["ArchivierungAktiv"].ToString();
|
|
if (ArchivAktiv != "True")
|
|
{
|
|
string message = "Hinweismeldung: "+System.Configuration.ConfigurationManager.AppSettings["ArchivierungNoAktivMessage"].ToString();
|
|
return Content(HttpStatusCode.OK, message);
|
|
}
|
|
try
|
|
{
|
|
|
|
string doktypnr = "";
|
|
string extension = "";
|
|
APILogging.Log((HttpRequestMessage)Request, "Start ArchiveDocFromDatabase: DokumentID:" + DokumentID, LogLevelType.Debug);
|
|
DB db = new DB(connectionstring);
|
|
//db.Get_Tabledata("Select dokumenttypnr, dokumentname from dokument where dokumentid='" + DokumentID + "'", false, true);
|
|
|
|
string SQL = "Select dokumenttypnr, dokumentname from dokument where dokumentid=@DokumentID";
|
|
db.clear_parameter();
|
|
db.add_parameter("@DokumentID", DokumentID);
|
|
db.Get_Tabledata_Addvar(SQL, false, true);
|
|
|
|
extension = System.IO.Path.GetExtension(db.dsdaten.Tables[0].Rows[0]["dokumentname"].ToString());
|
|
doktypnr = db.dsdaten.Tables[0].Rows[0][0].ToString();
|
|
//db.Get_Tabledata("Select erstellunginoffice from dokumenttyp where dokumenttypnr="+doktypnr.ToString(), false, true);
|
|
|
|
SQL = "Select erstellunginoffice from dokumenttyp where dokumenttypnr=@doktypnr";
|
|
db.clear_parameter();
|
|
db.add_parameter("@doktypnr", doktypnr);
|
|
db.Get_Tabledata_Addvar(SQL, false, true);
|
|
if (Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["Erstellunginoffice"]))
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, DokumentID + " ErstellungInOffec - EDKB02DMS", LogLevelType.Debug);
|
|
|
|
db.clear_parameter();
|
|
db.add_parameter("@dokumentid", DokumentID);
|
|
if (DokumentID.Contains("OFFEDK008"))
|
|
{
|
|
db.add_parameter("@ondocdoc", "1");
|
|
}
|
|
db.Get_Tabledata("[OnDoc_IRIS_Archivierung]", true, false);
|
|
string returnmessage = db.dsdaten.Tables[0].Rows[0][0].ToString();
|
|
switch (db.dsdaten.Tables[0].Rows[0][1].ToString())
|
|
{
|
|
case "1":
|
|
APILogging.Log((HttpRequestMessage)Request, DokumentID + " Image des Dokuments nicht vorhanden", LogLevelType.Error);
|
|
return Content(HttpStatusCode.NotFound, DokumentID);
|
|
break;
|
|
case "2":
|
|
APILogging.Log((HttpRequestMessage)Request, DokumentID + " nicht vorhanden", LogLevelType.Error);
|
|
return Content(HttpStatusCode.NotFound, DokumentID);
|
|
break;
|
|
case "3":
|
|
APILogging.Log((HttpRequestMessage)Request, db.dsdaten.Tables[0].Rows[0][0].ToString() + DokumentID, LogLevelType.Debug);
|
|
return Content(HttpStatusCode.OK, returnmessage);
|
|
case "0":
|
|
return (ArchivDocFromDatabase(DokumentID));
|
|
case "4":
|
|
APILogging.Log((HttpRequestMessage)Request, "Dokumentarchivierung via EDKB02_DMS ausgelöst" + DokumentID, LogLevelType.Info);
|
|
break;
|
|
case "5":
|
|
APILogging.Log((HttpRequestMessage)Request, "Dokument bereit zur Ausgangsarchivierung" + DokumentID, LogLevelType.Info);
|
|
break;
|
|
case "6":
|
|
APILogging.Log((HttpRequestMessage)Request, "Dokument in EDOKA abgeschlossen" + DokumentID, LogLevelType.Info);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
};
|
|
return Content(HttpStatusCode.OK, DokumentID + " archiviert");
|
|
}
|
|
|
|
|
|
|
|
|
|
db.clear_parameter();
|
|
db.add_parameter("@dokumentid", DokumentID);
|
|
db.Get_Tabledata("[sp_Get_OnDoc_Parameters]", true, false);
|
|
|
|
bool revisionupload = false;
|
|
string revisionhandle = "";
|
|
foreach (System.Data.DataRow dr in db.dsdaten.Tables[1].Rows)
|
|
{
|
|
if (dr[0].ToString() == "Handle" && dr[1].ToString() != "")
|
|
{
|
|
revisionhandle = dr[1].ToString();
|
|
revisionupload = true;
|
|
}
|
|
}
|
|
|
|
OnBaseDocUpload.OnBaseDokument onbasedoc = new OnBaseDocUpload.OnBaseDokument();
|
|
OnBaseDocUpload.OnBaseDokument_Revision onbasedoc_revision = new OnBaseDocUpload.OnBaseDokument_Revision();
|
|
|
|
DocGet dg = new DocGet(connectionstring);
|
|
clsdok dok = new clsdok("", "", "", "");
|
|
|
|
string[] officeformat = System.Configuration.ConfigurationManager.AppSettings["ArchivierungOfficeFormat"].ToString().Split(',');
|
|
string[] excelconvert = System.Configuration.ConfigurationManager.AppSettings["ExcelDokType"].ToString().Split(',');
|
|
string excelvaluefile = System.Configuration.ConfigurationManager.AppSettings["ExcelValueFile"].ToString();
|
|
if (excelconvert.Contains(doktypnr))
|
|
{
|
|
var settings = new CSVSettings()
|
|
{
|
|
FieldDelimiter = ';',
|
|
TextQualifier = '\'',
|
|
ForceQualifiers = true
|
|
};
|
|
DataTable dt = CSVDataTable.FromFile(excelvaluefile, settings);
|
|
DataTable dt1 = dt.Copy();
|
|
dt1.Rows.Clear();
|
|
foreach (System.Data.DataRow dr in dt.Rows)
|
|
{
|
|
if (dr[0].ToString() == doktypnr.ToString()) { dt1.ImportRow(dr); }
|
|
}
|
|
dt.Dispose();
|
|
dt1.Columns.Add("value");
|
|
|
|
|
|
Excel_Reader reader = new Excel_Reader();
|
|
dok = dg.GetDoc(DokumentID);
|
|
|
|
DB db1 = new DB(connectionstring);
|
|
reader.get_valus_from_excel(ref dt1, dok.dokument);
|
|
foreach (System.Data.DataRow dr in dt1.Rows)
|
|
{
|
|
try
|
|
{
|
|
db1.clear_parameter();
|
|
db1.add_parameter("@dokumentid", DokumentID);
|
|
db1.add_parameter("@vorlagenfeldnr", dr["valuenr"].ToString());
|
|
db1.add_parameter("@value", dr["bezeichnung"].ToString() + ";" + dr["value"].ToString());
|
|
db1.Get_Tabledata("dbo.SP_Dokument_Information_Wert", true, false);
|
|
}
|
|
catch { }
|
|
}
|
|
db1 = null;
|
|
dt = null;
|
|
reader = null;
|
|
db.clear_parameter();
|
|
db.add_parameter("@dokumentid", DokumentID);
|
|
db.Get_Tabledata("[sp_Get_OnDoc_Parameters]", true, false);
|
|
}
|
|
if (officeformat.Contains(doktypnr) || extension.ToUpper() == "PDF")
|
|
{
|
|
dg.GetDoc(DokumentID);
|
|
extension = extension.ToUpper().Replace(".", "");
|
|
}
|
|
else
|
|
{
|
|
dok = dg.GetDocAsPDF(DokumentID);
|
|
extension = "PDF";
|
|
}
|
|
|
|
if (!revisionupload) {
|
|
if (db.dsdaten.Tables[0].Rows[0]["BpNummer"].ToString() == "")
|
|
{
|
|
onbasedoc.personNummer = db.dsdaten.Tables[0].Rows[0]["PersonNummer"].ToString();
|
|
onbasedoc.bpNummer = "";
|
|
}
|
|
else
|
|
{
|
|
onbasedoc.bpNummer = db.dsdaten.Tables[0].Rows[0]["BpNummer"].ToString();
|
|
onbasedoc.personNummer = "";
|
|
}
|
|
onbasedoc.dokumentDatum = db.dsdaten.Tables[0].Rows[0]["DokumentDatum"].ToString();
|
|
onbasedoc.dokumentTyp = db.dsdaten.Tables[0].Rows[0]["dokumenttyp"].ToString(); ;
|
|
onbasedoc.dateiTyp = extension;
|
|
var Attribute = new List<Model.OnBaseDocUpload.attribute>();
|
|
onbasedoc.attributes = new List<Model.OnBaseDocUpload.attribute>();
|
|
foreach (System.Data.DataRow rw in db.dsdaten.Tables[1].Rows)
|
|
{
|
|
OnBaseDocUpload.attribute na = new OnBaseDocUpload.attribute(rw["fieldname"].ToString(), rw["fieldvalue"].ToString());
|
|
onbasedoc.attributes.Add(na);
|
|
}
|
|
onbasedoc.dokumentDatei = dok.dokument;
|
|
|
|
if (pdfdoc != "")
|
|
{
|
|
onbasedoc.dokumentDatei = pdfdoc;
|
|
}
|
|
}
|
|
else {
|
|
onbasedoc_revision.dokumentHandle = revisionhandle;
|
|
onbasedoc_revision.dokumentTyp = db.dsdaten.Tables[0].Rows[0]["dokumenttyp"].ToString(); ;
|
|
onbasedoc_revision.dateiTyp = extension;
|
|
var Attribute = new List<Model.OnBaseDocUpload.attribute>();
|
|
onbasedoc_revision.attributes = new List<Model.OnBaseDocUpload.attribute>();
|
|
onbasedoc_revision.comment = "";
|
|
foreach (System.Data.DataRow rw in db.dsdaten.Tables[1].Rows)
|
|
{
|
|
if (rw[0].ToString() != "Handle") {
|
|
OnBaseDocUpload.attribute na = new OnBaseDocUpload.attribute(rw["fieldname"].ToString(), rw["fieldvalue"].ToString());
|
|
onbasedoc_revision.attributes.Add(na);
|
|
}
|
|
}
|
|
onbasedoc_revision.dokumentDatei = dok.dokument;
|
|
if (pdfdoc != "")
|
|
{
|
|
onbasedoc_revision.dokumentDatei = pdfdoc;
|
|
}
|
|
|
|
}
|
|
db = null;
|
|
ILResponse ilr = new ILResponse();
|
|
string debugfilename = System.Configuration.ConfigurationManager.AppSettings["JSONDebugPath"];
|
|
string SendToOnBase = System.Configuration.ConfigurationManager.AppSettings["SendToOnBase"];
|
|
string SendToFile = System.Configuration.ConfigurationManager.AppSettings["SendToFile"];
|
|
string debugdir = System.Configuration.ConfigurationManager.AppSettings["DebugDir"];
|
|
string jsonstring = "";
|
|
if (!revisionupload)
|
|
{
|
|
jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(onbasedoc);
|
|
}
|
|
else
|
|
{
|
|
jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(onbasedoc_revision);
|
|
}
|
|
IHttpActionResult transferResult = null;
|
|
if (SendToOnBase != "Yes")
|
|
{
|
|
if (!revisionupload)
|
|
{
|
|
transferResult = Transfer_OnBase(uploadtype.fast, ref jsonstring, ref ilr);
|
|
}
|
|
else
|
|
{
|
|
transferResult = Transfer_OnBase(uploadtype.revision, ref jsonstring, ref ilr);
|
|
}
|
|
if (SendToFile == "Yes")
|
|
{
|
|
if (debugfilename != "")
|
|
{
|
|
debugfilename = debugfilename + DokumentID + ".json";
|
|
System.IO.File.WriteAllText(debugfilename, jsonstring);
|
|
debugfilename = debugfilename + ".pdf";
|
|
Helper.clsFileHelper fh = new Helper.clsFileHelper();
|
|
fh.SaveBase64ToFile(onbasedoc.dokumentDatei, debugfilename);
|
|
fh = null;
|
|
}
|
|
}
|
|
}
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende ArchiveDocFromDatabase: DokumentID:" + DokumentID, LogLevelType.Debug);
|
|
|
|
//Log nachführen
|
|
Update_IL_Log(ref ilr, DokumentID);
|
|
if (ilr.senderror == 1)
|
|
{
|
|
return Content(HttpStatusCode.InternalServerError, ilr.response);
|
|
}
|
|
else
|
|
{
|
|
update_dokumentstatus(DokumentID);
|
|
return Content(HttpStatusCode.OK, DokumentID + " archiviert");
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
[Route("API/ArchivDocFromIRIS")]
|
|
public IHttpActionResult ArchivDocFromIRIS(string dokumentid)
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
string ArchivAktiv;
|
|
ArchivAktiv = System.Configuration.ConfigurationManager.AppSettings["ArchivierungAktiv"].ToString();
|
|
if (ArchivAktiv != "True")
|
|
{
|
|
string message = ArchivAktiv = System.Configuration.ConfigurationManager.AppSettings["ArchivierungNoAktivMessage"].ToString();
|
|
return Content(HttpStatusCode.InternalServerError, message);
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start ArchivDocFromIRIS DokumentID: " + dokumentid, LogLevelType.Debug);
|
|
|
|
if (dokumentid.Substring(0, 9).ToUpper() == "OFFEDK008")
|
|
{
|
|
return (ArchivDocFromDatabase(dokumentid));
|
|
}
|
|
else
|
|
{
|
|
DB db = new DB(connectionstring);
|
|
db.clear_parameter();
|
|
db.add_parameter("@dokumentid", dokumentid);
|
|
|
|
db.Get_Tabledata("[OnDoc_IRIS_Archivierung]", true, false);
|
|
string returnmessage = db.dsdaten.Tables[0].Rows[0][0].ToString();
|
|
switch (db.dsdaten.Tables[0].Rows[0][1].ToString())
|
|
{
|
|
case "1":
|
|
APILogging.Log((HttpRequestMessage)Request, dokumentid + " Image des Dokuments nicht vorhanden", LogLevelType.Error);
|
|
return Content(HttpStatusCode.NotFound, dokumentid);
|
|
break;
|
|
case "2":
|
|
APILogging.Log((HttpRequestMessage)Request, dokumentid + " nicht vorhanden", LogLevelType.Error);
|
|
return Content(HttpStatusCode.NotFound, dokumentid);
|
|
break;
|
|
case "3":
|
|
APILogging.Log((HttpRequestMessage)Request, db.dsdaten.Tables[0].Rows[0][0].ToString() + dokumentid, LogLevelType.Debug);
|
|
return Content(HttpStatusCode.OK, returnmessage);
|
|
case "0":
|
|
return (ArchivDocFromDatabase(dokumentid));
|
|
case "4":
|
|
APILogging.Log((HttpRequestMessage)Request, "Dokumentarchivierung von Iris ausgelöst" + dokumentid, LogLevelType.Info);
|
|
break;
|
|
case "5":
|
|
APILogging.Log((HttpRequestMessage)Request, "Dokument bereit zur Ausgangsarchivierung" + dokumentid, LogLevelType.Info);
|
|
break;
|
|
case "6":
|
|
APILogging.Log((HttpRequestMessage)Request, "Dokument in EDOKA abgeschlossen" + dokumentid, LogLevelType.Info);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
};
|
|
|
|
}
|
|
|
|
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende ArchivDocFromIRIS DokumentID:" + dokumentid, LogLevelType.Debug);
|
|
return Ok(dokumentid);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
}
|
|
[HttpPost]
|
|
[Route("API/ArchivSBDoc")]
|
|
|
|
public IHttpActionResult ArchivSBDoc(string sbnr, string intid, int partnernr, string dokumentid)
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
string ArchivAktiv;
|
|
ArchivAktiv = System.Configuration.ConfigurationManager.AppSettings["ArchivierungAktiv"].ToString();
|
|
if (ArchivAktiv != "True")
|
|
{
|
|
string message = ArchivAktiv = System.Configuration.ConfigurationManager.AppSettings["ArchivierungNoAktivMessage"].ToString();
|
|
return Content(HttpStatusCode.InternalServerError, message);
|
|
}
|
|
APILogging.Log((HttpRequestMessage)Request, "Start ArchivSBDoc DokumentID: DokumentID:" + dokumentid, LogLevelType.Debug);
|
|
|
|
string json = "";
|
|
if (HttpContext.Current.Request.InputStream.Length > 0)
|
|
{
|
|
using (var inputStream = new StreamReader(HttpContext.Current.Request.InputStream))
|
|
{
|
|
json = inputStream.ReadToEnd();
|
|
}
|
|
}
|
|
string debugfilename = System.Configuration.ConfigurationManager.AppSettings["JSONDebugPath"];
|
|
string SendToOnBase = System.Configuration.ConfigurationManager.AppSettings["SendToOnBase"];
|
|
string SendToFile = System.Configuration.ConfigurationManager.AppSettings["SendToFile"];
|
|
string debugdir = System.Configuration.ConfigurationManager.AppSettings["DebugDir"];
|
|
string jsonstring = json;
|
|
|
|
ILResponse ilr = new ILResponse();
|
|
//jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(od);
|
|
IHttpActionResult transferResult = null;
|
|
if (SendToOnBase != "Yes")
|
|
{
|
|
transferResult = Transfer_OnBase(uploadtype.slow, ref jsonstring, ref ilr);
|
|
if (SendToFile == "Yes")
|
|
{
|
|
if (debugfilename != "")
|
|
{
|
|
debugfilename = debugfilename + sbnr.ToString() + "_" + intid.ToString() + "_" + partnernr.ToString() + ".json";
|
|
System.IO.File.WriteAllText(debugfilename, jsonstring);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//Log nachführen
|
|
Update_IL_Log(ref ilr, "SB_" + sbnr.ToString() + "_" + intid.ToString());
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende ArchivSBDoc DokumentID: DokumentID:" + dokumentid, LogLevelType.Debug);
|
|
return transferResult;
|
|
//return Content(HttpStatusCode.OK, "");
|
|
}
|
|
|
|
private IHttpActionResult Transfer_OnBase(uploadtype utype, ref string jsonstring, ref ILResponse ilr)
|
|
{
|
|
//ILResponse ilr = new ILResponse();
|
|
string response;
|
|
WebRequest request;
|
|
APILogging.Log((HttpRequestMessage)Request, "Start Transfer to OnBase", LogLevelType.Debug);
|
|
|
|
string url = "";
|
|
switch (utype)
|
|
{
|
|
case uploadtype.fast:
|
|
url = System.Configuration.ConfigurationManager.AppSettings["ILFast"];
|
|
break;
|
|
case uploadtype.slow:
|
|
url = System.Configuration.ConfigurationManager.AppSettings["ILSlow"];
|
|
break;
|
|
case uploadtype.docupload:
|
|
url = System.Configuration.ConfigurationManager.AppSettings["ILDocupload"];
|
|
break;
|
|
case uploadtype.revision:
|
|
url = System.Configuration.ConfigurationManager.AppSettings["ILRevision"];
|
|
break;
|
|
}
|
|
|
|
var data = Encoding.UTF8.GetBytes(jsonstring);
|
|
request = WebRequest.Create(url);
|
|
request.ContentLength = data.Length;
|
|
request.ContentType = "application/json";
|
|
request.Method = "POST";
|
|
try
|
|
{
|
|
using (Stream requestStream = request.GetRequestStream())
|
|
{
|
|
requestStream.Write(data, 0, data.Length);
|
|
requestStream.Close();
|
|
|
|
using (Stream responseStream = request.GetResponse().GetResponseStream())
|
|
{
|
|
using (var reader = new StreamReader(responseStream))
|
|
{
|
|
response = reader.ReadToEnd();
|
|
}
|
|
}
|
|
}
|
|
ilr.StatusCode = 0;
|
|
ilr.senderror = 0;
|
|
ilr.response = response;
|
|
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Transfer to OnBase", LogLevelType.Debug);
|
|
return Content(HttpStatusCode.OK, ilr);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ilr.StatusCode = 1;
|
|
ilr.senderror = 1;
|
|
ilr.response = ex.Message;
|
|
return Content(HttpStatusCode.InternalServerError, ilr);
|
|
}
|
|
}
|
|
|
|
|
|
private string archiv_sb_doc(string dokumentid, string partnernr, string serienbriefnr, string dokument, string inteintragnr)
|
|
{
|
|
OnBaseDocUpload.OnBaseDokument onbasedoc = new OnBaseDocUpload.OnBaseDokument();
|
|
DB db = new DB(connectionstring);
|
|
db.clear_parameter();
|
|
db.add_parameter("@serienbriefnr", serienbriefnr);
|
|
db.add_parameter("@intEintragnr", inteintragnr);
|
|
db.add_parameter("@partnernr", partnernr);
|
|
db.add_parameter("@dokumentid", dokumentid);
|
|
db.Get_Tabledata("sp_get_onbase_parameters_sb", true, false);
|
|
if (db.dsdaten.Tables[0].Rows[0]["BpNummer"].ToString() == "")
|
|
{
|
|
onbasedoc.personNummer = db.dsdaten.Tables[0].Rows[0]["PersonNummer"].ToString();
|
|
onbasedoc.bpNummer = "";
|
|
}
|
|
else
|
|
{
|
|
onbasedoc.bpNummer = db.dsdaten.Tables[0].Rows[0]["BpNummer"].ToString();
|
|
onbasedoc.personNummer = "";
|
|
}
|
|
onbasedoc.dokumentDatum = db.dsdaten.Tables[0].Rows[0]["DokumentDatum"].ToString();
|
|
onbasedoc.dokumentTyp = db.dsdaten.Tables[0].Rows[0]["dokumenttyp"].ToString();
|
|
onbasedoc.dateiTyp = db.dsdaten.Tables[0].Rows[0]["dateityp"].ToString();
|
|
|
|
onbasedoc.attributes = new List<Model.OnBaseDocUpload.attribute>();
|
|
foreach (System.Data.DataRow rw in db.dsdaten.Tables[1].Rows)
|
|
|
|
{
|
|
OnBaseDocUpload.attribute p = new OnBaseDocUpload.attribute(rw["fieldname"].ToString(), rw["fieldvalue"].ToString());
|
|
onbasedoc.attributes.Add(p);
|
|
}
|
|
onbasedoc.dokumentDatei = dokument;
|
|
string URL = "";
|
|
string response = "";
|
|
|
|
string jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(onbasedoc);
|
|
ILResponse ilr = new ILResponse();
|
|
Transfer_OnBase(uploadtype.fast, ref jsonstring, ref ilr);
|
|
Update_IL_Log(ref ilr, serienbriefnr.ToString() + "_" + inteintragnr.ToString());
|
|
return ilr.response;
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("API/Send_Versandstrasse")]
|
|
|
|
public IHttpActionResult Send_Versandstrasse(string paketid = "")
|
|
{
|
|
|
|
string json_versandpaket = "";
|
|
if (paketid != "")
|
|
{
|
|
Database.DB db = new Database.DB(connectionstring);
|
|
//db.Get_Tabledata("Select * from dokument where dokumentid = '" + DokumentID + "'", false, true);
|
|
|
|
string SQL = "Select * from Ondoc_Versandstrasse_Paket where id = @ID";
|
|
db.clear_parameter();
|
|
db.add_parameter("@ID", paketid);
|
|
db.Get_Tabledata_Addvar(SQL, false, true);
|
|
if (db.dsdaten.Tables[0].Rows.Count == 0)
|
|
{
|
|
db = null;
|
|
return Content(HttpStatusCode.NotFound, paketid);
|
|
}
|
|
json_versandpaket = db.dsdaten.Tables[0].Rows[0]["Paket"].ToString();
|
|
|
|
db = null;
|
|
}
|
|
else
|
|
{
|
|
json_versandpaket = Request.Content.ReadAsStringAsync().Result;
|
|
}
|
|
|
|
Versandpaket versandpaket = new Versandpaket();
|
|
versandpaket.Dokument = new List<Versanddokument>();
|
|
versandpaket = JsonConvert.DeserializeObject<Versandpaket>(json_versandpaket);
|
|
|
|
string inthandle = "";
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
string ArchivAktiv;
|
|
ArchivAktiv = System.Configuration.ConfigurationManager.AppSettings["ArchivierungAktiv"].ToString();
|
|
if (ArchivAktiv != "True")
|
|
{
|
|
string message = "Hinweismeldung: " + System.Configuration.ConfigurationManager.AppSettings["ArchivierungNoAktivMessage"].ToString();
|
|
return Content(HttpStatusCode.OK, message);
|
|
}
|
|
try
|
|
{
|
|
if (paketid != "")
|
|
{
|
|
DB db = new DB(connectionstring);
|
|
db.clear_parameter();
|
|
db.add_parameter("@tgnummer", "API/Service");
|
|
db.add_parameter("@partnernr", versandpaket.partnernr.ToString());
|
|
db.add_parameter("@gasadresse", versandpaket.GASAdresse);
|
|
db.add_parameter("@versandoption", versandpaket.Versandoption);
|
|
|
|
string dokumente = "";
|
|
foreach (Versanddokument vd in versandpaket.Dokument)
|
|
{
|
|
dokumente = dokumente + vd.DokumentID + ";";
|
|
}
|
|
db.add_parameter("@dokumente", dokumente);
|
|
db.add_parameter("@paketid", paketid);
|
|
db.Get_Tabledata("Ondoc_Insert_Versandprotokoll", true, false);
|
|
versandpaket.protokollid = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][0]);
|
|
}
|
|
|
|
OnBase_Attributes oba = new OnBase_Attributes();
|
|
if (!versandpaket.send_onbase_doc)
|
|
{
|
|
oba.BPNummer = versandpaket.partnernr.ToString();
|
|
oba.DocumentHandle = "";
|
|
oba.DistributionOption = versandpaket.Versandoption.ToString();
|
|
oba.GASCouvert = versandpaket.GAS;
|
|
oba.Returnaddress = versandpaket.GASAdresse;
|
|
oba.O2ODochandle = "";
|
|
oba.Status = "";
|
|
//if (oba.GASCouvert == "") { oba.GASCouvert = "false"; } else { oba.GASCouvert = "true"; }
|
|
foreach (Versanddokument vd in versandpaket.Dokument)
|
|
{
|
|
IHttpActionResult res = ArchivDocFromDatabase(vd.DokumentID, "");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
oba.BPNummer = versandpaket.partnernr.ToString();
|
|
oba.DocumentHandle = "";
|
|
oba.DistributionOption = versandpaket.Versandoption.ToString();
|
|
oba.GASCouvert = versandpaket.GAS;
|
|
oba.Returnaddress = versandpaket.GASAdresse;
|
|
oba.O2ODochandle = "";
|
|
oba.Status = "";
|
|
|
|
|
|
foreach (Versanddokument vd in versandpaket.Dokument)
|
|
{
|
|
if (versandpaket.isSerienbrief)
|
|
{
|
|
string result = "";
|
|
|
|
inthandle = archiv_sb_doc(vd.DokumentID, vd.Partnernr, versandpaket.sb.serienbriefnr.ToString(), vd.dokument, vd.inteintragnr.ToString());
|
|
oba.DocumentHandle = inthandle.ToString();
|
|
DOCGEN.DocGen dg = new DOCGEN.DocGen();
|
|
versandpaket.finaldoc = dg.geneate_dummy_pdf("VS Serienbrief: Handle "+oba.DocumentHandle.ToString() +" "+ DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss"));
|
|
}
|
|
else
|
|
{
|
|
IHttpActionResult res = ArchivDocFromDatabase(vd.DokumentID, vd.dokument);
|
|
DB db = new DB(connectionstring);
|
|
db.clear_parameter();
|
|
db.add_parameter("@dokumentid", vd.DokumentID);
|
|
db.Get_Tabledata("sp_get_handle", true, false);
|
|
if (db.dsdaten.Tables[0].Rows.Count > 0)
|
|
{
|
|
inthandle = db.dsdaten.Tables[0].Rows[0][0].ToString();
|
|
oba.DocumentHandle = inthandle;
|
|
DOCGEN.DocGen dg = new DOCGEN.DocGen();
|
|
versandpaket.finaldoc=dg.geneate_dummy_pdf("Versandstrasse - DummyDokument - " + DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss"));
|
|
//versandpaket.finaldoc = "";
|
|
dg = null;
|
|
}
|
|
db = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
OnBaseDocUpload.OnBaseDokument onbasedoc = new OnBaseDocUpload.OnBaseDokument();
|
|
onbasedoc.bpNummer = oba.BPNummer;
|
|
onbasedoc.dokumentTyp = "Tech Versandstrasse SendDoc";
|
|
onbasedoc.personNummer = "";
|
|
onbasedoc.dokumentDatum = DateTime.Now.ToString("dd.MM.yyyy");
|
|
onbasedoc.dokumentDatei = versandpaket.finaldoc;
|
|
onbasedoc.dateiTyp = "PDF";
|
|
onbasedoc.attributes = new List<OnBaseDocUpload.attribute>();
|
|
if (oba.GASCouvert=="") { oba.GASCouvert = "false"; } else { oba.GASCouvert = "true"; }
|
|
|
|
onbasedoc.attributes.Add(new OnBaseDocUpload.attribute("Document Handle",oba.DocumentHandle.ToString()));
|
|
onbasedoc.attributes.Add(new OnBaseDocUpload.attribute("O2O DistributionOption",oba.DistributionOption.ToString()));
|
|
onbasedoc.attributes.Add(new OnBaseDocUpload.attribute("O2O GasCouvert", oba.GASCouvert.ToString()));
|
|
onbasedoc.attributes.Add(new OnBaseDocUpload.attribute("O2O Returnaddress", oba.Returnaddress.ToString()));
|
|
|
|
onbasedoc.attributes.Add(new OnBaseDocUpload.attribute("O2O Dochandle", oba.DocumentHandle.ToString()));
|
|
onbasedoc.attributes.Add(new OnBaseDocUpload.attribute("O2O Status", oba.Status.ToString()));
|
|
|
|
ILResponse ilr = new ILResponse();
|
|
string debugfilename = System.Configuration.ConfigurationManager.AppSettings["JSONDebugPath"];
|
|
string SendToOnBase = System.Configuration.ConfigurationManager.AppSettings["SendToOnBase"];
|
|
string SendToFile = System.Configuration.ConfigurationManager.AppSettings["SendToFile"];
|
|
string debugdir = System.Configuration.ConfigurationManager.AppSettings["DebugDir"];
|
|
string jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(onbasedoc);
|
|
IHttpActionResult transferResult = null;
|
|
if (SendToOnBase != "Yes")
|
|
{
|
|
transferResult = Transfer_OnBase(uploadtype.fast, ref jsonstring, ref ilr);
|
|
|
|
if (SendToFile == "Yes")
|
|
{
|
|
if (debugfilename != "")
|
|
{
|
|
debugfilename = debugfilename + "VS_"+oba.BPNummer+"_"+DateTime.Now.ToString("yyyyMMddhhmmss")+".json";
|
|
System.IO.File.WriteAllText(debugfilename, jsonstring);
|
|
debugfilename = debugfilename + ".pdf";
|
|
Helper.clsFileHelper fh = new Helper.clsFileHelper();
|
|
fh.SaveBase64ToFile(onbasedoc.dokumentDatei, debugfilename);
|
|
fh = null;
|
|
}
|
|
}
|
|
}
|
|
DB db1 = new DB(connectionstring);
|
|
db1.Exec_SQL("Update Versandstrasse_Protokoll set handle = '" + ilr.response + "' where id=" + versandpaket.protokollid.ToString());
|
|
if (paketid != "")
|
|
{
|
|
db1.Exec_SQL("Update OnDoc_Versandstrasse_paket set versendet=1, versendet_am=getdate() where id=" + paketid);
|
|
}
|
|
db1 = null;
|
|
APILogging.Log((HttpRequestMessage)Request, "Opload Versandstrasse:" + debugfilename, LogLevelType.Debug);
|
|
|
|
//Log nachführen
|
|
// Update_IL_Log(ref ilr, DokumentID);
|
|
if (ilr.senderror == 1)
|
|
{
|
|
return Content(HttpStatusCode.InternalServerError, ilr.response);
|
|
}
|
|
else
|
|
{
|
|
// update_dokumentstatus(debugfilename);
|
|
return Content(HttpStatusCode.OK, oba.BPNummer.ToString() + " *archiviert*");
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("API/ResendVersandpaket")]
|
|
|
|
public IHttpActionResult ResendVersandpaket(string PaketID)
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start Resend Versandstrasse: PaketID:" + PaketID, LogLevelType.Debug);
|
|
Database.DB db = new Database.DB(connectionstring);
|
|
//db.Get_Tabledata("Select * from dokument where dokumentid = '" + DokumentID + "'", false, true);
|
|
|
|
string SQL = "Select * from Ondoc_Versandstrasse_Paket where = @ID";
|
|
db.clear_parameter();
|
|
db.add_parameter("@ID", PaketID);
|
|
db.Get_Tabledata_Addvar(SQL, false, true);
|
|
if (db.dsdaten.Tables[0].Rows.Count == 0)
|
|
{
|
|
return Content(HttpStatusCode.NotFound, PaketID);
|
|
}
|
|
|
|
Versandpaket vp = JsonConvert.DeserializeObject<Versandpaket>(db.dsdaten.Tables[0].Rows[0].ToString());
|
|
IHttpActionResult res = Send_Versandstrasse();
|
|
|
|
|
|
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Resend_Versandstrasse: PaketID:" + PaketID, LogLevelType.Debug);
|
|
|
|
return Content(HttpStatusCode.NotFound,PaketID);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
}
|
|
}
|
|
} |