示例#1
0
        static void DeleteFuzzyData(IDatumProvider dp, int[] indices)
        {
            if (MessageBox.Show(ASK_DELETE, "Confirmation requise",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                int nbDeleted = 0;

                try
                {
                    for (int i = indices.Length - 1; i >= 0; --i)
                    {
                        int    ndx   = indices[i];
                        IDatum datum = dp.Get(ndx);
                        var    item  = datum as ITaggedRow;
                        item.Disabled = true;
                        dp.Replace(ndx, datum);
                        ++nbDeleted;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                TextLogger.Info(string.Format("{0} élément(s) supprimé(s).", nbDeleted));
            }
        }
示例#2
0
        //protected:
        protected override void OnLoad(EventArgs e)
        {
            Opts.WindowPlacement wp = AppContext.Settings.UserSettings.WindowPlacement[OPT_KEY];

            if (wp != null)
            {
                Location = new Point(wp.Left, wp.Top);
            }
            else
            {
                int ScreenWidth = Screen.GetWorkingArea(this).Width;
                int x           = (ScreenWidth - Width) >> 1;

                Left = x > 0 ? x : 0;
                Top  = 0;
            }

            if (!AppContext.Settings.UserSettings.LogWindowHidden)
            {
                m_logWindow.Show(this);
            }

            TextLogger.Info($"Hub Governor version: {Assembly.GetExecutingAssembly().GetName().Version}");
            TextLogger.Info($"Version des données: {AppContext.Settings.AppSettings.DataGeneration}");

            base.OnLoad(e);
        }
示例#3
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();
            }
        }
示例#4
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.");
            }
        }
示例#5
0
        static void DeleteFarmedData(IDatumProvider dp, int[] indices)
        {
            if (MessageBox.Show(ASK_DELETE, "Confirmation requise",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                int nbDeleted = 0;

                try
                {
                    for (int i = indices.Length - 1; i >= 0; --i)
                    {
                        int ndx = indices[i];
                        dp.Delete(ndx);
                        ++nbDeleted;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                TextLogger.Info(string.Format("{0} élément(s) supprimé(s).", nbDeleted));
            }
        }
示例#6
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);
        }
        Message ProcessNewConnectionReq(Message msg)
        {
            Dbg.Assert(msg.MessageCode == Message_t.NewConnection);

            //TextLogger.Info("Réception d’une nouvelle requête  d’inscription.");

            var               ms     = new MemoryStream(msg.Data);
            var               reader = new RawDataReader(ms, Encoding.UTF8);
            ClientInfo        clInfo = ClientInfo.LoadClientInfo(reader);
            ClientEnvironment clEnv  = ClientEnvironment.Load(reader);

            byte[] data    = BitConverter.GetBytes(clInfo.ClientID);
            var    profile = m_ndxerProfiles.Get(clInfo.ProfileID) as UserProfile;

            string reqLog = $"Réception d'une demande d’inscription émanant  de {clInfo.ContactName}" +
                            $"(ID = {ClientStrID(clInfo.ClientID)}) pour " +
                            (profile == null ? "un profil inexistant." :
                             $"le profil {profile.Name}.");

            AppContext.LogManager.LogSysActivity(reqLog, true);


            //verifier que le profil existe
            if (profile == null)
            {
                AppContext.LogManager.LogSysActivity("Lancement de la procédure d’actualisation  " +
                                                     "de la liste des profils sur le serveur", true);

                ProcessProfilesChange();
                return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.InvalidProfile, data));
            }


            //verifier que ClientID n'existe pas
            var clSameID = m_ndxerClients.Get(clInfo.ClientID) as HubClient;

            if (clSameID != null)
            {
                AppContext.LogManager.LogSysActivity("Collision d’identifiants: " +
                                                     $"un client portant le même ID est déjà enregistré ({clSameID.ContactName}). " +
                                                     "Exiger au client de reformuler son inscription avec un nouvel ID", true);
                return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.InvalidID, data));
            }


            //verifier que le profile est en mode auto
            ManagementMode_t prfMgmntMode = GetProfileManagementMode(clInfo.ProfileID);

            if (prfMgmntMode == ManagementMode_t.Manual)
            {
                AppContext.LogManager.LogSysActivity("Profil en gestion manuelle, inscription rejetée.", true);
                return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.Rejected, data));
            }


            TextLogger.Info("Profil en gestion automatique.");
            TextLogger.Info("Enregistrement du client...");


            //desactiver l'ancien client actif si il existe
            var oldClient = GetProfileEnabledClient(clInfo.ProfileID);

            if (oldClient != null)
            {
                if (IsClientRunning(oldClient.ID))
                {
                    //rejeter l'inscription

                    AppContext.LogManager.LogSysActivity($"Un client pour le profil {profile.Name} est déjà en cours d’exécution. " +
                                                         "Inscription rejetée", true);

                    return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.Rejected, data));
                }


                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;
                oldClStatus.Status = ClientStatus_t.Disabled;
                int ndx = m_ndxerClientsStatus.IndexOf(oldClStatus.ID);
                m_ndxerClientsStatus.Source.Replace(ndx, oldClStatus);


                //maj des fichiers de dialogue de old client
                string       filePath = AppPaths.GetSrvDialogFilePath(oldClient.ID);
                ClientDialog clDlg    = new ClientDialog(oldClient.ID, ClientStatus_t.Disabled, Enumerable.Empty <Message>());
                DialogEngin.WriteSrvDialog(filePath, clDlg);
                AddUpload(Names.GetSrvDialogFile(oldClient.ID));
            }


            //creer le fichier dialogue
            string srvDlgPath = AppPaths.GetSrvDialogFilePath(clInfo.ClientID);

            DialogEngin.WriteSrvDialog(srvDlgPath, new ClientDialog(clInfo.ClientID,
                                                                    ClientStatus_t.Enabled, Enumerable.Empty <Message>()));
            DialogEngin.WriteHubDialog(AppPaths.GetClientDilogFilePath(clInfo.ClientID),
                                       clInfo.ClientID, Enumerable.Empty <Message>());

            try
            {
                new NetEngin(AppContext.Settings.NetworkSettings).Upload(Urls.DialogDirURL,
                                                                         new string[] { AppPaths.GetClientDilogFilePath(clInfo.ClientID), AppPaths.GetSrvDialogFilePath(clInfo.ClientID) });
            }
            catch (Exception ex)
            {
                AppContext.LogManager.LogSysError($"Traitement de la requête d'inscription du client {ClientStrID(clInfo.ClientID)}: " +
                                                  $"{ ex.Message}. demande ignorée, laisser le client reformuler la requête", true);

                return(null);    // let the cleint retry req.
            }


            //maj la table des clients
            var hClient = new HubClient(clInfo.ClientID, clInfo.ProfileID)
            {
                ContaclEMail = clInfo.ContaclEMail,
                ContactName  = clInfo.ContactName,
                ContactPhone = clInfo.ContactPhone,
            };

            m_ndxerClients.Source.Insert(hClient);


            //maj du status client
            var clStatus = new ClientStatus(clInfo.ClientID, ClientStatus_t.Enabled);

            m_ndxerClientsStatus.Source.Insert(clStatus);

            //maj du client env
            UpdateClientEnvironment(clInfo.ClientID, clEnv);


            //maj du dict des clients actifs
            m_onlineClients.Add(clInfo.ClientID);
            AppContext.LogManager.StartLogger(clInfo.ClientID);
            AppContext.LogManager.LogClientActivity(clInfo.ClientID, "Inscription");
            ClientStarted?.Invoke(clInfo.ClientID);


            AppContext.LogManager.LogSysActivity($"Inscription du client {clInfo.ClientID} terminée", true);
            TextLogger.Info("Inscription réussie. :-)");
            return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.Ok, data));
        }
示例#8
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);
            }
        }
示例#9
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.");
            }
        }
示例#10
0
文件: DatumView.cs 项目: Adel-dz/Hub
        void InsertColumns()
        {
            Assert(!InvokeRequired);

            IDataColumn[]  colHeader = m_dataProvider.DataSource.Columns;
            ColumnHeader[] columns   = new ColumnHeader[colHeader.Length];

            for (int i = 0; i < columns.Length; ++i)
            {
                columns[i] = new ColumnHeader()
                {
                    Text      = colHeader[i].Caption,
                    TextAlign = HorizontalAlignment.Center,
                    Tag       = colHeader[i].DataType,
                }
            }
            ;

            m_lvData.Columns.AddRange(columns);
        }

        void InsertItems(ListViewEntry[] items)
        {
            Assert(!InvokeRequired);

            m_lvData.Items.AddRange(items);

            TextLogger.Info("\nNbre d'enregistrements {0}.", m_dataProvider.Count);
        }

        void LoadDataAsync()
        {
            Func <ListViewEntry[]> loadData = () =>
            {
                ConnectProvider();
                return(LoadItems());
            };


            var waitClue = new Waits.WaitClue(this);

            Action <Task <ListViewEntry[]> > onError = t =>
            {
                Exception ex = t.Exception.InnerException;
                TextLogger.Error(ex.Message);

                waitClue.LeaveWaitMode();


                if (ex is CorruptedStreamException == false)
                {
                    ex = new CorruptedStreamException(innerException: ex);
                }

                throw ex;
            };


            Action <Task <ListViewEntry[]> > onSuccess = t =>
            {
                InsertColumns();

                ListViewEntry[] items = t.Result;
                InsertItems(items);
                waitClue.LeaveWaitMode();

                m_tslblStatus.Text = $"Nombre d'neregistrements: {m_lvData.Items.Count}";
            };


            waitClue.EnterWaitMode();

            var loading = new Task <ListViewEntry[]>(loadData, TaskCreationOptions.LongRunning);

            loading.ContinueWith(onSuccess,
                                 CancellationToken.None,
                                 TaskContinuationOptions.OnlyOnRanToCompletion,
                                 TaskScheduler.FromCurrentSynchronizationContext());

            loading.ContinueWith(onError, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted,
                                 TaskScheduler.FromCurrentSynchronizationContext());

            loading.Start();
        }

        IColumnSorter SorterFactory(int ndxColumn)
        {
            var           dataType = (ColumnDataType_t)m_lvData.Columns[ndxColumn].Tag;
            IColumnSorter sorter   = null;

            switch (dataType)
            {
            case ColumnDataType_t.Text:
                sorter = new TextColumnSorter(ndxColumn);
                break;

            case ColumnDataType_t.Integer:
                sorter = new IntegerColumnSorter(ndxColumn);
                break;

            case ColumnDataType_t.Float:
                sorter = new FloatColumnSorter(ndxColumn);
                break;

            case ColumnDataType_t.Time:
                sorter = new TimeColumnSorter(ndxColumn);
                break;
            }

            Assert(sorter != null);

            return(sorter);
        }
示例#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
文件: 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.");
                }
            }
        }