Beispiel #1
0
    protected void saveButton_Click(object sender, EventArgs e)
    {
        successLabel.Text = "";
        if (projectDropDownList.SelectedIndex.Equals(0))
        {
            errorLabel.Text = "Please select a project";
            return;
        }
        else if (selectedEmployeeListBox.Items.Count == 0)
        {
            errorLabel.Text = "Please select employee(s)";
            return;
        }

        string employeeNames = string.Empty;
        string employeeIDs   = string.Empty;

        try
        {
            foreach (ListItem item in selectedEmployeeListBox.Items)
            {
                employeeNames += item.Text + ",";
                employeeIDs   += item.Value + ",";
            }

            //removes the last coma from the string
            employeeNames = employeeNames.Substring(0, employeeNames.Length - 1);
            employeeIDs   = employeeIDs.Substring(0, employeeIDs.Length - 1);

            Project projectObject = new Project();
            projectObject.ID          = projectDropDownList.SelectedItem.Value;
            projectObject.Employee_Id = employeeIDs;
            ProjectGateway ProjectGatewayObject = new ProjectGateway();
            successLabel.Text = ProjectGatewayObject.AddEmployeeToProject(projectObject).ToString();

            if (successLabel.Text == "True")
            {
                successLabel.Text = "Added the new employee to the project";
            }

            errorLabel.Text = "";
            nonMemberEmployeeListBox.Items.Clear();
            selectedEmployeeListBox.Items.Clear();

            FillEmployeeListBox();
        }
        catch (SqlException sqlExceptionObj)
        {
            errorLabel.Text = sqlExceptionObj.Message;
        }
        catch (Exception exceptionObj)
        {
            errorLabel.Text = exceptionObj.Message;
        }
    }