Exemplo n.º 1
0
        private void SaveAccToDB(EmailBody emailBody)
        {
            //Write all the user details into a file
            File.WriteAllText($"{emailBody.userAccNum}.txt", Convert.ToString(emailBody.userAccNum));
            File.AppendAllText($"{emailBody.userAccNum}.txt", $"\n{0}");
            File.AppendAllText($"{emailBody.userAccNum}.txt", $"\n{emailBody.userFirstName}");
            File.AppendAllText($"{emailBody.userAccNum}.txt", $"\n{emailBody.userLastName}");
            File.AppendAllText($"{emailBody.userAccNum}.txt", $"\n{emailBody.userAddress}");
            File.AppendAllText($"{emailBody.userAccNum}.txt", $"\n{emailBody.userPhone}");
            File.AppendAllText($"{emailBody.userAccNum}.txt", $"\n{emailBody.userEmail}");

            //Append the new acc number to the "account databse"
            string appendableNum = Convert.ToString(emailBody.userAccNum);

            //check if the databse is empty and determine if it should escape a line
            //if database is empty, append acc num with out adding a line on top
            if (File.ReadAllLines("accDB.txt").Length == 0)
            {
                File.AppendAllText("accDB.txt", appendableNum);
            }
            else
            {
                File.AppendAllText("accDB.txt", "\n" + appendableNum);
            }
        }
Exemplo n.º 2
0
        public void sendEmail(string from, string to, EmailBody emailBody, double balance, bool newAcc)
        {
            //create a smtpclient instance
            using (SmtpClient smtpClient = new SmtpClient())
            {
                //acc and password to login to google
                var basicCredential = new NetworkCredential("*****@*****.**", "Wacdzx666");

                //create a email message instance
                using (MailMessage message = new MailMessage())
                {
                    //sender address
                    MailAddress fromAddress = new MailAddress(from);

                    smtpClient.EnableSsl = true;
                    smtpClient.Port      = 587;
                    //specify domain as gmail
                    smtpClient.Host = "smtp.gmail.com";
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials           = basicCredential;

                    message.From    = fromAddress;
                    message.Subject = "Your new KAZ bank account detail";

                    //based on parameter if it is new acc
                    //if new account, send as new account detail, else it should be send as bank account statement
                    string status         = newAcc ? "new account detail" : "bank account statement";
                    string displayBalance = newAcc ? "" : $"\n<p>Account Balance: ${Convert.ToString(balance)}</p>";

                    // Set IsBodyHtml to true means you can send HTML email.
                    message.IsBodyHtml = true;
                    message.Body       = $"<h3>Below is your {status}</h3>" +
                                         $"\n<p>Account number: {emailBody.userAccNum}</p> " +
                                         displayBalance +
                                         $"\n<p>First name: {emailBody.userFirstName}</p>" +
                                         $"\n<p>Last name: {emailBody.userLastName}</p>" +
                                         $"\n<p>Address: {emailBody.userAddress}</p>" +
                                         $"\n<p>Phone: {emailBody.userPhone}</p>" +
                                         $"\n<p>Email Address: {emailBody.userEmail}</p>";
                    message.To.Add(to);

                    try
                    {
                        Console.WriteLine("\t\t Please wait for the email to be sent...");
                        smtpClient.Send(message);
                    }
                    catch (Exception ex)
                    {
                        //Error, could not send the message
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
Exemplo n.º 3
0
        //display statement
        private void DisplayFound(int accnumber)
        {
            DisplayDetail displayDetail = new DisplayDetail();

            //store all the detail into array
            string[] accoutDetail = File.ReadAllLines($"{accnumber}.txt");
            Console.WriteLine("\t ------------------------------------------------------------- ");
            Console.WriteLine("\t|                        Account Details                      |");
            Console.WriteLine("\t =============================================================");
            Console.WriteLine("\t\t\b\b\bAccount Statement");
            Console.WriteLine("");

            //display detail
            displayDetail.UserDetails(accoutDetail);

            //display recent transaction below
            //based on number of transcations, switch display appropriate
            //accountDetail with no transaction is 7, start from length 8, display transaction detail
            switch (accoutDetail.Length)
            {
            case 7:
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: N/A");
                break;

            case 8:
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[7]}");
                break;

            case 9:
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[7]}");
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[8]}");
                break;

            case 10:
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[7]}");
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[8]}");
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[9]}");
                break;

            case 11:
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[7]}");
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[8]}");
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[9]}");
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[10]}");
                break;

            default:
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[accoutDetail.Length - 5]}");
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[accoutDetail.Length - 4]}");
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[accoutDetail.Length - 3]}");
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[accoutDetail.Length - 2]}");
                Console.WriteLine($"\t\t\b\b\bRecent Transcation: {accoutDetail[accoutDetail.Length - 1]}");
                break;
            }
            Console.WriteLine("\t ------------------------------------------------------------- ");
            Console.WriteLine("");

            //get user input and dertermine whether to send email or not
            string emailState = "";

            while (emailState != "y" && emailState != "n")
            {
                Console.Write("\t\t Email statement (y/n)? ");
                emailState = Console.ReadLine();
            }
            if (emailState == "n")
            {
                this.error = false;
            }
            else if (emailState == "y")
            {
                //send the email
                EmailBody   emailBody   = new EmailBody(accoutDetail[2], accoutDetail[3], accoutDetail[4], accoutDetail[6], Convert.ToInt32(accoutDetail[0]), Convert.ToInt32(accoutDetail[5]));
                EmailSender emailSender = new EmailSender();
                emailSender.sendEmail(this.emailSenderAddress, accoutDetail[6], emailBody, Convert.ToDouble(accoutDetail[1]), false);
                Console.WriteLine("\t\t Email sent Successfully!...");
                Console.WriteLine("\t\t Press any key to go to the menu..");
                Console.ReadKey();
            }
        }
Exemplo n.º 4
0
        public void NewAccScreen()
        {
            //do while loop to keep displaying the page if user wants to re-enter
            do
            {
                try
                {
                    this.error = false;
                    Console.Clear();
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    Console.WriteLine("\t|                      Create A New Account                   |");
                    Console.WriteLine("\t =============================================================");
                    Console.WriteLine("\t|                     Enter the Field Below                   |");
                    Console.WriteLine("\t|                                                             |");
                    Console.Write("\t| First Name: ");

                    //record cursor position for entering firstname
                    int firstNameLeft = Console.CursorLeft;
                    int firstNameTop  = Console.CursorTop;
                    Console.Write("                                                |\n");
                    Console.Write("\t| Last Name: ");
                    int lastNameLeft = Console.CursorLeft;
                    int lastNameTop  = Console.CursorTop;
                    Console.Write("                                                 |\n");
                    Console.Write("\t| Address: ");
                    int addressLeft = Console.CursorLeft;
                    int addressTop  = Console.CursorTop;
                    Console.Write("                                                   |\n");
                    Console.Write("\t| Phone: ");
                    int phoneLeft = Console.CursorLeft;
                    int phoneTop  = Console.CursorTop;
                    Console.Write("                                                     |\n");
                    Console.Write("\t| Email: ");
                    int emailLeft = Console.CursorLeft;
                    int emailTop  = Console.CursorTop;
                    Console.Write("                                                     |\n");
                    Console.WriteLine("\t|                                                             |");
                    Console.WriteLine("\t ------------------------------------------------------------- ");
                    this.feedbackLeft = Console.CursorLeft;
                    this.feedbackTop  = Console.CursorTop;

                    //set the cursor position to firstname enter position
                    Console.SetCursorPosition(firstNameLeft, firstNameTop);
                    this.firstName = Console.ReadLine();
                    Console.SetCursorPosition(lastNameLeft, lastNameTop);
                    this.lastName = Console.ReadLine();
                    Console.SetCursorPosition(addressLeft, addressTop);
                    this.userAddress = Console.ReadLine();
                    Console.SetCursorPosition(phoneLeft, phoneTop);
                    string tempInput = Console.ReadLine();
                    this.phoneNum = Convert.ToInt32(tempInput);

                    //check if the input is within 10 integer
                    if (tempInput.Length > 10)
                    {
                        throw new Exception("Please enter a valid phone number");
                    }


                    Console.SetCursorPosition(emailLeft, emailTop);
                    this.emailAdd = Console.ReadLine();

                    //check if email entered contains @
                    if (!this.emailAdd.Contains("@"))
                    {
                        throw new Exception("Please enter a valid email address");
                    }

                    //check if email entered contains specific domain name
                    if (!this.emailAdd.Contains("gmail.com") && !this.emailAdd.Contains("outlook.com") && !this.emailAdd.Contains("uts.edu.au"))
                    {
                        throw new Exception("Please enter a valid email address");
                    }
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);

                    //handle user input for confirm y/n
                    string confirm = "";

                    //loop until user enter either y or n
                    while (confirm != "y" && confirm != "n")
                    {
                        Console.Write("\t\t Is the information correct (y/n)? ");
                        confirm = Console.ReadLine();
                    }

                    //if n, throw empty exception and let user re-enter details
                    if (confirm == "n")
                    {
                        throw new Exception("");
                    }

                    //Go to the file database to generate a new uniq account number
                    int newAccNum = GenNewAccNum();

                    //generate a struct for email body
                    var emailBody = new EmailBody(this.firstName, this.lastName, this.userAddress, this.emailAdd, newAccNum, this.phoneNum);

                    //send the email to the user
                    EmailSender newEmail = new EmailSender();
                    newEmail.sendEmail(this.emailSenderAddress, this.emailAdd, emailBody, 0, true);

                    //Save the user detail to a file
                    SaveAccToDB(emailBody);

                    Console.WriteLine("\t\t Account detail is sent to the provided email address");
                    Console.WriteLine("\t\t Your new Account number is: " + newAccNum);
                    Console.WriteLine("\t\t Press any key to go to the menu..");

                    Console.ReadKey();
                }
                catch (OverflowException ex)
                {
                    //get rid of the warning
                    //handle exception if user enter a number greater than 10 digit and cannot convert
                    ex.ToString();
                    this.error = true;
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t Please enter a valid number");
                    Console.WriteLine("\t\t Press any key to re-enter details..");
                    Console.ReadKey();
                }
                catch (Exception e)
                {
                    //set error to true so that loop would continue to loop
                    this.error = true;
                    Console.SetCursorPosition(this.feedbackLeft, this.feedbackTop);
                    Console.WriteLine("\t\t " + e.Message);
                    Console.WriteLine("\t\t Press any key to re-enter details..");
                    Console.ReadKey();
                }
            } while (this.error);
        }