-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomepage.xaml.cs
288 lines (233 loc) · 8.15 KB
/
Homepage.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
using System;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Data.SqlClient;
using System.Data;
using Money_Savings_Tool.All_Menu;
using Microsoft.Win32;
using System.IO;
namespace Money_Savings_Tool
{
/// <summary>
/// Interaction logic for Homepage.xaml
/// </summary>
public partial class Homepage : Window
{
bool check = false;
string Image_Serial;
string EMAIL;
static string GetBalance, GetName;
int img_srl;
DatabaseConnection db = new DatabaseConnection();
DateTime date = DateTime.Now;
string CreatePath ,AccessPath;
// Window mainWindow=new Window();
public Homepage(string Email)//
{
EMAIL = Email;
InitializeComponent();
Date_Time.Content = date;
Get_Balance();
Get_Name();
SetName.Content = "Name : "+GetName;
SetBalance.Content = "Current Balance : "+GetBalance;
Get_Image_Serial();
img_srl = Convert.ToInt32(Image_Serial);
Settings s = new Settings(EMAIL);
string loc = @"D:\Money_Savings_Tool\Media\" + EMAIL + "(" + img_srl + ")" + ".png";
checkPath();
}
void checkPath()
{
CreatePath = @"D:\Money_Savings_Tool\Media\" + EMAIL + @"\";
if (!Directory.Exists(CreatePath))
{
Directory.CreateDirectory(CreatePath);
}
AccessPath = @"D:\Money_Savings_Tool\Media\" + EMAIL + @"\" + "(" + img_srl + ")" + ".png";
if (File.Exists(AccessPath))
{
Uri fileUri = new Uri(AccessPath);
ImageBox.Source = new BitmapImage(fileUri);
Upload_BTN.Visibility = Visibility.Hidden;
}
else
{
string loc2 = @"D:\Money_Savings_Tool\Media\Default pic.png";
Uri fileUri = new Uri(loc2);
ImageBox.Source = new BitmapImage(fileUri);
}
}
void Get_Name()
{
string sql = "select * from Registration where Email like '" + EMAIL + "' ";
db.command= new SqlCommand(sql, db.con);
SqlDataReader reader = db.command.ExecuteReader();
reader.Read();
GetName = reader["Name"].ToString();
reader.Close();
Console.WriteLine("This name is " + GetName);
}
void Get_Balance()
{
string sql = "select * from curr_balance where Email like '" + EMAIL + "' ";
SqlCommand command = new SqlCommand(sql, db.con);
DataTable dt = new DataTable();
dt.Load(command.ExecuteReader());
try
{
GetBalance = dt.Rows[0]["Balance"].ToString();
Console.WriteLine("Balance mane taka: " + GetBalance);
}
catch (Exception)
{
GetBalance = "0";
Console.WriteLine("Couldnt find");
}
}
void Get_Image_Serial()
{
string sql = "select * from Image_Control where Email like '" + EMAIL + "' ";
SqlCommand command = new SqlCommand(sql, db.con);
DataTable dt = new DataTable();
dt.Load(command.ExecuteReader());
try
{
Image_Serial = dt.Rows[0]["Image_Serial"].ToString();
}
catch (Exception)
{
check = true;
// Image_Serial = "0";
}
}
private void Exit_Button(object sender, RoutedEventArgs e)
{
string messageBoxText = "Do you really want to close?";
string caption = "Closing Application";
MessageBoxButton button = MessageBoxButton.YesNoCancel;
MessageBoxImage icon = MessageBoxImage.Warning;
// MessageBox.Show(messageBoxText, caption, button, icon);
MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
// Process message box results
switch (result)
{
case MessageBoxResult.Yes:
Application.Current.Shutdown();
break;
}
}
private void Expense_Button(object sender, RoutedEventArgs e)
{
Expense obj = new Expense(EMAIL);
this.Hide();
obj.Show();
}
private void Transaction_History_Button(object sender, RoutedEventArgs e)
{
Transaction_History obj = new Transaction_History(EMAIL);
this.Hide();
obj.Show();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Due_Balance d = new Due_Balance(EMAIL);
this.Hide();
d.Show();
}
private void Help_Click(object sender, RoutedEventArgs e)
{
Help h = new Help(EMAIL);
this.Hide();
h.Show();
}
private void About_Click(object sender, RoutedEventArgs e)
{
About a = new About(EMAIL);
this.Hide();
a.Show();
}
private void SignOut_Click(object sender, RoutedEventArgs e)
{
Login l = new Login();
this.Hide();
l.Show();
}
private void UserManual_Click(object sender, RoutedEventArgs e)
{
UserManual user = new UserManual(EMAIL);
this.Hide();
user.Show();
}
private void Settings_Click(object sender, RoutedEventArgs e)
{
Settings p = new Settings(EMAIL);
this.Hide();
p.Show();
}
void Insert_Image_Serial()
{
try
{
string sql = "insert into Image_Control (Email,Image_Serial) values('" + EMAIL + "','" + img_srl + "') ";
SqlCommand command = new SqlCommand(sql, db.con);
command.ExecuteNonQuery();
}
catch (Exception E)
{
MessageBox.Show("Here is error "+E.Message);
}
}
void Update_Image_Serial()
{
try
{
string sql = "Update Image_Control set Image_Serial='" + img_srl + "'";
SqlCommand command = new SqlCommand(sql, db.con);
command.ExecuteNonQuery();
}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
}
private void Upload_Picture(object sender, RoutedEventArgs e)
{
// img_srl++;
try
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == true)
{
Uri fileUri = new Uri(openFileDialog.FileName);
ImageBox.Source = new BitmapImage(fileUri);
File.Copy(openFileDialog.FileName, @"D:\Money_Savings_Tool\Media\" + EMAIL + @"\" +"("+img_srl+")"+ ".png", true);
}
}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
if (check == true)
{
Insert_Image_Serial();
}
else
{
Update_Image_Serial();
}
}
private void Savings_Goal(object sender, RoutedEventArgs e)
{
Savings_Goal s = new Savings_Goal(EMAIL);
this.Hide();
s.Show();
}
private void Cash_In_Button(object sender, RoutedEventArgs e)
{
Cash_In obj = new Cash_In(EMAIL);
this.Hide();
obj.Show();
}
}
}