query von liste oder sql command

This commit is contained in:
JenneJ 2015-11-02 13:54:12 +01:00
parent 16e858597e
commit 9177e7371c
7 changed files with 126 additions and 27 deletions

View File

@ -16,10 +16,15 @@
</client> </client>
</system.serviceModel> </system.serviceModel>
<appSettings> <appSettings>
<add key="username" value="TestBrainpool"/> <!-- Die Zugangangsdaten, die für den Zugriff auf die DPMA Datenbank benötigt werden -->
<add key="password" value="09Test2015"/> <add key="dpma_username" value="TestBrainpool"/>
<add key="query" value="(INH=&quot;BRAINPOOL&quot; OR ANM=&quot;BRAINPOOL&quot;) AND (DB=DE OR DB=EM OR DB=IR)"/> <add key="dpma_password" value="09Test2015"/>
<add key="connstring" value="Data Source=172.24.12.41\tests;Initial Catalog=DD_ECM;Persist Security Info=True;User ID=sa;Password=dd"/> <!-- query erwartet entweder eine mit Kommagetrennte List oder einen SQL Befehl, der ein einspaltiges Ergebnis liefert -->
<add key="database" value="DD_ECM" /> <!-- <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> </appSettings>
</configuration> </configuration>

View File

@ -108,6 +108,7 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput> <DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile> </Compile>
<Compile Include="Parser.vb" /> <Compile Include="Parser.vb" />
<Compile Include="Querybuilder.vb" />
<Compile Include="Service References\DPMA.Marke\Reference.vb"> <Compile Include="Service References\DPMA.Marke\Reference.vb">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>

View File

@ -10,11 +10,11 @@ Public Class AppConfig
Dim appsettings As AppSettingsSection = appconfig.AppSettings Dim appsettings As AppSettingsSection = appconfig.AppSettings
Dim settings As KeyValueConfigurationCollection = appsettings.Settings Dim settings As KeyValueConfigurationCollection = appsettings.Settings
Dim username As String = settings.Item("username").Value Dim username As String = settings.Item("dpma_username").Value
Dim password As String = settings.Item("password").Value Dim password As String = settings.Item("dpma_password").Value
Dim query As String = settings.Item("query").Value Dim query As String = settings.Item("dpma_query").Value
Dim connstring As String = settings.Item("connstring").Value Dim connstring As String = settings.Item("sql_connstring").Value
Dim database As String = settings.Item("database").Value Dim database As String = settings.Item("sql_database").Value
Return New ConfigValues(username, password, query, connstring, database) Return New ConfigValues(username, password, query, connstring, database)
End Function End Function

View File

@ -1,15 +1,19 @@
Imports System.Data.SqlClient Imports System.Data.SqlClient
Imports NLog
Public Class DB Public Class DB
Private _connstring Private _connstring
Private _db Private _db
Private _logger As Logger
Public FormId Public FormId
Public ControlId Public ControlId
Public RecordId Public RecordId
Public Username As String = "BrainpoolImporter" Public Username As String = "BrainpoolImporter"
Public Sub New(connectionString As String, dbname As String) Public Sub New(connectionString As String, dbname As String)
_logger = LogManager.GetLogger("DB")
_connstring = connectionString _connstring = connectionString
_db = dbname _db = dbname
End Sub End Sub
@ -30,6 +34,7 @@ Public Class DB
End Function End Function
Public Function GetProperty(m As Mark, propertyName As String) As Object 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) Dim value = CallByName(m, propertyName, CallType.Get)
If (value = Nothing) Then If (value = Nothing) Then
value = DBNull.Value value = DBNull.Value

View File

@ -19,6 +19,7 @@ Module Main
Private dpma As DPMAConnect Private dpma As DPMAConnect
Private db As DB Private db As DB
Private query As String
Private config As ConfigValues Private config As ConfigValues
Private marks As New List(Of Mark) Private marks As New List(Of Mark)
Private props = New List(Of String) From { Private props = New List(Of String) From {
@ -44,6 +45,7 @@ Module Main
Try Try
logger = LogManager.GetLogger("Main") logger = LogManager.GetLogger("Main")
config = AppConfig.GetConfiguration() config = AppConfig.GetConfiguration()
db = New DB(config.connstring, "DD_ECM")
logger.Info("{0} started", My.Application.Info.Title) logger.Info("{0} started", My.Application.Info.Title)
@ -55,12 +57,13 @@ Module Main
Directory.CreateDirectory(LogDir) Directory.CreateDirectory(LogDir)
End If End If
query = Querybuilder.Build(config, db)
' Abfrage starten ' 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) dpma = New DPMAConnect(config.username, config.password)
mainDoc = dpma.Search(config.query) mainDoc = dpma.Search(query)
mainDoc.Save(MainPath) mainDoc.Save(MainPath)
' Ergebnis auslesen und Marken-Klassen erstellen ' 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 formId As Integer = db.GetFormId()
Dim updatedMarks As Integer = 0 Dim updatedMarks As Integer = 0
Dim addedMarks As Integer = 0 Dim addedMarks As Integer = 0
@ -124,6 +126,7 @@ Module Main
If value = "wort-bildmarke" Or value = "bildmarke" Then If value = "wort-bildmarke" Or value = "bildmarke" Then
Dim imageControlId = db.GetControlId(formId, "MarkImage") Dim imageControlId = db.GetControlId(formId, "MarkImage")
Dim bimage() As Byte = Convert.FromBase64String(m.Image.BinaryImage) Dim bimage() As Byte = Convert.FromBase64String(m.Image.BinaryImage)
logger.Debug("Image inserted, RecordId: {0}")
db.InsertImage(bimage, imageControlId, recordId) db.InsertImage(bimage, imageControlId, recordId)
End If End If
End If End If
@ -178,6 +181,9 @@ Module Main
logger.Debug("=================== IMPORT END ===================") logger.Debug("=================== IMPORT END ===================")
Catch ex As Exception Catch ex As Exception
logger.Error("==================================================")
logger.Error("=================== ERROR ========================")
logger.Error("==================================================")
logger.Error("An Error occurred: {0}", GetExceptionInfo(ex)) logger.Error("An Error occurred: {0}", GetExceptionInfo(ex))
Environment.Exit(1) Environment.Exit(1)
End Try End Try

View File

@ -22,6 +22,25 @@ Public Class Mark
Private _OppositionPeriodEndDate As Date 'Ablauf Widerspruchsfrist Private _OppositionPeriodEndDate As Date 'Ablauf Widerspruchsfrist
Private _Image As ImageDetail 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" #Region "SearchProperties"
Public Property RegistrationOfficeCode As String Public Property RegistrationOfficeCode As String
Get Get
@ -37,7 +56,7 @@ Public Class Mark
Return _RegistrationDate Return _RegistrationDate
End Get End Get
Set(value As String) Set(value As String)
_RegistrationDate = DateTime.Parse(value).ToShortDateString() _RegistrationDate = ParseShortDate(value)
End Set End Set
End Property End Property
@ -55,9 +74,7 @@ Public Class Mark
Return _MarkCurrentStatusCode Return _MarkCurrentStatusCode
End Get End Get
Set(value As String) Set(value As String)
value = value.Replace("ae", "ä") value = ReplaceUmlauts(value)
value = value.Replace("oe", "ö")
value = value.Replace("ue", "ü")
_MarkCurrentStatusCode = value _MarkCurrentStatusCode = value
End Set End Set
@ -68,7 +85,10 @@ Public Class Mark
Return _MarkVerbalElementText Return _MarkVerbalElementText
End Get End Get
Set(value As String) Set(value As String)
_MarkVerbalElementText = WebUtility.HtmlDecode(value) value = DecodeHTML(value)
value = ReplaceSingleQuote(value)
_MarkVerbalElementText = value
End Set End Set
End Property End Property
@ -86,7 +106,7 @@ Public Class Mark
Return _ApplicationDate Return _ApplicationDate
End Get End Get
Set(value As String) Set(value As String)
_ApplicationDate = DateTime.Parse(value).ToShortDateString() _ApplicationDate = ParseShortDate(value)
End Set End Set
End Property End Property
@ -104,7 +124,10 @@ Public Class Mark
Return _Applicant Return _Applicant
End Get End Get
Set(value As String) Set(value As String)
_Applicant = WebUtility.HtmlDecode(value) value = DecodeHTML(value)
value = ReplaceSingleQuote(value)
_Applicant = value
End Set End Set
End Property End Property
@ -113,7 +136,10 @@ Public Class Mark
Return _Representative Return _Representative
End Get End Get
Set(value As String) Set(value As String)
_Representative = WebUtility.HtmlDecode(value) value = DecodeHTML(value)
value = ReplaceSingleQuote(value)
_Representative = value
End Set End Set
End Property End Property
#End Region #End Region
@ -123,7 +149,7 @@ Public Class Mark
Return _PublicationDate Return _PublicationDate
End Get End Get
Set(value As String) Set(value As String)
_PublicationDate = DateTime.Parse(value).ToShortDateString() _PublicationDate = ParseShortDate(value)
End Set End Set
End Property End Property
@ -132,7 +158,7 @@ Public Class Mark
Return _ExpiryDate Return _ExpiryDate
End Get End Get
Set(value As String) Set(value As String)
_ExpiryDate = DateTime.Parse(value).ToShortDateString() _ExpiryDate = ParseShortDate(value)
End Set End Set
End Property End Property
@ -141,7 +167,7 @@ Public Class Mark
Return _TerminationDate Return _TerminationDate
End Get End Get
Set(value As String) Set(value As String)
_TerminationDate = DateTime.Parse(value).ToShortDateString() _TerminationDate = ParseShortDate(value)
End Set End Set
End Property End Property
@ -150,7 +176,7 @@ Public Class Mark
Return _OppositionPeriodStartDate Return _OppositionPeriodStartDate
End Get End Get
Set(value As String) Set(value As String)
_OppositionPeriodStartDate = DateTime.Parse(value).ToShortDateString() _OppositionPeriodStartDate = ParseShortDate(value)
End Set End Set
End Property End Property
@ -159,7 +185,7 @@ Public Class Mark
Return _OppositionPeriodEndDate Return _OppositionPeriodEndDate
End Get End Get
Set(value As String) Set(value As String)
_OppositionPeriodEndDate = DateTime.Parse(value).ToShortDateString() _OppositionPeriodEndDate = ParseShortDate(value)
End Set End Set
End Property End Property
@ -216,7 +242,7 @@ End Class
Public Class ClassificationDetail Public Class ClassificationDetail
Public ClassNumber As String Public ClassNumber As String
Public GoodsServicesDescription Public GoodsServicesDescription As String
Public Sub New() Public Sub New()
End Sub End Sub

View 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