private void CreateCustomerButton_Click(object sender, EventArgs e) { Customer aCustomer = new Customer(); aCustomer.PersonId = custNum.NextValue(lastValueCust); aCustomer.Fn = FirstNametextBox.Text; aCustomer.Ln = LastNametextBox.Text; if (EmailValidation(EmailtextBox.Text)) { aCustomer.Email = new Email(EmailtextBox.Text); } else { MessageBox.Show("Invalid email address!"); aCustomer = null; } if (!(IntegerValidation(StreetNumbertextBox.Text))) { MessageBox.Show("Invalid street number!"); aCustomer = null; } if (!(IntegerValidation(AptNumbertextBox.Text))) { MessageBox.Show("Invalid apartment number!"); aCustomer = null; } if (aCustomer != null) { aCustomer.Email = new Email(EmailtextBox.Text); aCustomer.Phone = new Phone(PhonetextBox.Text); aCustomer.Address = new Address(Int32.Parse(StreetNumbertextBox.Text), StreetNametextBox.Text, Int32.Parse(AptNumbertextBox.Text), CitytextBox.Text, ProvincetextBox.Text, CountrytextBox.Text, PostalCodetextBox.Text); aCustomer.Pin = 1234; CustomerIDtextBox.Text = Convert.ToString(aCustomer.PersonId); AccCustIDtextBox.Text = CustomerIDtextBox.Text; dictCustomer.Add(aCustomer.PersonId, aCustomer); sortedCustomer.Add(aCustomer.PersonId, aCustomer); CustomerDB.SaveToFile(dictCustomer); CustomerDB.SaveToFile(sortedCustomer); ShowAllCustomers(dictCustomer); lastValueCust++; } else { MessageBox.Show("Please input correct information!"); } }
//make a transaction private void ConfirmButton_Click(object sender, EventArgs e) { UpdateTempData(); Checking tempCheckAccount = new Checking(); Saving tempSavAccount = new Saving(); double amount; Transaction aTransac = new Transaction(); if (Double.TryParse(AmountTextBox.Text, out amount)) { if (amount > 0) { aTransac.Date = DateTime.Now; aTransac.Amount = Convert.ToDouble(AmountTextBox.Text); aTransac.AccNumber = Int32.Parse(AccNumTextBox.Text); aTransac.AccType = dictAccount[Int32.Parse(AccNumTextBox.Text)].Acctype; } else { MessageBox.Show("Amount must be a positive value!"); aTransac = null; } } else { MessageBox.Show("Invalid amount!"); } /* * if (aTransac.AccType == Account.EnumType.Checkings) * { * foreach (Checking current in aCustomer.customerAccount.Values) * { * tempCheckAccount = (Checking)current; * } * if (tempCheckAccount.Counter < tempCheckAccount.LimitTransac) * { * tempCheckAccount.Counter++; * } * else * { * aTransac = null; * MessageBox.Show("You have reached your transaction limit for this account"); * } * } * * if (aTransac.AccType == Account.EnumType.Savings) * { * foreach (Saving current in aCustomer.customerAccount.Values) * { * tempSavAccount = (Saving)current; * } * } */ if (!(checkBoxWithdraw.Checked || checkBoxDeposit.Checked)) { MessageBox.Show("Please Select a Transaction Type"); aTransac = null; } if (aTransac != null && (Double.TryParse(AmountTextBox.Text, out amount)))/////CHECAR REPETICAO AQUI! { if (checkBoxWithdraw.Checked) { aTransac.TransNumber = transacNum.NextValue(lastValueTransac); aTransac.TransType = Transaction.EnumType.Withdraw; dictAccount[Int32.Parse(AccNumTextBox.Text)].Balance -= aTransac.Amount; dictCustomer[Int32.Parse(code)].customerAccount[Int32.Parse(AccNumTextBox.Text)].Balance -= aTransac.Amount; } else if (checkBoxDeposit.Checked) { aTransac.TransNumber = transacNum.NextValue(lastValueTransac); aTransac.TransType = Transaction.EnumType.Deposit; dictAccount[Int32.Parse(AccNumTextBox.Text)].Balance += aTransac.Amount; dictCustomer[Int32.Parse(code)].customerAccount[Int32.Parse(AccNumTextBox.Text)].Balance += aTransac.Amount; } TransactionNumberTextBox.Text = Convert.ToString(aTransac.TransNumber); NewBalanceTextBox.Text = Convert.ToString(dictCustomer[Int32.Parse(code)].customerAccount[Int32.Parse(AccNumTextBox.Text)].Balance); sortedTransaction.Add(aTransac.TransNumber, aTransac); TransactionDB.SaveToFile(sortedTransaction); dictTransaction.Add(aTransac.TransNumber, aTransac); TransactionDB.SaveToFile(dictTransaction); dictAccount[Int32.Parse(AccNumTextBox.Text)].accTransactionDict.Add(aTransac.TransNumber, aTransac); AccountDB.SaveToFile(dictAccount); dictCustomer[Int32.Parse(code)].customerAccount[Int32.Parse(AccNumTextBox.Text)].accTransactionDict.Add(aTransac.TransNumber, aTransac); CustomerDB.SaveToFile(dictCustomer); DisplayTransacList(dictCustomer[Int32.Parse(code)].customerAccount[Int32.Parse(AccNumTextBox.Text)].accTransactionDict); Dictionary <int, Account> tempDictAccount = new Dictionary <int, Account>(); tempDictAccount = dictCustomer[Int32.Parse(code)].customerAccount; DisplayAccList(tempDictAccount);//ATUALIZAR lastValueTransac++; ConfirmButton.Enabled = false; } }