Ejemplo n.º 1
0
        /* ==========================
         * SWITCHBOXES
         * ==========================*/
        public List <SwitchboxInfo> GetAllSwitchboxes()
        {
            // Init list
            List <SwitchboxInfo> switchboxList = new List <SwitchboxInfo>();

            using (SqlConnection connection = new SqlConnection(connectString))
                using (SqlCommand cmd = new SqlCommand("SELECT sid, name, num_switches FROM Switchboxes ORDER BY name asc", connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                SwitchboxInfo s = new SwitchboxInfo();
                                s.sid         = reader.GetInt32(reader.GetOrdinal("sid"));
                                s.name        = reader.GetString(reader.GetOrdinal("name"));
                                s.numSwitches = reader.GetInt32(reader.GetOrdinal("num_switches"));
                                switchboxList.Add(s);
                            }
                        }
                    }
                    connection.Close();
                }

            // return lsit
            return(switchboxList);
        }
Ejemplo n.º 2
0
        public void InsertSwitchbox(SwitchboxInfo newSwitchbox)
        {
            using (SqlConnection connection = new SqlConnection(connectString))
                using (SqlCommand cmd = new SqlCommand("INSERT INTO Switchboxes (name,num_switches) VALUES(@Name, @NumSwitches)", connection))
                {
                    // Add parameters
                    cmd.Parameters.AddWithValue("@Name", newSwitchbox.name);
                    cmd.Parameters.AddWithValue("@NumSwitches", newSwitchbox.numSwitches);
                    // Open connection and insert
                    connection.Open();
                    cmd.ExecuteNonQuery();

                    // Disconnect
                    connection.Close();
                }
        }
Ejemplo n.º 3
0
        public void UpdateSwitchbox(SwitchboxInfo updateSwitchbox)
        {
            using (SqlConnection connection = new SqlConnection(connectString))
                using (SqlCommand cmd = new SqlCommand("UPDATE Switchboxes SET name = @Name, num_switches = @NumSwitches WHERE sid = @Sid", connection))
                {
                    // Add parameters
                    cmd.Parameters.AddWithValue("@Sid", updateSwitchbox.sid);
                    cmd.Parameters.AddWithValue("@Name", updateSwitchbox.name);
                    cmd.Parameters.AddWithValue("@NumSwitches", updateSwitchbox.numSwitches);
                    // Open connection and insert
                    connection.Open();
                    cmd.ExecuteNonQuery();

                    // Disconnect
                    connection.Close();
                }
        }
Ejemplo n.º 4
0
        public void UpdateSwitchbox(SwitchboxInfo updateSwitchbox)
        {
            using (SqlConnection connection = new SqlConnection(connectString))
            using (SqlCommand cmd = new SqlCommand("UPDATE Switchboxes SET name = @Name, num_switches = @NumSwitches WHERE sid = @Sid", connection))
            {
                // Add parameters
                cmd.Parameters.AddWithValue("@Sid", updateSwitchbox.sid);
                cmd.Parameters.AddWithValue("@Name", updateSwitchbox.name);
                cmd.Parameters.AddWithValue("@NumSwitches", updateSwitchbox.numSwitches);
                // Open connection and insert
                connection.Open();
                cmd.ExecuteNonQuery();

                // Disconnect
                connection.Close();
            }
        }
Ejemplo n.º 5
0
        public void InsertSwitchbox(SwitchboxInfo newSwitchbox)
        {
            using (SqlConnection connection = new SqlConnection(connectString))
            using (SqlCommand cmd = new SqlCommand("INSERT INTO Switchboxes (name,num_switches) VALUES(@Name, @NumSwitches)", connection))
            {
                // Add parameters
                cmd.Parameters.AddWithValue("@Name", newSwitchbox.name);
                cmd.Parameters.AddWithValue("@NumSwitches", newSwitchbox.numSwitches);
                // Open connection and insert
                connection.Open();
                cmd.ExecuteNonQuery();

                // Disconnect
                connection.Close();
            }
        }
Ejemplo n.º 6
0
        /* ==========================
         * SWITCHBOXES
         * ==========================*/
        public List<SwitchboxInfo> GetAllSwitchboxes()
        {
            // Init list
            List<SwitchboxInfo> switchboxList = new List<SwitchboxInfo>();
            using (SqlConnection connection = new SqlConnection(connectString))
            using (SqlCommand cmd = new SqlCommand("SELECT sid, name, num_switches FROM Switchboxes ORDER BY name asc", connection))
            {
                connection.Open();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            SwitchboxInfo s = new SwitchboxInfo();
                            s.sid = reader.GetInt32(reader.GetOrdinal("sid"));
                            s.name = reader.GetString(reader.GetOrdinal("name"));
                            s.numSwitches = reader.GetInt32(reader.GetOrdinal("num_switches"));
                            switchboxList.Add(s);
                        }
                    }
                }
                connection.Close();
            }

            // return lsit
            return switchboxList;
        }