Beispiel #1
0
        public object Listar()
        {
           
            string cnx = db.Database.Connection.ConnectionString;
            con = new SqlConnection(cnx);
            string listar = "select * from Zonas order by DescripCorta asc";
            List<zonas> listper = new List<zonas>();
            try
            {
                SqlCommand comando = new SqlCommand(listar, con);
                con.Open();
                SqlDataReader reader = comando.ExecuteReader();
                while (reader.Read())
                {

                    zonas per = new zonas();
                    per.IdZona = Convert.ToInt32(reader[0].ToString());
                    per.DescripLarga = reader[1].ToString() +"-"+ reader[2].ToString();
                    listper.Add(per);
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            return listper;
        }
Beispiel #2
0
 public zonas BuscarZona(int id)
 {
     zonas zon = new zonas();
     string cnx = db.Database.Connection.ConnectionString;
     con = new SqlConnection(cnx);
     string find = "select*from zonas where IdZona='" + id + "'";
     try
     {
         comando = new SqlCommand(find, con);
         con.Open();
         SqlDataReader reader = comando.ExecuteReader();
         if(reader.Read())
         {
             zon.IdZona = Convert.ToInt32(reader[0].ToString());
             zon.DescripCorta = reader[1].ToString();
             zon.DescripLarga = reader[2].ToString();
             zon.Observacion = reader[3].ToString();
         }
         return zon;
     }
     catch(Exception ex)
     {
         throw ex;
     }
     finally
     {
         con.Close();
     }
 }
Beispiel #3
0
 public void Create(zonas zon)
 {
     string cnx = db.Database.Connection.ConnectionString;
     con = new SqlConnection(cnx);
     try
     {
         comando = new SqlCommand("usp_ZonaInsert", con);
         comando.Parameters.AddWithValue("@DescripCorta", zon.DescripCorta);
         comando.Parameters.AddWithValue("@DescripLarga", zon.DescripLarga);
         comando.Parameters.AddWithValue("@Observacion", zon.Observacion);
         comando.CommandType = System.Data.CommandType.StoredProcedure;
         con.Open();
         comando.ExecuteNonQuery();
     }
     catch(Exception ex)
     {
         throw ex;
     }
     finally
     {
         con.Close();
     }
 }