Esempio n. 1
0
    // Obtener lista de cuentas de cobro desde la base de datos
    protected void grvListaCuentaCobro_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int         index = int.Parse(e.CommandArgument.ToString());
        GridViewRow row   = grvListaCuentaCobro.Rows[(index)];

        int    cueCob_Id     = int.Parse(row.Cells[1].Text);
        string cueCob_MesNum = row.Cells[2].Text;
        string cueCob_Mes    = row.Cells[3].Text;
        string cueCob_Anio   = row.Cells[4].Text;
        string cueCob_Gen    = row.Cells[5].Text;
        string cueCob_Total  = row.Cells[6].Text;

        //
        DataTable dt = new DataTable();

        dt.Columns.AddRange(new DataColumn[6] {
            new DataColumn("Cuenta de cobro", typeof(int)),
            new DataColumn("Mes", typeof(string)),
            new DataColumn("Mes Nombre", typeof(string)),
            new DataColumn("Año", typeof(string)),
            new DataColumn("Fecha de Generación", typeof(string)),
            new DataColumn("Total", typeof(string))
        });

        dt.Rows.Add(cueCob_Id, cueCob_MesNum, cueCob_Mes, cueCob_Anio, cueCob_Gen, cueCob_Total);

        Session["mesCuentaCobroNum"] = cueCob_MesNum;
        Session["mesCuentaCobro"]    = cueCob_Mes;
        Session["anioCuentaCobro"]   = cueCob_Anio;
        Session["totalCuentaCobro"]  = cueCob_Total;

        cargarInformacionCuentaCobro(sender, e, cueCob_Id);

        Session["dtNovedadCuentaCobro"] = dt;

        if (e.CommandName == "ConsultarCuentaCobro_Click")
        {
            lblCuentaCobroId.Text          = cueCob_Id.ToString();
            listaCuentasCobroDatos.Visible = true;
            btnExportarExcel.Visible       = true;

            grvCuentaCobro.DataSource = dt;
            grvCuentaCobro.DataBind();
            listaCuentasCobroDatos.Visible = true;
        }
        if (e.CommandName == "ImprimirCuentaCobro_Click")
        {
            Session["cueCob_Id"] = cueCob_Id;
            //ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "window.location.replace('ImprimirCuentaCobro.aspx');", true);


            // Consultar cuenta bancaria realcionada a la cuenta de cobro
            int archivoId = int.Parse(Session["archivoId"].ToString());

            DataTable dtCuentaBancaria = new DataTable();
            dtCuentaBancaria = CuentasBancarias.ConsultarCuentasPorArchivo(archivoId);

            if (dtCuentaBancaria.Rows.Count > 0)
            {
                Response.RedirectToRoute("imprimirCuentaCobro");
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('No hay cuenta bancaria asociada a esta cuenta de cobro');", true);
            }
        }
        if (e.CommandName == "EliminarCuentaCobro_Click")
        {
            int eliMes = int.Parse(DateTime.Now.ToString("MM"));
            int eliDia = int.Parse(DateTime.Now.ToString("dd"));
            if (int.Parse(cueCob_MesNum) >= eliMes && eliDia <= diaLimiteEliminacion)
            {
                int reg = AdministrarNovedades.EliminarCuentasCobro(cueCob_Id, int.Parse(ddlArchivo.SelectedValue));
                if (reg > 0)
                {
                    ddlAnio_SelectedIndexChanged(sender, e);
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('" + "Cuenta de cobro eliminada" + "');", true);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('" + "No se puede eliminar la cuenta de cobro ya la fecha limite de eliminación ya caducó" + "');", true);
            }
        }
    }