private void SavePicture(TtPicture oldPic, TtPicture pic, SQLiteTransaction trans)
        {
            if (oldPic.CN != pic.CN)
                throw new Exception("Mismatch Picture CN");

            using (SQLiteCommand update = _dbConnection.CreateCommand())
            {
                StringBuilder queryBeginning = new StringBuilder();
                StringBuilder queryEnd = new StringBuilder();
                queryBeginning.AppendFormat("Update {0} set ", TwoTrailsSchema.PictureSchema.TableName);
                queryEnd.Append("(");

                queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.PicData);
                queryEnd.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.PicDataValue);
                update.Parameters.Add(TwoTrailsSchema.PictureSchema.PicDataValue, System.Data.DbType.Binary).Value =
                    ((pic.HasData) ? pic.GetPictureBytes() : new byte[0]);

                queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.Time);
                queryEnd.AppendFormat("'{0}',", pic.Time);

                queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.PicType);
                queryEnd.AppendFormat("'{0}',", pic.Type);

                queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.FileType);
                queryEnd.AppendFormat("'{0}',", pic.FileType);

                queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.FileName);
                queryEnd.AppendFormat("'{0}',", pic.FileName);

                queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.UtmX);
                queryEnd.AppendFormat("{0},", pic.UtmX);

                queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.UtmY);
                queryEnd.AppendFormat("{0},", pic.UtmY);

                queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.Elev);
                queryEnd.AppendFormat("{0},", pic.Elevation);

                queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.Comment);
                queryEnd.AppendFormat("'{0}',", pic.Comment);

                queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.Az);
                queryEnd.AppendFormat("{0},", pic.Azimuth == null ? "null" : String.Format("'{0}'", pic.Azimuth.ToString()));

                queryBeginning.AppendFormat("{0}", TwoTrailsSchema.PictureSchema.Acc);
                queryEnd.AppendFormat("{0}", pic.Accuracy == null ? "null" : String.Format("'{0}'", pic.Accuracy.ToString()));

                queryBeginning.Append(") values ");
                queryEnd.Append(");");

                queryBeginning.AppendFormat(" {0}", queryEnd.ToString());
                if (!IsOpen)
                    OpenDB();

                if (trans != null)
                    update.Transaction = trans;
                update.CommandText = queryBeginning.ToString();
                update.ExecuteNonQuery();
            }
        }
        private bool InsertPicture(TtPicture pic, SQLiteTransaction trans)
        {
            try
            {
                if (!pic.IsValid)
                    throw new Exception("Invalid TtPicture");

                using (SQLiteCommand cmd = _dbConnection.CreateCommand())
                {
                    StringBuilder queryBeginning = new StringBuilder();
                    StringBuilder queryEnd = new StringBuilder();

                    if (pic.CN == String.Empty)
                        pic.CN = Guid.NewGuid().ToString();

                    queryBeginning.AppendFormat("INSERT INTO {0} (", TwoTrailsSchema.PictureSchema.TableName);
                    queryEnd.Append("(");

                    //CN
                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.CN);
                    queryEnd.AppendFormat("'{0}',", pic.CN);

                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.PicData);
                    queryEnd.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.PicDataValue);
                    cmd.Parameters.Add(TwoTrailsSchema.PictureSchema.PicDataValue, System.Data.DbType.Binary).Value =
                        ((pic.HasData) ? pic.GetPictureBytes() : new byte[0]);

                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.Time);
                    queryEnd.AppendFormat("'{0}',", pic.Time.ToString());

                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.PicType);
                    queryEnd.AppendFormat("'{0}',", pic.Type);

                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.FileType);
                    queryEnd.AppendFormat("'{0}',", pic.FileType);

                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.FileName);
                    queryEnd.AppendFormat("'{0}',", pic.FileName);

                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.UtmX);
                    queryEnd.AppendFormat("{0},", pic.UtmX);

                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.UtmY);
                    queryEnd.AppendFormat("{0},", pic.UtmY);

                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.Elev);
                    queryEnd.AppendFormat("{0},", pic.Elevation);

                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.Comment);
                    queryEnd.AppendFormat("'{0}',", pic.Comment);

                    queryBeginning.AppendFormat("{0},", TwoTrailsSchema.PictureSchema.Az);
                    queryEnd.AppendFormat("{0},", pic.Azimuth == null ? "null" : String.Format("'{0}'", pic.Azimuth.ToString()));

                    queryBeginning.AppendFormat("{0}", TwoTrailsSchema.PictureSchema.Acc);
                    queryEnd.AppendFormat("{0}", pic.Accuracy == null ? "null" : String.Format("'{0}'", pic.Accuracy.ToString()));

                    queryBeginning.Append(") values ");
                    queryEnd.Append(");");
                    queryBeginning.AppendFormat(" {0}", queryEnd.ToString());

                    cmd.Transaction = trans;
                    cmd.ExecuteNonQuery();
                }
            }
            catch
            {
                //
                return false;
            }

            return true;
        }