Exemplo n.º 1
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.");
            }
        }
Exemplo n.º 2
0
        public DataSuppliersForm(IDatumProvider srcSupplier, IDatum datum)
        {
            Assert(srcSupplier != null);
            Assert(datum != null);
            Assert(datum is DataSupplier);

            InitializeComponent();

            m_datum          = datum as DataSupplier;
            m_ndxerSuppliers = new KeyIndexer(AppContext.TableManager.Suppiers.DataProvider);

            //handlers
            m_ndxerSuppliers.DatumDeleted  += SuppliersIndexer_DatumChanged;
            m_ndxerSuppliers.DatumReplaced += SuppliersIndexer_DatumChanged;
            m_tbName.TextChanged           += delegate { UpdateUI(); };
            m_tsbReload.Click += delegate { FillForm(); };
            m_tsbSave.Click   += Save_Click;

            FillForm();
            ConnectAsync();
        }