public void Update() { OblastBasic o = new OblastBasic() { JedinstvenoIme = tbxIme.Text, Povrsina = int.Parse(tbxPovrsina.Text), OblastId = IdOblastUpdate }; int i = DTOManangerOblast.UpdateOblastBasic(o); if (i == 0) { MessageBox.Show("Vec postoji oblast sa tim imenom"); } else if (i == 2) { MessageBox.Show("Doslo je do greske"); } else { this.Close(); DialogResult = System.Windows.Forms.DialogResult.OK; } }
public static int UpdateOblastBasic(OblastBasic a) { try { ISession s = DataLayer.GetSession(); string ime = (from ob in s.Query <Oblast>() where (ob.JedinstvenoIme == a.JedinstvenoIme) select ob.JedinstvenoIme).SingleOrDefault(); /*if (ime == a.JedinstvenoIme) * return 0;*/ Oblast o = s.Load <Oblast>(a.OblastId); // o.JedinstvenoIme = a.JedinstvenoIme; o.Povrsina = a.Povrsina; s.Update(o); s.Flush(); s.Close(); } catch (Exception ec) { return(2); } return(1); }
public static int DodajOblast(OblastBasic a) // ovo ne radi kako treba { try { ISession s = DataLayer.GetSession(); string ime = (from ob in s.Query <Oblast>() where (ob.JedinstvenoIme == a.JedinstvenoIme) select ob.JedinstvenoIme).SingleOrDefault(); if (ime == a.JedinstvenoIme) { return(0); } Oblast o = null; if (a.TipZastite == "Stalna zastita") { o = new StalnaZastita() { JedinstvenoIme = a.JedinstvenoIme, Povrsina = a.Povrsina }; } else if (a.TipZastite == "Monitoring") { o = new Monitoring() { JedinstvenoIme = a.JedinstvenoIme, Povrsina = a.Povrsina }; } else { o = new PovremeneIntervencije() { JedinstvenoIme = a.JedinstvenoIme, Povrsina = a.Povrsina }; } s.Save(o); s.Flush(); s.Close(); } catch (Exception ec) { return(2); } return(1); }
public static OblastBasic VratiOblast(int id) { OblastBasic o = null; try { ISession s = DataLayer.GetSession(); Oblast oblast = s.Load <Oblast>(id); string tip = ""; if (oblast.GetType() == typeof(StalnaZastita)) { tip = "Stalna zastita"; } else if (oblast.GetType() == typeof(Monitoring)) { tip = "Monitoring"; } else if (oblast.GetType() == typeof(PovremeneIntervencije)) { tip = "Povremena intervencija"; } o = new OblastBasic() { JedinstvenoIme = oblast.JedinstvenoIme, OblastId = oblast.Id, Povrsina = oblast.Povrsina, TipZastite = tip }; s.Close(); } catch (Exception) { throw; } return(o); }
private void postaviKontrole() { if (IdOblastUpdate == 0) { tbxId.Visible = false; lblId.Visible = false; cbxTipZastite.Location = new Point(341, 29); lblTip.Location = new Point(338, 9); } else { cbxTipZastite.Visible = false; lblTip.Visible = false; tbxId.Location = new Point(341, 29); lblId.Location = new Point(338, 9); OblastBasic o = DTOManangerOblast.VratiOblast(IdOblastUpdate); tbxId.Text = o.OblastId.ToString(); tbxId.Enabled = false; tbxIme.Text = o.JedinstvenoIme; tbxPovrsina.Text = o.Povrsina.ToString(); } }