// Method that adds a Customer to the list. public void CreateCustomer(Customer customerToCreate) { this.CustomersList.Add(customerToCreate); // Fire Event: modelChanged(this, new myModelEventArgs(customerToCreate, null)); // Save data to files: this.SaveData(); }
public myModelEventArgs(Customer cust, Order ord) { this._passingCustomer = cust; this._passingOrder = ord; }
// Method that updates an existing customer's info. public void UpdateCustomer(Customer customerToUpdate) { Customer oldCustomer = this.FindCustomer(customerToUpdate); if (oldCustomer != null) { oldCustomer.ID = customerToUpdate.ID; oldCustomer.Name = customerToUpdate.Name; oldCustomer.Phone = customerToUpdate.Phone; oldCustomer.Address = customerToUpdate.Address; // Fire event: modelChanged(this, new myModelEventArgs(customerToUpdate, null)); // Save data to files: this.SaveData(); } }
// Update Customer Button: private void selOpsUpdateBtn_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(this.selectedCustIdTxt.Text) && !string.IsNullOrWhiteSpace(this.selectedCustNameTxt.Text) && !string.IsNullOrWhiteSpace(this.selectedCustPhoneTxt.Text) && !string.IsNullOrWhiteSpace(this.selectedCustAddressTxt.Text)) { Customer cust = new Customer(int.Parse(this.selectedCustIdTxt.Text), this.selectedCustNameTxt.Text, int.Parse(this.selectedCustPhoneTxt.Text), this.selectedCustAddressTxt.Text); if (this._controller.FindCustomer(cust) != null) { if (MessageBox.Show("Are you sure you want to Update this customer?\n\r - ID: " + cust.ID + "\n\r - Name: " + cust.Name + "\n\r - Phone: " + cust.Phone + "\n\r - Address: " + cust.Address + "\n\r", "Attention!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { // CALL the controller's Update-Customer Function: this._controller.UpdateCustomer(cust); // Fire Event with the customer to update viewChanged.Invoke(this, new myViewEventArgs(cust, null)); } } else { this.responceLbl.ForeColor = System.Drawing.Color.Red; this.responceLbl.Text = "Customer with ID: " + cust.ID + " does not exist!"; } } else { this.responceLbl.ForeColor = System.Drawing.Color.Red; this.responceLbl.Text = "No fields should be blank!"; } }
// Method that searches the list for a customer. Returns the customer object if he is found, // or else null. public Customer FindCustomer(Customer customerToFind) { Customer customer = null; foreach (Customer cust in this.CustomersList) { if (cust.ID == customerToFind.ID) return cust; } return customer; }
// Create new Customer Button: private void selOpsCreateBtn_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(this.selectedCustIdTxt.Text) && !string.IsNullOrWhiteSpace(this.selectedCustNameTxt.Text) && !string.IsNullOrWhiteSpace(this.selectedCustPhoneTxt.Text) && !string.IsNullOrWhiteSpace(this.selectedCustAddressTxt.Text)) { Customer newCust = new Customer(int.Parse(this.selectedCustIdTxt.Text), this.selectedCustNameTxt.Text, int.Parse(this.selectedCustPhoneTxt.Text), this.selectedCustAddressTxt.Text); if (this._controller.FindCustomer(newCust) == null) { this.responceLbl.ForeColor = System.Drawing.Color.Black; this.responceLbl.Text = ""; MessageBox.Show("New customer created: \n\r - ID: " + newCust.ID + "\n\r - Name: " + newCust.Name + "\n\r - Phone: " + newCust.Phone + "\n\r - Address: " + newCust.Address + "\n\r", "Success!"); // CALL the controller's Create-Customer Function: this._controller.CreateCustomer(newCust); // Fire Event with the new customer added viewChanged.Invoke(this, new myViewEventArgs(newCust, null)); } else { this.responceLbl.ForeColor = System.Drawing.Color.Red; this.responceLbl.Text = "Customer with ID: " + newCust.ID + " already exists!"; } } else { this.responceLbl.ForeColor = System.Drawing.Color.Red; this.responceLbl.Text = "No fields should be blank!"; } }
public void UpdateCustomer(Customer c) { this._myModel.UpdateCustomer(c); }
public Customer FindCustomer(Customer c) { return this._myModel.FindCustomer(c); }
public void DeleteCustomer(Customer c) { this._myModel.DeleteCustomer(c); }
public void CreateCustomer(Customer c) { this._myModel.CreateCustomer(c); }