コード例 #1
0
        public int UpdatePutnicko(string id, Putnicko r)
        {
            try
            {
                ISession s = DataLayer.GetSession();

                IQuery   query  = s.CreateQuery("select r from Putnicko r where r.RegOznaka = " + id);
                Putnicko vozilo = query.UniqueResult <Putnicko>();

                vozilo.Boja            = r.Boja;
                vozilo.Gorivo          = r.Gorivo;
                vozilo.ZapreminaMotora = r.ZapreminaMotora;
                vozilo.BrojMesta       = r.BrojMesta;

                s.SaveOrUpdate(vozilo);

                s.Flush();
                s.Close();

                return(1);
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show(exc.Message);
                return(-1);
            }
        }
コード例 #2
0
        public PutnickoView GetPutnicko(string regozn)
        {
            ISession     s        = DataLayer.GetSession();
            Putnicko     v        = s.Query <Putnicko>().Where(e => e.RegOznaka == regozn).Select(p => p).FirstOrDefault();
            PutnickoView putnicko = new PutnickoView(v);

            return(putnicko);
        }
コード例 #3
0
 public PutnickoView(Putnicko p)
 {
     this.RegOznaka              = p.RegOznaka;
     this.Gorivo                 = p.Gorivo;
     this.Boja                   = p.Boja;
     this.ZapreminaMotora        = p.ZapreminaMotora;
     this.BrojMesta              = p.BrojMesta;
     this.BrojNadzornikaKojiDuze = p.Nadzornici.Count;
 }
コード例 #4
0
        public PutnickoView VratiPutnickoView(int id)
        {
            ISession s = DataLayer.GetSession();

            Putnicko vozilo = s.Query <Putnicko>()
                              .Where(v => v.id == id).Select(p => p).FirstOrDefault();

            if (vozilo == null)
            {
                return(new PutnickoView());
            }

            return(new PutnickoView(vozilo));
        }
コード例 #5
0
 public int AddPutnicko(Putnicko v)
 {
     try
     {
         ISession s = DataLayer.GetSession();
         s.Save(v);
         s.Flush();
         s.Close();
         return(1);
     }
     catch (Exception e)
     {
         return(-1);
     }
 }
コード例 #6
0
        public int RemovePutnicko(string reg)
        {
            try
            {
                ISession s = DataLayer.GetSession();

                Putnicko n = s.Load <Putnicko>(reg);
                s.Delete(n);
                s.Flush();
                s.Close();

                return(1);
            }
            catch (Exception e)
            {
                return(-1);
            }
        }
コード例 #7
0
        public int ObirisPutnickoVozilo(int id)
        {
            try
            {
                ISession s = DataLayer.GetSession();

                Putnicko v = s.Load <Putnicko>(id);

                s.Delete(v);

                s.Flush();
                s.Close();

                return(1);
            }
            catch (Exception ec)
            {
                return(-1);
            }
        }
コード例 #8
0
 public PutnickoView(Putnicko p)
 {
     id                = p.id;
     brojSasije        = p.brojSasije;
     boja              = p.boja;
     brojMotora        = p.brojMotora;
     gorivo            = p.gorivo;
     modelVozila       = p.modelVozila;
     kubikaza          = p.kubikaza;
     datumUvoza        = p.datumUvoza;
     datumKupovine     = p.datumKupovine;
     poznato           = p.poznato;
     opisProblema      = p.opisProblema;
     ime               = p.ime;
     prezime           = p.prezime;
     telefon           = p.telefon;
     tipVozila         = p.tipVozila;
     registarskiBroj   = p.registarskiBroj;
     godinaProizvodnje = p.godinaProizvodnje;
     brojPutnika       = p.brojPutnika;
 }
コード例 #9
0
        // PUT api/putnicko/5
        public int Put(string id, [FromBody] Putnicko value)
        {
            DataProvider provider = new DataProvider();

            return(provider.UpdatePutnicko(id, value));
        }
コード例 #10
0
        // POST api/putnicko
        public int Post([FromBody] Putnicko value)
        {
            DataProvider dp = new DataProvider();

            return(dp.AddPutnicko(value));
        }
コード例 #11
0
        private void btn_sacuvaj_Click(object sender, EventArgs e)
        {
            try
            {
                //kreira novog kupca
                if (novoVozilo)
                {
                    if (string.IsNullOrEmpty(txt_tip_vozila.Text))
                    {
                        MessageBox.Show("Polje Tip Vozila ne sme biti prazno!", "Upozorenje",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    ISession session = DataLayer.GetSession();

                    switch (cb_prikaz.Text)
                    {
                    case "putnicko":
                    {
                        Putnicko vozilo = new Putnicko();

                        vozilo.boja = txt_boja.Text;

                        if (string.IsNullOrEmpty(txt_br_motora.Text))
                        {
                            vozilo.brojMotora = null;
                        }
                        else
                        {
                            vozilo.brojMotora = Double.Parse(txt_br_motora.Text);
                        }

                        vozilo.brojPutnika = int.Parse(txt_br_putnika.Text);

                        if (string.IsNullOrEmpty(txt_br_sasije.Text))
                        {
                            vozilo.brojSasije = null;
                        }
                        else
                        {
                            vozilo.brojSasije = Double.Parse(txt_br_sasije.Text);
                        }

                        vozilo.datumKupovine = DateTime.Parse(dtp_datum_kupovine.Value.ToString());
                        vozilo.datumUvoza    = DateTime.Parse(dtp_datum_uvoza.Value.ToString());

                        if (string.IsNullOrEmpty(txt_godina_proizvodnje.Text))
                        {
                            vozilo.godinaProizvodnje = null;
                        }
                        else
                        {
                            vozilo.godinaProizvodnje = int.Parse(txt_godina_proizvodnje.Text);
                        }

                        vozilo.gorivo  = txt_gorivo.Text;
                        vozilo.ime     = txt_ime.Text;
                        vozilo.prezime = txt_prezime.Text;

                        if (string.IsNullOrEmpty(txt_telefon.Text))
                        {
                            vozilo.telefon = null;
                        }
                        else
                        {
                            vozilo.telefon = long.Parse(txt_telefon.Text);
                        }

                        if (string.IsNullOrEmpty(txt_kubikaza.Text))
                        {
                            vozilo.kubikaza = null;
                        }
                        else
                        {
                            vozilo.kubikaza = float.Parse(txt_kubikaza.Text);
                        }

                        if (!string.IsNullOrEmpty(txt_id_kupac.Text))
                        {
                            var kupac = (from kpc in session.Query <Kupac>()
                                         where kpc.id == int.Parse(txt_id_kupac.Text)
                                         select kpc).SingleOrDefault();
                            vozilo.kupac = kupac;
                        }
                        else
                        {
                            vozilo.kupac = null;
                        }

                        vozilo.modelVozila = txt_model_vozila.Text;

                        vozilo.opisProblema = txt_opis_problema.Text;
                        vozilo.poznato      = txt_poznato.Text;

                        if (string.IsNullOrEmpty(txt_registarski_broj.Text))
                        {
                            vozilo.registarskiBroj = null;
                        }
                        else
                        {
                            vozilo.registarskiBroj = long.Parse(txt_registarski_broj.Text);
                        }

                        if (!string.IsNullOrEmpty(txt_id_salon.Text))
                        {
                            var salon = (from sln in session.Query <Salon>()
                                         where sln.idSalon == int.Parse(txt_id_salon.Text)
                                         select sln).SingleOrDefault();
                            vozilo.salon = salon;
                        }
                        else
                        {
                            vozilo.salon = null;
                        }

                        if (!string.IsNullOrEmpty(txt_id_servis.Text))
                        {
                            var servis = (from srv in session.Query <Servis>()
                                          where srv.id == int.Parse(txt_id_servis.Text)
                                          select srv).SingleOrDefault();
                            vozilo.servis = servis;
                        }
                        else
                        {
                            vozilo.servis = null;
                        }

                        vozilo.tipVozila = txt_tip_vozila.Text;

                        session.Save(vozilo);
                        session.Flush();
                        session.Close();

                        GetData("putnicko");
                        novoVozilo = false;

                        break;
                    }

                    case "teretno":
                    {
                        Teretno vozilo = new Teretno();

                        vozilo.boja = txt_boja.Text;

                        if (string.IsNullOrEmpty(txt_br_motora.Text))
                        {
                            vozilo.brojMotora = null;
                        }
                        else
                        {
                            vozilo.brojMotora = Double.Parse(txt_br_motora.Text);
                        }

                        if (string.IsNullOrEmpty(txt_br_sasije.Text))
                        {
                            vozilo.brojSasije = null;
                        }
                        else
                        {
                            vozilo.brojSasije = Double.Parse(txt_br_sasije.Text);
                        }

                        vozilo.datumKupovine = DateTime.Parse(dtp_datum_kupovine.Value.ToString());
                        vozilo.datumUvoza    = DateTime.Parse(dtp_datum_uvoza.Value.ToString());

                        if (string.IsNullOrEmpty(txt_godina_proizvodnje.Text))
                        {
                            vozilo.godinaProizvodnje = null;
                        }
                        else
                        {
                            vozilo.godinaProizvodnje = int.Parse(txt_godina_proizvodnje.Text);
                        }

                        vozilo.gorivo  = txt_gorivo.Text;
                        vozilo.ime     = txt_ime.Text;
                        vozilo.prezime = txt_prezime.Text;

                        if (string.IsNullOrEmpty(txt_telefon.Text))
                        {
                            vozilo.telefon = null;
                        }
                        else
                        {
                            vozilo.telefon = long.Parse(txt_telefon.Text);
                        }

                        if (string.IsNullOrEmpty(txt_kubikaza.Text))
                        {
                            vozilo.kubikaza = null;
                        }
                        else
                        {
                            vozilo.kubikaza = float.Parse(txt_kubikaza.Text);
                        }

                        if (!string.IsNullOrEmpty(txt_id_kupac.Text))
                        {
                            var kupac = (from kpc in session.Query <Kupac>()
                                         where kpc.id == int.Parse(txt_id_kupac.Text)
                                         select kpc).SingleOrDefault();
                            vozilo.kupac = kupac;
                        }
                        else
                        {
                            vozilo.kupac = null;
                        }

                        vozilo.modelVozila = txt_model_vozila.Text;

                        vozilo.nosivost = Double.Parse(txt_nosivost.Text);

                        vozilo.opisProblema = txt_opis_problema.Text;
                        vozilo.poznato      = txt_poznato.Text;

                        if (string.IsNullOrEmpty(txt_registarski_broj.Text))
                        {
                            vozilo.registarskiBroj = null;
                        }
                        else
                        {
                            vozilo.registarskiBroj = long.Parse(txt_registarski_broj.Text);
                        }

                        if (!string.IsNullOrEmpty(txt_id_salon.Text))
                        {
                            var salon = (from sln in session.Query <Salon>()
                                         where sln.idSalon == int.Parse(txt_id_salon.Text)
                                         select sln).SingleOrDefault();
                            vozilo.salon = salon;
                        }
                        else
                        {
                            vozilo.salon = null;
                        }

                        if (!string.IsNullOrEmpty(txt_id_servis.Text))
                        {
                            var servis = (from srv in session.Query <Servis>()
                                          where srv.id == int.Parse(txt_id_servis.Text)
                                          select srv).SingleOrDefault();
                            vozilo.servis = servis;
                        }
                        else
                        {
                            vozilo.servis = null;
                        }

                        vozilo.tipProstora = txt_tip_prostora.Text;
                        vozilo.tipVozila   = txt_tip_vozila.Text;

                        session.Save(vozilo);
                        session.Flush();
                        session.Close();

                        GetData("teretno");
                        novoVozilo = false;
                        break;
                    }
                    }
                }
                //azurira postojeceg kupca
                else
                {
                    ISession session = DataLayer.GetSession();
                    int      id      = int.Parse(dgvVozilo.SelectedRows[0].Cells[0].Value.ToString());

                    switch (cb_prikaz.Text)
                    {
                    case "putnicko":
                    {
                        Putnicko vozilo = session.Load <Putnicko>(id);

                        vozilo.boja = txt_boja.Text;

                        if (string.IsNullOrEmpty(txt_br_motora.Text))
                        {
                            vozilo.brojMotora = null;
                        }
                        else
                        {
                            vozilo.brojMotora = Double.Parse(txt_br_motora.Text);
                        }

                        vozilo.brojPutnika = int.Parse(txt_br_putnika.Text);

                        if (string.IsNullOrEmpty(txt_br_sasije.Text))
                        {
                            vozilo.brojSasije = null;
                        }
                        else
                        {
                            vozilo.brojSasije = Double.Parse(txt_br_sasije.Text);
                        }

                        vozilo.datumKupovine = DateTime.Parse(dtp_datum_kupovine.Value.ToString());
                        vozilo.datumUvoza    = DateTime.Parse(dtp_datum_uvoza.Value.ToString());

                        if (string.IsNullOrEmpty(txt_godina_proizvodnje.Text))
                        {
                            vozilo.godinaProizvodnje = null;
                        }
                        else
                        {
                            vozilo.godinaProizvodnje = int.Parse(txt_godina_proizvodnje.Text);
                        }

                        vozilo.gorivo  = txt_gorivo.Text;
                        vozilo.ime     = txt_ime.Text;
                        vozilo.prezime = txt_prezime.Text;

                        if (string.IsNullOrEmpty(txt_telefon.Text))
                        {
                            vozilo.telefon = null;
                        }
                        else
                        {
                            vozilo.telefon = long.Parse(txt_telefon.Text);
                        }

                        if (string.IsNullOrEmpty(txt_kubikaza.Text))
                        {
                            vozilo.kubikaza = null;
                        }
                        else
                        {
                            vozilo.kubikaza = float.Parse(txt_kubikaza.Text);
                        }

                        if (!string.IsNullOrEmpty(txt_id_kupac.Text))
                        {
                            var kupac = (from kpc in session.Query <Kupac>()
                                         where kpc.id == int.Parse(txt_id_kupac.Text)
                                         select kpc).SingleOrDefault();
                            vozilo.kupac = kupac;
                        }
                        else
                        {
                            vozilo.kupac = null;
                        }

                        vozilo.modelVozila = txt_model_vozila.Text;

                        vozilo.opisProblema = txt_opis_problema.Text;
                        vozilo.poznato      = txt_poznato.Text;

                        if (string.IsNullOrEmpty(txt_registarski_broj.Text))
                        {
                            vozilo.registarskiBroj = null;
                        }
                        else
                        {
                            vozilo.registarskiBroj = long.Parse(txt_registarski_broj.Text);
                        }

                        if (!string.IsNullOrEmpty(txt_id_salon.Text))
                        {
                            var salon = (from sln in session.Query <Salon>()
                                         where sln.idSalon == int.Parse(txt_id_salon.Text)
                                         select sln).SingleOrDefault();
                            vozilo.salon = salon;
                        }
                        else
                        {
                            vozilo.salon = null;
                        }

                        if (!string.IsNullOrEmpty(txt_id_servis.Text))
                        {
                            var servis = (from srv in session.Query <Servis>()
                                          where srv.id == int.Parse(txt_id_servis.Text)
                                          select srv).SingleOrDefault();
                            vozilo.servis = servis;
                        }
                        else
                        {
                            vozilo.servis = null;
                        }

                        vozilo.tipVozila = txt_tip_vozila.Text;

                        session.SaveOrUpdate(vozilo);
                        session.Flush();
                        session.Close();

                        GetData("putnicko");
                        novoVozilo = false;

                        break;
                    }

                    case "teretno":
                    {
                        Teretno vozilo = session.Load <Teretno>(id);

                        vozilo.boja = txt_boja.Text;

                        if (string.IsNullOrEmpty(txt_br_motora.Text))
                        {
                            vozilo.brojMotora = null;
                        }
                        else
                        {
                            vozilo.brojMotora = Double.Parse(txt_br_motora.Text);
                        }

                        if (string.IsNullOrEmpty(txt_br_sasije.Text))
                        {
                            vozilo.brojSasije = null;
                        }
                        else
                        {
                            vozilo.brojSasije = Double.Parse(txt_br_sasije.Text);
                        }

                        vozilo.datumKupovine = DateTime.Parse(dtp_datum_kupovine.Value.ToString());
                        vozilo.datumUvoza    = DateTime.Parse(dtp_datum_uvoza.Value.ToString());

                        if (string.IsNullOrEmpty(txt_godina_proizvodnje.Text))
                        {
                            vozilo.godinaProizvodnje = null;
                        }
                        else
                        {
                            vozilo.godinaProizvodnje = int.Parse(txt_godina_proizvodnje.Text);
                        }

                        vozilo.gorivo  = txt_gorivo.Text;
                        vozilo.ime     = txt_ime.Text;
                        vozilo.prezime = txt_prezime.Text;

                        if (string.IsNullOrEmpty(txt_telefon.Text))
                        {
                            vozilo.telefon = null;
                        }
                        else
                        {
                            vozilo.telefon = long.Parse(txt_telefon.Text);
                        }

                        if (string.IsNullOrEmpty(txt_kubikaza.Text))
                        {
                            vozilo.kubikaza = null;
                        }
                        else
                        {
                            vozilo.kubikaza = float.Parse(txt_kubikaza.Text);
                        }

                        if (!string.IsNullOrEmpty(txt_id_kupac.Text))
                        {
                            var kupac = (from kpc in session.Query <Kupac>()
                                         where kpc.id == int.Parse(txt_id_kupac.Text)
                                         select kpc).SingleOrDefault();
                            vozilo.kupac = kupac;
                        }
                        else
                        {
                            vozilo.kupac = null;
                        }

                        vozilo.modelVozila = txt_model_vozila.Text;

                        vozilo.nosivost = Double.Parse(txt_nosivost.Text);

                        vozilo.opisProblema = txt_opis_problema.Text;
                        vozilo.poznato      = txt_poznato.Text;

                        if (string.IsNullOrEmpty(txt_registarski_broj.Text))
                        {
                            vozilo.registarskiBroj = null;
                        }
                        else
                        {
                            vozilo.registarskiBroj = long.Parse(txt_registarski_broj.Text);
                        }

                        if (!string.IsNullOrEmpty(txt_id_salon.Text))
                        {
                            var salon = (from sln in session.Query <Salon>()
                                         where sln.idSalon == int.Parse(txt_id_salon.Text)
                                         select sln).SingleOrDefault();
                            vozilo.salon = salon;
                        }
                        else
                        {
                            vozilo.salon = null;
                        }

                        if (!string.IsNullOrEmpty(txt_id_servis.Text))
                        {
                            var servis = (from srv in session.Query <Servis>()
                                          where srv.id == int.Parse(txt_id_servis.Text)
                                          select srv).SingleOrDefault();
                            vozilo.servis = servis;
                        }
                        else
                        {
                            vozilo.servis = null;
                        }

                        vozilo.tipProstora = txt_tip_prostora.Text;
                        vozilo.tipVozila   = txt_tip_vozila.Text;

                        session.SaveOrUpdate(vozilo);
                        session.Flush();
                        session.Close();

                        GetData("teretno");
                        novoVozilo = false;
                        break;
                    }
                    }
                }
            }
            catch (Exception catchException)
            {
                MessageBox.Show(catchException.Message + catchException.InnerException, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }