Exemple #1
0
        /// <summary>
        /// Retrieves all the columns for the table
        /// </summary>
        /// <param name="assemblyFilePath">The assembly file to search</param>
        public void GetColumns(string assemblyFilePath)
        {
            // Get primary key for table
            GetPrimaryKey(assemblyFilePath);

            Type type = AssemblySearch.GetTypeFromAssembly(assemblyFilePath, FullClassNamespace);

            //Search fields
            foreach (var field in TypeSearch.GetFieldsWithScriptPropertyAttribute(type) ?? new FieldInfo[0])
            {
                AddColumn(ColumnDefinition.CreateFromFieldInfo(field));
            }

            //Search properties
            foreach (var property in TypeSearch.GetPropertiesWithScriptPropertyAttribute(type) ?? new PropertyInfo[0])
            {
                AddColumn(ColumnDefinition.CreateFromPropertyInfo(property));
            }

#if DEBUG
            foreach (ColumnDefinition column in Columns)
            {
                Console.WriteLine($"Table: {Name} - Column: {column.Name}, {column.Type}, PK:{column.PrimaryKey}");
            }
#endif
        }
        /// <summary>
        /// Finds the tables that are to be generated.
        /// </summary>
        private void PopulateTables()
        {
            //Create new list of table definitions each time
            _tables = new List <TableDefinition>();

            //Search types for script-able tables
            foreach (Type type in AssemblySearch.GetClassesWithScriptTableAttribute(_assemblyFilePath) ?? new List <Type>())
            {
                _tables.Add(new TableDefinition(type.Name, type.Namespace));
            }
        }
        public JsonResult GetNum(DateTime start, DateTime end, string line)
        {
            List <string> list = new List <string>()
            {
                ""
            };

            AssemblySearch.GetNum(start, end, line).ForEach(
                p =>
            {
                list.Add(p);
            });

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
        /// <summary>
        /// Retrieves the primary key for the table
        /// </summary>
        /// <param name="assemblyFilePath">The assembly file to search</param>
        /// <remarks>Assumes only 1 primary key defined on class</remarks>
        public void GetPrimaryKey(string assemblyFilePath)
        {
            Type   type       = AssemblySearch.GetTypeFromAssembly(assemblyFilePath, FullClassNamespace);
            object primaryKey = TypeSearch.GetPrimaryKeyFromType(type);

            //if null, there is no primary key
            if (primaryKey != null)
            {
                try
                {
                    PropertyInfo property = (PropertyInfo)primaryKey;
                    AddColumn(ColumnDefinition.CreateFromPropertyInfo(property, true));
                }
                catch (InvalidCastException)
                {
                    //If not a PropertyInfo type or null, it must be FieldInfo. Otherwise, allow exceptions.
                    FieldInfo field = (FieldInfo)primaryKey;
                    AddColumn(ColumnDefinition.CreateFromFieldInfo(field, true));
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Retrieves all foreigns keys for the table
        /// </summary>
        /// <param name="assemblyFilePath">The assembly file to search</param>
        /// <remarks><see cref="CompleteForeignKeyDefinitions"/> should be called after this function.</remarks>
        public void GetForeignKeys(string assemblyFilePath)
        {
            Type type = AssemblySearch.GetTypeFromAssembly(assemblyFilePath, FullClassNamespace);

            //Search fields
            foreach (var field in TypeSearch.GetFieldsWithScriptForeignKeyAttribute(type) ?? new FieldInfo[0])
            {
                AddForeignKey(ForeignKeyDefinition.CreateFromFieldInfo(field, Name));
            }

            //Search properties
            foreach (var property in TypeSearch.GetPropertiesWithScriptForeignKeyAttribute(type) ?? new PropertyInfo[0])
            {
                AddForeignKey(ForeignKeyDefinition.CreateFromPropertyInfo(property, Name));
            }

#if DEBUG
            foreach (ForeignKeyDefinition fk in ForeignKeys)
            {
                Console.WriteLine($"Table: {Name} - Foreign Key: {fk.ColumnName}, {fk.ForeignTable}");
            }
#endif
        }
Exemple #6
0
        //Get Assembly by Data
        public List <AssemblyGroupModel> GetAssemblyByData(string searchFor, AssemblySearch columnName)
        {
            //Store raw query results to data table
            DataTable dt = new DataTable();

            //SQLite stuff
            SQLiteCommand    comm       = null;
            SQLiteConnection connection = null;

            string query = String.Format("SELECT * FROM {0} WHERE {0}.@C LIKE '%@param%';", TableName);

            //useable Data after conversion to be returned
            List <AssemblyGroupModel> assemblyList = new List <AssemblyGroupModel>();

            try
            {
                connection = SQLiteHelper.OpenConn();

                //comm = new SQLiteCommand(query, connection);
                switch (columnName)
                {
                case AssemblySearch.ID:
                    query = query.Replace("@C", "AssemblyId");
                    comm  = new SQLiteCommand(query, connection);
                    int idRes;
                    if (!int.TryParse(searchFor, out idRes))
                    {
                        throw new Exception("Assembly ID search is restricted to numbers");
                    }
                    comm.Parameters.Add("@param", DbType.Int32).Value = idRes;
                    break;

                case AssemblySearch.PARTSID:
                    query = query.Replace("@C", "PartsId");
                    comm  = new SQLiteCommand(query, connection);
                    int partIdRes;
                    if (!int.TryParse(searchFor, out partIdRes))
                    {
                        throw new Exception("Parts ID search is restricted to numbers");
                    }
                    comm.Parameters.Add("@param", DbType.Int32).Value = partIdRes;
                    break;

                case AssemblySearch.QUANTITY:
                    query = query.Replace("@C", "PartsQuantity");
                    comm  = new SQLiteCommand(query, connection);
                    int quantity;
                    if (!int.TryParse(searchFor, out quantity))
                    {
                        throw new Exception("Parts ID search is restricted to numbers");
                    }
                    comm.Parameters.Add("@param", DbType.Int32).Value = quantity;
                    break;
                }

                //Execute the command and load data to table
                SQLiteDataReader reader = comm.ExecuteReader();
                dt.Load(reader);

                //Closes reader stream then connection
                reader.Close();
                SQLiteHelper.CloseConn();

                //Use Datamapper to map selected results to objects
                DataNamesMapper <AssemblyGroupModel> mapper = new DataNamesMapper <AssemblyGroupModel>();

                assemblyList = mapper.Map(dt).ToList();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                SQLiteHelper.CloseConn();
                MessageBox.Show(e.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            return(assemblyList);
        }