Click or drag to resize

AppStandardDataItemClassGetView Method (ListViewConfig, DictionaryString, String)

Gives a list of data by settings of ListView Config. The list is divided into pages (paging).

Namespace:  SOWIApp.Foundation
Assembly:  SOWIApp.Foundation (in SOWIApp.Foundation.dll) Version: 19.1.23.1 (19.1.23.622)
Syntax
public virtual List<DataItemClass> GetView(
	ref ListViewConfig pViewConfig,
	Dictionary<string, string> pDictionaryUI = null
)

Parameters

pViewConfig
Type: SOWIData.ManagementListViewConfig
Setting for data list. This parameter is by reference (C# with ref prefix)
pDictionaryUI (Optional)
Type: System.Collections.GenericDictionaryString, String
Dictionary for UI translation. If null then the internal DictionaryUI is used

Return Value

Type: ListDataItemClass
List of data records

Implements

IAppStandardDataItemClassGetView(ListViewConfig, DictionaryString, String)
IAppControllerDataItemClassGetView(ListViewConfig, DictionaryString, String)
Remarks
What does this method?

Puts DictionaryUI object by parameter or his

Check and sets ViewListConfig object values: search field and value, sorting setting

Creates list of data records by settings

Puts list paging

Saves list config object values

Examples
Programming example when overriding this method

DictionaryUI object handling

#region --- puts DictionaryUI object ---
if (pDictionaryUI == null)
{
    pDictionaryUI = this.DictionaryUI;
}
if (pViewConfig == null)
{
    throw new Exception(SIC.Messages.DataNotFound.ToString());
}
#endregion
Check and sets ViewListConfig object values: search field and value, sorting setting

Search field and values

#region --- search field exist? ---
if (pViewConfig.SearchField == null)
{
    pViewConfig.SearchField = "";
}
#endregion

#region --- set SearchValues ---
pViewConfig.SearchValues = new List<string>();
string lSearchField = pViewConfig.SearchField;
if (lSearchField != "")
{
    var lSearchValues = (from p in GetList()
                         group p by SOWIData.Database.Connector<DataItemClass>.GetProperty(p, lSearchField) into SearchValues
                         orderby SearchValues.Key
                         select SearchValues.Key).ToList();
    if (lSearchValues.Count > 0)
    {
        foreach (var item in lSearchValues)
        {
            //* without null data field values because null values trigger an exception *
            if (item != null)
            {
                pViewConfig.SearchValues.Add(item.ToString());
            }
        }
    }
}
#endregion
Sorting setting
#region --- sort field and direction exist? ---
if (pViewConfig.SortField == null)
{
    pViewConfig.SortField = this.SortFieldStandard;
    pViewConfig.SortDirection = this.SortDirectionStandard;
}
#endregion

#region --- search and sort field list exist? ---
if (pViewConfig.Fields == null)
{
    var lFields = DataGridView;
    lFields = (from p in lFields
               where p.InFieldList == true
               select p).ToList();
    lFields.Insert(0, new SOWIData.Management.DataGrid());
    if (pDictionaryUI != null)
    {
        SOWIApp.Management.DataGrid.Translate(ref lFields, pDictionaryUI);
    }
    else
    {
        foreach (var item in lFields)
        {
            if (item.ColumnLabel.Length == 0)
            {
                item.ColumnLabel = item.DataFieldName;
            }
        }
    }
    pViewConfig.Fields = lFields; ;
}
#endregion
Creates list of data records by settings
#region --- Set data list ---
string lValue = (string.IsNullOrEmpty(pViewConfig.SearchValue) ? "" : pViewConfig.SearchValue);
if (lValue == "")
{
    lValue = (string.IsNullOrEmpty(pViewConfig.SearchValue2) ? "" : pViewConfig.SearchValue2);
    if (lValue != "")
    {   // ** Check exists Value in Search Values **
        var lFind = pViewConfig.SearchValues.Find(p => p == lValue);
        if (lFind == null)
        {
            lValue = "";
            pViewConfig.SearchValue2 = "";
        }
        else
        {
            lValue = pViewConfig.SearchValue2;
        }
    }
}
else
{
    pViewConfig.SearchValue2 = "";
}

var lQuery = GetAll(pViewConfig.SortField.ToString(), pViewConfig.SortDirection,
                    pViewConfig.SearchField.ToString(), pViewConfig.SearchOperator, lValue,
                    pViewConfig.Record);

#endregion
Data list paging (LINQ)
#region --- paging ---

pViewConfig.RecordCount = lQuery.Count();
pViewConfig.PageCount = pViewConfig.RecordCount / pViewConfig.PageSize;
int lRecordCountByPage = pViewConfig.PageSize * pViewConfig.PageCount;
if (lRecordCountByPage < pViewConfig.RecordCount)
{
    pViewConfig.PageCount += 1;
}
if (pViewConfig.CurrentPageIndex > pViewConfig.PageCount - 1)        // CurrentPageIndex null based
{
    pViewConfig.CurrentPageIndex = pViewConfig.PageCount - 1;
}

lQuery = lQuery.Skip(pViewConfig.CurrentPageIndex * pViewConfig.PageSize).Take(pViewConfig.PageSize).ToList();

#endregion
Saves list config object values
#region --- saves ListViewConfig object ---
SOWIApp.Management.ListViewConfig.SetListViewConfig(pViewConfig);
#endregion
See Also