Exemplo n.º 1
0
        Skill[] SkillsForEmployee()
        {
            string[] skill      = this.addBoxSkill.Text.Split(',');
            Skill[]  skills     = new Skill[skill.Length];
            int      skillCount = 0;

            for (int i = 0; i < skill.Length; i++)
            {
                skills[i] = SearchLinqToSql.GetSkill(skill[i]);
                if (skills[i] != null)
                {
                    skillCount++;
                }
                else
                {
                    string       message = $"Skill \"{skill[i]}\" is absend in skill list. Do you whant to add new skill?";
                    string       caption = "Word Processor";
                    DialogResult result  = MessageBox.Show(message, caption, MessageBoxButtons.OKCancel);
                    if (result == DialogResult.OK)
                    {
                        Post post = SearchLinqToSql.GetPost(this.comboBoxAdd.SelectedItem.ToString());
                        AddLinqToSql.AddSkill(skill[i], post.Id);
                        MessageBox.Show("Skill added successfull.");
                    }
                    else
                    {
                        throw new ArgumentException();
                    }
                    skills[i] = SearchLinqToSql.GetSkill(skill[i]);
                    skillCount++;
                }
            }

            return(skills);
        }
Exemplo n.º 2
0
 public static bool DeleteEmployee(string name)
 {
     try
     {
         Employee employee = SearchLinqToSql.Search(name);
         if (employee != null)
         {
             ConnectionDB.DeleteEmployee(employee);
         }
         else
         {
             throw new ArgumentException();
         }
     } catch
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 3
0
        private void searchButton_Click(object sender, EventArgs e)
        {
            this.outputBox.Text = "";
            string   name     = this.searchBox.Text;
            Employee employee = SearchLinqToSql.Search(name);
            string   output   = "";

            if (employee == null)
            {
                output += "No match found.";
            }
            else
            {
                output += $"Name:\t{employee.Name}";
                output += Environment.NewLine + $"Age:\t{employee.Age}";
                output += Environment.NewLine + $"Post:\t{employee.post.Name}";
                output += Environment.NewLine + Environment.NewLine + $"Skills:";
                for (int i = 0; i < employee.skill.Length; i++)
                {
                    output += $"\t{employee.skill[i].Name}" + Environment.NewLine;
                }
            }
            this.outputBox.Text = output;
        }
Exemplo n.º 4
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (this.addBoxName.Text == "" || this.addBoxAge.Text == "" || this.comboBoxAdd.SelectedItem == null || this.addBoxSkill.Text == "")
            {
                MessageBox.Show("Please, fill all fields.");
                return;
            }

            //reading name
            string name = this.addBoxName.Text;

            //reading and analyzing Age
            int age = 0;

            try
            {
                age = int.Parse(this.addBoxAge.Text);
            } catch (FormatException ex)
            {
                MessageBox.Show($"Error: Age: {ex.Message}");
                this.addBoxAge.Text = "";
                return;
            }

            //reading and analyzing Post
            string p    = this.comboBoxAdd.SelectedItem.ToString();
            Post   post = SearchLinqToSql.GetPost(p);

            //reading and analyzing Skills
            Skill[] skills = null;
            try
            {
                skills = SkillsForEmployee();
            } catch (ArgumentException)
            {
                this.addBoxSkill.Text = "";
                return;
            }

            Employee employee = new Employee();

            employee.Name   = name;
            employee.Age    = age;
            employee.post   = post;
            employee.PostId = post.Id;
            employee.skill  = skills;

            bool status = AddLinqToSql.AddEmployee(employee);

            if (status)
            {
                MessageBox.Show($"{employee.Name} add successfull.");
            }
            else
            {
                MessageBox.Show("Something goes wrong");
            }
            this.addBoxName.Text          = "";
            this.addBoxAge.Text           = "";
            this.comboBoxAdd.SelectedItem = null;
            this.addBoxSkill.Text         = "";
        }