private void SearchDepartmentNoButton_Click(object sender, EventArgs e)
 {
     if (!SearchEditableDepartmentNo.Visible)
     {
         SearchEditableDepartmentNo.Text    = SearchValueDepartmentNo.Text;
         SearchEditableDepartmentNo.Visible = true;
         SearchDepartmentNoButton.Text      = "Done";
     }
     else
     {
         if (SearchEditableDepartmentNo.Text.Length > 5 || SearchEditableDepartmentNo.Text.Length == 0)
         {
             MessageBox.Show("Invalid Department Number");
             return;
         }
         SearchEditableDepartmentNo.Visible = false;
         SearchDepartmentNoButton.Text      = "Edit";
         ActiveEmployee.DepId = int.Parse(SearchEditableDepartmentNo.Text);
         FileOperation.FileErrorType res = FileOperation.updateEmployee(ActiveUID, ActiveEmployee);
         if (res == FileOperation.FileErrorType.InvalidDepartmentID)
         {
             MessageBox.Show("Invalid Department");
         }
         else
         {
             SearchValueDepartmentNo.Text = SearchEditableDepartmentNo.Text;
         }
     }
 }
 private void SearchNameButton_Click(object sender, EventArgs e)
 {
     if (!SearchEditableName.Visible)
     {
         SearchEditableName.Text    = SearchValueName.Text;
         SearchEditableName.Visible = true;
         SearchNameButton.Text      = "Done";
     }
     else
     {
         if (SearchEditableName.Text.Length > 20 || SearchEditableName.Text.Length == 0)
         {
             MessageBox.Show("Invalid Name");
             return;
         }
         SearchEditableName.Visible = false;
         SearchNameButton.Text      = "Edit";
         ActiveEmployee.Name        = SearchEditableName.Text;
         FileOperation.FileErrorType res = FileOperation.updateEmployee(ActiveUID, ActiveEmployee);
         SearchValueName.Text = SearchEditableName.Text;
     }
 }
    private void EmployeeSubmitButton_Click(object sender, EventArgs e)
    {
        //Clearing existing error messages
        EmployeeNameError.Text  = "";
        EmployeeDepIdError.Text = "";
        EmployeeIdError.Text    = "";
        Submit_Result.Text      = "";

        //Displaying error messages if input is invalid
        bool InvalidInput = false;

        if (EmployeeName.Text.Length > 20 || EmployeeName.Text.Length == 0)
        {
            EmployeeNameError.Text = "Name's length should be between 1 and 20";
            InvalidInput           = true;
        }
        if (EmployeeId.Text.Length > 5 || EmployeeId.Text.Length == 0)
        {
            EmployeeIdError.Text = "ID's length should be between 1 and 5";
            InvalidInput         = true;
        }
        if (EmployeeDepId.Text.Length > 5 || EmployeeDepId.Text.Length == 0)
        {
            EmployeeDepIdError.Text = "ID's length should be between 1 and 5";
            InvalidInput            = true;
        }
        if (InvalidInput == true)
        {
            return;
        }

        //Creating Employee object with the entered data
        Employee temp = new Employee();

        temp.Id       = int.Parse(EmployeeId.Text);
        temp.Name     = EmployeeName.Text;
        temp.DepId    = int.Parse(EmployeeDepId.Text);
        temp.HireDate = EmployeeHiryDate.Value;

        //Sending entered data to FileOperation class
        FileOperation.FileErrorType res = FileOperation.WriteEmployee(temp, FileOperation.getOffset(), true);

        //Prompting the user with the submission result
        if (res == FileOperation.FileErrorType.NoError)
        {
            Submit_Result.Text = "Employee was addded succesfully!";

            //Clearing input fields
            EmployeeId.Text    = "";
            EmployeeName.Text  = "";
            EmployeeDepId.Text = "";
        }
        else if (res == FileOperation.FileErrorType.InvalidDepartmentID)
        {
            EmployeeDepIdError.Text = "Department ID doesn't exist";
        }
        else if (res == FileOperation.FileErrorType.InvalidEmployeeID)
        {
            EmployeeIdError.Text = "Employee ID is used before";
        }
    }