/// ///////////////////////////////////////////// public DataTable GetNewDataTable(string strNomTable) { DataTable dt = new DataTable(strNomTable); dt.Columns.Add("ID"); dt.Columns[0].AutoIncrement = true; CListeObjetsDonnees lstcol = Colonnes; for (int i = 0; i < lstcol.Count; i++) { foreach (CColonneTableParametrable col in lstcol) { if (col.Position == i) { dt.Columns.Add(col.GetDataColumn()); break; } } } lstcol = ColonnesClePrimaires; if (lstcol.Count > 0) { List <DataColumn> colPks = new List <DataColumn>(); foreach (CColonneTableParametrable col in lstcol) { foreach (DataColumn c in dt.Columns) { if (c.ColumnName == col.Libelle) { colPks.Add(c); break; } } } dt.PrimaryKey = colPks.ToArray(); } CTableParametrable.PrepareToForUse(dt, null); return(dt); }
internal static void PrepareToForUse(DataTable table, CTableParametrable tableParametrable) { //Ajout d'une colonne TimeStamp if (table.Columns[c_strColTimeStamp] == null) { DataColumn col = new DataColumn(c_strColTimeStamp, typeof(DateTime)); col.AllowDBNull = true; col.DefaultValue = DBNull.Value; table.Columns.Add(col); } //s'assure que le changement de valeurs est bien intercepté pour //mettre à jour la date de dernière modif if (table.ExtendedProperties[c_strExtPropChangeHandeled] == null) { table.RowChanged += new DataRowChangeEventHandler(OnChangementDansUneLigne); table.ExtendedProperties[c_strExtPropChangeHandeled] = true; table.RowDeleting += new DataRowChangeEventHandler(OnChangementDansUneLigne); } table.ExtendedProperties[c_extPropTableParametrable] = tableParametrable; }
//------------------------------------------------------------------- public override CResultAErreur VerifieDonnees(CObjetDonnee objet) { CResultAErreur result = CResultAErreur.True; try { CTableParametrable tb = (CTableParametrable)objet; if (tb.Libelle == "") { result.EmpileErreur(I.T("Custom Table label cannot be empty|373")); } CListeObjetsDonnees lst = new CListeObjetsDonnees(tb.ContexteDonnee, typeof(CTableParametrable)); //Nom unique dans son parent if (tb.ElementLie == null) { lst.Filtre = new CFiltreData( CTableParametrable.c_champLibelle + " = @1 AND " + CTableParametrable.c_champId + " <> @2", tb.Libelle, tb.Id); } else { IElementATableParametrable elt = tb.ElementLie; if (elt is CSite) { lst.Filtre = new CFiltreData(CTableParametrable.c_champLibelle + "=@1 and " + CSite.c_champId + "=@2 and " + CTableParametrable.c_champId + "<>@3", tb.Libelle, ((CSite)elt).Id, tb.Id); } if (elt is CEquipement) { lst.Filtre = new CFiltreData(CTableParametrable.c_champLibelle + "=@1 and " + CEquipement.c_champId + "=@2 and " + CTableParametrable.c_champId + "<>@3", tb.Libelle, ((CEquipement)elt).Id, tb.Id); } } if (lst.CountNoLoad != 0) { result.EmpileErreur(I.T("The Custom Table '@1' already exists|374", tb.Libelle)); } if (tb.TypeTable == null) { result.EmpileErreur(I.T("Custom Table '@1' must have a Custom Table Type|392", tb.Libelle)); } if (tb.Site != null && tb.Equipement != null) { result.EmpileErreur(I.T("Custom Table '@1' cannot be linked to both Site (@2) Site and Equipment (@3)|393", tb.Libelle, tb.Site.Libelle, tb.Equipement.Libelle)); } if (tb.ElementLie != null && tb.TypeTable != null) { bool typetablecompatible = false; CListeObjetsDonnees lstTypesPoss = tb.ElementLie.TypesTableParametrablePossibles; foreach (CTypeTableParametrable tt in lstTypesPoss) { if (tt.Equals(tb.TypeTable)) { typetablecompatible = true; break; } } if (!typetablecompatible) { result.EmpileErreur(I.T("The Custom Table Type '@1' of the custom table '@2' isn't compatible with element '@3'|394", tb.TypeTable.Libelle, tb.Libelle, tb.ElementLie.DescriptionElement)); } } } catch (Exception e) { result.EmpileErreur(new CErreurException(e)); } return(result); }