Beispiel #1
0
        private void InitialiseScreenComponents()
        {
            DefinitionFiles = new ObservableCollection <ListBoxPair>();
            DefinitionFiles.Add(new ListBoxPair {
                Key = "0", Value = "(Select a definition)"
            });

            foreach (var file in CSVConvertorFileManagement.GetDefinitionFiles(CSVAppFolderMapping, ".xml"))
            {
                DefinitionFiles.Add(new ListBoxPair(file, file));
            }

            DefinitionFileList.DisplayMemberPath = "Value";
            DefinitionFileList.SelectedValuePath = "Key";
            DefinitionFileList.ItemsSource       = DefinitionFiles;

            DefinitionFileList.SelectedIndex = 0;

            MappingFiles = new ObservableCollection <ListBoxPair>();
            MappingFiles.Add(new ListBoxPair {
                Key = "0", Value = "(Select a mapping)"
            });

            foreach (var file in CSVConvertorFileManagement.GetMappingFiles(CSVAppFolderMapping, ".xml"))
            {
                MappingFiles.Add(new ListBoxPair(file, file));
            }
            MappingFileList.DisplayMemberPath = "Value";
            MappingFileList.SelectedValuePath = "Key";
            MappingFileList.ItemsSource       = MappingFiles;

            MappingFileList.SelectedIndex = 0;

            SetFilterSelectors();
        }
Beispiel #2
0
        private void SaveCurrentMapping(string mappingFileName)
        {
            // TO DO - set drop down/mapping file values

            MappingDefinition currentMappingDefinition = new MappingDefinition();

            currentMappingDefinition.DefinitionFile     = ((ListBoxPair)DefinitionFileList.SelectedItem).Value;
            currentMappingDefinition.CompanyName        = CompanyNameTextBox.Text.Trim();
            currentMappingDefinition.MappingFilters     = MappingFilterList;
            currentMappingDefinition.RequiresLevel2File = checkBoxLevel2.IsChecked ?? false;
            currentMappingDefinition.RequiresOptOutFile = checkBoxOptOut.IsChecked ?? false;
            currentMappingDefinition.CanHaveErrorFile   = checkBoxErrorFile.IsChecked ?? false;


            MappingField mappingField = new MappingField();

            for (int idx = 0; idx < SampleHeaderRow.Count(); idx++)
            {
                mappingField             = new MappingField();
                mappingField.SampleID    = idx + 1;
                mappingField.SampleField = SampleHeaderRow[idx];
                mappingField.SampleValue = SampleDataRow[idx];
                var item = MappingSettingList[idx];
                mappingField.MiddlewareFieldIdentifier = item.Key;

                currentMappingDefinition.MappingFields.Add(mappingField);
            }

            CSVConvertorFileManagement.SaveMappingFile(currentMappingDefinition, mappingFileName, CSVAppFolderMapping, ".xml");
        }
Beispiel #3
0
        private void SetupDefinitionList()
        {
            if (DefinitionFileList.SelectedIndex > 0)
            {
                DefinitionFileNameTextBox.Text = ((ListBoxPair)DefinitionFileList.SelectedItem).Value;
                //  load from file
                DefinitionFields = new ObservableCollection <MiddlewareField>(CSVConvertorFileManagement.ReadDefinitionFile(DefinitionFileNameTextBox.Text, CSVAppFolderOptions, ".xml"));
            }
            else
            {
                DefinitionFileNameTextBox.Text = string.Empty;
                DefinitionFields = new ObservableCollection <MiddlewareField>();
            }

            definitionListBox.ItemsSource       = DefinitionFields;
            definitionListBox.DisplayMemberPath = "Description";
            definitionListBox.SelectedValuePath = "MiddlewareFieldID";


            //  if clicked then either new or already loaded
            //  so enable edit panels
            FieldListPanel.IsEnabled        = true;
            FieldListButtonsPanel.IsEnabled = true;
            SetEditButtonsToDefaultState();
        }
Beispiel #4
0
        private void LoadMiddlewareDefinition(string definitionFile)
        {
            List <MiddlewareField> middlewareFields = CSVConvertorFileManagement.ReadDefinitionFile(definitionFile, CSVAppFolderMapping, ".xml");

            DefinitionFields = new ObservableCollection <ListBoxPair>(middlewareFields.Select(x => new ListBoxPair {
                Key = x.MiddlewareFieldIdentifier, Value = x.Description
            }));
        }
Beispiel #5
0
        private void InitialiseScreenComponents()
        {
            //  definition files combo
            // load existing file list

            List <ListBoxPair> definitionFilePairs = new List <ListBoxPair>();

            definitionFilePairs.Add(new ListBoxPair("0", "(new)"));

            foreach (var file in CSVConvertorFileManagement.GetDefinitionFiles(CSVAppFolderOptions, ".xml"))
            {
                definitionFilePairs.Add(new ListBoxPair(file, file));
            }

            DefinitionFileList.DisplayMemberPath = "Value";
            DefinitionFileList.SelectedValuePath = "Key";

            DefinitionFileList.ItemsSource = definitionFilePairs;

            //  field type combo
            var datatTypeList = EnumExtractor.GetValueFromDescription <MiddlewareDataType>();

            FieldTypeSelector.ItemsSource       = datatTypeList;
            FieldTypeSelector.DisplayMemberPath = "Value";
            FieldTypeSelector.SelectedValuePath = "Key";

            //  special types combo
            var specialTypeList = EnumExtractor.GetValueFromDescription <MiddlewareSpecialType>();

            SpecialTypeSelector.ItemsSource       = specialTypeList;
            SpecialTypeSelector.DisplayMemberPath = "Value";
            SpecialTypeSelector.SelectedValuePath = "Key";

            var fixedValueList = EnumExtractor.GetValueFromDescription <MiddlewareFixedValue>();

            FixedValueSelector.ItemsSource       = fixedValueList;
            FixedValueSelector.DisplayMemberPath = "Value";
            FixedValueSelector.SelectedValuePath = "Key";

            //  panels
            FieldListButtonsPanel.IsEnabled = false;
            FieldItemsPanel.IsEnabled       = false;

            //  buttons
            EditCreateFieldsButton.IsEnabled = false;

            //  field items
            ClearFieldItemsPanel();

            definitionListBox.ItemsSource  = null;
            DefinitionFileNameTextBox.Text = string.Empty;

            // variables
            DefinitionFields = new ObservableCollection <MiddlewareField>();
        }
        private bool LoadCSVPayrollFile(string fileName, bool firstRowHasHeaders)
        {
            CSVDataIn = CSVConvertorFileManagement.LoadCSVFile(fileName, firstRowHasHeaders);

            if (CSVDataIn == null)
            {
                MessageBox.Show("Error reading CSV file");
                return(false);
            }

            return(true);
        }
Beispiel #7
0
 private void SaveCurrentDefinitionList(string definitionFileName)
 {
     for (int idx = 0; idx < DefinitionFields.Count(); idx++)
     {
         // reset the IDs
         DefinitionFields[idx].MiddlewareFieldID = idx + 1;
         if (DefinitionFields[idx].MiddlewareFieldIdentifier == string.Empty)
         {
             DefinitionFields[idx].MiddlewareFieldIdentifier = string.Format("ID{0:0000}", DefinitionFields[idx].MiddlewareFieldID);
         }
     }
     CSVConvertorFileManagement.SaveDefinitionFile(DefinitionFields.ToList(), definitionFileName, CSVAppFolderOptions, ".xml");
 }
        private void UpdateLevel2File(string level2File)
        {
            List <List <string> > level2Data = CSVConvertorFileManagement.LoadCSVFile(level2File, true);

            if (level2Data == null)
            {
                MessageBox.Show("Error reading level 2 file");
                return;
            }
            CurrentMappingDefinition.Level2Records        = level2Data;
            CurrentMappingDefinition.DateLevel2LastLoaded = DateTime.Now;

            return;

            //
        }
        private void loadSelectedFile_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog();

            // Set filter for file extension and default file extension
            fileDialog.DefaultExt       = ".csv";
            fileDialog.Filter           = "CSV files (*.csv)|*.csv|Text files (*.txt)|*.txt";
            fileDialog.CheckFileExists  = true;
            fileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            Nullable <bool> result = fileDialog.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                MessageBox.Show("No file loaded");
                return;
            }

            string fileName = fileDialog.FileName;

            switch (FileTypeForLoading)
            {
            case FileTypeForLoading.Level2:
                UpdateLevel2File(fileName);
                break;

            case FileTypeForLoading.OptOutNew:
                UpdateOptoutFile(fileName, true);
                break;

            case FileTypeForLoading.OptOutChanges:
                UpdateOptoutFile(fileName, false);
                break;

            case FileTypeForLoading.Errors:
                UpdateErrorFile(fileName);
                break;

            case FileTypeForLoading.None:
                return;
            }

            // save updated mapping file and update screen
            CSVConvertorFileManagement.SaveMappingFile(CurrentMappingDefinition, CurrentMappingFilename, CSVAppFolder, ".xml");
            SetAdditionFileDisplay(CurrentMappingDefinition);
        }
        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);
            }
        }
        private int ConvertCSVFile(string csvFileName, bool firstRowHasHeaders)
        {
            // initialise
            DefinitionFields = CSVConvertorFileManagement.ReadDefinitionFile(CurrentMappingDefinition.DefinitionFile, CSVAppFolder, ".xml");
            MappingFilters   = CurrentMappingDefinition.MappingFilters;

            // load CSV file
            if (!LoadCSVPayrollFile(csvFileName, firstRowHasHeaders))
            {
                return(-1);
            }

            CSVDataOut = new List <List <string> >();

            MakeHeaderRow();
            string excludeField = Properties.Settings.Default.Level2ExcludeField;

            MakeCSVBody(excludeField);

            return(WriteCSVFile());
        }
Beispiel #13
0
        private void DeleteFieldListButton_Click(object sender, RoutedEventArgs e)
        {
            if (DefinitionFileNameTextBox.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Please set the name of the definition set to delete");
                return;
            }

            if (MessageBox.Show("Are you sure you want to delete this definition", "Delete definition file", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                if (CSVConvertorFileManagement.DeleteDefinitionFile(DefinitionFileNameTextBox.Text.Trim(), CSVAppFolderOptions, ".xml"))
                {
                    MessageBox.Show("Definition deleted");
                    InitialiseScreenComponents();
                }
                else
                {
                    MessageBox.Show("Error deleting definition file");
                }
            }
        }
Beispiel #14
0
        private void DeleteSelectedMapping()
        {
            //  load from file
            if (MappingFileList.SelectedIndex < 1)
            {
                MessageBox.Show("No mapping selected");
                return;
            }

            if (MessageBox.Show("Are you sure you want to delete this mapping", "Delete mapping file", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                if (CSVConvertorFileManagement.DeleteMappingFile(((ListBoxPair)MappingFileList.SelectedItem).Value, CSVAppFolderMapping, ".xml"))
                {
                    MessageBox.Show("Mapping deleted");
                    InitialiseScreenComponents();
                }
                else
                {
                    MessageBox.Show("Error deleting mapping");
                }
            }
        }
        private void InitialiseScreenComponents()
        {
            CSVConvertorFileManagement.CreateWorkingFolder(CSVAppFolder);

            MappingFiles = new ObservableCollection <ListBoxPair>();
            MappingFiles.Add(new ListBoxPair {
                Key = "0", Value = "(Select a mapping)"
            });

            foreach (var file in CSVConvertorFileManagement.GetMappingFiles(CSVAppFolder, ".xml"))
            {
                MappingFiles.Add(new ListBoxPair(file, file));
            }
            MappingFileList.DisplayMemberPath = "Value";
            MappingFileList.SelectedValuePath = "Key";
            MappingFileList.ItemsSource       = MappingFiles;

            MappingFileList.SelectedIndex = 0;

            ManagementPanel.Visibility     = Visibility.Hidden;
            AdditionalFilePanel.Visibility = Visibility.Hidden;

            loadSelectedFile.IsEnabled = false;
        }
Beispiel #16
0
 private void ImportMappingButton_Click(object sender, RoutedEventArgs e)
 {
     MessageBox.Show(CSVConvertorFileManagement.ImportMappingFile(CSVAppFolderMapping));
     InitialiseScreenComponents();
 }
 private void ImportMappingsFile_Click(object sender, RoutedEventArgs e)
 {
     MessageBox.Show(CSVConvertorFileManagement.ImportMappingFile(CSVAppFolder));
 }
Beispiel #18
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();
        }
Beispiel #19
0
        private void ImportFieldListButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(CSVConvertorFileManagement.ImportDefinitionFile(CSVAppFolderOptions));

            InitialiseScreenComponents();
        }