private void btnEdit_Click(object sender, EventArgs e)
 {
     if (lvFolders.SelectedItems.Count > 0)
     {
         using (DlgSelectLogicalFolder dlg = new DlgSelectLogicalFolder(lvFolders.SmallImageList)) {
             ListViewItem  oldListViewItem = lvFolders.SelectedItems[0];
             LogicalFolder folderToEdit    = (LogicalFolder)oldListViewItem.Tag;
             dlg.Selected = folderToEdit;
             if (dlg.ShowDialog() == DialogResult.OK)
             {
                 LogicalFolder selectedFolder = dlg.Selected;
                 if (!logicalFolders.Contains(selectedFolder))
                 {
                     logicalFolders.Remove(folderToEdit);
                     lvFolders.Items.Remove(oldListViewItem);
                     logicalFolders.Add(selectedFolder);
                     lvFolders.Items.Add(createListView(selectedFolder));
                 }
                 else
                 {
                     MessageBox.Show(string.Format("This item already belongs to \"{0}\" folder.", selectedFolder.PathAndName), ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                 }
             }
         }
     }
 }
Exemple #2
0
        private static void WriteLFold(SQLiteConnection conn, LogicalFolder lfold, int parent = 0)
        {
            using (var cmd = conn.CreateCommand())
            {
                /*
                 * [ID] INTEGER NOT NULL PRIMARY KEY,
                 * [Owner] INTEGER NOT NULL,
                 * [Name] TEXT,
                 * [Desc] TEXT,
                 * [Type] INTEGER
                 */
                cmd.CommandText  = "INSERT INTO [LFold] (Owner, Name, Desc, Type) VALUES (";
                cmd.CommandText += "'" + parent + "',";
                cmd.CommandText += "'" + lfold.Name.Replace("'", "''") + "',";
                cmd.CommandText += "'" + lfold.Description.Replace("'", "''") + "',";
                cmd.CommandText += "'" + (int)lfold.FolderType + "')";

                cmd.ExecuteNonQuery();

                // pass disc id for folders
                cmd.CommandText = "select last_insert_rowid()";
                Int64 lastRowId64 = (Int64)cmd.ExecuteScalar();
                int   lastRowId   = (int)lastRowId64;

                lfold.DbId = lastRowId; // Will need this for logical folder map

                foreach (var subFold in lfold.GetSubFolders())
                {
                    WriteLFold(conn, subFold, lastRowId);
                }
            }
        }
Exemple #3
0
 public void AddFolder(LogicalFolder subFolder)
 {
     if (IsPartOfDvd() && (subFolder.folderType != LogicalFolderType.GeneralFolder))
     {
         throw new ApplicationException("Bad folder type.");
     }
     subFolders.Add(subFolder);
     subFolder.parent = this;
 }
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (lvFolders.SelectedItems.Count > 0)
     {
         ListViewItem  lvi           = lvFolders.SelectedItems[0];
         LogicalFolder logicalFolder = (LogicalFolder)lvi.Tag;
         logicalFolders.Remove(logicalFolder);
         lvFolders.Items.Remove(lvi);
     }
 }
Exemple #5
0
        private static void HookupParent(LogicalFolder child, int ownerId, List <LogicalFolder> foldlist)
        {
            // Connect a sub-folder to its parent
            var parent = foldlist.FirstOrDefault(f => f.DbId == ownerId);

            if (parent == null)
            {
                return; // shouldn't happen!
            }
            parent.AddFolder(child);
        }
        private static ListViewItem createListView(LogicalFolder folder)
        {
            ListViewItem lvi = new ListViewItem(folder.PathAndName);

            lvi.Tag = folder;
            //if (folder.InDvdFolder())
            if (folder.IsPartOfDvd())
            {
                lvi.ImageIndex = (int)LogicalFolderType.DiscCatalog;
            }
            else
            {
                lvi.ImageIndex = (int)folder.FolderType;
            }
            return(lvi);
        }
Exemple #7
0
        private static void WriteLFoldMap(SQLiteConnection conn, LogicalFolder lfold)
        {
            // Write the mapping between logical folders and items in them.
            // This code depends on each object's DbId having been updated
            // earlier in the write process.

//[ID] INTEGER NOT NULL PRIMARY KEY,
//[LFold] INTEGER NOT NULL,
//[ItemId] INTEGER NOT NULL,
//[ItemType] INTEGER NOT NULL

            if (_writeLFoldMapCmd == null)
            {
                _writeLFoldMapCmd = new SQLiteCommand(conn);
                const string sql = "insert into [LFoldMap] (LFold,ItemId,ItemType) VALUES (@lfold,@item,@type)";
                _writeLFoldMapCmd.CommandText = sql;
            }

            foreach (var iid in lfold.Items)
            {
                _writeFileCmd.Parameters.Clear();

                _writeLFoldMapCmd.Parameters.Add("@lfold", DbType.Int32).Value = lfold.DbId;
                _writeLFoldMapCmd.Parameters.Add("@item", DbType.Int32).Value  = iid.DbId;
                int itemType = 1; // assume folder (regular)
                if (iid is CompressedFile)
                {
                    itemType = 1;
                }
                else if (iid is FileInDatabase)
                {
                    itemType = 2;
                }
                else if (iid is DiscInDatabase)
                {
                    itemType = 3;
                }
                _writeLFoldMapCmd.Parameters.Add("@type", DbType.Int16).Value = itemType;

                _writeLFoldMapCmd.ExecuteNonQuery();
            }

            foreach (var subf in lfold.GetSubFolders())
            {
                WriteLFoldMap(conn, subf);
            }
        }
Exemple #8
0
        private static void ReadLogicalFolderItems(SQLiteConnection conn, VolumeDatabase mem)
        {
            string txt = "SELECT * FROM [LFoldMap]";

            using (SQLiteCommand cmd = new SQLiteCommand(txt, conn))
            {
                using (SQLiteDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        int lFoldId = rdr.GetInt32(1);
                        int iidId   = rdr.GetInt32(2);
                        int typeId  = rdr.GetInt16(3);

                        LogicalFolder  lfold = _lfoldHash[lFoldId] as LogicalFolder;
                        ItemInDatabase iid   = null;
                        switch (typeId)
                        {
                        case 1:
                            // folder
                            iid = _foldHash[iidId] as ItemInDatabase;
                            break;

                        case 2:
                            // file
                            iid = _fileHash[iidId] as ItemInDatabase;
                            break;

                        case 3:
                            // disc. brute it.
                            foreach (var discInDatabase in mem.GetDiscs())
                            {
                                if (-discInDatabase.DbId == iidId)
                                {
                                    iid = discInDatabase as ItemInDatabase;
                                    break;
                                }
                            }
                            break;
                        }

                        lfold.AddItem(iid); // TODO make sure the two-way mapping is set!
                    }
                }
            }
        }
Exemple #9
0
        public DlgEditLogicalFolder(LogicalFolderInfo info, ImageList imageList, LogicalFolder parent)
            : this()
        {
            toEdit = info;
            tbLogicalFolderName.Text = info.Name;
            this.parent = parent;
            if (parent == null)
            {
                llParentFolder.Text         = "(root)";
                tbLogicalFolderName.Enabled = false;
            }
            else
            {
                llParentFolder.Text = parent.Name;
            }
            tbDescription.Text    = toEdit.Description;
            tbDiscSize.Text       = toEdit.MaxSize.ToString();
            cbSizes.SelectedIndex = info.MaxSizeSelected;

            string folderTypeName;

            switch (info.FolderType)
            {
            case LogicalFolderType.Disc: folderTypeName = "Disc"; break;

            case LogicalFolderType.DiscCatalog: folderTypeName = "Disc Catalog"; break;

            case LogicalFolderType.Flag: folderTypeName = "Flag"; break;

            case LogicalFolderType.GeneralFolder: folderTypeName = "General Folder"; break;

            case LogicalFolderType.Person: folderTypeName = "Person"; break;

            case LogicalFolderType.PhysicalLocation: folderTypeName = "Physical Location"; break;

            case LogicalFolderType.VolumeType: folderTypeName = "Volume Type"; break;

            default: folderTypeName = "Unknown"; break;
            }
            int   imageIndex = (int)info.FolderType;
            Image icon       = imageList.Images[imageIndex];

            pbFolderType.Image = icon;
            llFolderType.Text  = folderTypeName;
        }
Exemple #10
0
        internal void AddItemAsDvd(IFolder folderInDatabase)
        {
            LogicalFolder newFolder = new LogicalFolder((folderInDatabase as ItemInDatabase).Name, LogicalFolderType.Disc, 0, 0);

            AddFolder(newFolder);
            foreach (FileInDatabase file in folderInDatabase.Files)
            {
                newFolder.AddItem(file);
            }
            foreach (IFolder folder in folderInDatabase.Folders)
            {
                if (folder is FolderInDatabase)
                {
                    // nie dodajemy CompressedFile
                    newFolder.AddItemAsFolder(folder, null);
                }
            }
        }
Exemple #11
0
        internal void AddItemAsFolder(IFolder folderInDatabase, string asName)
        {
            LogicalFolder newFolder = new LogicalFolder(folderType, asName != null ? asName : (folderInDatabase as ItemInDatabase).Name);

            AddFolder(newFolder);
            foreach (FileInDatabase file in folderInDatabase.Files)
            {
                newFolder.AddItem(file);
            }
            foreach (IFolder folder in folderInDatabase.Folders)
            {
                if (folder is FolderInDatabase)
                {
                    // nie dodajemy CompressedFile
                    newFolder.AddItemAsFolder(folder, null);
                }
            }
        }
 private bool selectInNodes(TreeNodeCollection treeNodeCollection, LogicalFolder folder)
 {
     foreach (TreeNode node in treeNodeCollection)
     {
         if (node.Tag == folder)
         {
             node.EnsureVisible();
             tvLogicalFolders.SelectedNode = node;
             return(true);
         }
         else
         if (selectInNodes(node.Nodes, folder))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #13
0
        private static void ReadLogicalFolders(SQLiteConnection conn, VolumeDatabase mem)
        {
            var lFoldList = mem.GetLogicalFolders();

            // Note: order by owner insures that sub-folders are after their parents and hookup works
            string txt = "select * from LFold ORDER BY Owner";

            using (SQLiteCommand cmd = new SQLiteCommand(txt, conn))
            {
                using (SQLiteDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
/*
 * [ID] INTEGER NOT NULL PRIMARY KEY,
 * [Owner] INTEGER NOT NULL,
 * [Name] TEXT,
 * [Desc] TEXT,
 * [Type] INTEGER
 */
                        LogicalFolder lfold = new LogicalFolder();
                        lfold.DbId        = rdr.GetInt32(0);
                        lfold.Name        = rdr.GetString(2);
                        lfold.Description = rdr.GetString(3);
                        lfold.FolderType  = (LogicalFolderType)rdr.GetInt32(4);

                        int owner = rdr.GetInt32(1);
                        if (owner != 0)
                        {
                            HookupParent(lfold, rdr.GetInt32(1), lFoldList);
                        }
                        else
                        {
                            lFoldList.Add(lfold);
                        }
                        _lfoldHash.Add(lfold.DbId, lfold);
                    }
                }
            }
        }
Exemple #14
0
        internal void SetSubFoldersAsGeneral()
        {
            List <FolderInDatabase> foldersToChange = new List <FolderInDatabase>();

            foreach (ItemInDatabase item in items)
            {
                if (item is FolderInDatabase)
                {
                    foldersToChange.Add(item as FolderInDatabase);
                }
            }
            foreach (FolderInDatabase folderToChange in foldersToChange)
            {
                RemoveItem(folderToChange);
                LogicalFolder newFolder = new LogicalFolder(folderToChange.Name, LogicalFolderType.GeneralFolder, 0, 0);
                AddFolder(newFolder);
            }
            foreach (LogicalFolder subFolder in subFolders)
            {
                subFolder.FolderType = LogicalFolderType.GeneralFolder;
                subFolder.MaxSize    = 0;
                subFolder.SetSubFoldersAsGeneral();
            }
        }
Exemple #15
0
 public void RemoveFolder(LogicalFolder subFolder)
 {
     subFolders.Remove(subFolder);
     // subFolder.parent = null;
     subFolder.Delete();
 }
Exemple #16
0
 public void RemoveLogicalFolder(LogicalFolder folder)
 {
     logicalFolders.Remove(folder);
     folder.Delete();
 }
Exemple #17
0
 public void AddLogicalFolder(LogicalFolder folder)
 {
     logicalFolders.Add(folder);
     folder.Parent = null;
 }
Exemple #18
0
 public DropInfo(TreeNode targetNode, List <ItemInDatabase> items, LogicalFolder logicalFolder)
 {
     this.targetNode    = targetNode;
     this.items         = items;
     this.logicalFolder = logicalFolder;
 }