private void InitializeDataTable(DataTable table) { foreach (System.Reflection.PropertyInfo exportableProperty in WppComputer.GetDataGridViewProperties()) { table.Columns.Add(this._localization.GetLocalizedString(exportableProperty.Name), exportableProperty.PropertyType); } }
// Remote computers queries internal void GetWsusClientID(List <int> indexes, WPP.Security.Credential credential) { foreach (int index in indexes) { WppComputer remoteComputer = this._computersTable.Rows[index].Field <WppComputer>(this._localization.GetLocalizedString("ComputerObj")); this._computersTable.Rows[index].SetField <String>(this._localization.GetLocalizedString("WsusClientID"), remoteComputer.GetWsusClientID(credential)); } }
private string GetCsvHeader() { string header = String.Empty; try { foreach (System.Reflection.PropertyInfo exportableProperty in WppComputer.GetDataGridViewProperties()) { header += this._localization.GetLocalizedString(exportableProperty.Name) + ";"; } header = header.Substring(0, header.Length - 1) + "\r\n"; } catch (Exception) { } return(header); }
// Data table Managment internal void UpdateDataTable(object computers) { List <WppComputer> adComputers = (List <WppComputer>)computers; this._computersTable.Clear(); List <System.Reflection.PropertyInfo> datagridviewProperties = WppComputer.GetDataGridViewProperties(); foreach (WppComputer adComputer in adComputers) { Object[] columns = new Object[datagridviewProperties.Count]; try { for (int i = 0; i < datagridviewProperties.Count; i++) { if (datagridviewProperties[i].PropertyType == typeof(DateTime)) { columns[i] = DateTime.Parse(datagridviewProperties[i].GetValue(adComputer, null).ToString()); } else if (datagridviewProperties[i].PropertyType == typeof(WppComputer)) { columns[i] = (WppComputer)datagridviewProperties[i].GetValue(adComputer, null); } else { string propertyValue = datagridviewProperties[i].GetValue(adComputer, null).ToString(); columns[i] = String.Equals(propertyValue, String.Empty) ? null : propertyValue; } } System.Data.DataRow newRow = this._computersTable.NewRow(); newRow.ItemArray = columns; this._computersTable.Rows.Add(newRow); adComputer.DatatableIndex = this._computersTable.Rows.IndexOf(newRow); } catch (Exception) { } } }
// CSV export internal string GetDataForExport() { string result = this.GetCsvHeader(); List <System.Reflection.PropertyInfo> exportableProperties = WppComputer.GetDataGridViewProperties(); foreach (DataRow row in this._computersTable.Rows) { try { WppComputer computer = row.Field <WppComputer>(this._localization.GetLocalizedString("ComputerObj")); foreach (System.Reflection.PropertyInfo exportableProperty in exportableProperties) { string propertyValue = exportableProperty.GetValue(computer, null).ToString(); result += propertyValue + ";"; } result = result.Substring(0, result.Length - 1) + "\r\n"; } catch (Exception) { } } return(result); }