public z_conductores getObjectz_conductores(string codigo) { z_conductores myz_conductores = new z_conductores(); CnxBase myBase = new CnxBase(); string reqSQL = "SELECT id_conductor,id_tipo_conductor,id_cuart_vol,tipo_licencia,licencia_vence,codigo_conductor,id_carros,disponible,temporal FROM z_conductores WHERE (codigo_conductor='" + codigo + "')"; try { NpgsqlConnection myConn = myBase.OpenConnection(myBase.cnxString); NpgsqlCommand myCommand = new NpgsqlCommand(reqSQL, myConn); NpgsqlDataReader myReader = myCommand.ExecuteReader(); if (myReader.Read()) { myz_conductores.id_conductor = Convert.ToInt32(myReader[0]); myz_conductores.id_tipo_conductor = Convert.ToInt32(myReader[1]); myz_conductores.id_cuart_vol = Convert.ToInt32(myReader[2]); myz_conductores.tipo_licencia = myReader[3].ToString(); myz_conductores.licencia_vence = Convert.ToDateTime(myReader[4]); myz_conductores.codigo_conductor = myReader[5].ToString(); myz_conductores.id_carros = myReader[6].ToString(); myz_conductores.disponible = Convert.ToBoolean(myReader[7]); myz_conductores.temporal = Convert.ToBoolean(myReader[8]); } myBase.CloseConnection(myConn); } catch (Exception myErr) { throw (new Exception(myErr.ToString() + reqSQL)); } return(myz_conductores); }
/// <summary> /// modify a record /// </summary> public void modifyz_conductores(z_conductores myz_conductores) { CnxBase myBase = new CnxBase(); string reqSQL = "UPDATE z_conductores SET id_conductor=" + myz_conductores.id_conductor + ",id_tipo_conductor=" + myz_conductores.id_tipo_conductor + ",id_cuart_vol=" + myz_conductores.id_cuart_vol + ",tipo_licencia='" + myz_conductores.tipo_licencia + "',licencia_vence='" + myz_conductores.licencia_vence + "',codigo_conductor='" + myz_conductores.codigo_conductor + "',id_carros='" + myz_conductores.id_carros + "',disponible=" + myz_conductores.disponible + ", temporal=" + myz_conductores.temporal + " WHERE (id_conductor=" + myz_conductores.id_conductor + ")"; try { NpgsqlConnection myConn = myBase.OpenConnection(myBase.cnxString); NpgsqlCommand myCommand = new NpgsqlCommand(reqSQL, myConn); myCommand.ExecuteNonQuery(); myBase.CloseConnection(myConn); } catch (Exception myErr) { throw (new Exception(myErr.ToString() + reqSQL)); } }
/// <summary> /// add a record /// </summary> /// <param name="myID"></param> public void addz_conductores(z_conductores myz_conductores) { CnxBase myBase = new CnxBase(); int id = 0; string reqSQL = "INSERT INTO z_conductores (id_tipo_conductor,id_cuart_vol,tipo_licencia,licencia_vence,codigo_conductor,id_carros,disponible, temporal) VALUES (" + myz_conductores.id_tipo_conductor + "," + myz_conductores.id_cuart_vol + ",'" + myz_conductores.tipo_licencia + "','" + myz_conductores.licencia_vence + "','" + myz_conductores.codigo_conductor + "','" + myz_conductores.id_carros + "'," + myz_conductores.disponible + "," + myz_conductores.temporal + ");select currval('z_conductores_id_conductor_seq');"; try { NpgsqlConnection myConn = myBase.OpenConnection(myBase.cnxString); NpgsqlCommand myCommand = new NpgsqlCommand(reqSQL, myConn); id = Convert.ToInt32(myCommand.ExecuteScalar()); myz_conductores.id_conductor = id; myBase.CloseConnection(myConn); } catch (Exception myErr) { throw (new Exception(myErr.ToString() + reqSQL)); } }