private void SubmitButton_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || string.IsNullOrWhiteSpace(textBoxMiddleName.Text) || string.IsNullOrWhiteSpace(textBoxLastName.Text) || string.IsNullOrWhiteSpace(textBoxAddress.Text) || string.IsNullOrWhiteSpace(textBoxEmail.Text) || string.IsNullOrWhiteSpace(textBoxPhone.Text) || Controls.OfType <RadioButton>().FirstOrDefault(x => x.Checked) == null) { string message = "All fields must be fill up."; string caption = "Please try again."; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK); } else { Customer customer = new Customer(); customer.FirstName = textBoxFirstName.Text; customer.MiddleName = textBoxMiddleName.Text; customer.LastName = textBoxLastName.Text; customer.Gender = Controls.OfType <RadioButton>().FirstOrDefault(x => x.Checked).Text; customer.ContactNo = textBoxPhone.Text; customer.Email = textBoxEmail.Text; customer.Address = textBoxAddress.Text; if ((customer.Id = _manager.Add(customer)) > 0) { _success = true; CustomerForm customerForm = Application.OpenForms.OfType <CustomerForm>().FirstOrDefault(); customerForm.LoadData(); ProfileForm profileForm = new ProfileForm(customer.Id); profileForm.MdiParent = this.ParentForm; profileForm.Show(); this.Close(); } else { string message = string.Empty; string caption = "Please try again."; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK); } } } catch (Exception ex) { Logger.log.Error(ex.ToString()); } }
private void EditProfileButton_Click(object sender, EventArgs e) { try { if (EditProfileButton.Text.Equals(ProfileStringConstants.EDIT_PROFILE, StringComparison.OrdinalIgnoreCase)) { string saveText = ProfileStringConstants.SAVE_BUTTON.FirstCharToUpper(); EditProfileButton.Text = saveText; textBoxName.ReadOnly = false; textBoxAddress.ReadOnly = false; textBoxEmail.ReadOnly = false; textBoxPhone.ReadOnly = false; } else { string[] name = textBoxName.Text.Split(' '); if (name.Length == 3 && !string.IsNullOrWhiteSpace(name[0]) && !string.IsNullOrWhiteSpace(name[2])) { using (TransactionScope scope = new TransactionScope()) { _customer.Info.FirstName = name[0]; _customer.Info.MiddleName = name[1]; _customer.Info.LastName = name[2]; _customer.Info.Address = textBoxAddress.Text; _customer.Info.Email = textBoxEmail.Text; _customer.Info.ContactNo = textBoxPhone.Text; if (_customerManager.Update(_customer.Info)) { CustomerForm logInForm = Application.OpenForms.OfType <CustomerForm>().FirstOrDefault(); logInForm.LoadData(); scope.Complete(); } else { string message = "Can't update profile. Please try again."; string caption = "Error"; MessageBox.Show(message, caption, MessageBoxButtons.OK); } } } else { string message = "Entered Name should follow format \"firstname middlename lastname\""; string caption = "Error"; MessageBox.Show(message, caption, MessageBoxButtons.OK); } string editText = ProfileStringConstants.EDIT_PROFILE.FirstCharToUpper(); EditProfileButton.Text = editText; textBoxName.ReadOnly = true; textBoxAddress.ReadOnly = true; textBoxEmail.ReadOnly = true; textBoxPhone.ReadOnly = true; } LoadData(); } catch (Exception ex) { Logger.log.Error(ex.ToString()); } }