Exemplo n.º 1
0
        public bool Save(IDbConnection conn)
        {
            dataParam.Value = ModelUtilities.PackData(this.entryData);
            if (profileId != 0)
            {
                conn.Open();

                if (entryId != 0)
                {
                    profileParam.Value = profileId;
                    entryParam.Value   = entryId;

                    IDbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = updateSql;
                    cmd.Parameters.Add(profileParam);
                    cmd.Parameters.Add(entryParam);
                    cmd.Parameters.Add(dataParam);

                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    profileParam.Value = profileId;
                    IDbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = lastEntryIdSql;
                    cmd.Parameters.Add(profileParam);
                    cmd.Prepare();

                    IDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        entryId = reader.GetInt64(0) + 1;
                    }
                    reader.Close();

                    entryParam.Value = entryId;
                    cmd.CommandText  = insertSql;
                    cmd.Parameters.Add(profileParam);
                    cmd.Parameters.Add(entryParam);
                    cmd.Parameters.Add(dataParam);

                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }

                conn.Close();
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public TradeJournalDiaryEntry(IDbConnection conn, uint profileId = 0, uint entryId = 0)
        {
            this.profileId = profileId;
            this.entryId   = entryId;

            // Open the connection
            conn.Open();
            IDbCommand dbcmd = conn.CreateCommand();

            dbcmd.CommandText = getSql;

            // Profile Parameter
            profileParam = dbcmd.CreateParameter();
            profileParam.ParameterName = "@profileId";
            profileParam.DbType        = DbType.Int64;
            profileParam.Value         = profileId;
            dbcmd.Parameters.Add(profileParam);

            // Entry Parameter
            entryParam = dbcmd.CreateParameter();
            entryParam.ParameterName = "@entryId";
            entryParam.DbType        = DbType.Int64;
            entryParam.Value         = entryId;
            dbcmd.Parameters.Add(entryParam);

            // Data Parameter
            dataParam = dbcmd.CreateParameter();
            dataParam.ParameterName = "@data";
            dataParam.DbType        = DbType.String;

            dbcmd.Prepare();
            IDataReader reader = dbcmd.ExecuteReader();

            while (reader.Read())
            {
                this.entryData = ModelUtilities.UnpackData(reader.GetString(0));
            }
            reader.Close();

            // Close the connection
            conn.Close();
        }