-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrentFileClass.cs
85 lines (72 loc) · 2.44 KB
/
currentFileClass.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
/* Gavin Rodgers
* 3309 ATM Project
* This class handles and stores all the information with the current file class
* Last edited: 10/13/18
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ATM
{
public class currentFileClass
{
private string currentFilePath;
private System.IO.StreamReader currentFileSR; // Reference variable of type SR
private int recordReadCount;
// Constructor with file path input
// Create instance of StreamReader class (type) and store reference
public currentFileClass
(string filePath)
{
recordReadCount = 0;
currentFilePath = filePath;
try
{
currentFileSR = new System.IO.StreamReader(currentFilePath);
}
catch (Exception ex)
{
MessageBox.Show("Cannot open file" + currentFilePath + "Terminate Program.",
"Output File Connection Error.",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
} // end Try
} // end currentFileClass
// Read a record from the current file
public string getNextRecord(
ref Boolean endOfFileFlag)
{
string nextRecord;
endOfFileFlag = false;
nextRecord = currentFileSR.ReadLine();
if (nextRecord == null)
{
endOfFileFlag = true;
}
else
{
recordReadCount += 1;
} // end if
return (nextRecord);
} // end getNextRecord
// Get value of number of records read
public int getRecordsReadCount()
{
return recordReadCount;
} // end getecordsReadCount
// Close the input file
public void closeFile()
{
currentFileSR.Close();
} // end Sub
// Rewind the input file
public void rewindFile()
{
recordReadCount = 0;
currentFileSR = new System.IO.StreamReader(currentFilePath);
currentFileSR.DiscardBufferedData();
currentFileSR.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
} // end rewindFile
} // end currentFileClass
} // end namespace