/// <summary>
        /// Populate internal translation table using Epi 3.x db
        /// </summary>
        /// <param name="legacyLanguageDatabasePath"></param>
        public void ReadDatabase(string legacyLanguageDatabasePath)
        {
            //IDbDriver db = DatabaseFactory.CreateDatabaseInstanceByFileExtension(legacyLanguageDatabasePath);
            IDbDriverFactory             dbFactory          = DbDriverFactoryCreator.GetDbDriverFactory(Epi.Configuration.AccessDriver);
            OleDbConnectionStringBuilder dbCnnStringBuilder = new OleDbConnectionStringBuilder();

            dbCnnStringBuilder.FileName = legacyLanguageDatabasePath;
            IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder);

            List <string> tableNames = db.GetTableNames();

            foreach (string tableName in tableNames)
            {
                List <string> columnNames = db.GetTableColumnNames(tableName);
                if (columnNames.Contains("English") && columnNames.Count == 2)
                {
                    DataTable span = db.Select(db.CreateQuery("select * from " + tableName));


                    int sourceColumnOrdinal, translationColumnOrdinal;

                    if (string.Compare(span.Columns[0].ColumnName, "English", true) == 0)
                    {
                        sourceColumnOrdinal      = 0;
                        translationColumnOrdinal = 1;
                    }
                    else
                    {
                        sourceColumnOrdinal      = 1;
                        translationColumnOrdinal = 0;
                    }

                    foreach (DataRow row in span.Rows)
                    {
                        AddTranslationTableEntry(sourceColumnOrdinal, translationColumnOrdinal, row);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns true if the given database is a valid Epi Info 7 project.
        /// </summary>
        /// <param name="connectionInfo">The connection information to the database.</param>
        /// <param name="isConnectionString">Whether the connection info is a connection string</param>
        /// <returns>bool</returns>
        public static bool IsDatabaseEpiProject(string connectionInfo, bool isConnectionString)
        {
            //if (fileName.ToLowerInvariant().EndsWith(".mdb"))
            //{
            IDbDriver db        = DBReadExecute.GetDataDriver(connectionInfo, isConnectionString);
            bool      isProject = true;

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

            metaTableNames.Add("metaBackgrounds");
            metaTableNames.Add("metaDataTypes");
            metaTableNames.Add("metaDbInfo");
            metaTableNames.Add("metaFields");
            metaTableNames.Add("metaFieldTypes");
            metaTableNames.Add("metaImages");
            metaTableNames.Add("metaLinks");
            metaTableNames.Add("metaPages");
            metaTableNames.Add("metaViews");

            foreach (string tableName in metaTableNames)
            {
                if (!db.TableExists(tableName))
                {
                    isProject = false;
                }
            }

            List <string> metaViewsColumnNames = db.GetTableColumnNames("metaViews");

            if (
                !metaViewsColumnNames.Contains("ViewId") ||
                !metaViewsColumnNames.Contains("Name") ||
                !metaViewsColumnNames.Contains("IsRelatedView") ||
                !metaViewsColumnNames.Contains("CheckCode") ||
                !metaViewsColumnNames.Contains("Width") ||
                !metaViewsColumnNames.Contains("Height") ||
                !metaViewsColumnNames.Contains("Orientation")
                )
            {
                isProject = false;
            }

            List <string> metaPagesColumnNames = db.GetTableColumnNames("metaPages");

            if (
                !metaPagesColumnNames.Contains("PageId") ||
                !metaPagesColumnNames.Contains("Name") ||
                !metaPagesColumnNames.Contains("Position") ||
                !metaPagesColumnNames.Contains("BackgroundId") ||
                !metaPagesColumnNames.Contains("ViewId")
                )
            {
                isProject = false;
            }

            List <string> metaFieldsColumnNames = db.GetTableColumnNames("metaFields");

            if (
                !metaFieldsColumnNames.Contains("FieldId") ||
                !metaFieldsColumnNames.Contains("UniqueId") ||
                !metaFieldsColumnNames.Contains("Name") ||
                !metaFieldsColumnNames.Contains("PromptText") ||
                !metaFieldsColumnNames.Contains("ControlFontFamily") ||
                !metaFieldsColumnNames.Contains("ControlFontSize") ||
                !metaFieldsColumnNames.Contains("ControlFontStyle") ||
                !metaFieldsColumnNames.Contains("ControlTopPositionPercentage") ||
                !metaFieldsColumnNames.Contains("ControlLeftPositionPercentage") ||
                !metaFieldsColumnNames.Contains("ControlHeightPercentage") ||
                !metaFieldsColumnNames.Contains("ControlWidthPercentage") ||
                !metaFieldsColumnNames.Contains("TabIndex") ||
                !metaFieldsColumnNames.Contains("HasTabStop") ||
                !metaFieldsColumnNames.Contains("Lower") ||
                !metaFieldsColumnNames.Contains("Upper") ||
                !metaFieldsColumnNames.Contains("Pattern") ||
                !metaFieldsColumnNames.Contains("PageId") ||
                !metaFieldsColumnNames.Contains("ViewId")
                )
            {
                isProject = false;
            }
            //}

            db.Dispose();
            db = null;

            return(isProject);
        }
Beispiel #3
0
        private void BuildKeyDialog_Load(object sender, EventArgs e)
        {
            if (SelectedDataSource != null)
            {
                if (SelectedDataSource is IDbDriver)
                {
                    IDbDriver db = SelectedDataSource as IDbDriver;
                    //--EI-114
                    // relatedFields = db.GetTableColumnNames(RelatedTable);
                    if (RelatedTable.Contains(StringLiterals.SPACE))
                    {
                        string    pstr      = "Select TOP 2 * from [" + RelatedTable + "]";
                        DataTable relfields = DBReadExecute.GetDataTable(db, pstr);
                        foreach (DataColumn dc in relfields.Columns)
                        {
                            relatedFields.Add(dc.ColumnName);
                        }
                    }
                    else
                    {
                        relatedFields = db.GetTableColumnNames(RelatedTable);
                    }
                    //---
                }
                else if (SelectedDataSource is Project)
                {
                    Project project = SelectedDataSource as Project;

                    if (project.Views.Exists(relatedTable))
                    {
                        foreach (Epi.Fields.IField field in project.Views[RelatedTable].Fields)
                        {
                            if (!(field is Epi.Fields.LabelField) & !(field is Epi.Fields.CommandButtonField) & !(field is Epi.Fields.PhoneNumberField)//EI-705
                                & !(field is Epi.Fields.MultilineTextField) & !(field is Epi.Fields.GroupField) & !(field is Epi.Fields.CheckBoxField)
                                & !(field is Epi.Fields.ImageField) & !(field is Epi.Fields.OptionField) & !(field is Epi.Fields.GridField)
                                & !(field is Epi.Fields.MirrorField))
                            {
                                relatedFields.Add(field.Name);
                            }
                        }
                    }
                    else
                    {
                        relatedFields = project.GetTableColumnNames(RelatedTable);
                    }
                }
                if (this.EpiInterpreter.Context.DataSet != null)
                {
                    View CurrentView = null;
                    bool currentReadIdentifierIsView = false;

                    if (this.EpiInterpreter.Context.CurrentProject != null)
                    {
                        currentReadIdentifierIsView = this.EpiInterpreter.Context.CurrentProject.IsView(this.EpiInterpreter.Context.CurrentRead.Identifier);
                    }

                    if (currentReadIdentifierIsView)
                    {
                        CurrentView = this.EpiInterpreter.Context.CurrentProject.GetViewByName(this.EpiInterpreter.Context.CurrentRead.Identifier); //EI-705
                        foreach (DataColumn column in this.EpiInterpreter.Context.DataSet.Tables["Output"].Columns)
                        {
                            if ((CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.LabelField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.CommandButtonField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.PhoneNumberField))
                                & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.MultilineTextField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.GroupField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.CheckBoxField))
                                & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.ImageField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.OptionField)) & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.GridField))
                                & (CurrentView.Fields.Exists(column.ColumnName) && !(CurrentView.Fields[column.ColumnName] is Epi.Fields.MirrorField)))
                            {
                                currentFields.Add(column.ColumnName);
                            }
                        }
                    }
                    else
                    {
                        foreach (DataColumn column in this.EpiInterpreter.Context.DataSet.Tables["Output"].Columns)
                        {
                            currentFields.Add(column.ColumnName);
                        }
                    }
                }
                currentFields.Sort();
            }
            //rdbCurrentTable.Checked = true;

            relatedFields.Sort();
            currentFields.Sort();

            //cmbAvailableVariables2.DataSource = relatedFields;
            lbxRelatedTableFields.DataSource = relatedFields;
            //cmbAvailableVariables.DataSource = currentFields;
            lbxCurrentTableFields.DataSource = currentFields;

            lbxCurrentTableFields.SelectedIndex = -1;
            lbxRelatedTableFields.SelectedIndex = -1;

            if (CallingDialog == "RELATE")
            {
                lblBuildKeyInstructions.Text = SharedStrings.BUILDKEY_RELATE_INSTRUCTIONS;
            }
            else
            {
                lblBuildKeyInstructions.Text = SharedStrings.BUILDKEY_MERGE_INSTRUCTIONS;
            }

            this.LoadIsFinished = true;
        }
        void ToNodeFiller_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (lvLinkedTo.InvokeRequired)
                {
                    lvLinkedTo.Invoke(new MethodInvoker(delegate
                    {
                        lvLinkedTo.Items.Clear();
                        lvLinkedTo.Groups.Clear();
                    }));
                }
                else
                {
                    lvLinkedTo.Items.Clear();
                    lvLinkedTo.Groups.Clear();
                }
                if (btnUnlinkTo.InvokeRequired)
                {
                    btnUnlinkTo.Invoke(new MethodInvoker(delegate
                    {
                        btnUnlinkTo.Enabled = false;
                    }));
                }
                else
                {
                    btnUnlinkTo.Enabled = false;
                }

                Dictionary <string, string> fieldNames = new Dictionary <string, string>();
                Query query;

                query = db.CreateQuery
                        (
                    "SELECT [metaPages.PageId] as PageId, [metaPages.ViewId] as ViewId, [metaViews.Name] as Name " +
                    "FROM [metaPages] " +
                    "LEFT OUTER JOIN [metaViews] ON metaPages.ViewId = metaViews.ViewId " +
                    "WHERE [metaPages.Position] = 0"
                        );

                DataTable pageIds = db.Select(query);

                query = db.CreateQuery
                        (
                    "SELECT [metaFields.Name] as Name, [metaFields.PageId] as PageId, [metaFields.ViewId] as ViewId, [metaFields.TabIndex] as TabIndex " +
                    "FROM [metaFields] " +
                    "LEFT OUTER JOIN [metaPages] ON metaPages.ViewId = metaFields.ViewId " +
                    "WHERE [metaFields.HasTabStop] = true AND [metaPages.Position] = 0 " +
                    "ORDER BY [metaFields.ViewId], [metaFields.TabIndex]"
                        );

                DataTable fields = db.Select(query);

                List <string> list = fields.AsEnumerable().Select(r => r.Field <string>(0)).ToList();

                string uniqueKeys = "";
                string parens     = "";
                string joins      = "";

                foreach (View view in enterMainForm.View.Project.Views)
                {
                    if (!string.IsNullOrEmpty(view.TableName) && db.TableExists(view.TableName))
                    {
                        if (!view.IsRelatedView)
                        {
                            uniqueKeys += "t" + view.Id + ".UniqueKey as Key" + view.Id + ", ";
                            parens     += "(";
                            joins      += "left outer join " + view.TableName + " t" + view.Id + " on m.ToRecordGuid = t" + view.Id + ".GlobalRecordId) ";
                        }
                    }
                }

                uniqueKeys = uniqueKeys.Substring(0, uniqueKeys.Length - 2) + " ";

                query = db.CreateQuery(@"Select FromRecordGuid, ToRecordGuid, FromViewId, ToViewId, " + uniqueKeys + " from " + parens + "metaLinks m " + joins + " where m.FromRecordGuid = @GlobalRecordId");
                QueryParameter parameter = new QueryParameter("@GlobalRecordId", DbType.StringFixedLength, enterMainForm.View.CurrentGlobalRecordId);
                parameter.Size = enterMainForm.View.CurrentGlobalRecordId.Length;
                query.Parameters.Add(parameter);
                DataTable data = db.Select(query);

                if (data.Rows.Count > 0)
                {
                    foreach (View view in enterMainForm.View.Project.Views)
                    {
                        if (lvLinkedTo.InvokeRequired)
                        {
                            lvLinkedTo.Invoke(new MethodInvoker(delegate
                            {
                                lvLinkedTo.Groups.Add(view.Id.ToString(), view.Name);
                            }));
                        }
                        else
                        {
                            lvLinkedTo.Groups.Add(view.Id.ToString(), view.Name);
                        }
                    }
                }

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

                string        toViewId     = string.Empty;
                string        toRecordGuid = string.Empty;
                string        fieldPrint   = string.Empty;
                DataRow[]     fieldRows    = null;
                List <string> fieldPrintList;
                string        collectedDataTableName = string.Empty;

                foreach (DataRow row in data.Rows)
                {
                    ListViewItem item = new ListViewItem();

                    toViewId     = row["ToViewId"].ToString();
                    toRecordGuid = row["ToRecordGuid"].ToString();

                    DataRow[] oneRow = pageIds.Select("ViewId = '" + toViewId + "'");
                    collectedDataTableName = ((string)oneRow[0]["Name"]) + ((string)oneRow[0]["PageId"].ToString());

                    fieldRows = fields.Select("ViewId = " + toViewId);

                    List <string> columnNames = db.GetTableColumnNames(collectedDataTableName);
                    fieldPrintList = fieldRows.Select(r => r.Field <string>(0)).ToList();
                    fieldPrintList = fieldPrintList.Intersect(columnNames).ToList();
                    fieldPrintList.Add("GlobalRecordId");

                    var datatable = db.GetTableData(collectedDataTableName, fieldPrintList);
                    var theRow    = datatable.Select("GlobalRecordId = '" + toRecordGuid + "'");

                    fieldPrint = row["Key" + row["ToViewId"].ToString()].ToString();;

                    if (theRow != null)
                    {
                        fieldPrint += " :: ";
                        fieldPrint += theRow[0][0].ToString() + "; " + theRow[0][1].ToString() + "; " + theRow[0][2].ToString();
                    }

                    item      = new ListViewItem(fieldPrint);
                    item.Tag  = row["Key" + row["ToViewId"].ToString()].ToString();
                    item.Name = toRecordGuid;

                    for (int x = 0; x < data.Columns.Count; x++)
                    {
                        item.SubItems.Add(row[x].ToString());
                    }

                    item.ImageIndex = 0;
                    item.Group      = lvLinkedTo.Groups[row["ToViewId"].ToString()];

                    if (names.Contains(toRecordGuid) == false)
                    {
                        names.Add(toRecordGuid);

                        if (lvLinkedTo.InvokeRequired)
                        {
                            lvLinkedTo.Invoke(new MethodInvoker(delegate
                            {
                                if (lvLinkedTo.Items.ContainsKey(toRecordGuid) == false)
                                {
                                    lvLinkedTo.Items.Add(item);
                                }
                            }));
                        }
                        else
                        {
                            if (lvLinkedTo.Items.ContainsKey(toRecordGuid) == false)
                            {
                                lvLinkedTo.Items.Add(item);
                            }
                        }
                    }
                }
            }
            catch { }
        }
Beispiel #5
0
        private void BuildKeyDialog_Load(object sender, EventArgs e)
        {
            if (SelectedDataSource != null)
            {
                if (SelectedDataSource is IDbDriver)
                {
                    IDbDriver db = SelectedDataSource as IDbDriver;
                    //--EI-114
                    // relatedFields = db.GetTableColumnNames(RelatedTable);
                    if (RelatedTable.Contains(StringLiterals.SPACE))
                    {
                        string    pstr      = "Select TOP 2 * from [" + RelatedTable + "]";
                        DataTable relfields = DBReadExecute.GetDataTable(db, pstr);
                        foreach (DataColumn dc in relfields.Columns)
                        {
                            relatedFields.Add(dc.ColumnName);
                        }
                    }
                    else
                    {
                        relatedFields = db.GetTableColumnNames(RelatedTable);
                    }
                    //---
                }
                else if (SelectedDataSource is Project)
                {
                    Project project = SelectedDataSource as Project;

                    if (project.Views.Exists(relatedTable))
                    {
                        foreach (Epi.Fields.IField field in project.Views[RelatedTable].Fields)
                        {
                            if (!(field is Epi.Fields.LabelField) &
                                !(field is Epi.Fields.CommandButtonField) &
                                !(field is Epi.Fields.PhoneNumberField) &
                                !(field is Epi.Fields.MultilineTextField) &
                                !(field is Epi.Fields.GroupField) &
                                !(field is Epi.Fields.CheckBoxField) &
                                !(field is Epi.Fields.ImageField) &
                                !(field is Epi.Fields.OptionField) &
                                !(field is Epi.Fields.GridField) &
                                !(field is Epi.Fields.MirrorField))
                            {
                                relatedFields.Add(field.Name);
                            }
                        }
                    }
                    else
                    {
                        relatedFields = project.GetTableColumnNames(RelatedTable);
                    }
                }

                currentFields = GetCurrentFields();
            }

            relatedFields.Sort();
            currentFields.Sort();

            lbxRelatedTableFields.DataSource = relatedFields;
            lbxCurrentTableFields.DataSource = currentFields;

            lbxCurrentTableFields.SelectedIndex = -1;
            lbxRelatedTableFields.SelectedIndex = -1;

            if (CallingDialog == "RELATE")
            {
                lblBuildKeyInstructions.Text = SharedStrings.BUILDKEY_RELATE_INSTRUCTIONS;
            }
            else
            {
                lblBuildKeyInstructions.Text = SharedStrings.BUILDKEY_MERGE_INSTRUCTIONS;
            }

            this.LoadIsFinished = true;
        }