Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid
Imports DevExpress.XtraBars.Ribbon
Imports DigitalData.Modules.Logging
Public Class frmSearchPredefined
    Private Logger As Logger
    Public Sub New()
        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        Logger = My.LogConfig.GetLogger()
    End Sub
    Private Sub frmPreSearch_Load(sender As Object, e As EventArgs) Handles Me.Load
        GridControl1.DataSource = LoadSearches()

        Dim oChangesColumn = ViewMain.Columns.Item("Changes")
        Dim oOverdueColumn = ViewMain.Columns.Item("Overdue")
        Dim oResultsColumn = ViewMain.Columns.Item("Results")
        Dim oTitleColumn = ViewMain.Columns.Item("Title")
        Dim oUserIdColumn = ViewMain.Columns.Item("UserID")
        Dim oLastChangeColumn = ViewMain.Columns.Item("LastChange")

        Dim oChangesRule = GetChangesFormatRule()
        oChangesRule.Column = oChangesColumn

        Dim oOverdueRule = GetOverdueFormatRule()
        oOverdueRule.Column = oOverdueColumn

        Dim oResultsRule = GetResultsFormatRule()
        oResultsRule.Column = oResultsColumn

        ViewMain.FormatRules.AddRange({oChangesRule, oResultsRule, oOverdueRule})

        oTitleColumn.AppearanceCell.FontStyleDelta = FontStyle.Bold
        oTitleColumn.AppearanceCell.FontSizeDelta = 1
    End Sub

    Private Function GetResultsFormatRule() As GridFormatRule
        Dim gridFormatRule As New GridFormatRule()
        Dim formatConditionRuleDataBar As New FormatConditionRuleDataBar With {
            .PredefinedName = "Yellow",
            .AutomaticType = FormatConditionAutomaticType.ZeroBased
        }
        gridFormatRule.Rule = formatConditionRuleDataBar

        Return gridFormatRule
    End Function

    Private Function GetOverdueFormatRule() As GridFormatRule
        Dim oFormatRule As New GridFormatRule()
        Dim oRule As New FormatConditionRuleIconSet With {
            .IconSet = New FormatConditionIconSet()
        }
        Dim oIconSet As FormatConditioniconset = oRule.IconSet
        oIconSet.ValueType = FormatConditionValueType.Number
        
        Dim oIcon1 As New FormatConditioniconseticon() With {
            .Icon = SvgImageCollection.GetImage("warning"),
            .Value = 0,
            .ValueComparison = FormatConditionComparisonType.Greater
        }      

        oIconSet.Icons.AddRange({oIcon1})

        oFormatRule.Rule = oRule

        Return oFormatRule
    End Function

    Private Function GetChangesFormatRule() As GridFormatRule
        Dim oFormatRule As New GridFormatRule()
        Dim oRule As New FormatConditionRuleIconSet With {
            .IconSet = New FormatConditionIconSet()        
        }
        Dim oIconSet As FormatConditioniconset = oRule.IconSet
        oIconSet.ValueType = FormatConditionValueType.Number
        
        Dim oIcon1 As New FormatConditioniconseticon() With {
            .Icon = SvgImageCollection.GetImage("green_arrow_up"),
            .Value = 2,
            .ValueComparison = FormatConditionComparisonType.Greater     
        }
      
        oIconSet.Icons.AddRange({oIcon1})

        oFormatRule.Rule = oRule

        Return oFormatRule
    End Function

    Private Function LoadSearches() As DataTable
        Dim oSQL = $"SELECT * FROM VWIDB_SEARCH_LANDING"
        Dim oDTLanding As DataTable = My.DatabaseIDB.GetDatatable(oSQL)
        Return oDTLanding
    End Function

    Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick

    End Sub
End Class