示例#1
0
        /// <summary>
        /// Processes the import button event.
        /// </summary>
        protected void DoImport()
        {
            // save current MetaDataContext
            MetaDataContext currentContext = OrderContext.MetaDataContext;

            try
            {
                string filePath = SelectedFilePath;

                if (String.IsNullOrEmpty(filePath))
                {
                    throw new Exception("No selected file.");
                }

                // import taxes
                try
                {
                    _ImportExport.ImportExportProgressMessage += new Mediachase.Commerce.Orders.ImportExport.TaxImportExportProgressMessageHandler(ImportExport_ImportExportProgressMessage);

                    // perform import operation
                    _ImportExport.Import(SelectedFilePath, GetCurrentApplicationId(), null, ',');

                    SelectedFilePath = null;
                }
                catch (Mediachase.Commerce.Orders.ImportExport.OrdersImportExportException ex)
                {
                    throw ex;
                }
                catch (Exception ex1)
                {
                    throw ex1;
                }
                finally
                {
                }
            }
            catch (Exception ex)
            {
                ProgressControl1.AddProgressMessageText(ex.Message, true, -1);
            }
            finally
            {
            }
        }
示例#2
0
        public void OrderSystem_ImportTax()
        {
            #region Keep existing taxes
            // Keep track of existing taxes
            Dictionary <int, int> existing      = new Dictionary <int, int>();
            List <int>            existingTaxes = new List <int>();
            TaxDto taxDto;
            foreach (TaxType taxType in Enum.GetValues(typeof(TaxType)))
            {
                taxDto = TaxManager.GetTaxDto(taxType);

                for (int i = 0; i < taxDto.Tax.Count; i++)
                {
                    existingTaxes.Add(taxDto.Tax[i].TaxId);
                    existing.Add(existing.Count, taxDto.Tax[i].TaxId);
                }
            }
            int totalExisting = existing.Count;
            #endregion

            // TODO: Connect to an online source to update contents

            // Import sample tax configurations from sample CSV file
            // TODO: Figure out why import does not work if there are existing taxes that
            //        match the taxes in CSV file.
            TaxImportExport tie = new TaxImportExport();
            tie.Import("TaxCSVSample2.csv", AppContext.Current.ApplicationId, CMSContext.Current.SiteId, ',');

            #region Delete imported taxes
            // Delete imported tax configurations, but keep pre-existing taxes. Works fine.
            foreach (TaxType taxType in Enum.GetValues(typeof(TaxType)))
            {
                taxDto = TaxManager.GetTaxDto(taxType);

                #region Foreach version

                /*
                 * TaxDto copy = (TaxDto)taxDto.Copy();
                 * foreach (TaxDto.TaxRow taxRow in copy.Tax)
                 * {
                 *  if (existing.ContainsValue(taxRow.TaxId))
                 *      continue;
                 *  else
                 *  {
                 *      TaxDto.TaxRow real = TaxManager.GetTax(taxRow.TaxId).Tax[0];
                 *      real.Delete();
                 *      TaxManager.SaveTax(taxDto);
                 *  }
                 * }
                 */
                #endregion

                // Delete code copied from OrderDeleteHandler.ProcessDeleteCommand(...)
                for (int i = 0; i < taxDto.Tax.Count; i++)
                {
                    if (existing.ContainsValue(taxDto.Tax[i].TaxId))
                    {
                        continue;
                    }
                    else
                    {
                        taxDto.Tax[i].Delete();
                        TaxManager.SaveTax(taxDto);
                        i--;
                    }
                }
            }
            #endregion
        }