Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace lda58_Homework2
- {
- public partial class Addnewemployee : Form
- {
- public Addnewemployee()
- {
- InitializeComponent();
- //Adding items to the combobox
- CmbDept.Items.Add("Hardware");
- CmbDept.Items.Add("Legal");
- CmbDept.Items.Add("Marketing");
- CmbDept.Items.Add("Operations");
- CmbDept.Items.Add("Production");
- CmbDept.Items.Add("Shipping");
- CmbDept.Items.Add("Software");
- }
- private void Addnewemployee_Load(object sender, EventArgs e)
- {
- }
- private void Btnexit_Click(object sender, EventArgs e)
- {
- //closing the application
- this.Close();
- }
- private void BtnNewemployee_Click(object sender, EventArgs e)
- {
- StreamWriter outputfile;
- int specificID;
- var lines = File.ReadAllLines("company.txt");
- outputfile = File.AppendText("company.txt");
- Boolean unique = false;
- foreach (var employeeinfo in lines)
- //for each line in the file
- {
- string[] employeeID = employeeinfo.Split(',');
- specificID = int.Parse(employeeID[0]);
- //This is the first item in the array of employee info ( the line )
- if (specificID == int.Parse(TbNewID.Text))
- //If the employee number all ready exists
- {
- MessageBox.Show("Employee ID already in the Database!");
- }
- else
- {
- //The number is unique!
- unique = true;
- }
- }
- if (unique == true)
- {
- //Add formatted line to the end of the file
- outputfile.WriteLine(TbNewID.Text + "," + CmbDept.SelectedIndex.ToString() + "," + Tbfirst.Text + "," + Tblast.Text);
- MessageBox.Show("Employee ID added!");
- }
- outputfile.Close();
- this.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement