Пример #1
0
        private void buttonReset_Click(object sender, EventArgs e)
        {
            int selected = getSelectedIdx(dataGridViewEmp, "idEmployee");

            toUpdateEmployee = data.Employees.SingleOrDefault(x => x.idEmployee == selected);
            toUpdateUser     = data.Users.SingleOrDefault(x => x.idUser == toUpdateEmployee.idUser);

            toUpdateUser.password = PasswordHash.getHash("Password1234");

            labelReset.Text = "Password changed";

            try { data.SubmitChanges(); } catch (Exception ex) { Console.WriteLine(ex); }
        }
Пример #2
0
        //////////////////////////////////
        //////////////////////////////////                  ADDING EMPLOYEES
        //////////////////////////////////

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            if (textBoxName.Text != "Name" && textBoxSurname.Text != "Surname" && textBoxLogin.Text != "Login")
            {
                //ComboBoxJobContract
                string comboContractVal = ((KeyValuePair <string, string>)comboBoxContract.SelectedItem).Value;
                //ComboBoxFrenchLevel
                string comboFrenchVal = ((KeyValuePair <string, string>)comboBoxFrenchLvl.SelectedItem).Value;
                //ComboBoxPermission
                string comboPermVal = ((KeyValuePair <string, string>)comboBoxPermission.SelectedItem).Value;
                //ComboBoxPermission
                string comboTeamVal = ((KeyValuePair <string, string>)comboBoxTeam.SelectedItem).Value;
                //ComboBoxFTE
                string comboFTE = ((KeyValuePair <string, string>)comboBoxFTE.SelectedItem).Value;

                ////////////////////////////////////////// USER
                User user = new User();
                user.login      = textBoxLogin.Text;
                user.password   = PasswordHash.getHash("Password1234");
                user.permission = comboPermVal;

                data.Users.InsertOnSubmit(user);
                try { data.SubmitChanges(); } catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); }

                ///////////////////////////////////////// EMPLOYEE
                Employee employee = new Employee();
                employee.name        = textBoxName.Text;
                employee.surname     = textBoxSurname.Text;
                employee.jobContract = comboContractVal;
                employee.frenchlvl   = comboFrenchVal;
                //idTeam
                if (comboTeamVal == "Channels")
                {
                    employee.idTeam = 2;
                }
                else
                {
                    employee.idTeam = 1;
                }
                //idUser
                var newUserId = (from users in data.Users
                                 orderby users.idUser descending
                                 select users.idUser).First();
                employee.idUser = newUserId;
                //independent
                if (checkBoxIndependent.Checked)
                {
                    employee.independent = true;
                }
                else
                {
                    employee.independent = false;
                }

                data.Employees.InsertOnSubmit(employee);
                try { data.SubmitChanges(); } catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); }

                /////////////////////////////////     FTE

                FTE newFte = new FTE();

                ///// idEmployee
                var FTEEmp = (from emp in data.Employees
                              orderby emp.idEmployee descending
                              select emp.idEmployee).First();
                newFte.idEmployee = FTEEmp;

                /////// dimension
                if (comboFTE == "1")
                {
                    newFte.dimension = 1;
                }
                else if (comboFTE == "0.8")
                {
                    newFte.dimension = 0.8;
                }
                else if (comboFTE == "0.6")
                {
                    newFte.dimension = 0.6;
                }
                data.FTEs.InsertOnSubmit(newFte);
                try { data.SubmitChanges(); } catch (System.Data.SqlClient.SqlException ex) { Console.WriteLine(ex); }

                loadEmployees();
            }
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            toUpdateUser     = data.Users.SingleOrDefault(x => x.idUser == this.loggedUser.idUser);
            toUpdateEmployee = data.Employees.SingleOrDefault(x => x.idUser == this.loggedUser.idUser);
            toUpdateFTE      = data.FTEs.SingleOrDefault(x => x.idEmployee == toUpdateEmployee.idEmployee);

            if (textBoxName.Text != toUpdateEmployee.name && textBoxName.Text != "")
            {
                toUpdateEmployee.name = textBoxName.Text;
            }
            if (textBoxSurname.Text != toUpdateEmployee.surname && textBoxSurname.Text != "")
            {
                toUpdateEmployee.surname = textBoxSurname.Text;
            }

            //ComboBoxJobContract
            string comboContractVal = ((KeyValuePair <string, string>)comboBoxContract.SelectedItem).Value;
            //ComboBoxFrenchLevel
            string comboFrenchVal = ((KeyValuePair <string, string>)comboBoxFrenchLvl.SelectedItem).Value;

            //ComboBoxPermission
            string comboTeamVal = ((KeyValuePair <string, string>)comboBoxTeam.SelectedItem).Value;
            //ComboBoxFTE
            string comboFTE = ((KeyValuePair <string, string>)comboBoxFTE.SelectedItem).Value;


            /////////////////////////////////     FTE
            /////// dimension
            if (comboFTE == "1")
            {
                toUpdateFTE.dimension = 1;
            }
            else if (comboFTE == "0.8")
            {
                toUpdateFTE.dimension = 0.8;
            }
            else if (comboFTE == "0.6")
            {
                toUpdateFTE.dimension = 0.6;
            }

            /////////////////////////////// Employee
            toUpdateEmployee.frenchlvl   = comboFrenchVal;
            toUpdateEmployee.jobContract = comboContractVal;
            toUpdateEmployee.jobContract = comboContractVal;
            //idTeam
            if (comboTeamVal == "Channels")
            {
                toUpdateEmployee.idTeam = 1;
            }
            else
            {
                toUpdateEmployee.idTeam = 2;
            }

            try { data.SubmitChanges(); } catch (Exception ex) { Console.WriteLine(ex); }
            labelCheck.Text = "CHANGED !!";

            if (textBoxPassword.Text != "" && textBoxRepassword.Text != "" && textBoxPassword.Text != "Password" && textBoxRepassword.Text != "Re-Password")
            {
                if (textBoxPassword.Text.Equals(textBoxRepassword.Text))
                {
                    toUpdateUser.password = PasswordHash.getHash(textBoxPassword.Text);
                    try { data.SubmitChanges(); } catch (Exception ex) { Console.WriteLine(ex); }
                    labelCheck.Text = "CHANGED !!";
                }
                else
                {
                    labelCheck.Text = "Passwords are different";
                }
            }
        }