コード例 #1
0
ファイル: MainForm.cs プロジェクト: Jekson90/QbixApp
        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);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Jekson90/QbixApp
        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         = "";
        }