update 20260326

This commit is contained in:
Stefan Hutter
2026-03-26 18:26:34 +01:00
parent 399d63bc69
commit e82057b6e4
87 changed files with 5024 additions and 139 deletions
+102 -17
View File
@@ -1,4 +1,5 @@
using Model;
using Database;
using Model;
using Newtonsoft.Json;
using SecuringWebApiUsingApiKey.Middleware;
using System;
@@ -6,6 +7,7 @@ using System.Buffers.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
@@ -162,6 +164,18 @@ namespace WebApp
c3.Controls.Add(l3);
e.Row.Cells.Add(c3);
break;
case "DOKUMENTEANZEIGEN":
var c4 = new TableCell();
var l4 = new LinkButton
{
Text = "Dokumente(e) anzeigen",
CssClass = "open"
};
l4.OnClientClick = $"showAPIDocs('{tableKeyJs}','{idJs}'); return false;";
c4.Controls.Add(l4);
e.Row.Cells.Add(c4);
break;
}
@@ -196,6 +210,67 @@ namespace WebApp
//e.Row.Cells.Add(cell);
}
private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
[WebMethod]
public static object gwrAPIDocs(string table, string id)
{
var config = TableConfigProvider.LoadConfig();
var cfg = config.Tables.FirstOrDefault(t => t.Key == table);
if (cfg == null) return "Tabelle nicht gefunden";
string sql = "SELECT NLOGApiDoc_1.id, NLOGApiDoc_1.GUID, a.Div FROM edoka_journale.dbo.NLOGApiDoc as a INNER JOIN edoka_journale.dbo.NLOGApiDoc AS NLOGApiDoc_1 ON a.GUID = NLOGApiDoc_1.GUID";
sql = sql + " WHERE (a.Div LIKE 'offedk%') AND (NLOGApiDoc_1.id = " + id + ")";
int rowcount = 0;
System.IO.DirectoryInfo di = new DirectoryInfo(@"d:\apps\ondoc\admintemp\");
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
string prefix=RandomString(6).ToString();
using (var con = new SqlConnection(StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["DocTesterconnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm")))
using (var cmd = new SqlCommand(sql, con))
{
//cmd.Parameters.AddWithValue("@id", id);
con.Open();
var dt = new DataTable();
dt.Load(cmd.ExecuteReader());
con.Close();
rowcount = dt.Rows.Count;
if (rowcount > 0)
{
foreach (DataRow dr in dt.Rows)
{
cmd.CommandText = "Select dbo.BinaryToBase64(dokument) from dbo.doks where dokumentid='" + dr[2].ToString() + "'";
con.Open();
string doc = cmd.ExecuteScalar()?.ToString();
con.Close();
var ms1 = new MemoryStream(Convert.FromBase64String(doc));
using (System.IO.FileStream file = new System.IO.FileStream(@"d:\apps\ondoc\admintemp\" + prefix + dr[2].ToString() + ".pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
byte[] bytes = new byte[ms1.Length];
ms1.Read(bytes, 0, (int)ms1.Length);
file.Write(bytes, 0, bytes.Length);
ms1.Close();
}
ms1 = null;
}
return prefix;
}
else
{
return "";
}
}
}
[WebMethod]
public static object GetPacDoc(string table, string id)
{
@@ -205,26 +280,36 @@ namespace WebApp
using (var con = new SqlConnection(StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["DocTesterconnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm")))
using (var cmd = new SqlCommand(cfg.AnzeigeDokument, con))
{
System.IO.DirectoryInfo di = new DirectoryInfo(@"d:\apps\ondoc\admintemp\");
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
cmd.Parameters.AddWithValue("@id", id);
con.Open();
string doc = cmd.ExecuteScalar()?.ToString();
var dt = new DataTable();
dt.Load(cmd.ExecuteReader());
con.Close();
dynamic dataj = JsonConvert.DeserializeObject(doc);
var b64 = dataj.finaldoc.ToString(); ;
bool isbase64 = (b64.Length % 4 == 0) && Regex.IsMatch(b64, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None);
b64 = System.IO.File.ReadAllText(@"y:\clm.json");
return b64; ;
Versandpaket vp = JsonConvert.DeserializeObject<Versandpaket>(dt.Rows[0][0].ToString());
var b64 = vp.finaldoc;
var ms = new MemoryStream(Convert.FromBase64String(b64));
using (System.IO.FileStream file = new System.IO.FileStream(@"d:\apps\ondoc\admintemp\vp.pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
byte[] bytes = new byte[ms.Length];
ms.Read(bytes, 0, (int)ms.Length);
file.Write(bytes, 0, bytes.Length);
ms.Close();
}
//System.Diagnostics.Process.Start(@"d:\apps\ondoc\admintemp\vp.pdf");
//System.IO.File.Delete("d:\\ondoc\\temp\\vp.pdf");
return "";
}
}
public static bool IsBase64String(string base64)
{
base64 = base64.Trim();
return (base64.Length % 4 == 0) && Regex.IsMatch(base64, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None);
}
[WebMethod]
public static object GetDoc(string table, string id)
{
@@ -238,7 +323,7 @@ namespace WebApp
con.Open();
string doc = cmd.ExecuteScalar()?.ToString();
con.Close();
System.IO.File.WriteAllText(@"y:\clm.json", doc);
return doc;
}
}