Esempio n. 1
0
        private void ShowMatchFieldsDialog(string tableName)
        {
            Project project = page.GetProject();

            List<string> selectedFields = new List<string>();
            foreach(Field field in SelectedFields)
            {
                selectedFields.Add(field.Name);
            }

            Dictionary<string, string> fieldColumnNamePairs = new Dictionary<string, string>();

            foreach (KeyValuePair<string, int> kvp in ddlField.PairAssociated)
            {
                Field fieldById = page.view.GetFieldById(kvp.Value);
                fieldColumnNamePairs.Add(fieldById.Name, kvp.Key);
            }

            MatchFieldsDialog dialog = new MatchFieldsDialog
                (
                MainForm,
                project,
                tableName,
                selectedFields,
                ddlField.TextColumnName,
                fieldColumnNamePairs);

            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string valueTableName = tableName.ToString() + "value";

                fieldSetupTable = new DataTable(tableName);
                fieldSetupTable.Columns.Add(fieldName, dialog.PrimaryColumnData.GetType());
                fieldValueSetupTable = new DataTable(valueTableName);

                if (project.CollectedData.TableExists(tableName))
                {
                    fieldValueSetupTable = project.GetTableData(tableName, dialog.PrimaryColumnData.ToString());
                }

                newCodeTable = new DataTable();
                newCodeTable = fieldValueSetupTable.Clone();
                newCodeTable.Clear();

                if (newCodeTable.Columns.Count > 0)
                {
                    newCodeTable.Columns.RemoveAt(0);
                }

                newCodeTable.Columns.Add(fieldName, dialog.PrimaryColumnData.GetType());

                foreach (DataRow row in fieldValueSetupTable.Rows)
                {
                    DataRow rowToAdd = newCodeTable.NewRow();
                    rowToAdd[0] = row[0];
                    newCodeTable.Rows.Add(rowToAdd);
                }

                kvPairs = dialog.Codes;

                System.Collections.ArrayList codeColumns = new System.Collections.ArrayList();
                string columnNames = string.Empty;

                foreach (KeyValuePair kvPair in kvPairs)
                {
                    codeColumns.Add(kvPair.Value);
                    columnNames += kvPair.Value.ToString() + StringLiterals.COMMA;
                }

                if (columnNames.Length > 1)
                {
                    columnNames = columnNames.Substring(0, (columnNames.Length - 1));
                }

                sourceTableName = tableName;
                textColumnName = dialog.PrimaryColumnData;

                if (Mode == CreationMode.CreateNewFromExisting)
                {
                    textColumnName = fieldName;

                    string[] comma = { "," };
                    string column = string.Empty;

                    foreach (KeyValuePair kvPair in kvPairs)
                    {
                        column += kvPair.Key.ToString() + StringLiterals.COMMA;
                    }

                    if (column.Length > 1)
                    {
                        column = column.Substring(0, (column.Length - 1));
                    }

                    string[] columns = column.Split(comma, StringSplitOptions.None);

                    for (int i = 0; i < columns.Length; i++)
                    {
                        newCodeTable.Columns.Add(columns[i]);
                    }

                    string columnNamesForValues = string.Empty;

                    foreach (KeyValuePair kvPair in kvPairs)
                    {
                        columnNamesForValues += kvPair.Value.ToString() + StringLiterals.COMMA;
                    }

                    if (columnNamesForValues.Length > 1)
                    {
                        columnNamesForValues = columnNamesForValues.Substring(0, (columnNamesForValues.Length - 1));
                    }

                    string newTableColumnName = string.Empty;
                    string existingColumnName = string.Empty;

                    foreach (DataColumn dataColumnOfNewTable in newCodeTable.Columns)
                    {
                        newTableColumnName = dataColumnOfNewTable.ColumnName;

                        foreach (KeyValuePair kvPair in kvPairs)
                        {
                            if(kvPair.Key == newTableColumnName)
                            {
                                existingColumnName = kvPair.Value;
                                break;
                            }
                        }

                        if (string.IsNullOrEmpty(existingColumnName) == false)
                        {
                            for (int i = 0; i < codeTable.Rows.Count; i++)
                            {
                                newCodeTable.Rows[i][newTableColumnName] = codeTable.Rows[i][existingColumnName];
                            }
                        }
                    }

                    sourceTableName = GetNewCodeTableName(FieldName);
                    newCodeTable.TableName = sourceTableName;
                    codeTable = newCodeTable;
                }
                else
                {
                    relateCondition = string.Empty;

                    foreach (KeyValuePair kvPair in kvPairs)
                    {
                        relateCondition = relateCondition.Length > 0 ? relateCondition + "," : relateCondition;
                        int fieldId = this.page.Fields[kvPair.Key].Id;
                        relateCondition = string.Format("{0}{1}:{2}", relateCondition, kvPair.Value, fieldId);
                    }
                }

                dialog.Close();
                DisplayData();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Builds the command text
        /// </summary>		
        protected override void GenerateCommand()
        {
            Configuration config = Configuration.GetNewInstance();
            KeyValuePairCollection kvPairs = new KeyValuePairCollection();
            kvPairs.Delimiter = CharLiterals.SPACE;

            if ((settingsPanel.RepresentationOfYes != config.Settings.RepresentationOfYes) || (hasYesAsChanged))
            {
                kvPairs.Add(new KeyValuePair(ShortHands.YES, Util.InsertInDoubleQuotes(settingsPanel.RepresentationOfYes)));
            }
            if ((settingsPanel.RepresentationOfNo != config.Settings.RepresentationOfNo) || (hasNoAsChanged))
            {
                kvPairs.Add(new KeyValuePair(ShortHands.NO, Util.InsertInDoubleQuotes(settingsPanel.RepresentationOfNo)));
            }
            if ((settingsPanel.RepresentationOfMissing != config.Settings.RepresentationOfMissing) || (hasMissingAsChanged))
            {
                kvPairs.Add(new KeyValuePair(ShortHands.MISSING, Util.InsertInDoubleQuotes(settingsPanel.RepresentationOfMissing)));
            }
            if ((settingsPanel.ShowGraphics != config.Settings.ShowGraphics) || (hasShowGraphicChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.FREQGRAPH,
                    Epi.Util.GetShortHand(settingsPanel.ShowGraphics)));
            }
            if ((settingsPanel.ShowHyperlinks != config.Settings.ShowHyperlinks) || (hasShowHyperlinkChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.HYPERLINKS,
                    Epi.Util.GetShortHand(settingsPanel.ShowHyperlinks)));
            }
            if ((settingsPanel.ShowPercents != config.Settings.ShowPercents) || (hasShowPercentsChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.PERCENTS,
                    Epi.Util.GetShortHand(settingsPanel.ShowPercents)));
            }
            if ((settingsPanel.ShowSelectCriteria != config.Settings.ShowSelection) || (hasShowSelectChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.SELECT,
                    Epi.Util.GetShortHand(settingsPanel.ShowSelectCriteria)));
            }
            if ((settingsPanel.ShowPrompt != config.Settings.ShowCompletePrompt) || (hasShowPromptChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.SHOWPROMPTS,
                    Epi.Util.GetShortHand(settingsPanel.ShowPrompt)));
            }
            if ((settingsPanel.ShowTablesOutput != config.Settings.ShowTables) || (hasShowTablesChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.TABLES,
                    Epi.Util.GetShortHand(settingsPanel.ShowTablesOutput)));
            }
            if ((settingsPanel.ShowIncludeMissing != config.Settings.IncludeMissingValues) || (hasIncludeMissingChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.MISSING,
                    Epi.Util.GetShortHand(settingsPanel.ShowIncludeMissing)));
            }
            if (hasStatisticsLevelChanged)
            {
                RadioButton rbSelected = settingsPanel.StatisticLevel;
                StatisticsLevel levelIdSelected = (StatisticsLevel)short.Parse(rbSelected.Tag.ToString());
                string levelTagSelected = AppData.Instance.GetStatisticsLevelById(levelIdSelected).Tag;
                kvPairs.Add(new KeyValuePair(CommandNames.STATISTICS, levelTagSelected));
            }
            if (hasProcessRecordsChanged)
            {
                RadioButton rbSelected = settingsPanel.ProcessRecords;
                RecordProcessingScope scopeIdSelected = (RecordProcessingScope)short.Parse(rbSelected.Tag.ToString());
                string scopeTagSelected = AppData.Instance.GetRecordProcessessingScopeById(scopeIdSelected).Tag;
                kvPairs.Add(new KeyValuePair(CommandNames.PROCESS, scopeTagSelected));
            }

            WordBuilder command = new WordBuilder();
            //Generate command only if there are key value pairs
            if (kvPairs.Count > 0)
            {
                if (!this.isDialogMode)
                {
                    command.Append(CommandNames.SET);
                }
                command.Append(kvPairs.ToString());
                if (!this.isDialogMode)
                {
                    command.Append(" END-SET\n");
                }
                this.CommandText = command.ToString();
            }
            else
            {
                this.CommandText = string.Empty;
            }
        }