-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
81 lines (72 loc) · 2.59 KB
/
MainWindow.xaml.cs
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
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
namespace PhoneBookAlpha
{
/// <summary>
/// DB => Create a PhoneBook DB with PhoneBook table;
/// Table => Should have fields like, Id, Name, Contact Number
/// App => Menu contains an Action Tab ( INSERT, DELETE And Exit ) and a Help Tab with item as About Us.
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
public MainWindow()
{
InitializeComponent();
dataGrid.CanUserAddRows = false;
dataGrid.CanUserDeleteRows = false;
OpenConnection();
OnPropertyChanged();
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string caller = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(caller));
}
}
public void OpenConnection()
{
string connectionString = ConfigurationManager.ConnectionStrings["PhoneBookAlpha.Properties.Settings.PhoneBookConnectionString"].ConnectionString;
string query = "SELECT * FROM PhoneBook";
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlDataAdapter data = new SqlDataAdapter(query, connectionString))
{
DataTable dt = new DataTable();
data.Fill(dt);
dataGrid.ItemsSource = dt.DefaultView;
}
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void MenuItem_Click_1(object sender, RoutedEventArgs e)
{
// Insert Data
Window1 InsertDataWindow = new Window1();
InsertDataWindow.Show();
OnPropertyChanged();
}
private async void MenuItem_Click_2(object sender, RoutedEventArgs e)
{
//About Us
await Task.Run(() =>
{
MessageBox.Show(" Programmed By Abdul Mujeeb" + "\n\n Email : " + "[email protected]");
});
}
private void MenuItem_Click_3(object sender, RoutedEventArgs e)
{
// Delete the Item.
DeleteItemWindow Box = new DeleteItemWindow();
Box.Show();
OnPropertyChanged();
}
}
}