private void RetryEntry(string RFID, string MemberID, string OldRemarks) { try { string path = ReadText.ReadFilePath("datapath"); string dateString = this.DateRelease.Year.ToString() + this.DateRelease.Month.ToString().PadLeft(2, '0') + this.DateRelease.Day.ToString().PadLeft(2, '0'); string entryDirectory = path + "\\entry\\" + dateString; string pathSyncApplication = AppDomain.CurrentDomain.BaseDirectory + "SyncApplication"; string EntryLogs = pathSyncApplication + "\\entrylogs.txt"; string bandedFileName = path + "\\PigeonDetails\\" + MemberID + "\\" + RFID + ".txt"; string MobileFileName = path + "\\PigeonMobileList\\" + RFID + ".txt"; if (File.Exists(bandedFileName)) { string[] pigeondetails = ReadText.ReadTextFile(bandedFileName); BusinessLayer.EclockEntryBLL entryBll = new EclockEntryBLL(); DomainObjects.Entry entryObject = new DomainObjects.Entry(); entryObject.Clubname = ClubName; entryObject.MemberIDNo = MemberID; entryObject.ReleaseDate = this.DateRelease; entryObject.RingNumber = pigeondetails[0]; entryObject.RaceCategoryName = pigeondetails[2]; entryObject.MobileNumber = ""; entryObject.RaceCategoryGroupName = "EClock"; entryObject.RFID = RFID; if (File.Exists(MobileFileName)) { string[] pigeonMobileCollection = ReadText.ReadTextFile(MobileFileName); string[] values = pigeonMobileCollection[0].ToString().Split('|'); entryObject.MobileNumber = values[1].ToString().Trim(); } DataSet dtResult = new DataSet(); dtResult = entryBll.EclockEntrySave(entryObject); if (dtResult.Tables.Count > 0) { if (dtResult.Tables[0].Rows.Count > 0) { String Remarks = dtResult.Tables[0].Rows[0]["Remarks"].ToString(); if (Remarks.ToUpper() != "SUCCESS") { String LogContents = MemberID + "|" + RFID + "|" + pigeondetails[0] + "|" + Remarks + "|"; string removeFromLogsPath = pathSyncApplication + "\\entrylogs.txt"; if (!CheckRemarks(LogContents, removeFromLogsPath)) { if (File.Exists(EntryLogs)) { using (StreamWriter sw = File.AppendText(EntryLogs)) { sw.WriteLine(LogContents); } } else { using (StreamWriter sw = File.CreateText(EntryLogs)) { sw.WriteLine(LogContents); } } } MessageBox.Show("Error detected.", "Error"); } else { string removeFromLogsPath = pathSyncApplication + "\\entrylogs.txt"; String removeFromLogs = MemberID + "|" + RFID + "|" + pigeondetails[0] + "|" + OldRemarks + "|"; UpdateLogs(removeFromLogs, removeFromLogsPath); MessageBox.Show("Eclock entry sync to database.", "Eclock Sync"); } } } } ReadEntryLogs(); } catch (Exception ex) { throw ex; } }
private static void SyncEntryToDatabase() { try { string path = DataPath; string dateString = DateRelease; string rootApplicationDirectory = AppDomain.CurrentDomain.BaseDirectory; string entryDirectory = path + "entry\\" + dateString; String EntryLogs = rootApplicationDirectory + "\\entrylogs.txt"; //delete log file if (File.Exists(EntryLogs)) { File.Delete(EntryLogs); } if (Directory.Exists(entryDirectory)) { String[] filelist = Directory.GetFiles(entryDirectory); foreach (var item in filelist) { string filepath = item; string[] filename = filepath.Split('\\'); if (File.Exists(filepath)) { string[] entryList = ReadText.ReadTextFile(filepath); string[] filenameValue = filename[filename.Length - 1].Split('.'); foreach (var entry in entryList) { string bandedFileName = path + "PigeonDetails\\" + filenameValue[0] + "\\" + entry + ".txt"; string MobileFileName = path + "\\PigeonMobileList\\" + entry + ".txt"; if (File.Exists(bandedFileName)) { string[] pigeondetails = ReadText.ReadTextFile(bandedFileName); BusinessLayer.EclockEntryBLL entryBll = new EclockEntryBLL(); DomainObjects.Entry entryObject = new DomainObjects.Entry(); entryObject.Clubname = ClubName; entryObject.MemberIDNo = filenameValue[0]; entryObject.ReleaseDate = ReleaseDate; entryObject.RingNumber = pigeondetails[0]; entryObject.RaceCategoryName = pigeondetails[2]; entryObject.RaceCategoryGroupName = "EClock"; entryObject.RFID = entry; entryObject.MobileNumber = ""; if (File.Exists(MobileFileName)) { string[] pigeonMobileCollection = ReadText.ReadTextFile(MobileFileName); string[] values = pigeonMobileCollection[0].ToString().Split('|'); entryObject.MobileNumber = values[1].ToString().Trim(); } DataSet dtResult = new DataSet(); dtResult = entryBll.EclockEntrySave(entryObject); if (dtResult.Tables.Count > 0) { if (dtResult.Tables[0].Rows.Count > 0) { String Remarks = dtResult.Tables[0].Rows[0]["Remarks"].ToString(); if (Remarks.ToUpper() != "SUCCESS") { String LogContents = filenameValue[0] + "|" + entry + "|" + pigeondetails[0] + "|" + Remarks + "|"; Console.WriteLine("----------------"); Console.WriteLine(filenameValue[0]); Console.WriteLine(entry); Console.WriteLine(pigeondetails[0]); Console.WriteLine(Remarks); Console.WriteLine("----------------"); if (File.Exists(EntryLogs)) { using (StreamWriter sw = File.AppendText(EntryLogs)) { sw.WriteLine(LogContents); } } else { using (StreamWriter sw = File.CreateText(EntryLogs)) { sw.WriteLine(LogContents); } } } else { Console.WriteLine("----------------"); Console.WriteLine(filenameValue[0]); Console.WriteLine(entry); Console.WriteLine(pigeondetails[0]); Console.WriteLine(Remarks); Console.WriteLine("----------------"); } } } } } } } } } catch (Exception ex) { throw ex; } }