public static bool GuardarDatos <T>(T dato) where T : class { int derivada = 0; string aux = ""; if (dato is DerivadaUno) { DerivadaUno auxRevision = (DerivadaUno)Convert.ChangeType(dato, typeof(DerivadaUno)); int cont = 0; int info = 0; foreach (char d in auxRevision.MostrarVersion()) { cont++; if (cont == 3) { info = int.Parse(d.ToString()); } } derivada = 1; aux = string.Format("Insert into Datos(version,subversion,revision,derivada) Values({0},{1},{2},{3})", _version, _subversion, info, derivada); } else { derivada = 2; aux = string.Format("Insert into Datos(version,subversion,derivada) Values({0},{1},{2})", _version, _subversion, derivada); } try { _command.Connection = _connection; _command.CommandType = CommandType.Text; _command.CommandText = aux; _connection.Open(); _command.ExecuteNonQuery(); _connection.Close(); return(true); } catch (Exception e) { Test t = new Test(); t.richTest.AppendText(e.Message); t.richTest.AppendText(e.StackTrace); t.richTest.AppendText(e.InnerException.Message); t.ShowDialog(); return(false); } }
private void btnPunto1_Click(object sender, EventArgs e) { Base derUno1 = new DerivadaUno(10, 11, 12); //103 DerivadaUno derUno2 = new DerivadaUno(1, 2, 3); //103 Base derDos1 = new DerivadaDos(); //2 listaElementos.Add(derUno1); listaElementos.Add(derUno2); listaElementos.Add(derDos1); StringBuilder sb = new StringBuilder(); foreach (Base b in listaElementos) { sb.AppendLine(b.VersionFull); } CargarRichTextBox(sb.ToString()); }
public static Queue <T> LeerDatos <T>() where T : Base { Queue <Base> myQ = new Queue <Base>(); try { _command.Connection = _connection; _command.CommandType = CommandType.Text; _command.CommandText = "SELECT * FROM Datos"; _connection.Open(); SqlDataReader sr = _command.ExecuteReader(); while (sr.Read()) { if (sr["derivada"].ToString() == "1") { DerivadaUno b = new DerivadaUno(int.Parse(sr[0].ToString()), int.Parse(sr[1].ToString()), int.Parse(sr[2].ToString())); myQ.Enqueue(b); } else { Base b = new DerivadaDos(int.Parse(sr[0].ToString()), int.Parse(sr[1].ToString())); myQ.Enqueue(b); } } sr.Close(); _connection.Close(); } catch (Exception e) { Test lectura = new Test(); lectura.richTest.AppendText(e.Message); lectura.ShowDialog(); } Queue <T> retorno = (Queue <T>)Convert.ChangeType(myQ, typeof(Queue <T>)); return(retorno); }