/
ReadAttendance.xaml.cs
149 lines (119 loc) · 4.89 KB
/
ReadAttendance.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
using DMSIPayroll.Model;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
namespace DMSIPayroll
{
/// <summary>
/// Interaction logic for ReadAttendance.xaml
/// </summary>
public partial class ReadAttendance : MetroWindow
{
List<DMSIClass.Attendance> lAttendance = new List<DMSIClass.Attendance>();
public ReadAttendance()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
private void button_Click(object sender, RoutedEventArgs e)
{
try
{
List<string> lString = new List<string>();
string path = "";
string line = "";
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == true)
{
path = openFileDialog.FileName;
}
else
{
return;
}
if (path != null)
{
var m_readFile = new StreamReader(path);
List<string> list = new List<string>();
while ((line = m_readFile.ReadLine()) != null)
{
string[] columns = line.Split(',');
foreach (var x in columns)
{
DMSIClass.Attendance attendance = new DMSIClass.Attendance();
var punctuation = x.Where(Char.IsPunctuation).Distinct().ToArray();
var test = punctuation.Where(m => !string.IsNullOrEmpty(x.Trim()));
var words = x.Split().Select(y => y.Trim(punctuation)).Where(m => !string.IsNullOrEmpty(m.Trim())).ToArray();
if (words.Length != 1)
{
attendance.ID = words[0];
attendance.Date = words[1];
attendance.Time = words[2];
attendance.Mode = words[4];
lAttendance.Add(attendance);
}
}
}
datagridview.ItemsSource = lAttendance.OrderByDescending(m=>m.Date).ThenByDescending(x=>x.Time).ToList();
}
}
catch (Exception)
{
MessageBox.Show("Something went wrong.", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
{
}
private async void btnSave_Click(object sender, RoutedEventArgs e)
{
try
{
using (var db = new DMSIPayrollEntities())
{
MessageDialogResult mdr = await this.ShowMessageAsync("READ", "ARE YOU SURE YOU WANT TO SAVE THIS ATTENDANCE?", MessageDialogStyle.AffirmativeAndNegative);
if (mdr == MessageDialogResult.Affirmative)
{
foreach (var x in lAttendance.Where(m=>m.ID == "8166"))
{
DateTime datetime = DateTime.ParseExact(x.Date + " " + x.Time, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
BiometricsLog bio = new BiometricsLog();
bio.BiometricsID = Convert.ToInt32(x.ID);
bio.DTime = datetime;
bio.Mode = Convert.ToInt32(x.Mode);
db.BiometricsLogs.Add(bio);
db.SaveChanges();
}
MessageBox.Show("Saving Succesful", "System Succes!", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
}
catch (Exception)
{
MessageBox.Show("Something went wrong.", "System Error!", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
//private void tbSearch_KeyDown(object sender, KeyEventArgs e)
//{
// if (e.Key == Key.Return)
// {
// var search = tbSearch.Text.Trim();
// datagridview.ItemsSource = lAttendance.Where(m => m.ID.Contains(search)).OrderBy(m => m.ID);
// }
//}
}
}