Ejemplo n.º 1
0
        public void HandlePositiveButtonClick(object sender, DialogClickEventArgs e)
        {
            try
            {
                //signature = Activity.FindViewById<SignaturePadView>(Resource.Id.signatureFrame);
                Bitmap       imagen = signature.GetImage();
                MemoryStream ms     = new MemoryStream();
                //ByteArrayOutputStream bos = new ByteArrayOutputStream();
                imagen.Compress(Bitmap.CompressFormat.Png, 100, ms);
                byte[] bArray = ms.ToArray();

                //string id = Guid.NewGuid().ToString();
                System.Console.WriteLine("GUID: " + guid);
                loadConnection();
                db.BeginTransaction();
                //Se almacena en base de datos el BLOB con su respectivo GUID
                try
                {
                    string          sql        = "INSERT INTO IMAGENES (Nombre,Imagen) VALUES(?,?)";
                    SQLiteStatement insertStmt = db.CompileStatement(sql);
                    insertStmt.ClearBindings();
                    insertStmt.BindString(1, guid);
                    insertStmt.BindBlob(2, bArray);
                    insertStmt.ExecuteInsert();
                    db.SetTransactionSuccessful();
                    db.EndTransaction();
                    db.Close();
                    try
                    {
                        if (actor.Equals("notificando", StringComparison.Ordinal))
                        {
                            ManejoBaseDatos.Abrir();
                            ManejoBaseDatos.Actualizar("Notificaciones", "ValidacionNotificando", "S", "CodigoNotificacion=" + codigo + "");
                            ManejoBaseDatos.Cerrar();
                        }
                        if (actor.Equals("testigo", StringComparison.Ordinal))
                        {
                            ManejoBaseDatos.Abrir();
                            ManejoBaseDatos.Actualizar("Notificaciones", "ValidacionTestigo", "S", "CodigoNotificacion=" + codigo + "");
                            ManejoBaseDatos.Cerrar();
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine("Error almacenando confirmacion de firma: " + ex.ToString());
                        Toast.MakeText(this.Activity, "Error guardando confirmacion", ToastLength.Short).Show();
                    }
                }
                catch (Exception ex) { System.Console.WriteLine("Error guardando imagen en db: " + ex.ToString()); }

                Toast.MakeText(this.Activity, "Firma capturada de forma exitosa", ToastLength.Short).Show();
            }
            catch (Exception ex) { System.Console.WriteLine("ERROR guardando la imagen: " + ex.ToString()); }
        }
Ejemplo n.º 2
0
        public void insertMaps(List <MapDownloadResource> maps, Dictionary <string, string> mapsItemsCodes, Dictionary <string, string> regionItemsCodes, Context applicationContext)
        {
            try
            {
                if ((maps != null) && (mapsItemsCodes != null) && (regionItemsCodes != null))
                {
                    // create a compile statement for inserting the maps using transactions
                    StringBuilder insertCommand = new StringBuilder("INSERT INTO ");
                    insertCommand.Append(MAPS_TABLE).Append(" VALUES (?");
                    // the number of columns in maps table is 20
                    for (int i = 0; i < 20; i++)
                    {
                        insertCommand.Append(",?");
                    }
                    insertCommand.Append(");");
                    resourcesDAO.getDatabase().BeginTransaction();
                    SQLiteStatement insertStatement = resourcesDAO.getDatabase().CompileStatement(insertCommand.ToString());
                    int             columnIndex, lineIndex = 0;
                    foreach (MapDownloadResource map in maps)
                    {
                        columnIndex = 1;
                        lineIndex++;
                        insertStatement.ClearBindings();
                        insertStatement.BindLong(columnIndex++, lineIndex);
                        insertStatement.BindString(columnIndex++, map.Code);
                        insertStatement.BindString(columnIndex++, mapsItemsCodes[map.Code]);
                        if ((map.getSubType() != null) && map.getSubType().Equals(STATE_TYPE)) //ignorecode
                        {
                            insertStatement.BindString(columnIndex++, regionItemsCodes[map.Code]);
                        }
                        else
                        {
                            insertStatement.BindString(columnIndex++, "");
                        }

                        // compute the string that contains all the name translations
                        StringBuilder nameInAllSpecifiedLanguages = new StringBuilder();

                        if (map.getNames() != null)
                        {
                            foreach (var currentEntry in map.getNames())
                            {
                                nameInAllSpecifiedLanguages.Append(currentEntry.Key).Append("=").Append(currentEntry.Value).Append(";");
                            }
                        }

                        if (nameInAllSpecifiedLanguages.Length > 1)
                        {
                            insertStatement.BindString(columnIndex++, nameInAllSpecifiedLanguages.ToString().Substring(0, nameInAllSpecifiedLanguages.Length - 1));
                        }
                        else
                        {
                            insertStatement.BindString(columnIndex++, "");
                        }
                        insertStatement.BindString(columnIndex++, map.getSKMFilePath());
                        insertStatement.BindString(columnIndex++, map.getZipFilePath());
                        insertStatement.BindString(columnIndex++, map.getTXGFilePath());
                        insertStatement.BindLong(columnIndex++, (int)map.getTXGFileSize());
                        insertStatement.BindLong(columnIndex++, (int)map.getSkmAndZipFilesSize());
                        insertStatement.BindLong(columnIndex++, (int)map.getSkmFileSize());
                        insertStatement.BindLong(columnIndex++, (int)map.getUnzippedFileSize());
                        insertStatement.BindDouble(columnIndex++, map.getBbLatMax());
                        insertStatement.BindDouble(columnIndex++, map.getBbLatMin());
                        insertStatement.BindDouble(columnIndex++, map.getBbLongMax());
                        insertStatement.BindDouble(columnIndex++, map.getBbLongMin());
                        insertStatement.BindString(columnIndex++, map.getSubType());
                        insertStatement.BindLong(columnIndex++, map.DownloadState);
                        insertStatement.BindLong(columnIndex++, map.NoDownloadedBytes);
                        insertStatement.BindLong(columnIndex++, 0);
                        insertStatement.BindString(columnIndex, map.DownloadPath);

                        insertStatement.Execute();
                    }
                }
            }
            finally
            {
                if ((maps != null) && (mapsItemsCodes != null))
                {
                    SKLogging.WriteLog(TAG, "Maps were inserted into database !!!", SKLogging.LogDebug);
                    // close the GENERAL transaction
                    resourcesDAO.getDatabase().SetTransactionSuccessful();
                    resourcesDAO.getDatabase().EndTransaction();
                }
            }
        }