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;
}
}
}
こんにちは、これは私が現時点で持っているコードです。-コードを実行すると、完全に正常に動作します。前と次のボタンと、レコードを参照できる更新ボタンがあります -しかし、テキストボックス内のテキストを変更して更新ボタンを押しても、保存されません何らかの理由で、[追加] をクリックしてから [次へ] をクリックし、[前へ] をクリックして、変更が保存されているかどうかを確認します
- どんなアイデアも素晴らしいでしょう!乾杯