public bool Guardar(Satelite satelite) { bool retorno = false; try { this.comando.CommandText = String.Format($"INSERT INTO dbo.Satelites(nombre, duracion_orbita, duracion_rotacion) VALUES('{satelite.Nombre}', '{satelite.DuraOrbita}', '{satelite.DuraRotacion}'"); this.conexion.Open(); this.comando.ExecuteNonQuery(); retorno = true; } catch (Exception ex) { retorno = false; throw ex; } finally { if (this.conexion.State == System.Data.ConnectionState.Open) { this.conexion.Close(); } } return(retorno); }
public bool Guardar(Satelite satelite) { bool retorno = false; try { connection.Open(); StringBuilder cadena = new StringBuilder(); cadena.AppendFormat("INSERT INTO Satelites(duraOrbita, duraRotacion, nombre) VALUES({0},{1},'{2}')", satelite.DuraOrbita, satelite.DuraRotacion, satelite.Nombre); SqlCommand comando = new SqlCommand(cadena.ToString(), connection); if (comando.ExecuteNonQuery() == 1) { retorno = true; } } catch (Exception e) { throw new SateliteException(e); } finally { connection.Close(); } return(retorno); }
public void Leer(List <Satelite> datos) { try { connection.Open(); comando.CommandText = $"SELECT * FROM dbo.Satelites"; SqlDataReader oDr = comando.ExecuteReader(); while (oDr.Read()) { string nombre = oDr["nombre"].ToString(); int orbita = int.Parse(oDr["duracion_orbita"].ToString()); int rotacion = int.Parse(oDr["duracion_rotacion"].ToString()); if (nombre != null && orbita >= 1 && rotacion >= 1) { Satelite s = new Satelite(orbita, rotacion, nombre); datos.Add(s); } } } catch (Exception e) { datos = default; throw new Exception(e.Message, e); } finally { connection.Close(); } }
public List <Satelite> Leer() { try { comando.Connection.Open(); List <Satelite> satList = new List <Satelite>(); comando.CommandText = "SELECT * From [dbo].Satelites"; SqlDataReader dr = comando.ExecuteReader(); while (dr.Read()) { int.TryParse(dr["duracion_orbita"].ToString(), out int orbita); int.TryParse(dr["duracion_rotacion"].ToString(), out int rota); Satelite satelite = new Satelite(orbita, rota, dr["nombre"].ToString()); satList.Add(satelite); } dr.Close(); return(satList); } catch (Exception e) { throw e; } finally { conexion.Close(); } }
public List <Satelite> Leer() { List <Satelite> sateliteListAux = new List <Satelite>(); try { comando.CommandText = String.Format("SELECT * from Satelites"); conexion.Open(); SqlDataReader oDr = comando.ExecuteReader(); while (oDr.Read()) { Satelite sat = new Satelite(); sat.Nombre = oDr["nombre"].ToString(); sat.DuraOrbita = (int)oDr["duracion_orbita"]; sat.DuraRotacion = (int)oDr["duracion_rotacion"]; sateliteListAux.Add(sat); } } catch (Exception e) { throw new Exception("Error al leer de la base de datos", e); } finally { conexion.Close(); } return(sateliteListAux); }
public static bool guardarXML(this Satelite sat) { string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (sat != null) { bool append = File.Exists(Path.Combine(desktop, "planetas.xml")); StreamWriter sw = new StreamWriter(Path.Combine(desktop, "planetas.xml"), append); XmlSerializer xs = new XmlSerializer(typeof(Satelite)); try { xs.Serialize(sw, sat); return(true); } catch (Exception e) { throw new Exception(e.Message, e); } finally { sw.Close(); } } return(false); }
static bool GuardarXML(this Satelite sat) { try { XmlSerializer ser = new XmlSerializer(typeof(Satelite)); StreamWriter sw = new StreamWriter("satelites.xml"); ser.Serialize(sw, sat); return(true); } catch (Exception e) { return(false); } }
public static bool GuardarXml(this Satelite sat) { try { XmlSerializer serializer = new XmlSerializer(typeof(Satelite)); TextWriter writer = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\GuardarXml.xml"); serializer.Serialize(writer, sat); writer.Close(); return(true); } catch (Exception e) { throw e; } }
public static bool GuardarXML(this Satelite sat) { try { XmlSerializer s = new XmlSerializer(typeof(Satelite)); using (XmlTextWriter xw = new XmlTextWriter("satelites.xml", Encoding.UTF8)) { xw.Formatting = Formatting.Indented; s.Serialize(xw, sat); } } catch (Exception e) { throw new Exception("Error al serializar archivo .xml", e); } return(true); }
public bool Guardar(Satelite satelite) { try { comando.Connection.Open(); comando.CommandText = "INSERT INTO dbo.Satelites (duracion_orbita, duracion_rotacion, nombre)" + " VALUES('" + satelite.DuraOrbita + "','" + satelite.DuraRotacion + "','" + satelite.Nombre + "')"; comando.ExecuteNonQuery(); return(true); } catch (Exception e) { throw e; } finally { conexion.Close(); } }
public static bool Guardar(Satelite satelite) { try { SqlConnection conexion = new SqlConnection(Entidades.Properties.Settings.Default.Conexion); SqlCommand comando = new SqlCommand(); comando.Connection = conexion; comando.CommandType = System.Data.CommandType.Text; comando.CommandText = "INSERT INTO [planetario].dbo.satelites(nombre,duraOrbita,duracionRotacion) VALUES('" + satelite.Nombre + "', '" + satelite.DuraOrbita + "', '" + satelite.DuraRotacion + "')"; comando.ExecuteNonQuery(); conexion.Close(); return(true); } catch (Exception e) { throw e; } }
public bool Guardar(Satelite satelite) { try { comando.CommandText = String.Format("INSERT INTO Satelites (nombre, duracion_orbita,duracion_rotacion) VALUES ('{0}','{1}', '{2}')", satelite.Nombre, satelite.DuraOrbita, satelite.DuraRotacion); conexion.Open(); comando.ExecuteNonQuery(); return(true); } catch (Exception e) { throw new Exception("Error al guardar en la base de datos", e); } finally { conexion.Close(); } }
public static bool GuardarXML(this Satelite sat) { string pathEscritorio = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\planeta.xml"; try { XmlSerializer serializer = new XmlSerializer(typeof(Satelite)); FileStream fStream = File.Open(pathEscritorio, FileMode.Create); serializer.Serialize(fStream, sat); fStream.Close(); return(true); } catch (Exception) { return(false); } }
public void Guardar(Satelite satelite) { if (!(satelite is null)) { try { connection.Open(); comando.CommandText = String.Format($"INSERT INTO dbo.Satelites(nombre,duracion_orbita,duracion_rotacion) VALUES('{satelite.Nombre}', {satelite.DuraOrbita}, {satelite.DuraRotacion})"); comando.ExecuteNonQuery(); } catch (Exception e) { throw new Exception(e.Message, e); } finally { connection.Close(); } } }
public static bool GuardarXML(this Satelite sat) { if (!(sat is null)) { try { XmlTextWriter writer; XmlSerializer ser; writer = new XmlTextWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/satelites.xml", Encoding.ASCII); ser = new XmlSerializer(typeof(Satelite)); ser.Serialize(writer, sat); writer.Close(); return(true); } catch (Exception e) { throw e; } } return(false); }
public static bool GuardarXML(this Satelite sat) { if (sat is null) { return(false); } try { string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); XmlTextWriter xmlWriter = new XmlTextWriter(path + "/" + "satelites.xml", Encoding.ASCII); XmlSerializer serializer = new XmlSerializer(typeof(Satelite)); serializer.Serialize(xmlWriter, sat); xmlWriter.Close(); return(true); } catch (Exception e) { throw e; } }
public bool Guardar(Satelite satelite) { //Creando variable de conexion SqlConnection conexion = new SqlConnection(); //Asignando conexion conexion.ConnectionString = String.Format("Data Source={0};Initial Catalog={1};Integrated Security=True", "", ""); //Creo Query string sqlQuery = "INSERT INTO dbo.Satelites (nombre, duracion_orbita, duracion_rotacion) VALUES ('" + satelite.Nombre + "', '" + satelite.DuraOrbita + "', '" + satelite.DuraRotacion + "')"; //Creo Comando para ejecutar Query SqlCommand comando = new SqlCommand(); comando.CommandType = CommandType.Text; comando.CommandText = sqlQuery; comando.Connection = conexion; try { //Abro conexion conexion.Open(); //Ejecuto Query comando.ExecuteNonQuery(); return(true); } catch (Exception) { return(false); } finally { //Cerrando conexion conexion.Close(); conexion.Dispose(); } }
public static bool GuardarXML(this Satelite sat) { return(true); }