private void btnAddClient_Click(object sender, EventArgs e) { try { List <Client> ClientList = clients.ReadingClients(); List <Account> AccountsList = accounts.ReadAccounts(); string clientID = txtClientID.Text; string name = txtClientName.Text; string surname = txtClientSurname.Text; string PhoneN = txtClientPN.Text; string email = txtEmail.Text; DateTime dob = DateTime.Parse(dtpDOB.Text); string IdNumber = txtIDNumber.Text; string Clientstatus = txtClientStatus.Text; string status = txtStatus.Text; int AccountID = int.Parse(txtAccId.Text); string accountN = txtAccNumber.Text; string accType = txtAccType.Text; string billType = txtBillingType.Text; string BankName = txtBankName.Text; int residenceID = int.Parse(txtResidenceID.Text); string address = txtAddress.Text; // Checking if all the input boxes are filled with the information if (name == "" && surname == "" && PhoneN == "" && email == "" && Clientstatus == "" && txtAccId.Text == "" && txtAccNumber.Text == "" && accType == "" && billType == "" && BankName == "" && status == "") { MessageBox.Show("All the information is required", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { //The Inserting method from the presentation layer which is for two tables named Clients and Accounts tables. foreach (var item in ClientList) { foreach (var acc in AccountsList) { if (clientID == item.ClientID.ToString() && AccountID == acc.AccountID) { storage = "Client or Account Exist"; } } } } try { if (storage != "Client or Account Exist ") { clients.InsertClient(clientID, name, surname, dob, IdNumber, PhoneN, email, Clientstatus, status); accounts.InsertAccount(AccountID, clientID, accountN, accType, billType, BankName); residences.InsertResidence(residenceID, clientID, address); MessageBox.Show("Client has been added", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); Random randy = new Random(); int rando = randy.Next(0, 5); char ch = (char)('A' + rando); Random random = new Random(); int randm = random.Next(0, 999999); txtAccId.Text = randm.ToString(); dt.Clear(); dt = clients.GetClients(); Random rand = new Random(); int Num = rand.Next(0, 9999); txtAccId.Text = Num.ToString(); txtClientName.Clear(); txtClientSurname.Clear(); txtClientPN.Clear(); txtEmail.Clear(); txtStatus.Clear(); txtBankName.DataSource = null; txtAccType.DataSource = null; txtAccNumber.Clear(); txtBillingType.Clear(); txtAddress.Clear(); txtResidenceID.Clear(); } else { Random randy = new Random(); int rando = randy.Next(0, 5); char ch = (char)('A' + rando); Random random = new Random(); int randm = random.Next(0, 99999); foreach (var item in ClientList) { if (txtAccId.Text == item.ClientID) { txtAccId.Text = item.ClientID + 1; } } string text = Convert.ToString(randm).PadLeft(8, '0'); txtClientID.Text = ch.ToString() + text; } } catch (Exception r) { MessageBox.Show(r.Message); } dt.Clear(); dt = clients.GetClients(); } catch (Exception) { throw; } }