Example #1
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();
            }
        }
Example #2
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.");
            }
        }
Example #3
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);
            }
        }
Example #4
0
        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.");
            }
        }
Example #5
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.");
            }
        }
Example #6
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.");
            }
        }
Example #7
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.");
            }
        }
Example #8
0
        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.");
                }
            }
        }