예제 #1
1
        private Theme FillTheme(SqliteDataReader reader)
        {
            Theme value = new Theme();

            int index = reader.GetOrdinal("Id");
            if (!reader.IsDBNull(index))
            {
                value.Id = reader.GetInt32(index);
            }

            index = reader.GetOrdinal("Title");
            if (!reader.IsDBNull(index))
            {
                value.Title = reader.GetString(index);
            }

            index = reader.GetOrdinal("Description");
            if (!reader.IsDBNull(index))
            {
                value.Description = reader.GetString(index);
            }

            index = reader.GetOrdinal("ParentId");
            if (!reader.IsDBNull(index))
            {
                value.ParentId = reader.GetInt32(index);
            }

            index = reader.GetOrdinal("ParentTitle");
            if (!reader.IsDBNull(index))
            {
                value.ParentTitle = reader.GetString(index);
            }

            index = reader.GetOrdinal("WithText");
            if(!reader.IsDBNull(index))
            {
                value.WithText = reader.GetBoolean(index);
            }

            return value;
        }
예제 #2
0
 public void Edit(Theme theme)
 {
     this.themeTable.Edit(theme);
 }
예제 #3
0
        public void Edit(Theme theme)
        {
            if (theme.IsNew)
            {
                // Add the theme 
                this.Execute((command) =>
                {
                    command.CommandText = "INSERT INTO [Theme] ([ParentId], [Title], [Description], [WithText]) VALUES(@parentId, @title,@description, @withText)";
                    command.Parameters.Add("@parentId", SqliteType.Integer);
                    command.Parameters.Add("@title", SqliteType.Text);
                    command.Parameters.Add("@description", SqliteType.Text);
                    command.Parameters.Add("@withText", SqliteType.Integer);

                    command.Parameters["@title"].Value = theme.Title;

                    if (theme.HasParent)
                    {
                        command.Parameters["@parentId"].Value = theme.ParentId;
                    }
                    else
                    {
                        command.Parameters["@parentId"].Value = DBNull.Value;
                    }

                    if (string.IsNullOrWhiteSpace(theme.Description))
                    {
                        command.Parameters["@description"].Value = DBNull.Value;
                    }
                    else
                    {
                        command.Parameters["@description"].Value = theme.Description;
                    }

                    command.Parameters["@withText"].Value = theme.WithText;

                    command.ExecuteNonQuery();
                });
            }
            else
            {
                // Update the exsiting theme
                this.Execute((command) =>
                {
                    command.CommandText = "UPDATE [Theme] SET [ParentId]=@parentId, [Title] = @title, [Description]= @description, [WithText]= @withText WHERE [Id]= @id";
                    command.Parameters.Add("@id", SqliteType.Integer);
                    command.Parameters.Add("@parentId", SqliteType.Integer);
                    command.Parameters.Add("@title", SqliteType.Text);
                    command.Parameters.Add("@description", SqliteType.Text);
                    command.Parameters.Add("@withText", SqliteType.Integer);

                    command.Parameters["@id"].Value = theme.Id;
                    command.Parameters["@title"].Value = theme.Title;

                    if (theme.HasParent)
                    {
                        command.Parameters["@parentId"].Value = theme.ParentId;
                    }
                    else
                    {
                        command.Parameters["@parentId"].Value = DBNull.Value;
                    }

                    if (string.IsNullOrWhiteSpace(theme.Description))
                    {
                        command.Parameters["@description"].Value = DBNull.Value;
                    }
                    else
                    {
                        command.Parameters["@description"].Value = theme.Description;
                    }

                    command.Parameters["@withText"].Value = theme.WithText;

                    command.ExecuteNonQuery();
                });
            }
        }