// GET: PutniNalog/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PutniNalog putniNalog = putniNalogRepository.GetById(id); if (putniNalog == null) { return(HttpNotFound()); } PutniNalogViewModel model = new PutniNalogViewModel { Vozac = vozacRepository.GetById(putniNalog.VozacID), Vozilo = voziloRepository.GetById(putniNalog.VoziloID), BrojDnevnica = putniNalog.BrojDnevnica, BrojSati = putniNalog.BrojSati, IDPutniNalog = putniNalog.IDPutniNalog.Value, IznosDnevnice = putniNalog.IznosDnevnice, Opis = putniNalog.Opis, DatumDolaska = putniNalog.DatumDolaska, DatumOdlaska = putniNalog.DatumOdlaska }; return(View(model)); }
public void Delete(PutniNalog entity) { using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("DeleteWarrant", connection)) { try { command.Connection = connection; command.Transaction = tran; //@pIme nvarchar(50), @pPrezime nvarchar(50), @pBrojMobitela nvarchar(50),@pSerijskiBrojVozacke nvarchar(8) command.Parameters.Add(database.CreateParameter("pID", entity.IDPutniNalog)); command.ExecuteNonQuery(); tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch (Exception ex2) { throw; } } } } }
public ActionResult Create(PutniNalogViewModel putniNalog) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { PutniNalog nalog = new PutniNalog { VozacID = putniNalog.VozacID, VoziloID = putniNalog.VoziloID, BrojSati = putniNalog.BrojSati, BrojDnevnica = putniNalog.BrojDnevnica, DatumDolaska = putniNalog.DatumDolaska, DatumOdlaska = putniNalog.DatumOdlaska, IznosDnevnice = putniNalog.IznosDnevnice, Opis = putniNalog.Opis }; putniNalogRepository.Add(nalog); //db.PutniNalozi.Add(putniNalog); //db.SaveChanges(); return(RedirectToAction("Index")); } putniNalog.ListaVozaca = vozacRepository.List(); putniNalog.ListaVozila = voziloRepository.List(); putniNalog.ListaGradova = gradRepository.List(); putniNalog.ListaDrzava = drzavaRepository.List(); return(View(putniNalog)); }
// GET: PutniNalog/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PutniNalog putniNalog = putniNalogRepository.GetById(id); if (putniNalog == null) { return(HttpNotFound()); } var model = new PutniNalogViewModel { ListaVozaca = vozacRepository.List(), ListaVozila = voziloRepository.List(), BrojDnevnica = putniNalog.BrojDnevnica, BrojSati = putniNalog.BrojSati, DatumDolaska = putniNalog.DatumDolaska, DatumOdlaska = putniNalog.DatumOdlaska, Opis = putniNalog.Opis, IznosDnevnice = putniNalog.IznosDnevnice, VozacID = putniNalog.VozacID, VoziloID = putniNalog.VoziloID, Vozac = putniNalog.Vozac, IDPutniNalog = putniNalog.IDPutniNalog.Value }; //ViewBag.VozacID = new SelectList(Models.SqlHandler.GetVozaci(), "IDVozac", "FirstName", putniNalog.VozacID); // ViewBag.VoziloID = new SelectList(Models.SqlHandler.GetVozila(), "IDVozilo", "FirstName", putniNalog.VozacID); return(View(model)); }
public PutniNalog GetPutniNalog(int id) { PutniNalog p = new PutniNalog(); using (SqlConnection con = new SqlConnection(cs)) { con.Open(); using (SqlCommand comm = con.CreateCommand()) { comm.CommandType = System.Data.CommandType.StoredProcedure; comm.CommandText = "GET_PUTNI_NALOG"; comm.Parameters.AddWithValue("@ID", id); using (SqlDataReader r = comm.ExecuteReader()) { if (r.HasRows) { while (r.Read()) { p.IDPutniNalog = (int)r["IDPutniNalog"]; p.VozacID = (int)r["VozacID"]; p.VoziloID = (int)r["VoziloID"]; p.VrijemePocetka = (DateTime)r["VrijemePocetka"]; p.VrijemeZavrsetka = (DateTime)r["VrijemeZavrsetka"]; p.OstaliDetalji = r["OstaliDetalji"].ToString(); } } } } } return(p); }
public IEnumerable <PutniNalog> FindBetweenDates(DateTime begin, DateTime end) { PutniNalog temp = null; List <PutniNalog> listPutniNalog = new List <PutniNalog>(); using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("FindWarrantBetweenDates", connection)) { try { command.Connection = connection; command.Transaction = tran; command.Parameters.Add(database.CreateParameter("pBegin", begin)); command.Parameters.Add(database.CreateParameter("pEnd", end)); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { IVozacRepository vozrepo = new VozacRepository(); IVoziloRepository vozilorepo = new VoziloRepository(); Vozac tempvoz = vozrepo.FindById(reader.GetInt32(1)); Vozilo tempvozilo = vozilorepo.FindById(reader.GetInt32(2)); temp = new PutniNalog { IDPutniNalog = reader.GetInt32(0), Vozac = tempvoz, Vozilo = tempvozilo, StartGrad = reader.GetString(3), StopGrad = reader.GetString(4), StartDate = reader.GetDateTime(5), StopDate = reader.GetDateTime(6) }; listPutniNalog.Add(temp); } } tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); throw ex; } catch (Exception ex2) { throw ex2; } } } } return(listPutniNalog.AsEnumerable()); }
public Ruta FindById(int id) { Ruta temp = null; using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("FindRoute", connection)) { try { command.Connection = connection; command.Transaction = tran; command.Parameters.Add(database.CreateParameter("pID", id)); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { IPutniNalogRepository putnirepo = new PutniNalogRepository(); PutniNalog putninalog = putnirepo.FindById(reader.GetInt32(1)); temp = new Ruta { IDRuta = reader.GetInt32(0), PutniNalog = putninalog, Vrijeme = reader.GetDateTime(2), ACoordX = reader.GetInt32(3), ACoordY = reader.GetInt32(4), BCoordX = reader.GetInt32(5), BCoordY = reader.GetInt32(6), PrijedeniKM = reader.GetDouble(7), ProsjecniKMH = reader.GetDouble(8), PotrosenoGorivoLitre = reader.GetDouble(9) }; } } tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch (Exception ex2) { throw; } } } } return(temp); }
public IEnumerable <Ruta> FindAll() { List <Ruta> list = new List <Ruta>(); using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("SelectAllRoutes", connection)) { try { command.Connection = connection; command.Transaction = tran; using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { IPutniNalogRepository putnirepo = new PutniNalogRepository(); PutniNalog putninalog = putnirepo.FindById(reader.GetInt32(1)); Ruta temp = new Ruta { IDRuta = reader.GetInt32(0), PutniNalog = putninalog, Vrijeme = reader.GetDateTime(2), ACoordX = reader.GetInt32(3), ACoordY = reader.GetInt32(4), BCoordX = reader.GetInt32(5), BCoordY = reader.GetInt32(6), PrijedeniKM = reader.GetDouble(7), ProsjecniKMH = reader.GetDouble(8), PotrosenoGorivoLitre = reader.GetDouble(9) }; list.Add(temp); } } tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch (Exception ex2) { throw; } } } } return(list.AsEnumerable()); }
public IEnumerable <PutniNalog> FindAll() { List <PutniNalog> list = new List <PutniNalog>(); using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("SelectAllWarrants", connection)) { try { command.Connection = connection; command.Transaction = tran; using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { IVozacRepository vozrepo = new VozacRepository(); IVoziloRepository vozilorepo = new VoziloRepository(); Vozac tempvoz = vozrepo.FindById(reader.GetInt32(1)); Vozilo tempvozilo = vozilorepo.FindById(reader.GetInt32(2)); PutniNalog temp = new PutniNalog { IDPutniNalog = reader.GetInt32(0), Vozac = tempvoz, Vozilo = tempvozilo, StartGrad = reader.GetString(3), StopGrad = reader.GetString(4), StartDate = reader.GetDateTime(5), StopDate = reader.GetDateTime(6) }; list.Add(temp); } } tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch (Exception ex2) { throw; } } } } return(list.AsEnumerable()); }
public PutniNalog FindById(int id) { PutniNalog temp = null; using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("FindWarrantByID", connection)) { try { command.Connection = connection; command.Transaction = tran; command.Parameters.Add(database.CreateParameter("pID", id)); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { IVozacRepository vozrepo = new VozacRepository(); IVoziloRepository vozilorepo = new VoziloRepository(); Vozac tempvoz = vozrepo.FindById(reader.GetInt32(1)); Vozilo tempvozilo = vozilorepo.FindById(reader.GetInt32(2)); temp = new PutniNalog { IDPutniNalog = reader.GetInt32(0), Vozac = tempvoz, Vozilo = tempvozilo, StartGrad = reader.GetString(3), StopGrad = reader.GetString(4), StartDate = reader.GetDateTime(5), StopDate = reader.GetDateTime(6) }; } } tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch (Exception ex2) { throw; } } } } return(temp); }
private void bntPotvrdi_Click(object sender, EventArgs e) { if (cbStatusNaloga.SelectedValue.ToString() == "0") { lblNalogID.Text = $"Obavezno ispuni status naloga!"; lblNalogID.ForeColor = Color.Red; lblNalogID.Font = new Font(Font, FontStyle.Bold); return; } DateTime dtO = String.IsNullOrWhiteSpace(dtpOtvaranje.Text) ? new DateTime(): DateTime.Parse(dtpOtvaranje.Text); DateTime dtZ = String.IsNullOrWhiteSpace(dtpZatvaranje.Text) ? new DateTime() : DateTime.Parse(dtpZatvaranje.Text); if (dtZ == DateTime.Parse(emptyDate) || dtZ > dtO) { PutniNalog putni = new PutniNalog( _IDNalog.HasValue ? _IDNalog.Value : 0, dtO, dtZ, new Vozac(int.Parse(cbVozac.SelectedValue.ToString())), new Vozilo(int.Parse(cbVozilo.SelectedValue.ToString())), new Grad(int.Parse(cbMjestoStart.SelectedValue.ToString())), new Grad(int.Parse(cbMjestoCilj.SelectedValue.ToString())), (PutniNalogStatus)int.Parse(cbStatusNaloga.SelectedValue.ToString()) ); int result = 0; try { result = SqlHandler.AddEditPN(putni); } catch (Exception ex) { MessageBox.Show(ex.Message); this.DialogResult = DialogResult.None; } if (result == 0) { this.DialogResult = DialogResult.None; MessageBox.Show("Nekaj ne valja nismo uspjeli upisati niš u bazu"); } else { this.Close(); pn.RefreshPN(); } } else { MessageBox.Show("Ne može brate vrijeme zatvaranja biti manje od otvaranja!!"); return; } }
// GET: PutniNalog/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PutniNalog putniNalog = null; //OVDJE IDE FIND if (putniNalog == null) { return(HttpNotFound()); } return(View(putniNalog)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } PutniNalog = repo.FindAll().FirstOrDefault(m => m.IDPutniNalog == id); if (PutniNalog == null) { return(NotFound()); } return(Page()); }
public IEnumerable <KupnjaGoriva> FindAll() { List <KupnjaGoriva> list = new List <KupnjaGoriva>(); using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("SelectAllFuelBuying", connection)) { try { command.Connection = connection; command.Transaction = tran; using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { IPutniNalogRepository putrepo = new PutniNalogRepository(); PutniNalog putniNalog = putrepo.FindById(reader.GetInt32(1)); KupnjaGoriva temp = new KupnjaGoriva { IDKupnjaGoriva = reader.GetInt32(0), Lokacija = reader.GetString(2), GorivoPoLitri = reader.GetFloat(3), CijenaPoLitri = reader.GetFloat(4), PutniNalog = putniNalog }; list.Add(temp); } } tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch (Exception ex2) { throw; } } } } return(list.AsEnumerable()); }
public KupnjaGoriva FindById(int id) { KupnjaGoriva temp = null; using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("FindFuelBuyingByID", connection)) { try { command.Connection = connection; command.Transaction = tran; command.Parameters.Add(database.CreateParameter("pID", id)); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { IPutniNalogRepository putrepo = new PutniNalogRepository(); PutniNalog putniNalog = putrepo.FindById(reader.GetInt32(1)); temp = new KupnjaGoriva { IDKupnjaGoriva = reader.GetInt32(0), Lokacija = reader.GetString(2), GorivoPoLitri = reader.GetFloat(3), CijenaPoLitri = reader.GetFloat(4), PutniNalog = putniNalog }; } } tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch (Exception ex2) { throw; } } } } return(temp); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } PutniNalog = repo.FindAll().FirstOrDefault(m => m.IDPutniNalog == id); /*await _context.Vozaci.FirstOrDefaultAsync(m => m.IDVozac == id);*/ if (PutniNalog == null) { return(NotFound()); } return(Page()); }
public void insetPutniNalog(PutniNalog p) { using (SqlConnection con = new SqlConnection(cs)) { con.Open(); using (SqlCommand comm = con.CreateCommand()) { comm.CommandType = System.Data.CommandType.StoredProcedure; comm.CommandText = "INSERT_PUTNI_NALOG"; comm.Parameters.AddWithValue("@VozacID", p.VozacID); comm.Parameters.AddWithValue("@VoziloID", p.VoziloID); comm.Parameters.AddWithValue("@VrijemePocetka", p.VrijemePocetka); comm.Parameters.AddWithValue("@VrijemeZavrsetka", p.VrijemeZavrsetka); comm.Parameters.AddWithValue("@OstaliDetalji", p.OstaliDetalji); comm.ExecuteNonQuery(); } } }
public ActionResult Edit(PutniNalogViewModel putniNalog) { if (ModelState.IsValid) { PutniNalog nalog = new PutniNalog { VozacID = putniNalog.VozacID, IDPutniNalog = putniNalog.IDPutniNalog, VoziloID = putniNalog.VoziloID, BrojSati = putniNalog.BrojSati, BrojDnevnica = putniNalog.BrojDnevnica, DatumDolaska = putniNalog.DatumDolaska, DatumOdlaska = putniNalog.DatumOdlaska, IznosDnevnice = putniNalog.IznosDnevnice, Opis = putniNalog.Opis }; putniNalogRepository.Update(nalog); return(RedirectToAction("Index")); } return(View(putniNalog)); }
public void Create(PutniNalog entity) { //WarrantCreate @pVozacID int, @pVoziloID int, @pStartGrad nvarchar(50),@pStopGrad nvarchar(50),@pOcekivaniDani int using (IDbConnection connection = database.CreateOpenConnection()) { IDbTransaction tran = connection.BeginTransaction(); using (IDbCommand command = database.CreateStoredProcCommand("WarrantCreate", connection)) { try { command.Connection = connection; command.Transaction = tran; command.Parameters.Add(database.CreateParameter("@pVozacID", entity.Vozac.IDVozac)); command.Parameters.Add(database.CreateParameter("@pVoziloID", entity.Vozilo.IDVozilo)); command.Parameters.Add(database.CreateParameter("@pStartGrad", entity.StartGrad)); command.Parameters.Add(database.CreateParameter("@pStopGrad", entity.StopGrad)); command.Parameters.Add(database.CreateParameter("@pStartDate", entity.StartDate)); command.Parameters.Add(database.CreateParameter("@pStopDate", entity.StopDate)); command.ExecuteNonQuery(); tran.Commit(); } catch (Exception ex) { try { tran.Rollback(); } catch (Exception ex2) { throw ex2; } } } } }
public ActionResult Create(PutniNalog p) { repo.insetPutniNalog(p); return(RedirectToAction("AllPutniNalog")); }
public ActionResult Edit(PutniNalog p) { repo.updatePutniNalog(p); return(RedirectToAction("AllPutniNalog")); }
internal static int AddEditPN(PutniNalog pn) { using (SqlConnection con = new SqlConnection(cs)) { SqlMessagesSubscription(con); con.Open(); using (SqlCommand cmd = con.CreateCommand()) { SqlTransaction transaction; transaction = con.BeginTransaction("AddEditPN"); cmd.Transaction = transaction; try { cmd.CommandText = nameof(AddEditPN); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(ID_PUTNI_NALOG, SqlDbType.Int); cmd.Parameters[ID_PUTNI_NALOG].Value = pn.IDPutniNalog; if (pn.Otvaranje == DateTime.Parse(emptyDate)) { cmd.Parameters.AddWithValue(OTVARANJE_PN, DBNull.Value); } else { cmd.Parameters.AddWithValue(OTVARANJE_PN, pn.Otvaranje.ToString(dateTimeFormat)); } if (pn.Zatvaranje == DateTime.Parse(emptyDate)) { cmd.Parameters.AddWithValue(ZATVARANJE_PN, DBNull.Value); } else { cmd.Parameters.AddWithValue(ZATVARANJE_PN, pn.Zatvaranje.ToString(dateTimeFormat)); } if (pn.Vozac.IDVozac == 0) { cmd.Parameters.AddWithValue(VOZAC_ID, DBNull.Value); } else { cmd.Parameters.AddWithValue(VOZAC_ID, pn.Vozac.IDVozac); } if (pn.Vozilo.IDVozilo == 0) { cmd.Parameters.AddWithValue(VOZILO_ID, DBNull.Value); } else { cmd.Parameters.AddWithValue(VOZILO_ID, pn.Vozilo.IDVozilo); } if (pn.Start.IDGrad == 0) { cmd.Parameters.AddWithValue(MJESTOSTART_ID, DBNull.Value); } else { cmd.Parameters.AddWithValue(MJESTOSTART_ID, pn.Start.IDGrad); } if (pn.Cilj.IDGrad == 0) { cmd.Parameters.AddWithValue(MJESTOCILJ_ID, DBNull.Value); } else { cmd.Parameters.AddWithValue(MJESTOCILJ_ID, pn.Cilj.IDGrad); } if (pn.NalogStatus == 0) { cmd.Parameters.AddWithValue(STATUS_NALOGA, DBNull.Value); } else { cmd.Parameters.AddWithValue(STATUS_NALOGA, pn.NalogStatus); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } return(cmd.ExecuteNonQuery()); } } }