ここに2つの方法があり、最初のエラーは、以下に示されている}が必要であると不平を言っています
これは通常、ブラケットがどこかに欠けていることを意味することを知っていますが、そうではないと思います。
public Customer(string first, string last)
{
FileStream getID = new FileStream(FILENAME, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);
String line;
string[] fields;
try
{
//Pass the file path and file name to the StreamReader constructor
StreamReader srID = new StreamReader(getID);
//Read the first line of text
line = srID.ReadLine();
while(line != null)
{
fields = line.Split(DELIM);
if (Convert.ToInt32(fields[2]) > CustomerID)
{
CustomerID = Convert.ToInt32(fields[2]);
}
line = srID.ReadLine();
}
//close the file
srID.Close();
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
FileStream customerWrite = new FileStream(FILENAME, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
int idCounter;
try
{
//Pass the filepath and filename to the StreamWriter Constructor
StreamWriter sw = new StreamWriter(customerWrite);
//Write a line of text
FirstName = first;
LastName = last;
CustomerID += 1;
sw.WriteLine(ToString());
//Close the file
sw.Close();
}
catch(Exception e)
{
// messagebox
MessageBox.Show(e.Message,"Problem",MessageBoxButtons.OK, MessageBoxIcon.Error);
//Console.WriteLine("Exception: " + e.Message);
} // asking for a } here
public new string ToString()
{
return (FirstName + ',' + LastName + ',' + CustomerID);
}
}
// checks for duplicate customer info
public bool CustomerOrderCheck(string first, string last) // gives the expected class... for the bool here
// pass the first and last name to be checked in the system for a previous entry
{
FileStream customerCheck = new FileStream(FILENAME, FileMode.OpenCreate, FileAccess.Read, FileShare.ReadWrite);
String line;
string[] fields;
bool customerExists = false;
try
{
//Pass the file path and file name to the StreamReader constructor
StreamReader sr = new StreamReader(customerCheck);
//Read the first line of text
line = sr.ReadLine();
while (line != null)
{
fields = recordIn.Split(DELIM);
FirstName = fields[0];
LastName = fields[1];
if (FirstName + LastName == first + last) //(line.Equals(orderCheck))
{
MessageBox.Show("This order has already been submitted, please try again","Order already exists",MessageBoxIcon.Warning);
//Console.WriteLine("This order has already been submitted, please try again");
customerExists = true;
break;
}
line = sr.ReadLine();
}
//close the file
sr.Close();
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
return customerExists;
}
}