private void MappingFileList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (MappingFileList.SelectedIndex >= 1)
            {
                CurrentMappingFilename = ((ListBoxPair)MappingFileList.SelectedItem).Value;

                CurrentMappingDefinition = CSVConvertorFileManagement.ReadMappingFile(CurrentMappingFilename, CSVAppFolder, ".xml");
                if (CurrentMappingDefinition.HasAdditionalFile)
                {
                    SetAdditionFileDisplay(CurrentMappingDefinition);
                    AdditionalFilePanel.Visibility = Visibility.Visible;
                }
                else
                {
                    AdditionalFilePanel.Visibility = Visibility.Hidden;
                    //textBlockAdditionalFileStatus.Text = string.Empty;
                }
            }
        }
        private void ConvertFile_Click(object sender, RoutedEventArgs ev)
        {
            //  check everything is ready, file to process, destination and mapping file
            if (OriginalFileName == string.Empty || !File.Exists(OriginalFile.Text.Trim()))
            {
                MessageBox.Show("Please select a file to process");
                return;
            }

            if (MappingFileList.SelectedIndex < 1)
            {
                MessageBox.Show("Please select a mapping");
                return;
            }

            string temp = DestinationLocation.Text.Trim();

            if (temp == string.Empty || !Directory.Exists(temp))
            {
                MessageBox.Show("Please select a destination location");
                return;
            }

            CurrentMappingDefinition = CSVConvertorFileManagement.ReadMappingFile(((ListBoxPair)MappingFileList.SelectedItem).Value, CSVAppFolder, ".xml");

            // finally, check mapping file for level 2 records
            if (CurrentMappingDefinition.RequiresLevel2File && CurrentMappingDefinition.Level2Records.Count() == 0)
            {
                MessageBox.Show("There are no level 2 records loaded");
                return;
            }

            int rowsProcessed = ConvertCSVFile(OriginalFile.Text.Trim(), FirstRowHeadersCheckBox.IsChecked ?? false);

            if (rowsProcessed < 0)
            {
                return;
            }
            {
                MessageBox.Show("Processing complete, rows output: " + rowsProcessed);
            }
        }
Beispiel #3
0
        private void SetupExistingMapping()
        {
            //  load from file
            if (MappingFileList.SelectedIndex < 1)
            {
                MessageBox.Show("No mapping selected");
                return;
            }
            MappingDefinition mappingDefinition = CSVConvertorFileManagement.ReadMappingFile(((ListBoxPair)MappingFileList.SelectedItem).Value, CSVAppFolderMapping, ".xml");

            // file/combo settings
            MappingNameTextBox.Text          = ((ListBoxPair)MappingFileList.SelectedItem).Value;
            DefinitionFileList.SelectedValue = mappingDefinition.DefinitionFile;

            LoadMiddlewareDefinition(mappingDefinition.DefinitionFile);
            MappingSettingList = new ObservableCollection <ListBoxPair>();
            ListBoxPair listBoxPair               = new ListBoxPair();
            int         mappingFieldID            = 0;
            string      middlewareFieldIdentifier = string.Empty;

            SampleHeaderRow = new List <string>();
            SampleDataRow   = new List <string>();

            foreach (MappingField mappingField in mappingDefinition.MappingFields)
            {
                int idx = mappingField.SampleID;
                //  set sample value and restore Sample and Header arrays
                SampleHeaderRow.Add(mappingField.SampleField);
                SampleDataRow.Add(mappingField.SampleValue);


                middlewareFieldIdentifier = mappingField.MiddlewareFieldIdentifier;

                listBoxPair = new ListBoxPair();
                if (Int32.TryParse(mappingField.MiddlewareFieldIdentifier, out mappingFieldID))
                {
                    //  convention is that unset mapping has negative integer ID
                    // if mapping set then delete from DefintionFields and Add to MappingFields
                    listBoxPair = new ListBoxPair(((idx + 1) * -1).ToString(), "-");
                }
                else
                {
                    // or set actual mapping and remove from definition list
                    listBoxPair = DefinitionFields.FirstOrDefault(x => x.Key == middlewareFieldIdentifier);
                    DefinitionFields.Remove(listBoxPair);
                }
                MappingSettingList.Add(listBoxPair);
            }


            SetDefinitionListBox();
            SetMappingList();
            ClearFilterSettings();
            DisplaySampleFile();
            SetFilterFieldNames();

            CompanyNameTextBox.Text = mappingDefinition.CompanyName;
            MappingFilterList       = mappingDefinition.MappingFilters;

            checkBoxLevel2.IsChecked    = mappingDefinition.RequiresLevel2File;
            checkBoxOptOut.IsChecked    = mappingDefinition.RequiresOptOutFile;
            checkBoxErrorFile.IsChecked = mappingDefinition.CanHaveErrorFile;

            DisplayCurrentFilterList();

            SetScrollViewer();
        }