Exemplo n.º 1
0
    public String modificarSucursales(DataSucursal ds)
    {
        string msg = "";

        SqlCommand cmd = new SqlCommand("USP_ACTUALIZAR_SUCURSAL", cn.getCn);
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.Add("@id", SqlDbType.Int).Value = ds.Id;
        cmd.Parameters.Add("@Sucur", SqlDbType.VarChar).Value = ds.Sucursal;
        cmd.Parameters.Add("@descSucur", SqlDbType.VarChar).Value = ds.Descripcion;
        cmd.Parameters.Add("@telefono", SqlDbType.VarChar).Value = ds.Telefono;
        cmd.Parameters.Add("@idDist", SqlDbType.Char).Value = ds.Distrito;
        cmd.Parameters.Add("@direccion", SqlDbType.VarChar).Value = ds.Direccion;

        cn.getCn.Open();
        try
        {
            msg = cmd.ExecuteNonQuery().ToString() + " Sucursal actualizado";
        }
        catch (Exception ex)
        {
            msg = ex.Message;

        }
        finally
        {
            cn.getCn.Close();
        }
        return msg;
    }
Exemplo n.º 2
0
    public String eliminaSucursales(DataSucursal ds)
    {
        string msg = "";

        SqlCommand cmd = new SqlCommand("USP_ELIMINAR_SUCURSAL", cn.getCn);
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.Add("@id", SqlDbType.Int).Value = ds.Id;

        cn.getCn.Open();
        try
        {
            msg = cmd.ExecuteNonQuery().ToString() + " Sucursal eliminado";
        }
        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))
            {
                DataSucursal ds = new DataSucursal();

                ds.Sucursal = txtSucursal.Text;
                ds.Descripcion = txtDescripcion.Text;
                ds.Telefono = txtTelefono.Text;
                ds.Distrito = cboDistrito.SelectedValue;
                ds.Direccion = txtDireccion.Text;
                ds.Cliente = txtCliente.Text;

                string msg = s.registraSucursales(ds);
                lblMensaje.Text = msg;

                GridView1.DataSource = s.listarSucursales();
                GridView1.DataBind();

                desactivarCampos();
            }
            else
            {
                DataSucursal ds = new DataSucursal();

                ds.Id = int.Parse(hdfCodigoAlerta.Value);
                ds.Sucursal = txtSucursal.Text;
                ds.Descripcion = txtDescripcion.Text;
                ds.Telefono = txtTelefono.Text;
                ds.Distrito = cboDistrito.SelectedValue;
                ds.Direccion = txtDireccion.Text;
                ds.Cliente = txtCliente.Text;

                string msg = s.modificarSucursales(ds);
                lblMensaje.Text = msg;

                GridView1.DataSource = s.listarSucursales();
                GridView1.DataBind();

                hdfCodigoAlerta.Value = null;

                desactivarCampos();
            }
        }
        catch (Exception ex)
        {
            lblMensaje.Text = ex.Message;
        }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            DataSucursal ds = new DataSucursal();

            ds.Id = int.Parse(hdfCodigoAlerta.Value);

            string msg = s.eliminaSucursales(ds);
            lblMensaje.Text = msg;

            GridView1.DataSource = s.listarSucursales();
            GridView1.DataBind();

            limpiarCampos();
            limpiarCombo();
            desactivarCampos();
        }
        catch (Exception)
        {
            lblMensaje.Text = "Porfavor seleccione un registro de la tabla.";
        }
    }