Beispiel #1
0
        /// <summary>
        /// Wandelt ein FilterSet der Datenbank in eine Instanz von FilterSetModel um
        /// </summary>
        /// <param name="filterSet">DataModel.FilterSet</param>
        /// <returns>FilterSetModel</returns>
        public static FilterSetModel getFilterSetModelFromFilterSet(FilterSet filterSet)
        {
            if (filterSet == null)
            {
                return(null);
            }

            IEnumerable <Filter> filters = Filter.GetFilters(null, filterSet.FilterSetID);

            // Name des FilterSets
            FilterSetModel filterSetModel = new FilterSetModel(filterSet.Linking);

            filterSetModel.name = filterSet.Name;

            // füge diesem filterSet alle filter hinzu
            foreach (var filter in filters)
            {
                FilterModel filterModel = new FilterModel();
                // konvertiere die strings aus der datenbank in enums
                filterModel.group     = (FilterModel.Groups)Enum.Parse(typeof(FilterModel.Groups), filter.Table);
                filterModel.criterion = (FilterModel.Criterions)Enum.Parse(typeof(FilterModel.Criterions), filter.Type);
                filterModel.operation = (FilterModel.Operations)Enum.Parse(typeof(FilterModel.Operations), filter.Operation);
                filterModel.value     = SafeStringParser.safeParseToStr(filter.Value);
                filterSetModel.filterList.Add(filterModel);
            }
            return(filterSetModel);
        }
Beispiel #2
0
        /// <summary>
        /// Wandelt ein FilterSet der Datenbank in eine Instanz von FilterSetModel um
        /// </summary>
        /// <param name="filterSet">DataModel.FilterSet</param>
        /// <returns>FilterSetModel</returns>
        public static FilterSetModel getFilterSetModelFromFilterSet(FilterSet filterSet)
        {
            if (filterSet == null)
                return null;

            IEnumerable<Filter> filters = Filter.GetFilters(null, filterSet.FilterSetID);

            // Name des FilterSets
            FilterSetModel filterSetModel = new FilterSetModel(filterSet.Linking);
            filterSetModel.name = filterSet.Name;

            // füge diesem filterSet alle filter hinzu
            foreach (var filter in filters)
            {
                FilterModel filterModel = new FilterModel();
                // konvertiere die strings aus der datenbank in enums
                filterModel.group = (FilterModel.Groups)Enum.Parse(typeof(FilterModel.Groups), filter.Table);
                filterModel.criterion = (FilterModel.Criterions)Enum.Parse(typeof(FilterModel.Criterions), filter.Type);
                filterModel.operation = (FilterModel.Operations)Enum.Parse(typeof(FilterModel.Operations), filter.Operation);
                filterModel.value = SafeStringParser.safeParseToStr(filter.Value);
                filterSetModel.filterList.Add(filterModel);
            }
            return filterSetModel;
        }
Beispiel #3
0
        /// <summary>
        /// Erzeugt neues Filter-Datenbankobjekt anhand einer formletter_pattern-ID
        /// </summary>
        /// <param name="patternID"></param>
        public FormletterPatternModelDB(int patternID)
        {
            filterSetModels = new List <FilterSetModel>();
            //formletterTableAssignments = new List<FormletterTableAssignment>();
            formletterColumnCsvDocumentAssignments = new List <FormletterColumnCsvDocumentAssignment>();

            // Lese zurück
            IList <FormletterPattern> patterns = FormletterPattern.GetFormletterPatterns(patternID).ToList <FormletterPattern>();

            // Es gibt genau einen formletterPattern
            FormletterPattern pattern = patterns[0];

            // Strings füllen
            this.name                = SafeStringParser.safeParseToStr(pattern.Name);
            this.saluation_m         = SafeStringParser.safeParseToStr(pattern.SaluationM);
            this.saluation_f         = SafeStringParser.safeParseToStr(pattern.SaluationF);
            this.saluation_n         = SafeStringParser.safeParseToStr(pattern.SaluationNT);
            this.formletter_filename = SafeStringParser.safeParseToStr(pattern.FileName);
            this.csv_filename        = SafeStringParser.safeParseToStr(pattern.FileName).Replace(".odt", ".csv");
            this.letterText          = SafeStringParser.safeParseToStr(pattern.Text);

            // pattern ID
            pID = pattern.FormletterPatternID;

            // füge diesem formletterPattern alle filterSets hinzu
            IEnumerable <FilterSet> filterSets = FilterSet.GetFilterSets(null, pID);

            foreach (var set in filterSets)
            {
                // Hole die IDs alle Filter dieses FilterSets
                int fsID = set.FilterSetID;
                IEnumerable <Filter> filters = Filter.GetFilters(null, fsID);

                // Name des FilterSets
                FilterSetModel filterSetModel = new FilterSetModel(set.Linking);
                filterSetModel.name = set.Name;

                // füge diesem filterSet alle filter hinzu
                foreach (var filter in filters)
                {
                    FilterModel filterModel = new FilterModel();
                    // konvertiere die strings aus der datenbank in enums
                    filterModel.group     = (FilterModel.Groups)Enum.Parse(typeof(FilterModel.Groups), filter.Table);
                    filterModel.criterion = (FilterModel.Criterions)Enum.Parse(typeof(FilterModel.Criterions), filter.Type);
                    filterModel.operation = (FilterModel.Operations)Enum.Parse(typeof(FilterModel.Operations), filter.Operation);
                    filterModel.value     = SafeStringParser.safeParseToStr(filter.Value);
                    filterSetModel.filterList.Add(filterModel);
                }

                filterSetModels.Add(filterSetModel);
            }

            // Füge alle Spaltenverknüpfungen hinzu
            IEnumerable <ColumnAssignment> assignments = ColumnAssignment.GetColumnAssignments(null, pID);

            foreach (var assignment in assignments)
            {
                string csvCol  = SafeStringParser.safeParseToStr(assignment.CsvColumn);
                string dbTable = SafeStringParser.safeParseToStr(assignment.DatabaseTable);
                string dbCol   = SafeStringParser.safeParseToStr(assignment.DatabaseColumn);

                // parse diese strings in ihre Enum-Äquivalente
                FormletterTableAssignment.Groups eDbTable = (FormletterTableAssignment.Groups)Enum.Parse(typeof(FormletterTableAssignment.Groups), dbTable);
                FormletterTableAssignment.Fields eDbCol   = (FormletterTableAssignment.Fields)Enum.Parse(typeof(FormletterTableAssignment.Fields), dbCol);

                // erstelle eine enum-basierte tabellen-spalten-verknüpfung damit
                FormletterTableAssignment fta = new FormletterTableAssignment(eDbTable, eDbCol);

                // jetzt haben wir ein komplettes csv-datenbank-spaltenverknüpfungs-objekt
                FormletterColumnCsvDocumentAssignment colAssignment = new FormletterColumnCsvDocumentAssignment(csvCol, fta);

                this.formletterColumnCsvDocumentAssignments.Add(colAssignment);
            }
        }
        /// <summary>
        /// Erzeugt neues Filter-Datenbankobjekt anhand einer formletter_pattern-ID
        /// </summary>
        /// <param name="patternID"></param>
        public FormletterPatternModelDB(int patternID)
        {
            filterSetModels = new List<FilterSetModel>();
            //formletterTableAssignments = new List<FormletterTableAssignment>();
            formletterColumnCsvDocumentAssignments = new List<FormletterColumnCsvDocumentAssignment>();

            // Lese zurück
            IList<FormletterPattern> patterns = FormletterPattern.GetFormletterPatterns(patternID).ToList<FormletterPattern>();

            // Es gibt genau einen formletterPattern
            FormletterPattern pattern = patterns[0];

            // Strings füllen
            this.name = SafeStringParser.safeParseToStr(pattern.Name);
            this.saluation_m = SafeStringParser.safeParseToStr(pattern.SaluationM);
            this.saluation_f = SafeStringParser.safeParseToStr(pattern.SaluationF);
            this.saluation_n = SafeStringParser.safeParseToStr(pattern.SaluationNT);
            this.formletter_filename = SafeStringParser.safeParseToStr(pattern.FileName);
            this.csv_filename = SafeStringParser.safeParseToStr(pattern.FileName).Replace(".odt", ".csv");
            this.letterText = SafeStringParser.safeParseToStr(pattern.Text);

            // pattern ID
            pID = pattern.FormletterPatternID;

            // füge diesem formletterPattern alle filterSets hinzu
            IEnumerable<FilterSet> filterSets = FilterSet.GetFilterSets(null, pID);
            foreach (var set in filterSets)
            {
                // Hole die IDs alle Filter dieses FilterSets
                int fsID = set.FilterSetID;
                IEnumerable<Filter> filters = Filter.GetFilters(null, fsID);

                // Name des FilterSets
                FilterSetModel filterSetModel = new FilterSetModel(set.Linking);
                filterSetModel.name = set.Name;

                // füge diesem filterSet alle filter hinzu
                foreach (var filter in filters)
                {
                    FilterModel filterModel = new FilterModel();
                    // konvertiere die strings aus der datenbank in enums
                    filterModel.group = (FilterModel.Groups)Enum.Parse(typeof(FilterModel.Groups), filter.Table);
                    filterModel.criterion = (FilterModel.Criterions)Enum.Parse(typeof(FilterModel.Criterions), filter.Type);
                    filterModel.operation = (FilterModel.Operations)Enum.Parse(typeof(FilterModel.Operations), filter.Operation);
                    filterModel.value = SafeStringParser.safeParseToStr(filter.Value);
                    filterSetModel.filterList.Add(filterModel);
                }

                filterSetModels.Add(filterSetModel);
            }

            // Füge alle Spaltenverknüpfungen hinzu
            IEnumerable<ColumnAssignment> assignments = ColumnAssignment.GetColumnAssignments(null, pID);
            foreach (var assignment in assignments)
            {
                string csvCol = SafeStringParser.safeParseToStr(assignment.CsvColumn);
                string dbTable = SafeStringParser.safeParseToStr(assignment.DatabaseTable);
                string dbCol = SafeStringParser.safeParseToStr(assignment.DatabaseColumn);

                // parse diese strings in ihre Enum-Äquivalente
                FormletterTableAssignment.Groups eDbTable = (FormletterTableAssignment.Groups)Enum.Parse(typeof(FormletterTableAssignment.Groups), dbTable);
                FormletterTableAssignment.Fields eDbCol = (FormletterTableAssignment.Fields)Enum.Parse(typeof(FormletterTableAssignment.Fields), dbCol);

                // erstelle eine enum-basierte tabellen-spalten-verknüpfung damit
                FormletterTableAssignment fta = new FormletterTableAssignment(eDbTable, eDbCol);

                // jetzt haben wir ein komplettes csv-datenbank-spaltenverknüpfungs-objekt
                FormletterColumnCsvDocumentAssignment colAssignment = new FormletterColumnCsvDocumentAssignment(csvCol, fta);

                this.formletterColumnCsvDocumentAssignments.Add(colAssignment);
            }
        }
 /// <summary>
 /// alle Felder und Listen zurücksetzen
 /// </summary>
 public void resetEverything()
 {
     this.clearForm();
     listBox2.Items.Clear();
     allFilterSets = new List<FilterSetModel>();
     currentFilterSet = null;
     listBox1.IsEnabled = false;
     btDeleteButton.IsEnabled = false;
     saveFilterSet.IsEnabled = false;
     tbName.Clear();
 }
        /// <summary>
        /// FilterSet speichern
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveFilterSet_Click(object sender, RoutedEventArgs e)
        {
            // Prüfe ob für das Statistiken/Listen-Modul
            if (this.useForListModule && string.IsNullOrEmpty(tbName.Text))
            {
                MessageBoxEnhanced.Error(IniParser.GetSetting("FORMLETTER", "noSetNameSpecified"));
                return;
            }

            // Keine leeren Filtersets zulassen
            if (!(listBox1.Items.Count > 0))
                return;

            // Lese Filter aus Filter-Liste
            foreach (var subitem in listBox1.Items)
            {
                currentFilterSet.addFilter( subitem as FilterModel );
            }

            // Wenn nicht für Listen-Modul, lege FilterSet im Speicher ab
            if (!this.useForListModule)
                allFilterSets.Add(currentFilterSet);

            // Für das Listen/Statistiken-Modul wird das FilterSet direkt in die Datenbank gespeichert
            if (this.useForListModule)
            {
                string name = tbName.Text;
                try
                {
                    int filterSetID = FilterSet.Add(name, currentFilterSet.linkingType);

                    // Bearbeite alle Filter zu jedem Set
                    foreach (var filter in currentFilterSet.filterList)
                    {
                        string table = filter.group.ToString();
                        string type = filter.criterion.ToString();
                        string operation = filter.operation.ToString();
                        string value = filter.value;
                        int filterID = Filter.Add(filterSetID, table, type, operation, value);
                    }
                }
                catch
                {
                }
            }

            listBox1.IsEnabled = false;
            listBox2.IsEnabled = true;
            btDeleteSetButton.IsEnabled = true;
            refreshListBoxWithAllFilterSets();
            currentFilterSet = null;
            clearForm();
            tbName.Clear();
            deactivateForm();
        }
        /// <summary>
        /// FilterSet aus FilterSet-Liste rechts löschen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteFromFilterSetList_Click(object sender, RoutedEventArgs e)
        {
            FilterSetModel filterSet = listBox2.SelectedItem as FilterSetModel;

            if (filterSet != null)
            {
                listBox2.Items.Remove(listBox2.SelectedItem);
                this.allFilterSets.Remove(filterSet);

                if (listBox2.Items.Count == 0)
                {
                    listBox2.IsEnabled = false;
                    btDeleteSetButton.IsEnabled = false;
                }

                listBox1.IsEnabled = false;
                refreshListBoxWithAllFilterSets();
                currentFilterSet = null;
                clearForm();
                tbName.Clear();
                deactivateForm();
            }
        }
        /// <summary>
        /// ODER-Verknüpftes FilterSet initialisieren
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addFilterSetOR(object sender, RoutedEventArgs e)
        {
            if (this.useForListModule)
                if (string.IsNullOrEmpty(tbName.Text))
                {
                    MessageBoxEnhanced.Error(IniParser.GetSetting("FILTER", "errorFilterSet"));
                    return;
                }

            currentFilterSet = new FilterSetModel(IniParser.GetSetting("FILTER", "defaultOrString"));

            if (this.useForListModule)
                currentFilterSet.name = tbName.Text;

            clearForm();
            activateForm();
            lbLinking.Content = IniParser.GetSetting("FILTER", "defaultOrString");
        }