public static string add_Promocion(Promocion d) { return "{" + '"' + "IdPromocion" + '"' + ": " + d.IdPromocion.ToString() + ',' + '"' + "IdMoneda" + '"' + ": " + d.IdMoneda.ToString() + ',' + '"' + "Nombre" + '"' + ": " + '"' + d.Nombre + '"' + ',' + '"' + "Descripcion" + '"' + ": " + '"' + d.Descripcion + '"' + ',' + '"' + "Semana" + '"' + ": " + (d.Semana ? "true" : "false") + ',' + '"' + "PrecioUnitario" + '"' + ": " + d.PrecioUnitario.ToString() + ',' + '"' + "FechaInicio" + '"' + ": " + '"' + Utils.dateToJson(d.FechaInicio) + '"' + ',' + '"' + "FechaFin" + '"' + ": " + '"' + Utils.dateToJson(d.FechaFin) + '"' + ',' + '"' + "Imagen" + '"' + ": " + '"' + d.Imagen + '"' + "}"; }
public ResponseBD add_Promocion(Promocion p) { try { ResponseBD response = new ResponseBD(); string ConnString = ConfigurationManager.ConnectionStrings["barabaresConnectionString"].ConnectionString; using (SqlConnection SqlConn = new SqlConnection(ConnString)) { try { SqlConn.Open(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); response.Flujo = Constantes.FALLA; response.Mensaje = "Error al abrir la conexión a BD"; return response; } SqlCommand sqlCmd = new SqlCommand("PROMOCION_INSERT", SqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter flujo = new SqlParameter("@opsFlujo", SqlDbType.VarChar) { Direction = ParameterDirection.Output, Size = 10 }; SqlParameter mensaje = new SqlParameter("@opsMsj", SqlDbType.VarChar) { Direction = ParameterDirection.Output, Size = 100 }; sqlCmd.Parameters.Add("@ipsNombre", SqlDbType.VarChar).Value = p.Nombre; sqlCmd.Parameters.Add("@ipsDescripcion", SqlDbType.VarChar).Value = p.Descripcion; sqlCmd.Parameters.Add("@ipdFechaInicio", SqlDbType.DateTime).Value = p.FechaInicio; sqlCmd.Parameters.Add("@ipdFechaFin", SqlDbType.DateTime).Value = p.FechaFin; sqlCmd.Parameters.Add("@ipbSemana", SqlDbType.Bit).Value = p.Semana; sqlCmd.Parameters.Add("@ipnPrecioUnitario", SqlDbType.Real).Value = p.PrecioUnitario; sqlCmd.Parameters.Add("@ipsImagen", SqlDbType.VarChar).Value = p.Imagen; sqlCmd.Parameters.Add("@ipnIdMoneda", SqlDbType.Int).Value = p.IdMoneda; sqlCmd.Parameters.Add(flujo); sqlCmd.Parameters.Add(mensaje); sqlCmd.ExecuteNonQuery(); response.Flujo = flujo.Value.ToString(); response.Mensaje = mensaje.Value.ToString(); SqlConn.Close(); } return response; } catch (Exception ex) { LogBarabares b = new LogBarabares() { Accion = Constantes.LOG_CREAR, Servicio = Constantes.Add_Promocion, Input = "", //TODO Descripcion = ex.ToString(), Clase = (p == null) ? "null" : p.GetType().Name, Aplicacion = Constantes.ENTORNO_SERVICIOS, Estado = Constantes.FALLA, Ip = "", IdUsuario = 1 //TODO: obtener usuario de la sesión }; Utils.add_LogBarabares(b); ResponseBD response = new ResponseBD(); response.Flujo = Constantes.FALLA; response.Mensaje = "Error al abrir la conexión a BD"; return response; } }
public List<Select.PromocionSemana> semana_Promocion() { try { List<Select.PromocionSemana> promociones = new List<Select.PromocionSemana>(); Select.PromocionSemana p; 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 promociones; } SqlCommand sqlCmd = new SqlCommand("PROMOCION_SEMANA", SqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; 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.semana_promocion_parse(rows[i]); promociones.Add(p); } return promociones; } catch (Exception ex) { Promocion d = new Promocion(); LogBarabares b = new LogBarabares() { Accion = Constantes.LOG_LISTAR, Servicio = Constantes.Semana_Promocion, Input = "", 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 List<Select.PromocionSemana>(); } }
public static Promocion promocion_parse(DataRow r) { Promocion p = new Promocion(); 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.Observaciones = r["observaciones"].ToString(); return p; }