Beispiel #1
0
        public SpotValueForm(IDatumProvider srcValues, IDatum datum)
        {
            Assert(datum is SpotValue);
            Assert(srcValues != null);

            InitializeComponent();

            m_nudPrice.Maximum = decimal.MaxValue;

            m_ndxerValues = new KeyIndexer(srcValues);
            m_spotValue   = datum as SpotValue;

            m_nudPrice.DecimalPlaces = AppContext.Settings.AppSettings.PriceDecimalPlaces;

            ConnectAsync();

            m_nudPrice.Value    = (decimal)m_spotValue.Price;
            m_dtpSpotTime.Value = m_spotValue.SpotTime;

            m_nudPrice.TextChanged += delegate { UpdateUI(); };
            m_tsbReload.Click      += delegate
            {
                m_nudPrice.Value    = (decimal)m_spotValue.Price + 1; //si m_nudPrice.Value == m_spotValue.Price l'affichage
                m_nudPrice.Value    = (decimal)m_spotValue.Price;     // n'est pas mis a jour
                m_dtpSpotTime.Value = m_spotValue.SpotTime;
            };

            m_tsbSave.Click += delegate { Save(); };

            m_ndxerValues.DatumDeleted  += FreezeDialog;
            m_ndxerValues.DatumReplaced += FreezeDialog;
        }
Beispiel #2
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();
            }
        }