def update():
     adminobj = AdministratorBL.AdministratorBL().read_administrator(
         username)
     field_no = e1.get()
     var = e2.get()
     if e1.get() and e2.get():
         if field_no == "1":
             adminobj.password = var
         elif field_no == "2":
             adminobj.email1 = var
         elif field_no == "3":
             adminobj.email2 = var
         elif field_no == "4":
             adminobj.firstname = var
         elif field_no == "5":
             adminobj.lastname = var
         elif field_no == "6":
             adminobj.aboutme = var
         elif field_no == "7":
             adminobj.photourl1 = var
         elif field_no == "8":
             adminobj.photourl12 = var
         elif field_no == "9":
             adminobj.photourl13 = var
         elif field_no == "10":
             adminobj.streetnumber = var
         elif field_no == "11":
             adminobj.streetname = var
         elif field_no == "12":
             adminobj.majormunicipality = var
         elif field_no == "13":
             adminobj.governingdistrict = var
         elif field_no == "14":
             adminobj.postalarea = var
         elif field_no == "15":
             adminobj.phone = var
         if AdministratorBL.AdministratorBL().update_administrator(
                 adminobj) is True:
             Label(master, text="Updated").grid(row=5, column=2)
         else:
             Label(master, text="Not Updated").grid(row=5, column=2)
     else:
         Label(master,
               text="Both fields (Field Id and New value) are mandatory!!",
               fg="red").grid(row=5, column=1)
 def addqual():
     qual_id = random.randint(1, 1000)
     desc = e3.get()
     if e3.get():
         qo = Entities.Qualification(qual_id, desc)
         if AdministratorBL.AdministratorBL().add_qual(qo) is True:
             Label(master, text="Added").grid(row=8, column=2)
         else:
             Label(master, text="Not Added").grid(row=8, column=2)
     else:
         Label(master,
               text="Qualification description is mandatory!!",
               fg="red").grid(row=8, column=1)
 def addprop():
     propid = random.randint(1, 1000)
     name = e4.get()
     desc = e5.get()
     if e4.get() and e5.get():
         po = Entities.Property(propid, name, desc)
         if AdministratorBL.AdministratorBL().add_property(po) is True:
             Label(master, text="Added").grid(row=12, column=2)
         else:
             Label(master, text="Not Added").grid(row=12, column=2)
     else:
         Label(
             master,
             text=
             "Both fields (Property name and Description) are mandatory!!",
             fg="red").grid(row=12, column=1)
 def display():
     mstr = Tk()
     listbox = Listbox(mstr, width=100, height=30)
     listbox.pack()
     adminobj = AdministratorBL.AdministratorBL().read_administrator(
         username)
     listbox.insert(END, 'UserName(cannot be updated)-' + adminobj.username)
     listbox.insert(END, '1.Password-' + adminobj.password)
     listbox.insert(END, '2.FirstEmailID-' + adminobj.email1)
     listbox.insert(END, '3.SecondEmailID-' + adminobj.email2)
     listbox.insert(END, '4.FirstName-' + adminobj.firstname)
     listbox.insert(END, '5.LastName-' + adminobj.lastname)
     listbox.insert(END, '6.AboutYou-' + adminobj.aboutme)
     listbox.insert(END, '7.URL1-' + adminobj.photourl1)
     listbox.insert(END, '8.URL2-' + adminobj.photourl2)
     listbox.insert(END, '9.URL3-' + adminobj.photourl3)
     listbox.insert(END, '10.StreetNumber-' + adminobj.streetnumber)
     listbox.insert(END, '11.StreetName-' + adminobj.streetname)
     listbox.insert(END,
                    '12.MajorMunicipality-' + adminobj.majormunicipality)
     listbox.insert(END, '13.Gov. District-' + adminobj.governingdistrict)
     listbox.insert(END, '14.PostalArea-' + adminobj.postalarea)
     listbox.insert(END, '15.Phone-' + adminobj.phone)
示例#5
0
    def register():
        global l_all_properties, l_error
        username_flag = 0
        if e2.get() and e4.get() and e5.get() and e7.get() and e9.get() and e10.get() and e11.get() and e12.get() and \
                e13.get() and e14.get() and e15.get() and e16.get() and e17.get() and e18.get() and e19.get() and e21.get():
            try:
                if l_all_properties is not None:
                    l_all_properties.grid_forget()
                if l_error is not None:
                    l_error.grid_forget()
                if e2.get():
                    if not UserDao.UserDao().check_if_user_exists(e2.get()):
                        Label(master, text="Username is available",
                              fg="green").grid(row=3, column=2)
                    else:
                        Label(master,
                              text="Username already exists!!",
                              fg="red").grid(row=3, column=2)
                        username_flag = 1
                else:
                    Label(master,
                          text="Username field is mandatory!!",
                          fg="red").grid(row=3, column=1)

                if e5.get():
                    if validate_email(e5.get()):
                        Label(master, text="Correct email ID",
                              fg="green").grid(row=6, column=2)
                    else:
                        Label(master,
                              text="primary mail is not correct",
                              fg="red").grid(row=6, column=2)
                else:
                    Label(master,
                          text="EmailID field is mandatory!!",
                          fg="red").grid(row=6, column=1)

                if e7.get():
                    if validate_email(e7.get()):
                        Label(master, text="Correct email ID",
                              fg="green").grid(row=8, column=2)
                    else:
                        Label(master,
                              text="secondaray mail is not correct",
                              fg="red").grid(row=8, column=2)
                else:
                    Label(master,
                          text="EmailID field is mandatory!!",
                          fg="red").grid(row=8, column=1)

                uid = int(e21.get())

                if uid == 1:
                    karma = 0
                    enduserobj = Entities.EndUser(karma, datetime.date.today(),
                                                  e2.get(), e4.get(), e5.get(),
                                                  e7.get(), e9.get(),
                                                  e10.get(), e11.get(),
                                                  e12.get(), e13.get(),
                                                  e14.get(), e15.get(),
                                                  e16.get(), e17.get(),
                                                  e18.get(), e19.get(), uid, 1)
                    proplist = HealthDataDao.HealthDataDao().read_properties()
                    ocount = len(proplist)
                    mcount = ocount
                    datumkey = random.randint(1, 100000)
                    if count1 != 0:
                        l_all_properties = Label(
                            master,
                            text="You have to add all properties!!",
                            fg="red")
                        l_all_properties.grid(row=41, column=1)
                    else:
                        if EndUserBL.EndUserBL().create_end_user(
                                enduserobj) is True:
                            while mcount > 0:
                                datumobj = Entities.Datum(
                                    datumkey, e2.get(),
                                    propidlist[ocount - mcount],
                                    propvallist[ocount - mcount],
                                    datetime.date.today())
                                EndUserBL.EndUserBL(
                                ).create_user_datum_mapping(datumobj)
                                datumkey += 1
                                mcount -= 1
                            Label(master, text="Registered!",
                                  fg="green").grid(row=40, column=1)
                            propvallist.clear()
                            propidlist.clear()
                            master.after(1000, lambda: Tk.destroy(master))
                elif uid == 2:
                    phone = e22.get()
                    modobj = Entities.Moderator(phone, e2.get(), e4.get(),
                                                e5.get(), e7.get(), e9.get(),
                                                e10.get(), e11.get(),
                                                e12.get(), e13.get(),
                                                e14.get(), e15.get(),
                                                e16.get(), e17.get(),
                                                e18.get(), e19.get(), uid, 1)
                    if Moderator_BL.ModeratorBL().create_moderator(
                            modobj, qual_list) is True:
                        Label(master, text="Registered!!",
                              fg="green").grid(row=40, column=1)
                        qual_list.clear()
                        master.after(1000, lambda: Tk.destroy(master))
                elif uid == 3:
                    phone = e22.get()
                    adminobj = Entities.Administrator(phone,
                                                      e2.get(), e4.get(),
                                                      e5.get(), e7.get(),
                                                      e9.get(), e10.get(),
                                                      e11.get(), e12.get(),
                                                      e13.get(), e14.get(),
                                                      e15.get(), e16.get(),
                                                      e17.get(), e18.get(),
                                                      e19.get(), uid, 1)
                    if AdministratorBL.AdministratorBL().create_administrator(
                            adminobj) is True:
                        Label(master, text="Registered!!",
                              fg="green").grid(row=40, column=1)
                        master.after(1000, lambda: Tk.destroy(master))
                else:
                    Label(
                        master,
                        text=
                        "Wrong Choice..should be integer number among (1-3)!!",
                        fg="red").grid(row=41, column=1)
            except Exception as e:
                if username_flag:
                    l_error = Label(master,
                                    text="Username is not unique!!",
                                    fg="red")
                    l_error.grid(row=41, column=1)
                elif "invalid literal for int() with base 10:" in str(e):
                    l_error = Label(master,
                                    text=str(e) + " Enter Integer value!!",
                                    fg="red")
                    l_error.grid(row=41, column=1)
                else:
                    l_error = Label(master, text=str(e), fg="red")
                    l_error.grid(row=41, column=1)
        else:
            Label(master, text="All user fields are mandatory!!",
                  fg="red").grid(row=42, column=1)
def call():
    datumkey = random.randint(1, 100000)
    username = input("Enter the username ")
    if not UserDao.UserDao().check_if_user_exists(username):
        password = input('Enter your password ')
        eid_1 = input("Enter the first email id ")
        eid_2 = input("Enter the second email id ")
        fname = input("Enter the first name ")
        lname = input("Enter the last name ")
        about_me = input("Tell us something about yourself ")
        url_1 = input("Enter the URL for your first profile photo ")
        url_2 = input("Enter the URL for your second profile photo ")
        url_3 = input("Enter the URL for your third profile photo ")
        street_num = input("Enter the street number ")
        street_name = input("Enter the street name ")
        major_municipality = input("Enter the major municipality ")
        gov_district = input("Enter the governing district ")
        post_area = input("Enter the postal area ")
        #status = int(input("Enter the status-Should be tinyint.. "))
        print("Which type of user do you wish to add?")
        print("1.End User 2.Moderator 3.Administrator")
        command_var_2 = int(input())
        if command_var_2 == 1:
            user_type_id = 1
            print('Enter the values for the following properties-')
            myproplist = HealthDataDao.HealthDataDao().read_properties()
            mypropidlist = []
            propvallist = []
            if myproplist is not None:
                for prop in myproplist:
                    mypropidlist.append(prop.propertyid)
                    print('Property id - ' + str(prop.propertyid) +
                          ' Property name - ' + prop.name +
                          ' Property description - ' + prop.description)
                looplen = len(myproplist)
                while looplen > 0:
                    propvallist.append(
                        int(input(
                            'Enter the value for the property in order')))
                    looplen -= 1
                karma = 0
                enduserobj = Entities.EndUser(
                    karma, datetime.date.today(), username, password, eid_1,
                    eid_2, fname, lname, about_me, url_1, url_2, url_3,
                    street_num, street_name, major_municipality, gov_district,
                    post_area, user_type_id, 1)
                olooplen = len(myproplist)
                mlooplen = len(myproplist)
                if EndUserBL.EndUserBL().create_end_user(enduserobj) is True:
                    while mlooplen > 0:
                        datumobj = Entities.Datum(
                            datumkey, username,
                            mypropidlist[olooplen - mlooplen],
                            propvallist[olooplen - mlooplen],
                            datetime.date.today())
                        EndUserBL.EndUserBL().create_user_datum_mapping(
                            datumobj)
                        datumkey += 1
                        mlooplen -= 1
                    print("Added!")
            else:
                print("No properties exist! Ask admin to add properties")
        elif command_var_2 == 2:
            user_type_id = 2
            emergency_no = input('Enter your emergency contact number ')
            no_of_qual = int(input('Enter count of the qualifications '))
            myquallist = QualificationDao.QualificationDao().readall()
            myinputlist = []
            if myquallist != None:
                print(
                    'Select from the following qualifications. If you want to add more to this list, contact the admin..'
                )
                for qual1 in myquallist:
                    print('Qualification id - ' + str(qual1.qualificationid) +
                          ' Description - ' + qual1.description)
                while no_of_qual > 0:
                    qualification_id = int(
                        input(
                            'Enter Qualification ID.Invalid ID will not lead to an entry in the database!!'
                        ))
                    if QualificationDao.QualificationDao().is_present(
                            qualification_id) is False:
                        print('Qualification id - ' + str(qualification_id) +
                              ' not present in Database ')
                    else:
                        for qual2 in myquallist:
                            if qual2.qualificationid == qualification_id:
                                myinputlist.append(qual2)
                    no_of_qual -= 1
                modobj = Entities.Moderator(emergency_no, username, password,
                                            eid_1, eid_2, fname, lname,
                                            about_me, url_1, url_2, url_3,
                                            street_num, street_name,
                                            major_municipality, gov_district,
                                            post_area, user_type_id, 1)
                Moderator_BL.ModeratorBL().create_moderator(
                    modobj, myinputlist)
                print("Added!")
            else:
                print(
                    "No qualification found! Ask the admin to add a qualification"
                )
        elif command_var_2 == 3:
            user_type_id = 3
            emergency_no = input("Enter your emergency contact number ")
            adminobj = Entities.Administrator(emergency_no, username, password,
                                              eid_1, eid_2, fname, lname,
                                              about_me, url_1, url_2, url_3,
                                              street_num, street_name,
                                              major_municipality, gov_district,
                                              post_area, user_type_id, 1)
            if AdministratorBL.AdministratorBL().create_administrator(
                    adminobj) is True:
                print("Added!")
    else:
        print('User name already exists! Try again')
        call()
def call(username):
    print('Welcome Administrator to SmartHealth')
    #username = input('Enter your username ')
    ainput1 = int(
        input(
            'How can we help you? 1.Display my details 2.Update my details 3.Add Qualification for moderator 4.Add Property for End User '
        ))
    if ainput1 == 1:
        adminobj = AdministratorBL.AdministratorBL().read_administrator(
            username)
        print('UserName-' + adminobj.username + ' Password-' +
              adminobj.password + ' FirstEmailID-' + adminobj.email1 +
              ' SecondEmailID-' + adminobj.email2 + ' FirstName-' +
              adminobj.firstname + ' LastName-' + adminobj.lastname +
              ' AboutYou-' + adminobj.aboutme + ' URL1-' + adminobj.photourl1 +
              ' URL2-' + adminobj.photourl2 + ' URL3-' + adminobj.photourl3 +
              ' StreetNumber-' + adminobj.streetnumber + ' StreetName-' +
              adminobj.streetname + ' MajorMunicipality-' +
              adminobj.majormunicipality + ' Gov. District-' +
              adminobj.governingdistrict + ' PostalArea-' +
              adminobj.postalarea + ' Phone-' + adminobj.phone)
    elif ainput1 == 2:
        adminobj = AdministratorBL.AdministratorBL().read_administrator(
            username)
        field_no = int(
            input(
                "Enter the field number that you wish to update:- 1.Password 2.FirstEmailId 3.SecondEmailId 4.FirstName 5.LastName 6.AboutMe 7.Url1 8.Url2 9.Url3 10.StreetNumber 11.StreetName 12.MajorMunicipality 13.GoverningDistrict 14.PostalArea 15.EmergencyContact"
            ))
        if field_no == 1:
            var = input("Enter the new value ")
            adminobj.password = var
        elif field_no == 2:
            var = input("Enter the new value ")
            adminobj.email1 = var
        elif field_no == 3:
            var = input("Enter the new value ")
            adminobj.email2 = var
        elif field_no == 4:
            var = input("Enter the new value ")
            adminobj.firstname = var
        elif field_no == 5:
            var = input("Enter the new value ")
            adminobj.lastname = var
        elif field_no == 6:
            var = input("Enter the new value ")
            adminobj.aboutme = var
        elif field_no == 7:
            var = input("Enter the new value ")
            adminobj.photourl1 = var
        elif field_no == 8:
            var = input("Enter the new value ")
            adminobj.photourl12 = var
        elif field_no == 9:
            var = input("Enter the new value ")
            adminobj.photourl13 = var
        elif field_no == 10:
            var = input("Enter the new value ")
            adminobj.streetnumber = var
        elif field_no == 11:
            var = input("Enter the new value ")
            adminobj.streetname = var
        elif field_no == 12:
            var = input("Enter the new value ")
            adminobj.majormunicipality = var
        elif field_no == 13:
            var = input("Enter the new value ")
            adminobj.governingdistrict = var
        elif field_no == 14:
            var = input("Enter the new value ")
            adminobj.postalarea = var
        elif field_no == 15:
            var = input("Enter the new value ")
            adminobj.phone = var
        if AdministratorBL.AdministratorBL().update_administrator(
                adminobj) is True:
            print('Updated!')
    elif ainput1 == 3:
        qual_id = random.randint(1, 1000)
        desc = input('Enter the desciption')
        qo = Entities.Qualification(qual_id, desc)
        if AdministratorBL.AdministratorBL().add_qual(qo) is True:
            print('Added!')
    elif ainput1 == 4:
        propid = random.randint(1, 1000)
        name = input("Enter name ")
        desc = input("Enter description ")
        po = Entities.Property(propid, name, desc)
        if AdministratorBL.AdministratorBL().add_property(po) is True:
            print('Added')