Für etwaige Programmierer unter Ihnen

Hier ein Beispiel zu meinem vorletzten Eintrag.

Wieder nur für Programmierer:

Schauen Sie sich das mal an (chatgtp generierter Code)

using System;

using System.Data;

using System.Linq;

using Dapper;

using QSS.Contfakt.Data;

public sealed class XInvoiceSellerWriter {

private readonly IDbConnection _db;

public XInvoiceSellerWriter(IDbConnection db) {

_db = db;

}

public void Write(int documentId, string documentType, int mandantId) {

var fields = _db.Query<XInvoiceFieldMap>(

@“SELECT *

FROM dbo.xinvoice_field_map

WHERE section = ‚SELLER'“

).ToList();

_db.Execute(@“

DELETE FROM dbo.xinvoice_data

WHERE document_id = @DocId

AND document_type = @DocType

AND party_role = ‚SELLER'“,

new { DocId = documentId, DocType = documentType });

foreach (var f in fields) {

if (string.IsNullOrWhiteSpace(f.SourceTable) ||

string.IsNullOrWhiteSpace(f.SourceField) ||

string.IsNullOrWhiteSpace(f.BtCode))

throw new InvalidOperationException(

$“Invalid mapping row for BT {f.BtCode}“);

var sql = $@“

SELECT [{f.SourceField}]

FROM tv.[{f.SourceTable}]

WHERE MandantenNummer = @MandantID“;

var value = _db.ExecuteScalar(sql, new { MandantID = mandantId });

InsertValue(documentId, documentType, f, value);

}

}

private void InsertValue(

int documentId,

string documentType,

XInvoiceFieldMap f,

object value) {

const string sql = @“

INSERT INTO dbo.xinvoice_data

(document_id, document_type, party_role, bt_code,

value_text, value_number, value_date)

VALUES

(@DocId, @DocType, ‚SELLER‘, @Bt,

@Text, @Number, @Date)“;

_db.Execute(sql, new {

DocId = documentId,

DocType = documentType,

Bt = f.BtCode,

Text = f.ValueType == „text“ ? value : null,

Number = f.ValueType == „number“ ? value : null,

Date = f.ValueType == „date“ ? value : null

});

}

}

Hey, was hast Du, alter Mann, es läuft doch ….

100:1 das wird Code mit dem wir Alten uns in naher Zukunft rumäergern müssen/dürfen.

Wirklich?

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert