public void init(Pol pol)
        {
            // Najpre izbaci sve kontrole koje su dodate u prethodnom pozivu funkcije init, osim prve.
            List<Control> controls = new List<Control>();
            foreach (Control c in this.Controls)
            {
                controls.Add(c);
            }
            foreach (Control c in controls)
            {
                SpravaGridUserControl c2 = c as SpravaGridUserControl;
                if (c2 != null && c2 != spravaGridUserControl1)
                    this.Controls.Remove(c2);
            }

            Sprava[] sprave = Sprave.getSprave(pol);

            int width = spravaGridUserControl1.Width;
            int height = spravaGridUserControl1.Height;
            int xOffset = 50;
            int yOffset = 25;

            this.Width = 2 * width + xOffset;
            int brojSprava = sprave.Length;
            this.Height = (brojSprava / 2) * height + (brojSprava / 2 - 1) * yOffset;

            int tabIndex = spravaGridUserControl1.TabIndex;
            for (int i = 0; i < brojSprava; i++)
            {
                Sprava sprava = sprave[i];
                if (i == 0)
                {
                    // Za svaki slucaj najpre uklanjam event handlere (za slucaj da je metod init vec pozivan),
                    // mada predpostavljam da cak i da se operacija += pozove dvaput uzastopce sa istim handlerom
                    // da ce samo jedan handler biti dodat.
                    spravaGridUserControl1.SpravaGridMouseDown -= new EventHandler<SpravaGridMouseDownEventArgs>(spravaGrid_MouseDown);
                    spravaGridUserControl1.SpravaGridMouseUp -= new EventHandler<SpravaGridMouseUpEventArgs>(spravaGrid_MouseUp);

                    spravaGridUserControl1.SpravaGridMouseDown += new EventHandler<SpravaGridMouseDownEventArgs>(spravaGrid_MouseDown);
                    spravaGridUserControl1.SpravaGridMouseUp += new EventHandler<SpravaGridMouseUpEventArgs>(spravaGrid_MouseUp);
                    spravaGridUserControl1.init(sprava);
                    continue;
                }

                int row = i / 2;
                int col = i % 2;
                SpravaGridUserControl userControl = new SpravaGridUserControl();
                userControl.Location =
                    new Point(col * (width + xOffset), row * (height + yOffset));
                userControl.Size = new Size(width, height);
                userControl.TabIndex = tabIndex + i;
                userControl.SpravaGridMouseDown += new EventHandler<SpravaGridMouseDownEventArgs>(spravaGrid_MouseDown);
                userControl.SpravaGridMouseUp += new EventHandler<SpravaGridMouseUpEventArgs>(spravaGrid_MouseUp);
                userControl.init(sprava);
                this.Controls.Add(userControl);
            }
        }
Exemple #2
0
        private void unesiOcenu(SpravaGridUserControl c, bool openedWithEnter)
        {
            DataGridViewSelectedRowCollection selRows = c.DataGridViewUserControl.DataGridView.SelectedRows;
            if (selRows.Count != 1)
                return;

            NastupNaSpravi nastup = selRows[0].DataBoundItem as NastupNaSpravi;
            Ocena ocena = null;
            GimnasticarUcesnik g = null;
            bool ok = false;
            try
            {
                DataAccessProviderFactory factory = new DataAccessProviderFactory();
                dataContext = factory.GetDataContext();
                dataContext.BeginTransaction();

                g = nastup.Gimnasticar;
                ocena = findOcena(g, deoTakKod, c.Sprava);

                ok = true;
            }
            catch (Exception ex)
            {
                if (dataContext != null && dataContext.IsInTransaction)
                    dataContext.Rollback();
                MessageDialogs.showMessage(
                    Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text);
            }
            finally
            {
                if (dataContext != null)
                    dataContext.Dispose();
                dataContext = null;
            }

            if (!ok)
            {
                Close();
                return;
            }

            Nullable<int> ocenaId = null;
            if (ocena != null)
                ocenaId = ocena.Id;
            OcenaForm f = new OcenaForm(ocenaId, g, c.Sprava, deoTakKod,
                takmicenje.Id);
            if (f.ShowDialog() == DialogResult.OK)
            {
                int index = c.DataGridViewUserControl.getSelectedItemIndex();
                if (openedWithEnter)
                {
                    // Enter ce automatski selektovati novu vrstu. Potrebno je samo proveriti da li je ovo poslednja vrsta.
                    if (index == c.DataGridViewUserControl.DataGridView.Rows.Count - 1)
                    {
                        // uneta je zadnja ocena
                        c.clearSelection();
                    }
                }
                else
                {
                    ++index;
                    if (index < c.DataGridViewUserControl.DataGridView.Rows.Count)
                    {
                        // selektuj sledecu ocenu
                        c.DataGridViewUserControl.setSelectedItemIndex(index);
                    }
                    else
                    {
                        // uneta je zadnja ocena
                        c.clearSelection();
                    }
                }
            }
        }
        public void init(Sprava[] sprave)
        {
            // Najpre izbaci sve kontrole koje su dodate u prethodnom pozivu funkcije init, osim prve.
            List <Control> controls = new List <Control>();

            foreach (Control c in this.Controls)
            {
                controls.Add(c);
            }
            foreach (Control c in controls)
            {
                SpravaGridUserControl c2 = c as SpravaGridUserControl;
                if (c2 != null && c2 != spravaGridUserControl1)
                {
                    this.Controls.Remove(c2);
                }
            }

            int width   = spravaGridUserControl1.Width;
            int height  = spravaGridUserControl1.Height;
            int xOffset = 50;
            int yOffset = 25;

            // xOffset i yOffset je razmak izmedju sprava. razmak pre prve sprave i posle poslednje sprave je nula.
            this.Width = 2 * width + xOffset;
            int brojSprava = sprave.Length;

            this.Height = ((brojSprava + 1) / 2) * height + ((brojSprava + 1) / 2 - 1) * yOffset;

            int tabIndex = spravaGridUserControl1.TabIndex;

            for (int i = 0; i < brojSprava; i++)
            {
                Sprava sprava = sprave[i];
                if (i == 0)
                {
                    // Za svaki slucaj najpre uklanjam event handlere (za slucaj da je metod init vec pozivan),
                    // mada predpostavljam da cak i da se operacija += pozove dvaput uzastopce sa istim handlerom
                    // da ce samo jedan handler biti dodat.
                    spravaGridUserControl1.SpravaGridMouseDown -= new EventHandler <SpravaGridMouseDownEventArgs>(spravaGrid_MouseDown);
                    spravaGridUserControl1.SpravaGridMouseUp   -= new EventHandler <SpravaGridMouseUpEventArgs>(spravaGrid_MouseUp);

                    spravaGridUserControl1.SpravaGridMouseDown += new EventHandler <SpravaGridMouseDownEventArgs>(spravaGrid_MouseDown);
                    spravaGridUserControl1.SpravaGridMouseUp   += new EventHandler <SpravaGridMouseUpEventArgs>(spravaGrid_MouseUp);
                    spravaGridUserControl1.init(sprava);
                    continue;
                }

                int row = i / 2;
                int col = i % 2;
                SpravaGridUserControl userControl = new SpravaGridUserControl();
                userControl.Location =
                    new Point(col * (width + xOffset), row * (height + yOffset));
                userControl.Size                 = new Size(width, height);
                userControl.TabIndex             = tabIndex + i;
                userControl.SpravaGridMouseDown += new EventHandler <SpravaGridMouseDownEventArgs>(spravaGrid_MouseDown);
                userControl.SpravaGridMouseUp   += new EventHandler <SpravaGridMouseUpEventArgs>(spravaGrid_MouseUp);
                userControl.init(sprava);
                this.Controls.Add(userControl);
            }
        }