public String modificarOfertas(DataOfertas doo) { string msg = ""; SqlCommand cmd = new SqlCommand("USP_ACTUALIZAR_OFERTA", cn.getCn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@id", SqlDbType.Int).Value = doo.Id; cmd.Parameters.Add("@oferta", SqlDbType.VarChar).Value = doo.Oferta; cmd.Parameters.Add("@descripcion", SqlDbType.VarChar).Value = doo.Descripcion; cmd.Parameters.Add("@fecha_inicio", SqlDbType.DateTime).Value = doo.Fecha_inicio; cmd.Parameters.Add("@fecha_fin", SqlDbType.DateTime).Value = doo.Fecha_fin; cmd.Parameters.Add("@producto", SqlDbType.Int).Value = doo.Producto; cmd.Parameters.Add("@precioactual", SqlDbType.Float).Value = doo.PrecioActual; cmd.Parameters.Add("@preciooferta", SqlDbType.Float).Value = doo.PrecioOferta; cn.getCn.Open(); try { msg = cmd.ExecuteNonQuery().ToString() + " Oferta actualizada"; } catch (Exception ex) { msg = ex.Message; } finally { cn.getCn.Close(); } return msg; }
public String eliminaOferta(DataOfertas doo) { string msg = ""; SqlCommand cmd = new SqlCommand("USP_ELIMINAR_OFERTA", cn.getCn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@id", SqlDbType.Int).Value = doo.Id; cn.getCn.Open(); try { msg = cmd.ExecuteNonQuery().ToString() + " Oferta eliminada"; } catch (Exception ex) { msg = ex.Message; } finally { cn.getCn.Close(); } return msg; }
protected void btnGrabar_Click(object sender, EventArgs e) { try { if (hdfCodigoAlerta.Value == null || hdfCodigoAlerta.Value.ToString().Equals(string.Empty)) { DataOfertas doo = new DataOfertas(); doo.Oferta = txtOferta.Text; doo.Descripcion = txtDescripcion.Text; doo.Fecha_inicio = DateTime.Parse(txtFechaInicio.Text); doo.Fecha_fin = DateTime.Parse(txtFechaFin.Text); doo.Cliente = txtCliente.Text; doo.Producto = int.Parse(cboProducto.SelectedValue.ToString()); doo.PrecioActual = float.Parse(lblPrecioActual.Text); doo.PrecioOferta = float.Parse(txtPrecioNuevo.Text); string msg = o.registraOfertas(doo); lblMensaje.Text = msg; GridView1.DataSource = o.listarOfertas(Context.User.Identity.Name); GridView1.DataBind(); desactivarCampos(); } else { DataOfertas doo = new DataOfertas(); doo.Id = int.Parse(hdfCodigoAlerta.Value); doo.Oferta = txtOferta.Text; doo.Descripcion = txtDescripcion.Text; doo.Fecha_inicio = DateTime.Parse(txtFechaInicio.Text); doo.Fecha_fin = DateTime.Parse(txtFechaFin.Text); doo.Producto = int.Parse(cboProducto.SelectedValue.ToString()); doo.PrecioActual = float.Parse(lblPrecioActual.Text); doo.PrecioOferta = float.Parse(txtPrecioNuevo.Text); string msg = o.modificarOfertas(doo); ; lblMensaje.Text = msg; GridView1.DataSource = o.listarOfertas(Context.User.Identity.Name); GridView1.DataBind(); hdfCodigoAlerta.Value = null; desactivarCampos(); } } catch (Exception ex) { lblMensaje.Text = ex.Message; } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { DataOfertas doo = new DataOfertas(); doo.Id = int.Parse(hdfCodigoAlerta.Value); string msg = o.eliminaOferta(doo); lblMensaje.Text = msg; GridView1.DataSource = o.listarOfertas(Context.User.Identity.Name); GridView1.DataBind(); limpiarCampos(); desactivarCampos(); } catch (Exception) { lblMensaje.Text = "Porfavor seleccione un registro de la tabla."; } }