def display_organizer_info(organizers, eventname, cal, city, street):
    """
    Displays organizer information.
    """
    con = connection.Connection()

    query = "SELECT o.organizer_name, o.contact_no, o.email, e.event_name, e.date, e.street, e.city FROM ORGANIZERS as o, BLOOD_DONATION_EVENT as e WHERE o.organizer_id=e.organizer_id AND e.event_name= '" + str(
        eventname.get()) + "' AND e.date= '" + str(
            cal.get()) + "' AND e.street = '" + str(
                street.get()) + "' AND e.city = '" + str(city.get()) + "';"
    print(query)
    try:
        con.execute_command(query)
    except Exception as e:
        messagebox.showerror("Error", e)
    all_results = con.fetch_all()

    organizerss = {}
    for result in all_results:
        result_splitted = str(result).replace("(", "").replace(")",
                                                               "").split(",")
        organizerss['Organizer Name'] = result_splitted[0]
        organizerss['Organizer Contact No'] = result_splitted[1]
        organizerss['Organizer Email'] = result_splitted[2]

    organizer_results = str(organizerss).replace("{", "").replace("}", "")

    organizers.set(organizer_results)

    return
Exemplo n.º 2
0
def past_events():
    
    """
    Displays all past blood donation events.
    """

    now = date.today()

    con = connection.Connection()

    query = "SELECT e.event_name, e.date, e.street, e.city FROM BLOOD_DONATION_EVENT AS  e WHERE e.date <= '" + str(now) + "';"
    try:
        con.execute_command(query)
    except Exception as e:
        messagebox.showerror("Error",e)
    all_results  = con.fetch_all()

    event_records = []
    for result in all_results:
        print(result)
        event_records.append(result)

    column_names = ("Event Name", "Date", "Street", "City")
    data = event_records
    title = "Past Events"
    tr9 = TreeView(column_names, data, title)

    return
Exemplo n.º 3
0
def add_event(event_id, event_name, cal, street, city, organizer_name):
    """Adds new event to the database.
        """

    con = connection.Connection()
    try:
        query_one = "SELECT o.organizer_id FROM ORGANIZERS AS o WHERE o.organizer_name = '" + organizer_name.get(
        ) + "';"
    except Exception as e:
        messagebox.showerror("Error", e)
    con.execute_command(query_one)
    organizer_id = con.fetch_one()

    my_data = ('EI' + str(event_id.get()), event_name.get(), str(cal.get()),
               street.get(), city.get(), organizer_id[0])
    print(my_data)
    query_two = """INSERT INTO BLOOD_DONATION_EVENT(event_id, event_name, date, street, city, organizer_id)
        VALUES """ + str(my_data)
    try:
        con.execute_command(query_two)
        con.commit_changes()
        messagebox.showinfo("Information", "The event has been saved.")
    except Exception as e:
        messagebox.showerror("Error", e)
    return
Exemplo n.º 4
0
def show_donation_records(cal, city):

    """
    Query to display all donation records in Alabama Blood Bank
    """
    
    today = date.today()

    con = connection.Connection()

    query = "SELECT r.fname, r.mnit, r.lname, r.dob, r.city, r.blood_type,r.gender,bd.event_name,bd.date,bd.street,bd.city FROM REGISTERED_USERS as r, BLOOD_DONATION_EVENT as bd, PARTICIPATES_IN as p WHERE p.pssn=r.ssn AND p.event_id=bd.event_id AND bd.date >= '" + str(cal.get()) + "' AND bd.date < '" + str(today) + "' AND bd.city = '" + str(city.get()) + "';"
    try:
        con.execute_command(query)
    except Exception as e:
        messagebox.showerror("Error", e)
    all_results  = con.fetch_all()

    donation_records = []
    for result in all_results:
        print(result)
        donation_records.append(result)

    column_names = ("Fname", "Mint", "Lname", "Date of Birth", "City", "Blood Type", "Gender", "Event Name", "Date of Blood Donation", "Street (Event organized)", "City (Event organized)")
    data = donation_records
    title = "Records of Donation"
    tr1 = TreeView(column_names, data, title)

    return
Exemplo n.º 5
0
def save(i, ssn):
    """
    Inserts user as a participant of selected blood donation event.
    """

    con = connection.Connection()

    query_one = "SELECT * FROM REGISTERED_USERS WHERE ssn = '" + str(
        ssn.get()) + "';"
    try:
        con.execute_command(query_one)
    except Exception as e:
        messagebox.showerror("Error", e)

    if con.fetch_all():
        my_data = (ssn.get(), i.get().replace("'", ""))
        query_two = "INSERT INTO PARTICIPATES_IN (pssn, event_id) VALUES " + str(
            my_data) + ";"
        try:
            con.execute_command(query_two)
            con.commit_changes()
            messagebox.showinfo("Information", "Saved Successfully.")
        except Exception as e:
            messagebox.showerror("Error", e)
    else:
        messagebox.showerror("Error", "This user isn't registered.")
Exemplo n.º 6
0
def request_records():
    """
    Displays user records who has requested the blood unit.
    """
    con = connection.Connection()

    query = "SELECT r.fname, r.mnit, r.lname, r.dob, r.city, r.blood_type, r.gender, bs.blood_type, bs.quantity_in_ml, bs.storage_id FROM REGISTERED_USERS AS r, BLOOD AS b, ALABAMA_BLOOD_STORAGE AS bs WHERE bs.storage_id=b.storage_id AND b.ssn=r.ssn;"
    try:
        con.execute_command(query)
    except Exception as e:
        messagebox.showerror("Error", e)
    all_results = con.fetch_all()

    request_records = []
    for result in all_results:
        print(result)
        request_records.append(result)

    column_names = ("First Name", "Middle Name", "Last Name", "Date of Birth",
                    "City", "Blood Type", "Gender", "Requested Blood Type",
                    "Quantity Requested (in mL)", "Requested from Storage Id")
    data = request_records
    title = "Supplied Blood Requests Records"
    tr2 = TreeView(column_names, data, title)

    return
Exemplo n.º 7
0
def donate(window):
    """
    Creates UI selection buttons for scheduling donation.
    """
    schedule_window = tk.Toplevel(window)
    schedule_window.title("Schedule Blood Donation")
    Label(schedule_window, text="Select Events").grid(row=0, column=1)

    today_date = date.today()

    con = connection.Connection()

    query = "SELECT e.event_id, e.event_name, e.date, e.street, e.city FROM BLOOD_DONATION_EVENT AS e WHERE e.date >= '" + str(
        today_date) + "';"
    try:
        con.execute_command(query)
    except Exception as e:
        messagebox.showerror("Error", e)
    all_results = con.fetch_all()

    eid_list = []
    combined_text_list = []
    for result in all_results:
        result_splitted = str(result).replace("(", "").replace(")",
                                                               "").split(", ")
        eid_list.append(result_splitted[0])
        date_format = result_splitted[4].replace(
            ")",
            "") + "/" + result_splitted[3] + "/" + result_splitted[2].replace(
                "datetime.date", "")
        combined_text_list.append(result_splitted[1] + "," +
                                  result_splitted[5] + "," +
                                  result_splitted[6].replace(")", "") +
                                  "\n Date: " + date_format)

    i = StringVar()
    for j in range(0, len(combined_text_list)):
        c = Radiobutton(schedule_window,
                        text=combined_text_list[j],
                        value=eid_list[j],
                        variable=i)
        c.grid(row=j + 1, column=1)

    ssn = Label(schedule_window,
                text="Enter SSN *").grid(row=len(combined_text_list) + 2,
                                         column=0)
    ssn = IntVar()
    ssnEntry = Entry(schedule_window,
                     textvariable=ssn).grid(row=len(combined_text_list) + 2,
                                            column=1)

    validate_s = partial(save, i, ssn)

    show_records = Button(schedule_window,
                          text="Save Event",
                          command=validate_s).grid(
                              row=len(combined_text_list) + 3, column=3)

    schedule_window.mainloop
def validate_and_insert_users(fname, mnit, lname, dob, city, bloodtype, gender,
                              email, password, confirmpassword, weight, height,
                              ssn, hmembership_no):
    """
    Add user information into the database.
    """
    fname = fname.get()
    mnit = mnit.get()
    lname = lname.get()
    dob = dob.get()
    city = city.get()
    bloodtype = bloodtype.get()
    gender = gender.get()
    email = email.get()
    password = password.get()
    confirmpassword = confirmpassword.get()
    weight = weight.get()
    height = height.get()
    ssn = ssn.get()
    hmembership_no = hmembership_no.get()

    if password != '' and fname != '':
        if password != confirmpassword:
            messagebox.showerror("String doesn't match ",
                                 "Password and ConfirmPassword do not match.")
            return

        if not fname or not lname or not dob or not bloodtype or not gender or not email or not password or not confirmpassword or not weight or not height or not ssn or not hmembership_no:
            messagebox.showerror("Missing fields",
                                 "One or more required fields are missing.")
            return

        con = connection.Connection()

        my_data = (fname, mnit, lname, ssn, dob, city, bloodtype, gender,
                   email, password, weight, height, hmembership_no)
        print(my_data)
        query = """INSERT INTO REGISTERED_USERS(fname, mnit, lname, ssn, dob, city, blood_type, gender, email, password, weight_in_lbs, height_in_lbs, hmembership_no)
        VALUES """ + str(my_data)
        print(query)

        if fname != '':
            try:
                con.execute_command(query)
                print('query executed')
                con.commit_changes()
                messagebox.showinfo("Information",
                                    "The user has been registered.")
            except Exception as e:
                messagebox.showerror("Error", e)
    return
def delete_checkbox(ssn, delete_window):
    """
    Query to generate the events which are scheduled from which some events are to be deleted.
    """

    today_date = date.today()

    con = connection.Connection()
    query = "SELECT e.event_id, e.event_name, e.date, e.street, e.city FROM BLOOD_DONATION_EVENT AS e, PARTICIPATES_IN AS p WHERE p.pssn = '" + str(
        ssn.get()) + "' AND p.event_id=e.event_id;"
    try:
        con.execute_command(query)
    except Exception as e:
        messagebox.showerror("Error", e)
    all_results = con.fetch_all()

    eid_list = []
    combined_text_list = []
    for result in all_results:
        result_splitted = str(result).replace("(", "").replace(")",
                                                               "").split(", ")
        eid_list.append(result_splitted[0])
        date_format = result_splitted[4].replace(
            ")",
            "") + "/" + result_splitted[3] + "/" + result_splitted[2].replace(
                "datetime.date", "")
        combined_text_list.append(result_splitted[1] + "," +
                                  result_splitted[5] + "," +
                                  result_splitted[6].replace(")", "") +
                                  "\n Date: " + date_format)

    i = StringVar()
    for j in range(0, len(combined_text_list)):
        print(j + 1)
        print(eid_list[j])
        c = Radiobutton(delete_window,
                        text=combined_text_list[j],
                        value=eid_list[j],
                        variable=i)
        c.grid(row=j + 2, column=1)

    validate_s = partial(check_delete, i, ssn, con)
    delete_records = Button(delete_window,
                            text="Delete Event",
                            command=validate_s).grid(
                                row=len(combined_text_list) + 5, column=3)
def show_events(ssn):
    """
    Display all scheduled events.
    """

    con = connection.Connection()

    query = "SELECT e.event_name, e.date, e.street, e.city FROM BLOOD_DONATION_EVENT AS e, PARTICIPATES_IN AS p WHERE p.pssn = '" + str(
        ssn.get()) + "' AND p.event_id=e.event_id;"
    try:
        con.execute_command(query)
    except Exception as e:
        messagebox.showerror("Error", e)
    all_results = con.fetch_all()

    event_records = []
    for result in all_results:
        print(result)
        event_records.append(result)

    column_names = ("Event Name", "Date", "Street", "City")
    data = event_records
    title = "All Schedules Events"
    tr9 = TreeView(column_names, data, title)
def check_availability(blood_type, age, weight, height, gender,
                       quantity_in_ml):
    """
    Query to check availability of specific blood_type, age, weight, height, gender and quantity.
    """
    blood_type = blood_type.get()
    age = age.get()
    weight = weight.get()
    height = height.get()
    gender = gender.get()
    quantity_in_ml = quantity_in_ml.get()

    if blood_type != '':
        con = connection.Connection()
        query = "SELECT bs.blood_type, bs.quantity_in_ml, bs.storage_id, b.available_from, b.d_gender, b.d_weight, b.d_height, b.d_age FROM ALABAMA_BLOOD_STORAGE as bs, BLOOD as b WHERE b.storage_id = bs.storage_id AND bs.blood_type= '" + blood_type + "' AND b.d_gender= '" + gender + "' AND b.d_height>= " + str(
            height
        ) + " AND b.d_weight>= " + str(weight) + " AND b.d_age<= " + str(
            age
        ) + " AND b.storage_id = bs.storage_id AND bs.quantity_in_ml >= " + str(
            quantity_in_ml) + ";"
        con.execute_command(query)
        all_results = con.fetch_all()

        availability_results = []
        for result in all_results:
            availability_results.append(result)

        column_names = ("Blood Type", "Quantity", "StorageId",
                        "Blood Available From", "Donor Gender", "Donor Weight",
                        "Donor Height", "Donor Age")
        data = availability_results
        title = "Results of Blood Availability"
        tr = TreeView(column_names, data, title)
    else:
        messagebox.showerror("Error", "Blood Type is empty")
    return