private void btnEdit_Click(object sender, EventArgs e) { Customer customer = new Customer(); customer.LastName = this.TxtBoxLastName.Text; customer.FirstName = this.TxtBoxFirstName.Text; customer.Cnp = this.TxtBoxCnp.Text; customer.BirthDate = this.DpBirthdate.Text; Dictionary <String, String> errors = Validations.validateCustInfo(customer); if (errors.Count != 0) { String errorMessage = null; errors.TryGetValue(errors.Keys.First <string>(), out errorMessage); MessageBox.Show(errorMessage); return; } customer.Phone = this.TxtBoxPhone.Text; customer.Email = this.TxtBoxEmail.Text; customer.Country = this.TxtBoxCountry.Text; customer.County = this.TxtBoxCounty.Text; customer.City = this.TxtBoxCity.Text; customer.Locality = this.TxtBoxLocality.Text; customer.Street = this.TxtBoxStreet.Text; customer.StreetNo = Int32.Parse(this.NudStreetNo.Value.ToString()); errors = Validations.validateCustDetails(customer); if (errors.Count != 0) { String errorMessage = null; errors.TryGetValue(errors.Keys.First <string>(), out errorMessage); MessageBox.Show(errorMessage); return; } if (errors.Count == 0) { SQLiteConnection connection = DatabaseConnection.getConnection(); connection.Open(); SQLiteTransaction transaction = connection.BeginTransaction(); ICustomersDAO customersDao = new CustomersDAO(); try { customersDao.updateCustomer(customer, connection); transaction.Commit(); MessageBox.Show("The Customer was successfully added!"); } catch (SQLiteException exception) { Console.WriteLine(exception.Message); transaction.Rollback(); MessageBox.Show("The Customer can't be update!"); } connection.Close(); } }
private void btnAllCustomers_Click(object sender, EventArgs e) { SQLiteConnection connection = DatabaseConnection.getConnection(); connection.Open(); Console.WriteLine("### Connection is: " + connection.State.ToString()); lvMain.View = View.Details; Utils.initCustListViewHeaders(lvMain); ICustomersDAO customersDao = new CustomersDAO(); List <Customer> customers = customersDao.getAllCustomers(connection); Utils.addCustomersToListView(lvMain, customers); connection.Close(); }
private void btnNewCustomer_Click(object sender, EventArgs e) { Customer customer = new Customer(); customer.LastName = this.TxtBoxLastName.Text; customer.FirstName = this.TxtBoxFirstName.Text; customer.Cnp = this.TxtBoxCnp.Text; customer.BirthDate = this.DpBirthdate.Text; Dictionary <String, String> errors = Validations.validateCustInfo(customer); if (errors.Count != 0) { String errorMessage = null; errors.TryGetValue(errors.Keys.First <string>(), out errorMessage); this.LblCustInfoError.Text = errorMessage; this.LblCustInfoError.Visible = true; return; } customer.Phone = this.TxtBoxPhone.Text; customer.Email = this.TxtBoxEmail.Text; customer.Country = this.TxtBoxCountry.Text; customer.County = this.TxtBoxCounty.Text; customer.City = this.TxtBoxCity.Text; customer.Locality = this.TxtBoxLocality.Text; customer.Street = this.TxtBoxStreet.Text; customer.StreetNo = Int32.Parse(this.NudStreetNo.Value.ToString()); errors = Validations.validateCustDetails(customer); if (errors.Count != 0) { String errorMessage = null; errors.TryGetValue(errors.Keys.First <string>(), out errorMessage); this.LblCustDetailsError.Text = errorMessage; this.LblCustDetailsError.Visible = true; return; } Account account = new Account(); int accountNo = 0; Int32.TryParse(this.TxtBoxAccountNo.Text, out accountNo); account.AccountNo = accountNo; account.AccountType = this.CbAccountType.SelectedValue.ToString(); account.Currency = this.CbCurrency.SelectedValue.ToString(); float amount = 0f; float.TryParse(TxtBoxAmount.Text.ToString(), out amount); account.Ammount = amount; errors = Validations.validateCustAccount(account); if (errors.Count != 0) { String errorMessage = null; errors.TryGetValue(errors.Keys.First <string>(), out errorMessage); this.LblAccountInfoError.Text = errorMessage; this.LblAccountInfoError.Visible = true; return; } if (errors.Count == 0) { SQLiteConnection connection = DatabaseConnection.getConnection(); connection.Open(); SQLiteTransaction transaction = connection.BeginTransaction(); ICustomersDAO customersDao = new CustomersDAO(); List <Account> custAccounts = new List <Account>(); custAccounts.Add(account); customer.CustomerAccounts = custAccounts; try { customersDao.addCustomer(customer, connection); customersDao.addCustomerDetails(customer, connection); customersDao.addCustomerAccounts(customer, connection); transaction.Commit(); this.LblConfirmationMessage.Visible = true; this.LblConfirmationMessage.Text = "Success!"; this.LblConfirmationMessage.ForeColor = System.Drawing.Color.Green; } catch (SQLiteException) { transaction.Rollback(); this.LblConfirmationMessage.Visible = true; this.LblConfirmationMessage.Text = "Error"; this.LblConfirmationMessage.ForeColor = System.Drawing.Color.Red; } connection.Close(); } }