-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomerFrame.xaml.cs
407 lines (355 loc) · 14.4 KB
/
CustomerFrame.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Shapes;
using MySql.Data.MySqlClient;
using System.Data;
using System.Windows.Navigation;
using System.Data.Common;
using System.ComponentModel;
using System.IO;
using System.Windows.Xps;
using System.Windows.Xps.Packaging;
using System.IO.Packaging;
using System.Windows.Markup;
using Microsoft.Win32;
using System.Collections;
using System.Windows.Controls.Primitives;
using System.Net;
using System.Threading;
using System.Windows.Forms.Integration;
namespace CheckCasher
{
/// <summary>
/// Interaction logic for NewInvoice.xaml
/// </summary>
public partial class CustomerFrame : Inv365Sortable
{
string table = "customers";
DataTable t = new DataTable();
string[] cols = new string[] { "Date", "TxnId", "Customer", "Amount", "Routing", "Account", "Check", "Bank"};
public static WebcamWindow w = new WebcamWindow();
public CustomerFrame()
{
InitializeComponent();
initTable(cols);
CustUtil.loadTxn(cols, t, customerCB.Text);
}
public override DataTemplate getUpTemplate()
{
return Resources["HeaderTemplateArrowUp"] as DataTemplate;
}
public override DataTemplate getDownTemplate()
{
return Resources["HeaderTemplateArrowDown"] as DataTemplate;
}
public override ListView getView()
{
return custView;
}
public CustomerFrame(bool billers)
{
InitializeComponent();
initTable(cols);
CustUtil.loadTxn(cols, t, customerCB.Text);
}
private void initTable(string [] acols)
{
for (int i = 0; i < acols.Length; i++)
{
DataColumn column = new DataColumn(acols[i]);
column.DataType = typeof(string);
t.Columns.Add(column);
}
t.Rows.Clear();
GridView gridview = new GridView();
for (int i = 0; i < acols.Length; i++)
{
GridViewColumn gvcolumn = new GridViewColumn();
gvcolumn.Width = 150;
gvcolumn.Header = acols[i];
gvcolumn.DisplayMemberBinding = new Binding(acols[i]);
gridview.Columns.Add(gvcolumn);
}
custView.View = gridview;
Binding bind = new Binding();
custView.DataContext = t;
custView.SetBinding(ListView.ItemsSourceProperty, bind);
}
private void Window_Initialized(object sender, EventArgs e)
{
string str = "select distinct id from customers order by id";
DbDataReader rdr = DB.getInstance().ExecuteQuery(str);
while (rdr.Read()) {
customerCB.Items.Add(rdr.GetString(0));
}
rdr.Close();
DB.getInstance().close();
FocusHelper.Focus(customerID);
//customerCB.Focus();
}
private void savecustomer_Click(object sender, RoutedEventArgs e)
{
string _id = customerCB.Text;
string _fn = firstName.Text;
string _ln = lastName.Text;
string _street1 = street1.Text;
string _street2 = street2.Text;
string _city = city.Text;
string _state = state.Text;
string _zip = zip.Text;
string _phone = phone.Text;
Object _dob = null;
if(!(String.IsNullOrEmpty(dob.Text))) {
try{
_dob = DateTime.Parse(dob.Text).ToString();
} catch(Exception ee) {
}
}
string _ssn = ssn.Text;
string _height = height.Text;
string _weight = weight.Text;
Hashtable t = new Hashtable();
t["city"] = "'" + _city + "'";
t["state"] = "'" + _state + "'";
t["zip"] = "'" + _zip + "'";
t["phone"] = "'" + _phone + "'";
t["street1"] = "'" + _street1 + "'";
t["street2"] = "'" + _street2 + "'";
t["fname"] = "'" + _fn + "'";
t["lname"] = "'" + _ln + "'";
t["id"] = "'" + _id + "'";
t["ssn"] = "'" + _ssn + "'";
t["dob"] = "'" + _dob + "'";
t["height"] = "'" + _height + "'";
t["weight"] = "'" + _weight + "'";
t["status"] = "1";
ArrayList l = new ArrayList();
l.Add("'" + _city + "'");
l.Add("'" + _state + "'");
l.Add("'" + _phone + "'");
l.Add("'" + _street1 + "'");
l.Add("'" + _street2 + "'");
l.Add("'" + _fn + "'");
l.Add("'" + _ln + "'");
l.Add("'" + _zip + "'");
l.Add("'" + _id + "'");
l.Add("'" + _ssn + "'");
l.Add("'" + _dob + "'");
l.Add("'" + _height + "'");
l.Add("'" + _weight + "'");
l.Add("null");
l.Add("null");
l.Add(1);
if (_id == null || _id.Trim().Length != 11)
{
MessageBox.Show("Customer ID must be 11 characters");
return;
}
string str = DB.getInstance().getUpdateString(t, table, " where id='" + _id + "'");
int ret = DB.getInstance().ExecuteNonQuery(str);
if (ret == 0)
{
str = DB.getInstance().getInsertString(l, table);
ret = DB.getInstance().ExecuteNonQuery(str);
if (ret == 0)
{
MessageBox.Show("Please enter required fields (first name, last name, company, street1, city, state) ");
return;
}
}
w.custID = customerCB.Text;
w.isCheck = false;
//w.webcam.Start();
w.ShowDialog();
mn.ShowDialog();
mn.Close();
if(!(string.IsNullOrEmpty(mn._tempImageName))) {
BitmapImage img1 = new BitmapImage();
img1.BeginInit();
img1.UriSource = new Uri(mn._tempImageName);
img1.EndInit();
JpegBitmapEncoder encoder = Helper.GetImage(img1);
MemoryStream bas = new MemoryStream();
encoder.Save(bas);
string qry = "update customers set license=@license where id='" + _id + "'";
DB.getInstance().UpdateImage(qry, bas.GetBuffer(), "@license");
bas.Close();
}
MessageBoxResult res = MessageBox.Show("Do you want to cash the check?", "Cash Check?", MessageBoxButton.YesNo);
this.NavigationService.RemoveBackEntry();
if (res == MessageBoxResult.Yes)
{
this.NavigationService.Navigate(CashCheck.Get(_id,true));
}
else
this.NavigationService.Navigate(new CustomerFrame(false));
}
DLFrontFaceScanDemo.frmMain mn = new DLFrontFaceScanDemo.frmMain();
private void custCB_SelectedValueChanged(object sender, EventArgs e)
{
this.Background = Brushes.White;
flag.Content = "Flag As Bad";
imgCapture.Source = null;
licenseCapture.Source = null;
string item = (string)customerCB.SelectedItem;
DbDataReader rdr = null;
rdr = DB.getInstance().ExecuteQuery(
"select id,phone,fname,lname,street1,street2,city,state,zip,dob,ssn,height,weight,status,picture,license from customers where id='" + item + "'");
if (rdr.Read())
{
int i = 0;
customerCB.Text = rdr.GetString(i++);
phone.Text = rdr.GetString(i++);
firstName.Text = rdr.GetString(i++);
lastName.Text = rdr.GetString(i++);
street1.Text = rdr.GetString(i++);
street2.Text = rdr.GetString(i++);
city.Text = rdr.GetString(i++);
state.Text = rdr.GetString(i++);
//dob.Text = rdr.GetString(i++);
//ssn.Text = rdr.GetString(i++);
zip.Text = rdr.GetString(i++);
dob.Text = rdr.GetDateTime(i++).ToString("MM/dd/yyyy");
ssn.Text = rdr.GetString(i++);
height.Text = rdr.GetString(i++);
weight.Text = rdr.GetString(i++);
int stat = rdr.GetInt32(i++);
if (stat < 1)
{
this.Background = Brushes.Red;
flag.Content = "Unflag";
}
if (!(rdr.IsDBNull(i)))
imgCapture.Source = CustUtil.GetImage(rdr, i);
i++;
if (!(rdr.IsDBNull(i)))
licenseCapture.Source = CustUtil.GetImage(rdr, i);
}
rdr.Close();
CustUtil.loadTxn(cols, t, customerCB.Text);
DB.getInstance().close();
}
private void deleteCustomer_Click(object sender, RoutedEventArgs e)
{
if (custView.SelectedIndex == -1) return;
if (System.Windows.Forms.MessageBox.Show("Really delete?", "Confirm delete", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
DB.getInstance().ExecuteNonQuery(
"delete from "+table+" where id='" + customerCB.Text + "'");
t.Rows[custView.SelectedIndex].Delete();
custView.SelectedIndex = -1;
this.NavigationService.RemoveBackEntry();
this.NavigationService.Navigate(new CustomerFrame(false));
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
}
private void custView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DataRow r = t.Rows[custView.SelectedIndex];
this.NavigationService.RemoveBackEntry();
this.NavigationService.Navigate(CashCheck.Get(""+r[1]+"", 1));
}
private void button1_Click_1(object sender, RoutedEventArgs e)
{
if (!HomeWindow.IsAdmin())
{
MessageBox.Show("You must be logged in as administrator to perform this operation.");
return;
}
if (customerCB.Text.Trim().Length != 11)
{
MessageBox.Show("Customer ID must be 11 characters");
return;
}
System.Diagnostics.Process.Start("http://instantofac.com/search.php?input_string="+firstName.Text);
//WebBrowser wb = new WebBrowser();
//wb.Document = new
//MessageBox.Show("Customer not found in terrorist list");
}
private void flag_Click(object sender, RoutedEventArgs e)
{
if (!HomeWindow.IsAdmin())
{
MessageBox.Show("You must be logged in as administrator to perform this operation.");
return;
}
if (customerCB.Text.Trim().Length != 11)
{
MessageBox.Show("Customer ID must be 11 characters");
return;
}
string qry = "";
string cnt = flag.Content.ToString();
if ("Unflag" == cnt)
qry = "update customers set status=1 where id='" + customerCB.Text + "'";
else
qry = "update customers set status=0 where id='" + customerCB.Text + "'";
DB.getInstance().ExecuteNonQuery(qry);
DB.getInstance().close();
if ("Unflag" == cnt)
{
this.Background = Brushes.White;
flag.Content = "Flag As Bad";
}
else
{
this.Background = Brushes.Red;
flag.Content = "Unflag";
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
//MessageBoxResult res = MessageBox.Show("Do you want to cash the check?", "Cash Check?", MessageBoxButton.YesNo);
this.NavigationService.RemoveBackEntry();
this.NavigationService.Navigate(CashCheck.Get(customerCB.Text, true));
}
private void dob_KeyUp(object sender, KeyEventArgs e)
{
//dob.Text = DateTime.TryParse(dob.Text).ToString("mm/dd/yyyy");
}
private void button3_Click(object sender, RoutedEventArgs e)
{
this.NavigationService.RemoveBackEntry();
this.NavigationService.Navigate(new CustomerFrame());
}
private void customerID_GotFocus(object sender, RoutedEventArgs e)
{
//customerCB.Focus();
}
private void customerCB_GotFocus(object sender, EventArgs e)
{
//MessageBox.Show("got focus");
}
}
static class FocusHelper
{
private delegate void MethodInvoker();
public static void Focus(UIElement element)
{
//Focus in a callback to run on another thread, ensuring the main UI thread is initialized by the
//time focus is set
ThreadPool.QueueUserWorkItem(delegate(Object foo)
{
UIElement elem = (UIElement)foo;
elem.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
(MethodInvoker)delegate()
{
elem.Focus();
((WindowsFormsHost)elem).Child.Focus();
//Keyboard.Focus(((WindowsFormsHost)elem).Child);
});
}, element);
}
}
}