AppStandardDataItemClassGetView Method (ListViewConfig, DictionaryString, String) |
Namespace: SOWIApp.Foundation
public virtual List<DataItemClass> GetView( ref ListViewConfig pViewConfig, Dictionary<string, string> pDictionaryUI = null )
#region --- puts DictionaryUI object --- if (pDictionaryUI == null) { pDictionaryUI = this.DictionaryUI; } if (pViewConfig == null) { throw new Exception(SIC.Messages.DataNotFound.ToString()); } #endregion
#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
#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
#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
#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
#region --- saves ListViewConfig object --- SOWIApp.Management.ListViewConfig.SetListViewConfig(pViewConfig); #endregion