Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace lda58_Homework2
  13. {
  14. public partial class Addnewemployee : Form
  15. {
  16. public Addnewemployee()
  17. {
  18. InitializeComponent();
  19. //Adding items to the combobox
  20. CmbDept.Items.Add("Hardware");
  21. CmbDept.Items.Add("Legal");
  22. CmbDept.Items.Add("Marketing");
  23. CmbDept.Items.Add("Operations");
  24. CmbDept.Items.Add("Production");
  25. CmbDept.Items.Add("Shipping");
  26. CmbDept.Items.Add("Software");
  27. }
  28.  
  29. private void Addnewemployee_Load(object sender, EventArgs e)
  30. {
  31.  
  32. }
  33.  
  34. private void Btnexit_Click(object sender, EventArgs e)
  35. {
  36. //closing the application
  37. this.Close();
  38. }
  39.  
  40. private void BtnNewemployee_Click(object sender, EventArgs e)
  41. {
  42. StreamWriter outputfile;
  43. int specificID;
  44. var lines = File.ReadAllLines("company.txt");
  45. outputfile = File.AppendText("company.txt");
  46. Boolean unique = false;
  47.  
  48. foreach (var employeeinfo in lines)
  49. //for each line in the file
  50. {
  51. string[] employeeID = employeeinfo.Split(',');
  52. specificID = int.Parse(employeeID[0]);
  53. //This is the first item in the array of employee info ( the line )
  54.  
  55. if (specificID == int.Parse(TbNewID.Text))
  56. //If the employee number all ready exists
  57. {
  58. MessageBox.Show("Employee ID already in the Database!");
  59. }
  60. else
  61. {
  62. //The number is unique!
  63. unique = true;
  64. }
  65. }
  66. if (unique == true)
  67. {
  68. //Add formatted line to the end of the file
  69. outputfile.WriteLine(TbNewID.Text + "," + CmbDept.SelectedIndex.ToString() + "," + Tbfirst.Text + "," + Tblast.Text);
  70. MessageBox.Show("Employee ID added!");
  71. }
  72. outputfile.Close();
  73. this.Close();
  74.  
  75.  
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement