public partial class Form1 : Form
{
//With the code custID.Text = customers[id].ID.ToString();
//Function above will always be in par with the ID no matter what
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 custID_Click(object sender, EventArgs e)
{
}
private void custSub_Click(object sender, EventArgs e)
{
}
private void custBal_Click(object sender, EventArgs e)
{
}
private void custYear_Click(object sender, EventArgs e)
{
}
private void exitApp_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void totBalance_Click(object sender, EventArgs e)
{
}
private void totSuburb_Click(object sender, EventArgs e)
{
}
private void DelButton_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void custSuburb_TextChanged(object sender, EventArgs e)
{
}
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);
}
}
public class Customer
{
protected string id;
protected string name;
protected string suburb;
protected double balance;
protected double year_used;
public string ID
{
get { return id; }
}
public string Name
{
get { return name; }
set { value = name; }
}
public string Suburb
{
get { return suburb; }
set { value = suburb; }
}
public double Balance
{
get { return balance; }
set { value = balance; }
}
public double Year_used
{
get { return year_used; }
set { value = year_used; }
}
public Customer(string id, string name, string suburb, double balance, double year_used)
{
this.id = id;
this.name = name;
this.suburb = suburb;
this.balance = balance;
this.year_used = year_used;
}
}
}
嗨,这是我目前拥有的代码。- 当我运行代码时,我有一个上一个和下一个按钮以及一个更新按钮,我可以在其中浏览记录 - 但是当我尝试更改文本框中的文本并点击更新按钮时,它不会保存出于某种原因,我单击添加然后单击下一步然后单击上一个以查看更改是否已保存
- 任何想法都会很棒!干杯