public async Task <IActionResult> Edit(int id, [Bind("PradziosData,PabaigosData,DraudimoSuma,Tiekejas,Pobudis,DraudimoNumeris,IdDraudimas,FkPrekeidPreke")] Draudimas draudimas) { if (id != draudimas.IdDraudimas) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(draudimas); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DraudimasExists(draudimas.IdDraudimas)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FkPrekeidPreke"] = new SelectList(_context.Preke, "IdPreke", "IdPreke", draudimas.FkPrekeidPreke); return(View(draudimas)); }
private void deleteDraudimas_Click(object sender, EventArgs e) { try { Draudimas gl = new Draudimas(); gl.draudId = int.Parse(deleteDraudimasDraudId.Text); draudimasRep.DeleteDraud(gl); deleteDraudimasDraudId.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } MessageBox.Show("Deleted succesfully"); getDraudimasDisplay(); getDraudimasTiekDisplay(); }
public void DeleteDraud(Draudimas draudimas) { try { cnn = new MySqlConnection(connectionString); string newSql = ("Delete from draudimas where draudimas.draudId=@id"); cnn.Open(); //open connection. we use the Open method of the cnn variable to open a connection to the database. MySqlCommand cmd = new MySqlCommand(newSql, cnn); //select all from newTestTable cmd.Parameters.AddWithValue("@id", draudimas.draudId); cmd.ExecuteNonQuery(); //execute function cnn.Close(); } catch (Exception exc) { Console.WriteLine(exc); } }
private void addDraudimas_Click(object sender, EventArgs e) { try { Draudimas dr = new Draudimas(); DateTime pradData = DateTime.Parse(addDraudPradData.Text); DateTime pabData = DateTime.Parse(addDraudPabData.Text); dr.draudPradData = pradData.Date; dr.draudPabData = pabData.Date; dr.tiekId = int.Parse(addDraudTiekId.Text); dr.Trans_Id = int.Parse(addDraudTransId.Text); Draudimas insertedDr = draudimasRep.InsertDraudimas(dr); } catch (Exception ex) { MessageBox.Show(ex.Message); } MessageBox.Show("Succesfully inserted"); getDraudimasDisplay(); }
public void UpdateDraudimas(Draudimas draudimas) { try { //setting new SqlConnection, providing connectionString cnn = new MySqlConnection(connectionString); //check if user exist MySqlCommand cmd = new MySqlCommand("Update draudimas SET draudPradData=@draudPradData,draudPabData=@draudPabData,tiekId=@tiekId,Trans_Id=@Trans_Id WHERE draudId=@draudId", cnn);//to check if username exist we have to select all items with username cmd.Parameters.AddWithValue("@draudPradData", draudimas.draudPradData); cmd.Parameters.AddWithValue("@draudPabData", draudimas.draudPabData); cmd.Parameters.AddWithValue("@tiekId", draudimas.tiekId); cmd.Parameters.AddWithValue("@Trans_Id", draudimas.Trans_Id); cmd.Parameters.AddWithValue("@draudId", draudimas.draudId); cnn.Open(); cmd.ExecuteNonQuery(); cnn.Close(); } catch (Exception ex) { Console.WriteLine(ex); } }
public async Task <IActionResult> Create([Bind("PradziosData,PabaigosData,DraudimoSuma,Tiekejas,Pobudis,DraudimoNumeris,FkPrekeidPreke")] Draudimas draudimas) { var last = 0; if (_context.Draudimas.Count() == 0) { draudimas.IdDraudimas = 0; } else { last = _context.Draudimas.Last().IdDraudimas; last++; draudimas.IdDraudimas = last; } if (ModelState.IsValid) { _context.Add(draudimas); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FkPrekeidPreke"] = new SelectList(_context.Preke, "pavadinimas", "pavadinimas", draudimas.FkPrekeidPreke); return(View(draudimas)); }
//REGISTER STUDENT public Draudimas InsertDraudimas(Draudimas draudimas)//provide transportas object when calling this function { try { bool transYra = false; bool draudimoTiekYra = false; //setting new SqlConnection, providing connectionString cnn = new MySqlConnection(connectionString); cnn.Open();//open database //check if transportas exist MySqlCommand cmd = new MySqlCommand("Select * from transportas where Trans_Id=@Trans_Id", cnn); cmd.Parameters.AddWithValue("@Trans_Id", draudimas.Trans_Id); MySqlDataReader dataReader = cmd.ExecuteReader();//sends SQLCommand.CommandText to the SQLCommand.Connection and builds SqlDataReader if ((dataReader.Read() == true)) { transYra = true; Console.WriteLine("Transportas toks yra"); } else { Console.WriteLine("Tokio transporto nera"); return(null); } dataReader.Close();//close data reader when it finishes work //check if draudimoTiekejas exist MySqlCommand cmd1 = new MySqlCommand("Select * from draudimoTiekejai where tiekId=@tiekId", cnn); cmd1.Parameters.AddWithValue("@tiekId", draudimas.tiekId); MySqlDataReader dataReader1 = cmd1.ExecuteReader();//sends SQLCommand.CommandText to the SQLCommand.Connection and builds SqlDataReader if ((dataReader1.Read() == true)) { draudimoTiekYra = true; Console.WriteLine("Transportas toks yra"); } else { Console.WriteLine("Tokio transporto nera"); return(null); } dataReader1.Close(); if (transYra == true && draudimoTiekYra == true) { MySqlCommand cmd2 = new MySqlCommand("Insert into draudimas (draudPradData,draudPabData,tiekId,Trans_Id) VALUES(@draudPradData,@draudPabData,@tiekId,@Trans_Id)", cnn); cmd2.Parameters.AddWithValue("@draudPradData", draudimas.draudPradData); cmd2.Parameters.AddWithValue("@draudPabData", draudimas.draudPabData); cmd2.Parameters.AddWithValue("@tiekId", draudimas.tiekId); cmd2.Parameters.AddWithValue("@Trans_Id", draudimas.Trans_Id); cmd2.ExecuteNonQuery(); } cnn.Close(); } catch (Exception exc) { Console.WriteLine(exc); } return(draudimas);//return }