private bool IsProfessionCanBeDeleted()
        {
            ITSkillsDataContext dataContext     = new ITSkillsDataContext();
            string professionName               = professionsListBox.SelectedItem.ToString();
            int    professionID                 = dataContext.Professions.SingleOrDefault(p => p.Profession == professionName).Id;
            var    employeesWithThisProfessions = from e in dataContext.Employees
                                                  where e.ProfessionID == professionID
                                                  select e;

            if (employeesWithThisProfessions.Count() == 0)
            {
                return(true);
            }
            else
            {
                MessageBox.Show(
                    "Удаление невозможно, так как имеются сотрудники с данной профессией.",
                    "Ошибка",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly);
                return(false);
            }
        }
 private void addButton_Click(object sender, EventArgs e)
 {
     this.ValidateChildren();
     if (FormValidator.IsValidated(this, errorProvider1))
     {
         var       dataContext = new ITSkillsDataContext();
         Employees employee    = new Employees();
         employee.Name     = nameTextBox.Text;
         employee.LastName = lastNameTextBox.Text;
         if (patronymicTextBox.Text == "")
         {
             employee.Patronymic = null;
         }
         else
         {
             employee.Patronymic = patronymicTextBox.Text;
         }
         employee.DateOfBirth = birthDateTimePicker.Value;
         string newProfession = professionComboBox.SelectedItem.ToString();
         employee.ProfessionID = dataContext.Professions.SingleOrDefault(p => p.Profession == newProfession).Id;
         dataContext.Employees.InsertOnSubmit(employee);
         dataContext.SubmitChanges();
         this.Close();
     }
 }
Beispiel #3
0
        internal int getProfessionsCount()
        {
            var dataContext = new ITSkillsDataContext();
            var professions = from p in dataContext.Professions
                              select p;

            return(professions.Count());
        }
        private void DeleteProfession()
        {
            ITSkillsDataContext dataContext = new ITSkillsDataContext();
            string professionName           = professionsListBox.SelectedItem.ToString();
            var    profession = dataContext.Professions.SingleOrDefault(p => p.Profession == professionName);

            dataContext.Professions.DeleteOnSubmit(profession);
            dataContext.SubmitChanges();
            InitProfessionsList();
        }
Beispiel #5
0
        private void DeleteEmloyee()
        {
            int employeeID  = Convert.ToInt32(EmployeesGrid.Rows[EmployeesGrid.CurrentCell.RowIndex].Cells[3].Value);
            var dataContext = new ITSkillsDataContext();
            var employee    = dataContext.Employees.SingleOrDefault(e => e.Id == employeeID);

            dataContext.Employees.DeleteOnSubmit(employee);
            dataContext.SubmitChanges();
            FillEmployeeGrid();
        }
Beispiel #6
0
        private void removeEmployeeSkillsFromDB()
        {
            var dataContext    = new ITSkillsDataContext();
            var employeeSkills = from es in dataContext.EmployeesSkills
                                 where es.EmployeeID == this.employeeID
                                 select es;

            dataContext.EmployeesSkills.DeleteAllOnSubmit(employeeSkills);
            dataContext.SubmitChanges();
        }
Beispiel #7
0
        private void InitProfessionsList()
        {
            professionsListBox.Items.Clear();
            var dataContext = new ITSkillsDataContext();
            var professions = from p in dataContext.Professions
                              select p.Profession.ToString();

            foreach (string profession in professions)
            {
                professionsListBox.Items.Add(profession);
            }
        }
Beispiel #8
0
        private void FillProfessionComboBoxValues()
        {
            var dataContext = new ITSkillsDataContext();
            var professions = from p in dataContext.Professions
                              select p.Profession.ToString();

            foreach (string profession in professions)
            {
                professionComboBox.Items.Add(profession);
            }
            ;
        }
Beispiel #9
0
        private void FillEmployeeSkillsList()
        {
            var dataContext = new ITSkillsDataContext();
            var skills      = from s in dataContext.Skills
                              join es in dataContext.EmployeesSkills on s.Id equals es.SkillID
                              where es.EmployeeID == this.employeeID
                              select s.Skill;

            employeeSkillsListBox.Items.Clear();
            foreach (string skill in skills)
            {
                employeeSkillsListBox.Items.Add(skill);
            }
        }
Beispiel #10
0
        private void DeleteSkill()
        {
            ITSkillsDataContext dataContext = new ITSkillsDataContext();
            string profession   = professionsListBox.SelectedItem.ToString();
            int    professionID = dataContext.Professions.SingleOrDefault(p => p.Profession == profession).Id;

            if (skillsListBox.SelectedItems.Count == 1)
            {
                string skillName = skillsListBox.SelectedItem.ToString();
                var    skill     = dataContext.Skills.SingleOrDefault(s => s.Skill == skillName && s.ProfessionID == professionID);
                dataContext.Skills.DeleteOnSubmit(skill);
                dataContext.SubmitChanges();
            }
            ShowSkills();
        }
Beispiel #11
0
        private void ShowSkills()
        {
            skillsListBox.Items.Clear();
            var    dataContext  = new ITSkillsDataContext();
            string profession   = professionsListBox.SelectedItem.ToString();
            int    professionID = dataContext.Professions.SingleOrDefault(p => p.Profession == profession).Id;
            var    skills       = from s in dataContext.Skills
                                  where s.ProfessionID == professionID
                                  select s.Skill.ToString();

            foreach (string skill in skills)
            {
                skillsListBox.Items.Add(skill);
            }
        }
Beispiel #12
0
        private void FillEmployeeGrid()
        {
            var dataContext = new ITSkillsDataContext();
            var employee    = from e in dataContext.Employees
                              join p in dataContext.Professions on e.ProfessionID equals p.Id
                              select new { FullName    = String.Format(@"{0} {1} {2}", e.Name, e.LastName, e.Patronymic),
                                           DateOfBirth = e.DateOfBirth,
                                           Profession  = p.Profession,
                                           Id          = e.Id };

            EmployeesGrid.DataSource            = employee;
            EmployeesGrid.Columns[0].HeaderText = "ФИО";
            EmployeesGrid.Columns[1].HeaderText = "Дата рождения";
            EmployeesGrid.Columns[2].HeaderText = "Профессия";
            EmployeesGrid.Columns[3].Visible    = false;
        }
Beispiel #13
0
        internal static void AddProfession()
        {
            string newProfessionName = InputDialog.Show("Введите название профессии", "Создание профессии");

            if (!String.IsNullOrWhiteSpace(newProfessionName))
            {
                ITSkillsDataContext dataContext = new ITSkillsDataContext();
                var alreadyInDB = from p in dataContext.Professions
                                  where p.Profession == newProfessionName
                                  select p;
                if (alreadyInDB.Count() == 0)
                {
                    Professions newProfession = new Professions();
                    newProfession.Profession = newProfessionName;
                    dataContext.Professions.InsertOnSubmit(newProfession);
                    dataContext.SubmitChanges();
                }
            }
        }
Beispiel #14
0
        private void FillInformation()
        {
            var dataContext = new ITSkillsDataContext();
            var employees   = from e in dataContext.Employees
                              join p in dataContext.Professions on e.ProfessionID equals p.Id
                              where e.Id == this.employeeID
                              select new
            {
                Name       = e.Name.ToString(),
                LastName   = e.LastName.ToString(),
                Patronymic = e.Patronymic.ToString(),
                BirthDate  = e.DateOfBirth,
                Profession = p.Profession.ToString()
            };
            var employee = employees.First();

            nameTextBox.Text                = employee.Name;
            lastNameTextBox.Text            = employee.LastName;
            patronymicTextBox.Text          = employee.Patronymic;
            birthDateTimePicker.Value       = employee.BirthDate;
            professionComboBox.SelectedItem = employee.Profession;
        }
Beispiel #15
0
        private void AddSkill()
        {
            string newSkillName = InputDialog.Show("Введите название навыка", "Создание навыка");

            if (!String.IsNullOrWhiteSpace(newSkillName))
            {
                ITSkillsDataContext dataContext = new ITSkillsDataContext();
                string profession   = professionsListBox.SelectedItem.ToString();
                int    professionID = dataContext.Professions.SingleOrDefault(p => p.Profession == profession).Id;
                var    alreadyInDB  = from s in dataContext.Skills
                                      where s.Skill == newSkillName
                                      select s;
                if (alreadyInDB.Count() == 0)
                {
                    Skills newSkill = new Skills();
                    newSkill.Skill        = newSkillName;
                    newSkill.ProfessionID = professionID;
                    dataContext.Skills.InsertOnSubmit(newSkill);
                    dataContext.SubmitChanges();
                }
            }
            ShowSkills();
        }
Beispiel #16
0
        private void FillProfessionSkillsList()
        {
            var dataContext = new ITSkillsDataContext();

            /*var allSkills = from s in dataContext.Skills
             *              join e in dataContext.Employees on s.ProfessionID equals e.ProfessionID
             *              where e.Id == this.employeeID
             *              select s.Skill;*/
            string profession   = professionComboBox.SelectedItem.ToString();
            int    professionID = dataContext.Professions.SingleOrDefault(p => p.Profession == profession).Id;
            var    allSkills    = from s in dataContext.Skills
                                  where s.ProfessionID == professionID
                                  select s.Skill;
            var employeeSkills = from s in dataContext.Skills
                                 join es in dataContext.EmployeesSkills on s.Id equals es.SkillID
                                 where es.EmployeeID == this.employeeID
                                 select s.Skill;

            professionSkillsListBox.Items.Clear();
            foreach (string skill in allSkills.Except <string>(employeeSkills))
            {
                professionSkillsListBox.Items.Add(skill);
            }
        }
Beispiel #17
0
        private void saveToDB()
        {
            var dataContext = new ITSkillsDataContext();
            var employee    = dataContext.Employees.SingleOrDefault(e => e.Id == this.employeeID);

            employee.Name     = nameTextBox.Text;
            employee.LastName = lastNameTextBox.Text;
            if (patronymicTextBox.Text == "")
            {
                employee.Patronymic = null;
            }
            else
            {
                employee.Patronymic = patronymicTextBox.Text;
            }
            employee.DateOfBirth = birthDateTimePicker.Value;
            string newProfession = professionComboBox.SelectedItem.ToString();

            employee.ProfessionID = dataContext.Professions.SingleOrDefault(p => p.Profession == newProfession).Id;
            removeEmployeeSkillsFromDB();
            foreach (string skill in employeeSkillsListBox.Items)
            {
                EmployeesSkills employeeSkill = new EmployeesSkills();
                employeeSkill.EmployeeID = this.employeeID;
                employeeSkill.SkillID    = dataContext.Skills.SingleOrDefault(s => s.Skill == skill).Id;
                var alreadyInDB = from es in dataContext.EmployeesSkills
                                  where es.EmployeeID == employeeSkill.EmployeeID
                                  where es.SkillID == employeeSkill.SkillID
                                  select es;
                if (alreadyInDB.Count() == 0)
                {
                    dataContext.EmployeesSkills.InsertOnSubmit(employeeSkill);
                }
            }
            dataContext.SubmitChanges();
        }