/// <summary> /// Adds a new object to the collection. /// </summary> /// <param name="key">The key of the object.</param> /// <param name="obj">The object to add</param> protected void Add(KeyBase key, PhotoObjectBase obj) { innerList.Add(key, obj); // Keep a map of the keys to the IDs keyMap.Add(obj.Id, key); }
protected int GetIdentityValue(PhotoObjectBase obj) { IDbCommand command = this.GetCommand(); command.CommandText = "SELECT @@IDENTITY"; int id = (int)command.ExecuteScalar(); obj.SetId(id); return(id); }
internal override void Delete(PhotoObjectBase obj) { PhotoDirectory directory = (PhotoDirectory)obj; IDbCommand command = base.GetCommand(); command.CommandText = "DELETE FROM tblDirectories WHERE ID = ?"; command.Parameters.Add(base.CreateIntParam("ID", directory.Id)); if (command.ExecuteNonQuery() != 1) { throw new Exception("Attempted to delete a PhotoDirectory record that did not exit"); } }
private void InitPage(HttpRequest request) { DirectoryBrowser dirBrowser = (DirectoryBrowser)Session["photo_DirectoryBrowser"]; PhotoDirectory CurrentDirectory = (PhotoDirectory)Session["photo_CurrentDirectory"]; if (dirBrowser == null || request.Params["method"] == null) { // string photosPath = request.ApplicationPath + Path.DirectorySeparatorChar; string mappedPhotosDbPath = request.MapPath("") + "\\photos"; if (Session["photo_rootpath"] == null) { Response.Write("错误的参数,通知管理员此异常现象"); Response.End(); } string path = (string)Session["photo_rootpath"]; dirBrowser = new DirectoryBrowser(mappedPhotosDbPath, path); } Hashtable directoryLookup = (Hashtable)Session["photo_DirectoryLookup"]; if (directoryLookup == null) { directoryLookup = new Hashtable(); } DisplayTreeview(dirBrowser, directoryLookup); // expand out the current directory node int directoryID = -1; if (CurrentDirectory != null) { directoryID = CurrentDirectory.Id; } else if (request.Params["directoryID"] != null) { directoryID = Int32.Parse(request.Params["directoryID"]); } else { PhotoObjectBase pd1 = dirBrowser.rootDir.GetByIndex(0); directoryID = pd1.Id; } squishyWARE.WebComponents.squishyTREE.TreeNode node = tvwMain.FindTreeNode(directoryID.ToString()); ExpandNode(node); Session.Add("photo_DirectoryBrowser", dirBrowser); Session.Add("photo_DirectoryLookup", directoryLookup); // Must be called after DisplayTreeview ProcessMethod(request, directoryLookup, directoryID); }
/// <summary> /// Deletes a photo from the database. Note that this does not delete any associated comments. /// </summary> /// <param name="obj">A Photo object representing the photo to be deleted.</param> internal override void Delete(PhotoObjectBase obj) { Photo photo = (Photo)obj; IDbCommand cmd = GetCommand(); cmd.CommandText = "DELETE FROM tblPhotos WHERE ID = " + photo.Id; //cmd.Parameters.Add(CreateIntParam("ID", photo.Id)); int rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected != 1) { throw new Exception("Attempted to delete a Photo record that does not exist"); } }
internal override void Delete(PhotoObjectBase obj) { throw new NotImplementedException("Cannot delete comment objects"); }
protected override KeyBase CreateKey(PhotoObjectBase obj) { Comment comment = (Comment)obj; return(new CommentKey(comment.Id, comment.Name, comment.DateAdded)); }
protected override KeyBase CreateKey(PhotoObjectBase obj) { Photo photo = (Photo)obj; return(new PhotoKey(photo.Id, photo.DateTaken, photo.Name)); }
/// <summary> /// Creates the collection key based on a PhotoDirectory object. /// </summary> /// <param name="obj">The PhotoDirectory object who's collection key we want.</param> /// <returns>A PhotoDirectoryKey object.</returns> protected override KeyBase CreateKey(PhotoObjectBase obj) { PhotoDirectory photoDirectory = (PhotoDirectory)obj; return(new PhotoDirectoryKey(photoDirectory.Id, photoDirectory.Name)); }
/// <summary> /// Creates a KeyBase object that is used to store PhotoObjectBase objects in /// the collection. /// </summary> /// <param name="obj">The object to create the key for.</param> /// <returns>A KeyBase object.</returns> protected abstract KeyBase CreateKey(PhotoObjectBase obj);
/// <summary> /// Returns the zero-based index of the specified key in the PhotosCollectionBase. /// </summary> /// <param name="key">The key to locate in the PhotosCollectionBase. </param> /// <returns>The zero-based index of key, if key is found in the PhotosCollectionBase; otherwise, -1.</returns> public int IndexOf(PhotoObjectBase obj) { KeyBase key = CreateKey(obj); return(innerList.IndexOfKey(key)); }
internal abstract void Delete(PhotoObjectBase obj);
protected void Add(KeyBase key, PhotoObjectBase obj) { this.innerList.Add(key, obj); this.keyMap.Add(obj.Id, key); }