-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPage.xaml.cs
More file actions
176 lines (144 loc) · 5.43 KB
/
MainPage.xaml.cs
File metadata and controls
176 lines (144 loc) · 5.43 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace dbCon2
{
/// <summary>
/// Interaction logic for MainPage.xaml
/// </summary>
public partial class MainPage : Page
{
List<DBRecord> people = new List<DBRecord>();
public MainPage()
{
InitializeComponent();
VoiceOversListbox.ItemsSource = people;
VoiceOversListbox.DisplayMemberPath = "FullInfo";
}
//Shearhtype check box
private void SearchType_Checked(object sender, RoutedEventArgs e)
{
}
//Visable and Collapsing Deleting Button depends on listbox selection
private void VoiceOversListbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
EditButton.Visibility = Visibility.Collapsed;
if (VoiceOversListbox.SelectedItems != null)
{
DeleteButon.Visibility = Visibility.Visible;
}
else
{
DeleteButon.Visibility = Visibility.Collapsed;
}
}
//Search button
private void Search_Click(object sender, RoutedEventArgs e)
{
DataAccess db = new DataAccess();
people = db.GetPeople(Name.Text, Surname.Text, Phone.Text, Email.Text, SearchType.IsChecked.Value);
VoiceOversListbox.ItemsSource = people;
Status.Content = db.ExecuteStatus;
Status.Foreground = db.Color;
}
//Clear textboxes when doubleclick
private void Name_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
Name.Text = "";
}
private void Surname_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
Surname.Text = "";
}
private void Email_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
Email.Text = "";
}
private void Phone_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
Phone.Text = "";
}
//Reenter default texts to textboxex when empties
private void Name_LostFocus(object sender, RoutedEventArgs e)
{
if (Name.Text == "")
{
Name.Text = "Name";
}
}
private void Surname_LostFocus(object sender, RoutedEventArgs e)
{
if (Surname.Text == "")
{
Surname.Text = "Surname";
}
}
private void Email_LostFocus(object sender, RoutedEventArgs e)
{
if (Email.Text == "")
{
Email.Text = "Email";
}
}
private void Phone_LostFocus(object sender, RoutedEventArgs e)
{
if (Phone.Text == "")
{
Phone.Text = "Phone";
}
}
//Deleting button
private void DeleteButon_Click(object sender, RoutedEventArgs e)
{
List<int> selectedID = new List<int>();
foreach (object record in VoiceOversListbox.SelectedItems)
{
selectedID.Add(Convert.ToInt16(people[VoiceOversListbox.Items.IndexOf(record)].ID));
}
if (selectedID.Count() != 0)
{
DeleteItems deleting = new DeleteItems(selectedID);
//Research list after deleting
Search_Click(sender, e);
Status.Foreground = new SolidColorBrush(Colors.Green);
Status.Content = "Data removed successfully";
}
selectedID = null;
}
private void EditButton_Click(object sender, RoutedEventArgs e)
{
string idEdit = Convert.ToString(people[VoiceOversListbox.Items.IndexOf(VoiceOversListbox.SelectedItem)].ID);
DBRecordEdit recordEdit = new DBRecordEdit();
recordEdit.EditRecord(Name.Text, Surname.Text, Phone.Text, Email.Text, idEdit);
//Research list after deleting
Search_Click(sender, e);
}
private void VoiceOversListbox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//edit buttoon visability
if (VoiceOversListbox.SelectedItems.Count == 1)
{
EditButton.Visibility = Visibility.Visible;
Name.Text = Convert.ToString(people[VoiceOversListbox.Items.IndexOf(VoiceOversListbox.SelectedItem)].Name);
Surname.Text = Convert.ToString(people[VoiceOversListbox.Items.IndexOf(VoiceOversListbox.SelectedItem)].Surname);
Phone.Text = Convert.ToString(people[VoiceOversListbox.Items.IndexOf(VoiceOversListbox.SelectedItem)].Phone);
Email.Text = Convert.ToString(people[VoiceOversListbox.Items.IndexOf(VoiceOversListbox.SelectedItem)].Email);
}
else
{
EditButton.Visibility = Visibility.Collapsed;
}
}
}
}