0
1
00:00:04,433 --> 00:00:05,630
<v Instructor>Hello again</v>
1

2
00:00:05,630 --> 00:00:07,530
In previous lecture we learned how we can
2

3
00:00:07,530 --> 00:00:11,180
update our Persons, right? And now in this lecture,
3

4
00:00:11,180 --> 00:00:13,430
we are going to learn how we can delete a person
4

5
00:00:13,430 --> 00:00:16,540
from our database. To do that what I need to do.
5

6
00:00:16,540 --> 00:00:20,910
Here let's go to find our button. It is here.
6

7
00:00:20,910 --> 00:00:25,660
My-People, right? And must be somewhere here buttons
7

8
00:00:25,660 --> 00:00:29,090
and btn delete it is here OK. So, here I will create
8

9
00:00:30,680 --> 00:00:33,857
and to use "Command" property for  my button
9

10
00:00:33,857 --> 00:00:37,073
I will say "self.funcDeletePerson" OK.
10

11
00:00:40,464 --> 00:00:45,070
And now what I need to do, and to create this function,
11

12
00:00:45,070 --> 00:00:50,070
and it will be here "def funcDeletePerson".
12

13
00:00:51,559 --> 00:00:55,250
OK, so for deleting, what I need to do, I don't need
13

14
00:00:55,250 --> 00:00:59,730
to create a class or new page OK, a function is more
14

15
00:00:59,730 --> 00:01:04,630
than enough for that OK. And here what I need to do,
15

16
00:01:04,630 --> 00:01:07,960
because we not use a new window OK, that's why we will
16

17
00:01:07,960 --> 00:01:11,940
only hit the button and ask the user: Are you sure
17

18
00:01:11,940 --> 00:01:15,210
to delete this person? Yes or No. If Yes, we will
18

19
00:01:15,210 --> 00:01:17,323
delete this person from our database OK.
19

20
00:01:17,323 --> 00:01:19,997
To that what I need to do here, I need to say again
20

21
00:01:19,997 --> 00:01:23,447
"Selected_item=self.listBox.curselection"
21

22
00:01:34,760 --> 00:01:38,330
Because user will make a choice a right. So which item
22

23
00:01:38,330 --> 00:01:41,200
is that item and after here what I need to say,
23

24
00:01:41,200 --> 00:01:45,287
like before I will say, "person=self.listBox.get"
24

25
00:01:51,120 --> 00:01:53,373
and here I will say selected item.
25

26
00:01:54,630 --> 00:01:57,920
And after that I need  to find ID, my person ID,
26

27
00:01:57,920 --> 00:01:59,810
which person I will delete, right?
27

28
00:01:59,810 --> 00:02:02,910
Person ID is equal to person
28

29
00:02:04,550 --> 00:02:09,550
split by again, I will split by dash OK.
29

30
00:02:09,600 --> 00:02:12,010
And for ID, what I need to do, I need to
30

31
00:02:12,010 --> 00:02:16,000
use first index, Right? it is zero. OK
31

32
00:02:16,000 --> 00:02:18,580
So, now I have my ID, I know which person
32

33
00:02:18,580 --> 00:02:21,340
I will delete from my database, right?
33

34
00:02:21,340 --> 00:02:24,780
What I need to do here, I will create a message box
34

35
00:02:24,780 --> 00:02:29,117
and I will say, "mbox=messagebox.askquestion" OK.
35

36
00:02:34,810 --> 00:02:39,030
And the first will be our title again, "Warning"
36

37
00:02:39,030 --> 00:02:42,437
and say here for title and second parameter will be
37

38
00:02:42,437 --> 00:02:47,437
"Are you sure to delete this person"
38

39
00:02:48,190 --> 00:02:53,120
and the last one we can use icon and for icon I will say
39

40
00:02:53,120 --> 00:02:56,716
is equal to warning OK. Warning icon.
40

41
00:02:56,716 --> 00:03:01,716
OK, now what we will do, if yes, I mean if user
41

42
00:03:02,144 --> 00:03:05,000
press yes button, we need to say here
42

43
00:03:05,000 --> 00:03:10,000
if mbox value is equal equal to yes, OK.
43

44
00:03:13,600 --> 00:03:15,493
if it is yes, what we will do
44

45
00:03:15,493 --> 00:03:18,010
we need to delete this person, right?
45

46
00:03:18,010 --> 00:03:21,923
And here I will say, try and then except.
46

47
00:03:24,560 --> 00:03:28,820
For except, for now let's say pass OK, and now let's
47

48
00:03:28,820 --> 00:03:32,950
delete our person. Here I will say "cur.execute" OK,
48

49
00:03:35,730 --> 00:03:40,370
and I will use delete query from my table name "persons",
49

50
00:03:43,840 --> 00:03:48,840
right? Where "person_id=?" OK.
50

51
00:03:55,130 --> 00:03:56,963
And after that here, what I need to do,
51

52
00:03:58,670 --> 00:04:01,160
after parentheses, I need to use comma
52

53
00:04:01,160 --> 00:04:03,323
and again parentheses and I will say,
53

54
00:04:04,250 --> 00:04:07,450
Person, I got something wrong here. Let me check.
54

55
00:04:07,450 --> 00:04:12,020
Sorry not like that. Here comma and after that here
55

56
00:04:12,020 --> 00:04:16,903
I will say parentheses and another one is also here OK.
56

57
00:04:18,730 --> 00:04:23,730
And now here I will say, person ID, OK and again comma
57

58
00:04:24,580 --> 00:04:27,710
OK don't forget to put comma at end of the person ID.
58

59
00:04:27,710 --> 00:04:32,710
And what I need to do now, I need to say "con.commit" OK
59

60
00:04:33,040 --> 00:04:35,870
and after that now, I will show a message box,
60

61
00:04:35,870 --> 00:04:39,067
I will say "messagebox.showinfo("Success")" and here
61

62
00:04:44,811 --> 00:04:48,811
my message will be "Person has been deleted" OK.
62

63
00:04:54,310 --> 00:04:59,310
And after that here, I will say, self-dot-destroy, sorry
63

64
00:05:02,098 --> 00:05:05,283
Actually we don't need to say, we can keep this window OK
64

65
00:05:05,283 --> 00:05:09,443
and something wrong here, let me check. Con-dot-commit
65

66
00:05:14,560 --> 00:05:18,500
and for except, what I will say, I will use another message.
66

67
00:05:18,500 --> 00:05:23,293
OK, message box here and I will say "messagebox.showinfo"
67

68
00:05:26,540 --> 00:05:31,540
and here I will say "Info", "Person has not been deleted"
68

69
00:05:42,010 --> 00:05:45,840
OK, if any error we will show this message, if not,
69

70
00:05:45,840 --> 00:05:50,260
we will show this message OK. And let's run our application.
70

71
00:05:50,260 --> 00:05:55,260
Main, right and run, My-People let's add a new record OK
71

72
00:05:58,150 --> 00:06:03,150
Add, so here I will say new, record or person and here
72

73
00:06:08,380 --> 00:06:13,380
new@msn.com. For phone number, something like that and for address
73

74
00:06:14,340 --> 00:06:17,270
something else is enough. Add person now.
74

75
00:06:17,270 --> 00:06:19,940
And now let's go back to our person.
75

76
00:06:19,940 --> 00:06:24,230
Here My-People, new record is here. I will say, delete.
76

77
00:06:24,230 --> 00:06:27,040
As you see, it says are you sure to delete this person,
77

78
00:06:27,040 --> 00:06:29,950
I will say No. You see nothing happens but
78

79
00:06:29,950 --> 00:06:33,920
if I say yes, delete, yes, as you see
79

80
00:06:35,140 --> 00:06:38,530
person has been deleted from our database.
80

81
00:06:38,530 --> 00:06:43,430
And now actually we can yes, we can say 
81

82
00:06:46,460 --> 00:06:48,830
Actually it is better if you say "self.destroy"
82

83
00:06:48,830 --> 00:06:51,400
because our new record is still here, right?
83

84
00:06:51,400 --> 00:06:55,400
So here, but if I click My-People, you see
84

85
00:06:55,400 --> 00:06:59,450
our new record is not here. So what we need to do here,
85

86
00:06:59,450 --> 00:07:04,400
we need to go here to find my people and here after
86

87
00:07:04,400 --> 00:07:08,000
deleting my person I will say "self.destroy", this is better
87

88
00:07:10,400 --> 00:07:15,053
and now is fine. Let's run it again and I will say run,
88

89
00:07:15,920 --> 00:07:20,520
My-People, add new, something new and here I will say
89

90
00:07:22,630 --> 00:07:25,660
take it here somewhere OK, and here let's say
90

91
00:07:25,660 --> 00:07:30,660
again new, record and you need something like that
91

92
00:07:31,050 --> 00:07:33,980
for phone number, let say something like that
92

93
00:07:33,980 --> 00:07:38,963
and Add-Person is fine. Now close this one.
93

94
00:07:39,820 --> 00:07:43,720
And our record is here. Now I will say delete.
94

95
00:07:43,720 --> 00:07:48,710
Are you sure? Yes. OK and you see that "self.destroy"
95

96
00:07:48,710 --> 00:07:53,430
is also working. And that's all for this lesson.
96

97
00:07:53,430 --> 00:07:58,430
In next lesson we are going to create our About-Us page.
97

98
00:07:58,480 --> 00:08:02,010
For this button we'll create a new Python file and after that
98

99
00:08:02,010 --> 00:08:04,343
we will finish our project. For now, that's all.
99

100
00:08:04,343 --> 00:08:05,453
See you in the next.
