public virtual void Edit() { if (SelectedItem == null) { return; } int index = dataGridViewUserControl1.getSelectedItemIndex(); try { EntityDetailForm form = createEntityDetailForm(getEntityId(SelectedItem)); if (form.ShowDialog() == DialogResult.OK) { T entity = (T)form.Entity; List <T> items = dataGridViewUserControl1.getItems <T>(); items[index] = entity; dataGridViewUserControl1.setItems <T>(items); // ovo ponovo sortira items dataGridViewUserControl1.setSelectedItem <T>(entity); } } catch (InfrastructureException ex) { MessageDialogs.showError(ex.Message, this.Text); } }
private void btnDodajIzvodMKR_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() != DialogResult.OK) { return; } string fileName = Path.GetFileName(ofd.FileName); string fileDirectory = Path.GetDirectoryName(ofd.FileName); string appDirectory = AppDomain.CurrentDomain.BaseDirectory; string destDirectory = Path.Combine(appDirectory, ConfigurationParameters.IzvodiMKRFolder); bool fileIsInDestDirectory = fileDirectory.ToUpper() == destDirectory.ToUpper(); string newPath = Path.Combine(appDirectory, ConfigurationParameters.IzvodiMKRFolder, fileName); if (!fileIsInDestDirectory && File.Exists(newPath)) { // Izabran je fajl van odredisnog foldera, a u odredisnom folderu vec postoji fajl sa istim imenom. // Nemoj da kopiras da ne bi prebrisao stari fajl. MessageDialogs.showError(String.Format("Fajl sa identicnim imenom ('{0}') vec postoji u folderu {1}.", fileName, ConfigurationParameters.IzvodiMKRFolder), this.Text); } else { // Kopiraj samo ako je izabran fajl van odredisnog direktorijuma if (!fileIsInDestDirectory) { File.Copy(ofd.FileName, newPath); } txtIzvodMKR.Text = fileName; } }
private void deleteCommand() { if (SelectedItem == null) { return; } if (!MessageDialogs.queryConfirmation(deleteConfirmationMessage(SelectedItem), this.Text)) { return; } ISession session = null; bool ok = false; try { using (session = NHibernateHelper.Instance.OpenSession()) using (session.BeginTransaction()) { CurrentSessionContext.Bind(session); if (refIntegrityDeleteDlg(SelectedItem)) { delete(SelectedItem); session.Transaction.Commit(); ok = true; } } } catch (Exception ex) { if (session != null && session.Transaction != null && session.Transaction.IsActive) { session.Transaction.Rollback(); } MessageDialogs.showError( String.Format("{0} \n\n{1}", deleteErrorMessage(), ex.Message), this.Text); } finally { CurrentSessionContext.Unbind(NHibernateHelper.Instance.SessionFactory); } if (ok) { List <T> items = dataGridViewUserControl1.getItems <T>(); items.Remove(SelectedItem); CurrencyManager currencyManager = (CurrencyManager)this.BindingContext[dataGridViewUserControl1.DataGridView.DataSource]; currencyManager.Refresh(); updateEntityCount(); } }
private void mnTreneri_Click(object sender, EventArgs e) { try { TreneriForm form = new TreneriForm(); form.ShowDialog(); } catch (Exception ex) { MessageDialogs.showError(ex.Message, this.Text); } }
private void mnKategorijeGimnasticara_Click(object sender, EventArgs e) { try { KategorijeGimnasticaraForm form = new KategorijeGimnasticaraForm(); form.ShowDialog(); } catch (Exception ex) { MessageDialogs.showError(ex.Message, this.Text); } }
private void mnGimnasticari_Click(object sender, EventArgs e) { try { GimnasticariForm form = new GimnasticariForm(); form.ShowDialog(); } catch (Exception ex) { // NOTE: Izuzetak moze da potice samo iz konstruktora. Kada se form // uspesno kreira i prikaze pozivom ShowDialog (ili Show), tada se // izuzetci unutar forma ne propagiraju do koda koji je pozvao // ShowDialog. MessageDialogs.showError(ex.Message, this.Text); } }
private void btnAddKlub_Click(object sender, EventArgs e) { try { KlubForm form = new KlubForm(null); if (form.ShowDialog() == DialogResult.OK) { Klub k = (Klub)form.Entity; klubovi.Add(k); klubovi.Sort(); setKlubovi(klubovi); SelectedKlub = k; } } catch (InfrastructureException ex) { MessageDialogs.showError(ex.Message, this.Text); } }
protected virtual void AddNew() { try { EntityDetailForm form = createEntityDetailForm(null); if (form.ShowDialog() == DialogResult.OK) { T newEntity = (T)form.Entity; List <T> items = dataGridViewUserControl1.getItems <T>(); items.Add(newEntity); dataGridViewUserControl1.setItems <T>(items); dataGridViewUserControl1.setSelectedItem <T>(newEntity); updateEntityCount(); } } catch (InfrastructureException ex) { MessageDialogs.showError(ex.Message, this.Text); } }
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); } }
protected override void onApplyFilter() { if (filterForm == null || filterForm.IsDisposed) { // NOTE: IsDisposed je true kada se form zatvori (bilo pritiskom na X // ili pozivom Close) try { filterForm = new FilterGimnasticarForm(null); // can throw filterForm.Filter += new EventHandler(filterForm_Filter); filterForm.Show(); } catch (InfrastructureException ex) { MessageDialogs.showError(ex.Message, this.Text); } } else { filterForm.Activate(); } }
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); } }
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); } }