private QueryParamCollection BuildSearchList() { var searchParams = new QueryParamCollection(); using (var controlParser = new DBControlParser(this)) { foreach (var ctl in controlParser.GetDBControls(this)) { var ctlValue = controlParser.GetDBControlValue(ctl); if (ctlValue != DBNull.Value && !string.IsNullOrEmpty(ctlValue.ToString())) { var dbInfo = (DBControlInfo)ctl.Tag; bool isExact = false; switch (dbInfo.ColumnName) { //case DevicesCols.OSVersion: // IsExact = true; // break; case DevicesCols.EQType: isExact = true; break; case DevicesCols.Location: isExact = true; break; case DevicesCols.Status: isExact = true; break; default: isExact = false; break; } searchParams.Add(dbInfo.ColumnName, ctlValue, isExact); } } return(searchParams); } }
/// <summary> /// Returns a list of controls whose value differs from the previous historical state. /// </summary> /// <param name="currentData"></param> /// <returns></returns> private List <Control> GetChangedFields(DataTable currentData) { var changedControls = new List <Control>(); var currentTimeStamp = (System.DateTime)currentData.Rows[0][HistoricalDevicesCols.ActionDateTime]; // Query for all rows with a timestamp older than the current historical entry. using (var olderData = DBFactory.GetDatabase().DataTableFromQueryString(Queries.SelectDevHistoricalEntriesOlderThan(deviceGuid, currentTimeStamp))) { if (olderData.Rows.Count > 0) { // Declare the current and previous DataRows. DataRow previousRow = olderData.Rows[0]; DataRow currentRow = currentData.Rows[0]; var changedColumns = new List <string>(); // Iterate through the current row item array and compare them to the previous row items. for (int i = 0; i <= currentRow.ItemArray.Length - 1; i++) { if (previousRow[i].ToString() != currentRow[i].ToString()) { //Add column names to a list if the item values don't match. changedColumns.Add(previousRow.Table.Columns[i].ColumnName); } } // Get a list of all the controls with DBControlInfo tags. var controlList = controlParser.GetDBControls(this); // Get a list of all the controls whose data columns match the ChangedColumns. foreach (string col in changedColumns) { changedControls.Add(controlList.Find(c => ((DBControlInfo)c.Tag).ColumnName == col)); } } } return(changedControls); }