예제 #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();
            }
        }
예제 #2
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();
            }
        }