ASP.NET - como validar los datos de un datagrid

 
Vista:
sin imagen de perfil
Val: 19
Ha aumentado 1 puesto en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

como validar los datos de un datagrid

Publicado por Daniela (10 intervenciones) el 19/04/2018 16:45:32
hola, a continuacion estará el codigo que estoy usando, dicho codigo me muestra la consulta para generar un pedido, lo que necesito es cuando hago dicha consulta me diga es si hay pedidos disponibles y si no que me muestre un mensaje de error

Button1 es consulta

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
protected void Button1_Click(object sender, EventArgs e)
{
    if (lbUsuario.Text == "jmartinez" || lbUsuario.Text == "carevalo" || lbUsuario.Text == "cjaramillo")
    {
        Response.Redirect("Inicio.aspx");
    }
 
    if (ddlAlmacen.Text != "")
    {
        try
        {
            SqlDataAdapter da = new SqlDataAdapter("Select * from (select *, Sum(R.CantModificadas - R.inv)sugerido  from (select ROW_NUMBER() over( partition by A.Almacen, A.RefTallaColor order by a.Año+a.Mes+a.Dia desc) row, A.Almacen, A.RefTallaColor, A.IDCurva, A.CantModificadas, case WHEN sum(S.ICANTIDAD-S.OCANTIDAD) is null then 0 ELSE cast (sum(S.ICANTIDAD-S.OCANTIDAD)AS INT) END AS INV from Analisis_Curva A left join SALDOINV S on A.Almacen = S.BODEGA and A.RefTallaColor = S.CODIGO GROUP BY A.Almacen, A.RefTallaColor, A.IDCurva, A.CantModificadas, A.Año, A.Mes, A.Dia) R where R.row = 1 GROUP BY R.row, R.Almacen, R.RefTallaColor, R.IDCurva, R.CantModificadas, R.INV) S Where S.sugerido > 0 and S.Almacen = '"+ddlAlmacen.Text+"' GROUP BY S.row, S.Almacen, S.RefTallaColor, S.IDCurva, S.CantModificadas, S.INV, S.sugerido ", cn);
            DataTable dt = new DataTable();
 
            da.Fill(dt);
 
            this.grvPedidos.DataSource = dt;
            grvPedidos.DataBind();
        }
 
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}
protected void btnPedido_Click(System.Object sender, EventArgs e)
{
    if (lbUsuario.Text == "jmartinez" || lbUsuario.Text == "carevalo" || lbUsuario.Text == "cjaramillo")
    {
        Response.Redirect("Inicio.aspx");
    }
 
    double BRUTO = 0;
 
    foreach (GridViewRow row in grvPedidos.Rows)
    {
        double Precio = 0, BRUTONETO = 0;
 
        double Sugerido = Convert.ToDouble(((System.Web.UI.WebControls.Label)row.FindControl("lbSugerido")).Text);
 
        if (Sugerido > 0)
        {
            string RefTallaColor = ((System.Web.UI.WebControls.Label)row.FindControl("lbRefTallaColor")).Text;
            double inv = 0;
 
            //validacion de cantidades en el inventario 
            try
            {
                string sql = @"select case when sum(ICANTIDAD-OCANTIDAD) is null or sum(ICANTIDAD-OCANTIDAD)< 0 then 0  else sum(ICANTIDAD-OCANTIDAD)  END INV from saldoinv where  bodega = 'cedi' and codigo = '" + RefTallaColor + "'";
                cn.Open();
                SqlCommand cmd = new SqlCommand(sql, cn);
                inv = Convert.ToDouble(cmd.ExecuteScalar());
                cn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
 
            if (inv > 0)
            {
 
                try
                {
                    string sql = @"select top 1 PRECIO  from MVPRECIO  WHERE CODPRECIO='14' and CODPRODUC = '" + RefTallaColor + "'";
                    cn.Open();
                    SqlCommand cmd = new SqlCommand(sql, cn);
                    Precio = Convert.ToDouble(cmd.ExecuteScalar());
                    Sugerido = Convert.ToDouble(((System.Web.UI.WebControls.Label)row.FindControl("lbSugerido")).Text);
                    BRUTONETO = ((Precio * Sugerido) * 0.19) + (Precio * Sugerido);
 
                    BRUTO = (BRUTO + BRUTONETO);
 
                    cn.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
    }
 
    NegTrade Negtr = new NegTrade();
 
 
    Negtr.addTradepp(ddlAlmacen.Text, lbUsuario.Text, BRUTO);
    Negtr.addTradesv(ddlAlmacen.Text, lbUsuario.Text, BRUTO);
 
    foreach (GridViewRow row in grvPedidos.Rows)
    {
        double Sugerido = Convert.ToDouble(((System.Web.UI.WebControls.Label)row.FindControl("lbSugerido")).Text);
 
        if (Sugerido > 0)
        {
            string RefTallaColor = ((System.Web.UI.WebControls.Label)row.FindControl("lbRefTallaColor")).Text;
 
            double inv;
 
            //validacion de cantidades en el inventario 
            try
            {
                string sql = @"select case when sum(ICANTIDAD-OCANTIDAD) is null or sum(ICANTIDAD-OCANTIDAD)< 0 then 0 else sum(ICANTIDAD-OCANTIDAD)   END  INV from saldoinv where  bodega = 'cedi' and codigo = '" + RefTallaColor + "'";
                cn.Open();
                SqlCommand cmd = new SqlCommand(sql, cn);
                inv = Convert.ToDouble(cmd.ExecuteScalar());
                cn.Close();
 
            }
            catch (Exception ex)
            {
                throw ex;
            }
 
            if (inv > 0)
            {
 
                NegMvTrade NegMvTrPP = new NegMvTrade();
 
                NegMvTrPP.addmvTradepp(Sugerido, RefTallaColor, ddlAlmacen.Text, lbUsuario.Text);
                NegMvTrPP.addmvTradesv(Sugerido, RefTallaColor, ddlAlmacen.Text, lbUsuario.Text);
            }
        }
    }
 
    double pp;
    string sql1 = @"select CONSECUT from consecut where origen = 'fac' and tipodcto = 'pp'";
    cn.Open();
    SqlCommand cmd1 = new SqlCommand(sql1, cn);
    pp = Convert.ToDouble(cmd1.ExecuteScalar());
    cn.Close();
 
    double sv;
    string sql2 = @"select CONSECUT from consecut where origen = 'inv' and tipodcto = 'sv'";
    cn.Open();
    SqlCommand cmd2 = new SqlCommand(sql2, cn);
    sv = Convert.ToDouble(cmd2.ExecuteScalar());
    cn.Close();
 
    Response.Write("<script>window.alert('Pedido realizado exitosamente      PP:  " + pp + "     sv:   " + sv + "');</script>");
    grvPedidos.Columns.Clear();
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Andrea

como validar los datos de un datagrid

Publicado por Andrea (10 intervenciones) el 08/06/2018 18:07:18
Especifica el error. Cuál es el resultado al hacer clic en Button1 en el caso que no haya pedido...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar