示例#1
0
        public bool Check()
        {
            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.Countries.Name}");
            logger.PutLine("Les élemnets suivants ont un numerà de géneration invalide:");

            using (IDatumProvider dp = AppContext.TableManager.TablesGeneration.DataProvider)
            {
                dp.Connect();

                bool anyErr = false;

                if (dp.Count > 0)
                {
                    foreach (FileGeneration d in dp.Enumerate())
                    {
                        if (d.Generation == 0)
                        {
                            logger.PutLine(d.ToString());
                            anyErr = true;
                        }
                    }
                }

                if (anyErr)
                {
                    logger.Flush();
                }

                return(!anyErr);
            }
        }
示例#2
0
        bool CheckConstraint17()
        {
            //∀m ∈ ProductMapping  ∃c ∈ ValueContext : c.ID = m.ContextID

            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.TRProductsMapping.Name}");

            bool err = false;

            if (m_ndxerMapProdNber.Source.Count > 0)
            {
                foreach (ProductMapping pm in m_ndxerMapProdNber.Source.Enumerate())
                {
                    if (m_ndxerContext.Get(pm.ContextID) == null)
                    {
                        logger.PutLine("La contrainte d’intégrité n° 17 est violée par l'élément suivant :");
                        logger.PutLine(pm);
                        logger.PutLine();

                        err = true;
                    }
                }
            }
            if (err)
            {
                logger.Flush();
            }

            return(!err);
        }
示例#3
0
        public bool Check()
        {
            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.Incoterms.Name}");
            logger.PutLine("La contrainte d’intégrité n° 16 est violée par les éléments suivants :");

            bool err = false;

            foreach (uint prodID in m_ndxerLabelProdNbers.Attributes)
            {
                if (m_ndxerMappingProdNbers.Get(prodID).Any())
                {
                    logger.PutLine(m_ndxerLabelProdNbers.Get(prodID).First().ToString());

                    logger.PutLine();
                    err = true;
                }
            }


            if (err)
            {
                logger.Flush();
            }

            return(!err);
        }
示例#4
0
        void Save()
        {
            Assert(!InvokeRequired);

            var      price  = (double)m_nudPrice.Value;
            DateTime dtSpot = m_dtpSpotTime.Value;

            if (m_spotValue.Price == price && m_spotValue.SpotTime == dtSpot)
            {
                TextLogger.Info("Aucune modification détectée, enregistrement non-nécessaire.");
                Close();

                return;
            }


            //verification contrainte 8
            using (var ndxer = new AttrIndexer <DateTime>(m_ndxerValues.Source, d => (d as SpotValue).SpotTime))
            {
                ndxer.Connect();

                IEnumerable <SpotValue> values = from SpotValue sv in ndxer.Get(dtSpot)
                                                 where sv.ProductID == m_spotValue.ProductID &&
                                                 sv.SupplierID == m_spotValue.SupplierID &&
                                                 sv.ValueContextID == m_spotValue.ValueContextID
                                                 select sv;

                if (values.Count() > 1 || (values.Count() == 1 && values.Single().ID != m_spotValue.ID))
                {
                    var logger = new TextLogger(LogSeverity.Warning);
                    logger.Put("Duplication de données détectée.");
                    logger.Put("Elément trouvé:\n");

                    foreach (SpotValue sv in values)
                    {
                        logger.PutLine(sv);
                    }

                    logger.Flush();

                    MessageBox.Show("La validation de  données a échouée. " +
                                    "Consultez le journal des événements pour plus d’informations.",
                                    null,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);

                    return;
                }


                var newValue = new SpotValue(m_spotValue.ID, price, dtSpot, m_spotValue.ProductID,
                                             m_spotValue.ValueContextID, m_spotValue.SupplierID, 0);
                m_ndxerValues.Source.Replace(m_ndxerValues.IndexOf(m_spotValue.ID), newValue);

                TextLogger.Info("Enregistrement réussi.");
                Close();
            }
        }
示例#5
0
        void Save()
        {
            Assert(!InvokeRequired);

            string name = m_tbName.GetInputText();

            //is input ok
            if (string.IsNullOrWhiteSpace(name))
            {
                this.ShowWarning("Nom de source mal servis. Veuillez compléter le formulaire.");
                m_tbName.Select();

                return;
            }


            //any modifs?
            if (m_datum.Name == name)
            {
                TextLogger.Info("Aucune modification détectée, enregistrement non-nécessaire.");
                Close();
                return;
            }


            //any dupliacte?
            var rows = m_ndxerSuppliers.Source.Count == 0 ? Enumerable.Empty <DataSupplier>() :
                       from ds in m_ndxerSuppliers.Source.Enumerate().Cast <DataSupplier>()
                       where string.Compare(ds.Name, name) == 0 && ds.ID != m_datum.ID
                       select ds;

            if (rows.Any())
            {
                DataSupplier supplier = rows.First();

                var logger = new TextLogger(LogSeverity.Warning);
                logger.Put("Duplication de données détectée.");
                logger.Put("Elément trouvé:\n");
                logger.Put("ID: {0}\n", supplier.ID);
                logger.Put("Source: {0}", supplier.Name);
                logger.Flush();

                this.ShowWarning("La validation de  données a échouée. " +
                                 "Consultez le journal des événements pour plus d’informations.");
            }
            else
            {
                var supplier = new DataSupplier(m_datum.ID, name);
                int ndx      = m_ndxerSuppliers.IndexOf(m_datum.ID);

                m_ndxerSuppliers.Source.Replace(ndx, supplier);
                Close();

                TextLogger.Info("Enregistrement réussi.");
            }
        }
示例#6
0
        bool CheckConstraint20()
        {
            //∀v1, v2 ∈ TRSpotValueTable (v1.ProductMappingId, v1.Time) = (v2.ProductMappingId, v2.Time) <=> v1=v2

            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.TRSpotValues.Name}");


            Func <IDatum, Pair <uint, DateTime> > selector = d =>
            {
                var sv = d as SpotValue;
                return(Pair.Create(sv.ProductMappingID, sv.Time));
            };

            bool err = false;

            using (var ndxer = new AttrIndexer <Pair <uint, DateTime> >(m_srcSpotValues, selector))
            {
                ndxer.Connect();

                foreach (var pair in ndxer.Attributes)
                {
                    if (ndxer.Get(pair).Count() != 1)
                    {
                        {
                            logger.PutLine("La contrainte d’intégrité n° 20 est violée par les éléments suivants :");

                            foreach (var datum in ndxer.Get(pair))
                            {
                                logger.PutLine(datum);
                            }

                            logger.PutLine();

                            err = true;
                        }
                    }
                }
            }


            if (err)
            {
                logger.Flush();
            }

            return(!err);
        }
示例#7
0
        public bool Check()
        {
            //contrainte 4

            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.Places.Name}");
            logger.PutLine("La contrainte d’intégrité n° 4 est violée par les éléments suivants :");

            Func <IDatum, Pair <string, uint> > filter = d =>
            {
                var p = d as Place;

                return(new Pair <string, uint>(p.Name, p.CountryID));
            };


            bool anyErr = false;

            using (AttrIndexer <Pair <string, uint> > ndxer = new AttrIndexer <Pair <string, uint> >(m_srcPlaces, filter))
            {
                ndxer.Connect();

                foreach (Pair <string, uint> item in ndxer.Attributes)
                {
                    IEnumerable <IDatum> data = ndxer.Get(item);

                    if (data.Count() > 1)
                    {
                        logger.PutLine("Eléments suivant sont identiques:");

                        foreach (Place p in data)
                        {
                            logger.PutLine($"(Lieu:{p.Name}, ID Pays:{p.CountryID})");
                        }

                        logger.PutLine();
                        anyErr = true;
                    }
                }
            }

            if (anyErr)
            {
                logger.Flush();
            }

            return(!anyErr);
        }
示例#8
0
        bool CheckConstraint11()
        {
            //∀ p1, p2 ∈ TRProductMapping (p1.ProductID, p1.ContextID) = (p2.ProductID, p2.ContextID) <=> p1 = p2

            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.TRProductsMapping.Name}");

            Func <IDatum, Pair <uint, uint> > selctor = d =>
            {
                var p = d as ProductMapping;
                return(Pair.Create(p.ProductID, p.ContextID));
            };


            bool err = false;

            using (var ndxer = new AttrIndexer <Pair <uint, uint> >(m_ndxerMapProdNber.Source, selctor))
            {
                ndxer.Connect();

                foreach (Pair <uint, uint> item in ndxer.Attributes)
                {
                    var seq = ndxer.Get(item);

                    if (seq.Count() != 1)
                    {
                        logger.PutLine("La contrainte d’intégrité n° 11 est violée par les éléments suivants :");
                        foreach (ProductMapping mapping in seq)
                        {
                            logger.PutLine(mapping);
                        }

                        logger.PutLine();
                        err = true;
                    }
                }
            }


            if (err)
            {
                logger.Flush();
            }

            return(!err);
        }
示例#9
0
        public bool Check()
        {
            //contrainte 1

            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.Products.Name}");
            logger.PutLine("La contrainte d’intégrité n° 1 est violée par les éléments suivants :");

            Func <IDatum, Pair <string, SubHeading> > selector = (d) =>
            {
                var p = d as Product;
                return(Pair.Create(p.Name, p.SubHeading));
            };

            bool anyErr = false;

            using (var ndxer = new AttrIndexer <Pair <string, SubHeading> >(m_srcProducts, selector))
            {
                ndxer.Connect();

                foreach (var pair in ndxer.Attributes)
                {
                    IEnumerable <IDatum> products = ndxer.Get(pair);

                    if (products.Count() > 1)
                    {
                        logger.PutLine("Eléments suivant sont identiques:");

                        foreach (Product prod in products)
                        {
                            logger.PutLine(prod);
                        }

                        logger.PutLine();
                        anyErr = true;
                    }
                }
            }

            if (anyErr)
            {
                logger.Flush();
            }

            return(!anyErr);
        }
示例#10
0
        public bool Check()
        {
            //contrainte 14

            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.ValuesContext.Name}");


            Func <IDatum, Tuple <uint, uint, uint, uint, uint> > selector = delegate(IDatum d)
            {
                var vc = d as ValueContext;
                return(Tuple.Create(vc.CurrencyID, vc.IncotermID, vc.OriginID, vc.PlaceID, vc.UnitID));
            };

            bool err = false;

            using (var ndxer = new AttrIndexer <Tuple <uint, uint, uint, uint, uint> >(m_srcContext, selector))
            {
                ndxer.Connect();

                foreach (var tpl in ndxer.Attributes)
                {
                    if (ndxer.Get(tpl).Count() > 1)
                    {
                        logger.PutLine("La contrainte d’intégrité n° 14 est violée par les éléments suivants :");
                        foreach (IDatum d in ndxer.Get(tpl))
                        {
                            logger.PutLine(d);
                        }

                        logger.PutLine();
                        err = true;
                    }
                }

                if (err)
                {
                    logger.Flush();
                }

                return(!err);
            }
        }
示例#11
0
        bool AddDatum(string name, ProfilePrivilege_t privilege)
        {
            var seq = from UserProfile p in m_ndxProfiles.Source.Enumerate()
                      where string.Compare(p.Name, name, true) == 0
                      select p;

            if (seq.Count() > 0)
            {
                var logger = new TextLogger(LogSeverity.Warning);
                logger.PutLine("Duplication de données détectée.");
                logger.PutLine(seq.Single().ToString());
                logger.Flush();

                MessageBox.Show("La validation de  données a échouée. " +
                                "Consultez le journal des événements pour plus d’informations.",
                                null,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);

                return(false);
            }

            var profile = new UserProfile(AppContext.TableManager.Profiles.CreateUniqID(), name, privilege);

            //ajouter gestion des profils
            var mgmntMode = new ProfileManagementMode(profile.ID);

            using (IDatumProvider dp = AppContext.TableManager.ProfileManagementMode.DataProvider)
            {
                dp.Connect();
                dp.Insert(mgmntMode);
            }

            //ajouer le profil
            m_ndxProfiles.Source.Insert(profile);


            return(true);
        }
示例#12
0
        public bool Check()
        {
            //contrainte no 10 = Name et unique
            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.Suppiers.Name}");


            bool err = false;

            using (var ndxer = new AttrIndexer <string>(m_srcUnits, d => (d as Unit).Name, StringComparer.CurrentCultureIgnoreCase))
            {
                ndxer.Connect();

                foreach (string name in ndxer.Attributes)
                {
                    if (ndxer.Get(name).Count() > 1)
                    {
                        logger.PutLine("La contrainte d’intégrité n° 10 est violée par les éléments suivants :");
                        foreach (IDatum d in ndxer.Get(name))
                        {
                            logger.PutLine(d);
                        }

                        logger.PutLine();
                        err = true;
                    }
                }
            }

            if (err)
            {
                logger.Flush();
            }

            return(!err);
        }
示例#13
0
        public bool Check()
        {
            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.Incoterms.Name}");
            logger.PutLine("La contrainte d’intégrité n° 9 est violée par les éléments suivants :");


            bool anyErr = false;

            foreach (string name in m_ndxerNames.Attributes)
            {
                IEnumerable <IDatum> icts = m_ndxerNames.Get(name);

                if (icts.Count() > 1)
                {
                    logger.PutLine($"Noms identiques ({name}):");

                    foreach (Incoterm c in icts)
                    {
                        logger.PutLine(c.ToString());
                    }

                    logger.PutLine();
                    anyErr = true;
                }
            }


            if (anyErr)
            {
                logger.Flush();
            }

            return(!anyErr);
        }
示例#14
0
        bool CheckConstraint19()
        {
            // ∀v ∈ TRSpotValueTable ∃m ∈ TRProductMappingTable: v.ProductMappingID = m.ID;

            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.TRSpotValues.Name}");

            bool err = false;

            using (var ndxer = new AttrIndexer <uint>(m_srcSpotValues, d => (d as SpotValue).ProductMappingID))
            {
                ndxer.Connect();

                foreach (uint idMapping in ndxer.Attributes)
                {
                    if (m_ProductMappings.Get(idMapping) == null)
                    {
                        logger.PutLine("La contrainte d’intégrité n° 19 est violée par l'élément suivant :");
                        logger.PutLine(ndxer.Get(idMapping));

                        logger.PutLine();

                        err = true;
                    }
                }
            }


            if (err)
            {
                logger.Flush();
            }

            return(!err);
        }
示例#15
0
        //private:
        bool CheckConstraint5()
        {
            //∀ p1, P2 ∈ TRProductMapping, p1.ProductNumber = p2.ProductNumber <=> p1 = p2;

            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.TRProductsMapping.Name}");

            bool err = false;

            foreach (uint prodNber in m_ndxerMapProdNber.Attributes)
            {
                if (m_ndxerMapProdNber.Get(prodNber).Count() != 1)
                {
                    logger.PutLine("La contrainte d’intégrité n° 5 est violée par les éléments suivants :");

                    foreach (IDatum d in m_ndxerMapProdNber.Get(prodNber))
                    {
                        logger.PutLine(d);
                    }

                    logger.PutLine();

                    err = true;
                }
            }


            if (err)
            {
                logger.Flush();
            }


            return(!err);
        }
示例#16
0
        bool UpdateDatum(string name, ProfilePrivilege_t privilege)
        {
            if (string.Compare(name, m_datum.Name) == 0 && m_datum.Privilege == privilege)
            {
                TextLogger.Info("Aucune modification détectée, enregistrement non-nécessaire.");
                return(true);
            }

            var seq = from UserProfile p in m_ndxProfiles.Source.Enumerate()
                      where string.Compare(p.Name, name, true) == 0 && p.ID != m_datum.ID
                      select p;

            if (seq.Count() > 0)
            {
                var logger = new TextLogger(LogSeverity.Warning);
                logger.PutLine("Duplication de données détectée.");
                logger.PutLine(seq.Single().ToString());
                logger.Flush();

                MessageBox.Show("La validation de  données a échouée. " +
                                "Consultez le journal des événements pour plus d’informations.",
                                null,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);


                return(false);
            }

            int ndx     = m_ndxProfiles.IndexOf(m_datum.ID);
            var profile = new UserProfile(m_datum.ID, name, privilege);

            m_ndxProfiles.Source.Replace(ndx, profile);

            return(true);
        }
示例#17
0
        void Save()
        {
            Assert(!InvokeRequired);

            string ictName = m_tbName.GetInputText();

            if (string.IsNullOrWhiteSpace(ictName))
            {
                this.ShowWarning("Champs monétaire mal servi. Veuillez compléter le formulaire.");
                m_tbName.Select();

                return;
            }


            if (m_incoterm != null && m_incoterm.Name == ictName)
            {
                TextLogger.Info("Aucune modification détectée, enregistrement non-nécessaire.");

                Close();
                return;
            }


            IEnumerable <IDatum> data = m_ndxerNames.Get(ictName.ToUpper());

            int count = data.Count();

            if (count == 0 || (count == 1 && m_incoterm != null && m_incoterm.ID == data.Cast <Incoterm>().Single().ID))
            {
                uint id = m_incoterm == null?AppContext.TableManager.Incoterms.CreateUniqID() :
                              m_incoterm.ID;

                var ict = new Incoterm(id, ictName);

                if (m_incoterm == null)
                {
                    m_ndxerNames.Source.Insert(ict);
                }
                else
                {
                    m_ndxerNames.Source.Replace(m_ndxerNames.IndexOf(m_incoterm.Name.ToUpper()).Single(), ict);
                }

                TextLogger.Info("Enregistrement réussi.");
                Close();
            }
            else
            {
                var logger = new TextLogger(LogSeverity.Warning);
                logger.Put("Duplication de données détectée.");
                logger.Put("Elément trouvé:\n");

                foreach (Incoterm ict in data)
                {
                    logger.PutLine(ict);
                }

                logger.Flush();

                MessageBox.Show("La validation de  données a échouée. " +
                                "Consultez le journal des événements pour plus d’informations.",
                                null,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
            }
        }
示例#18
0
文件: UnitForm.cs 项目: Adel-dz/Hub
        void Save()
        {
            Assert(!InvokeRequired);

            string name = m_tbName.GetInputText();

            //is input ok?
            if (string.IsNullOrWhiteSpace(name))
            {
                this.ShowWarning("Unité mal servie. Veuillez compléter le formulaire.");
                m_tbName.Select();

                return;
            }

            string descr = m_tbDescription.GetInputText();


            //any modif?
            if (m_datum != null && name == m_datum.Name && descr == m_datum.Description)
            {
                TextLogger.Info("Aucune modification détectée, enregistrement non-nécessaire.");
                Close();
                return;
            }



            //any duplicate?
            using (new AutoReleaser(() => UseWaitCursor = false))
            {
                UseWaitCursor = true;

                var seq = m_ndxerUnits.Source.Count == 0 ? Enumerable.Empty <Unit>() :
                          from u in m_ndxerUnits.Source.Enumerate().Cast <Unit>()
                          where string.Compare(u.Name, name, true) == 0 &&
                          (m_datum == null || m_datum.ID != u.ID)
                          select u;

                if (seq.Any())
                {
                    Unit unit = seq.First();

                    var logger = new TextLogger(LogSeverity.Warning);
                    logger.Put("Duplication de données détectée.");
                    logger.Put("Elément trouvé:\n");
                    logger.Put("ID: {0}\n", unit.ID);
                    logger.Put("Unité: {0}\n", unit.Name);
                    logger.Put("Description: {0}", unit.Description);
                    logger.Flush();

                    this.ShowWarning("La validation de  données a échouée. " +
                                     "Consultez le journal des événements pour plus d’informations.");
                }
                else
                {
                    uint id   = (m_datum?.ID) ?? AppContext.TableManager.Units.CreateUniqID();
                    var  unit = new Unit(id, name, descr);

                    if (m_datum != null)
                    {
                        int ndx = m_ndxerUnits.IndexOf(id);
                        m_ndxerUnits.Source.Replace(ndx, unit);

                        Close();
                    }
                    else
                    {
                        m_ndxerUnits.Source.Insert(unit);
                        ClearForm();
                    }

                    TextLogger.Info("Enregistrement réussi.");
                }
            }
        }
示例#19
0
文件: PlaceForm.cs 项目: Adel-dz/Hub
        void Save()
        {
            Assert(!InvokeRequired);

            //is input ok?
            string name = m_tbName.GetInputText();

            if (string.IsNullOrWhiteSpace(name))
            {
                this.ShowWarning("Champs monétaire mal servi. Veuillez compléter le formulaire.");
                m_tbName.Select();

                return;
            }

            uint idCtry = (m_cbCountries.SelectedItem as CountryListEntry).Country.ID;

            if (m_datum != null && name == m_datum.Name && idCtry == m_datum.CountryID)
            {
                TextLogger.Info("Aucune modification détectée, enregistrement non-nécessaire.");
                Close();

                return;
            }


            /*
             *  - selon containte 4 (name, idCtry) est unique
             *
             **/

            //any duplicate?
            Predicate <IDatum> filter = d =>
            {
                var place = d as Place;
                return(string.Compare(place.Name, name, true) == 0 && place.CountryID == idCtry);
            };

            bool duplicate = true;

            using (var dp = new DatumProvider(m_ndxerPlaces.Source, filter))
                using (new AutoReleaser(() => UseWaitCursor = false))
                {
                    UseWaitCursor = true;
                    dp.Connect();

                    if (dp.Count == 0 || (dp.Count == 1 && m_datum != null && m_datum.ID != (dp.Get(0) as Place).ID))
                    {
                        duplicate = false;
                    }
                    else
                    {
                        var place = dp.Get(0) as Place;

                        var logger = new TextLogger(LogSeverity.Warning);
                        logger.Put("Duplication de données détectée.");
                        logger.Put("Elément trouvé:\n");
                        logger.Put("ID: {0}\n", place.ID);
                        logger.Put("Lieu: {0}\n", place.Name);
                        logger.Put("Pays: {0}", (m_cbCountries.SelectedItem as CountryListEntry).Country);
                        logger.Flush();
                    }
                }


            if (duplicate)
            {
                this.ShowWarning("La validation de  données a échouée. " +
                                 "Consultez le journal des événements pour plus d’informations.");
            }
            else
            {
                uint id    = (m_datum?.ID) ?? AppContext.TableManager.Places.CreateUniqID();
                var  place = new Place(id, name, idCtry);

                if (m_datum == null)
                {
                    m_ndxerPlaces.Source.Insert(place);
                    ClearForm();
                }
                else
                {
                    int ndx = m_ndxerPlaces.IndexOf(m_datum.ID);
                    m_ndxerPlaces.Source.Replace(ndx, place);

                    Close();
                }

                TextLogger.Info("Enregistrement réussi.");
            }
        }
示例#20
0
        void Save()
        {
            Assert(!InvokeRequired);

            string     name       = m_tbName.GetInputText();
            SubHeading subHeading = SubHeading.Parse(m_tbSubHeading.GetInputText());

            //is input ok?
            if (string.IsNullOrWhiteSpace(name) || subHeading == null)
            {
                this.ShowWarning("Champs mal servis. Veuillez compléter le formulaire.");

                if (string.IsNullOrWhiteSpace(name))
                {
                    m_tbName.SelectAll();
                }
                else
                {
                    m_tbSubHeading.Select();
                }

                return;
            }

            //any modif.?
            if (m_datum != null && name == m_datum.Name && subHeading.Value == m_datum.SubHeading.Value)
            {
                TextLogger.Info("Aucune modification détectée, enregistrement non-nécessaire.");
                Close();
                return;
            }


            //any duplicates?
            Predicate <IDatum> filter = d =>
            {
                var prod = d as Product;
                return(prod.SubHeading.Value == subHeading.Value &&
                       string.Compare(name, prod.Name, true) == 0 &&
                       (m_datum == null || m_datum.ID != prod.ID));
            };

            bool duplicate = true;

            using (var dp = new DatumProvider(m_ndxerProducts.Source, filter))
                using (new AutoReleaser(() => UseWaitCursor = false))
                {
                    UseWaitCursor = true;

                    dp.Connect();

                    if (dp.Count == 0)
                    {
                        duplicate = false;
                    }
                    else
                    {
                        Product prod = dp.Get(0) as Product;

                        var logger = new TextLogger(LogSeverity.Warning);
                        logger.Put("Duplication de données détectée.");
                        logger.Put("Elément trouvé:\n");
                        logger.Put("ID: {0}\n", prod.ID);
                        logger.Put("Pays: {0}\n", prod.Name);
                        logger.Put("Code: {0}", prod.SubHeading);
                        logger.Flush();
                    }
                }

            if (duplicate)
            {
                this.ShowWarning("La validation de  données a échouée. " +
                                 "Consultez le journal des événements pour plus d’informations.");
            }
            else
            {
                uint id   = (m_datum?.ID) ?? AppContext.TableManager.Products.CreateUniqID();
                var  prod = new Product(id, name, subHeading);

                if (m_datum == null)
                {
                    m_ndxerProducts.Source.Insert(prod);
                    ClearForm();
                }
                else
                {
                    int ndx = m_ndxerProducts.IndexOf(m_datum.ID);
                    m_ndxerProducts.Source.Replace(ndx, prod);

                    Close();
                }

                TextLogger.Info("Enregistrement réussi.");
            }
        }
示例#21
0
        public bool Check()
        {
            //contrainte 2
            var logger = new TextLogger(LogSeverity.Warning);

            logger.PutLine("*** Control d’intégrité ***");
            logger.PutLine($"Table: {AppContext.TableManager.Countries.Name}");
            logger.PutLine("La contrainte d’intégrité n° 2 est violée par les éléments suivants :");

            bool anyErr = false;

            //nom unique
            foreach (string name in m_ndxerName.Attributes)
            {
                IEnumerable <IDatum> countries = m_ndxerName.Get(name);

                if (countries.Count() > 1)
                {
                    logger.PutLine($"Noms identiques ({name}):");

                    foreach (Country c in countries)
                    {
                        logger.PutLine(c.ToString());
                    }

                    logger.PutLine();
                    anyErr = true;
                }
            }


            //code pays unique
            foreach (ushort code in m_ndxerInternalCode.Attributes)
            {
                IEnumerable <IDatum> countries = m_ndxerInternalCode.Get(code);

                if (countries.Count() > 1)
                {
                    logger.PutLine($"Codes pays identiques ({code}):");

                    foreach (Country c in countries)
                    {
                        logger.PutLine(c.ToString());
                    }

                    logger.PutLine();
                    anyErr = true;
                }
            }


            //iso code est nul ou unique
            foreach (string isoCode in  m_ndxerIsoCode.Attributes.Where(s => !string.IsNullOrWhiteSpace(s)))
            {
                IEnumerable <IDatum> countries = m_ndxerIsoCode.Get(isoCode);

                if (countries.Count() > 1)
                {
                    logger.PutLine($"Iso Codes identiques ({isoCode}):");

                    foreach (Country c in countries)
                    {
                        logger.PutLine(c.ToString());
                    }

                    logger.PutLine();
                    anyErr = true;
                }
            }


            if (anyErr)
            {
                logger.Flush();
            }

            return(!anyErr);
        }
示例#22
0
        void Save()
        {
            Assert(!InvokeRequired);


            /*
             * - Name required and not uniq
             * - Description and CountryID not required and both not uniq
             * */

            string name = m_tbName.GetInputText();

            //is input ok?
            if (string.IsNullOrWhiteSpace(name))
            {
                this.ShowWarning("Champs monétaire mal servi. Veuillez compléter le formulaire.");
                m_tbName.Select();

                return;
            }


            string descr  = m_tbDescription.GetInputText();
            uint   idCtry = m_cbCountries.SelectedIndex == 0 ? 0 : (m_cbCountries.SelectedItem as CountryListEntry).Country.ID;

            //any modif?
            if (m_datum != null && name == m_datum.Name && m_datum.Description == descr && idCtry == m_datum.CountryID)
            {
                TextLogger.Info("Aucune modification détectée, enregistrement non-nécessaire.");
                Close();

                return;
            }


            /*
             * - si idCtry == 0 => name doit etre unique
             * - sinon (name, idCtry) doit etre unique
             *
             *  #
             *  - checher name -> rows
             *  - si rows.Count = 0 => ok
             *  - si rows.Count = 1 et m_datum != null => ok
             *  - sinon
             *      - si idCtry = 0 => erreur
             *      - sinon
             *          - pour tout r dans rows
             *              - si r.CountryID = 0 ou r.CountryID == idCtry => erreur
             **/


            //any duplicate?
            bool duplicate = true;

            using (var ndxerNames = new AttrIndexer <string>(m_ndxerCurrencies.Source, d => (d as Currency).Name.ToUpper()))
                using (new AutoReleaser(() => UseWaitCursor = false))
                {
                    UseWaitCursor = true;
                    ndxerNames.Connect();
                    Currency[] rows = ndxerNames.Get(name.ToUpper()).Cast <Currency>().ToArray();

                    if (rows.Length == 0 || (rows.Length == 1 && m_datum != null && m_datum.ID == rows[0].ID))
                    {
                        duplicate = false;
                    }
                    else
                    {
                        var cncy = rows.First();

                        var logger = new TextLogger(LogSeverity.Warning);
                        logger.Put("Duplication de données détectée.");
                        logger.Put("Elément trouvé:\n");
                        logger.Put("ID: {0}\n", cncy.ID);
                        logger.Put("Monnaie: {0}\n", cncy.Name);
                        logger.Put("Pays ID: {0}\n", cncy.CountryID);
                        logger.Put("Description ISO: {0}", cncy.Description);
                        logger.Flush();
                    }
                }


            if (duplicate)
            {
                this.ShowWarning("La validation de  données a échouée. " +
                                 "Consultez le journal des événements pour plus d’informations.");
            }
            else
            {
                uint id   = (m_datum?.ID) ?? AppContext.TableManager.Currencies.CreateUniqID();
                var  cncy = new Currency(id, name, idCtry, descr);

                if (m_datum == null)
                {
                    AppContext.LogManager.LogUserActivity($"Action utilsateur: Ajout d'une monnaie: {cncy}");
                    m_ndxerCurrencies.Source.Insert(cncy);
                    ClearForm();
                }
                else
                {
                    AppContext.LogManager.LogUserActivity("Action utilsateur: Remplacement d'une monnaie: " +
                                                          $"ancienne valeur: {m_datum}, nouvelle valeur: {cncy}");

                    int ndx = m_ndxerCurrencies.IndexOf(m_datum.ID);
                    m_ndxerCurrencies.Source.Replace(ndx, cncy);

                    Close();
                }

                TextLogger.Info("Enregistrement réussi.");
            }
        }
示例#23
0
        void SaveDatum()
        {
            Assert(!InvokeRequired);

            /* - check that fields are filled
             * - in edit mode:
             *      - if no change then exit (case sensitive)
             *  - iterate through rows and check that:
             *      - Name, Code are uniq
             *      - if isoCode is set then it must be uniq
             *   - if no duplicate then save
             *   - otherwise inform
             * */

            string name    = m_tbName.GetInputText();
            var    code    = (ushort)m_nudInternalCode.Value;
            string isoCode = m_tbIsoCode.GetInputText();

            //input is ok?
            if (string.IsNullOrWhiteSpace(name) || code == 0)
            {
                string msg = "Certains champs sont mal servis. Veuillez compléter le formulaire.";
                MessageBox.Show(msg, null, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                if (string.IsNullOrWhiteSpace(name))
                {
                    m_tbName.SelectAll();
                }
                else
                {
                    m_nudInternalCode.Select();
                }

                return;
            }


            //are there any modif?
            if (m_datum != null && name == m_datum.Name && code == m_datum.InternalCode &&
                isoCode == m_datum.IsoCode)
            {
                TextLogger.Info("Aucune modification détectée, enregistrement non-nécessaire.");

                Close();
                return;
            }



            Predicate <IDatum> filter = d =>
            {
                var row = d as Country;

                return((row.InternalCode == code ||
                        string.Compare(name, row.Name, true) == 0 ||
                        (isoCode != "" && string.Compare(isoCode, row.IsoCode, true) == 0)) &&
                       (m_datum == null || m_datum.ID != row.ID));
            };



            bool duplicate = true;

            using (new AutoReleaser(() => UseWaitCursor = false))
                using (var dp = new DatumProvider(m_ndxerCountries.Source, filter))
                {
                    UseWaitCursor = true;
                    dp.Connect();

                    //any dupliacte data?
                    if (dp.Count == 0)
                    {
                        uint id = m_datum == null?AppContext.TableManager.Countries.CreateUniqID() : m_datum.ID;

                        var ctry = new Country(id, name, code, isoCode);

                        if (m_datum == null)
                        {
                            AppContext.LogManager.LogUserActivity($"Action utilisateur :  Ajout d’un pays: {ctry}");
                            m_ndxerCountries.Source.Insert(ctry);

                            m_tbIsoCode.Clear();
                            m_tbName.Clear();
                            m_nudInternalCode.Value = 0;
                            m_tbName.Select();
                        }
                        else
                        {
                            AppContext.LogManager.LogUserActivity("Action utilisateur :  Remplacement d’un pays: " +
                                                                  $"ancienne valeur: {m_datum}, nouvelle vaeur: {ctry}");

                            int ndx = m_ndxerCountries.IndexOf(id);
                            m_ndxerCountries.Source.Replace(ndx, ctry);
                            Close();
                        }

                        duplicate = false;
                    }


                    if (duplicate)
                    {
                        var logger = new TextLogger(LogSeverity.Warning);
                        logger.Put("Duplication de données détectée.");
                        logger.Put("Elément trouvé:\n");

                        foreach (Country ctry in dp.Enumerate())
                        {
                            logger.Put("ID: {0}\n", ctry.ID);
                            logger.Put("Pays: {0}\n", ctry.Name);
                            logger.Put("Code: {0}\n", ctry.InternalCode);
                            logger.Put("Code ISO: {0}", ctry.IsoCode);
                        }

                        logger.Flush();
                    }
                }


            if (duplicate)
            {
                MessageBox.Show("La validation de  données a échouée. " +
                                "Consultez le journal des événements pour plus d’informations.",
                                null,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
            }
            else
            {
                TextLogger.Info("Enregistrement réussi.");
            }
        }