//////////////////////////////////////////////////// public virtual IDataAdapter GetNewAdapter(DataRowState etatsAPrendreEnCompte, bool bDisableIdAuto, params string[] champsExclus) { m_etatsAPrendreEnCompte = etatsAPrendreEnCompte; CStructureTable structure = CStructureTable.GetStructure(m_type); m_tblExclusions = new Hashtable(); foreach (string strChamp in champsExclus) { m_tblExclusions[strChamp] = strChamp; } IDbDataAdapter adapter = new OleDbDataAdapter(); if (typeof(IObjetDonneeAutoReference).IsAssignableFrom(m_type)) { adapter = new C2iDataAdapterForClasseAutoReferencee(m_type, adapter); } adapter.TableMappings.Add("Table", structure.NomTable); adapter.SelectCommand = GetSelectCommand(structure); if ((etatsAPrendreEnCompte & DataRowState.Added) != 0) { adapter.InsertCommand = GetInsertCommand(structure, bDisableIdAuto, adapter); } else { adapter.InsertCommand = new OleDbCommand("select 1", (OleDbConnection)m_connexion.GetConnexion(), (OleDbTransaction)m_connexion.Transaction); } if ((etatsAPrendreEnCompte & DataRowState.Deleted) != 0) { adapter.DeleteCommand = GetDeleteCommand(structure); } else { adapter.DeleteCommand = new OleDbCommand("select 1", (OleDbConnection)(OleDbConnection)m_connexion.GetConnexion(), (OleDbTransaction)m_connexion.Transaction); } if ((etatsAPrendreEnCompte & DataRowState.Modified) != 0) { adapter.UpdateCommand = GetUpdateCommand(structure); } else { adapter.UpdateCommand = new OleDbCommand("select 1", (OleDbConnection)m_connexion.GetConnexion(), (OleDbTransaction)m_connexion.Transaction); } if (adapter is OleDbDataAdapter) { ((OleDbDataAdapter)adapter).RowUpdating += new OleDbRowUpdatingEventHandler(OnRowUpdating); ((OleDbDataAdapter)adapter).RowUpdated += new OleDbRowUpdatedEventHandler(OnRowUpdated); } return(adapter); }
//////////////////////////////////////////////////// public virtual IDataAdapter GetNewAdapter(DataRowState etatsAPrendreEnCompte, bool bDisableIdAuto, params string[] champsExclus) { CStructureTable structure = CStructureTable.GetStructure(m_type); m_etatsAPrendreEnCompte = etatsAPrendreEnCompte; m_tblExclusions = new Hashtable(); foreach (string strChamp in champsExclus) { m_tblExclusions[strChamp] = strChamp; } IDbDataAdapter adapter = (IDbDataAdapter)m_connexion.GetTableAdapter(structure.NomTableInDb); if (typeof(IObjetDonneeAutoReference).IsAssignableFrom(m_type)) { adapter = new C2iDataAdapterForClasseAutoReferencee(m_type, adapter); } adapter.TableMappings.Add("Table", structure.NomTable); adapter.SelectCommand = GetSelectCommand(structure); if ((etatsAPrendreEnCompte & DataRowState.Added) != 0) { adapter.InsertCommand = GetInsertCommand(structure, bDisableIdAuto, adapter); } else { adapter.InsertCommand = m_connexion.GetConnexion().CreateCommand(); adapter.InsertCommand.CommandText = GetCommandQuiFaitRien(); adapter.InsertCommand.Transaction = m_connexion.Transaction; } if ((etatsAPrendreEnCompte & DataRowState.Deleted) != 0) { adapter.DeleteCommand = GetDeleteCommand(structure); } else { adapter.DeleteCommand = m_connexion.GetConnexion().CreateCommand(); adapter.DeleteCommand.CommandText = GetCommandQuiFaitRien(); adapter.DeleteCommand.Transaction = m_connexion.Transaction; } if ((etatsAPrendreEnCompte & DataRowState.Modified) != 0) { adapter.UpdateCommand = GetUpdateCommand(structure); } else { adapter.UpdateCommand = m_connexion.GetConnexion().CreateCommand(); adapter.UpdateCommand.CommandText = GetCommandQuiFaitRien(); adapter.UpdateCommand.Transaction = m_connexion.Transaction; } return(adapter); }
//////////////////////////////////////////////////// public virtual OleDbCommand GetInsertCommand(CStructureTable structure, bool bDisableIdAuto, IDataAdapter adapter) { string strReq = "insert into [" + structure.NomTableInDb + "]("; string strValues = "("; foreach (CInfoChampTable champ in structure.Champs) { if ((!champ.IsAutoId || bDisableIdAuto) && m_tblExclusions[champ.NomChamp] == null) { if (champ.TypeDonnee != typeof(CDonneeBinaireInRow) && !champ.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow))) { strReq += "[" + champ.NomChamp + "],"; strValues += "?,"; //GetNomParametreFor(champ, DataRowVersion.Current)+","; } } } strReq = strReq.Substring(0, strReq.Length - 1) + ")"; strValues = strValues.Substring(0, strValues.Length - 1) + ")"; strReq += " values " + strValues; if (structure.HasChampIdAuto && !bDisableIdAuto) { C2iDataAdapterForClasseAutoReferencee adapteurAutoRef = adapter as C2iDataAdapterForClasseAutoReferencee; if (adapteurAutoRef != null) { adapteurAutoRef.RowInserted += new C2iDataAdapterForClasseAutoReferencee.RowInsertedEventHandler(OnRowAIdAutoInsertedGeneric); if (m_bAvecSynchro) { adapteurAutoRef.RowInserted += new C2iDataAdapterForClasseAutoReferencee.RowInsertedEventHandler(OnRowAIdAutoInserted); } } else { ((OleDbDataAdapter)adapter).RowUpdated += new OleDbRowUpdatedEventHandler(OnRowAIdAutoUpdated); } } OleDbCommand command = new OleDbCommand(strReq, (OleDbConnection)m_connexion.GetConnexion(), (OleDbTransaction)m_connexion.Transaction); command.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord; //Ajoute les paramètres foreach (CInfoChampTable champ in structure.Champs) { if ((!champ.IsAutoId || bDisableIdAuto) && m_tblExclusions[champ.NomChamp] == null) { if (champ.TypeDonnee != typeof(CDonneeBinaireInRow) && !champ.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow))) { command.Parameters.Add(GetParametreFor(champ, DataRowVersion.Current, ParameterDirection.Input)); } } } return(command); }