using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Lab2bSQL { public partial class Form1 : Form { ECE eceObj; int bookID; BookShop bkShopObj = new BookShop(); public Form1() { InitializeComponent(); } private void nameComboBox_SelectedIndexChanged(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { eceObj = new ECE(); for (int i = 0; i < eceObj.ECENames.Length; i++) { nameComboBox.Items.Add(eceObj.ECENames[i]); } for (int i = 0; i < bkShopObj.Book.Length; i++) { bookListBox.Items.Add(bkShopObj.Book[i]); stockListBox.Items.Add(bkShopObj.Stock[i]); costListBox.Items.Add(bkShopObj.Cost[i].ToString("C")); } } private void loginButton_Click(object sender, EventArgs e) { if (nameComboBox.Text == "") { MessageBox.Show("Empty Name"); return; } else if (passwordTextBox.Text == "") { MessageBox.Show("Empty Password"); passwordTextBox.Focus(); return; } else { eceObj = new ECE(nameComboBox.Text); if (passwordTextBox.Text != eceObj.Password) { MessageBox.Show("Incorrect password"); return; } MessageBox.Show("Welcome " + eceObj.Name + " ! "); addressTextBox.Text = eceObj.Address; } } private void updateButton_Click(object sender, EventArgs e) { if (addressTextBox.Text == "") { MessageBox.Show("Please enter your address to update"); } else { eceObj = new ECE(nameComboBox.Text); eceObj.UpdateAddr(addressTextBox.Text); addressTextBox.Text = eceObj.Address; } } private void bookListBox_SelectedIndexChanged(object sender, EventArgs e) { pictureBox1.Image = Image.FromFile(bkShopObj.Book[bookListBox.SelectedIndex] + ".jpg"); } private void okButton_Click(object sender, EventArgs e) { eceObj.intQuantity = int.Parse(comboBox1.Text); int i = bookListBox.SelectedIndex; bookID = i + 1; eceObj.CalCost(bkShopObj.Cost[i]); MessageBox.Show("Total is " + eceObj.TotalCost); bkShopObj.RecordSales(eceObj.intQuantity, bookID, eceObj.intCustID); bkShopObj.CheckStock(i, eceObj.intQuantity); stockListBox.Items[i] = bkShopObj.DecreaseStock(bookListBox.SelectedIndex, eceObj.intQuantity); } } }