Пример #1
0
        void NormalizeAppUpdates(AppUpdate update)
        {
            KeyIndexer ndxer = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.APP_UPDATE);

            var seq = from AppUpdate up in ndxer.Source.Enumerate()
                      where up.AppArchitecture == update.AppArchitecture && up.Version.CompareTo(update.Version) > 0
                      select up;

            if (seq.Any())
            {
                update.DeployTime = AppUpdate.NEVER;
            }
            else
            {
                seq = from AppUpdate up in ndxer.Source.Enumerate()
                      where up.AppArchitecture == update.AppArchitecture &&
                      up.Version.CompareTo(update.Version) <= 0 &&
                      up.DeployTime == AppUpdate.NOT_YET
                      select up;

                foreach (AppUpdate up in seq.ToArray())
                {
                    var datum = new AppUpdate(up.ID, up.Version, up.AppArchitecture, up.CreationTime);
                    datum.DeployTime = AppUpdate.NEVER;
                    int ndx = ndxer.IndexOf(up.ID);
                    ndxer.Source.Replace(ndx, datum);
                }
            }
        }
Пример #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();
            }
        }
Пример #3
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.");
            }
        }
Пример #4
0
        private void UploadDataUpdates_Click(object sender, EventArgs e)
        {
            var dlg = new Jobs.ProcessingDialog();

            Action upload = () =>
            {
                KeyIndexer         ndxerInc = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.INCREMENT);
                IEnumerable <uint> ids      = from UpdateIncrement inc in ndxerInc.Source.Enumerate()
                                              where inc.IsDeployed == false
                                              select inc.ID;

                var netEngin = new NetEngin(AppContext.Settings.NetworkSettings);

                foreach (var id in ids)
                {
                    string fileName = id.ToString("X");
                    string src      = Path.Combine(AppPaths.DataUpdateFolder, fileName);
                    string dst      = Urls.DataUpdateDirURL + fileName;
                    netEngin.Upload(dst, src);
                }

                netEngin.Upload(Urls.DataManifestURL, AppPaths.DataManifestPath);
                netEngin.Upload(Urls.ManifestURL, AppPaths.ManifestPath);

                foreach (uint id in ids)
                {
                    var inc = ndxerInc.Get(id) as UpdateIncrement;
                    inc.DeployTime = DateTime.Now;
                    ndxerInc.Source.Replace(ndxerInc.IndexOf(id), inc);
                }
            };

            Action <Task> onErr = t =>
            {
                dlg.Dispose();
                this.ShowError(t.Exception.InnerException.Message);
            };

            Action onSuccess = () =>
            {
                dlg.Dispose();
                m_tsbUploadDataUpdates.Enabled = false;
            };

            var task = new Task(upload, TaskCreationOptions.LongRunning);

            task.OnSuccess(onSuccess);
            task.OnError(onErr);

            task.Start();
            dlg.ShowDialog(Parent);
        }
Пример #5
0
        public void SetProfileManagementMode(uint idProfile, ManagementMode_t mode)
        {
            var mgmntMode = m_ndxerProfilesMgmnt.Get(idProfile) as ProfileManagementMode;

            Dbg.Assert(mgmntMode != null);

            if (mgmntMode.ManagementMode != mode)
            {
                AppContext.LogManager.LogSysActivity($"Mode de gestion du profil {idProfile} changé vers " +
                                                     $"{ProfileManagementMode.GetManagementModeName(mode)}", true);

                mgmntMode.ManagementMode = mode;
                int ndx = m_ndxerProfilesMgmnt.IndexOf(idProfile);
                m_ndxerProfilesMgmnt.Source.Replace(ndx, mgmntMode);
            }
        }
Пример #6
0
        public void DeleteClient(uint clID)
        {
            //remove client from running clients queue if present
            using (m_onlineClients.Lock())
                if (m_onlineClients.Contains(clID))
                {
                    m_onlineClients.Remove(clID);
                    ClientClosed?.Invoke(clID);
                    AppContext.LogManager.CloseLogger(clID);
                }

            // delete: env
            uint[] ids = (from HubClientEnvironment env in m_ndxerClientsEnv.Source.Enumerate()
                          where env.ClientID == clID
                          select env.ID).ToArray();

            for (int i = ids.Length - 1; i >= 0; --i)
            {
                int ndx = m_ndxerClientsEnv.IndexOf(ids[i]);
                m_ndxerClientsEnv.Source.Delete(ndx);
                AppContext.LogManager.LogSysActivity($"Environnement du client {ClientsManager.ClientStrID(clID)} supprimé");
            }


            //delete status
            int ndxStatus = m_ndxerClientsStatus.IndexOf(clID);

            if (ndxStatus >= 0)
            {
                m_ndxerClientsStatus.Source.Delete(ndxStatus);
                AppContext.LogManager.LogSysActivity($"Status du client {ClientsManager.ClientStrID(clID)} supprimé");
            }

            //delete client.
            int ndxClient = m_ndxerClients.IndexOf(clID);

            m_ndxerClients.Source.Delete(ndxClient);
            AppContext.LogManager.LogSysActivity($"Client {ClientsManager.ClientStrID(clID)} supprimé");
        }
Пример #7
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);
        }
Пример #8
0
        public void SetClientStatus(HubClient client, ClientStatus_t status)
        {
            //basculer le mode de gestion des profil vers manuel
            //SetProfileManagementMode(client.ProfileID , ManagementMode_t.Manual);

            //desactiver le client
            HubClient oldClient = GetProfileEnabledClient(client.ProfileID);

            if (status == ClientStatus_t.Enabled && oldClient != null && oldClient.ID != client.ID)
            {
                AppContext.LogManager.LogSysActivity($"Désactivation du client {ClientStrID(oldClient.ID)}", true);

                //maj la table des status clients
                var oldClStatus = m_ndxerClientsStatus.Get(oldClient.ID) as ClientStatus;
                int ndx         = m_ndxerClientsStatus.IndexOf(oldClient.ID);

                oldClStatus.Status = ClientStatus_t.Disabled;
                m_ndxerClientsStatus.Source.Replace(ndx, oldClStatus);

                string oldClFilePath = AppPaths.GetSrvDialogFilePath(oldClient.ID);

                try
                {
                    ClientDialog oldClDlg = DialogEngin.ReadSrvDialog(oldClFilePath);
                    oldClDlg.ClientStatus = ClientStatus_t.Disabled;
                    DialogEngin.WriteSrvDialog(oldClFilePath, oldClDlg);
                }
                catch (Exception ex)
                {
                    AppContext.LogManager.LogSysError($"Lecture du fichier dialogue du client {ClientStrID(oldClient.ID)}" +
                                                      ex.Message);

                    DialogEngin.WriteSrvDialog(oldClFilePath,
                                               new ClientDialog(oldClient.ID, ClientStatus_t.Disabled, Enumerable.Empty <Message>()));
                }
                finally
                {
                    AddUpload(Names.GetSrvDialogFile(oldClient.ID));
                }
            }


            //maj la table des statuts clients
            int ndxStatus = m_ndxerClientsStatus.IndexOf(client.ID);
            var clStatus  = m_ndxerClientsStatus.Get(client.ID) as ClientStatus;

            clStatus.Status = status;
            m_ndxerClientsStatus.Source.Replace(ndxStatus, clStatus);

            string filePath = AppPaths.GetSrvDialogFilePath(client.ID);

            try
            {
                ClientDialog clDlg = DialogEngin.ReadSrvDialog(filePath);
                clDlg.ClientStatus = status;
                DialogEngin.WriteSrvDialog(filePath, clDlg);
            }
            catch (Exception ex)
            {
                AppContext.LogManager.LogSysError($"Lecture du fichier dialogue du client {ClientStrID(client.ID)}" +
                                                  ex.Message);

                DialogEngin.WriteSrvDialog(filePath,
                                           new ClientDialog(client.ID, status, Enumerable.Empty <Message>()));
            }
            finally
            {
                AddUpload(Names.GetSrvDialogFile(client.ID));
            }
        }
Пример #9
0
        private void UploadAppUpdates_Click(object sender, EventArgs e)
        {
            var filesNames = new Dictionary <AppArchitecture_t, string>
            {
                { AppArchitecture_t.Win7SP1, WIN7SP1_UPDATE_FILENAME },
                { AppArchitecture_t.Win7SP1X64, WIN7SP1X64_UPADTE_FILENAME },
                { AppArchitecture_t.WinXP, WINXP_UPADTE_FILENAME }
            };


            var waitDlg = new Jobs.ProcessingDialog();


            Action run = () =>
            {
                KeyIndexer ndxer = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.APP_UPDATE);

                var seq = (from AppUpdate up in ndxer.Source.Enumerate()
                           where up.DeployTime == AppUpdate.NOT_YET
                           select up).ToArray();

                //maj app manifest + manifest global
                Dictionary <AppArchitecture_t, string> appManifest;

                try
                {
                    appManifest = UpdateEngin.ReadAppManifest(AppPaths.AppManifestPath);
                }
                catch (Exception ex)
                {
                    TextLogger.Warning(ex.Message);
                    appManifest = new Dictionary <AppArchitecture_t, string>();
                }



                IUpdateManifest gManifest;

                try
                {
                    gManifest = UpdateEngin.ReadUpdateManifest(AppPaths.ManifestPath);
                }
                catch (Exception ex)
                {
                    TextLogger.Warning(ex.Message);
                    gManifest = new UpdateManifest(0, 0);
                }



                var netEngin = new NetEngin(AppContext.Settings.NetworkSettings);

                foreach (AppUpdate up in seq)
                {
                    gManifest.Versions[up.AppArchitecture] = up.Version;
                    appManifest[up.AppArchitecture]        = filesNames[up.AppArchitecture];

                    string srcFileName  = up.ID.ToString("X");
                    string destFileName = filesNames[up.AppArchitecture];
                    string dst          = Urls.AppUpdateDirURL + destFileName;

                    waitDlg.Message = $"Transfert du fichier {destFileName}. Cette opération peut durer plusieurs minutes.";
                    netEngin.Upload(dst, Path.Combine(AppPaths.AppUpdateFolder, srcFileName));
                    up.DeployTime = DateTime.Now;

                    ndxer.Source.Replace(ndxer.IndexOf(up.ID), up);
                }

                waitDlg.Message = "Transfert du manifest des applications...";
                UpdateEngin.WriteAppManifest(AppPaths.AppManifestPath, appManifest);
                netEngin.Upload(Urls.AppManifestURL, AppPaths.AppManifestPath);

                waitDlg.Message = "Transfert du manifest global...";
                UpdateEngin.WriteUpdateManifest(gManifest, AppPaths.ManifestPath);
                netEngin.Upload(Urls.ManifestURL, AppPaths.ManifestPath);
            };


            Action onSucces = () =>
            {
                m_tsbUploadAppUpdates.Enabled = false;
                waitDlg.Dispose();
            };

            Action <Task> onErr = t =>
            {
                waitDlg.Dispose();
                this.ShowError(t.Exception.InnerException.Message);
                TextLogger.Error(t.Exception.InnerException.Message);
            };


            var task = new Task(run, TaskCreationOptions.LongRunning);

            task.OnSuccess(onSucces);
            task.OnError(onErr);
            task.Start();

            waitDlg.ShowDialog(this);
        }
Пример #10
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.");
            }
        }
Пример #11
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.");
            }
        }
Пример #12
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.");
            }
        }
Пример #13
0
        private void DeleteProfile_Click(object sender, EventArgs e)
        {
            List <UserProfile> profiles = (from ListViewItem lvi in m_lvData.SelectedItems
                                           select lvi.Tag as UserProfile).ToList();


            int initCount = profiles.Count;

            using (IDatumProvider dpClients = AppContext.TableManager.HubClients.DataProvider)
            {
                dpClients.Connect();

                foreach (HubClient hc in dpClients.Enumerate())
                {
                    int ndx = profiles.FindIndex(p => p.ID == hc.ProfileID);

                    if (ndx >= 0)
                    {
                        profiles.RemoveAt(ndx);
                    }
                }



                if (profiles.Count() == 0)
                {
                    const string msg = "Tous les profiles sélectionnés pour la suppression " +
                                       "sont associés à des clients. " +
                                       "Pour supprimer un profile celui-ci ne doit être associé à aucun client.";

                    MessageBox.Show(msg, Text);
                    return;
                }

                if (initCount != profiles.Count)
                {
                    const string msg = "Certains profiles candidats à la suppression sont associés " +
                                       "à des clients. Ceux-ci ne seront pas supprimés. Voulez-vous poursuivre ?";

                    if (MessageBox.Show(msg, Text, MessageBoxButtons.YesNo) != DialogResult.Yes)
                    {
                        return;
                    }
                }
            }

            const string msgContinue = "Veuillez confirmer la suppression. Poursuivre ?";

            if (MessageBox.Show(msgContinue, Text, MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }


            foreach (IDataRow row in profiles)
            {
                int ndx = m_ndxerProfiles.IndexOf(row.ID);
                m_dpProfiles.Delete(ndx);

                //sup. le mode gestion
                m_ndxerMgmntMode.Source.Delete(m_ndxerMgmntMode.IndexOf(row.ID));
            }


            TextLogger.Info($"{profiles.Count()} profiles(s) supprimé(s).");
        }
Пример #14
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.");
            }
        }
Пример #15
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.");
                }
            }
        }