Ejemplo n.º 1
0
        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.");
            }
        }
Ejemplo n.º 2
0
        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.");
            }
        }