Ejemplo n.º 1
0
        Product ParseProduct(int ndxRow)
        {
            string[] row           = m_srcData[ndxRow];
            int      colName       = m_colMapping[ColumnKey_t.LabelFr];
            int      colSubHeading = m_colMapping[ColumnKey_t.SubHeading];

            //parsing
            string     name = AdjustInput(row[colName]);
            SubHeading sh   = SubHeading.Parse(row[colSubHeading].Trim());

            if (string.IsNullOrWhiteSpace(name) || sh == null)
            {
                return(null);
            }

            Product prod = FindProduct(sh, name);

            if (prod == null)
            {
                prod = new Product(AppContext.TableManager.Products.CreateUniqID(), name, sh);

                Assert(!m_pendingData.ContainsKey(AppContext.TableManager.Products.ID));
                m_pendingData[AppContext.TableManager.Products.ID] = prod;
            }

            return(prod);
        }
Ejemplo n.º 2
0
        //handlers:
        private void Search_Click(object sender , EventArgs e)
        {
            var subHeading = SubHeading.Parse(m_tbSubHeading.Text);

            if (subHeading == null)
            {
                MessageBox.Show(Parent , "Contenu ou format de la sous-position tarifaire incorrect." , null , MessageBoxButtons.OK ,
                    MessageBoxIcon.Error);
                return;
            }

            DateTime date = m_dtpSpotDate.Value;
            var ict = m_cbIncoterm.SelectedItem as Incoterm;
            var ctry = (m_cbOrigin.SelectedItem as CountryEntry).Country;

            SearchAsyncSubHeading(subHeading , date , ict , ctry);
        }
Ejemplo n.º 3
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.");
            }
        }