private void IzmeniSubjekta() { try { if (gridView.SelectedRowsCount > 0 && gridView.GetFocusedRowCellValue("Subjekat_ID") != null) { Subjekat sub = new Subjekat() { Subjekat_ID = Convert.ToInt32(gridView.GetFocusedRowCellValue("Subjekat_ID")), Naziv = gridView.GetFocusedRowCellValue("Naziv").ToString(), Naziv2 = gridView.GetFocusedRowCellValue("Naziv2").ToString(), jeKupac = gridView.GetFocusedRowCellValue("jeKupac").ToString(), jeDobavljac = gridView.GetFocusedRowCellValue("jeDobavljac").ToString(), OIB = gridView.GetFocusedRowCellValue("OIB").ToString(), Adresa = gridView.GetFocusedRowCellValue("Adresa").ToString(), Posta_ID = Convert.ToInt32(gridView.GetFocusedRowCellValue("Posta_ID")), Telefon = gridView.GetFocusedRowCellValue("Telefon").ToString(), Email = gridView.GetFocusedRowCellValue("Email").ToString(), Drzava_ID = Convert.ToInt32(gridView.GetFocusedRowCellValue("Drzava_ID")) }; using (var IzmeniSubjekta = new InterakcijaSubjekat(sub)) { IzmeniSubjekta.BringToFront(); IzmeniSubjekta.Activate(); var result = IzmeniSubjekta.ShowDialog(); if (result == DialogResult.OK) { ucitajTabelu(); } } } else { MessageBox.Show("Morate prvo da izabere subjekta iz tabele.", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (DbUpdateException ex) { if (ex.InnerException != null) { if (ex.InnerException.ToString().Contains("The DELETE statement conflicted with the REFERENCE constraint")) { MessageBox.Show("Došlo je do greške prilikom brisanja. \nNije moguće obrsati elemnt koji se već koristi u drugoj tabeli.", "Greška", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MainForm.logger.Error("Naziv klase: " + this.GetType().Name + "\n Funkcija: " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n\"" + ex.InnerException.ToString().Trim().Substring(0, Math.Min(ex.InnerException.ToString().Trim().Length, 350)) + "\""); } } } catch (Exception ex) { MainForm.logger.Error("Naziv klase: " + this.GetType().Name + "\n Funkcija: " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n\"" + ex.Message.ToString().Trim().Substring(0, Math.Min(ex.Message.ToString().Trim().Length, 350)) + "\""); } }
public InterakcijaSubjekat(Subjekat sub) // KADA SE PRAVI IZMENA NA SUBJEKTU { try { //PODESAVANJE POCETNO InitializeComponent(); Text = "Izmena subjekta"; this.sub = sub; btnOcisti.Visible = false; btnPotvrdi.Enabled = false; //PODESAVANJE POCETNO popuniDrzave(); popuniPoste(Convert.ToInt32(sub.Drzava_ID)); txtNaziv.Text = sub.Naziv; txtPunNaziv.Text = sub.Naziv2; txtOIB.Text = sub.OIB; txtAdresa.Text = sub.Adresa; checkKupac.Checked = Convert.ToBoolean(Convert.ToInt32(sub.jeKupac)); checkDobavljac.Checked = Convert.ToBoolean(Convert.ToInt32(sub.jeDobavljac)); txtTelefon.Text = sub.Telefon; txtEmail.Text = sub.Email; ProveraPromene(); } catch (DbUpdateException ex) { if (ex.InnerException != null) { if (ex.InnerException.ToString().Contains("The DELETE statement conflicted with the REFERENCE constraint")) { MessageBox.Show("Došlo je do greške prilikom brisanja. \nNije moguće obrsati elemnt koji se već koristi u drugoj tabeli.", "Greška", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MainForm.logger.Error("Naziv klase: " + this.GetType().Name + "\n Funkcija: " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n\"" + ex.InnerException.ToString().Trim().Substring(0, Math.Min(ex.InnerException.ToString().Trim().Length, 350)) + "\""); } } } catch (Exception ex) { MainForm.logger.Error("Naziv klase: " + this.GetType().Name + "\n Funkcija: " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n\"" + ex.Message.ToString().Trim().Substring(0, Math.Min(ex.Message.ToString().Trim().Length, 350)) + "\""); } }
public InterakcijaSubjekat() // KADA SE KREIRA SUBJEKAT { try { //PODESAVANJE POCETNO InitializeComponent(); Text = "Kreiranje novog subjekta"; checkKupac.Checked = true; popuniDrzave(); txtNaziv.SelectAll(); txtPunNaziv.SelectAll(); txtOIB.SelectAll(); txtEmail.SelectAll(); txtAdresa.SelectAll(); txtTelefon.SelectAll(); lblPostaNaziv.Text = ""; this.sub = null; //PODESAVANJE POCETNO } catch (DbUpdateException ex) { if (ex.InnerException != null) { if (ex.InnerException.ToString().Contains("The DELETE statement conflicted with the REFERENCE constraint")) { MessageBox.Show("Došlo je do greške prilikom brisanja. \nNije moguće obrsati elemnt koji se već koristi u drugoj tabeli.", "Greška", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MainForm.logger.Error("Naziv klase: " + this.GetType().Name + "\n Funkcija: " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n\"" + ex.InnerException.ToString().Trim().Substring(0, Math.Min(ex.InnerException.ToString().Trim().Length, 350)) + "\""); } } } catch (Exception ex) { MainForm.logger.Error("Naziv klase: " + this.GetType().Name + "\n Funkcija: " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n\"" + ex.Message.ToString().Trim().Substring(0, Math.Min(ex.Message.ToString().Trim().Length, 350)) + "\""); } }
private void NapraviSubjekta() { try { //PROVERA DA LI SU SVA POLJA POPUNJENA if (txtNaziv.Text.Trim() != "" && txtPunNaziv.Text.Trim() != "" && txtOIB.Text.Trim() != "" && txtAdresa.Text.Trim() != "" && txtTelefon.Text.Trim() != "" && txtEmail.Text.Trim() != "" && cmbDrzava.Text.Trim() != cmbDrzava.Properties.NullText.Trim() && cmbPosta.Text.Trim() != cmbPosta.Properties.NullText.Trim() && cmbDrzava.Text.Trim() != "" && cmbPosta.Text.Trim() != "") { if (txtOIB.Text.Trim().Length == 11) { //OVDE POCINJE UPISIVANJE KORSNIKA using (var con = new MONTESINOEntities()) { var oib = con.Subjekats.SingleOrDefault(x => x.OIB.ToString().Trim() == txtOIB.Text.Trim()); if (oib == null) { DataRowView rowView1 = (DataRowView)cmbDrzava.GetSelectedDataRow(); DataRow redDrzava = rowView1.Row; DataRowView rowView2 = (DataRowView)cmbPosta.GetSelectedDataRow(); DataRow redPosta = rowView2.Row; var noviSub = new Subjekat() { Naziv = txtNaziv.Text.Trim(), Naziv2 = txtPunNaziv.Text.Trim(), jeKupac = (checkKupac.Checked ? "1" : "0").Trim(), jeDobavljac = (checkDobavljac.Checked ? "1" : "0").Trim(), OIB = txtOIB.Text.Trim().Trim(), Adresa = txtAdresa.Text.Trim(), Posta_ID = Convert.ToInt32(redPosta["Posta_ID"].ToString().Trim()), Telefon = txtTelefon.Text.Trim(), Email = txtEmail.Text.Trim(), Drzava_ID = Convert.ToInt32(redDrzava["Drzava_ID"].ToString().Trim()) }; con.Subjekats.Add(noviSub); con.SaveChanges(); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("Subjekat sa unetim OIB-om već postoji!", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { MessageBox.Show("OIB mora da ima tačno 11 karaktera!", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Morate popuniti sva polja!", "Greška", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (DbUpdateException ex) { if (ex.InnerException != null) { if (ex.InnerException.ToString().Contains("The DELETE statement conflicted with the REFERENCE constraint")) { MessageBox.Show("Došlo je do greške prilikom brisanja. \nNije moguće obrsati elemnt koji se već koristi u drugoj tabeli.", "Greška", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MainForm.logger.Error("Naziv klase: " + this.GetType().Name + "\n Funkcija: " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n\"" + ex.InnerException.ToString().Trim().Substring(0, Math.Min(ex.InnerException.ToString().Trim().Length, 350)) + "\""); } } } catch (Exception ex) { MainForm.logger.Error("Naziv klase: " + this.GetType().Name + "\n Funkcija: " + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n\"" + ex.Message.ToString().Trim().Substring(0, Math.Min(ex.Message.ToString().Trim().Length, 350)) + "\""); } }