Exemple #1
0
 def read_datum(self, username):
     myflag = 0
     mydatumlist = []
     con = mysql.connector.connect(user='******',
                                   password='******',
                                   host='127.0.0.1',
                                   database='smarthealthdb')
     cursor = con.cursor(buffered=True)
     try:
         query = ("select * from smarthealthdb.datum")
         cursor.execute(query)
         if cursor.rowcount > 0:
             result = cursor.fetchall()
             for row in result:
                 if row[1] == username:
                     myflag = 1
                     myboj = Entities.Datum(row[0], row[1], row[2], row[3],
                                            row[4])
                     mydatumlist.append(myboj)
             if myflag == 0:
                 return None
             else:
                 return mydatumlist
         else:
             return None
     except Exception as e:
         raise
     finally:
         cursor.close()
 def updatedatum():
     if e3.get() and e4.get() and e5.get():
         try:
             did = int(e3.get())
             pid = int(e4.get())
             val = e5.get()
             do = Entities.Datum(did, username, pid, val,
                                 datetime.date.today())
             if EndUserBL.EndUserBL().update_datum(do) is True:
                 Label(master, text="Updated").grid(row=10, column=2)
             else:
                 Label(master, text="Not Updated").grid(row=10, column=2)
         except Exception as e:
             Label(
                 master,
                 text=
                 "Both fields (Datum Id and Product Id) must be integers!!",
                 fg="red").grid(row=10, column=1)
     else:
         Label(master,
               text=
               "All fields (Datum Id, Property Id, Value) are mandatory!!",
               fg="red").grid(row=10, column=1)
Exemple #3
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(username):
    print('Welcome EndUser to SmartHealth')
    #username = input('Enter your username ')
    einput1 = int(
        input(
            'How can we help you? 1.Display my details 2.Update my details 3.Visit friendship portal 4.Visit Discussion Forum'
        ))
    if einput1 == 1:
        retlist = EndUserBL.EndUserBL().read_end_user(username)
        euobj = retlist[0]
        datumlist = retlist[1]
        print('UserName-' + euobj.username + ' Password-' + euobj.password +
              ' FirstEmailID-' + euobj.email1 + ' SecondEmailID-' +
              euobj.email2 + ' FirstName-' + euobj.firstname + ' LastName-' +
              euobj.lastname + ' AboutYou-' + euobj.aboutme + ' URL1-' +
              euobj.photourl1 + ' URL2-' + euobj.photourl2 + ' URL3-' +
              euobj.photourl3 + ' StreetNumber-' + euobj.streetnumber +
              ' StreetName-' + euobj.streetname + ' MajorMunicipality-' +
              euobj.majormunicipality + ' Gov. District-' +
              euobj.governingdistrict + ' PostalArea-' + euobj.postalarea +
              ' Karma-' + str(euobj.karma))
        print('Following is the Activity Mapping with legend..')
        for d in datumlist:
            print('Property ID-' + str(d.propertyid) + ' Value-' + d.value)
        print(
            '*************************************************************************************************************'
        )
        print('Properties in Database-')
        myproplist = HealthDataDao.HealthDataDao().read_properties()
        for prop in myproplist:
            print('Property id - ' + str(prop.propertyid) +
                  ' Property name - ' + prop.name +
                  ' Property description - ' + prop.description)
    elif einput1 == 2:
        retlist = EndUserBL.EndUserBL().read_end_user(username)
        euobj = retlist[0]
        datumlist = retlist[1]
        einput2 = int(
            input('What do you wish to update? 1.Basic details 2.Activities'))
        if einput2 == 1:
            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"
                ))
            if field_no == 1:
                var = input("Enter the new value ")
                euobj.password = var
            elif field_no == 2:
                var = input("Enter the new value ")
                euobj.email1 = var
            elif field_no == 3:
                var = input("Enter the new value ")
                euobj.email2 = var
            elif field_no == 4:
                var = input("Enter the new value ")
                euobj.firstname = var
            elif field_no == 5:
                var = input("Enter the new value ")
                euobj.lastname = var
            elif field_no == 6:
                var = input("Enter the new value ")
                euobj.aboutme = var
            elif field_no == 7:
                var = input("Enter the new value ")
                euobj.photourl1 = var
            elif field_no == 8:
                var = input("Enter the new value ")
                euobj.photourl12 = var
            elif field_no == 9:
                var = input("Enter the new value ")
                euobj.photourl13 = var
            elif field_no == 10:
                var = input("Enter the new value ")
                euobj.streetnumber = var
            elif field_no == 11:
                var = input("Enter the new value ")
                euobj.streetname = var
            elif field_no == 12:
                var = input("Enter the new value ")
                euobj.majormunicipality = var
            elif field_no == 13:
                var = input("Enter the new value ")
                euobj.governingdistrict = var
            elif field_no == 14:
                var = input("Enter the new value ")
                euobj.postalarea = var
            if EndUserBL.EndUserBL().update_end_user(euobj) is True:
                print('Updated!')
        elif einput2 == 2:
            retlist = EndUserBL.EndUserBL().read_end_user(username)
            euobj = retlist[0]
            datumlist = retlist[1]
            print('UserName-' + euobj.username + ' Password-' +
                  euobj.password + ' FirstEmailID-' + euobj.email1 +
                  ' SecondEmailID-' + euobj.email2 + ' FirstName-' +
                  euobj.firstname + ' LastName-' + euobj.lastname +
                  ' AboutYou-' + euobj.aboutme + ' URL1-' + euobj.photourl1 +
                  ' URL2-' + euobj.photourl2 + ' URL3-' + euobj.photourl3 +
                  ' StreetNumber-' + euobj.streetnumber + ' StreetName-' +
                  euobj.streetname + ' MajorMunicipality-' +
                  euobj.majormunicipality + ' Gov. District-' +
                  euobj.governingdistrict + ' PostalArea-' + euobj.postalarea +
                  ' Karma-' + str(euobj.karma))
            print('Following is the Activity Mapping with legend..')
            for d in datumlist:
                print('Datum ID-' + str(d.datumid) + ' Property ID-' +
                      str(d.propertyid) + ' Value-' + d.value)
            print(
                '*************************************************************************************************************'
            )
            print('Properties in Database-')
            myproplist = HealthDataDao.HealthDataDao().read_properties()
            for prop in myproplist:
                print('Property id - ' + str(prop.propertyid) +
                      ' Property name - ' + prop.name +
                      ' Property description - ' + prop.description)
            print(
                '*************************************************************************************************************'
            )
            print(
                'To update activity, simply insert the  Datum ID,Property ID and its new value'
            )
            did = int(input('Enter the DatumID'))
            pid = int(input('Enter the PropertyID'))
            val = input('Enter value')
            do = Entities.Datum(did, username, pid, val, datetime.date.today())
            if EndUserBL.EndUserBL().update_datum(do) is True:
                print('Updated!')
    elif einput1 == 3:
        FriendshipMain.call(username)
    elif einput1 == 4:
        EndUserDiscussionForumMain.call(username)
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()