I can not create QR code in C #

2

I have this code which I want to access to the QR part, in order to generate one, but at the moment of creating a record in RecordEvent when I send it to call AltaQRBoleto (1, Correo); (In spite of sending him to call twice) he does not take any action, why is this?

public void ProcessRequest(HttpContext context)
        {
            //write your handler implementation here.
;
            string Tipo = context.Request.QueryString["Tipo"];

            switch (Tipo)
            {
                case "registro":
                    {
                        RegistroEvento(context);
                    }
                    break;
            }
        }

        private static void RegistroEvento(HttpContext context)
        {
            Mensajes claseMensajes = new Mensajes();

            string NombreEmpresa = context.Request.QueryString["NE"];
            string NombreAsistente = context.Request.QueryString["NA"];
            string Puesto = context.Request.QueryString["PU"];
            string Correo = context.Request.QueryString["CO"];
            string Telefono = context.Request.QueryString["TE"];

            using (SqlConnection conexion = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["I_Registros"].ToString()))
            {
                conexion.Open();

                using (SqlCommand orden = new SqlCommand("PROC_RegistroEvento @NombreEmpresa , @NombreAsistente , @Puesto , @Correo , @Telefono , @Evento", conexion))
                {
                    //@NombreEmpresa 
                    orden.Parameters.Add(new SqlParameter("@NombreEmpresa", SqlDbType.VarChar));
                    orden.Parameters["@NombreEmpresa"].Value = NombreEmpresa;
                    //@NombreAsistente 
                    orden.Parameters.Add(new SqlParameter("@NombreAsistente", SqlDbType.VarChar));
                    orden.Parameters["@NombreAsistente"].Value = NombreAsistente;
                    //@Puesto 
                    orden.Parameters.Add(new SqlParameter("@Puesto", SqlDbType.VarChar));
                    orden.Parameters["@Puesto"].Value = Puesto;
                    //@Correo 
                    orden.Parameters.Add(new SqlParameter("@Correo", SqlDbType.VarChar));
                    orden.Parameters["@Correo"].Value = Correo;
                    //@Telefono 
                    orden.Parameters.Add(new SqlParameter("@Telefono", SqlDbType.VarChar));
                    orden.Parameters["@Telefono"].Value = Telefono;
                    //@Evento 
                    orden.Parameters.Add(new SqlParameter("@Evento", SqlDbType.Int));
                    orden.Parameters["@Evento"].Value = 1;

                    int id = 0;
                    string regreso = "";

                    using (SqlDataReader lector = orden.ExecuteReader())
                    {
                        while (lector.Read())
                        {
                            id = (int)lector["id"];
                            regreso = (string)lector["RegresoDatos"];
                        }
                        lector.Close();

                        AltaQRBoleto(1, Correo);

                        claseMensajes.Tipo = "RegistroEvento";
                        claseMensajes.cadenaRegreso = regreso;

                        AltaQRBoleto(1, Correo);
                    }
                }
                conexion.Close();
            }
            context.Response.Write(claseMensajes.toJson());
        }

        public static void AltaQRBoleto(int idEvento, string Correo)
        {
            int idFolioRegistro = 0;
            string UUIDEvento = "";

            string FolioManual = "";

            byte[] CodigoBarras = null;
            byte[] RptBoleto = null;

            using (SqlConnection conexion = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["I_Registros"].ToString()))
            {
                conexion.Open();

                using (SqlCommand orden = new SqlCommand(@"
SELECT [idRegistro], [FolioAsistenciaEvento] FROM [dbo].[EventosRegistros]
            INNER JOIN [dbo].[Asistentes] ON [Asistentes].[idPersona] = [EventosRegistros].[idPersona]
        WHERE [Correo] = @CORREO AND [idEvento] = @EVENTO", conexion))
                {
                    orden.Parameters.AddWithValue("@CORREO", Correo);
                    orden.Parameters.AddWithValue("@EVENTO", idEvento);

                    SqlDataReader lector = orden.ExecuteReader();
                    while(lector.Read())
                    {
                        idFolioRegistro = (int)lector["idRegistro"];
                        UUIDEvento = (string)lector["FolioAsistenciaEvento"];
                    }
                    lector.Close();

                    Gma.QrCodeNet.Encoding.QrCode clase = new Gma.QrCodeNet.Encoding.QrCode();
                    Gma.QrCodeNet.Encoding.QrEncoder claseee = new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.H);
                    clase = claseee.Encode(UUIDEvento);
                    Gma.QrCodeNet.Encoding.Windows.Render.GraphicsRenderer lectorRender = new Gma.QrCodeNet.Encoding.Windows.Render.GraphicsRenderer(new Gma.QrCodeNet.Encoding.Windows.Render.FixedCodeSize(400, Gma.QrCodeNet.Encoding.Windows.Render.QuietZoneModules.Zero), Brushes.Black, Brushes.White);
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    lectorRender.WriteToStream(clase.Matrix, System.Drawing.Imaging.ImageFormat.Png, ms);
                    CodigoBarras = ReadFully(ms);
                    Random claseRandom = new Random();

                    FolioManual = idFolioRegistro.ToString() + "." + claseRandom.Next(1111, 9999).ToString();

                    orden.CommandText = "UPDATE [dbo].[EventosRegistros] SET [FolioManual] = @FOLIOMANUAL, [QR] = @QR WHERE [idRegistro] = @ID";
                    orden.Parameters.AddWithValue("@FOLIOMANUAL", FolioManual);
                    orden.Parameters.AddWithValue("@QR", CodigoBarras);
                    orden.Parameters.AddWithValue("@ID", idFolioRegistro);

                    orden.ExecuteNonQuery();

                    DataSet regresoRPT = new DataSet();

                    orden.CommandText = @"
SELECT [Evento], [Ubicacion], [FechaInicio], [FechaFin], 
        [NombreEmpresa], [NombreAsistente], [Puesto], [FolioManual], [QR] 
FROM [dbo].[Eventos]
            INNER JOIN [dbo].[EventosRegistros] ON [EventosRegistros].[idEvento] = [Eventos].[idEvento]
            INNER JOIN [dbo].[Asistentes] ON [Asistentes].[idPersona] = [EventosRegistros].[idPersona]
        WHERE [idRegistro] = @ID
";
                    regresoRPT.Load(orden.ExecuteReader(), LoadOption.PreserveChanges, "RegistroEntrada");
                }
                conexion.Close();
            }
        }

        public static byte[] ReadFully(System.IO.Stream input)
        {
            byte[] buffer = new byte[16 * 1024];
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                int read;
                while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }
    
asked by CarlosOro 14.05.2016 в 01:35
source

1 answer

1

The first thing I could comment is that defining a while of a reader to assign variables does not make any sense, if you are going to take a valrod the reader uses the if

if(lector.Read())
{
   id = (int)lector["id"];
   regreso = (string)lector["RegresoDatos"];
}

because if you are going to travel you should assign a list or collection when you iterate in the while, so you do not step on the previous value

> > at the time of calling AltaQRBoleto (1, Mail); does not take any action,

I can see that the update action depends on a folio id that you assign per parameter to UPDATE

What you should do is put a breakpoint I have to inspect that the id that you send in the UPDATE exists as a record, because if not it will not update

You could also validate how row affects the UPDATE execution

int rowafectadas = orden.ExecuteNonQuery();

If the value of rowafectadas is zero then it means that the id you assign is not finding any record

    
answered by 14.05.2016 в 06:44