public void AssignBoat(int indexOfSelectedCustomer, int indexOfSelectedBoat, ListBox listBox_ownedBoats)
        {
            // Selected customer.
            Customer selectedCustomer = myDataStorerForCustomers.ArrayOfCustomers[indexOfSelectedCustomer];
            // Selected boat.
            Boat selectedBoat = myDataStorerForBoats.ArrayOfBoats[indexOfSelectedBoat];

            // Make sure the boat doesn't have an owner yet.
            if (selectedBoat.Owner == null)
            {
                // Add the ownership to data storer.
                string customerPhoneNum = selectedCustomer.TelephoneNumber;
                string boatRegNum       = selectedBoat.RegistrationNumber.ToString();

                myDataStorerForOwnedBoats.AssignBoatToOwner(customerPhoneNum, boatRegNum);

                // Update ownership for:
                // customer and..
                selectedCustomer.UpdateBoatsArr(selectedBoat);
                // boat.
                selectedBoat.Owner = selectedCustomer;

                // Update the ListBox for boats owned.
                MyListPopulatorForOwnedBoats.List(listBox_ownedBoats, selectedCustomer);
            }
            else
            {
                MyDebugger.ShowComment("already has an owner");
            }
        }
Ejemplo n.º 2
0
        public void Save()
        {
            FileStream   myFileStream;
            StreamWriter myStreamWriter;

            try
            {
                // Create an input stream and a file writer;
                myFileStream   = new FileStream(FILEPATH, FileMode.Create, FileAccess.Write);
                myStreamWriter = new StreamWriter(myFileStream);

                // Write all the records to the file.
                for (int i = 0; i < this.numOfOwnership; i++)
                {
                    myStreamWriter.WriteLine(arrayOfPhoneAndRegNumPair[i, 0] + "," + arrayOfPhoneAndRegNumPair[i, 1]);
                }


                // Close the writer and stream.
                myStreamWriter.Close();
                myFileStream.Close();
            }
            catch (FileNotFoundException fnfe)
            {
                MyDebugger.ShowComment("Caught in class MyDataStorerForOwnedBoats, method Save(), catch block fnfe: " + fnfe.Message);
            }
            catch (Exception e)
            {
                MyDebugger.ShowComment("Caught in class MyDataStorerForOwnedBoats, method Save(), catch block e: " + e.Message);
            }
        }
Ejemplo n.º 3
0
        public void AssignBoatToOwner(string customerPhoneNum, string boatRegNum)
        {
            arrayOfPhoneAndRegNumPair[numOfOwnership, 0] = customerPhoneNum;
            arrayOfPhoneAndRegNumPair[numOfOwnership, 1] = boatRegNum;

            // DEBUG
            MyDebugger.ShowComment("Ownership assigned: " + arrayOfPhoneAndRegNumPair[numOfOwnership, 0] + ", " + arrayOfPhoneAndRegNumPair[numOfOwnership, 1]);

            ++numOfOwnership;
        }
Ejemplo n.º 4
0
 public MyInvalidFieldException(string message) : base(message)
 {
     // DEBUG
     MyDebugger.ShowComment(message);
 }