0

这是两种方法,第一个错误是抱怨我需要一个 },如下所示

我知道这通常意味着我在某处缺少支架,但我认为情况并非如此,而且我一生都找不到任何问题。

    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;
    }
}
4

2 回答 2

1

我认为这:

        } // asking for a } here

        public new string ToString()
        {
           return (FirstName + ',' + LastName + ',' + CustomerID);
        }
    }

应该:

        }// asking for a } here
    }

    public new string ToString()
    {
        return (FirstName + ',' + LastName + ',' + CustomerID);
    }
于 2012-05-26T15:02:45.667 回答
0

您在函数中包含了一个函数。将 ToString() 函数移到 Customer() 函数之外。只需在需要的地方加一个括号,然后在 ToString() 函数后删除括号。

于 2012-05-26T15:26:05.023 回答