Update 20260123
This commit is contained in:
@@ -425,6 +425,79 @@ namespace API_NetFramework.Controllers
|
||||
|
||||
|
||||
|
||||
[HttpPost]
|
||||
[Route("API/ArchivDoc")]
|
||||
public IHttpActionResult ArchivDoc(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/ArchivDocFromIRIS")]
|
||||
|
||||
@@ -35,6 +35,7 @@ using System.Reflection;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Web.Http.Results;
|
||||
using Syncfusion.DocIO.DLS.XML;
|
||||
|
||||
|
||||
namespace API_NetFramework.Controllers
|
||||
@@ -552,6 +553,8 @@ namespace API_NetFramework.Controllers
|
||||
Logging.APIDocLog.Info("Input JSON", "CreateCLM", guid, result);
|
||||
|
||||
var jo = JObject.Parse(Request.Content.ReadAsStringAsync().Result);
|
||||
var x = dataj.Produkt;
|
||||
Console.WriteLine(dataj.Bp.Zustaendiger.TgNummer);
|
||||
var valueTuples = GetNodes(jo).ToList();
|
||||
foreach (var valueTuple in valueTuples)
|
||||
{
|
||||
@@ -568,6 +571,7 @@ namespace API_NetFramework.Controllers
|
||||
db.Get_Tabledata("Select * from vorlagenfeld where dokumenttypnr=" + dataj.Dokumenttyp.ToString() + " and aktiv=1 and ess_field_class_id<>0", false, true);
|
||||
foreach (DataRow dr in db.dsdaten.Tables[0].Rows)
|
||||
{
|
||||
|
||||
foreach (CLMDocItem di in clmdocitemlist)
|
||||
{
|
||||
if ("$." + di.itemname == dr["ess_feldname"].ToString())
|
||||
@@ -580,10 +584,43 @@ namespace API_NetFramework.Controllers
|
||||
di.width = dr["ess_img_width"].ToString();
|
||||
di.height = dr["ess_img_height"].ToString();
|
||||
di.type = dr["ess_field_class_id"].ToString();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (dr["ess_feldname"].ToString().Contains("@T:"))
|
||||
{
|
||||
string[] arr = dr["ess_feldname"].ToString().Split(new string[] { "$Format:" }, StringSplitOptions.None);
|
||||
dr["ess_feldname"] = arr[0];
|
||||
string value = "";
|
||||
string tablename = "";
|
||||
string format = "";
|
||||
|
||||
get_tabledata(dr["ess_feldname"].ToString(), ref clmdocitemlist, out value, out tablename);
|
||||
|
||||
CLMDocItem di = new CLMDocItem();
|
||||
di.bmstart = dr["beginntextmarke"].ToString();
|
||||
di.bmend = dr["endetextmarke"].ToString();
|
||||
di.field = dr["feldname"].ToString();
|
||||
di.top = dr["ess_img_top"].ToString();
|
||||
di.left = dr["ess_img_left"].ToString();
|
||||
di.width = dr["ess_img_width"].ToString();
|
||||
di.height = dr["ess_img_height"].ToString();
|
||||
di.type = dr["ess_field_class_id"].ToString();
|
||||
di.itemname = tablename;
|
||||
di.itemvalue = value;
|
||||
di.itemname = tablename;
|
||||
try
|
||||
{
|
||||
di.format = arr[1];
|
||||
}
|
||||
catch { di.format = ""; }
|
||||
clmdocitemlist.Add(di);
|
||||
}
|
||||
|
||||
}
|
||||
clmdocitemlist.RemoveAll((y) => string.IsNullOrEmpty(y.type));
|
||||
|
||||
string CheckResult = "";
|
||||
CheckResult = CLM_Verify(ref clmdocitemlist, ref result);
|
||||
@@ -608,7 +645,7 @@ namespace API_NetFramework.Controllers
|
||||
apiok.message = "";
|
||||
apiok.documentid = dataj.Id.ToString();
|
||||
apiok.file = dok.dokument;
|
||||
return Ok(Newtonsoft.Json.JsonConvert.SerializeObject(apiok));
|
||||
return Ok((apiok));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -624,6 +661,68 @@ namespace API_NetFramework.Controllers
|
||||
finally { apireturn = null; apiok = null; clmdocitemlist = null; dataj = null; };
|
||||
}
|
||||
|
||||
private void get_tabledata(string ifeldname, ref List<CLMDocItem> docitemlist, out string value, out string tablename)
|
||||
{
|
||||
//@T: Produkt.Produktinfo:Name,Beschreibung
|
||||
string Feldname = ifeldname;
|
||||
string Source = Feldname.Replace("@T:", "");
|
||||
string Tablename = Source.Split(':')[0];
|
||||
Source = Source.Replace(Tablename + ":", "");
|
||||
string[] attributs = Source.Split(',');
|
||||
|
||||
var newlist = docitemlist.FindAll(s => s.itemname.Contains(Tablename));
|
||||
|
||||
string suchText = Tablename;
|
||||
var treffer = docitemlist
|
||||
.Where(p => p.itemname.Contains(suchText))
|
||||
.ToList()
|
||||
.OrderBy(p => p.itemname);
|
||||
|
||||
DataTable dt = new DataTable();
|
||||
foreach (string attrib in attributs)
|
||||
{
|
||||
dt.Columns.Add(attrib);
|
||||
}
|
||||
int rowcounter = 0;
|
||||
foreach (CLMDocItem di in treffer)
|
||||
{
|
||||
string x = di.itemname;
|
||||
x = x.Replace(Tablename + "[", "");
|
||||
char ch = ']';
|
||||
int offset = x.IndexOf(ch);
|
||||
string prefix = x.Substring(0, offset);
|
||||
rowcounter = Convert.ToInt32(prefix);
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < rowcounter + 1; i++)
|
||||
{
|
||||
DataRow dx = dt.NewRow();
|
||||
for (int j = 0; dt.Columns.Count > j; j++)
|
||||
{
|
||||
foreach (CLMDocItem di in newlist)
|
||||
{
|
||||
if (di.itemname == Tablename + "[" + i.ToString().Trim() + "]" + "." + dt.Columns[j].ColumnName)
|
||||
{
|
||||
dx[dt.Columns[j]] = di.itemvalue;
|
||||
}
|
||||
}
|
||||
}
|
||||
dt.Rows.Add(dx);
|
||||
}
|
||||
foreach (CLMDocItem di in treffer)
|
||||
{
|
||||
docitemlist.Remove(di);
|
||||
}
|
||||
dt.AcceptChanges();
|
||||
string JSONresult;
|
||||
JSONresult = JsonConvert.SerializeObject(dt);
|
||||
tablename = Tablename;
|
||||
value = JSONresult;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#region Helper
|
||||
private IEnumerable<(string path, string key, string value)> GetNodes(JToken token)
|
||||
{
|
||||
@@ -1195,14 +1294,34 @@ namespace API_NetFramework.Controllers
|
||||
// dokdata.dokumentwerte = ToDataTable<CLMDocItem>
|
||||
dokumentid = db.Create_EDOKA_Doc(dokdata, false, "");
|
||||
dokdata.Dokumentid = dokumentid;
|
||||
|
||||
|
||||
dokdata.Erstellung_in_Office = false;
|
||||
DOCGEN.Generator.DocGenerator_from_EDOKA Generator = new DOCGEN.Generator.DocGenerator_from_EDOKA(this.connectionstring, OwnHost, key.ToString());
|
||||
dok = Generator.Generate_Doc_EDOKA(dokumentid, ref dokdata, false, 0, false, false);
|
||||
db.Save_To_DB(dokumentid, "", dok.dokument);
|
||||
DocGet dget = new DocGet(this.connectionstring);
|
||||
dok.dokument = dget.Convert_Word_To_PDF(dok.dokument);
|
||||
// db.Save_To_DB(dokumentid, "", dok.dokument);
|
||||
|
||||
|
||||
// dok = dget.GetDocAsPDF(dokumentid);
|
||||
dok.extension = "pdf";
|
||||
dok.doktype = "P";
|
||||
if (System.Configuration.ConfigurationManager.AppSettings["CLMSaveOnDoc"].ToString() == "True")
|
||||
{
|
||||
db.Save_To_DB(dokumentid, "", dok.dokument);
|
||||
} else
|
||||
{
|
||||
db.clear_parameter();
|
||||
db.add_parameter("@dokumentid", dokumentid);
|
||||
db.Get_Tabledata("ondoc_delete_apidoc", true, false);
|
||||
}
|
||||
deflist.Clear();
|
||||
dget = null;
|
||||
Generator = null;
|
||||
clmdocitemlist.Clear();
|
||||
APILogging.Log((HttpRequestMessage)Request, "Ende GenDoc DokumentID:" + dokumentid, LogLevelType.Debug);
|
||||
APILogging.DocLog((HttpRequestMessage)Request, docgendata.partnernr.ToString(), "Dokument über API erstellt", dokumentid, LogLevelType.Info);
|
||||
db = null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
208
API_NetFramework/Controllers/JsonController.cs
Normal file
208
API_NetFramework/Controllers/JsonController.cs
Normal file
@@ -0,0 +1,208 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
|
||||
using System.Configuration;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using SecuringWebApiUsingApiKey.Middleware;
|
||||
using System.Threading.Tasks;
|
||||
using Model;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Web.Http.Results;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
|
||||
namespace OnDocAPI_NetFramework.Controllers
|
||||
{
|
||||
public class JsonRequestDto
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Json { get; set; }
|
||||
}
|
||||
|
||||
[System.Web.Http.RoutePrefix("api/json")]
|
||||
public class JsonController : ApiController
|
||||
{
|
||||
|
||||
private readonly string _connectionString = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["DocTesterconnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
||||
|
||||
// 🔹 JSON LESEN
|
||||
[System.Web.Http.HttpGet]
|
||||
[System.Web.Http.Route("load/{key}")]
|
||||
public IHttpActionResult LoadJson(string key)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
return BadRequest("Key fehlt");
|
||||
|
||||
string json;
|
||||
|
||||
using (SqlConnection con = new SqlConnection(_connectionString))
|
||||
using (SqlCommand cmd = new SqlCommand(
|
||||
"SELECT JavaScriptObject FROM ProvDokuments WHERE ProvDokumentid = @key", con))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@key", key);
|
||||
con.Open();
|
||||
json = cmd.ExecuteScalar()?.ToString();
|
||||
}
|
||||
|
||||
if (json == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(json);
|
||||
}
|
||||
|
||||
// 🔹 JSON SPEICHERN
|
||||
[System.Web.Http.HttpPost]
|
||||
[System.Web.Http.Route("save")]
|
||||
public IHttpActionResult SaveJson(JsonRequestDto dto)
|
||||
{
|
||||
if (dto == null || string.IsNullOrWhiteSpace(dto.Key))
|
||||
return BadRequest("Key fehlt");
|
||||
|
||||
using (SqlConnection con = new SqlConnection(_connectionString))
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
IF EXISTS (SELECT 1 FROM provdokuments WHERE provdokumentid = @key)
|
||||
UPDATE provdokuments SET JavaScriptObject = @json, geaendertam = GETDATE()
|
||||
WHERE provdokumentid = @key
|
||||
ELSE
|
||||
INSERT INTO provdokuments (provdokumentid,erstelltam,geaendertam, JavaScriptObject)
|
||||
VALUES (@key, getdate(),getdate(),@json)
|
||||
", con))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@key", dto.Key);
|
||||
cmd.Parameters.AddWithValue("@json", dto.Json);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
public class JsonRequestDto
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Json { get; set; } // ← reiner JSON-String
|
||||
}
|
||||
public class PdfBase64Response
|
||||
{
|
||||
public string PdfBase64 { get; set; }
|
||||
}
|
||||
// 🔹 PDF GENERIEREN
|
||||
[System.Web.Http.HttpPost]
|
||||
[System.Web.Http.Route("GeneratePDF")]
|
||||
public async Task<HttpResponseMessage> GeneratePdf(JsonRequestDto dto)
|
||||
{
|
||||
if (dto == null || string.IsNullOrWhiteSpace(dto.Json))
|
||||
return new HttpResponseMessage(HttpStatusCode.BadRequest);
|
||||
|
||||
byte[] pdfBytes = await CallExternalPdfApi(dto.Json);
|
||||
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new ByteArrayContent(pdfBytes)
|
||||
};
|
||||
|
||||
|
||||
response.Content.Headers.ContentType =
|
||||
new MediaTypeHeaderValue("application/pdf");
|
||||
|
||||
response.Content.Headers.ContentDisposition =
|
||||
new ContentDispositionHeaderValue("inline")
|
||||
{
|
||||
FileName = $"{dto.Key}.pdf"
|
||||
};
|
||||
response.Content.Headers.ContentLength = pdfBytes.Length;
|
||||
if (System.IO.File.Exists(@"x:\file.pdf")) { System.IO.File.Delete(@"x:\file.pdf"); }
|
||||
System.IO.FileStream stream =
|
||||
|
||||
new FileStream(@"x:\file.pdf", FileMode.CreateNew);
|
||||
System.IO.BinaryWriter writer =
|
||||
new BinaryWriter(stream);
|
||||
writer.Write(pdfBytes, 0, pdfBytes.Length);
|
||||
writer.Close();
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private async Task<byte[]> CallExternalPdfApi(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
APIErrorSimple apireturn = new APIErrorSimple();
|
||||
APIOK apiok = new APIOK();
|
||||
;
|
||||
string jsonstring = json;
|
||||
|
||||
WebRequest request;
|
||||
|
||||
var data = Encoding.UTF8.GetBytes(jsonstring);
|
||||
string OwnHost = System.Configuration.ConfigurationManager.AppSettings["OwnHost"].ToString();
|
||||
string uri = OwnHost + "/API/CreateCLM";
|
||||
request = WebRequest.Create(uri);
|
||||
request.ContentLength = data.Length;
|
||||
request.ContentType = "application/json";
|
||||
request.Method = "POST";
|
||||
request.Headers["Authorization"] = "Bearer " + "pZkuG6l6ORCEckqQimPK58PO1A9EnkMtL5oCgRX9WiWnD4xeH7ikGzhWnTBy/vk8J4Iiz8gCSx9uFHA4+DvITG0roO97sk82d/0BCjVlwLWINpXlJfGYEF3X96AdoCQvb3ruwv/tVqEHsSU5aNfyxBAe+EhLTHQ8t7ysgJZWh98=";
|
||||
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))
|
||||
{
|
||||
var response = reader.ReadToEnd();
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
apiok = JsonConvert.DeserializeObject<APIOK>(response);
|
||||
var jo = JObject.Parse(response.ToString());
|
||||
|
||||
return Convert.FromBase64String(apiok.file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apireturn = JsonConvert.DeserializeObject<APIErrorSimple>(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch {
|
||||
byte[] pdf;
|
||||
return null;}
|
||||
|
||||
|
||||
// var request = (HttpWebRequest)WebRequest.Create("https://api.example.com/generate-pdf");
|
||||
//request.Method = "POST";
|
||||
//request.ContentType = "application/json";
|
||||
|
||||
//byte[] payload = Encoding.UTF8.GetBytes(json);
|
||||
//request.ContentLength = payload.Length;
|
||||
|
||||
//using (var stream = request.GetRequestStream())
|
||||
// stream.Write(payload, 0, payload.Length);
|
||||
|
||||
//using (var response = (HttpWebResponse)request.GetResponse())
|
||||
//using (var rs = response.GetResponseStream())
|
||||
//using (var ms = new MemoryStream())
|
||||
//{
|
||||
// rs.CopyTo(ms);
|
||||
// return ms.ToArray();
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,7 @@ namespace API_NetFramework.Controllers
|
||||
|
||||
[HttpGet]
|
||||
[Route("API/GetUnterschriftAsBase64New")]
|
||||
public IHttpActionResult GetUnterschriftAsBase64New(string TGNummer, int ImageWidth = 0, int ImageHeight = 0)
|
||||
public IHttpActionResult GetUnterschriftAsBase64IL(string TGNummer, int ImageWidth = 0, int ImageHeight = 0)
|
||||
{
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user