Example #1
0
        public override void Edit()
        {
            if (SelectedItem == null)
            {
                return;
            }
            int index = dataGridViewUserControl1.getSelectedItemIndex();

            try
            {
                GimnasticarForm form = (GimnasticarForm)createEntityDetailForm(SelectedItem.Id);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    if (form.GimnasticarToEdit == null)
                    {
                        Gimnasticar        entity = (Gimnasticar)form.Entity;
                        List <Gimnasticar> items  = dataGridViewUserControl1.getItems <Gimnasticar>();
                        items[index] = entity;
                        dataGridViewUserControl1.setItems <Gimnasticar>(items);  // ovo ponovo sortira items
                        dataGridViewUserControl1.setSelectedItem <Gimnasticar>(entity);
                    }
                    else
                    {
                        List <Gimnasticar> items = dataGridViewUserControl1.getItems <Gimnasticar>();
                        Gimnasticar        g     = form.GimnasticarToEdit;
                        if (items.IndexOf(g) == -1)
                        {
                            items.Add(g);
                            dataGridViewUserControl1.setItems <Gimnasticar>(items);
                            updateEntityCount();
                        }
                        dataGridViewUserControl1.setSelectedItem <Gimnasticar>(g);
                        Edit(g);
                    }
                }
            }
            catch (InfrastructureException ex)
            {
                MessageDialogs.showError(ex.Message, this.Text);
            }
        }
Example #2
0
 protected override void AddNew()
 {
     try
     {
         GimnasticarForm form = (GimnasticarForm)createEntityDetailForm(null);
         if (form.ShowDialog() == DialogResult.OK)
         {
             if (form.GimnasticarToEdit == null)
             {
                 Gimnasticar        newEntity = (Gimnasticar)form.Entity;
                 List <Gimnasticar> items     = dataGridViewUserControl1.getItems <Gimnasticar>();
                 items.Add(newEntity);
                 dataGridViewUserControl1.setItems <Gimnasticar>(items);
                 dataGridViewUserControl1.setSelectedItem <Gimnasticar>(newEntity);
                 updateEntityCount();
             }
             else
             {
                 List <Gimnasticar> items = dataGridViewUserControl1.getItems <Gimnasticar>();
                 Gimnasticar        g     = form.GimnasticarToEdit;
                 if (items.IndexOf(g) == -1)
                 {
                     items.Add(g);
                     dataGridViewUserControl1.setItems <Gimnasticar>(items);
                     updateEntityCount();
                 }
                 dataGridViewUserControl1.setSelectedItem <Gimnasticar>(g);
                 Edit(g);
             }
         }
     }
     catch (InfrastructureException ex)
     {
         MessageDialogs.showError(ex.Message, this.Text);
     }
 }