Exemple #1
0
        private void guarda_datos()
        {
            // verifico si existe una imagen escaneada
            if (pic_scan.Image != null)
            {
                bool   ok      = false;
                string codPais = "";



                WinAPI.NoSiempreEncima(this.Handle.ToInt32());
                genera_carpeta();
                try
                {
                    string      sql;
                    UConnection DB1 = new UConnection(Properties.Settings.Default.ipBD, Properties.Settings.Default.serverBD, Properties.Settings.Default.usuarioBD, Properties.Settings.Default.passBD);
                    // verifico si no es nulo o vacio para hacer el update
                    foreach (DataGridViewRow row2 in dgvHuespedes.Rows)
                    {
                        if (ToStringNullSafe(row2.Cells["ESCANEAR"].Value) == "Y")
                        {
                            // obtengo la secuencia seleccionada en el grid
                            string secuencia = row2.Cells[1].Value.ToString();
                            if (!String.IsNullOrEmpty(secuencia))
                            {
                                int filasU = 0;
                                sql = string.Format("update freserno set vn_pasaporte = '{0}', vn_edad = {1}, vn_nac_f = '{2}' where vn_reserva = '{3}' and vn_secuencia = {4}",
                                                    numPasaporte, edad, fecha_nac, Program.Reserva, secuencia);
                                ok = DB1.EjecutaSQL(sql, ref filasU);
                                DB1.Dispose();
                                // guardo la imagen
                                var    image_name = nombreImagen + Program.Reserva + identificadorDoc + secuencia + ".jpg";
                                byte[] imgb       = ImageToByte(imagenReal);
                                wsimg.Img_save(carpeta, imgb, image_name);

                                WinAPI.SiempreEncima(this.Handle.ToInt32());
                                MessageBox.Show("SE GUARDARON SATISFACTORIAMENTE LA IMAGEN Y LOS DATOS.", "¡ÉXITO!");
                                pic_scan.Image = null;
                            }
                            llenarFreserno();
                            return;
                        }
                    }

                    int filas = 0;

                    // primero consulto si ya hay un huesped asignado a la reserva
                    sql = "select MAX(VN_SECUENCIA) VN_SECUENCIA from freserno where vn_reserva = '" + Program.Reserva + "' and vn_pasaporte is not null";
                    ++cuentaPasa; // las veces que se escanea un pasaporte
                    try
                    {
                        if (DB1.EjecutaSQL(sql))
                        {
                            string comandoSqls = string.Empty;
                            // si existe, no elimino el primer registro porque ya tiene pasaporte
                            if (DB1.ora_DataReader.HasRows)
                            {
                                while (DB1.ora_DataReader.Read())
                                {
                                    if (!DBNull.Value.Equals(DB1.ora_DataReader["VN_SECUENCIA"]))
                                    {
                                        random = Convert.ToInt16(DB1.ora_DataReader["VN_SECUENCIA"]);
                                    }
                                }
                            }
                            ++random;
                        }
                        // actualizo el codigo de pais en la reserva
                        string comandoSql3 = string.Format("update freserva set rv_pais = '{0}' where rv_reserva = '{1}' and rv_pais is null", codPais, Program.Reserva);
                        ok = DB1.EjecutaSQL(comandoSql3, ref filas);

                        // inserto el nuevo pax que leyo el escaner
                        string comandoSql = string.Format("insert into freserno (vn_reserva,vn_secuencia,vn_apellido,vn_nombre,vn_pase,vn_cupon,vn_edad,vn_edo_civil,vn_tipo_tarjeta,vn_extra_llegada,vn_extra_salida,vn_extra_status,vn_extra_importe,vn_extra_transa,vn_extra_cheque,vn_pasaporte,vn_en_casa,vn_en_casa_f,vn_nac_f) values ('{0}',{1},'{2}','{3}','{4}','{5}',{6},'{7}','{8}','{9}','{10}','{11}',{12},'{13}','{14}','{15}',{16},'{17}','{18}')",
                                                          Program.Reserva, random, apellido, nombre, null, null, edad, null, null, null, null, null, 0.0, null, null, numPasaporte, 0, null, fecha_nac);

                        ok = DB1.EjecutaSQL(comandoSql, ref filas);

                        var    image_name = nombreImagen + Program.Reserva + identificadorDoc + random + ".jpg";
                        byte[] imgb       = ImageToByte(imagenReal);
                        wsimg.Img_save(carpeta, imgb, image_name);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("ERROR EN EL FRONT: " + ex.Message);
                        // elimino el archivo ya guardado
                        FileInfo file = new FileInfo(testImagePath);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                        pic_scan.Image = null;
                    }
                    finally
                    {
                        DB1.Dispose();
                    }

                    if (filas > 0)
                    {
                        //WinAPI.SiempreEncima(this.Handle.ToInt32());
                        WinAPI.NoSiempreEncima(this.Handle.ToInt32());
                        MessageBox.Show("SE GUARDARON SATISFACTORIAMENTE LA IMAGEN Y LOS DATOS.", "¡ÉXITO!");
                        pic_scan.Image = null;
                    }
                    else
                    {
                        WinAPI.NoSiempreEncima(this.Handle.ToInt32());
                        MessageBox.Show("NO SE GUARDARON LOS DATOS SATISFACTORIAMENTE", "FAVOR DE REVISAR");
                        // elimino el archivo ya guardado
                        FileInfo file = new FileInfo(testImagePath);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                        pic_scan.Image = null;
                    }
                }
                catch (Exception ex)
                {
                }
                llenarFreserno();
            }
        }