List<Customer> customers = new List<Customer>();
int id = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void AddButton_Click(object sender, EventArgs e)
{
Customer rec1 = new Customer("C0020", "Alfred", "Campbelltown", 1500, 2006);
Customer rec2 = new Customer("C0021", "Ryder", "Liverpool", 2000, 2008);
Customer rec3 = new Customer("C0022", "Alison", "Strathfield", 5500, 2012);
Customer rec4 = new Customer("C0023", "Eliza", "Liverpool", 6000, 2012);
Customer rec5 = new Customer("C0024", "Natsu", "Campbelltown", 2560, 2011);
customers.Add(rec1);
customers.Add(rec2);
customers.Add(rec3);
customers.Add(rec4);
customers.Add(rec5);
}
private void NextButton_Click(object sender, EventArgs e)
{
int length = customers.Count - 1;
if (id == length)
{
id = 0;
}
else
{
++id;
}
//Stage 3 Shows the total balance of all records and is displayed
double total = 0;
foreach (Customer Total in customers)
total += Total.Balance; //Total Balance
double balance = 0;
foreach (Customer SubTotal in customers)
balance = customers.Where(c => c.Suburb == "Liverpool").Sum( c => c.Balance);
//Create a total balance for each suburb
custID.Text = customers[id].ID.ToString();
custName.Text = customers[id].Name.ToString();
custSuburb.Text = customers[id].Suburb.ToString();
custBal.Text = customers[id].Balance.ToString();
custYear.Text = customers[id].Year_used.ToString();
totBalance.Text = total.ToString();
totSuburb.Text = balance.ToString();
}
private void PrevButton_Click(object sender, EventArgs e)
{
int length = customers.Count - 1;
if (id == 0)
{
id = length;
}
else
{
--id;
}
custID.Text = customers[id].ID.ToString();
custName.Text = customers[id].Name.ToString();
custSuburb.Text = customers[id].Suburb.ToString();
custBal.Text = customers[id].Balance.ToString();
custYear.Text = customers[id].Year_used.ToString();
}
private void exitApp_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void updateButton_Click(object sender, EventArgs e)
{
customers[id].Name = custName.Text.ToString();
customers[id].Suburb = custSuburb.Text.ToString();
customers[id].Balance = double.Parse(custBal.Text);
customers[id].Year_used = double.Parse(custYear.Text);
this.Update(customers);
}
我尝试使用更新按钮保存我的更改,但是当我尝试更改名称或余额并点击更新时它似乎没有更新
有任何想法吗?
我已经尝试过 this.Update() 功能,但没有用 :( 将获得帮助