query von liste oder sql command
This commit is contained in:
parent
16e858597e
commit
9177e7371c
@ -16,10 +16,15 @@
|
||||
</client>
|
||||
</system.serviceModel>
|
||||
<appSettings>
|
||||
<add key="username" value="TestBrainpool"/>
|
||||
<add key="password" value="09Test2015"/>
|
||||
<add key="query" value="(INH="BRAINPOOL" OR ANM="BRAINPOOL") AND (DB=DE OR DB=EM OR DB=IR)"/>
|
||||
<add key="connstring" value="Data Source=172.24.12.41\tests;Initial Catalog=DD_ECM;Persist Security Info=True;User ID=sa;Password=dd"/>
|
||||
<add key="database" value="DD_ECM" />
|
||||
<!-- Die Zugangangsdaten, die für den Zugriff auf die DPMA Datenbank benötigt werden -->
|
||||
<add key="dpma_username" value="TestBrainpool"/>
|
||||
<add key="dpma_password" value="09Test2015"/>
|
||||
<!-- query erwartet entweder eine mit Kommagetrennte List oder einen SQL Befehl, der ein einspaltiges Ergebnis liefert -->
|
||||
<!-- <add key="dpma_query" value="SELECT [Unternehmen] FROM [DD_ECM].[dbo].[VWTEMP_PMO_FORM19] WHERE ProdUnternehmen = 1 ORDER BY Unternehmen"/> -->
|
||||
<add key="dpma_query" value="BRAINPOOL Artist und Content Services GmbH,BRAINPOOL TV GmbH,BRAINPOOL TV GmbH / Stein TV,Elton TV Produktions GmbH,Köln Comedy Festival GmbH,Kuttner TV GmbH,Ladykracher TV GmbH,MARIO BARTH TV Produktionsgesellschaft mbH ,mea culpa TV Production GmbH,Millionärswahl Formatentwicklungs- und -verwertungsgesellschaft mbH,Minestrone TV Produktions GbR ,Pocher TV GmbH,Princess TV GmbH ,Punani Enterprises GmbH,Raab TV-Produktion GmbH,Stein TV-Produktion GmbH,Ulmen Television GmbH"/>
|
||||
<!-- Die Verbindung, in die das Ergebnis des Imports eingelesen wird, damit werden auch dpma_searchvalues ausgelesen! -->
|
||||
<add key="sql_connstring" value="Data Source=172.24.12.41\tests;Initial Catalog=DD_ECM;Persist Security Info=True;User ID=sa;Password=dd"/>
|
||||
<!-- Die Datenbank, in die das Ergebnis eingelesen wird und die Datenbank, die Record-Organizer/ADDI benutzt -->
|
||||
<add key="sql_database" value="DD_ECM" />
|
||||
</appSettings>
|
||||
</configuration>
|
||||
@ -108,6 +108,7 @@
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="Parser.vb" />
|
||||
<Compile Include="Querybuilder.vb" />
|
||||
<Compile Include="Service References\DPMA.Marke\Reference.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
@ -10,11 +10,11 @@ Public Class AppConfig
|
||||
Dim appsettings As AppSettingsSection = appconfig.AppSettings
|
||||
Dim settings As KeyValueConfigurationCollection = appsettings.Settings
|
||||
|
||||
Dim username As String = settings.Item("username").Value
|
||||
Dim password As String = settings.Item("password").Value
|
||||
Dim query As String = settings.Item("query").Value
|
||||
Dim connstring As String = settings.Item("connstring").Value
|
||||
Dim database As String = settings.Item("database").Value
|
||||
Dim username As String = settings.Item("dpma_username").Value
|
||||
Dim password As String = settings.Item("dpma_password").Value
|
||||
Dim query As String = settings.Item("dpma_query").Value
|
||||
Dim connstring As String = settings.Item("sql_connstring").Value
|
||||
Dim database As String = settings.Item("sql_database").Value
|
||||
|
||||
Return New ConfigValues(username, password, query, connstring, database)
|
||||
End Function
|
||||
|
||||
@ -1,15 +1,19 @@
|
||||
Imports System.Data.SqlClient
|
||||
Imports NLog
|
||||
|
||||
Public Class DB
|
||||
Private _connstring
|
||||
Private _db
|
||||
Private _logger As Logger
|
||||
|
||||
Public FormId
|
||||
Public ControlId
|
||||
Public RecordId
|
||||
Public Username As String = "BrainpoolImporter"
|
||||
|
||||
|
||||
Public Sub New(connectionString As String, dbname As String)
|
||||
_logger = LogManager.GetLogger("DB")
|
||||
_connstring = connectionString
|
||||
_db = dbname
|
||||
End Sub
|
||||
@ -30,6 +34,7 @@ Public Class DB
|
||||
End Function
|
||||
|
||||
Public Function GetProperty(m As Mark, propertyName As String) As Object
|
||||
_logger.Debug("Reading property: {0}, Mark? {1}", propertyName, IsNothing(m))
|
||||
Dim value = CallByName(m, propertyName, CallType.Get)
|
||||
If (value = Nothing) Then
|
||||
value = DBNull.Value
|
||||
|
||||
@ -19,6 +19,7 @@ Module Main
|
||||
Private dpma As DPMAConnect
|
||||
Private db As DB
|
||||
|
||||
Private query As String
|
||||
Private config As ConfigValues
|
||||
Private marks As New List(Of Mark)
|
||||
Private props = New List(Of String) From {
|
||||
@ -44,6 +45,7 @@ Module Main
|
||||
Try
|
||||
logger = LogManager.GetLogger("Main")
|
||||
config = AppConfig.GetConfiguration()
|
||||
db = New DB(config.connstring, "DD_ECM")
|
||||
|
||||
logger.Info("{0} started", My.Application.Info.Title)
|
||||
|
||||
@ -55,12 +57,13 @@ Module Main
|
||||
Directory.CreateDirectory(LogDir)
|
||||
End If
|
||||
|
||||
query = Querybuilder.Build(config, db)
|
||||
|
||||
' Abfrage starten
|
||||
logger.Info("Sending request with query: {0}", config.query)
|
||||
logger.Info("Sending request with query: {0}", query)
|
||||
dpma = New DPMAConnect(config.username, config.password)
|
||||
|
||||
mainDoc = dpma.Search(config.query)
|
||||
mainDoc = dpma.Search(query)
|
||||
mainDoc.Save(MainPath)
|
||||
|
||||
' Ergebnis auslesen und Marken-Klassen erstellen
|
||||
@ -84,7 +87,6 @@ Module Main
|
||||
|
||||
' =========================================================================================
|
||||
|
||||
db = New DB(config.connstring, "DD_ECM")
|
||||
Dim formId As Integer = db.GetFormId()
|
||||
Dim updatedMarks As Integer = 0
|
||||
Dim addedMarks As Integer = 0
|
||||
@ -124,6 +126,7 @@ Module Main
|
||||
If value = "wort-bildmarke" Or value = "bildmarke" Then
|
||||
Dim imageControlId = db.GetControlId(formId, "MarkImage")
|
||||
Dim bimage() As Byte = Convert.FromBase64String(m.Image.BinaryImage)
|
||||
logger.Debug("Image inserted, RecordId: {0}")
|
||||
db.InsertImage(bimage, imageControlId, recordId)
|
||||
End If
|
||||
End If
|
||||
@ -178,6 +181,9 @@ Module Main
|
||||
logger.Debug("=================== IMPORT END ===================")
|
||||
|
||||
Catch ex As Exception
|
||||
logger.Error("==================================================")
|
||||
logger.Error("=================== ERROR ========================")
|
||||
logger.Error("==================================================")
|
||||
logger.Error("An Error occurred: {0}", GetExceptionInfo(ex))
|
||||
Environment.Exit(1)
|
||||
End Try
|
||||
|
||||
@ -22,6 +22,25 @@ Public Class Mark
|
||||
Private _OppositionPeriodEndDate As Date 'Ablauf Widerspruchsfrist
|
||||
Private _Image As ImageDetail
|
||||
|
||||
Private Function ReplaceSingleQuote(value As String)
|
||||
Return value.Replace("'", "''")
|
||||
End Function
|
||||
|
||||
Private Function ReplaceUmlauts(value As String)
|
||||
Dim result = value.Replace("ae", "ä")
|
||||
result = result.Replace("oe", "ö")
|
||||
result = result.Replace("ue", "ü")
|
||||
Return result
|
||||
End Function
|
||||
|
||||
Private Function DecodeHTML(value As String)
|
||||
Return WebUtility.HtmlDecode(value)
|
||||
End Function
|
||||
|
||||
Private Function ParseShortDate(value As String)
|
||||
Return DateTime.Parse(value).ToShortDateString()
|
||||
End Function
|
||||
|
||||
#Region "SearchProperties"
|
||||
Public Property RegistrationOfficeCode As String
|
||||
Get
|
||||
@ -37,7 +56,7 @@ Public Class Mark
|
||||
Return _RegistrationDate
|
||||
End Get
|
||||
Set(value As String)
|
||||
_RegistrationDate = DateTime.Parse(value).ToShortDateString()
|
||||
_RegistrationDate = ParseShortDate(value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
@ -55,9 +74,7 @@ Public Class Mark
|
||||
Return _MarkCurrentStatusCode
|
||||
End Get
|
||||
Set(value As String)
|
||||
value = value.Replace("ae", "ä")
|
||||
value = value.Replace("oe", "ö")
|
||||
value = value.Replace("ue", "ü")
|
||||
value = ReplaceUmlauts(value)
|
||||
|
||||
_MarkCurrentStatusCode = value
|
||||
End Set
|
||||
@ -68,7 +85,10 @@ Public Class Mark
|
||||
Return _MarkVerbalElementText
|
||||
End Get
|
||||
Set(value As String)
|
||||
_MarkVerbalElementText = WebUtility.HtmlDecode(value)
|
||||
value = DecodeHTML(value)
|
||||
value = ReplaceSingleQuote(value)
|
||||
|
||||
_MarkVerbalElementText = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
@ -86,7 +106,7 @@ Public Class Mark
|
||||
Return _ApplicationDate
|
||||
End Get
|
||||
Set(value As String)
|
||||
_ApplicationDate = DateTime.Parse(value).ToShortDateString()
|
||||
_ApplicationDate = ParseShortDate(value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
@ -104,7 +124,10 @@ Public Class Mark
|
||||
Return _Applicant
|
||||
End Get
|
||||
Set(value As String)
|
||||
_Applicant = WebUtility.HtmlDecode(value)
|
||||
value = DecodeHTML(value)
|
||||
value = ReplaceSingleQuote(value)
|
||||
|
||||
_Applicant = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
@ -113,7 +136,10 @@ Public Class Mark
|
||||
Return _Representative
|
||||
End Get
|
||||
Set(value As String)
|
||||
_Representative = WebUtility.HtmlDecode(value)
|
||||
value = DecodeHTML(value)
|
||||
value = ReplaceSingleQuote(value)
|
||||
|
||||
_Representative = value
|
||||
End Set
|
||||
End Property
|
||||
#End Region
|
||||
@ -123,7 +149,7 @@ Public Class Mark
|
||||
Return _PublicationDate
|
||||
End Get
|
||||
Set(value As String)
|
||||
_PublicationDate = DateTime.Parse(value).ToShortDateString()
|
||||
_PublicationDate = ParseShortDate(value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
@ -132,7 +158,7 @@ Public Class Mark
|
||||
Return _ExpiryDate
|
||||
End Get
|
||||
Set(value As String)
|
||||
_ExpiryDate = DateTime.Parse(value).ToShortDateString()
|
||||
_ExpiryDate = ParseShortDate(value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
@ -141,7 +167,7 @@ Public Class Mark
|
||||
Return _TerminationDate
|
||||
End Get
|
||||
Set(value As String)
|
||||
_TerminationDate = DateTime.Parse(value).ToShortDateString()
|
||||
_TerminationDate = ParseShortDate(value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
@ -150,7 +176,7 @@ Public Class Mark
|
||||
Return _OppositionPeriodStartDate
|
||||
End Get
|
||||
Set(value As String)
|
||||
_OppositionPeriodStartDate = DateTime.Parse(value).ToShortDateString()
|
||||
_OppositionPeriodStartDate = ParseShortDate(value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
@ -159,7 +185,7 @@ Public Class Mark
|
||||
Return _OppositionPeriodEndDate
|
||||
End Get
|
||||
Set(value As String)
|
||||
_OppositionPeriodEndDate = DateTime.Parse(value).ToShortDateString()
|
||||
_OppositionPeriodEndDate = ParseShortDate(value)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
@ -216,7 +242,7 @@ End Class
|
||||
|
||||
Public Class ClassificationDetail
|
||||
Public ClassNumber As String
|
||||
Public GoodsServicesDescription
|
||||
Public GoodsServicesDescription As String
|
||||
|
||||
Public Sub New()
|
||||
End Sub
|
||||
|
||||
56
app/BrainpoolXmlParser/Querybuilder.vb
Normal file
56
app/BrainpoolXmlParser/Querybuilder.vb
Normal file
@ -0,0 +1,56 @@
|
||||
Public Class Querybuilder
|
||||
|
||||
Public Shared Function Build(config As ConfigValues, db As DB)
|
||||
Dim suffixQuery As String = "AND (DB=DE OR DB=EM OR DB=IR)"
|
||||
Dim mainQuery As String
|
||||
Dim baseQuery As String
|
||||
Dim companies As List(Of String)
|
||||
|
||||
' searchvalues ist entweder eine SQL Abfrage oder eine Kommagetrennte Liste
|
||||
If config.query.ToUpper.StartsWith("SELECT") Then
|
||||
companies = GetLiveQueryResult(config.query, db)
|
||||
Else
|
||||
companies = New List(Of String)(config.query.Split(","))
|
||||
End If
|
||||
|
||||
mainQuery = BuildMainQuery(companies)
|
||||
baseQuery = String.Format("({0}) {1}", mainQuery, suffixQuery)
|
||||
|
||||
Return baseQuery
|
||||
End Function
|
||||
|
||||
Public Shared Function BuildMainQuery(companies As List(Of String)) As String
|
||||
Dim query As String = ""
|
||||
|
||||
For Each company As String In companies
|
||||
Dim querypart As String = String.Format("(INH=""{0}"" OR ANM=""{0}"")", company.Trim())
|
||||
|
||||
query &= querypart
|
||||
|
||||
' Bei alles bis auf das letzte Unternehmen einen OR Operator einfügen
|
||||
If (companies.IndexOf(company) + 1) < companies.Count Then
|
||||
query &= " OR "
|
||||
End If
|
||||
Next
|
||||
|
||||
Return query
|
||||
End Function
|
||||
|
||||
Public Shared Function GetLiveQueryResult(query As String, db As DB) As List(Of String)
|
||||
Dim result As New List(Of String)
|
||||
Dim SQL As String = query
|
||||
Dim DT As DataTable = db.QueryTable(SQL)
|
||||
|
||||
If DT.Rows.Count = 0 Then
|
||||
Throw New Exception("SQL Abfrage lieferte ein leeres Ergebnis zurück: " & query)
|
||||
End If
|
||||
|
||||
For Each row As DataRow In DT.Rows
|
||||
Dim item As String = CStr(row.Item(0)).Trim()
|
||||
result.Add(row.Item(0))
|
||||
Next
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
End Class
|
||||
Loading…
x
Reference in New Issue
Block a user