/// <summary> /// Fetches the IDs of rows that are associated to the panel`s datarow through a maptable and edited in a M2NMappingField /// </summary> /// <param name="mapping"></param> /// <param name="key"></param> /// <returns></returns> private List <int> FetchMappingValues(M2NMapping mapping, int key) { DataTable tbl = driver.fetchAll("SELECT", dbe.Col(mapping.mapRefColumn), "FROM", dbe.Table(mapping.mapTable), "WHERE", dbe.Col(mapping.mapMyColumn), " = ", dbe.InObj(key)); List <int> res = new List <int>(); foreach (DataRow r in tbl.Rows) { res.Add((int)(r[0])); } return(res); }
/// <summary> /// INSERTs rows neccessary for mapping the inserted / updated datarow to another table via a M2NMappingField. Does not clear the mapping by itself /// => UnmapM2NMappingKey must be called on update /// </summary> /// <param name="mapping"></param> /// <param name="key"></param> /// <param name="vals"></param> private void MapM2NVals(M2NMapping mapping, int key, List <int> vals) { DataTable table = new DataTable(); table.Columns.Add(mapping.mapMyColumn, typeof(int)); table.Columns.Add(mapping.mapRefColumn, typeof(int)); DataRow row = table.NewRow(); foreach (int val in vals) { row[0] = key; row[1] = val; driver.query("INSERT INTO", mapping.mapTable, dbe.InsVals(row)); } }
/// <summary> /// Deletes the row determined by the panel`s PK from the panl`s table. /// Also clears the mapping (this may not be neccessary if the constraint CASCADEs, but it is probably the desired behaviour in either case). /// </summary> /// <param name="panel"></param> public void DeleteFromPanel(Panel panel) { driver.BeginTransaction(); foreach (IField f in panel.fields) { if (f is M2NMappingField) { M2NMapping mapping = ((M2NMappingField)f).Mapping; UnmapM2NMappingKey(mapping, (int)(panel.PK[mapping.mapMyColumn])); } } int affected = driver.query("DELETE FROM", dbe.Table(panel.tableName), " WHERE", dbe.Condition(panel.PK)); if (affected > 1) { driver.RollbackTransaction(); throw new Exception("Panel PK not unique, trying to delete more rows at a time!"); } driver.CommitTransaction(); }
private void UnmapM2NMappingKey(M2NMapping mapping, int key) { driver.query("DELETE FROM", dbe.Table(mapping.mapTable), "WHERE", dbe.Col(mapping.mapMyColumn), " = ", key); }
public M2NMappingField(M2NMapping mapping, string caption) : base(caption) { this.Mapping = mapping; }