示例#1
0
    protected void btnGuardar_Click(object sender, EventArgs e)
    {
        string Requ_Numero, Reqd_CodLinea, Reqs_Correlativo, cleanMessage, Reqs_ItemSecuencia;


        int intContador  = 0;
        int intregistros = 0;

        if (GridView1.Rows.Count == 0)
        {
            cleanMessage = "No existe registros";
            ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
        }

        foreach (GridViewRow Fila in GridView1.Rows)
        {
            CheckBox ChkBoxCell = ((CheckBox)Fila.FindControl("chkSelect"));
            if (ChkBoxCell.Checked == true)
            {
                intContador += 1;
            }
        }

        if (intContador == 0)
        {
            cleanMessage = "Debe seleccionar al menos un registro.";
            ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
        }

        Guid g;

        g = Guid.NewGuid();
        string codigos = string.Empty;

        if (FileUpload1.HasFile)
        {
            consultarFile();


            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox ChkBoxCell = ((CheckBox)row.FindControl("chkSelect"));
                if (ChkBoxCell.Checked)
                {
                    intregistros++;
                    Requ_Numero      = GridView1.DataKeys[row.RowIndex].Values[0].ToString(); // extrae key
                    Reqd_CodLinea    = GridView1.DataKeys[row.RowIndex].Values[1].ToString(); // extrae key
                    Reqs_Correlativo = GridView1.DataKeys[row.RowIndex].Values[2].ToString(); // extrae key

                    //Reqs_ItemSecuencia = GridView1.DataKeys[row.RowIndex].Values[4].ToString(); // extrae key

                    TextBox txtMonto  = ((TextBox)row.FindControl("txtMonto"));
                    TextBox txtInicio = ((TextBox)row.FindControl("txtInicio"));
                    TextBox txtFin    = ((TextBox)row.FindControl("txtFin"));
                    if (txtMonto.Text.Trim() == string.Empty)
                    {
                        cleanMessage = "Falta ingresar monto del req.: " + Requ_Numero.Trim() + "." + Reqd_CodLinea.Trim() + "-" + Reqs_Correlativo.Trim();
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
                    }

                    else if (txtInicio.Text.Trim() == string.Empty)
                    {
                        cleanMessage = "Falta ingresar fecha de inicio del req: " + Requ_Numero.Trim() + "." + Reqd_CodLinea.Trim() + "-" + Reqs_Correlativo.Trim();
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
                    }
                    else if (txtFin.Text.Trim() == string.Empty)
                    {
                        cleanMessage = "Falta ingresar fecha de termino del req: " + Requ_Numero.Trim() + "." + Reqd_CodLinea.Trim() + "-" + Reqs_Correlativo.Trim();
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
                    }
                    else if (IsDate(txtInicio.Text.Trim()) == false)
                    {
                        cleanMessage = "Error en la fecha de inicio del req : " + Requ_Numero.Trim() + "." + Reqd_CodLinea.Trim() + "-" + Reqs_Correlativo.Trim();
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
                    }
                    else if (IsDate(txtFin.Text.Trim()) == false)
                    {
                        cleanMessage = "Error en la fecha de termino del req : " + Requ_Numero.Trim() + "." + Reqd_CodLinea.Trim() + "-" + Reqs_Correlativo.Trim();
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
                    }
                    else if (Convert.ToDateTime(txtInicio.Text) > Convert.ToDateTime(txtFin.Text))
                    {
                        cleanMessage = "Error en la fecha inicio no puede ser mayor a la fecha de termino del req : " + Requ_Numero.Trim() + "." + Reqd_CodLinea.Trim() + "-" + Reqs_Correlativo.Trim();
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
                    }

                    else
                    {
                        BL_TBL_RequerimientoSubDetalle xobj = new BL_TBL_RequerimientoSubDetalle();
                        DataTable xdtResultado = new DataTable();
                        xdtResultado = xobj.uspUPD_MONTO_AMPLIACION(Requ_Numero, Reqd_CodLinea, Reqs_Correlativo, txtMonto.Text.Trim(), Convert.ToDateTime(txtInicio.Text).ToString("dd/MM/yyyy"), Convert.ToDateTime(txtFin.Text).ToString("dd/MM/yyyy"), Session["IDE_USUARIO"].ToString());

                        codigos += Requ_Numero.Trim() + "." + Reqd_CodLinea.Trim() + "-" + Reqs_Correlativo.Trim() + ",";

                        if ((Session["FileUpload1"] != null) || (FileUpload1.HasFile))
                        {
                            intContador = cargar(FileUpload1, "AMPLIACION", g.ToString(), Requ_Numero.Trim(), Reqd_CodLinea.Trim(), Reqs_Correlativo.Trim());
                            if (intContador > 0)
                            {
                                intContador++;
                            }
                        }
                    }
                }
                ChkBoxCell = null;
            }
        }
        else
        {
            cleanMessage = "Falta adjuntar documentos de sustento de ampliacion";
            ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
        }


        if (intregistros > 0)
        {
            BL_TBL_RequerimientoSubDetalle obj = new BL_TBL_RequerimientoSubDetalle();
            DataTable dtResultado = new DataTable();

            obj.USP_SEL_TBL_REQUERIMIENTO_CORREO_AMPLIACION(codigos, "ALQUILER CARE", 1);
            cleanMessage = "Envio satisfactorio";
            ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
            Session.Remove("FileUpload1");
        }
    }