public IEnumerable <StudentCheckTime> GetStudentCheckTimes(string rootPath, string date) { var results = new List <StudentCheckTime>(); var fullPath = rootPath.GetFullPath(date); if (File.Exists(fullPath)) { // Protect Exception Another Process var fs = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using (var table = Table.Open(fs)) { var reader = table.OpenReader(Encoding.GetEncoding(874)); while (reader.Read()) { decimal? cuserid = reader.GetDecimal("CUSERID") == null ? 0 : reader.GetDecimal("CUSERID"); DateTime?chkTime = reader.GetDateTime("CHKTIME"); var model = new StudentCheckTime() { CuserId = cuserid, EmpId = reader.GetString("EMPID"), EmpName = reader.GetString("EMPNAME"), ChkTime = (DateTime)chkTime }; results.Add(model); } } } return(results); }
public static List <StudentCheckTime> GetStudentCheckTimes(this List <StudentCheckTime> models, TimeSpan timeStart, TimeSpan timeEnd) { var results = new List <StudentCheckTime>(); foreach (var item in models) { var chkTime = item.ChkTime; var time = new TimeSpan(chkTime.Hour, chkTime.Minute, chkTime.Millisecond); if (time.IsBetween(timeStart, timeEnd)) { var model = new StudentCheckTime() { CuserId = item.CuserId, EmpId = item.EmpId, EmpName = item.EmpName, ChkTime = item.ChkTime }; results.Add(model); } } return(results); }
public ResponseMessage SentOnceNotifyMessage(StudentCheckTime model, SentType sentType) { var result = new ResponseMessage(); if (MySqlDataConnection.SentSuccess(model.EmpId, sentType)) { result = new ResponseMessage() { success = "1" }; return(result); } var studentsAddPara = GlobalConfig.AppSettings("students"); //var roomsAddPara = GlobalConfig.AppSettings("rooms"); //var messageAddPara = GlobalConfig.AppSettings("message"); //var usernameAddPara = GlobalConfig.AppSettings("username"); //var appName = GlobalConfig.AppSettings("appName"); #region for test var students = studentsAddPara.Split('|'); if (GlobalConfig.Index > students.Length - 1) { GlobalConfig.Index = 0; } var sentStd = students[GlobalConfig.Index]; GlobalConfig.Index += 1; #endregion var studentsReq = studentsAddPara == "" ? model.EmpId : sentStd; var url = GlobalConfig.AppSettings("sentMessageService") .Replace("{schoolCode}", GlobalConfig.AppSettings("schoolCode")) .Replace("{studentCode}", studentsReq); var client = new RestClient(url); var request = new RestRequest(Method.POST); request.AddBody("content-type", "application/form-data"); #region message //entry //ทดสอบ //รหัสนักเรียน //ชื่อ //เวลาเข้าเรียน //exit //ทดสอบ //รหัสนักเรียน //ชื่อ //เวลาเลิกเรียน #endregion request.AddParameter("students", studentsReq); if (sentType == SentType.Entry) { request.AddParameter("message", $"ส่งจากระบบ" + System.Environment.NewLine + $"รหัสนักเรียน: {model.EmpId}" + System.Environment.NewLine + $"ชื่อ: {model.EmpName}" + System.Environment.NewLine + $"เวลาเข้าเรียน: {model.ChkTime}"); } else if (sentType == SentType.Exit) { request.AddParameter("message", $"ส่งจากระบบ" + System.Environment.NewLine + $"รหัสนักเรียน: {model.EmpId}" + System.Environment.NewLine + $"ชื่อ: {model.EmpName}" + System.Environment.NewLine + $"เวลาเลิกเรียน: {model.ChkTime}"); } //request.AddParameter("rooms", roomsAddPara); //request.AddParameter("username", usernameAddPara); StudentSentMessage sentMessage = new StudentSentMessage(); var json = client.Execute <ResponseMessage>(request).Content; result = JsonConvert.DeserializeObject <ResponseMessage>(json); //if (res != null) //{ if (result.success == "1") { GlobalConfig.StudentCount += 1; sentMessage = new StudentSentMessage() { EmpId = model.EmpId, Status = $"{SentStatus.Success}", SentType = sentType.ToString(), SentTime = DateTime.Parse(Helper.GetDateNowStringUs("yyyy-MM-dd HH:mm:ss")), ChkTime = model.ChkTime }; MySqlDataConnection.SaveStudentSentMessage(sentMessage); } else { sentMessage = new StudentSentMessage() { EmpId = model.EmpId, Status = $"{SentStatus.Error} : {result.error}", SentType = sentType.ToString(), SentTime = DateTime.Parse(Helper.GetDateNowStringUs("yyyy-MM-dd HH:mm:ss")), ChkTime = model.ChkTime }; MySqlDataConnection.SaveStudentSentMessage(sentMessage); } //} #region sent Async //client.ExecuteAsync(request, response => //{ // StudentSentMessage sentMessage = new StudentSentMessage(); // var json = response.Content; // ResponseMessage resAsync = JsonConvert.DeserializeObject<ResponseMessage>(json); // result = resAsync; // if (resAsync != null) // { // if (resAsync.success == "1") // { // sentMessage = new StudentSentMessage() // { // EmpId = model.EmpId, // Status = $"{SentStatus.Success}", // SentType = sentType.ToString(), // SentTime = DateTime.Parse(Helper.GetDateNowStringUs("yyyy-MM-dd HH:mm:ss")), // ChkTime = model.ChkTime // }; // MySqlDataConnection.SaveStudentSentMessage(sentMessage); // } // else // { // sentMessage = new StudentSentMessage() // { // EmpId = model.EmpId, // Status = $"{SentStatus.Error} : {resAsync.error}", // SentType = sentType.ToString(), // SentTime = DateTime.Parse(Helper.GetDateNowStringUs("yyyy-MM-dd HH:mm:ss")), // ChkTime = model.ChkTime // }; // MySqlDataConnection.SaveStudentSentMessage(sentMessage); // } // } //}); #endregion return(result); }