private void btnAdd_Click(object sender, EventArgs e) { var customerRepository = new SqlCustomerRepository(frmGymManager.connectionString); var customer = new Customer(); if (dgvAddCustomer.CurrentRow.Cells[0].Value != null && dgvAddCustomer.CurrentRow.Cells[1].Value != null && dgvAddCustomer.CurrentRow.Cells[2].Value != null && dgvAddCustomer.CurrentRow.Cells[3].Value != null) { customer.Name = dgvAddCustomer.CurrentRow.Cells[0].Value.ToString(); customer.Surname = dgvAddCustomer.CurrentRow.Cells[1].Value.ToString(); customer.Street = dgvAddCustomer.CurrentRow.Cells[2].Value.ToString(); customer.HouseNumber = Convert.ToInt32(dgvAddCustomer.CurrentRow.Cells[3].Value); customer.PhoneNumber = dgvAddCustomer.CurrentRow.Cells[4].Value.ToString(); customer.Email = dgvAddCustomer.CurrentRow.Cells[5].Value.ToString(); customer.Validaty = Convert.ToInt32(dgvAddCustomer.CurrentRow.Cells[7].Value); customer.Price = Convert.ToInt32(dgvAddCustomer.CurrentRow.Cells[8].Value); customer.CardType = dgvAddCustomer.CurrentRow.Cells[6].Value.ToString(); customer.AdminId = ActiveAdmin.Id; if (customerRepository.AddNewCustomer(customer) > 0) { MessageBox.Show("Successfull operation", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("Try Again", "Allert", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Enter data!"); } }
private void btAdd_Click(object sender, EventArgs e) { //checks inputs for length and isempty if (tbName.Text.Length <= 50 && !String.IsNullOrWhiteSpace(tbName.Text) && tbSurname.Text.Length <= 50 && !String.IsNullOrWhiteSpace(tbSurname.Text) && tbContactPhone.Text.Length <= 50 && !String.IsNullOrWhiteSpace(tbContactPhone.Text) && tbAdress.Text.Length <= 50 && !String.IsNullOrWhiteSpace(tbAdress.Text)) { var customerRepository = new SqlCustomerRepository(Globals.connectionString); customerRepository.AddNewCustomer(new Customer() { Adress = tbAdress.Text, ContactPhone = tbContactPhone.Text, Name = tbName.Text, Surname = tbSurname.Text }); this.Close(); } else { MessageBox.Show("Plesae verify input data", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }