//Create and Read Method private void BtnCustomerAdd_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TxtCustomerName.Text) || !string.IsNullOrEmpty(TxtCustomerSurname.Text) || !string.IsNullOrEmpty(TxtCustomerIdNumber.Text)) { Customer customer = new Customer//add user to database { Name = TxtCustomerName.Text, Surname = TxtCustomerSurname.Text, Phone = TxtCustomerIdNumber.Text, }; _context.Customers.Add(customer); _context.SaveChanges(); } else { MessageBox.Show("Please"); } DgvAddCustomer.Rows.Clear(); FillCustomers(); Clear(); }
//Create and Read Method private void BtnCustomerAdd_Click(object sender, EventArgs e) { DialogResult r = MessageBox.Show("Are you Sure?", "Yes", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (r == DialogResult.Yes) { if (!string.IsNullOrEmpty(TxtCustomerName.Text) || !string.IsNullOrEmpty(TxtCustomerSurname.Text) || !string.IsNullOrEmpty(TxtCustomerPhone.Text) || !string.IsNullOrEmpty(TxtCustomerEmail.Text) || !string.IsNullOrEmpty(TxtCustomerIdNumber.Text)) { Customer customer = new Customer//add user to database { Name = TxtCustomerName.Text, Surname = TxtCustomerSurname.Text, Phone = TxtCustomerPhone.Text, Email = TxtCustomerEmail.Text, IdentifyNumber = TxtCustomerIdNumber.Text, }; _context.Customers.Add(customer); _context.SaveChanges(); } else { MessageBox.Show("Please"); } DgvAddCustomer.Rows.Clear(); FillCustomers(); Clear(); } if (r == DialogResult.No) { Clear(); } }