private void buttonagrega_Click(object sender, EventArgs e) { bool result; ConductorBE conductorbe = new ConductorBE(); conductorbe.Placa = Convert.ToInt32(textboxplaca.Text); conductorbe.Año = Convert.ToInt16(textboxyear.Text); conductorbe.Color = textboxcolor.Text; conductorbe.Nombres = textboxnombr.Text; conductorbe.Apellidos = textboxapell.Text; conductorbe.DNI = Convert.ToInt32(textboxcedul.Text); conductorbe.Edad = Convert.ToInt16(textboxage.Text); conductorbe.Direccion = textdirec.Text; conductorbe.Provincia = textboxprovincia.Text; ConductorController controler = new ConductorController(); if (result = controler.AgregaConductor(conductorbe)) { MessageBox.Show("Conductor Almacenado con Exito"); } else { MessageBox.Show("La Insercion ha Fallado"); } }
//metodos para editar un conductor------------------------------------------------- public static List<ConductorBE> Buscar(string pNombre, string pApellido) { List<ConductorBE> resultadolista = new List<ConductorBE>(); ConductorBE vvv = new ConductorBE(); Conexion myConnection = new Conexion(); SqlConnection conexion = myConnection.CreateConnection(); SqlCommand comando = new SqlCommand(String.Format("SELECT PLACA, AñO, COLOR, NOMBRES, APELLIDOS,DNI, EDAD, DIRECCION, PROVINCIA FROM CONDUCTOR where NOMBRES ='{0}' or APELLIDOS='{1}'", pNombre,pApellido), conexion); SqlDataReader cconductor; conexion.Open(); cconductor = comando.ExecuteReader(); while (cconductor.Read()) { ConductorBE pConductor = new ConductorBE(); pConductor.Placa = cconductor.GetString(0); pConductor.Año = cconductor.GetString(1); pConductor.Color = cconductor.GetString(2); pConductor.Nombres=cconductor.GetString(3); pConductor.Apellidos = cconductor.GetString(4); pConductor.DNI = cconductor.GetString(5); pConductor.Edad = cconductor.GetString(6); pConductor.Direccion = cconductor.GetString(7); pConductor.Provincia = cconductor.GetString(8); resultadolista.Add(pConductor); } conexion.Close(); return resultadolista; }
public static ConductorBE ObtenerConductor(int pPlaca) { ConductorBE pConductor = new ConductorBE(); Conexion myConnection = new Conexion(); SqlConnection conexion = myConnection.CreateConnection(); SqlCommand comando = new SqlCommand(String.Format("SELECT PLACA, AñO, COLOR, NOMBRES,APELLIDOS, DNI, EDAD, DIRECCION, PROVINCIA FROM CONDUCTOR where PLACA ='{0}'", pPlaca), conexion); SqlDataReader cconductor; conexion.Open(); cconductor = comando.ExecuteReader(); while (cconductor.Read()) { pConductor.Placa = cconductor.GetString(0); pConductor.Año = cconductor.GetString(1); pConductor.Color = cconductor.GetString(2); pConductor.Nombres = cconductor.GetString(3); pConductor.Apellidos = cconductor.GetString(4); pConductor.DNI = cconductor.GetString(5); pConductor.Edad = cconductor.GetString(6); pConductor.Direccion = cconductor.GetString(7); pConductor.Provincia = cconductor.GetString(8); } conexion.Close(); return pConductor; }
public bool AgregaConductor(ConductorBE ConductorBk) { bool result = false; try { Conexion myConnection = new Conexion(); SqlConnection conexion = myConnection.CreateConnection(); SqlCommand comando = myConnection.CreateCommand(conexion); comando.CommandText = "REGISTRAR_CONDUCTOR"; comando.CommandType = CommandType.StoredProcedure; comando.Parameters.AddWithValue("@PLACA", ConductorBk.Placa); comando.Parameters.AddWithValue("@AñO", ConductorBk.Año); comando.Parameters.AddWithValue("@COLOR", ConductorBk.Color); comando.Parameters.AddWithValue("@NOMBRES", ConductorBk.Nombres); comando.Parameters.AddWithValue("@APELLIDOS", ConductorBk.Apellidos); comando.Parameters.AddWithValue("@DNI", ConductorBk.DNI); comando.Parameters.AddWithValue("@EDAD", ConductorBk.Edad); comando.Parameters.AddWithValue("@DIRECCION", ConductorBk.Direccion); comando.Parameters.AddWithValue("@PROVINCIA", ConductorBk.Provincia); conexion.Open(); comando.ExecuteNonQuery(); conexion.Close(); result = true; } catch (SqlException e) { //insert error in a log result = false; } return result; }
private void buttonacept_Click(object sender, EventArgs e) { { if (dgvBuscar.SelectedRows.Count == 1) { int id = Convert.ToInt32(dgvBuscar.CurrentRow.Cells[0].Value); ConductorSeleccionado = ConductorController.ObtenerConductor(id); this.Close(); } else MessageBox.Show("debe de seleccionar una fila"); } }
public static int Actualizar(ConductorBE mConductor) { int retorno = 0; Conexion myConnection = new Conexion(); SqlConnection conexion = myConnection.CreateConnection(); SqlCommand comando = new SqlCommand(string.Format("UPDATE CONDUCTOR set AÑO='{0}', COLOR='{1}', NOMBRES='{2}', APELLIDOS='{3}', DNI='{4}', EDAD='{5}', DIRECCION='{6}',PROVINCIA='{7}' where PLACA={8}", mConductor.Año, mConductor.Color, mConductor.Nombres, mConductor.Apellidos, mConductor.DNI,mConductor.Edad,mConductor.Direccion,mConductor.Provincia,mConductor.Placa), conexion); conexion.Open(); retorno = comando.ExecuteNonQuery(); conexion.Close(); return retorno; }
private void button1_Click(object sender, EventArgs e) { bool result; ConductorBE conductorbe = new ConductorBE(); conductorbe.DNI = textBoxelim.Text; ConductorController controler = new ConductorController(); if (result = controler.EliminaConductor(conductorbe)) { MessageBox.Show("Conductor Eliminado con Exito"); } else { MessageBox.Show("Revise que el numero de cedula sea el correcto"); } }
public List<ConductorBE> Agregaconduct() { ConductorBE conductorBE; List<ConductorBE> listaResult = new List<ConductorBE>(); Conexion myConnection = new Conexion(); SqlConnection conexion = myConnection.CreateConnection(); SqlCommand comando = myConnection.CreateCommand(conexion); SqlDataReader cconduct; comando.CommandText = "REGISTRAR_CONDUCTOR"; comando.CommandType = CommandType.StoredProcedure; conexion.Open(); cconduct = comando.ExecuteReader(); while (cconduct.Read()) { conductorBE = new ConductorBE(); conductorBE.Placa = Convert.ToInt32(cconduct["PLACA"]); conductorBE.Año = Convert.ToInt16(cconduct["AñO"]); conductorBE.Color = cconduct["COLOR"].ToString(); conductorBE.Nombres = cconduct["NOMBRES"].ToString(); conductorBE.Apellidos = cconduct["APELLIDOS"].ToString(); conductorBE.DNI = Convert.ToInt16(cconduct["DNI"]); conductorBE.Edad = Convert.ToInt16(cconduct["EDAD"]); conductorBE.Direccion = cconduct["DIRECCION"].ToString(); conductorBE.Provincia = cconduct["PROVINCIA"].ToString(); listaResult.Add(conductorBE); } conexion.Close(); return listaResult; }
private void buttonactualizar_Click(object sender, EventArgs e) { ConductorBE pConduct = new ConductorBE(); pConduct.Año = textboxyear.Text.Trim(); pConduct.Color = textboxcolor.Text.Trim(); pConduct.Nombres = textboxnombr.Text.Trim(); pConduct.Apellidos = textboxapell.Text.Trim(); pConduct.DNI = textboxcedul.Text.Trim(); pConduct.Edad = numericUpDown1.Text.Trim(); pConduct.Direccion = textdirec.Text.Trim(); pConduct.Provincia = comboprovin.Text.Trim(); pConduct.Placa = conductorActual.Placa; if (ConductorController.Actualizar(pConduct) > 0) { MessageBox.Show("Los datos del conductor se actualizaron", "Datos Actualizados", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("No se pudo actualizar", "Error al Actualizar", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
//metodos para eliminar un conductor--------------------------------------------------- public bool EliminaConductor(ConductorBE ConductorElimina) { bool result = false; try { Conexion myConnection = new Conexion(); SqlConnection conexion = myConnection.CreateConnection(); SqlCommand comando = myConnection.CreateCommand(conexion); comando.CommandText = "BORRAR_CONDUCTOR"; comando.CommandType = CommandType.StoredProcedure; comando.Parameters.AddWithValue("@DNI", ConductorElimina.DNI); conexion.Open(); comando.ExecuteNonQuery(); conexion.Close(); result = true; } catch (SqlException e) { //insert error in a log result = false; } return result; }
public List<ConductorBE> Eliminaconduct() { ConductorBE conductorBE; List<ConductorBE> listaResult = new List<ConductorBE>(); Conexion myConnection = new Conexion(); SqlConnection conexion = myConnection.CreateConnection(); SqlCommand comando = myConnection.CreateCommand(conexion); SqlDataReader cconduct; comando.CommandText = "BORRAR_CONDUCTOR"; comando.CommandType = CommandType.StoredProcedure; conexion.Open(); cconduct = comando.ExecuteReader(); while (cconduct.Read()) { conductorBE = new ConductorBE(); conductorBE.DNI = cconduct["DNI"].ToString(); listaResult.Add(conductorBE); } conexion.Close(); return listaResult; }
private void buttonbuscareditar_Click(object sender, EventArgs e) { BuscarConductores busc = new BuscarConductores(); busc.ShowDialog(); if (busc.ConductorSeleccionado != null) { conductorActual = busc.ConductorSeleccionado; textboxplaca.Text = busc.ConductorSeleccionado.Placa; textboxyear.Text = busc.ConductorSeleccionado.Año; textboxcolor.Text = busc.ConductorSeleccionado.Color; textboxnombr.Text = busc.ConductorSeleccionado.Nombres; textboxapell.Text = busc.ConductorSeleccionado.Apellidos; textboxcedul.Text = busc.ConductorSeleccionado.DNI; numericUpDown1.Text = busc.ConductorSeleccionado.Edad; textdirec.Text = busc.ConductorSeleccionado.Direccion; comboprovin.Text = busc.ConductorSeleccionado.Provincia; } }