public Select.Promocion_Sistema selectById_Sistema_Promocion(int id) { try { Select.Promocion_Sistema p = new Select.Promocion_Sistema(); DataTable dt = new DataTable(); SqlDataAdapter sda = new SqlDataAdapter(); string ConnString = ConfigurationManager.ConnectionStrings["barabaresConnectionString"].ConnectionString; using (SqlConnection SqlConn = new SqlConnection(ConnString)) { try { SqlConn.Open(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return p; } SqlCommand sqlCmd = new SqlCommand("PROMOCION_SELECT_BY_ID_SISTEMA", SqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.Add("@ipnIdPromocion", SqlDbType.Int).Value = id; sqlCmd.Parameters.Add("@ipsAccion", SqlDbType.VarChar).Value = Constantes.LOG_LISTAR; sqlCmd.Parameters.Add("@ipsClase", SqlDbType.VarChar).Value = p.GetType().Name; sqlCmd.Parameters.Add("@ipnIdUsuarioLog", SqlDbType.Int).Value = 1; sda.SelectCommand = sqlCmd; sda.Fill(dt); SqlConn.Close(); sqlCmd.Dispose(); sda.Dispose(); } DataRow[] rows = dt.Select(); for (int i = 0; i < rows.Length; i++) { p = Utils.promocion_sistema_parse(rows[i]); } return p; } catch (Exception ex) { Select.Promocion d = new Select.Promocion(); LogBarabares b = new LogBarabares() { Accion = Constantes.LOG_LISTAR, Servicio = Constantes.SelectById_Sistema_Promocion, Input = JsonSerializer.selectById(id), Descripcion = ex.ToString(), Clase = d.GetType().Name, Aplicacion = Constantes.ENTORNO_SERVICIOS, Estado = Constantes.FALLA, Ip = "", IdUsuario = 1 //TODO: obtener usuario de la sesión }; Utils.add_LogBarabares(b); return new Select.Promocion_Sistema(); } }
public static Select.Promocion_Sistema promocion_sistema_parse(DataRow r) { Select.Promocion_Sistema p = new Select.Promocion_Sistema(); p.IdPromocion = Int32.Parse(r["idPromocion"].ToString()); p.Nombre = r["nombre"].ToString(); p.Descripcion = r["descripcion"].ToString(); p.FechaInicio = DateTime.ParseExact(r["fechaInicio"].ToString(), "M/d/yyyy h:mm:ss ttt", null); p.FechaFin = DateTime.ParseExact(r["fechaFin"].ToString(), "M/d/yyyy h:mm:ss ttt", null); p.Imagen = r["imagen"].ToString(); p.PrecioUnitario = Double.Parse(r["precioUnitario"].ToString()); p.Semana = Boolean.Parse(r["semana"].ToString()); p.Moneda = r["moneda"].ToString(); p.Observaciones = r["observaciones"].ToString(); return p; }