Esempio n. 1
0
    void UpdateSourceTable()
    {
        //Scollega le righe presenti in ToAdd, ove presenti in SourceTable
        DataRow[] ToAddRows = ToAdd.Select();
        foreach (DataRow ToUnlinkRow in ToAddRows)
        {
            string unlinkkeyfilter = QueryCreator.WHERE_KEY_CLAUSE(ToUnlinkRow,
                                                                   DataRowVersion.Default, false);
            DataRow[] ToUnlinkRows = SourceTable.Select(unlinkkeyfilter);
            if (ToUnlinkRows.Length == 0)
            {
                continue;
            }
            DataRow ToUnlink = ToUnlinkRows[0];
            linked.UnlinkDataRow(ToUnlink);
        }

        //Collega le righe presenti in Added, aggiungendole se non presenti
        DataRow[] AddedRows = Added.Select();
        foreach (DataRow ToLinkRow in AddedRows)
        {
            string linkkeyfilter = QueryCreator.WHERE_KEY_CLAUSE(ToLinkRow,
                                                                 DataRowVersion.Default, false);
            DataRow[] TolinkRows = SourceTable.Select(linkkeyfilter);
            DataRow   AddedRow;
            if (TolinkRows.Length == 0)
            {
                //La riga va aggiunta
                AddedRow = AddRowToTable(SourceTable, ToLinkRow);
            }
            else
            {
                AddedRow = TolinkRows[0];
            }
            linked.CheckEntityChildRowAdditions(AddedRow, null);
        }
        // Qui vanno rifatti i SetDataTable
        SetDataTable(ToAdd, GridToAdd);
        SetDataTable(Added, GridAdded);
    }