private static PivotMaster GetPivotMaster(DataSet result) { #region Sanity Checks if (!result.Tables.Contains(MASTER_TABLE_NAME)) { throw new ArgumentException("Invalid Pivot data set. Table not found: " + MASTER_TABLE_NAME); } if (!result.Tables.Contains(DEF_TABLE_NAME)) { throw new ArgumentException("Invalid Pivot data set. Table not found: " + DEF_TABLE_NAME); } if (!result.Tables.Contains(SOURCE_TABLE_NAME)) { throw new ArgumentException("Invalid Pivot data set. Table not found: " + SOURCE_TABLE_NAME); } if (!result.Tables.Contains(PIVOT_TABLE_NAME)) { throw new ArgumentException("Invalid Pivot data set. Table not found: " + PIVOT_TABLE_NAME); } #endregion var master = new PivotMaster(result.Tables[MASTER_TABLE_NAME]); // TODO: Need more sanity checks here... return(master); }
private static bool UpdateSource(DataTable source, PivotMaster master, Dictionary <string, string> key, object value) { using (var dv = new DataView(source)) { var sb = new StringBuilder(); foreach (KeyValuePair <string, string> kv in key) { if (sb.Length > 0) { sb.Append(" and "); } sb.AppendFormat("[{0}] = '{1}'", kv.Key, kv.Value); } dv.RowFilter = sb.ToString(); if (dv.Count != 1) { throw new ArgumentException(string.Format("expected 1 for column '{0}={1}'; but found {2}", master.KeyColumn, key, dv.Count)); } string oldValue = dv[0][master.ValueColumn].ToString(); if (oldValue == value.ToString()) { return(false); } dv[0][master.ValueColumn] = value; return(true); } }