Esempio n. 1
1
        private Painting FillPainting(SqliteDataReader reader)
        {
            Painting value = new Painting();

            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("ThemeId");
            if (!reader.IsDBNull(index))
            {
                value.ThemeId = reader.GetInt32(index);
            }

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

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

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

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

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

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

            return value;
        }
Esempio n. 2
0
        public void Edit(Painting painting)
        {
            if (painting.IsNew)
            {
                // Create the file
                string path = Path.Combine("images\\tableaux", painting.Filename);
                if (File.Exists(path) == false)
                {
                    string data = painting.Data;
                    string imageDatas = data.Split(',')[1];

                    File.WriteAllBytes(path, Convert.FromBase64String(imageDatas));
                }

                this.Execute((command) =>
                {
                    command.CommandText = @"INSERT INTO Painting (Title, ThemeId, Description, Filename, OnSlider, Price, Available)
            VALUES(@title, @themeId,@description, @fileName, @onslider, @price, @available)";

                    command.Parameters.Add("@title", SqliteType.Text);
                    command.Parameters.Add("@themeId", SqliteType.Integer);
                    command.Parameters.Add("@description", SqliteType.Text);
                    command.Parameters.Add("@fileName", SqliteType.Text);
                    command.Parameters.Add("@onslider", SqliteType.Integer);
                    command.Parameters.Add("@price", SqliteType.Integer);
                    command.Parameters.Add("@available", SqliteType.Integer);

                    command.Parameters["@title"].Value = painting.Title;
                    command.Parameters["@themeId"].Value = painting.ThemeId;
                    command.Parameters["@fileName"].Value = painting.Filename;
                    command.Parameters["@onslider"].Value = painting.OnSlider;
                    command.Parameters["@price"].Value = painting.Price;
                    command.Parameters["@available"].Value = painting.Available;

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

                    command.ExecuteNonQuery();
                });
            }
            else
            {
                this.Execute((command) =>
                {
                    command.CommandText = @"UPDATE Painting
            SET Title =@title,
            ThemeId =@themeId,
            Description = @description,
            OnSlider = @onslider,
            Price = @price,
            Available = @available
            WHERE Id = @id";
                    command.Parameters.Add("@id", SqliteType.Integer);
                    command.Parameters.Add("@title", SqliteType.Text);
                    command.Parameters.Add("@themeId", SqliteType.Integer);
                    command.Parameters.Add("@description", SqliteType.Text);
                    command.Parameters.Add("@onslider", SqliteType.Integer);
                    command.Parameters.Add("@price", SqliteType.Integer);
                    command.Parameters.Add("@available", SqliteType.Integer);

                    command.Parameters["@id"].Value = painting.Id;
                    command.Parameters["@title"].Value = painting.Title;
                    command.Parameters["@themeId"].Value = painting.ThemeId;
                    command.Parameters["@onslider"].Value = painting.OnSlider;
                    command.Parameters["@price"].Value = painting.Price;
                    command.Parameters["@available"].Value = painting.Available;

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

                    command.ExecuteNonQuery();
                });
            }
        }