Exemple #1
0
 /// <summary>
 /// Permet de définir directement  la structure de la table pour ce datarow, création d'une nouvelle si elle existe pas
 /// Ne fonctionnera
 /// </summary>
 /// <param name="nameTable"></param>
 /// <param name="ColsKeys"></param>
 public static void DefineSchemaPO(DataPO po, string nameTable, System.Data.DataColumn[] Cols, System.Data.DataColumn[] ColsKeys)
 {
     System.Data.DataTable table = null;
     table = DataSetTools.DefineDataTable(nameTable, Cols, ColsKeys);
     DefineSchemaPO(po, table);
     //   itemcc.ReadOnly = false; // pas de readonly dans les bulles, sinon on ne peut plus modifier
 }
Exemple #2
0
        /// <summary>
        /// Permet de définir directement la structure du PO (Un nouveau Row a partir de la nouvelle table)
        /// </summary>
        /// <param name="po"></param>
        /// <param name="table"></param>
        /// <param name="AllowKeepOriginalRow">Si il y as déja un datarow avec des données, on préserve les données dans la nouvelle Table</param>
        public static void DefineSchemaPO(DataPO po, DataTable tableSchema, bool AllowKeepOriginalRow = true, bool CloneNewTable = true)
        {
            try
            {
                bool rowexisting = false;
                if (po.localRow != null && po.localRow.ItemArray != null && po.localRow.ItemArray.Length > 0)
                {
                    rowexisting = true;                            // il y as des données dans le datarow existant
                }
                if (rowexisting && AllowKeepOriginalRow)           //Clone un nouveau datarow dans la nouvelle table avec des données d'origine
                {
                    po.localRow.Table.MergeAddSchema(tableSchema); // il suffit juste de vérifier que le shémas est bien identique
                }
                //po.localRow = DataSetTools.ReplaceRowInOtherTable(po.localRow, table); // premet de recopier les données orgininal dans la nouvelle table
                else
                {
                    DataTable tabledata = CloneNewTable ? tableSchema.Clone() : tableSchema;
                    // il faut clonner la table pour eviter les erreurs sur autoincrement, !!! voir si possible d'améliorer car multipli le temps de traitement x10
                    po.localRow = tabledata.NewRow(); // init simple
                }

                po._isDefined = true;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("DefineSchemaPO {0}", ex.Message));
            }
        }
Exemple #3
0
        public static Dictionary <string, object> GetChangedValues(this DataPO po)
        {
            bool refreshflow = (po.flows != null && po.flows.Count(f => f.IsChanges()) > 0);

            System.Data.DataRow row = po.GetRow(refreshflow);
            return(DataSetTools.GetChangedValues(row));
        }
Exemple #4
0
        /// <summary>
        /// Présence de changements
        /// </summary>
        /// <returns></returns>
        public static bool IsChanges(this DataPO item)
        {
            // On regarde si il y as eu un changement dans les flow
            if (item.flows != null && item.flows.Count(f => f.IsChanges()) > 0)
            {
                return(true);
            }

            // on regarde si il y as eu un changement dans le datarow
            if (item.localRow == null)
            {
                return(false);
            }
            else if (item.localRow.RowState.HasFlag(System.Data.DataRowState.Modified))
            {
                return(true);
            }
            else if (item.localRow.RowState.HasFlag(System.Data.DataRowState.Detached))
            {
                return(true);                                                                        // on considere que les datarow Detached nécesite un Insert donc ils nécessiteront un traitement
            }
            else
            {
                return(false);
            }
        }
Exemple #5
0
        //(System.Data.DataTable ret, object paramconstructeur = null) where Tobj : DATA.DATAPO.DataPO, new()
        /// <summary>
        /// Désérialisation des données
        /// </summary>
        /// <param name="SerialInputData">Données sérialisé</param>
        /// <returns></returns>
        public DataPO DeserializationDatas(string SerialInputData, DataPO orgnPo = null)
        {
            if (string.IsNullOrWhiteSpace(SerialInputData))
            {
                return(null);
            }
            DataPO retour = orgnPo;

            try
            {
                System.Data.DataTable ret = new DataTable();
                //if(retour==null)retour = new



                //string[] orgstringT = orgstring.Split(new string[] { "[[!!" }, StringSplitOptions.RemoveEmptyEntries);

                //foreach (string orgstringTitem in orgstringT)
                //{
                //    string nameValue = orgstringTitem.Substring(0, orgstringTitem.IndexOf("!!]]") + 1);
                //    string value = orgstringTitem.Substring((nameValue.Length + 4) - 1);
                //    retour.Add(nameValue, value);
                //}
                //return retour;



                return(retour);
            }
            catch (Exception ex)
            {
                throw new Exception("DeserializationDatas " + ex.Message, ex);
            }
        }
Exemple #6
0
 /// <summary>
 /// Obtientir les données du DataPO
 /// </summary>
 /// <returns></returns>
 public static Dictionary <string, object> GetValues(this DataPO po, bool returnKeys, bool returnValues)
 {
     System.Data.DataRow row = po.GetRow(returnValues);// Si les valeurs sont demandé on refresh les flow
     if (returnKeys && !IsDefinedSchema(po))
     {
         DefineSchemaPO(po);                                    // Si l'objet est pas définis il faut le daire
     }
     return(DataSetTools.GetValues(row, returnKeys, returnValues));
 }
Exemple #7
0
        /// <summary>
        /// Obtient toute les valeurs des propriétées déclarées dans la classe (PAR REFLEXION)
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, object> GetDeclaredValues(this DataPO po)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            foreach (PropertyInfo prp in APP.CODE.PropertiesTools.GetProperties(po.GetType()))
            {
                object value = prp.GetValue(po, new object[] { });
                dict.Add(prp.Name, value);
            }
            return(dict);
        }
Exemple #8
0
 /// <summary>
 /// Savoir si le datapo à été correctement défini pour des actions SQL
 /// </summary>
 /// <param name="po"></param>
 /// <returns></returns>
 public static bool IsDefinedSchema(this DataPO po)
 {
     if (po == null)
     {
         return(false);
     }
     if (po.GetRow() == null)
     {
         return(false);
     }
     if (!po._isDefined)
     {
         return(false);
     }
     return(true);
 }
Exemple #9
0
        //public static System.Data.DataTable CreateSchemaOnPO(DataPO po)
        //{
        //    System.Data.DataTable tableStd = null;
        //    if (tableStd == null) tableStd = po.InitSchema(); // sinon on tente avec la prédéinition hérité
        //    if (tableStd == null) tableStd = CreateSchemaWithAttributes(po);// sinon on tente de mettre l'objet en cache avec les attributs
        //    return tableStd;
        //}


        public static System.Data.DataTable CreateSchemaOnPO(Type potype)
        {
            System.Data.DataTable tableStd = null;
            if (tableStd == null) // La structure est defini dans une methode hérité.
            {
                // sinon on tente avec la prédéinition hérité, mais pour cela il faut instancier un objet (!!! gérer si constructeur non vide)
                DataPO pofictif = APP.CODE.ReflectionTools.NewInstance(potype) as DataPO;
                tableStd = pofictif.InitSchema();
            }
            // sinon on tente de voir si l'objet dispose d'attributs spécifiant sa structure
            if (tableStd == null)
            {
                tableStd = CreateSchemaWithAttributes(potype);
            }
            return(tableStd);
        }
Exemple #10
0
        /// <summary>
        /// Obtientir les données du DataPO
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, object> GetValues(this DataPO po, params string[] ColNames)
        {
            if (ColNames == null || ColNames.Length == 0)
            {
                return(new Dictionary <string, object>());
            }
            bool refreshflow = false;

            if (po.flows != null && po.flows.Count > 0)
            {
                refreshflow = po.flows.Select(f => f.GetFieldName()).Where(fn => !string.IsNullOrWhiteSpace(fn)).Any(fn => ColNames.Any(eq => fn.Equals(eq, StringComparison.OrdinalIgnoreCase)));
            }

            System.Data.DataRow row = po.GetRow(refreshflow);
            return(DataSetTools.GetValues(row, ColNames));
        }
Exemple #11
0
        private List <DATAPO.DataPO> GetAllInternal(DataPO po)
        {
            Type typepo = po.GetType();

            PropertyInfo[]       properties = typepo.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            List <DATAPO.DataPO> retour     = new List <DataPO>();

            foreach (PropertyInfo prp in properties)
            {
                // Only work with strings
                //if (prp.DeclaringType != typeof(DATAPO.DataPO)) { continue; }

                // If not writable then cannot null it; if not readable then cannot check it's value
                if (!prp.CanWrite || !prp.CanRead)
                {
                    continue;
                }
                //if(prp.)
                object objval = null;
                try
                {
                    objval = prp.GetValue(po, new object[] { });
                }
                catch (Exception) // fnc a revoir
                {
                    continue;
                }


                if (!(objval is DATAPO.DataPO))
                {
                    continue;
                }

                DATAPO.DataPO value = objval as DATAPO.DataPO;
                if (value == null)
                {
                    continue;
                }
                //dict.Add(prp.Name, value);
                retour.Add(value);
            }
            return(retour);
        }
Exemple #12
0
        /// <summary>
        /// Permet de preparer l'objet (notament définir le datarow et son schema)
        /// C'est nécessaire pour les opérations SQL, ou l'instanciation vide d'un DATAPO
        /// </summary>
        /// <param name="po"></param>
        /// <returns></returns>
        public static void DefineSchemaPO(this DataPO po, bool allowCache = true)
        {
            try
            {
                if (po == null)
                {
                    return;
                }
                Type potype = po.GetType();
                System.Data.DataTable tableStd = DataPOTools.GetSchemaOnPO(potype, allowCache);

                // on prend un clone de la table
                DefineSchemaPO(po, tableStd, true); // voir si il est possible d'améliorer pour ne pas prendre de clone !!! (faire le clone que si il y as modification des colonnes)
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("InitalizeDataPo {0}", ex.Message));
            }
        }
Exemple #13
0
        /// <summary>
        /// Sérialiser le Datapo
        /// </summary>
        /// <param name="po">Objet racine à sérialiser</param>
        /// <param name="includeInternalPO">Inclure les sous objets</param>
        /// <param name="fromProperty">Pour les sérialisations en boucles</param>
        /// <returns>string sérialiser custom</returns>
        public static string SerializeDatas(DataPO po, bool includeInternalPO = true, PropertyInfo fromProperty = null)
        {
            try
            {
                StringBuilder retour = new StringBuilder();
                retour.Append("[[$");
                System.Data.DataRow rowd = po.GetRow();
                string strd = MANIPULATE.DATASET.DataTableTools.SerializeDataRow(rowd);
                if (!string.IsNullOrEmpty(strd))
                {
                    retour.Append("[[!dataxml!]]");
                    retour.Append(strd);
                    retour.AppendLine();
                }
                if (!includeInternalPO)
                {
                    return(retour.ToString());
                }


                Type           typepo     = po.GetType();
                PropertyInfo[] properties = typepo.GetProperties(BindingFlags.Public | BindingFlags.Instance);

                foreach (PropertyInfo propertie in properties)
                {
                    string strproper = ToDatasXMLProperty(propertie, po);
                    if (string.IsNullOrWhiteSpace(strproper))
                    {
                        continue;
                    }
                    retour.AppendFormat("[[!{0}!]]", propertie.Name);
                    retour.Append(strproper);
                    retour.AppendLine();
                }
                retour.Append("$]]");
                return(retour.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("GetDatasXML" + ex.Message, ex);
            }
        }
Exemple #14
0
        /// <summary>
        /// Définit les valeur dans le datarow dans l'objet
        /// </summary>
        /// <param name="row">L'objet de données</param>
        public static void SetValues(this DataPO po, Dictionary <string, object> DicDataRow)
        {
            try
            {
                if (po.localRow == null)
                {
                    po.DefineSchemaPO();                      // si pas de datarow, on l'initialise (identique à GetRow())
                }
                foreach (var item in DicDataRow)
                {
                    po.SetObject(item.Key, item.Value);
                }


                //po._isLoaded = false; // N'a pas été chargé depuis une base de données !!! voir comment on fait
            }
            catch (Exception ex)
            {
                throw new Exception("SetValues " + ex.Message, ex);
            }
        }
Exemple #15
0
        private string ToDatasXMLProperty(PropertyInfo property, DataPO po)
        {
            if (property == null || po == null)
            {
                return(null);
            }
            try
            {
                // !!! filtrer les types innutiles
                object val = property.GetValue(po, null);
                if (val == null)
                {
                    return(null);
                }
                if (val is DataPO)
                {
                    string str = this.SerializeDatas((DataPO)val, true, property);
                    return(str);
                }

                var attributes = property.GetCustomAttributes(true);
                foreach (var item in attributes)
                {
                    if (item is DATAPO.JoinPOAttribute)
                    {
                        if (val is List <DataPO> ) // si c'est une liste
                        {
                            return(this.ToDatasXMLMultiPos(property, (List <DataPO>)val));
                        }
                    }
                }
                return(null);
            }
            catch (Exception)
            {
                return(null);

                throw;
            }
        }
Exemple #16
0
        public DataPO GetOrInstanciateInternalPO(DataPO poOrgn, string propName, bool allowInstanciate = true) //where Tobj : DATA.DATAPO.DataPO, new()
        {
            DataPO       retour     = null;
            Type         poType     = poOrgn.GetType();
            PropertyInfo poProperty = poType.GetProperty(propName);
            object       poino      = poProperty.GetValue(poOrgn, null);

            if (poino != null)
            {
                if (poino is DataPO)
                {
                    retour = (DataPO)poino;
                }
                else
                {
                    return(null); // erreur dans les types
                }
            }
            if (retour == null)
            {
                retour = (DataPO)Activator.CreateInstance(poProperty.PropertyType);
            }
            return(retour);
        }
Exemple #17
0
        private static System.Data.DataTable CreateSchemaWithAttributes(DataPO po)
        {
            Type potype = po.GetType();

            return(CreateSchemaWithAttributes(potype));
        }
Exemple #18
0
 public IEnumerable <Tobj> GetOrInstanciateInternalPOs <Tobj>(DataPO poOrgn, string propName, bool allowInstanciate = true) where Tobj : DATAPO.DataPO, new()
 {
     return(null);
 }