126 lines
4.3 KiB
C#
126 lines
4.3 KiB
C#
using GenDocCli;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Data.SqlTypes;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Tool_Check_DokID_Partner.Properties;
|
|
|
|
namespace Tool_Check_DokID_Partner
|
|
{
|
|
internal class Program
|
|
{
|
|
public class OnBaseDokument
|
|
{
|
|
public string dokumentTyp { get; set; }
|
|
public string dokumentDatum { get; set; }
|
|
public string dateiTyp { get; set; }
|
|
public string bpNummer { get; set; }
|
|
public string personNummer { get; set; }
|
|
public string dokumentDatei { get; set; }
|
|
public string ReferenceId { get; set; }
|
|
public List<attribute> attributes { get; set; }
|
|
}
|
|
|
|
public class attribute
|
|
{
|
|
public string fieldname { get; set; }
|
|
public string fieldvalue { get; set; }
|
|
|
|
public attribute(string fname, string fvalue)
|
|
{
|
|
fieldname = fname;
|
|
fieldvalue = fvalue;
|
|
}
|
|
}
|
|
|
|
private static readonly Logger Logger =
|
|
LogManager.GetCurrentClassLogger();
|
|
static void Main(string[] args)
|
|
{
|
|
|
|
string logFile = args[0];
|
|
string okLogFile = args[1];
|
|
string errorLogFile = args[2];
|
|
string logLevel = args[2];
|
|
|
|
NLogConfigurator.Configure(logFile, logLevel);
|
|
Logger.Info("Programmstart");
|
|
DirectoryInfo d = new DirectoryInfo(Settings.Default.Path); //Assuming Test is your Folder
|
|
|
|
FileInfo[] Files = d.GetFiles("offedk*.json.pdf"); //Getting Text files
|
|
string str = "";
|
|
|
|
foreach (FileInfo file in Files)
|
|
{
|
|
Logger.Info("File: {0}", file.Name);
|
|
string bp = get_bp(file.Name);
|
|
|
|
OnBaseDokument od = new OnBaseDokument();
|
|
//dynamic data = JsonConvert.DeserializeObject(result);
|
|
var jsonText = File.ReadAllText(Settings.Default.Path + "\\" + file.Name.Substring(0,22)+".json");
|
|
od = JsonConvert.DeserializeObject<OnBaseDokument>(jsonText);
|
|
if (bp.Length > 8)
|
|
{
|
|
if (od.personNummer != bp)
|
|
{
|
|
Logger.Error("Fehler: {0} - {1} - {2}", file.Name, od.personNummer, bp);
|
|
File.AppendAllText(
|
|
errorLogFile,
|
|
"Personnummer stimmt nicht überein: " + od.personNummer + " != " + bp + " " + file.Name+Environment.NewLine);
|
|
Console.WriteLine("Personnummer stimmt nicht überein: " + od.personNummer + " != " + bp + " " + file.Name);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (od.bpNummer != bp)
|
|
{
|
|
Logger.Error("Fehler: {0} - {1} - {2}", file.Name, od.bpNummer, bp);
|
|
File.AppendAllText(
|
|
errorLogFile,
|
|
"BP-Nummer stimmt nicht überein: " + od.bpNummer + " != " + bp + " " + file.Name+Environment.NewLine);
|
|
Console.WriteLine("BP-Nummer stimmt nicht überein: " + od.bpNummer + " != " + bp + " " + file.Name);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
Logger.Info("Ende");
|
|
|
|
}
|
|
|
|
static string get_bp(string str)
|
|
{
|
|
string dokid = str.Substring(0, 22);
|
|
|
|
string sql = "SELECT top 1 nrpar00 from dokument where dokumentid='" + dokid + "'";
|
|
|
|
using (SqlConnection conn = new SqlConnection(Settings.Default.Connectionstring))
|
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
|
{
|
|
try
|
|
{
|
|
|
|
conn.Open();
|
|
int result = (int)cmd.ExecuteScalar();
|
|
conn.Close();
|
|
return result.ToString();
|
|
|
|
}
|
|
catch
|
|
{
|
|
Logger.Error("Fehler beim Abrufen der BP-Nummer für DokumentID: {0}", dokid);
|
|
return "";
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|