Filesbalance
Filesbalance
{
[Serializable]
public class RecordSerializable
{
public int Account { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public decimal Balance { get; set; }
namespace FileExample_01
{
public class Record
{
public int Account { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public decimal Balance { get; set; }
namespace FileExample_01
{
public partial class MainForm : Form
{
//
//openbtn_Click: Handles the click event of the "Open" button.It opens a
file dialog for the user to select a file.If a file is selected, it reads the
contents of the file and enables the "Next Record" button.
//savebtn_Click: Handles the click event of the "Save" button.It opens a
file dialog for the user to specify the file to save the data.If a valid file name
is provided, it enables the "Enter" button to start entering data.
//enterbtn_Click: Handles the click event of the "Enter" button.It
retrieves the values from text boxes, validates them, creates a Record object, and
writes the record to the file.
//exitbtn_Click: Handles the click event of the "Exit" button.It closes the
file writer and exits the application.
//The nextbtn_Click event handler is responsible for displaying the next
record from the file when the "Next Record" button is clicked.
// object for deserializing RecordSerializable in binary format
private FileStream input; // stream for reading from a file
private StreamWriter fileWriter; // writes data to text file
protected int TextBoxCount { get; set; } = 4; // number of TextBoxes
// Create and show the file dialog with proper resource management
using (OpenFileDialog fileChooser = new OpenFileDialog())
{
// Display the dialog and capture the user's choice
result = fileChooser.ShowDialog(); // Show the Open File dialog
fileName = fileChooser.FileName; // Get the chosen file's name
ClearTextBoxes();
ClearTextBoxes();
Application.Exit();
}
}
}