private void deactivateEmployeeButton_Click(object sender, EventArgs e) { //Deactivates a selected employee. try { //Checks to ensure an employee is selected. if (employeeListingListView.SelectedItems.Count == 0) { MessageBox.Show("Employee not selected, select an Employee and try again."); } //Loops through and deletes only the selected employee. foreach (int i in employeeListingListView.SelectedIndices) { DsUtil utility = new DsUtil(); int employee = utility.getEmployeeId(employeeListingListView.Items[i].Text); employeeListingListView.Items.Remove(employeeListingListView.Items[i]); string query = "DELETE FROM software_eng_db_1.employee WHERE employee.employee_id = " + employee + ";"; RetrieveData rD = new RetrieveData(query); if (rD.updateData()) { //Shows a success message upon sucessful deletion from the database. MessageBox.Show("Employee Deactivated."); } } } catch { MessageBox.Show("Database may have disconnected, or selected data is not available."); } }
private void applyChangesButton_Click(object sender, EventArgs e) { //This button is used for two different things depending on the context in which it is clicked. The "handler" variable //is responsible for providing context as to whether this screen is creating or editing a project. Once clicked, the //buton methods will either create a new project or edit an existing one based on the current setting in the ProjectHandler.cs //class. DsUtil utility = new DsUtil(); handler = new ProjectHandler(DsUtil.formID); int project = DsUtil.selectedIndex; string projectName = projectNameTextBox.Text; int clientID = utility.getClientID(clientNameTextBox.Text); string shortDesc = shortDescTextBox.Text; DateTime date = dateTimePicker.Value; bool flag = false; bool flag1 = false; if (projectName != "" && clientID != 0 && shortDesc != "") { if (handler.getID() == 0) { //Create Project RetrieveData update = new RetrieveData(); flag = update.createProject(projectName, shortDesc, date, clientID); } else { //Edit Project RetrieveData edit = new RetrieveData(); flag1 = edit.editProject(projectName, shortDesc, date, clientID); } if (flag) { MessageBox.Show("Project created successfully."); } if (flag1) { MessageBox.Show("Project edited successfully."); } } else { MessageBox.Show("Data missing, please ensure you have filled out all required fields."); } }
private void editProjectButton_Click(object sender, EventArgs e) { //Launches the Project Screen for a given selected project. DsUtil dsU = new DsUtil(); //Checks to see if a project is selected: if (dsU.getSelected(employeeListView) != -1) { //If it is, assign the correct index for the project and launch the Project Screen. int index = employeeListView.Items[dsU.getSelected(employeeListView)].Index; dsU.assignIndex(index); this.Hide(); projectScreenForm projectScreen = new projectScreenForm(); projectScreen.Show(); } else { //If no project is selected, display an error message. MessageBox.Show("Please select a project to edit.", "Error"); } }
private void enterTaskButton_Click(object sender, EventArgs e) { DsUtil utility = new DsUtil(); //Set variables to user input int project = DsUtil.selectedIndex; string taskDesc = taskNameTextBox.Text; int hours = int.Parse(hoursTextBox.Text); int completedBy = utility.getEmployeeId(completedTextBox.Text); int materialID = utility.getMaterialId(materialNameTextBox.Text); bool flag = false; try { //Create SQL query. string query = "INSERT INTO software_eng_db_1.task (task_description, task_hours_to_complete, employee_id, project_id, material_id)" + " VALUES('" + taskDesc + "', " + hours + ", " + completedBy + ", " + project + ", " + materialID + ");"; //Send query to data retrieval class. RetrieveData rD = new RetrieveData(query); if (rD.updateData()) { //If update is successful, set flag. flag = true; } if (flag) { MessageBox.Show("New Task created."); } } catch { MessageBox.Show("Database may have disconnected, or selected data is not available."); } }
private void projectScreenForm_Load(object sender, EventArgs e) { try { //Calculates the Hours Worked for a given project based off the sum of Hours to Complete for the tasks for //that project. int project = DsUtil.selectedIndex; getQ = new Queries(DsUtil.selectedIndex); RetrieveData update = new RetrieveData(getQ.getHoursWorkedQuery()); bool flag = false; flag = update.updateData(); } catch { MessageBox.Show("Hours computation failed."); } try { //Retrieves the same Project Info as listed on the Main Screen from the database and populates it on the //Project Screen int project = DsUtil.selectedIndex; getQ = new Queries(DsUtil.selectedIndex); pScreenDetailsListView.View = View.Details; RetrieveData rD = new RetrieveData(getQ.getEditProjectQueryOne()); DataTable dataTable = rD.retrieveData(); for (int i = 0; i < dataTable.Rows.Count; i++) { DataRow dataRow = dataTable.Rows[i]; ListViewItem listData = new ListViewItem(dataRow["project_id"].ToString()); listData.SubItems.Add(dataRow["project_name"].ToString()); listData.SubItems.Add(dataRow["client_name"].ToString()); listData.SubItems.Add(dataRow["project_short_description"].ToString()); listData.SubItems.Add(dataRow["project_start_date"].ToString()); pScreenDetailsListView.Items.Add(listData); } } catch { MessageBox.Show("Database may have disconnected, or selected data is not available."); } try { //Retrieves and populates Assigned Employees and Materials fdor a given project. DsUtil utility = new DsUtil(); int project = DsUtil.selectedIndex; getQ = new Queries(DsUtil.selectedIndex); pScreenEmpListView.View = View.Details; RetrieveData rD = new RetrieveData(getQ.getEditProjectQueryTwo()); DataTable dataTable = rD.retrieveData(); for (int i = 0; i < dataTable.Rows.Count; i++) { DataRow dataRow = dataTable.Rows[i]; ListViewItem listData = new ListViewItem(utility.getEmployeeName((int)dataRow["employee_id"])); listData.SubItems.Add(dataRow["hours_worked"].ToString()); listData.SubItems.Add(dataRow["material_name"].ToString()); listData.SubItems.Add(dataRow["material_price"].ToString()); pScreenEmpListView.Items.Add(listData); } } catch { MessageBox.Show("Assigned employees failed to load."); } try { //Retrieves and populates Task and related Employee information for a given project. DsUtil utility = new DsUtil(); int project = DsUtil.selectedIndex; getQ = new Queries(DsUtil.selectedIndex); pScreenTaskListView.View = View.Details; RetrieveData rD2 = new RetrieveData(getQ.getEditProjectQueryThree()); DataTable dataTable2 = rD2.retrieveData(); for (int i = 0; i < dataTable2.Rows.Count; i++) { DataRow dataRow = dataTable2.Rows[i]; ListViewItem listData = new ListViewItem(dataRow["task_description"].ToString()); listData.SubItems.Add(dataRow["task_hours_to_complete"].ToString()); listData.SubItems.Add(utility.getEmployeeName((int)dataRow["employee_id"])); pScreenTaskListView.Items.Add(listData); } } catch { MessageBox.Show("Database may have disconnected, or selected data is not available."); } }