Ejemplo n.º 1
0
        public void addEmployee(Employee add, String password)
        {
            string checkIfExsites = "Select * FROM users WHERE person_id = '"+ add.getIdNumber() +"' ;";
            MySqlCommand cmdCheck = new MySqlCommand(checkIfExsites, this.connection);
            MySqlDataReader dataReader = cmdCheck.ExecuteReader();
            int count = 0;

            while (dataReader.Read()) {
                count++;
            }
            dataReader.Close();

            if (count > 0) {
                System.Windows.Forms.MessageBox.Show("ID allready in use");
                return;
            }

            if (add is Manager)
            {

                string query = "INSERT INTO administration (F_Name, L_Name, Job_Description, Premission, Sal_Hour, phone_number, password, person_id, address, email) VALUES('" + add.getNameFirst() + "', '" + add.getNameLast() + "', 'manager', '" + add.getPermissionLevel() + "', '" + add.getSallaryPerHour() + "', '" + add.getPhoneNumber() + "', md5('" + password + "'), '" + add.getIdNumber() + "', '" + add.getHomeAddress() + "', '" + add.getEmailAddress() + "');";
                MySqlCommand cmd = new MySqlCommand(query, this.connection);

                cmd.ExecuteNonQuery();

                long customerDbId = cmd.LastInsertedId;

                string query2 = "INSERT INTO users (person_id, password, type) VALUES('" + add.getIdNumber() + "', md5('" + password + "'), 'manager');";
                MySqlCommand cmd2 = new MySqlCommand(query2, this.connection);
                cmd2.ExecuteNonQuery();

                System.Windows.Forms.MessageBox.Show("Manager was added");

            }
            else if (add is Receptionist)
            {
                string query = "INSERT INTO reception (F_Name, L_Name, Job_Description, Premission, Sal_Hour, phone_number, password, person_id, address, email) VALUES('" + add.getNameFirst() + "', '" + add.getNameLast() + "', 'Receptionist', '" + add.getPermissionLevel() + "', '" + add.getSallaryPerHour() + "', '" + add.getPhoneNumber() + "', md5('" + password + "'), '" + add.getIdNumber() + "', '" + add.getHomeAddress() + "', '" + add.getEmailAddress() + "');";
                MySqlCommand cmd = new MySqlCommand(query, this.connection);

                cmd.ExecuteNonQuery();

                long customerDbId = cmd.LastInsertedId;

                string query2 = "INSERT INTO users (person_id, password, type) VALUES('" + add.getIdNumber() + "', md5('" + password + "'), 'reception');";
                MySqlCommand cmd2 = new MySqlCommand(query2, this.connection);
                cmd2.ExecuteNonQuery();

                System.Windows.Forms.MessageBox.Show("Reciption was added");
            }
            else if (add is Trainer)
            {
                string query = "INSERT INTO trainers (F_Name, L_Name, Job_Description, Premission, Sal_Hour, phone_number, password, person_id, address, email, certificate) VALUES('" + add.getNameFirst() + "', '" + add.getNameLast() + "', 'trainer', '" + add.getPermissionLevel() + "', '" + add.getSallaryPerHour() + "', '" + add.getPhoneNumber() + "', md5('" + password + "'), '" + add.getIdNumber() + "', '" + add.getHomeAddress() + "', '" + add.getEmailAddress() + "', '" + ((Trainer)add).getTrainerCartificate() + "');";
                MySqlCommand cmd = new MySqlCommand(query, this.connection);

                cmd.ExecuteNonQuery();

                long customerDbId = cmd.LastInsertedId;

                string query2 = "INSERT INTO users (person_id, password, type) VALUES('" + add.getIdNumber() + "', md5('" + password + "'), 'trainer');";
                MySqlCommand cmd2 = new MySqlCommand(query2, this.connection);
                cmd2.ExecuteNonQuery();

                System.Windows.Forms.MessageBox.Show("Trainer was added");
            }
            else if (add is Instructor)
            {
                string query = "INSERT INTO instructor (F_Name, L_Name, Job_Description, Premission, Sal_Hour, phone_number, password, person_id, address, email) VALUES('" + add.getNameFirst() + "', '" + add.getNameLast() + "', 'instructor', '" + add.getPermissionLevel() + "', '" + add.getSallaryPerHour() + "', '" + add.getPhoneNumber() + "', md5('" + password + "'), '" + add.getIdNumber() + "', '" + add.getHomeAddress() + "', '" + add.getEmailAddress() + "');";
                MySqlCommand cmd = new MySqlCommand(query, this.connection);

                cmd.ExecuteNonQuery();

                long customerDbId = cmd.LastInsertedId;

                string query2 = "INSERT INTO users (person_id, password, type) VALUES('" + add.getIdNumber() + "', md5('" + password + "'), 'instructor');";
                MySqlCommand cmd2 = new MySqlCommand(query2, this.connection);
                cmd2.ExecuteNonQuery();

                System.Windows.Forms.MessageBox.Show("Instructor was added");
            }


        }
        private void buttonAddFind_Click(object sender, EventArgs e)
        {
            // Validate ID Input
            if (!validateID()) { return; }

            if (this.requetsType == "Add")
            {// Current Form Request is Add
                if (validateData())
                {// Detiles are OK
                    current.AddEmployee(comboBoxEmloyeeType.Text, textBoxNameFirst.Text, textBoxNameLast.Text, textBoxAddress.Text, textBoxPhoneNumber.Text, textBoxEmail.Text, Convert.ToInt32(textBoxID.Text),
                    float.Parse(textBoxSallary.Text), textBoxCertificate.Text, textBoxPassword.Text);
                    refresher();
                }
                return;
            }
            // Current Form Request is Edit / Delete (Button Text is Find)
            employeeObject = dbConnector.Instance.getEmployeeById(Convert.ToInt64(textBoxID.Text));
            if (employeeObject == null)
            { // Employee Not Found
                MessageBox.Show("There is no Employee with this id");
                return;
            }

            // Employee Found
            panelData.Visible = true;

            // Fill Data
            comboBoxEmloyeeType.Text = employeeObject.GetType().Name;
            textBoxNameFirst.Text = employeeObject.getNameFirst();
            textBoxNameLast.Text = employeeObject.getNameLast();
            textBoxPhoneNumber.Text = employeeObject.getPhoneNumber();
            textBoxEmail.Text = employeeObject.getEmailAddress();
            textBoxAddress.Text = employeeObject.getHomeAddress();
            textBoxSallary.Text = employeeObject.getSallaryPerHour().ToString();
            // Check if Employee is a Trainer
            if (employeeObject.getPermissionLevel() == PermissiomLevels.TRIANER)
            {
                textBoxCertificate.Text = ((Trainer)employeeObject).getTrainerCartificate();
            }
            buttonSave.Enabled = true;
        }
Ejemplo n.º 3
0
         public String EditEmployee(Employee add)
        {
             int returnRows = 0;

            if (add is Manager)
            {
                string query = "UPDATE administration SET F_Name='" + add.getNameFirst() + "', L_Name='" + add.getNameLast() + "', Job_Description='manager', Premission='" + add.getPermissionLevel() + "', Sal_Hour='" + add.getSallaryPerHour() + "', phone_number='" + add.getPhoneNumber() + "', person_id='" + add.getIdNumber() + "', address='" + add.getHomeAddress() + "', email='" + add.getEmailAddress() + "' WHERE idAdministration='"+add.getDBid()+"';";
                MySqlCommand cmd = new MySqlCommand(query, this.connection);

                returnRows = cmd.ExecuteNonQuery();

            }
            else if (add is Receptionist)
            {
                string query = "UPDATE reception SET F_Name='" + add.getNameFirst() + "', L_Name='" + add.getNameLast() + "', Job_Description='reception', Premission='" + add.getPermissionLevel() + "', Sal_Hour='" + add.getSallaryPerHour() + "', phone_number='" + add.getPhoneNumber() + "', person_id='" + add.getIdNumber() + "', address='" + add.getHomeAddress() + "', email='" + add.getEmailAddress() + "' WHERE idReception='" + add.getDBid() + "';";
                MySqlCommand cmd = new MySqlCommand(query, this.connection);

                returnRows =  cmd.ExecuteNonQuery();

            }
            else if (add is Trainer)
            {
                string query = "UPDATE trainers SET F_Name='" + add.getNameFirst() + "', L_Name='" + add.getNameLast() + "', Job_Description='trainer', Premission='" + add.getPermissionLevel() + "', Sal_Hour='" + add.getSallaryPerHour() + "', phone_number='" + add.getPhoneNumber() + "', person_id='" + add.getIdNumber() + "', address='" + add.getHomeAddress() + "', certificate=" + ((Trainer)add).getTrainerCartificate() + ",email='" + add.getEmailAddress() + "' WHERE idtrainer='" + add.getDBid() + "';";
                MySqlCommand cmd = new MySqlCommand(query, this.connection);

                returnRows =  cmd.ExecuteNonQuery();
            }
            else if (add is Instructor)
            {
                string query = "UPDATE instructor SET F_Name='" + add.getNameFirst() + "', L_Name='" + add.getNameLast() + "', Job_Description='instructor', Premission='" + add.getPermissionLevel() + "', Sal_Hour='" + add.getSallaryPerHour() + "', phone_number='" + add.getPhoneNumber() + "', person_id='" + add.getIdNumber() + "', address='" + add.getHomeAddress() + "', email='" + add.getEmailAddress() + "' WHERE idInstructor='" + add.getDBid() + "';";
                MySqlCommand cmd = new MySqlCommand(query, this.connection);

                returnRows =  cmd.ExecuteNonQuery();
               
            }

            if (returnRows <= 0)
            {
                return "No Employee Was Edited";
            }
            else {
                return add.getNameFirst() + " " + add.getNameLast() + " was Edited";
            }
        }