private void btnAdd_Click(object sender, EventArgs e) { if (!validation.validID(txtID.Text))//checks valid id { MessageBox.Show("Invalid ID. Must be only digits and 5 in length."); validClient = false; validWorker = false; validManager = false; } else if (!validation.validName(txtName.Text)) //checks valid name { MessageBox.Show("Invalid Name. Cannot contain numbers, must be at least 2 letters."); validClient = false; validWorker = false; validManager = false; } else if (!validation.validBirthDate(txtBirthDate.Text)) //checks valid birthday { MessageBox.Show("Invalid Birth data. Must be of the format: mm/dd/yyyy"); validClient = false; validWorker = false; validManager = false; } else { if (isClient) //if the person entered is a client (when the user first clicked on the button) { if (!validation.validType(txtType.Text)) //checks if client validation is good, if not make everything false { MessageBox.Show("Invalid Job Type. Cannot contain digits and must be at least two characters."); validClient = false; validWorker = false; validManager = false; } else { validClient = true; validWorker = false; validManager = false; } } if (isManager) //if manager { if (!validation.validJobTitle(txtJobTitle.Text)) //checks valid job title { MessageBox.Show("Invalid Job Title. Cannot contain numbers and must be at least 2 in length"); } else if (!validation.validSalary(txtSalary.Text)) //checks valid salary { MessageBox.Show("Invalid Salary. Must be only digits and a period. Of the form xxxxx.yy (e.g. 80000.00)"); } else if (!validation.validBonus(txtBonus.Text)) //checks valid bonus { MessageBox.Show("Invalid Bonus. Must be only digits and a period. Of the form xxxxx.yy (e.g. 80000.00)"); } else { validClient = false; validWorker = false; validManager = true; } } if (isWorker) { if (!validation.validJobTitle(txtJobTitle.Text)) { MessageBox.Show("Invalid Job Title. Cannot contain numbers and must be at least 2 in length"); } else if (!validation.validHourlyPay(txtHourlyPay.Text)) { MessageBox.Show("Invalid Hourly Pay. Must be in decimal form (xx.yy) and cannot be lower than 7.25"); } else { validClient = false; validWorker = true; validManager = false; } } } if (validClient) //adds client to the person list { MessageBox.Show("CLIENT ADDED"); Person client = new Client(txtID.Text, txtName.Text, txtBirthDate.Text, txtType.Text); personList.add(client); POManager.writeToFile(personList, fileName); db.InsertClient(Int32.Parse(txtID.Text), txtName.Text, txtBirthDate.Text, txtType.Text); } if (validManager) //adds manager to the person list { MessageBox.Show("MANAGER ADDED"); decimal sal = Convert.ToDecimal(txtSalary.Text); decimal bon = Convert.ToDecimal(txtBonus.Text); Person manager = new Manager(txtID.Text, txtName.Text, txtBirthDate.Text, txtJobTitle.Text, sal, bon); personList.add(manager); POManager.writeToFile(personList, fileName); db.InsertManager(Int32.Parse(txtID.Text), txtName.Text, txtBirthDate.Text, bon, sal, txtJobTitle.Text); } if (validWorker) //adds worker to the person list { MessageBox.Show("WORKER ADDED"); decimal hourpay = Convert.ToDecimal(txtHourlyPay.Text); Person manager = new Worker(txtID.Text, txtName.Text, txtBirthDate.Text, txtJobTitle.Text, hourpay); personList.add(manager); POManager.writeToFile(personList, fileName); db.InsertWorker(Int32.Parse(txtID.Text), txtName.Text, txtBirthDate.Text, hourpay, txtJobTitle.Text); } //ADD TO PERSON LIST HERE }
private void frmEmpMan_Load(object sender, EventArgs e) { //read file POManager.readFromFile(ref personList, fileName);//when the form loads, read everything from .bin file to the person list //personList.printList(); }
private void btnClose_Click(object sender, EventArgs e) //closes the form { this.Close(); POManager.writeToFile(personList, fileName); }