Advertisement
yepau

VacunasController

Aug 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8.  
  9. namespace ControlVacunasDAL
  10.  
  11. {
  12.  
  13.     public class Vacuna
  14.  
  15.     {
  16.         public int Id { get; set; }
  17.  
  18.         public string Name { get; set; }
  19.  
  20.         public string Administracion { get; set; }
  21.  
  22.         public string Dose { get; set; }
  23.  
  24.  
  25.         public void Save()
  26.  
  27.         {
  28.  
  29.             var connection = new DBConnection().getConnection();
  30.        
  31.             string sql = $"INSERT INTO Mstr_Vacunas (vac_nombre,vac_Dosis, vac_Via_administracion)  VALUES ('{Name}', '{Dose}', '{Administracion}');";
  32.             SqlCommand command;
  33.  
  34.             try
  35.  
  36.             {
  37.                 connection.Open();
  38.                 command = new SqlCommand(sql, connection);
  39.                 command.ExecuteNonQuery();
  40.  
  41.             }
  42.  
  43.             catch (Exception ex)
  44.  
  45.             {
  46.  
  47.                 MessageBox.Show(ex.Message);
  48.  
  49.             }
  50.  
  51.     }
  52.  
  53.         public static List<Vacuna> getAllVacunas()
  54.         {
  55.             var connection = new DBConnection().getConnection();
  56.  
  57.             string sql = $"SELECT * FROM Hist_Historial_Vacunas;";
  58.             SqlCommand command;
  59.             List<Vacuna> allVacunas = new List<Vacuna>();
  60.  
  61.             try
  62.             {
  63.                 connection.Open();
  64.                 command = new SqlCommand(sql, connection);
  65.                 SqlDataReader reader = command.ExecuteReader();
  66.  
  67.                 while (reader.Read())
  68.                 {
  69.                     Vacuna vacuna = new Vacuna();
  70.                     vacuna.Id = Convert.ToInt32(reader.GetValue(0).ToString());
  71.                     vacuna.Name = reader.GetValue(1).ToString();
  72.                     vacuna.Dose = reader.GetValue(2).ToString();
  73.                     vacuna.Administracion = reader.GetValue(3).ToString();
  74.  
  75.                     allVacunas.Add(vacuna);
  76.  
  77.                 }
  78.  
  79.             }
  80.             catch (Exception ex)
  81.             {
  82.                 MessageBox.Show(ex.Message);
  83.             }
  84.  
  85.             return allVacunas;
  86.         }
  87.  
  88.  
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement