File size: 1,694 Bytes
e4fe207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# academic_list.py
import streamlit as st
from app5_selectbox.database_con import cursor, db_connection #connect_to_database, execute_query
from app5_selectbox.app5_selectbox_func import display_table, generate_unique_4


def academic_list(table_name):
    # Include the academic_list-specific code here
    acad_id = generate_unique_4(cursor, "acad_id", table_name)
    acad_year = st.text_input("Academic Year", key="acad_year")
    sem_num = st.selectbox("Semester Number", ("1", "2"), key="sem_num")

    if st.button("Insert Academic List Record"):
        # Check if the acad_year and sem_num are provided
        if not acad_year or not sem_num:
            st.error("Academic Year and Semester Number are required. Please provide values for both fields.")
        else:
            try:
                # Check for duplicates in acad_year and sem_num
                cursor.execute("SELECT acad_id FROM academic_list WHERE acad_year = %s AND sem_num = %s", (acad_year, sem_num))
                duplicate = cursor.fetchone()
                if duplicate is not None:
                    st.error("Duplicate entry found. Please provide unique Academic Year and Semester Number.")
                else:
                    # Insert a record into the academic_list table
                    cursor.execute("INSERT INTO academic_list (acad_id, acad_year, sem_num) VALUES (%s, %s, %s)",
                                    (acad_id, acad_year, sem_num))
                    db_connection.commit()
                    st.success("Record inserted successfully.")
            except Exception as e:
                st.error(f"An error occurred: {str(e)}")
    display_table(cursor, table_name)