Ejemplo n.º 1
0
        public void DelItem(Item item)
        {
            using (SQLiteCommand cmd = new SQLiteCommand(conn))
            {
                cmd.CommandText = "delete from items where id=@Id;";
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@Id", item.Id);
                cmd.ExecuteNonQuery();

                Items.Remove(item);
            }
            if (item.FileName!=string.Empty)
            {
                try
                {
                File.Delete(SomeConst.FILEDIR + item.FileName);
                }
                catch (System.Exception)
                {
                    System.Windows.Forms.MessageBox.Show("Delete file failed.");
                }
            }
        }
Ejemplo n.º 2
0
        public void SaveItem(Item refItem, Item newItem)
        {
            refItem.Title = newItem.Title;
            refItem.Description = newItem.Description;
            refItem.Tagum = newItem.Tagum;
            if (refItem.IsChanged())
            {
                using (SQLiteCommand cmd = new SQLiteCommand(conn))
                {
                    List<string> sList = new List<string>();

                    if (refItem.IsTitleChanged)
                    {
                        sList.Add("title=@Title");
                    }
                    if (refItem.IsDescriptionChanged)
                    {
                        sList.Add("description=@Description");
                    }
                    if (refItem.IsTagumChanged)
                    {
                        sList.Add("tagum=@Tagum");
                    }

                    cmd.CommandText = "update items set " + string.Join(",", sList) + " where id=@Id";
                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@Id", refItem.Id);
                    cmd.Parameters.AddWithValue("@Title", refItem.Title);
                    cmd.Parameters.AddWithValue("@Description", refItem.Description);
                    cmd.Parameters.Add("@Tagum", System.Data.DbType.Binary).Value = refItem.Tagum;
                    cmd.ExecuteNonQuery();

                    refItem.ClearChangeStatus();
                }
            }
        }
Ejemplo n.º 3
0
 public void AddItem(Item item, string path)
 {
     using (SQLiteCommand cmd = new SQLiteCommand(conn))
     {
         cmd.CommandText = "insert into items(title,description,file,tagum) values(@Title,@Description,@File,@Tagum);";
         cmd.Prepare();
         cmd.Parameters.AddWithValue("@Title", item.Title);
         cmd.Parameters.AddWithValue("@Description", item.Description);
         cmd.Parameters.AddWithValue("@File", item.FileName);
         cmd.Parameters.Add("@Tagum", System.Data.DbType.Binary).Value = item.Tagum;
         cmd.ExecuteNonQuery();
         item.Id = (int)conn.LastInsertRowId;
         Items.Add(item);
     }
     if (item.FileName!=string.Empty)
     {
         File.Copy(path, SomeConst.FILEDIR + item.FileName);
     }
 }