//---------------------------------------------------------------------- public CResultAErreur SetParametres(Dictionary <string, object> dicParametres) { CResultAErreur result = CResultAErreur.True; object obj = null; if (dicParametres.TryGetValue(m_cParametreElementId, out obj)) { if (obj is int) { int nId = (int)obj; if (dicParametres.TryGetValue(m_cParametreElementType, out obj)) { string strType = (string)obj; Type tp = CActivatorSurChaine.GetType(strType); if (tp != null) { m_elementForGED = (CObjetDonneeAIdNumerique)Activator.CreateInstance( tp, new object[] { CSc2iWin32DataClient.ContexteCourant }); if (!m_elementForGED.ReadIfExists(nId)) { m_elementForGED = null; result.EmpileErreur(I.T("Element for EDM Navigation Form not found|10100")); return(result); } } } } } return(result); }
/// ////////////////////////////////////////// public override CResultAErreur MyEval(CContexteEvaluationExpression ctx, object[] valeursParametres) { CResultAErreur result = CResultAErreur.True; if (valeursParametres[0] is String) { Type tp = DynamicClassAttribute.GetTypeFromNomConvivial((string)valeursParametres[0]); if (tp != null) { result.Data = tp.ToString(); return(result); } tp = CActivatorSurChaine.GetType((string)valeursParametres[0]); if (tp != null) { result.Data = tp.ToString(); return(result); } } else { if (valeursParametres[0] != null) { result.Data = valeursParametres[0].GetType().ToString(); return(result); } } result.Data = ""; return(result); }
/// ////////////////////////////////////////// public override CResultAErreur VerifieParametres() { CResultAErreur result = base.VerifieParametres(); if (!result) { return(result); } if (Parametres.Count < 2) { result.EmpileErreur(I.T("Incorrect number of parameters|161")); return(result); } C2iExpression expType = Parametres2i[1]; if (expType is C2iExpressionConstante) { string strType = ((C2iExpressionConstante)expType).Valeur.ToString(); if (CActivatorSurChaine.GetType(strType, true) == null) { result.EmpileErreur(I.T("The type @1 doesn't exist|162", strType)); } } if (Parametres.Count >= 3) { if (!(Parametres2i[2] is C2iExpressionVrai) && !(Parametres2i[2] is C2iExpressionFaux)) { result.EmpileErreur(I.T("The third parameter must be 'true()' or 'false()'|163")); } } return(result); }
public static object GetValeur( DataRow row, string strChampString, string strChampBlob, string strChampType, CContexteDonnee ctx) { Type t = CActivatorSurChaine.GetType((string)row[strChampType]); if (t == typeof(IDifferencesBlob)) { CDonneeBinaireInRow blob = GetBlob(row, strChampBlob, ctx); MemoryStream stream = new MemoryStream(blob.Donnees); BinaryReader reader = new BinaryReader(stream); CSerializerReadBinaire serializer = new CSerializerReadBinaire(reader); I2iSerializable objet = null; CResultAErreur result = serializer.TraiteObject(ref objet); reader.Close(); stream.Close(); if (result) { return(objet); } System.Console.WriteLine(I.T("Error while deserializing blob diffs|30000")); return(null); } else if (t == typeof(byte[])) { CDonneeBinaireInRow blob = GetBlob(row, strChampBlob, ctx); if (blob != null) { return(blob.Donnees); } else { return(null); } } else if (typeof(CObjetDonneeAIdNumerique).IsAssignableFrom(t)) { int nId = Int32.Parse((string)row[strChampString]); CObjetDonneeAIdNumerique obj = (CObjetDonneeAIdNumerique)Activator.CreateInstance(t, new object[] { ctx }); if (obj.ReadIfExists(nId)) { return(obj); } return(null); } else if (t != null && row[strChampString] != DBNull.Value) { return(CUtilTexte.FromUniversalString((string)row[strChampString], t)); } return(null); }
//////////////////////////////////////////////////////////////////////////////////////////////// protected MarshalByRefObject GetNewObjectProtected(string strClasse, Type typeDeBase, int nIdSession) { #if PDA Type tp = CActivatorSurChaine.GetType(strClasse); if (tp != null) { object obj = Activator.CreateInstance(tp); if (obj != null) { ((I2iMarshalObject)obj).IdSession = nIdSession; } return((MarshalByRefObject)obj); } return(null); #else if (m_localFactory != null && m_localDicSingleton != null) { MarshalByRefObject objLocal = null; if (m_localDicSingleton.TryGetValue(strClasse, out objLocal)) { return(objLocal); } } string strNameSpace; int nPos = strClasse.LastIndexOf("."); if (nPos < 0) { strNameSpace = ""; } else { strNameSpace = strClasse.Substring(0, nPos); strClasse = strClasse.Substring(nPos + 1, strClasse.Length - nPos - 1); } string strUrl = (string)m_tableUrls[strNameSpace]; nPos = strNameSpace.LastIndexOf("."); while (strUrl == null && nPos > 0) { strNameSpace = strNameSpace.Substring(0, nPos); strUrl = (string)m_tableUrls[strNameSpace]; nPos = strNameSpace.LastIndexOf("."); } if (strUrl == null) { strUrl = m_strDefautUrl; } strUrl = strUrl + "/" + strClasse; MarshalByRefObject obj = (MarshalByRefObject)Activator.GetObject(typeDeBase, strUrl); if (obj is I2iMarshalObjectDeSession && nIdSession != c_idSessionAucune) { ((I2iMarshalObjectDeSession)obj).IdSession = nIdSession; } return(obj); #endif }
/// ////////////////////////////////////////// public override CResultAErreur MyEval(CContexteEvaluationExpression ctx, object[] listeParametres) { CResultAErreur result = CResultAErreur.True; string strVal = listeParametres[0].ToString(); Type tp = listeParametres[0] as Type; if (tp == null) { tp = CActivatorSurChaine.GetType(strVal, true); } if (tp == null) { tp = CActivatorSurChaine.GetType(strVal, false); } if (tp == null) { result.EmpileErreur(I.T("The @1 type does not exist|221", strVal)); return(result); } try { IAllocateurSupprimeurElements allocateur; object source = ctx.ObjetSource; allocateur = source as IAllocateurSupprimeurElements; if (allocateur == null) { allocateur = ctx.GetObjetAttache(typeof(IAllocateurSupprimeurElements)) as IAllocateurSupprimeurElements; } result.Data = null; if (allocateur != null) { result.Data = allocateur.AlloueElement(tp).Data; } if (result.Data == null) { try { result.Data = Activator.CreateInstance(tp, new object[0]); } catch { } } return(result); } catch (Exception e) { result.EmpileErreur(new CErreurException(e)); } return(result); }
public void InitFiltrageChamps() { m_bCheckWithoutEvent = true; InitTypesOperations(); List <string> lstChamps = new List <string>(); m_lstChamps.Items.Clear(); foreach (CAuditVersionObjetOperation cavoo in m_cavo.Datas) { if (cavoo.Champ == null) { continue; } string strNomChamp = cavoo.Champ.NomConvivial; if (!lstChamps.Contains(strNomChamp)) { lstChamps.Add(cavoo.Champ.NomConvivial); ListViewItem itm = new ListViewItem(strNomChamp); string strTypeChamp = ""; if (cavoo.Champ.GetType() == typeof(CChampCustomPourVersion)) { strTypeChamp = I.T("Custom Field|30215"); } else { strTypeChamp = I.T("Field|85"); } Type tpChamp = CActivatorSurChaine.GetType(cavoo.TypeValeurString); if (tpChamp == typeof(CDetailOperationSurObjet)) { } itm.SubItems.Add(strTypeChamp); itm.SubItems.Add(DynamicClassAttribute.GetNomConvivial(tpChamp)); m_lstChamps.Items.Add(itm); itm.Checked = true; } } m_bCheckWithoutEvent = false; }
//------------------------------------------------------------ public CResultAErreur GetValue(object objet, string strPropriete) { CResultAErreur result = CResultAErreur.True; CObjetDonneeAIdNumerique objetTypeId = objet as CObjetDonneeAIdNumerique; if (objetTypeId == null) { return(result); } //trouve la relation correspondante à l'identifiant de la propriété RelationTypeIdAttribute relation = null; foreach (RelationTypeIdAttribute relTest in CContexteDonnee.RelationsTypeIds) { if (relTest.IdRelation == strPropriete) { relation = relTest; break; } } if (relation == null) { result.EmpileErreur(I.T("Relation @1 doesn't exists|20030", strPropriete)); return(result); } CObjetDonneeAIdNumerique objetParent = null; //Récupère le type de l'objet parent try { Type tp = CActivatorSurChaine.GetType((string)objetTypeId.Row[relation.ChampType], false); objetParent = Activator.CreateInstance(tp, new object[] { objetTypeId.ContexteDonnee }) as CObjetDonneeAIdNumerique; if (!objetParent.ReadIfExists((int)objetTypeId.Row[relation.ChampId])) { objetParent = null; } } catch { } result.Data = objetParent; return(result); }
private void m_btnOk_Click(object sender, EventArgs e) { if (m_txtNom.Text == "") { MessageBox.Show("Name ?"); return; } Type tp = null; if (m_variable != null && m_variable.TypeDonnee != null) { tp = m_variable.TypeDonnee.TypeDotNetNatif; } if (m_parametre != null && m_parametre.TypeResultatExpression != null) { tp = m_parametre.TypeResultatExpression.TypeDotNetNatif; } if (tp == null || m_txtType.Text != DynamicClassAttribute.GetNomConvivial(tp)) { tp = CActivatorSurChaine.GetType(m_txtType.Text, true); if (tp == null) { MessageBox.Show(I.T("Invalid type|20023")); return; } } if (m_variable != null) { m_variable = new CDefinitionProprieteDynamiqueVariableFormule( m_txtNom.Text, new CTypeResultatExpression(tp, m_chkArray.Checked), true); } if (m_parametre != null) { m_parametre.Nom = m_txtNom.Text; m_parametre.TypeResultatExpression = new CTypeResultatExpression(tp, m_chkArray.Checked); } DialogResult = DialogResult.OK; Close(); }
/// ///////////////////////////////////////// public CResultAErreur Serialize(C2iSerializer serializer) { int nVersion = GetNumVersion(); CResultAErreur result = serializer.TraiteVersion(ref nVersion); if (!result) { return(result); } serializer.TraiteString(ref m_strChamp); string strTmp = ""; if (m_typeLie != null) { strTmp = m_typeLie.ToString(); } serializer.TraiteString(ref strTmp); if (serializer.Mode == ModeSerialisation.Lecture) { m_typeLie = CActivatorSurChaine.GetType(strTmp); } return(result); }
//-------------------------------------------------- public IEnumerable <IElementACout> GetObjetsImputés(CContexteDonnee contexteDonnee) { List <IElementACout> lst = new List <IElementACout>(); foreach (KeyValuePair <string, double> kv in m_dicImputations) { string strIdType = ""; string strIdUniversel = ""; bool bCoutReel = false; if (DecomposeKey(kv.Key, out strIdType, out strIdUniversel, out bCoutReel)) { Type tp = CActivatorSurChaine.GetType(strIdType); if (tp != null) { IElementACout element = Activator.CreateInstance(tp, new object[] { contexteDonnee }) as IElementACout; if (element != null && element.ReadIfExistsUniversalId(strIdUniversel)) { lst.Add(element); } } } } return(lst.AsReadOnly()); }
//----------------------------------------------------------- private CNoeudDeGrapheReseau GetNoeudFromKey(string strKey) { string[] strDatas = strKey.Split('/'); if (strDatas.Length != 3) { return(null); } Type tp = CActivatorSurChaine.GetType(strDatas[0]); if (tp == null) { return(null); } try{ int nIdSchema = Int32.Parse(strDatas[1]); int nIdObjet = Int32.Parse(strDatas[2]); CNoeudDeGrapheReseau noeud = Activator.CreateInstance(tp, new object[] { nIdObjet, nIdSchema, false }) as CNoeudDeGrapheReseau; return(noeud); } catch (Exception e) { } return(null); }
/// ////////////////////////////////////////// public override CResultAErreur MyEval(CContexteEvaluationExpression ctx, object[] listeParametres) { CResultAErreur result = CResultAErreur.True; try { string strVal = listeParametres[0].ToString(); Type tp = listeParametres[0] as Type; if (tp == null) { tp = CActivatorSurChaine.GetType(strVal, true); } if (tp == null) { tp = CActivatorSurChaine.GetType(strVal, false); } if (tp == null) { result.EmpileErreur(I.T("The @1 type does not exist|221", strVal)); return(result); } string strTable = CContexteDonnee.GetNomTableForType(tp); if (strTable == null) { result.EmpileErreur(I.T("The @1 type is not associated with a table|225", strVal)); return(result); } CFiltreDataAvance filtreAvance = new CFiltreDataAvance(strTable, listeParametres[1].ToString()); for (int n = 2; n < listeParametres.Length; n++) { filtreAvance.Parametres.Add(listeParametres[n]); } CComposantFiltre c = filtreAvance.ComposantPrincipal; CContexteDonnee contexteDonnee = null; if (ctx.ObjetSource is IObjetAContexteDonnee) { contexteDonnee = ((IObjetAContexteDonnee)ctx.ObjetSource).ContexteDonnee; } if (contexteDonnee == null) { contexteDonnee = (CContexteDonnee)ctx.GetObjetAttache(typeof(CContexteDonnee)); } if (contexteDonnee == null) { contexteDonnee = new CContexteDonnee(CSessionClient.GetSessionUnique().IdSession, true, false); ctx.AttacheObjet(typeof(CContexteDonnee), contexteDonnee); } CFiltreData filtre = null; if (filtreAvance.HasFiltre) { filtre = filtreAvance; } CListeObjetsDonnees liste = new CListeObjetsDonnees(contexteDonnee, tp, filtre); result.Data = liste; } catch (Exception e) { result.EmpileErreur(new CErreurException(e)); } return(result); }
//---------------------------------------------------------------- public void Init(Type typeObjetPourForm) { if (typeObjetPourForm == m_typeObjets) { return; } m_typeObjets = typeObjetPourForm; List <CReferenceTypeForm> lstRefsTypes = new List <CReferenceTypeForm>(); // Init liste des formulaires standards List <CInfoClasseDynamique> lstForms = new List <CInfoClasseDynamique>(); // Cherche tous les formulaires d'édition correspondants au type foreach (Assembly ass in CGestionnaireAssemblies.GetAssemblies()) { foreach (Type tp in ass.GetTypes()) { if (!tp.IsAbstract && tp.IsSubclassOf(typeof(System.Windows.Forms.Form))) { Type tpEdite = null; string strLibelle = ""; object[] attribs = tp.GetCustomAttributes(typeof(ObjectEditeur), true); if (attribs.Length > 0) { ObjectEditeur attrib = (ObjectEditeur)attribs[0]; tpEdite = attrib.TypeEdite; strLibelle = DynamicClassAttribute.GetNomConvivial(tpEdite) + " - " + attrib.Code; } if (tpEdite == typeObjetPourForm && strLibelle != "") { CReferenceTypeFormBuiltIn refBin = new CReferenceTypeFormBuiltIn(tp); lstRefsTypes.Add(refBin); } } } } // Iinit liste des formulaires custom CListeObjetsDonnees lstFormulaires = new CListeObjetsDonnees(CSc2iWin32DataClient.ContexteCourant, typeof(CFormulaire)); lstFormulaires.Filtre = new CFiltreData( CFormulaire.c_champTypeElementEdite + " = @1 AND " + CFormulaire.c_champCodeRole + " is null", typeObjetPourForm.ToString()); foreach (CFormulaire formulaire in lstFormulaires) { //Elimine les formulaires en surimpression if (formulaire.Libelle.Contains(".")) { Type tp = CActivatorSurChaine.GetType(formulaire.Libelle); if (tp != null) { continue; } } CReferenceTypeFormDynamic refDync = new CReferenceTypeFormDynamic(formulaire); lstRefsTypes.Add(refDync); } m_comboRefTypeForm.Fill( lstRefsTypes, "Libelle", true); m_comboRefTypeForm.AssureRemplissage(); if (m_typeSelectionne != null) { m_comboRefTypeForm.SelectedValue = m_typeSelectionne; } }
/// //////////////////////////////////////////////////////// private CResultAErreur CleanType( CContexteExecutionAction contexteExecution, Type tpToClean, RelationTypeIdAttribute rel) { if (tpToClean == typeof(CVersionDonneesObjet)) { return(CResultAErreur.True); } if (contexteExecution.IndicateurProgression != null) { contexteExecution.IndicateurProgression.SetInfo("Cleaning " + DynamicClassAttribute.GetNomConvivial(tpToClean)); } CResultAErreur result = CResultAErreur.True; //Identifie tous les types liés C2iRequeteAvancee requete = new C2iRequeteAvancee(null); requete.TableInterrogee = rel.TableFille; requete.ListeChamps.Add(new C2iChampDeRequete( "TYPE_ELEMENT", new CSourceDeChampDeRequete(rel.ChampType), typeof(string), OperationsAgregation.None, true)); result = requete.ExecuteRequete(contexteExecution.IdSession); if (!result) { return(result); } if (!typeof(CObjetDonneeAIdNumerique).IsAssignableFrom(tpToClean)) { return(result); } DataTable table = result.Data as DataTable; if (table == null || table.Rows.Count == 0) { return(result); } CStructureTable structRel = CStructureTable.GetStructure(tpToClean); foreach (DataRow row in table.Rows) { if (row[0] is string) { Type tpLie = CActivatorSurChaine.GetType((string)row[0]); string strNomTable = tpLie != null?CContexteDonnee.GetNomTableForType(tpLie) : null; if (strNomTable != null && typeof(CObjetDonneeAIdNumerique).IsAssignableFrom(tpLie)) { System.Console.WriteLine(tpToClean.ToString() + " / " + tpLie.ToString()); //trouve tous les ids associés requete = new C2iRequeteAvancee(null); requete.TableInterrogee = rel.TableFille; requete.ListeChamps.Add(new C2iChampDeRequete( "ETT_ID", new CSourceDeChampDeRequete(rel.ChampId), typeof(int), OperationsAgregation.None, true)); requete.FiltreAAppliquer = new CFiltreData(rel.ChampType + "=@1", tpLie.ToString()); result = requete.ExecuteRequete(contexteExecution.IdSession); if (!result) { return(result); } DataTable tableIds = result.Data as DataTable; List <int> lstIdsCherchees = new List <int>(); if (tableIds != null) { StringBuilder bl = new StringBuilder(); foreach (DataRow rowId in tableIds.Rows) { if (rowId[0] is int) { lstIdsCherchees.Add((int)rowId[0]); bl.Append((int)rowId[0]); bl.Append(','); } } if (bl.Length > 0) { CStructureTable structure = CStructureTable.GetStructure(tpLie); bl.Remove(bl.Length - 1, 1); requete = new C2iRequeteAvancee(null); requete.TableInterrogee = strNomTable; requete.ListeChamps.Add(new C2iChampDeRequete( "ETT_ID", new CSourceDeChampDeRequete(structure.ChampsId[0].NomChamp), typeof(int), OperationsAgregation.None, false)); requete.FiltreAAppliquer = new CFiltreData( structure.ChampsId[0].NomChamp + " in (" + bl.ToString() + ")"); result = requete.ExecuteRequete(contexteExecution.IdSession); if (!result) { return(result); } DataTable tableIdsTrouvees = result.Data as DataTable; HashSet <int> setTrouves = new HashSet <int>(); if (tableIdsTrouvees != null) { foreach (DataRow rowId in tableIdsTrouvees.Rows) { if (rowId[0] is int) { setTrouves.Add((int)rowId[0]); } } bl = new StringBuilder(); foreach (int nId in lstIdsCherchees.ToArray()) { if (!setTrouves.Contains(nId)) { bl.Append(nId); bl.Append(','); } } if (bl.Length > 0) { bl.Remove(bl.Length - 1, 1); //Trouve la liste des relTypesIds à virer requete = new C2iRequeteAvancee(null); requete.TableInterrogee = rel.TableFille; requete.ListeChamps.Add(new C2iChampDeRequete( structRel.ChampsId[0].NomChamp, new CSourceDeChampDeRequete(structRel.ChampsId[0].NomChamp), typeof(int), OperationsAgregation.None, true)); requete.FiltreAAppliquer = new CFiltreData( rel.ChampId + " in (" + bl.ToString() + ") and " + rel.ChampType + "=@1", tpLie.ToString()); result = requete.ExecuteRequete(contexteExecution.IdSession); if (!result) { return(result); } DataTable tableIdsToDelete = result.Data as DataTable; if (tableIdsToDelete != null) { List <int> lstToDelete = new List <int>(); foreach (DataRow rowDel in tableIdsToDelete.Rows) { if (rowDel[0] is int) { lstToDelete.Add((int)rowDel[0]); } } if (contexteExecution.IndicateurProgression != null) { contexteExecution.IndicateurProgression.PushLibelle( DynamicClassAttribute.GetNomConvivial(tpToClean) + "/" + DynamicClassAttribute.GetNomConvivial((tpLie))); } for (int nPart = 0; nPart < lstToDelete.Count; nPart += 100) { List <int> lstTmp = new List <int>(); int nMin = Math.Min(nPart + 100, lstToDelete.Count); for (int n = nPart; n < nMin; n++) { lstTmp.Add(lstToDelete[n]); } if (contexteExecution.IndicateurProgression != null) { contexteExecution.IndicateurProgression.SetInfo(nPart.ToString() + "/" + lstToDelete.Count); } result = CActionSupprimerEntite.PurgeEntites(contexteExecution.IdSession, tpToClean, lstTmp.ToArray()); if (contexteExecution.IndicateurProgression != null && contexteExecution.IndicateurProgression.CancelRequest) { result.EmpileErreur("User cancellation"); } if (!result) { return(result); } } if (contexteExecution.IndicateurProgression != null) { contexteExecution.IndicateurProgression.PopLibelle(); } } } } } } } } } return(result); }
/// ////////////////////////////////////////// public override CResultAErreur AfterAnalyse(CAnalyseurSyntaxique analyseur) { CResultAErreur result = CResultAErreur.True; bool bIsTableau = false; Type tp = null; CAnalyseurSyntaxiqueExpression analyseurExpression = analyseur as CAnalyseurSyntaxiqueExpression; if (analyseurExpression != null) { C2iExpressionChamp champ = Parametres2i[0] as C2iExpressionChamp; //Vérifie que les paramètres sont bien des constantes string bool bParamOk = false; if (Parametres.Count >= 2) { if (Parametres[0] is C2iExpressionChamp && (Parametres[1] is C2iExpressionConstante || Parametres[1] is C2iExpressionTypesDynamics) && (Parametres.Count != 3 || Parametres[2] is C2iExpressionConstante || Parametres[2] is C2iExpressionVrai || Parametres[2] is C2iExpressionFaux)) { if (Parametres[1] is C2iExpressionTypesDynamics) { tp = ((C2iExpressionTypesDynamics)Parametres[1]).TypeReprésenté; } else if (Parametres[1] is Type) { tp = Parametres[1] as Type; } else { string strType = ((C2iExpressionConstante)Parametres2i[1]).Valeur.ToString(); tp = CActivatorSurChaine.GetType(strType, true); } if (tp == null) { result.EmpileErreur(I.T("The @1 type doesn't exist|136", Parametres[1].ToString())); return(result); } else { if (Parametres.Count == 3 && Parametres2i[2] is C2iExpressionConstante) { if (((C2iExpressionConstante)Parametres[2]).Valeur is int) { bIsTableau = (int)(((C2iExpressionConstante)Parametres[2]).Valeur) != 0; } if (((C2iExpressionConstante)Parametres[2]).Valeur is bool) { bIsTableau = (bool)((C2iExpressionConstante)Parametres[2]).Valeur; } } if (Parametres.Count == 3 && Parametres[2] is C2iExpressionVrai) { bIsTableau = true; } if (Parametres.Count == 3 && Parametres[2] is C2iExpressionFaux) { bIsTableau = false; } bParamOk = true; } } } if (!bParamOk) { result.EmpileErreur(I.T("The Var function paramters are invalid (two constant string are awaited and possibly one Boolean for the table)|138")); return(result); } CDefinitionProprieteDynamiqueVariableFormule def = new CDefinitionProprieteDynamiqueVariableFormule( champ.DefinitionPropriete.Nom, new CTypeResultatExpression(tp, bIsTableau), false); champ.DefinitionPropriete = def; analyseurExpression.AddVariable(def); } return(base.AfterAnalyse(analyseur)); }
/// ////////////////////////////////////////// public override CResultAErreur MyEval(CContexteEvaluationExpression ctx, object[] valeursParametres) { CResultAErreur result = CResultAErreur.True; object val = valeursParametres[0]; string strType = valeursParametres[1].ToString(); Type tp = valeursParametres[1] as Type; if (tp == null) { tp = CActivatorSurChaine.GetType(strType); } bool bArray = false; if (tp == null) { tp = DynamicClassAttribute.GetTypeFromNomConvivial(strType); } if (valeursParametres.Length >= 3) { if (valeursParametres[2] is bool && (bool)valeursParametres[2]) { bArray = true; } } try { if (!bArray) { if (val == null) { result.Data = null; } else { if (tp.IsAssignableFrom(val.GetType())) { result.Data = val; } else { result.Data = Convert.ChangeType(val, tp); } } } else { ArrayList lst = new ArrayList(); if (val is IEnumerable) { foreach (object obj in (IEnumerable)val) { lst.Add(Convert.ChangeType(obj, tp)); } } else { lst.Add(Convert.ChangeType(val, tp)); } result.Data = lst.ToArray(tp); } return(result); } catch { result.EmpileErreur(I.T("Impossible to convert the value in the @1 type|164", strType)); } return(result); }
public static CResultAErreur InitFromXml(string strFichier) { /* * <configuration> * <sc2iRestrictions> * <Mode cle=" "> * <Restriction type="Cafel.data.partenaire" restriction="NoCreate"> * <Propriete name="Libelle" restriction="ReadOnly"/> * </Restriction> * </Mode> * </sc2iRestrictions> * <configuration> * */ CResultAErreur result = CResultAErreur.True; XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(new StreamReader(strFichier)); //Noeud login XmlNode node = xmlDoc.SelectSingleNode("/configuration/sc2iRestrictions"); if (node == null) { return(result); } XmlNode child = node.FirstChild; while (child != null) { if (child.Name.ToUpper() == "MODE") { string strMode = child.Attributes["cle"].Value; XmlNode nodeClass = child.FirstChild; while (nodeClass != null) { if (nodeClass.Name.ToUpper() == "RESTRICTION") { CListeRestrictionsUtilisateurSurType liste = (CListeRestrictionsUtilisateurSurType)m_tableRestrictions[strMode]; if (liste == null) { liste = new CListeRestrictionsUtilisateurSurType(); m_tableRestrictions[strMode] = liste; } Type tp = CActivatorSurChaine.GetType(nodeClass.Attributes["type"].Value); if (tp != null) { CRestrictionUtilisateurSurType restriction = liste.GetRestriction(tp); string strRestriction = nodeClass.Attributes["restriction"].Value; restriction.RestrictionUtilisateur = (ERestriction)Enum.Parse(typeof(ERestriction), strRestriction); XmlNode nodePropriete = nodeClass.FirstChild; while (nodePropriete != null) { if (nodePropriete.Name.ToUpper() == "PROPRIETE") { restriction.SetRestrictionLocale(nodePropriete.Attributes["name"].Value, (ERestriction)Enum.Parse(typeof(ERestriction), nodePropriete.Attributes["restriction"].Value.ToString())); } nodePropriete = nodePropriete.NextSibling; } liste.AddRestriction(restriction); } } nodeClass = nodeClass.NextSibling; } } child = child.NextSibling; } } catch (Exception e) { result.EmpileErreur(new CErreurException(e)); result.EmpileErreur(I.T("Error in the restrictions configuration|102")); } return(result); }
//------------------------------------------------------------------- public virtual object GetValeur(DataRowVersion version) { if (ChampCustom == null) { return(""); } if (IsNull) { return(null); } try { switch (ChampCustom.TypeDonneeChamp.TypeDonnee) { case TypeDonnee.tBool: return((bool)Row[c_champValeurBool, version]); case TypeDonnee.tDate: return((DateTime)Row[c_champValeurDate, version]); case TypeDonnee.tDouble: if (ChampCustom.ClasseUnite != null) { string strFormat = (string)Row[c_champValeurString, version]; if (strFormat == null || strFormat.Trim().Length == 0) { strFormat = ChampCustom.FormatAffichageUnite; if (strFormat.Trim().Length == 0) { } } if (strFormat == null) { strFormat = ""; } return(new CValeurUnite((double)Row[c_champValeurDouble], ChampCustom.ClasseUnite.UniteBase, strFormat)); } return((double)Row[c_champValeurDouble, version]); case TypeDonnee.tEntier: return((int)Row[c_champValeurInt, version]); case TypeDonnee.tString: return((string)Row[c_champValeurString, version]); case TypeDonnee.tObjetDonneeAIdNumeriqueAuto: { string strType = (string)Row[c_champValeurString, version]; int nId = (int)Row[c_champValeurInt, version]; Type tp = CActivatorSurChaine.GetType(strType, true); if (tp != null) { CObjetDonneeAIdNumerique objet = (CObjetDonneeAIdNumerique)Activator.CreateInstance(tp, new object[] { ContexteDonnee }); if (objet.ReadIfExists(nId)) { return(objet); } } return(null); } } } catch { } return(ChampCustom.TypeDonneeChamp.ObjectToType("", ContexteDonnee)); }
public bool Initialiser(object valeur) { Controls.Clear(); try { m_valeur = (CControlListeOperationsSurCAVO.CValeurCAVOO)valeur; } catch { return(false); } CAuditVersionObjetOperation cavoo = m_valeur.CAVOO; Type tpEntite = cavoo.TypeEntite; string strType = cavoo.IDifferencesBlobType == null || cavoo.IDifferencesBlobType == "" ? cavoo.TypeValeurString : cavoo.IDifferencesBlobType; Type tpValeur = CActivatorSurChaine.GetType(strType); Control ctrl = null; //ENTITE LIEE ? if (tpValeur == typeof(int)) { if (cavoo.Champ.GetType() == typeof(CChampCustomPourVersion)) { //SAVOIR SI LE CHAMP CUSTOM POINTE VERS UNE ENTITE... //((CChampPourVersionInDb)cavoo.Champ). } else { PropertyInfo[] props = tpEntite.GetProperties(); foreach (PropertyInfo p in props) { object[] atts = p.GetCustomAttributes(typeof(RelationAttribute), false); if (atts.Length == 1) { RelationAttribute att = (RelationAttribute)atts[0]; if (att.ChampsParent.Length == 1 && att.ChampsFils.Length == 1 && att.ChampsParent[0] == cavoo.Champ.FieldKey) { string strDescrip = ""; if (m_valeur.Valeur != null) { CFiltreData filtre = new CFiltreData(att.ChampsFils[0] + " =@1", (int)m_valeur.Valeur); CListeObjetsDonnees lstObj = new CListeObjetsDonnees(cavoo.ContexteDonnee, p.PropertyType, filtre); bool bElementAccessible = lstObj.Count == 1; CObjetDonneeAIdNumerique obj = null; if (bElementAccessible) { obj = (CObjetDonneeAIdNumerique)lstObj[0]; strDescrip = obj.DescriptionElement; } else { strDescrip = I.T("Indefinite element from type @1 |30278", DynamicClassAttribute.GetNomConvivial(p.PropertyType)); } CControlListeOperationsSurCAVO.CValeurCAVOOEntite valeurEntite = new CControlListeOperationsSurCAVO.CValeurCAVOOEntite(strDescrip, (int)m_valeur.Valeur, p.PropertyType, obj); CControlOpertionCAVOOEntite ctrlEntite = new CControlOpertionCAVOOEntite(); ctrlEntite.Initialiser(valeurEntite); ctrl = ctrlEntite; break; } return(true); } } } } } if (ctrl == null) { //if (tpValeur == typeof(DateTime)) //{ //} //else if (tpValeur == typeof(int)) //{ //} //else if (tpValeur == typeof(bool)) //{ //} if (typeof(IDifferencesBlob).IsAssignableFrom(tpValeur)) { if (tpValeur == typeof(timos.data.CDifferencesTables)) { CControlOpertionCAVOOBlobTableParametrable ctrlTable = new CControlOpertionCAVOOBlobTableParametrable(); ctrlTable.Init(m_valeur); ctrl = ctrlTable; } else { } } //else if (tpValeur == typeof(byte[])) //{ //} else { try { Label lbl = new Label(); if (m_valeur.Valeur != null) { lbl.Text = m_valeur.Valeur.ToString(); } ctrl = lbl; } catch { } } } if (ctrl != null) { Controls.Add(ctrl); ctrl.Dock = DockStyle.Fill; } return(true); }
//-------------------------------------------------------------------------------------------------------------------- public override CResultAErreur ExecuterOperation(IDatabaseConnexion connection, IIndicateurProgression indicateur) { CResultAErreur result = CResultAErreur.True; IDataBaseCreator createur = connection.GetDataBaseCreator(); string strNomTableInContexte = CContexteDonnee.GetNomTableForType(m_type); string strNomTableInDb = CContexteDonnee.GetNomTableInDbForNomTable(strNomTableInContexte); createur.CreationOuUpdateTableFromType(m_type); string strChampIdObjet = m_strChampIdObjet; if (m_strChampIdObjet.StartsWith("#SQL#")) { strChampIdObjet = m_strChampIdObjet.Substring("#SQL#".Length); } CObjetServeur.ClearCacheSchemas(); if (createur.ChampExists(strNomTableInDb, strChampIdObjet) && createur.ChampExists(strNomTableInDb, m_strChampDbKey)) { using (CContexteDonnee ctx = new CContexteDonnee(connection.IdSession, true, false)) { C2iRequeteAvancee requete = new C2iRequeteAvancee(); requete.TableInterrogee = strNomTableInDb; CStructureTable structure = CStructureTable.GetStructure(m_type); /* * requete.ListeChamps.Add ( new C2iChampDeRequete ( * "ID", * new CSourceDeChampDeRequete(structure.ChampsId[0].NomChamp), * typeof(int), * OperationsAgregation.None, * true ));*/ requete.ListeChamps.Add(new C2iChampDeRequete( "IDOBJET", new CSourceDeChampDeRequete(m_strChampIdObjet), typeof(int), OperationsAgregation.None, true)); if (m_typeObjetFixe == null) { requete.ListeChamps.Add(new C2iChampDeRequete( "TYPEOBJET", new CSourceDeChampDeRequete(m_strChampTypeObjet), typeof(string), OperationsAgregation.None, true)); } result = requete.ExecuteRequete(connection.IdSession); if (!result) { return(result); } DataTable table = result.Data as DataTable; Dictionary <int, int?> dicIdToIdObjet = new Dictionary <int, int?>(); string strFieldIdObjetInTable = m_strChampIdObjet.Replace("#SQL#", ""); foreach (DataRow row in table.Rows) { object val = row["IDOBJET"]; int? nValId = val == DBNull.Value?null:(int?)val; if (nValId != null && nValId >= 0) { CDbKey key = null; Type tp = m_typeObjetFixe; if (tp == null)//Type non fixe { string strType = (string)row["TYPEOBJET"]; tp = CActivatorSurChaine.GetType(strType); } if (tp != null) { CObjetDonneeAIdNumerique objPointe = (CObjetDonneeAIdNumerique)Activator.CreateInstance(tp, ctx); if (objPointe.ReadIfExists(nValId.Value)) { key = objPointe.DbKey; } } if (key != null) { string strRequete = "Update " + strNomTableInDb + " set " + m_strChampDbKey + "=" + connection.GetStringForRequete(key.StringValue) + " where " + strFieldIdObjetInTable + "=" + nValId.Value; if (m_typeObjetFixe == null) { strRequete += " and " + m_strChampTypeObjet + "='" + row["TYPEOBJET"].ToString() + "'"; } connection.RunStatement(strRequete); } } } } //Supprime le champ createur.DeleteChamp(strNomTableInDb, strChampIdObjet); } return(result); }
public CResultAErreur Execute(int nIdSession, System.Collections.Hashtable valeursParametres) { CResultAErreur resErreur = CResultAErreur.True; string strType = (string)valeursParametres[c_parametreTypeAEnvoyer]; if (strType == null) { resErreur.EmpileErreur("Le type d'élément à envoyer n'est pas renseigné"); return(resErreur); } Type typeElement = CActivatorSurChaine.GetType(strType); if (typeElement == null) { resErreur.EmpileErreur("Le type d'élément à envoyer n'est pas correct (" + strType + ")"); return(resErreur); } if (!(valeursParametres[c_parametreIdElement] is int)) { resErreur.EmpileErreur("L'id de l'élément n'est pas correct"); return(resErreur); } DataSet ds = CUtilClientTiag.GetDataSetStructure(); using (CContexteDonnee contexteDonnee = new CContexteDonnee(nIdSession, true, false)) { CObjetDonneeAIdNumeriqueAuto objet = (CObjetDonneeAIdNumeriqueAuto)Activator.CreateInstance(typeElement, contexteDonnee); if (!objet.ReadIfExists((int)valeursParametres[c_parametreIdElement])) { resErreur.EmpileErreur("L'élément demandé n'existe pas (" + strType + " / " + valeursParametres[c_parametreIdElement].ToString() + ")"); return(resErreur); } CUtilClientTiag.FillDataSet((IElementAInterfaceTiag)objet, ds); } CServiceDistantTiag service = new CServiceDistantTiag("tcp://127.0.0.1:8182"); //TiagService.TiagService service = new TiagService.TiagService(); resErreur = CResultAErreur.True; CResultDataSet result = service.OpenSession(c_strServerKey); int nIdSessionTiag = -1; try { nIdSessionTiag = (int)result.Data; result = service.OnModifieDonnees(nIdSessionTiag, ds); } catch (Exception e) { resErreur.EmpileErreur(new CErreurException(e)); } finally { service.CloseSession(nIdSessionTiag); } if (!result) { foreach (string strErreur in result.GetErreurs()) { resErreur.EmpileErreur(strErreur); } } return(resErreur); }
/// ////////////////////////////////////////// public override CResultAErreur MyEval(CContexteEvaluationExpression ctx, object[] listeParametres) { CResultAErreur result = CResultAErreur.True; string strVal = listeParametres[0].ToString(); Type tp = listeParametres[0] as Type; if (tp == null) { tp = CActivatorSurChaine.GetType(strVal, true); } if (tp == null) { tp = CActivatorSurChaine.GetType(strVal, false); } if (tp == null) { result.EmpileErreur(I.T("The @1 type does not exist|221", strVal)); return(result); } if (!typeof(CObjetDonneeAIdNumerique).IsAssignableFrom(tp)) { result.EmpileErreur(I.T("The @1 type cannot be loaded by the 'GetEntite' function|222", strVal)); return(result); } try { CContexteDonnee contexteDonnee = (CContexteDonnee)ctx.GetObjetAttache(typeof(CContexteDonnee)); if (contexteDonnee == null) { contexteDonnee = new CContexteDonnee(CSessionClient.GetSessionUnique().IdSession, true, false); ctx.AttacheObjet(typeof(CContexteDonnee), contexteDonnee); } CObjetDonneeAIdNumerique obj = (CObjetDonneeAIdNumerique)Activator.CreateInstance(tp, new object[] { contexteDonnee }); if (listeParametres[1] is int) { if (obj.ReadIfExists((int)listeParametres[1])) { result.Data = obj; } else { result.Data = null; } } // YK 14/04/2011 Surcharge du deuxième paramètre en String Nom de l'entité nommée else if (listeParametres[1] is string) { CNommageEntite nommage = new CNommageEntite(contexteDonnee); if (nommage.ReadIfExists(new CFiltreData( CNommageEntite.c_champTypeEntite + " = @1 AND " + CNommageEntite.c_champNomFort + " = @2", tp.ToString(), (string)listeParametres[1]))) { result.Data = nommage.GetObjetNomme(); } else if (typeof(IObjetDonnee).IsAssignableFrom(tp)) { IObjetDonnee objUniv = (IObjetDonnee)Activator.CreateInstance(tp, new object[] { contexteDonnee }); if (objUniv.ReadIfExistsUniversalId((string)listeParametres[1])) { result.Data = objUniv; } } else { result.Data = null; } } } catch (Exception e) { result.EmpileErreur(new CErreurException(e)); } return(result); }
/// ///////////////////////////////////////////////////////// public static object StringToType(TypeDonnee type, string strTexte, CContexteDonnee contexteDonnee) { if (strTexte.ToUpper() == c_ConstanteNull) { return(null); } switch (type) { case TypeDonnee.tBool: return(strTexte.ToString() == "1" || strTexte.ToUpper() == "TRUE"); case TypeDonnee.tDate: try { return(Convert.ChangeType(strTexte, typeof(DateTime), null)); } catch { //Tente le format sc2i de date chaine try { return(CUtilDate.FromUniversalString(strTexte)); } catch { return(null); } } case TypeDonnee.tDouble: try { return(CUtilDouble.DoubleFromString(strTexte)); } catch { return(null); } case TypeDonnee.tEntier: try { return(Convert.ChangeType(strTexte, typeof(int), null)); } catch { return(null); } case TypeDonnee.tString: return(strTexte); case TypeDonnee.tObjetDonneeAIdNumeriqueAuto: try { if (contexteDonnee == null) { return(null); } //Syntaxe : classe|id int nPos = strTexte.LastIndexOf("|"); if (nPos < 0) { return(null); } string strClasse = strTexte.Substring(0, nPos); int nId = Int32.Parse(strTexte.Substring(nPos + 1)); Type tp = CActivatorSurChaine.GetType(strClasse, true); if (tp != null) { CObjetDonneeAIdNumerique objet = (CObjetDonneeAIdNumerique)Activator.CreateInstance(tp, new object[] { contexteDonnee }); if (objet.ReadIfExists(nId)) { return(objet); } } return(null); } catch { return(null); } } return(null); }
//-------------------------------------------------------- public CResultAErreur InterpreteParametres() { CResultAErreur result = CResultAErreur.True; if (m_bIsInterprete) { return(result); } //Paramètre 1 : champ //Paramètre 2 : sous type //Parametre 3 : champ de sous type retourné //Paramètre 4 : Filtre if (Parametres.Count < 4) { result.EmpileErreur(GetOperateurSousFiltre() + " " + I.T("Require 4 parameters : field, type, source field, sub filter|20008")); return(result); } m_champTeste = Parametres[0] as CComposantFiltreChamp; if (m_champTeste == null) { result.EmpileErreur(GetOperateurSousFiltre() + " : " + I.T("First parameter is invalid (field requiered|20070")); } Type tp = null; m_strTableSousFiltre = null; CComposantFiltreConstante compoCst = Parametres[1] as CComposantFiltreConstante; if (compoCst != null && compoCst.Valeur != null) { tp = CActivatorSurChaine.GetType(compoCst.Valeur.ToString(), true); if (tp != null) { m_strTableSousFiltre = CContexteDonnee.GetNomTableForType(tp); } if (m_strTableSousFiltre == null) { result.EmpileErreur(I.T("Invalid type reference (@1)|20009", compoCst.Valeur.ToString())); } } else { result.EmpileErreur(GetOperateurSousFiltre() + " : " + I.T("Second parameter is invalid (type requiered)|20010")); } if (result) { CComposantFiltreConstante compoFiltre = Parametres[3] as CComposantFiltreConstante; if (compoFiltre == null || compoFiltre.Valeur == null) { result.EmpileErreur(GetOperateurSousFiltre() + " : " + I.T("4th parameter is invalid (filtre requiered)|20012")); return(result); } m_filtre = new CFiltreDataAvance(m_strTableSousFiltre, compoFiltre.Valeur.ToString()); if (m_filtre.ComposantPrincipal == null) { result.EmpileErreur(I.T("Sub filter is invalide|20014")); return(result); } } if (result) { CComposantFiltreConstante compoSousChamp = Parametres[2] as CComposantFiltreConstante; if (compoSousChamp == null || compoSousChamp.Valeur == null) { result.EmpileErreur(GetOperateur() + " : " + I.T("3rd parameter is invalide (field requiered)|20013")); return(result); } m_champSousFiltre = new CComposantFiltreChamp(compoSousChamp.Valeur.ToString(), m_strTableSousFiltre); } m_bIsInterprete = result.Result; return(result); }
private void ConstruireDataTable(List <CAuditVersionObjetOperation> lstOperations) { m_dt = new DataTable(); m_dt.Columns.Add("Type opération", typeof(CTypeOperationSurObjet)); m_dt.Columns.Add("Champ", typeof(IChampPourVersion)); m_dt.Columns.Add("Type donnée", typeof(Type)); m_dt.Columns.Add("Valeur Source", typeof(IValeurCAVOO)); m_dt.Columns.Add("Valeur Cible", typeof(IValeurCAVOO)); foreach (CAuditVersionObjetOperation cavoo in lstOperations) { DataRow dr = m_dt.NewRow(); dr[m_dt.Columns[0]] = cavoo.TypeOperation; if (cavoo.Champ != null) { dr[m_dt.Columns[1]] = cavoo.Champ; dr[m_dt.Columns[2]] = CActivatorSurChaine.GetType(cavoo.TypeValeurString); dr[m_dt.Columns[3]] = new CValeurCAVOO(cavoo, EOrigineVersion.Source); dr[m_dt.Columns[4]] = new CValeurCAVOO(cavoo, EOrigineVersion.Cible); } else { string strDescrip = cavoo.VersionObjet.Description; dr[m_dt.Columns[2]] = cavoo.TypeEntite; if (CUtilAChampID.Contexte == null) { CUtilAChampID.Contexte = cavoo.ContexteDonnee; } int nColonne = -1; EOrigineVersion origine = EOrigineVersion.Cible; if (cavoo.TypeOperation.Code == CTypeOperationSurObjet.TypeOperation.Suppression) { origine = EOrigineVersion.Source; nColonne = 3; } else { origine = EOrigineVersion.Cible; nColonne = 4; } if (origine == EOrigineVersion.Source && cavoo.ValeurSource != null || origine == EOrigineVersion.Cible && cavoo.ValeurCible != null) { dr[m_dt.Columns[nColonne]] = new CValeurCAVOO(cavoo, origine); } else { int nIdEntite = cavoo.VersionObjet.IdObjetCible.HasValue ? cavoo.VersionObjet.IdObjetCible.Value : cavoo.VersionObjet.IdObjetSource.Value; Type tpEntite = cavoo.VersionObjet.TypeElement; CFiltreData filtre = new CFiltreData(CUtilAChampID.GetChampID(tpEntite) + " =@1", nIdEntite); CListeObjetsDonnees lstObj = new CListeObjetsDonnees(cavoo.ContexteDonnee, tpEntite, filtre); CObjetDonneeAIdNumerique obj = null; if (lstObj.Count == 1) { obj = (CObjetDonneeAIdNumerique)lstObj[0]; } dr[m_dt.Columns[nColonne]] = new CValeurCAVOOEntite(strDescrip, nIdEntite, cavoo.TypeEntite, obj); } } m_dt.Rows.Add(dr); m_dt.Rows[m_dt.Rows.Count - 1].AcceptChanges(); } m_dgvViewer.LectureSeule = false; Bind(); }