예제 #1
0
        /// <summary>
        /// Add units to table. Removes old units first.
        /// </summary>
        /// <param name="tableName">The table name</param>
        /// <param name="columnNames">The column names to add</param>
        /// <param name="columnUnits">The column units to add</param>
        public void AddUnitsForTable(string tableName, List <string> columnNames, List <string> columnUnits)
        {
            Table foundTable = tables.Find(t => t.Name == tableName);

            if (foundTable != null)
            {
                for (int i = 0; i < columnNames.Count; i++)
                {
                    Table.Column column = foundTable.Columns.Find(c => c.Name == columnNames[i]);
                    if (column != null)
                    {
                        column.Units = columnUnits[i];
                    }
                }
            }

            connection.ExecuteNonQuery("DELETE FROM _Units WHERE TableName = '" + tableName + "'");

            List <object[]> values = new List <object[]>();

            for (int i = 0; i < columnNames.Count; i++)
            {
                values.Add(new object[] { tableName, columnNames[i], columnUnits[i] });
            }
            List <string> unitsColumns = new List <string>(new string[] { "TableName", "ColumnHeading", "Units" });

            connection.InsertRows("_Units", unitsColumns, values);
        }
예제 #2
0
        /// <summary>
        /// Add units to table. Removes old units first.
        /// </summary>
        /// <param name="tableName">The table name</param>
        /// <param name="columnNames">The column names to add</param>
        /// <param name="columnUnits">The column units to add</param>
        public void AddUnitsForTable(string tableName, List <string> columnNames, List <string> columnUnits)
        {
            Table foundTable = tables.Find(t => t.Name == tableName);

            if (foundTable != null)
            {
                for (int i = 0; i < columnNames.Count; i++)
                {
                    Table.Column column = foundTable.Columns.Find(c => c.Name == columnNames[i]);
                    if (column != null)
                    {
                        column.Units = columnUnits[i];
                    }
                }
            }

            connection.ExecuteNonQuery("DELETE FROM _Units WHERE TableName = '" + tableName + "'");

            string sql = "INSERT INTO _Units (TableName, ColumnHeading, Units) " +
                         "VALUES (?, ?, ?)";
            IntPtr statement = connection.Prepare(sql);

            for (int i = 0; i < columnNames.Count; i++)
            {
                connection.BindParametersAndRunQuery(statement, new object[] {
                    tableName,
                    columnNames[i],
                    columnUnits[i]
                });
            }
            connection.Finalize(statement);
        }
예제 #3
0
        /// <summary>
        /// Obtain the units for a column of data
        /// </summary>
        /// <param name="tableName">Name of the table</param>
        /// <param name="columnHeading">Name of the data column</param>
        /// <returns>The units (with surrounding parentheses), or null if not available</returns>
        public string GetUnits(string tableName, string columnHeading)
        {
            Table table = tables.Find(t => t.Name == tableName);

            if (table != null)
            {
                Table.Column column = table.Columns.Find(c => c.Name == columnHeading);
                if (column != null)
                {
                    return("(" + column.Units + ")");
                }
            }
            return(null);
        }