public static List<DtoProductoVenta> selectoDtoProd()
        {
            List<DtoProductoVenta> lista = new List<DtoProductoVenta>();
            SqlConnection cn = new SqlConnection();
            try
            {
                cn.ConnectionString = cadenaConex;
                cn.Open();
                string consulta = "SELECT P.nombre as NombreProd, P.precio, P.stock, P.codigoBarra FROM Productos P";
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = consulta;
                cmd.Connection = cn;

                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    DtoProductoVenta p = new DtoProductoVenta();
                    p.nombre = dr["NombreProd"].ToString();
                    p.precio = float.Parse(dr["precio"].ToString());
                    p.stock = (int)dr["stock"];
                    p.codigoBarra = (int)dr["codigoBarra"];
                    lista.Add(p);
                }
            }
            catch (SqlException ex)
            {
                throw new ApplicationException("Error SQL al obtener los Productos Simplificados.");
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                    cn.Close();
            }
            return lista;
        }
示例#2
0
        protected void txt_cant_TextChanged(object sender, EventArgs e)
        {
            if (Session["MiCarro"] == null) Session["MiCarro"] = new List<DtoProductoVenta>();
            Boolean insertar = true;
            List<DtoProductoVenta> miCarro = (List<DtoProductoVenta>)Session["MiCarro"];
            int index = grilla.SelectedRow.RowIndex;
            int codigoBarra = int.Parse(grilla.Rows[index].Cells[5].Text);
            TextBox tbo = grilla.Rows[index].FindControl("txt_cant") as TextBox;
            int A;
            if (int.TryParse((tbo.Text), out A))
            {
                if (int.Parse(grilla.Rows[index].Cells[4].Text) >= A)
                {
                    validadorServidor.Visible = false;
                    btn_confirmar.Visible = true;
                    foreach (DtoProductoVenta dto in miCarro)
                    {
                        if (dto.codigoBarra == codigoBarra)
                        {
                            tbo = grilla.Rows[index].FindControl("txt_cant") as TextBox;
                            dto.cantidad = int.Parse(tbo.Text);
                            insertar = false;
                        }
                    }
                    if (insertar == true)
                    {
                        DtoProductoVenta p = new DtoProductoVenta();
                        p.nombre = grilla.Rows[index].Cells[2].Text;
                        TextBox tb = grilla.Rows[index].FindControl("txt_cant") as TextBox;
                        p.cantidad = int.Parse(tb.Text);
                        p.codigoBarra = int.Parse(grilla.Rows[index].Cells[5].Text);
                        p.precio = int.Parse(grilla.Rows[index].Cells[3].Text);
                        miCarro.Add(p);

                    }
                }

                else
                {
                    validadorServidor.Visible = true;
                    btn_confirmar.Visible = false;
                }
            }
            else
            {
                validadorServidor.Visible = true;
                btn_confirmar.Visible = false;

            }
        }