示例#1
0
        //Return all software

        public List <SoftwareModel> index(int id)
        {
            SoftwareModel        software;
            List <SoftwareModel> softwares = new List <SoftwareModel>();

            connection.Connect();
            SqlCommand sqlCommand = new SqlCommand("select s.id, s.name as name, c.name as corporation from software s inner join corporation c on c.id = s.corporation_id  where s.corporation_id=@corporationId", connection.getConnection());

            sqlCommand.Parameters.AddWithValue("@corporationId", id);
            SqlDataReader reader = sqlCommand.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    software             = new SoftwareModel();
                    software.id          = Convert.ToInt32(reader["id"]);
                    software.name        = reader["name"].ToString();
                    software.corporation = reader["corporation"].ToString();
                    softwares.Add(software);
                }
            }

            connection.disConnect();
            return(softwares);
        }
示例#2
0
        //Update software

        public void update(SoftwareModel software)
        {
            connection.Connect();
            SqlCommand sqlCommand = new SqlCommand("update software set name = @name, corporation_id = @corporation_id where id = @id", connection.getConnection());

            sqlCommand.Parameters.AddWithValue("@id", software.id);
            sqlCommand.Parameters.AddWithValue("@name", software.name);
            sqlCommand.Parameters.AddWithValue("@corporation_id", software.corporation_id);
            sqlCommand.ExecuteNonQuery();
            connection.disConnect();
        }
示例#3
0
        //Store software

        public void store(SoftwareModel software)
        {
            SqlCommand sqlCommand = new SqlCommand("insert into software (name, corporation_id) VALUES (@name, @corporation_id)", connection.getConnection());

            connection.Connect();

            sqlCommand.Parameters.AddWithValue("@name", software.name);
            sqlCommand.Parameters.AddWithValue("@corporation_id", software.corporation_id);
            sqlCommand.Connection = connection.getConnection();

            sqlCommand.ExecuteNonQuery();

            connection.disConnect();
        }
示例#4
0
        //Return one software

        public SoftwareModel find(int id)
        {
            SoftwareModel software = new SoftwareModel();

            connection.Connect();
            SqlCommand sqlCommand = new SqlCommand("select id, name, corporation_id from software where id = @softwareId", connection.getConnection());

            sqlCommand.Parameters.AddWithValue("@softwareId", id);
            SqlDataReader reader = sqlCommand.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    software.id             = Convert.ToInt32(reader["id"]);
                    software.name           = reader["name"].ToString();
                    software.corporation_id = Convert.ToInt32(reader["corporation_id"]);
                }
            }

            connection.disConnect();
            return(software);
        }