private void button_save_Click(object sender, EventArgs e) { Customer newCustomer; firstName = textBox_newFirstName.Text; lastName = textBox_newLastName.Text; address = textBox_newAddress.Text; phoneNumber = textBox_newPhoneNumber.Text; if (string.IsNullOrWhiteSpace(firstName)) { MessageBox.Show("Invalid or empty first name", "First Name is Required"); return; } if (string.IsNullOrWhiteSpace(lastName)) { MessageBox.Show("Invalid or empty last name", "Last Name is Required"); return; } if (string.IsNullOrWhiteSpace(address)) { MessageBox.Show("Invalid or empty address", "Address is Required"); return; } if (string.IsNullOrWhiteSpace(phoneNumber)) { MessageBox.Show("Invalid or empty phone number", "Phone Number is Required"); return; } if (comboBox_customerType.Text.Equals("Premium") && string.IsNullOrWhiteSpace(richTextBox_creditLimit.Text)) { MessageBox.Show("Invalid or empty credit limit", "Credit linit is Required"); return; } if (customerType.Equals("Premium")) { newCustomer = new PremiumCustomer(firstName, lastName, address, customerType, phoneNumber, Int32.Parse(richTextBox_creditLimit.Text)); } else { newCustomer = new NormalCustomer(firstName, lastName, address, customerType, phoneNumber); } CustomersData.addNewCustomer(newCustomer); Form mainForm = Application.OpenForms["CustomerForm"]; CustomerForm salesForm = (CustomerForm)mainForm; salesForm.reloadList(); this.Close(); }
public EditCustomerForm(Customer currentCustomer) : this() { CurrentCustomer = currentCustomer; if (currentCustomer.CustomerType.Equals("Premium")) { PremiumCustomer CurrentCustomer = (PremiumCustomer)currentCustomer; richTextBox_creditLimit.Text = CurrentCustomer.CreditLimit.ToString(); } else { NormalCustomer CurrentCustomer = (NormalCustomer)currentCustomer; richTextBox_creditLimit.Hide(); label_creditLimit.Hide(); } }
public static void updateInformation(Customer currentCustomer) { Customer existingCustomer = customers.Find(x => x.ID == currentCustomer.ID); int index = customers.IndexOf(existingCustomer); if (currentCustomer.CustomerType.Equals("Premium")) { PremiumCustomer existingPremiumCustomer = (PremiumCustomer)currentCustomer; customers[index] = existingPremiumCustomer; } else { NormalCustomer existingNormalCustomer = (NormalCustomer)currentCustomer; customers[index] = existingNormalCustomer; } }
private void button_save_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(richTextBox_firstName.Text)) { MessageBox.Show("Invalid or empty first name", "First Name is Required"); return; } if (string.IsNullOrWhiteSpace(richTextBox_lastName.Text)) { MessageBox.Show("Invalid or empty last name", "Last Name is Required"); return; } if (string.IsNullOrWhiteSpace(richTextBox_address.Text)) { MessageBox.Show("Invalid or empty address", "Address is Required"); return; } if (string.IsNullOrWhiteSpace(richTextBox_phoneNumber.Text)) { MessageBox.Show("Invalid or empty phone number", "Phone Number is Required"); return; } if (comboBox_customerType.Text.Equals("Premium") && string.IsNullOrWhiteSpace(richTextBox_creditLimit.Text)) { MessageBox.Show("Invalid or empty credit limit", "Credit linit is Required"); return; } if (comboBox_customerType.Text.Equals("Premium")) { PremiumCustomer currentPremiumCustomer = new PremiumCustomer(); currentPremiumCustomer.ID = CurrentCustomer.ID; currentPremiumCustomer.FirstName = richTextBox_firstName.Text; currentPremiumCustomer.LastName = richTextBox_lastName.Text; currentPremiumCustomer.CustomerType = comboBox_customerType.Text; currentPremiumCustomer.Address = richTextBox_address.Text;; currentPremiumCustomer.PhoneNumber = richTextBox_phoneNumber.Text; try { currentPremiumCustomer.CreditLimit = Int32.Parse(richTextBox_creditLimit.Text); }catch (FormatException fe) { MessageBox.Show("Invalid Format", "Invalid Credit Limit Format is Required"); return; } CurrentCustomer = currentPremiumCustomer; } else { NormalCustomer currentNormalCustomer = new NormalCustomer(); currentNormalCustomer.ID = CurrentCustomer.ID; currentNormalCustomer.FirstName = richTextBox_firstName.Text; currentNormalCustomer.LastName = richTextBox_lastName.Text; currentNormalCustomer.CustomerType = comboBox_customerType.Text; currentNormalCustomer.Address = richTextBox_address.Text;; currentNormalCustomer.PhoneNumber = richTextBox_phoneNumber.Text; CurrentCustomer = currentNormalCustomer; } CustomersData.updateInformation(CurrentCustomer); Form mainForm = Application.OpenForms["CustomerForm"]; CustomerForm salesForm = (CustomerForm)mainForm; salesForm.currentListOfCustomers[salesForm.currentIndex] = CurrentCustomer; salesForm.reloadList(); this.Close(); }