Esempio n. 1
0
        private void m_lnkAjouter_LinkClicked(object sender, EventArgs e)
        {
            CColonneTableParametrable col = new CColonneTableParametrable(TypeTableParametrable.ContexteDonnee);

            col.CreateNewInCurrentContexte();
            col.Libelle         = I.T("New column|1242");
            col.TypeDonneeChamp = new C2iTypeDonnee(TypeDonnee.tString);
            col.TypeTable       = TypeTableParametrable;
            col.Position        = m_wndColonnes.Items.Count;

            ListViewItem item = new ListViewItem();

            m_wndColonnes.Items.Add(item);
            m_wndColonnes.UpdateItemWithObject(item, col);
            foreach (ListViewItem itemSel in m_wndColonnes.SelectedItems)
            {
                itemSel.Selected = false;
            }
            item.Selected = true;

            MAJComboBoxPKs();
        }
Esempio n. 2
0
        public void TestVersionsDeTables()
        {
            System.Console.WriteLine("-----------------------------------Test versions de tables----------------------");
            System.Console.WriteLine("Initialisation");
            ResetModifs();

            string strNomTableTest = "TEST_NUNIT";

            string[] strNomsCols = new string[] { "Cle", "Val1", "Val2" };
            //Supprime les tables de test
            m_contexteDonnee.SetVersionDeTravail(-1, false);            //Toutes versions
            CListeObjetsDonnees listeTables = new CListeObjetsDonnees(m_contexteDonnee, typeof(CTableParametrable));

            listeTables.Filtre = new CFiltreData(CTableParametrable.c_champLibelle + "=@1",
                                                 strNomTableTest);
            Assert.IsTrue(CObjetDonneeAIdNumerique.Delete(listeTables));

            //Création du type de table
            m_contexteDonnee.SetVersionDeTravail(null, false);
            CTypeTableParametrable typeTable = new CTypeTableParametrable(m_contexteDonnee);

            if (typeTable.ReadIfExists(new CFiltreData(CTypeTableParametrable.c_champLibelle + "=@1",
                                                       strNomTableTest)))
            {
                Assert.IsTrue(CObjetDonneeAIdNumerique.Delete(typeTable.Colonnes));
                typeTable.BeginEdit();
            }
            else
            {
                typeTable.CreateNew();
            }
            typeTable.Libelle = strNomTableTest;
            CColonneTableParametrable col1 = new CColonneTableParametrable(typeTable.ContexteDonnee);

            col1.CreateNewInCurrentContexte();
            col1.Libelle            = strNomsCols[0];
            col1.TypeDonneeChamp    = new C2iTypeDonnee(TypeDonnee.tString);
            col1.AllowNull          = false;
            col1.TypeTable          = typeTable;
            col1.PrimaryKeyPosition = 0;
            col1.Position           = 0;

            CColonneTableParametrable col2 = new CColonneTableParametrable(typeTable.ContexteDonnee);

            col2.CreateNewInCurrentContexte();
            col2.Libelle         = strNomsCols[1];
            col2.TypeDonneeChamp = new C2iTypeDonnee(TypeDonnee.tString);
            col2.TypeTable       = typeTable;
            col2.Position        = 1;

            CColonneTableParametrable col3 = new CColonneTableParametrable(typeTable.ContexteDonnee);

            col3.CreateNewInCurrentContexte();
            col3.Libelle         = strNomsCols[2];
            col3.TypeDonneeChamp = new C2iTypeDonnee(TypeDonnee.tString);
            col3.TypeTable       = typeTable;
            col3.Position        = 2;

            Assert.IsTrue(typeTable.CommitEdit());

            //Création d'une table dans le référentiel
            CTableParametrable tableP = new CTableParametrable(m_contexteDonnee);

            tableP.CreateNew();
            tableP.Libelle   = strNomTableTest;
            tableP.TypeTable = typeTable;
            DataTable table = tableP.DataTableObject;

            /*Table dans le referentiel
             * KEY	|	Val1	|	Val2
             * A1	|	A2		|	A3
             * B1	|	B2		|	B3
             * C1	|	C2		|	C3
             * D1	|	D2		|	D3
             * */
            DataRow row = null;

            for (int nRow = 0; nRow < 4; nRow++)
            {
                row = table.NewRow();
                string strCleLigne = (new string[] { "A", "B", "C", "D" })[nRow];
                for (int nCol = 1; nCol < table.Columns.Count; nCol++)
                {
                    if (table.Columns[nCol].ColumnName != CTableParametrable.c_strColTimeStamp)
                    {
                        row[nCol] = strCleLigne + (nCol).ToString();
                    }
                }
                table.Rows.Add(row);
            }
            tableP.DataTableObject = table;
            Assert.IsTrue(tableP.CommitEdit());

            //---------------------------------------------------------
            ///Modification de la table en V1
            System.Console.Write("Modif dans V1");
            string strA2V1 = "A2 en V1";

            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[0], false);
            table = tableP.DataTableObject;
            row   = table.Rows[0];
            row[strNomsCols[1]] = strA2V1;
            tableP.BeginEdit();
            tableP.DataTableObject = table;
            Assert.IsTrue(tableP.CommitEdit());

            //La table n'a pas bougé en version référentiel
            m_contexteDonnee.SetVersionDeTravail(null, false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", "A2", "A3" },
                new string[] { "B1", "B2", "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //La table n'a pas bougé en V2
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[1], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", "A2", "A3" },
                new string[] { "B1", "B2", "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //La table a bougé en V1
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[0], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", strA2V1, "A3" },
                new string[] { "B1", "B2", "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //La table a bougé en V3
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[2], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", strA2V1, "A3" },
                new string[] { "B1", "B2", "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //---------------------------------------------------------
            //Modification de la table dans le référentiel :
            //Modif ligne 1 et ligne 2.
            System.Console.Write("Modif dans Ref");
            m_contexteDonnee.SetVersionDeTravail(null, false);
            table = tableP.DataTableObject;
            row   = table.Rows[0];
            string strA3REF = "A3 ref";

            row[strNomsCols[2]] = strA3REF;
            row = table.Rows[1];
            string strB2REF = "B2 ref";

            row[strNomsCols[1]] = strB2REF;
            tableP.BeginEdit();
            tableP.DataTableObject = table;
            Assert.IsTrue(tableP.CommitEdit());

            //La table n'a pas bougé en version référentiel
            m_contexteDonnee.SetVersionDeTravail(null, false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", "A2", strA3REF },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //La table n'a pas bougé en V2
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[1], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", "A2", strA3REF },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //la ligne A de V1 ne doit pas être modifiée,
            //Par contre la ligne 2 oui
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[0], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", strA2V1, "A3" },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //V3 = V1
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[2], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", strA2V1, "A3" },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //---------------------------------------------------------
            System.Console.Write("Modif dans V3");
            //Modification de la ligne en V3
            string strA2V3 = "A2 en V3";

            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[2], false);
            table = tableP.DataTableObject;
            row   = table.Rows[0];
            row[strNomsCols[1]] = strA2V3;
            tableP.BeginEdit();
            tableP.DataTableObject = table;
            Assert.IsTrue(tableP.CommitEdit());

            //La table n'a pas bougé en version référentiel
            m_contexteDonnee.SetVersionDeTravail(null, false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", "A2", strA3REF },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //La table n'a pas bougé en V2
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[1], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", "A2", strA3REF },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //La table a bougé en V1
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[0], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", strA2V1, "A3" },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //La table a bougé en V3
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[2], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", strA2V3, "A3" },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //-----------------------------------------------
            //Suppression de la ligne C en V1
            System.Console.Write("Delete dans V1");
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[0], false);
            table = tableP.DataTableObject;
            table.Rows[2].Delete();
            tableP.BeginEdit();
            tableP.DataTableObject = table;
            Assert.IsTrue(tableP.CommitEdit());

            //La table n'a pas bougé en version référentiel
            m_contexteDonnee.SetVersionDeTravail(null, false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", "A2", strA3REF },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //La table n'a pas bougé en V2
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[1], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", "A2", strA3REF },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "C1", "C2", "C3" },
                new string[] { "D1", "D2", "D3" }
            });

            //La table a bougé en V1 (plus de ligne C)
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[0], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", strA2V1, "A3" },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "D1", "D2", "D3" }
            });

            //La table a bougé en V3 (plus de ligne C)
            m_contexteDonnee.SetVersionDeTravail(m_nIdsVersions[2], false);
            table = tableP.DataTableObject;
            VerifTable(table, strNomsCols, new string[][] {
                new string[] { "A1", strA2V3, "A3" },
                new string[] { "B1", strB2REF, "B3" },
                new string[] { "D1", "D2", "D3" }
            });
        }