示例#1
0
        public BomCleanup(ConfigurationElementBom bomConfig, BomPopulations populatedOutput)
        {
            _populatedOutput = populatedOutput;
            _bomConfig       = bomConfig;

            foreach (ConfigurationElementColumn evaluateColumn in _bomConfig.ColumnCollection)
            {
                ConfigurationElementColumn value = null;
                foreach (BomDataColumn checkColumn in populatedOutput.PopulatedDataTable.Columns)
                {
                    if (evaluateColumn.Order == checkColumn.Ordinal && !checkColumn.ColumnName.Equals(evaluateColumn.Name))
                    {
                        value                      = new ConfigurationElementColumn();
                        value.Name                 = checkColumn.ColumnName;
                        value.Order                = evaluateColumn.Order;
                        value.Output               = checkColumn.OutputName;
                        value.Override             = evaluateColumn.Override;
                        value.Required             = evaluateColumn.Required;
                        value.PopulationCollection = evaluateColumn.PopulationCollection;
                        value.CleanupCollection    = evaluateColumn.CleanupCollection;
                        value.DataType             = evaluateColumn.DataType;
                        value.Delimiter            = evaluateColumn.Delimiter;
                        value.Enabled              = evaluateColumn.Enabled;
                        value.Header               = checkColumn.HeaderName;
                        value.IdentifierOrder      = evaluateColumn.IdentifierOrder;
                        value.IsQuantity           = evaluateColumn.IsQuantity;
                        value.IsSplit              = evaluateColumn.IsSplit;
                        break;
                    }
                }

                if (value == null)
                {
                    value = evaluateColumn;
                }

                if (value.CleanupCollection.Count > 0)
                {
                    _columnsWithCleanup.Add(value);
                }
                if (value.IdentifierOrder != -1)
                {
                    _columnsForIdentifier.Add(value.IdentifierOrder, evaluateColumn);
                }
            }

            PerformCleanup();
        }
        public void FormatBom()
        {
            string outputFilePath = Path.Combine(_formatterConfiguration.OutputFolderPath, _productNumberModel.ProductNumber + "-output");

            outputFilePath = Path.GetFullPath(Path.ChangeExtension(outputFilePath, Properties.Resources.OUTPUTFILE_EXTENTION));

            ConfigurationElementBom selectedBomConfig = _formatterConfiguration.BomConfiguration.BomCollection[_selectedBom];

            string inputFilePath = Path.Combine(_formatterConfiguration.InputFolderPath, _productNumberModel.ProductNumber);

            inputFilePath = Path.GetFullPath(Path.ChangeExtension(inputFilePath, selectedBomConfig.InputFileExtention));

            if (!File.Exists(inputFilePath))
            {
                throw new FileNotFoundException("File not found: " + inputFilePath + "\nMake sure the directory configurations are correct and that the files are named correctly and located in the right directory.");
            }

            try {
                File.OpenWrite(outputFilePath).Close();
            } catch (Exception) {
                throw new FileNotFoundException("Unable to open file: " + outputFilePath + "\nCheck to see if you have it open.");
            }

            Stopwatch s = new Stopwatch();

            s.Start();

            while (Bootstrapper.GetExcelInstance() == null && s.ElapsedMilliseconds < 10000)
            {
                ;
            }

            s.Stop();

            if (Bootstrapper.GetExcelInstance() == null)
            {
                throw new ArgumentNullException("Unable to open instance of excel.");
            }

            Bootstrapper.ClearOpenWorkbooks();

            BomInput  bomInput  = new BomInput(_productNumberModel, _formatterConfiguration.InputFolderPath, selectedBomConfig.InputFileExtention, selectedBomConfig);
            BomOutput bomOutput = new BomOutput(Bootstrapper.GetExcelInstance(), bomInput, selectedBomConfig, _formatterConfiguration);

            new BomLoad(selectedBomConfig, bomInput, bomOutput);
            BomPopulations bomPopulations = new BomPopulations(bomOutput, selectedBomConfig);
            BomCleanup     bomCleanup     = new BomCleanup(selectedBomConfig, bomPopulations);

            bomOutput.CopyDataToExcel();

            WindowManager windowManager = new WindowManager();

            Collection <TreeViewItem> items = bomCleanup.OutputResults();

            dynamic settings = new ExpandoObject();

            settings.WindowStyle   = WindowStyle.None;
            settings.ShowInTaskbar = false;
            settings.Title         = "Cleanup Results";

            bomOutput.SaveWorkbook();

            BomFormatCleanUpReportPopUpViewModel cleanupViewModel = new BomFormatCleanUpReportPopUpViewModel(items);

            windowManager.ShowDialog(new PopUpViewModel(cleanupViewModel), null, settings);

            Bootstrapper.GetExcelInstance().Visible = true;
        }