Example #1
0
        private void InitAdditional()
        {
            SimpleButton additional = new SimpleButton()
            {
                Text = "Изменение навыков",
                Location = new Point(5, 5),
                AutoSize = true
            };
            additional.Click += (sender, e) =>
            {
                using (AddAdditional adds = new AddAdditional())
                {
                    adds.Initialize(Context.t_post.ToList(), this.detailGridControl1.DataSource as List<t_post>, "t_postName");
                    var res = adds.ShowDialog();
                    if (res == DialogResult.OK)
                    {
                        var col = (adds.listBoxInEntity.DataSource as List<t_post>).Except((Entity as t_skill).t_skillPosts.ToList());
                        if (col.Count() > 0)
                        {
                            foreach (var post in col)
                            {
                                (Entity as t_skill).t_skillPosts.Add(post);
                            }
                        }
                        else
                        {
                            col = (Entity as t_skill).t_skillPosts.ToList().Except((adds.listBoxInEntity.DataSource as List<t_post>));
                            foreach (var post in col)
                            {
                                (Entity as t_skill).t_skillPosts.Remove(post);
                            }

                        }
                        Context.SaveChangesAsync();
                        this.detailGridControl1.DataSource = (Entity as t_skill).t_skillPosts.ToList();
                    }
                }

            };
            this.panelAditionalButtons.Controls.Add(additional);
        }
        private void InitAdditionalFields()
        {
            LabelControl labelSecondName = new LabelControl()
            {
                Text = "Отчество",
                Location = new Point(labelControl1.Location.X, 90)
            };

            this.groupMain.Controls.Add(labelSecondName);

            TextEdit editSecondName = new TextEdit()
            {
                Location = new Point(textEdit1.Location.X, 87),
                Size = textEdit1.Size
            };
            editSecondName.DataBindings.Add(new Binding("EditValue", bindingSource, "t_employeeSecondName", true));
            this.groupMain.Controls.Add(editSecondName);

            LabelControl labelSalary = new LabelControl()
            {
                Text = "Зарплата",
                Location = new Point(labelControl1.Location.X, 115)
            };

            this.groupMain.Controls.Add(labelSalary);

            CalcEdit editSalary = new CalcEdit()
            {
                Location = new Point(textEdit1.Location.X, 112),
                Size = textEdit1.Size
            };
            editSalary.DataBindings.Add(new Binding("EditValue", bindingSource, "t_employeeSalary", true));
            this.groupMain.Controls.Add(editSalary);

            LabelControl labelDepartment = new LabelControl()
            {
                Text = "Департамент",
                Location = new Point(labelControl3.Location.X, 60)
            };

            this.groupMain.Controls.Add(labelDepartment);

            LookUpEdit editDepartment = new LookUpEdit()
            {
                Location = new Point(lookUpEdit.Location.X, 57),
                Size = lookUpEdit.Size
            };
            editDepartment.Properties.Columns.Add(new LookUpColumnInfo("t_departmentName", "Департамент"));
            editDepartment.Properties.DataSource = Context.t_department.ToList();
            editDepartment.DataBindings.Add(new Binding("EditValue", bindingSource, "t_department", true));
            this.groupMain.Controls.Add(editDepartment);

            LabelControl labelHobbies = new LabelControl()
            {
                Text = "Увлечения",
                Location = new Point(labelControl3.Location.X, 90)
            };

            this.groupMain.Controls.Add(labelHobbies);

            TextEdit editHobbies = new TextEdit()
            {
                Location = new Point(lookUpEdit.Location.X, 87),
                Size = lookUpEdit.Size
            };
            editHobbies.DataBindings.Add(new Binding("EditValue", bindingSource, "t_eployeeHobbies", true));
            this.groupMain.Controls.Add(editHobbies);

            SimpleButton additional = new SimpleButton()
            {
                Text = "Изменение навыков",
                Location = new Point(5, 5),
                AutoSize = true
            };
            additional.Click += (sender, e) =>
            {
                using (AddAdditional adds = new AddAdditional())
                {
                    adds.Initialize(Context.t_skill.ToList(), this.detailGridControl1.DataSource as List<t_skill>, "t_skillName");
                    var res = adds.ShowDialog();
                    if (res == DialogResult.OK)
                    {
                        var col = (adds.listBoxInEntity.DataSource as List<t_skill>).Except((Entity as t_employee).t_employeeSkills.ToList());
                        if (col.Count() > 0)
                        {
                            foreach (var skill in col)
                            {
                                (Entity as t_employee).t_employeeSkills.Add(skill);
                            }
                        }
                        else
                        {
                            col = (Entity as t_employee).t_employeeSkills.ToList().Except((adds.listBoxInEntity.DataSource as List<t_skill>));
                            foreach (var skill in col)
                            {
                                (Entity as t_employee).t_employeeSkills.Remove(skill);
                            }

                        }
                        Context.SaveChangesAsync();
                        this.detailGridControl1.DataSource = (Entity as t_employee).t_employeeSkills.ToList();
                    }
                }

            };
            this.panelAditionalButtons.Controls.Add(additional);
        }