private void btnFiltriraj_Click(object sender, EventArgs e) { Nullable <Gimnastika> gimnastika = null; if (cmbGimnastika.SelectedIndex == cmbGimnastika.Items.IndexOf(MSG)) { gimnastika = Gimnastika.MSG; } else if (cmbGimnastika.SelectedIndex == cmbGimnastika.Items.IndexOf(ZSG)) { gimnastika = Gimnastika.ZSG; } string klub = cmbKlub.SelectedItem as string; if (klub == SVI_KLUBOVI) { klub = String.Empty; } GimnasticarBiltenDAO dao = new GimnasticarBiltenDAO(); dao.ConnectionString = Opcije.Instance.BiltenConnectionString; IList <GimnasticarBilten> gimnasticari = dao.findGimnasticariBilten(txtIme.Text.Trim(), txtPrezime.Text.Trim(), gimnastika, klub); dataGridViewUserControl1.setItems <GimnasticarBilten>(gimnasticari); if (gimnasticari.Count == 0) { MessageDialogs.showMessage("Ne postoje gimnasticari koji zadovoljavaju date kriterijume", this.Text); } dataGridViewUserControl1.clearSelection(); }
private void btnOK_Click(object sender, EventArgs e) { if (dataGridViewUserControl1.DataGridView.SelectedRows.Count == 0) { MessageDialogs.showMessage("Selektujte gimnasticare", this.Text); DialogResult = DialogResult.None; return; } SelektovaniGimnasticari.Clear(); foreach (DataGridViewRow row in dataGridViewUserControl1.DataGridView.SelectedRows) { SelektovaniGimnasticari.Add(row.DataBoundItem as GimnasticarBilten); } }
private void btnPrikaziIzvodMKR_Click(object sender, EventArgs e) { string fileName = txtIzvodMKR.Text.Trim(); if (!String.IsNullOrEmpty(fileName)) { string path = Path.Combine(ConfigurationParameters.IzvodiMKRFolder, fileName); if (!File.Exists(path)) { MessageDialogs.showMessage(String.Format("Fajl {0} ne postoji u folderu {1}.", Path.GetFileName(fileName), ConfigurationParameters.IzvodiMKRFolder), this.Text); } else { System.Diagnostics.Process.Start(path); } } }
private void reloadKategorije() { Nullable <Gimnastika> gim = null; if (cmbGimnastika.SelectedIndex == cmbGimnastika.Items.IndexOf(MSG)) { gim = Gimnastika.MSG; } else if (cmbGimnastika.SelectedIndex == cmbGimnastika.Items.IndexOf(ZSG)) { gim = Gimnastika.ZSG; } ISession session = null; try { using (session = NHibernateHelper.Instance.OpenSession()) using (session.BeginTransaction()) { CurrentSessionContext.Bind(session); kategorije = new List <KategorijaGimnasticara>(loadKategorije(gim)); setKategorije(); } } catch (Exception ex) { if (session != null && session.Transaction != null && session.Transaction.IsActive) { session.Transaction.Rollback(); } MessageDialogs.showMessage( Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text); // TODO: Ovde bi nekako trebalo zatvoriti form na kome se nalazi // ova user kontrola } finally { CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory); } }
private bool validateFilter() { Notification notification = new Notification(); int dummyInt; if (txtGodRodj.Text.Trim() != String.Empty && !int.TryParse(txtGodRodj.Text, out dummyInt)) { notification.RegisterMessage( "GodinaRodjenja", "Neispravan format za godinu rodjenja."); } if (!notification.IsValid()) { NotificationMessage msg = notification.FirstMessage; // TODO: this.Text nije inicijalizovan MessageDialogs.showMessage(msg.Message, this.Text); setFocus(msg.FieldName); return(false); } else { return(true); } }
void btnRezultati_Click(object sender, EventArgs e) { if (SelectedItem == null) { return; } if (Opcije.Instance.BiltenConnectionString == null) { MessageDialogs.showMessage("Pronadjite folder za bilten i selektujte fajl 'BiltenPodaci.sdf'.", "Registracija"); OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() != DialogResult.OK) { return; } Opcije.Instance.BiltenConnectionString = String.Format(@"Data Source={0}", ofd.FileName); } KonacanPlasmanDAO kpDAO = new KonacanPlasmanDAO(); kpDAO.ConnectionString = Opcije.Instance.BiltenConnectionString; Cursor.Current = Cursors.WaitCursor; Cursor.Show(); List <KonacanPlasman> plasmani; try { List <KonacanPlasman> viseboj = new List <KonacanPlasman>(); viseboj.AddRange(kpDAO.findVisebojFinaleKupa(SelectedItem.Ime, SelectedItem.Prezime)); viseboj.AddRange(kpDAO.findVisebojZbirViseKola(SelectedItem.Ime, SelectedItem.Prezime)); viseboj.AddRange(kpDAO.findVisebojTak1(SelectedItem.Ime, SelectedItem.Prezime)); viseboj.AddRange(kpDAO.findVisebojTak2(SelectedItem.Ime, SelectedItem.Prezime)); List <KonacanPlasman> sprave = new List <KonacanPlasman>(); // Dodajem najpre finale kupa da bi, ako je postojalo odvojeno takmicenje 3 finale kupa, rezultati prebrisali // ove rezultate (za one gimnasticare koji su ucestvovali u odvojenom finalu kupa). Iz istog razloga najpre // dodajem spraveTak1 pa spraveTak3. sprave.AddRange(kpDAO.findSpraveFinaleKupa(SelectedItem.Ime, SelectedItem.Prezime)); sprave.AddRange(kpDAO.findSpraveTak1(SelectedItem.Ime, SelectedItem.Prezime)); sprave.AddRange(kpDAO.findSpraveTak3(SelectedItem.Ime, SelectedItem.Prezime)); sprave.AddRange(kpDAO.findPreskokTak1(SelectedItem.Ime, SelectedItem.Prezime)); sprave.AddRange(kpDAO.findPreskokTak3(SelectedItem.Ime, SelectedItem.Prezime)); Dictionary <int, KonacanPlasman> plasmaniMap = new Dictionary <int, KonacanPlasman>(); foreach (KonacanPlasman kp in viseboj) { if (plasmaniMap.ContainsKey(kp.RezultatskoTakmicenjeId)) { if (kp.Viseboj != null) { plasmaniMap[kp.RezultatskoTakmicenjeId].Viseboj = kp.Viseboj; } } else { plasmaniMap.Add(kp.RezultatskoTakmicenjeId, kp); } } foreach (KonacanPlasman kp in sprave) { if (plasmaniMap.ContainsKey(kp.RezultatskoTakmicenjeId)) { updatePlasmanSprava(plasmaniMap[kp.RezultatskoTakmicenjeId], kp); } else { plasmaniMap.Add(kp.RezultatskoTakmicenjeId, kp); } } plasmani = new List <KonacanPlasman>(plasmaniMap.Values); } finally { Cursor.Hide(); Cursor.Current = Cursors.Arrow; } if (plasmani.Count == 0) { MessageDialogs.showMessage("Ne postoje rezultati za gimnasticara '" + SelectedItem.ImeSrednjeImePrezimeDatumRodjenja + "'.", "Rezultati"); } else { KonacanPlasmanForm form = new KonacanPlasmanForm(plasmani, SelectedItem.Gimnastika); form.ShowDialog(); } }
void btnUveziIzBiltena_Click(object sender, EventArgs e) { if (Opcije.Instance.BiltenConnectionString == null) { MessageDialogs.showMessage("Pronadjite folder za bilten i selektujte fajl 'BiltenPodaci.sdf'.", "Registracija"); OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() != DialogResult.OK) { return; } Opcije.Instance.BiltenConnectionString = String.Format(@"Data Source={0}", ofd.FileName); } SelectGimnasticarBiltenForm form = new SelectGimnasticarBiltenForm(); if (form.ShowDialog() != DialogResult.OK) { return; } IList <Gimnasticar> noviGimnasticari = new List <Gimnasticar>(); Cursor.Current = Cursors.WaitCursor; Cursor.Show(); bool ok = false; ISession session = null; try { using (session = NHibernateHelper.Instance.OpenSession()) using (session.BeginTransaction()) { CurrentSessionContext.Bind(session); GimnasticarDAO gimDAO = DAOFactoryFactory.DAOFactory.GetGimnasticarDAO(); KlubDAO klubDAO = DAOFactoryFactory.DAOFactory.GetKlubDAO(); KategorijaGimnasticaraDAO katDAO = DAOFactoryFactory.DAOFactory.GetKategorijaGimnasticaraDAO(); IDictionary <Klub, Klub> klubovi = new Dictionary <Klub, Klub>(); foreach (Klub k in klubDAO.FindAll()) { klubovi.Add(k, k); } IDictionary <KategorijaGimnasticara, KategorijaGimnasticara> kategorije = new Dictionary <KategorijaGimnasticara, KategorijaGimnasticara>(); foreach (KategorijaGimnasticara kat in katDAO.FindAll()) { kategorije.Add(kat, kat); } foreach (GimnasticarBilten g in form.SelektovaniGimnasticari) { if (!gimDAO.existsGimnasticarImePrezimeSrednjeImeDatumRodjenja(g.Ime, g.Prezime, g.SrednjeIme, g.DatumRodjenja)) { Gimnasticar gim = createGimnasticar(g, klubDAO, katDAO, klubovi, kategorije); noviGimnasticari.Add(gim); gimDAO.Add(gim); } } session.Transaction.Commit(); ok = true; } } catch (Exception ex) { if (session != null && session.Transaction != null && session.Transaction.IsActive) { session.Transaction.Rollback(); } throw new InfrastructureException(ex.Message, ex); } finally { Cursor.Hide(); Cursor.Current = Cursors.Arrow; CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory); } if (ok) { List <Gimnasticar> items = dataGridViewUserControl1.getItems <Gimnasticar>(); foreach (Gimnasticar g in noviGimnasticari) { items.Add(g); } dataGridViewUserControl1.setItems <Gimnasticar>(items); dataGridViewUserControl1.clearSelection(); updateEntityCount(); } }
private void filter(object filterObject) { GimnasticarFilter flt = filterObject as GimnasticarFilter; if (flt == null) { return; } ISession session = null; try { using (session = NHibernateHelper.Instance.OpenSession()) using (session.BeginTransaction()) { CurrentSessionContext.Bind(session); // biranje gimnasticara sa prethodnog takmicenja //Takmicenje takmicenje = dataContext.GetById<Takmicenje>(5); //gimnasticari = dataContext.ExecuteNamedQuery<Gimnasticar>( // "FindGimnasticariByTakmicenje", // new string[] { "takmicenje" }, new object[] { takmicenje }); IList <Gimnasticar> gimnasticari; string failureMsg = ""; if (!String.IsNullOrEmpty(flt.RegBroj)) { gimnasticari = DAOFactoryFactory.DAOFactory.GetGimnasticarDAO().FindGimnasticariByRegBroj(flt.RegBroj); if (gimnasticari.Count == 0) { failureMsg = "Ne postoji gimnasticar sa datim registarskim brojem."; } } else { gimnasticari = DAOFactoryFactory.DAOFactory.GetGimnasticarDAO().FindGimnasticari(flt.Ime, flt.Prezime, flt.GodRodj, flt.Gimnastika, flt.Kategorija, flt.Klub); if (gimnasticari.Count == 0) { failureMsg = "Ne postoje gimnasticari koji zadovoljavaju date kriterijume."; } } SetItems(gimnasticari); updateEntityCount(); if (gimnasticari.Count == 0) { MessageDialogs.showMessage(failureMsg, this.Text); } } } catch (Exception ex) { if (session != null && session.Transaction != null && session.Transaction.IsActive) { session.Transaction.Rollback(); } MessageDialogs.showError( Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text); } finally { CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory); } }
protected virtual void handleOkClick() { if (showWaitCursor) { Cursor.Current = Cursors.WaitCursor; Cursor.Show(); } ISession session = null; try { using (session = NHibernateHelper.Instance.OpenSession()) using (session.BeginTransaction()) { CurrentSessionContext.Bind(session); Notification notification = new Notification(); requiredFieldsAndFormatValidation(notification); if (!notification.IsValid()) { throw new BusinessException(notification); } if (editMode) { update(); } else { add(); } if (persistEntity) { session.Transaction.Commit(); } closedByOK = true; } } catch (BusinessException ex) { if (session != null && session.Transaction != null && session.Transaction.IsActive) { session.Transaction.Rollback(); } if (ex.Notification != null) { NotificationMessage msg = ex.Notification.FirstMessage; MessageDialogs.showMessage(msg.Message, this.Text); setFocus(msg.FieldName); } else if (!string.IsNullOrEmpty(ex.InvalidProperty)) { MessageDialogs.showMessage(ex.Message, this.Text); setFocus(ex.InvalidProperty); } else { MessageDialogs.showMessage(ex.Message, this.Text); } this.DialogResult = DialogResult.None; } /*catch (StaleObjectStateException staleEx) * { * // TODO: This implementation does not implement optimistic concurrency * // control. Your application will not work until you add compensation * // actions. Rollback, close everything, possibly compensate for any * // permanent changes during the conversation, and finally restart * // business conversation. Maybe give the user of the application a * // chance to merge some of his work with fresh data... what you do * // here depends on your applications design. * * throw staleEx; * }*/ catch (Exception ex) { if (session != null && session.Transaction != null && session.Transaction.IsActive) { session.Transaction.Rollback(); } MessageDialogs.showError( Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text); this.DialogResult = DialogResult.Cancel; discardChanges(); closedByCancel = true; } finally { if (showWaitCursor) { Cursor.Hide(); Cursor.Current = Cursors.Arrow; } CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory); } }