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.
640 lines
35 KiB
640 lines
35 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.Security.Cryptography;
|
|
using edoka_dms;
|
|
using SecuringWebApiUsingApiKey.Middleware;
|
|
using System.Linq.Expressions;
|
|
using System.Data;
|
|
using System.Web.Management;
|
|
using System.Web;
|
|
using System.IO;
|
|
using OnDocAPI_NetFramework.Controllers;
|
|
using Versandstrasse;
|
|
using System.ComponentModel;
|
|
using System.Text;
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
|
namespace API_NetFramework.Controllers
|
|
{
|
|
public class TestParam
|
|
{
|
|
public string param1 { get; set; }
|
|
public string param2 { get; set; }
|
|
}
|
|
public class DocumentController : ApiController
|
|
{
|
|
public string tokenfunction = "Dokument";
|
|
string connectionstring = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["EDOKAConnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
|
[HttpGet]
|
|
[Route("API/GetDocument")]
|
|
public IHttpActionResult GetDocument(string dokid)
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start GetDocument DokumentID:" + dokid, LogLevelType.Debug);
|
|
|
|
DOCGEN.DocGet gd = new DocGet(connectionstring);
|
|
clsdok dok = new clsdok("", "", "", "");
|
|
dok = gd.GetDoc(dokid);
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende GetDocument DokumentID:" + dokid, LogLevelType.Debug);
|
|
|
|
return Ok(dok);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
|
|
}
|
|
|
|
//public object pageCollection { get; set; }
|
|
//[HttpGet]
|
|
//[Route("API/GetDocumentJSONBody")]
|
|
//public IHttpActionResult GetDocumentJSONBody([FromBody] TestParam tp)
|
|
//{
|
|
// //JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, PreserveReferencesHandling = PreserveReferencesHandling.None };
|
|
// //var myObject = JsonConvert.DeserializeObject<TestParam>(pageCollection.ToString(), settings);
|
|
|
|
// return Ok(tp.param1);
|
|
// //return Ok(tp.param1.ToString());
|
|
//}
|
|
[Route("API/GetDocumentPDF")]
|
|
[HttpGet]
|
|
public IHttpActionResult GetDocumentPDF(string dokid)
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start GetDocumentPDF DokumentID:" + dokid, LogLevelType.Debug);
|
|
|
|
DOCGEN.DocGet gd = new DocGet(connectionstring);
|
|
clsdok dok = new clsdok("", "", "", "");
|
|
dok = gd.GetDocAsPDF(dokid);
|
|
dok.extension = "pdf";
|
|
dok.doktype = "P";
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende GetDocument DokumentID:" + dokid, LogLevelType.Debug);
|
|
|
|
return Ok(dok);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("API/CreateDoc")]
|
|
public IHttpActionResult CreateDoc()
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
HttpRequestMessage rmsg = (HttpRequestMessage)Request;
|
|
string OwnHost = System.Configuration.ConfigurationManager.AppSettings["OwnHost"].ToString();
|
|
string imagepath = System.Configuration.ConfigurationManager.AppSettings["VSImagePath"].ToString();
|
|
|
|
|
|
var key = rmsg.Headers.Authorization.Parameter.ToString();
|
|
string result = Request.Content.ReadAsStringAsync().Result;
|
|
DocCreate doccreate = new DocCreate();
|
|
doccreate = JsonConvert.DeserializeObject<DocCreate>(result);
|
|
clsDocData dokdata = new clsDocData();
|
|
string dokumentid = "";
|
|
|
|
string CheckResult = "";
|
|
CheckResult = CreateDoc_Verify(ref doccreate);
|
|
if (CheckResult != "")
|
|
{
|
|
return BadRequest(CheckResult);
|
|
}
|
|
|
|
Database.DB db = new DB(connectionstring);
|
|
db.Get_Tabledata("Select * from dokumenttyp where dokumenttypnr=" + doccreate.VorlagenTypID, false, true);
|
|
System.Data.DataRow dr = db.dsdaten.Tables[0].Rows[0];
|
|
dokdata.Barcode = Convert.ToBoolean(dr["Vertrag"]) == true;
|
|
db.Get_Tabledata("Select beschreibung from physischesarchiv where physischesarchivnr = " + dr["physisches_archiv"].ToString(), false, true);
|
|
dokdata.barcode_zusatz = db.dsdaten.Tables[0].Rows[0][0].ToString();
|
|
if (dokdata.barcode_zusatz != "") { dokdata.barcode_zusatz = " " + dokdata.barcode_zusatz; }
|
|
|
|
db.Get_Tabledata("Select office_vorlagenr,kopfzeile_generieren, bcpt,bcpl, bcw, bch, bchorizontal, barcodetype, datamatrixcontent from office_vorlage where office_vorlagenr=" + dr["office_vorlagenr"].ToString(), false, true);
|
|
dokdata.VorlageNr = Convert.ToInt32(dr["office_vorlagenr"]).ToString(); ;
|
|
try
|
|
{
|
|
dokdata.Kopfzeile_generieren = false;
|
|
if (Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0][1]) == true) { dokdata.Kopfzeile_generieren = true; }
|
|
}
|
|
catch { }
|
|
|
|
if (dokdata.Barcode)
|
|
{
|
|
dokdata.barcode_left = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["bcpl"]);
|
|
dokdata.barcode_top = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["bcpt"]);
|
|
dokdata.barcode_width = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["bcw"]);
|
|
dokdata.barcode_height = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["bch"]);
|
|
dokdata.barcode_horizontal = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["bchorizontal"]);
|
|
dokdata.barcode_type = db.dsdaten.Tables[0].Rows[0]["BarcodeType"].ToString();
|
|
dokdata.barcode_content = db.dsdaten.Tables[0].Rows[0]["DatamatrixContent"].ToString();
|
|
string sql = "";
|
|
sql = "select bcpt, bcpl, bcw, bch, bchorizontal from OnDocBarcodeMpping ";
|
|
sql = sql + "where orig_bcpt = " + dokdata.barcode_top.ToString() + " and orig_bcpl=" + dokdata.barcode_left.ToString() + " ";
|
|
sql = sql + "and orig_bcw=" + dokdata.barcode_width.ToString() + " and orig_bch=" + dokdata.barcode_height.ToString();
|
|
db.Get_Tabledata(sql, false, true);
|
|
if (db.dsdaten.Tables[0].Rows.Count > 0)
|
|
{
|
|
dokdata.barcode_left = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["bcpl"]);
|
|
dokdata.barcode_top = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["bcpt"]);
|
|
dokdata.barcode_width = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["bcw"]);
|
|
dokdata.barcode_height = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["bch"]);
|
|
}
|
|
if (dokdata.barcode_type == "1")
|
|
{
|
|
DB dB = new DB(connectionstring);
|
|
dB.clear_parameter();
|
|
dB.add_parameter("@dokumentid", dokumentid);
|
|
dB.add_parameter("@DokumentidBR", "");
|
|
dB.add_parameter("@BARCODEFONTNAME", "");
|
|
dB.add_parameter("@BARCODEFONTSIZE", "");
|
|
dB.add_parameter("@BarcodeKantenlaenge", "");
|
|
dB.Get_Tabledata("sp_get_OnDoc_barcodetype_and_value", true, false);
|
|
dokdata.barcode_content = dB.dsdaten.Tables[0].Rows[0][1].ToString();
|
|
dokdata.barcode_formatn = dB.dsdaten.Tables[0].Rows[0][3].ToString();
|
|
dokdata.barcode_text = dB.dsdaten.Tables[0].Rows[0][4].ToString();
|
|
dokdata.barcode_kantenlaenge = dB.dsdaten.Tables[0].Rows[0][5].ToString();
|
|
dokdata.Zusatz_Font = dB.dsdaten.Tables[0].Rows[0][6].ToString();
|
|
dokdata.Zusatz_FontSize = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0][7]);
|
|
dokdata.barcode_width = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0][8]);
|
|
dokdata.barcode_height = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0][9]);
|
|
|
|
//dokdata.barcode_type= dB.dsdaten.Tables[0].Rows[0][3].ToString();
|
|
|
|
sql = "select bcpt, bcpl, bcw, bch, bchorizontal from OnDocBarcodeMpping ";
|
|
sql = sql + "where orig_bcpt = " + dokdata.barcode_top.ToString() + " and orig_bcpl=" + dokdata.barcode_left.ToString() + " ";
|
|
sql = sql + "and orig_bcw=" + dokdata.barcode_width.ToString() + " and orig_bch=" + dokdata.barcode_height.ToString();
|
|
dB.Get_Tabledata(sql, false, true);
|
|
if (dB.dsdaten.Tables[0].Rows.Count > 0)
|
|
{
|
|
Logging.Logging.Debug("Barcode-Übersteuerung" + dokdata.DokumenttypNr.ToString(), "Dokumenterstellung", "");
|
|
dokdata.barcode_left = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0]["bcpl"]);
|
|
dokdata.barcode_top = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0]["bcpt"]);
|
|
dokdata.barcode_width = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0]["bcw"]);
|
|
dokdata.barcode_height = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0]["bch"]);
|
|
}
|
|
}
|
|
db.Get_Tabledata("Select * from ondoc_appparams", false, true);
|
|
dokdata.barcode_font = db.dsdaten.Tables[0].Rows[0]["barcodefont"].ToString();
|
|
dokdata.barcode_fontsize = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["barcodefontsize"].ToString());
|
|
dokdata.Zusatz_Font = db.dsdaten.Tables[0].Rows[0]["Zusatzfont"].ToString();
|
|
dokdata.Zusatz_FontSize = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["ZusatzfontSize"].ToString());
|
|
dokdata.barcode_textposition = db.dsdaten.Tables[0].Rows[0]["barcodetextposition"].ToString(); ;
|
|
}
|
|
Model.clsdocgendata docgendata = new Model.clsdocgendata();
|
|
DataTable dokwertlist = new DataTable();
|
|
dokwertlist = db.Get_DokumentWertList("", Convert.ToInt32(doccreate.VorlagenTypID), 1);
|
|
|
|
docgendata.dokumentwerte = dokwertlist;
|
|
docgendata.partnernr = doccreate.Partnernr;
|
|
docgendata.inhaberadresse = "";
|
|
docgendata.zustelladresse = "";
|
|
docgendata.dokumenttypnr = doccreate.VorlagenTypID;
|
|
docgendata.unterschriftLinks = db.Get_Mitarbeiternr(doccreate.TGNrUnterschriftLinks).ToString();
|
|
docgendata.unterschriftRehts = db.Get_Mitarbeiternr(doccreate.TGNrUnterschriftRechts).ToString();
|
|
docgendata.verantwortlich = db.Get_Mitarbeiternr(doccreate.TGNrVerantwortlich).ToString();
|
|
docgendata.ersteller = db.Get_Mitarbeiternr(doccreate.TGNrErsteller).ToString();
|
|
docgendata.team = db.Get_Teamnr(docgendata.ersteller).ToString();
|
|
docgendata.digitaleunterschrift = false;
|
|
docgendata.frormularOhneUnterschrift = doccreate.OhneUnterschrift == "Yes";
|
|
docgendata.zustaendigkube = db.Get_Mitarbeiternr(doccreate.TGNrVerantwortlich).ToString();
|
|
docgendata.status = "-1";
|
|
docgendata.dokumentdatum = DateTime.Now.ToString("dd.MM.yyyy");
|
|
docgendata.dokumentdatum = doccreate.Dokumentdatum;
|
|
docgendata.frormularOhneUnterschrift = doccreate.OhneUnterschrift == "Yes";
|
|
docgendata.bezeichnung = doccreate.Bezeichnung;
|
|
if (doccreate.Result_FileType == "WORD") { docgendata.erstellungsart = Erstellungsart.DokumentBearbeiten; } else { docgendata.erstellungsart = Erstellungsart.DokumentAlsPDF; }
|
|
if (docgendata.verantwortlich == "0") { docgendata.verantwortlich = docgendata.ersteller; }
|
|
|
|
|
|
dokdata.PartnerNr = docgendata.partnernr;
|
|
dokdata.UseEDOKA_Values = "True";
|
|
dokdata.DokumenttypNr = docgendata.dokumenttypnr;
|
|
dokdata.Unterschrift_Links = docgendata.unterschriftLinks;
|
|
if (dokdata.Unterschrift_Links == "0") { dokdata.Unterschrift_Links = "-1"; }
|
|
dokdata.Unterschrift_Rechts = docgendata.unterschriftRehts;
|
|
if (dokdata.Unterschrift_Rechts == "0") { dokdata.Unterschrift_Rechts = "-1"; }
|
|
dokdata.Verantwortlich = docgendata.verantwortlich;
|
|
dokdata.Team = docgendata.team;
|
|
dokdata.Zustaendig = docgendata.zustaendigkube;
|
|
dokdata.Zustaendig = docgendata.zustaendigkube;
|
|
dokdata.Status = docgendata.status;
|
|
dokdata.Ersteller = docgendata.ersteller;
|
|
dokdata.DokumentDatum = docgendata.dokumentdatum;
|
|
dokdata.Termin = "01.01.1900";
|
|
dokdata.Bezeichnung = docgendata.bezeichnung;
|
|
dokdata.dokumentwerte = docgendata.dokumentwerte;
|
|
|
|
//Unterschriftenprüfung
|
|
dokdata.Form_ohne_Unterschrift = docgendata.frormularOhneUnterschrift.ToString();
|
|
dokdata.approval1 = 0;
|
|
dokdata.approval2 = 0;
|
|
dokdata.approved = 0;
|
|
if (dokdata.Form_ohne_Unterschrift == "True")
|
|
{
|
|
dokdata.Unterschrift_Links = "-1";
|
|
dokdata.Unterschrift_Rechts = "-1";
|
|
}
|
|
if (doccreate.FaksimileUnterschrift == "Yes")
|
|
{
|
|
dokdata.As_Faksimile = "True"; dokdata.sign = true; docgendata.digitaleunterschrift = true;
|
|
if (dokdata.Unterschrift_Links != "-1") { dokdata.approval1 = 1; }
|
|
if (dokdata.Unterschrift_Rechts != "-1") { dokdata.approval2 = 1; }
|
|
if (dokdata.Unterschrift_Links != "-1" && dokdata.Unterschrift_Rechts == "-1")
|
|
{
|
|
if (dokdata.Ersteller == dokdata.Unterschrift_Links)
|
|
{
|
|
dokdata.approved = 1;
|
|
}
|
|
else
|
|
{
|
|
dokdata.sign = false;
|
|
dokdata.toapprove = 1;
|
|
dokdata.approved = 0;
|
|
dokdata.approval1 = 0;
|
|
dokdata.approval2 = 1;
|
|
docgendata.erstellungsart = Erstellungsart.DokumentBearbeiten;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
docgendata.erstellungsart = Erstellungsart.DokumentBearbeiten;
|
|
dokdata.toapprove = 1;
|
|
dokdata.sign = false;
|
|
}
|
|
|
|
}
|
|
|
|
dokdata.APIValues = doccreate.APIValues;
|
|
|
|
if (doccreate.PrintLogo == "Yes") { dokdata.PrintLogo = true; } else { dokdata.PrintLogo = false; }
|
|
if (docgendata.erstellungsart == Erstellungsart.DokumentAlsPDF) { dokdata.Result_as_PDF = "True"; } else { dokdata.Result_as_PDF = "False"; }
|
|
if (docgendata.digitaleunterschrift == true) { dokdata.As_Faksimile = "True"; } else { dokdata.As_Faksimile = "False"; }
|
|
|
|
dokumentid = db.Create_EDOKA_Doc(dokdata, false, "");
|
|
dokdata.Dokumentid = dokumentid;
|
|
|
|
DOCGEN.Generator.DocGenerator_from_EDOKA Generator = new DOCGEN.Generator.DocGenerator_from_EDOKA(this.connectionstring, OwnHost, key.ToString());
|
|
clsdok dok = new clsdok("", "", "", "");
|
|
dok = Generator.Generate_Doc_EDOKA(dokumentid, ref dokdata, false, 0, false, false);
|
|
db.Save_To_DB(dokumentid, "", dok.dokument);
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende GenDoc DokumentID:" + dokumentid, LogLevelType.Debug);
|
|
APILogging.DocLog((HttpRequestMessage)Request, doccreate.Partnernr, "Dokument über API erstellt", dokumentid, LogLevelType.Info);
|
|
|
|
if (doccreate.Result_Versandstrasse == "Yes")
|
|
{
|
|
|
|
|
|
clsVersandstrasse vs = new clsVersandstrasse();
|
|
string vsdoc = "";
|
|
vsdoc = vs.Prepare_PDF(dokumentid, "", connectionstring, OwnHost, key.ToString(), imagepath);
|
|
|
|
Versandpaket vp = new Versandpaket();
|
|
vp.partnernr = Convert.ToInt32(docgendata.partnernr);
|
|
vp.GASAdresse = doccreate.GAS_Adresse;
|
|
if (vp.GASAdresse.ToString().Trim() == "") { vp.GAS="";} else { vp.GAS="true";}
|
|
vp.Versandoption = doccreate.Versand_Option; ;
|
|
List<Versanddokument> vdoc = new List<Versanddokument>();
|
|
Versanddokument vd = new Versanddokument(dokumentid, doccreate.Partnernr + " - " + dokdata.Bezeichnung, doccreate.Partnernr);
|
|
vd.dokument = vsdoc;
|
|
vdoc.Add(vd);
|
|
vp.Dokument = vdoc;
|
|
vp.finaldoc = vsdoc;
|
|
vp.send_onbase_doc = true;
|
|
vp.verified = true;
|
|
send_vs(ref vp, dokdata.Ersteller, doccreate.Versand_Direkt == "Yes", OwnHost, key.ToString(), dokumentid, doccreate.Partnernr);
|
|
|
|
|
|
}
|
|
if (doccreate.ConfirmationMail == "Yes")
|
|
{
|
|
|
|
string message = "Dokument '" + doccreate.Bezeichnung + "' für Partner " + doccreate.Partnernr + " erstellt." + Environment.NewLine;
|
|
if (doccreate.Result_Versandstrasse == "Yes")
|
|
{
|
|
if (doccreate.Versand_Direkt == "Yes")
|
|
{
|
|
message = message + " Dokument über Versandstrasse versendet.";
|
|
}
|
|
else
|
|
{
|
|
message = message + " Dokument über Versandstrasse bereit gestellt.";
|
|
}
|
|
}
|
|
}
|
|
|
|
return Ok(dokumentid);
|
|
|
|
}
|
|
private void send_vs(ref Versandpaket vp, string mitarbeiternr, bool direktversenden, string url, string key, string dokumentid, string partnernr)
|
|
{
|
|
string jsonstring = JsonConvert.SerializeObject(vp);
|
|
|
|
DB db = new DB(connectionstring);
|
|
db.clear_parameter();
|
|
db.add_parameter("@ersteller", mitarbeiternr);
|
|
db.Get_Tabledata("ondoc_create_versandpaket", true, false);
|
|
int paketid = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][0]);
|
|
|
|
|
|
db.Get_Tabledata_for_Update("Select top 1 * from Ondoc_Versandstrasse_Paket where id=" + paketid.ToString(), false, true);
|
|
DataRow dr = db.daten.Tables[0].Rows[0];
|
|
dr[2] = jsonstring;
|
|
dr["aktiv"] = 1;
|
|
dr["versandoption"] = vp.Versandoption.ToString();
|
|
dr["Bemerkung"] = vp.bemerkung;
|
|
// db.daten.Tables[0].Rows.Add(dr);
|
|
db.Update_Data();
|
|
|
|
db.daten.Tables.Clear();
|
|
db.Get_Tabledata_for_Update("Select * from ondoc_versandstrasse_paket_dokumentid where couvert_id = -1", false, true);
|
|
foreach (Versanddokument vd in vp.Dokument)
|
|
{
|
|
DataRow dr1 = db.daten.Tables[0].NewRow();
|
|
dr1[1] = paketid;
|
|
dr1[2] = vd.DokumentID;
|
|
dr1[3] = 1;
|
|
db.daten.Tables[0].Rows.Add(dr1);
|
|
|
|
}
|
|
db.Update_Data();
|
|
Logging.DocLog.Info("Versandpaket vorbereitet", "OnDoc-API", dokumentid, partnernr, "");
|
|
if (!direktversenden)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string URL = url + "api/Send_Versandstrasse?paketid=" + paketid.ToString();
|
|
|
|
|
|
|
|
WebRequest request;
|
|
var data = Encoding.UTF8.GetBytes(jsonstring);
|
|
request = WebRequest.Create(URL);
|
|
request.ContentLength = data.Length;
|
|
request.ContentType = "application/json";
|
|
request.Method = "POST";
|
|
request.Headers["Authorization"] = "Bearer " + key;
|
|
string response;
|
|
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();
|
|
}
|
|
if (response.ToString().Contains("*archiviert"))
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
Logging.DocLog.Info("Versandpaket versendet", "OnDoc-API", dokumentid, partnernr, "");
|
|
|
|
return;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logging.DocLog.Info("Direktversand nicht möglich: " + ex.Message, "OnDoc-API", dokumentid, partnernr, "");
|
|
}
|
|
|
|
}
|
|
|
|
private string CreateDoc_Verify(ref DocCreate doccreate)
|
|
{
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start GenDoc ", LogLevelType.Debug);
|
|
if (!(ParamCheck("partnernr", doccreate.Partnernr.ToString()))) { return "Partnernr " + doccreate.Partnernr + " ist ungültig"; }
|
|
if (!(ParamCheck("dokumenttyp", doccreate.VorlagenTypID))) { return "Vorlagentyp " + doccreate.VorlagenTypID + " ist ungültig"; }
|
|
if (!(ParamCheck("tgnr", doccreate.TGNrErsteller))) { return "TGNr-Ersteller " + doccreate.TGNrErsteller + " ist ungültig"; }
|
|
if (!(ParamCheck("tgnr", doccreate.TGNrVerantwortlich))) { return "TGNr-Verantwortlich " + doccreate.TGNrVerantwortlich + " ist ungültig"; }
|
|
if (!(ParamCheck("tgnr", doccreate.TGNrUnterschriftLinks))) { return "TGNr-Unterschriftlinks " + doccreate.TGNrUnterschriftLinks + " ist ungültig"; }
|
|
if (!(ParamCheck("tgnr", doccreate.TGNrUnterschriftRechts))) { return "TGNr-Unterschriftrechts " + doccreate.TGNrUnterschriftRechts + " ist ungültig"; }
|
|
if (!(ParamCheck("yesno", doccreate.FaksimileUnterschrift))) { return "Parameter Faxsimile " + doccreate.FaksimileUnterschrift + " ist ungültig"; }
|
|
if (!(ParamCheck("yesno", doccreate.OhneUnterschrift))) { return "Parameter Form ohne Unterschrift " + doccreate.OhneUnterschrift + " ist ungültig"; }
|
|
if (!(ParamCheck("yesno", doccreate.PrintLogo))) { return "Parameter PrintLogo " + doccreate.PrintLogo + " ist ungültig"; }
|
|
if (!(ParamCheck("yesno", doccreate.Result_Versandstrasse))) { return "Parameter Result_Versandstrasse " + doccreate.Result_Versandstrasse + " ist ungültig"; }
|
|
if (!(ParamCheck("yesno", doccreate.Versand_Direkt))) { return "Parameter Versand Direkt " + doccreate.Versand_Direkt + " ist ungültig"; }
|
|
if (!(ParamCheck("yesno", doccreate.Result_OnDoc))) { return "Parameter Result_OnDoc " + doccreate.Result_OnDoc + " ist ungültig"; }
|
|
if (!(ParamCheck("yesno", doccreate.Result_Sender))) { return "Parameter Result_Sender " + doccreate.Result_Sender + " ist ungültig"; }
|
|
if (!(ParamCheck("filetype", doccreate.Result_FileType))) { return "Parameter Result_Filetype " + doccreate.Result_FileType + " ist ungültig"; }
|
|
if (!(ParamCheck("yesno", doccreate.ConfirmationMail))) { return "Parameter ConfirmationMail " + doccreate.ConfirmationMail + " ist ungültig"; }
|
|
if (!(ParamCheck("yesno", doccreate.ConfirmationMail))) { return "Parameter ConfirmationMail " + doccreate.ConfirmationMail + " ist ungültig"; }
|
|
if (!(ParamCheck("versandoption", doccreate.Versand_Option))) { return "Versandoption " + doccreate.Versand_Option + " ist ungültig"; }
|
|
if (doccreate.ConfirmationMail.ToUpper() == "YES" && doccreate.ConfirmationMailAddress.ToString() != "") { return "E-Mailadresse für Confirmation fehlt"; }
|
|
if (doccreate.TGNrUnterschriftLinks.ToString() == "") { doccreate.TGNrUnterschriftLinks = "-1"; }
|
|
if (doccreate.TGNrUnterschriftRechts.ToString() == "") { doccreate.TGNrUnterschriftRechts = "-1"; }
|
|
if (doccreate.FaksimileUnterschrift.ToUpper() == "YES")
|
|
{
|
|
if (doccreate.TGNrUnterschriftLinks.ToString() == "-1") { return "Faksimile Unterschrift benötigt mit den Parameter TGUnterschriftLinks"; }
|
|
if (doccreate.TGNrUnterschriftLinks.ToString() != "")
|
|
{
|
|
string path = System.Configuration.ConfigurationManager.AppSettings["UnterschriftPath"].ToString() + doccreate.TGNrUnterschriftLinks.ToString() + ".jpg";
|
|
if (!System.IO.File.Exists(path)) { return "Image Unterschrift links " + doccreate.TGNrUnterschriftLinks + " ist nicht vorhanden"; }
|
|
}
|
|
if (doccreate.TGNrUnterschriftRechts.ToString() != "-1")
|
|
{
|
|
string path = System.Configuration.ConfigurationManager.AppSettings["UnterschriftPath"].ToString() + doccreate.TGNrUnterschriftLinks.ToString() + ".jpg";
|
|
if (!System.IO.File.Exists(path)) { return "Image Unterschrift rechts " + doccreate.TGNrUnterschriftRechts + " ist nicht vorhanden"; }
|
|
}
|
|
}
|
|
if (doccreate.Result_Versandstrasse == "Yes")
|
|
{
|
|
if (ParamCheck("doktypversandstrasse", doccreate.VorlagenTypID) == false) { return "Vorlagentyp " + doccreate.VorlagenTypID + " ist nicht für die Versandstrasse konfiguriert"; }
|
|
if (doccreate.TGNrUnterschriftLinks.ToLower() != "-1" && doccreate.TGNrUnterschriftRechts.ToString() != "-1") { return "Versandstrasse mit zwei Unterschriften kann nicht automatisch angesteuert werden"; }
|
|
if (doccreate.Versand_Option == "") { return "Versandoption fehlt (A_Post, B1_Post, B2_Post"; }
|
|
}
|
|
return "";
|
|
}
|
|
catch (Exception ex) { return ex.Message; }
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
[Route("API/GenDoc")]
|
|
public IHttpActionResult GenDoc(string Partnernr, String Dokumenttypnr, string TGCreator = "", string TGResp = "", string TGUL = "", string TGUR = "", string Faksimile = "", string FoU = "", string PrintLogo = "")
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start GenDoc ", LogLevelType.Debug);
|
|
|
|
if (!(ParamCheck("partnernr", Partnernr))) { return BadRequest("Partnernr " + Partnernr + " ist ungültig"); }
|
|
if (!(ParamCheck("dokumenttyp", Dokumenttypnr))) { return BadRequest("Dokumenttyp " + Dokumenttypnr + " ist ungültig"); }
|
|
if (!(ParamCheck("tgcreator", TGCreator))) { return BadRequest("TGCreator " + TGCreator + " ist ungültig"); }
|
|
if (!(ParamCheck("tgresp", TGResp))) { return BadRequest("TGResp " + TGResp + " ist ungültig"); }
|
|
if (!(ParamCheck("tgul", TGUL))) { return BadRequest("TG Unterschrift links " + TGUL + " ist ungültig"); }
|
|
if (!(ParamCheck("tgul", TGUR))) { return BadRequest("TG Unterschrift rechts " + TGUR + " ist ungültig"); }
|
|
if (!(ParamCheck("faksimile", Faksimile))) { return BadRequest("Parameter Faxsimile " + Faksimile + " ist ungültig"); }
|
|
if (!(ParamCheck("formohneunterschrift", FoU))) { return BadRequest("Parameter Form ohne Unterschrift " + FoU + " ist ungültig"); }
|
|
if (!(ParamCheck("printlogo", PrintLogo))) { return BadRequest("Parameter PrintLogo " + PrintLogo + " ist ungültig"); }
|
|
|
|
|
|
|
|
Database.DB db = new DB(connectionstring);
|
|
Model.clsdocgendata docgendata = new Model.clsdocgendata();
|
|
|
|
docgendata.partnernr = Partnernr;
|
|
docgendata.inhaberadresse = "";
|
|
docgendata.zustelladresse = "";
|
|
docgendata.dokumenttypnr = Dokumenttypnr;
|
|
docgendata.unterschriftLinks = db.Get_Mitarbeiternr(TGUL).ToString();
|
|
docgendata.unterschriftRehts = db.Get_Mitarbeiternr(TGUR).ToString();
|
|
docgendata.verantwortlich = db.Get_Mitarbeiternr(TGResp).ToString();
|
|
docgendata.ersteller = db.Get_Mitarbeiternr(TGCreator).ToString();
|
|
docgendata.team = db.Get_Teamnr(docgendata.ersteller).ToString();
|
|
docgendata.digitaleunterschrift = false;
|
|
docgendata.frormularOhneUnterschrift = false;
|
|
//docgendata.team = "";
|
|
docgendata.zustaendigkube = db.Get_Mitarbeiternr(TGResp).ToString();
|
|
docgendata.status = "-1";
|
|
docgendata.dokumentdatum = DateTime.Now.ToString("dd.MM.yyyy");
|
|
docgendata.bezeichnung = "";
|
|
docgendata.erstellungsart = Erstellungsart.DokumentAlsPDF;
|
|
docgendata.verantwortlich = db.Get_Mitarbeiternr(TGResp).ToString();
|
|
if (docgendata.verantwortlich == "0") { docgendata.verantwortlich = docgendata.ersteller; }
|
|
|
|
clsDocData dokdata = new clsDocData();
|
|
|
|
//Barcode-Parameter von Dokumenttyp
|
|
dokdata.PartnerNr = docgendata.partnernr;
|
|
dokdata.UseEDOKA_Values = "True";
|
|
dokdata.DokumenttypNr = docgendata.dokumenttypnr;
|
|
dokdata.Unterschrift_Links = docgendata.unterschriftLinks;
|
|
dokdata.Unterschrift_Rechts = docgendata.unterschriftRehts;
|
|
dokdata.Verantwortlich = docgendata.verantwortlich;
|
|
dokdata.Team = docgendata.team;
|
|
dokdata.Zustaendig = docgendata.zustaendigkube;
|
|
dokdata.Zustaendig = docgendata.zustaendigkube;
|
|
dokdata.Status = docgendata.status;
|
|
dokdata.Ersteller = docgendata.ersteller;
|
|
dokdata.DokumentDatum = docgendata.dokumentdatum;
|
|
dokdata.Bezeichnung = docgendata.bezeichnung;
|
|
if (PrintLogo == "Yes") { dokdata.PrintLogo = true; } else { dokdata.PrintLogo = false; }
|
|
if (docgendata.erstellungsart == Erstellungsart.DokumentAlsPDF) { dokdata.Result_as_PDF = "True"; } else { dokdata.Result_as_PDF = "False"; }
|
|
if (docgendata.digitaleunterschrift == true) { dokdata.As_Faksimile = "True"; } else { dokdata.As_Faksimile = "False"; }
|
|
|
|
string dokumentid = "";
|
|
dokumentid = db.Create_EDOKA_Doc(dokdata, false, "");
|
|
dokdata.Dokumentid = dokumentid;
|
|
DOCGEN.Generator.DocGenerator_from_EDOKA Generator = new DOCGEN.Generator.DocGenerator_from_EDOKA(this.connectionstring);
|
|
clsdok dok = new clsdok("", "", "", "");
|
|
dok = Generator.Generate_Doc_EDOKA(dokumentid, ref dokdata);
|
|
db.Save_To_DB(dokumentid, "", dok.dokument);
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende GenDoc DokumentID:" + dokumentid, LogLevelType.Debug);
|
|
|
|
return Ok(dokumentid);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
|
|
|
|
}
|
|
private bool ParamCheck(string ParamType, string ParamValue)
|
|
{
|
|
DB db = new DB(connectionstring);
|
|
try
|
|
{
|
|
|
|
switch (ParamType)
|
|
{
|
|
case "partnernr":
|
|
db.Get_Tabledata("Select count(*) from partner where nrpar00=" + ParamValue, false, true);
|
|
if (db.dsdaten.Tables[0].Rows[0][0].ToString() == "0") { return false; }
|
|
break;
|
|
case "dokumenttyp":
|
|
db.Get_Tabledata("Select count(*) from dokumenttyp where dokumenttypnr=" + ParamValue, false, true);
|
|
if (db.dsdaten.Tables[0].Rows[0][0].ToString() == "0") { return false; }
|
|
break;
|
|
case "partnerdokumenttyp":
|
|
//Prüfung Person/Doktyp BP/Doktyp
|
|
break;
|
|
case "tgcreator":
|
|
case "tgresp":
|
|
case "tgul":
|
|
case "tgur":
|
|
case "tgnr":
|
|
if (ParamType == "tgcreator" && ParamValue == "") { return false; } else { if (ParamValue == "") { return true; } };
|
|
db.Get_Tabledata("Select count(*) from mitarbeiter where tgnummer='" + ParamValue + "'", false, true);
|
|
if (db.dsdaten.Tables[0].Rows[0][0].ToString() == "0") { return false; }
|
|
break;
|
|
case "yesno":
|
|
if (ParamValue != "Yes" && ParamValue != "No" && ParamValue != "") { return false; };
|
|
break;
|
|
case "filetype":
|
|
if (ParamValue != "WORD" && ParamValue != "PDF") { return false; }
|
|
break;
|
|
case "versandoption":
|
|
if (ParamValue != "A_POST" && ParamValue != "B1_POST" && ParamValue != "B2_POST" && ParamValue != "") { return false; }
|
|
break;
|
|
case "doktypversandstrasse":
|
|
db.Get_Tabledata("Select versandstrasse_moeglich, versandstrasse_firstdoc from dokumenttyp where dokumenttypnr=" + ParamValue, false, true);
|
|
if (Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][0]) == 0 || Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][1]) == 0) { return false; }
|
|
break;
|
|
default:
|
|
return false;
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
finally
|
|
{
|
|
db = null;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|