我已经完成了我的大部分项目,但是我需要帮助调用一个函数。在第38行显示DisplayCustomerMenu(客户);,我没有调用该函数。调出这个函数的正确方法是什么?
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LabMenu {
public static class Program
{
public static PreferredCustomer[] preferredCustomers;
public static Customer customer;
public static string firstName { get; set; }
public static string lastName { get; set; }
public static double flashlight { get; private set; }
public static double iphone { get; private set; }
public static double printer { get; private set; }
public static double laptop { get; private set; }
public static double playstation { get; private set; }
static void Main(string[] args)
{
DisplayMainMenu();
}
public static void DisplayMainMenu()
{
do
{
Console.Clear();
Console.WriteLine("Welcome to the Menu!");
Console.WriteLine("0. Quit");
Console.WriteLine("1. Make An Order");
Console.WriteLine("2. Manage Customers");
switch (ConsoleHelper.ReadInt32(0, 1))
{
case 0: return;
case 1: DisplayCustomersMenu(); break;
};
} while (true);
}
public static void DisplayCustomersMenu()
{
do
{
Console.Clear();
Console.WriteLine("Make An Order");
Console.WriteLine($"What is your first name?");
firstName = Console.ReadLine();
Console.WriteLine($"What is your last name?");
lastName = Console.ReadLine();
string strTarget = String.Format("Hello, {0} {1}.", firstName, lastName);
Console.WriteLine("{0}{1}{0}",
Environment.NewLine, strTarget);
Console.WriteLine("1) Select Customer");
Console.WriteLine("0) Return to Manage Customers");
switch (ConsoleHelper.ReadInt32(0, 3))
{
case 0: return;
case 1:
{
string enteredID = "";
do
{
Console.WriteLine("Enter the customer ID: ");
enteredID = Console.ReadLine();
//var id = ConsoleHelper.ReadInt32("Invalid customer ID", 0, Int32.MaxValue);
foreach (var id in preferredCustomers)
{
if (id.CustomerID == enteredID)
{
DisplayCustomerMenu(customer); //Is this correct?
}
else
{
Console.WriteLine("You are not in the database");
}
}
} while (true);
//var customer = SelectCustomer();
//if (customer != null)
// DisplayCustomerMenu(customer);
//else
// Console.WriteLine("Customer not found");
//break;
};
};
} while (true);
}
public static void DisplayCustomerMenu(Customer customer)
{
do
{
Console.Clear();
Console.WriteLine("Manage Customers");
Console.WriteLine($"Custumer name, ID and current order");
Console.WriteLine("1) Add to Order");
Console.WriteLine("2) Remove from Order");
Console.WriteLine("3) Finalize Order");
Console.WriteLine("0) Return to Manage Customers");
switch (ConsoleHelper.ReadInt32(0, 3))
{
case 0: return;
case 1: AddToOrder(customer); break;
case 2: RemoveFromOrder(customer); break;
case 3: FinalizeOrder(customer); break;
};
} while (true);
}
public static void AddToOrder(Customer id)
{
Console.Clear();
int numberOfInputForFlashlight = 0;
int numberOfInputForIphone = 0;
int numberOfInputForPrinter = 0;
int numberOfInputForLaptop = 0;
int numberOfInputForPlaystation = 0;
int myint = -1;
while (myint != 0)
{
string group;
Console.WriteLine("Add To Order");
Console.WriteLine("1) Flashlight");
Console.WriteLine("2) iPhone 7");
Console.WriteLine("3) Printer");
Console.WriteLine("4) Dell Laptop");
Console.WriteLine("5) Playstation 4");
Console.WriteLine("6) View Total");
Console.WriteLine("[Press 0 to quit]");
group = Console.ReadLine();
myint = Int32.Parse(group);
switch (myint)
{
case 0:
break;
case 1:
double input1;
string inputString1;
Console.WriteLine("How many flashlights do you want?");
inputString1 = Console.ReadLine();
input1 = Convert.ToDouble(inputString1);
flashlight += input1;
numberOfInputForFlashlight++;
break;
case 2:
double input2;
string inputString2;
Console.WriteLine("How many iPhone 7 do you want?");
inputString2 = Console.ReadLine();
input2 = Convert.ToDouble(inputString2);
iphone += input2;
numberOfInputForIphone++;
break;
case 3:
double input3;
string inputString3;
Console.WriteLine("How many Printers do you want?");
inputString3 = Console.ReadLine();
input3 = Convert.ToDouble(inputString3);
printer += input3;
numberOfInputForPrinter++;
break;
case 4:
double input4;
string inputString4;
Console.WriteLine("How many Dell Laptops do you want?");
inputString4 = Console.ReadLine();
input4 = Convert.ToDouble(inputString4);
laptop += input4;
numberOfInputForLaptop++;
break;
case 5:
double input5;
string inputString5;
Console.WriteLine("How many Playstion 4 do you want?");
inputString5 = Console.ReadLine();
input5 = Convert.ToDouble(inputString5);
playstation += input5;
numberOfInputForPlaystation++;
break;
case 6:
Console.WriteLine("Flashlist quantity is {0}", flashlight.ToString("F"));
Console.WriteLine("iPhone 7 quantity is {0}", iphone.ToString("F"));
Console.WriteLine("Printer quantity is {0}", printer.ToString("F"));
Console.WriteLine("Dell Laptop quantity is {0}", laptop.ToString("F"));
Console.WriteLine("Playstation 4 quantity is {0}", playstation.ToString("F"));
Console.WriteLine("Flashlight total is {0}", (flashlight * 15.00).ToString("C"));
Console.WriteLine("iPhone 7 total is {0}", (iphone * 700.00).ToString("C"));
Console.WriteLine("Printer total is {0}", (printer * 80.00).ToString("C"));
Console.WriteLine("Dell Laptop total is {0}", (laptop * 500.00).ToString("C"));
Console.WriteLine("Playstation 4 total is {0}", (playstation * 380.00).ToString("C"));
break;
default:
Console.WriteLine("Incorrect input", myint);
break;
}
}
}
public static void FinalizeOrder(Customer customer)
{
do
{
Console.Clear();
} while (true);
}
static void RemoveFromOrder(Customer customer)
{
do
{
Console.Clear();
Console.WriteLine("Remove From Order:");
Console.WriteLine("1) Flashlight total is {0}", (flashlight * 15.00).ToString("C"));
Console.WriteLine("2) iPhone 7 total is {0}", (iphone * 700.00).ToString("C"));
Console.WriteLine("3) Printer total is {0}", (printer * 80.00).ToString("C"));
Console.WriteLine("4) Dell Laptop total is {0}", (laptop * 500.00).ToString("C"));
Console.WriteLine("5) Playstation 4 total is {0}", (playstation * 380.00).ToString("C"));
switch (ConsoleHelper.ReadInt32(0, 5))
{
case 0: break;
case 1:
double input1;
string inputString1;
Console.WriteLine("How many flashlights do you want to remove?");
inputString1 = Console.ReadLine();
input1 = Convert.ToDouble(inputString1);
flashlight -= input1;
break;
case 2:
double input2;
string inputString2;
Console.WriteLine("How many iPhone 7 do you remove?");
inputString2 = Console.ReadLine();
input2 = Convert.ToDouble(inputString2);
iphone -= input2;
break;
case 3:
double input3;
string inputString3;
Console.WriteLine("How many Printers do you remove?");
inputString3 = Console.ReadLine();
input3 = Convert.ToDouble(inputString3);
printer -= input3;
break;
case 4:
double input4;
string inputString4;
Console.WriteLine("How many Dell Laptops do you remove?");
inputString4 = Console.ReadLine();
input4 = Convert.ToDouble(inputString4);
laptop += input4;
break;
case 5:
double input5;
string inputString5;
Console.WriteLine("How many Playstion 4 do you remove?");
inputString5 = Console.ReadLine();
input5 = Convert.ToDouble(inputString5);
playstation += input5;
break;
};
} while (true);
}
public static void GetData()
{
using (var reader = new StreamReader("CustomerInfo.txt"))
{
var index = 0;
preferredCustomers = new PreferredCustomer[5];
while (!reader.EndOfStream)
{
var line = reader.ReadLine().Split(':');
var name = line[0];
var address = line[1];
var phone = line[2];
var id = line[3];
var email = line[4];
var spentAmount = Convert.ToInt32(line[5]);
var onEmailList = Convert.ToBoolean(line[6]);
preferredCustomers[index] = new PreferredCustomer(name, address, phone, id, email, spentAmount,
onEmailList);
index++;
}
}
}
public static void UpdateData()
{
using (var writer = new StreamWriter("CustomerInfo2.txt"))
{
for (var i = 0; i < 5; i++)
{
var name = preferredCustomers[i].CustomerName;
var address = preferredCustomers[i].Address;
var phone = preferredCustomers[i].Phone;
var id = preferredCustomers[i].CustomerID;
var email = preferredCustomers[i].CustomerID;
var updatedSpentAmount = preferredCustomers[i].CalcAmount();
var onEmailList = preferredCustomers[i].OnEmailList;
writer.WriteLine("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
name, address, phone, id, email, updatedSpentAmount, onEmailList == true ? "true" : "false");
}
}
}
public static string UserChoice()
{
var userChoice = Console.ReadLine();
while (userChoice !="1" && userChoice != "2")
{
Console.WriteLine("Wrong Entry. Try Again.");
DisplayMenu();
userChoice = Console.ReadLine();
}
return userChoice;
}
public static void DisplayMenu()
{
Console.WriteLine("1. Display Customer Info");
Console.WriteLine("2. Update Customer Info");
Console.Write("Please enter your choice: ");
}
}
}
此处还有&#39; Customer.cs&#39;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LabMenu
{
public class Customer : Person
{
public Customer(string name, string address, string phone, string id, string email, int spentAmount,
bool onEmailList)
: base(name, address, phone)
{
CustomerID = id;
CustomerEmail = email;
SpentAmount = spentAmount;
OnEmailList = onEmailList;
}
public string CustomerID { get; set; }
public string CustomerEmail { get; set; }
public int SpentAmount { get; set; }
public bool OnEmailList { get; set; }
public virtual double CalcAmount()
{
return SpentAmount;
}
}
}
Person.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LabMenu
{
public class Person
{
public Person(string name, string address, string phone)
{
CustomerName = name;
Address = address;
Phone = phone;
}
PreferredCustomers.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LabMenu
{
public class PreferredCustomer : Customer
{
public PreferredCustomer(string name, string address, string phone, string id,
string email, int spentAmount, bool onEmailList)
: base (name, address, phone, id, email, spentAmount, onEmailList)
{
DiscountLevel = SetDiscountLevel();
}
public readonly decimal DiscountLevel;
public decimal SetDiscountLevel()
{
int range = SpentAmount / 500;
switch (range)
{
case 0:
return 0;
case 1:
return 0.05m;
case 2:
return 0.05m;
case 3:
return 0.08m;
default:
return 0.1m;
}
}
public double GetDiscount()
{
return SpentAmount * (double)DiscountLevel;
}
public override double CalcAmount()
{
return base.CalcAmount() - GetDiscount();
}
public override string ToString()
{
return
String.Format(
"CustomerID: {0}\nCustomer Name: {1}\nCustomerAddress: {2}\n" +
"Customer Phone: {3} \nCustomer Email: {4}" +
"Customer Spending: {5:C2}\nCustomer On Email List: {6}",
CustomerID, CustomerName, Address, Phone, CustomerEmail, SpentAmount, OnEmailList
);
}
}
}
public string CustomerName { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
}
}
CustomerInfo.txt
John Candy:123 10th st, Allen, TX 78714:972-555-0000:A0000001:email@gmail.com:2500:true
Robert Smith:456 15th st, Austin, TX 78504:512-456-1000:A0000002:bobsmith@gmail.com:2500:true
Bill Clinton:2004 44th st, Washington, DC 20001:202-456-2222:A0000003:williamc@gmail.com:495:false
Patricia Garner:123 16th st, Washington, DC 20002:202-555-6666:A0000004:garnerp@gmail.com:1200:true
Pablo Corbin:777 2th st, Houston, TX 77002:832-100-2000:A0000005:pcorzbin@yahoo.com:1750:false