AlbumManager类 (windows forms 编程实战 学习笔记)

通过AlbumManager类同用户界面进行交互

很清楚的将用户界面可以完成的任务放在一个单独的类中,以保证Photograph和PhotoAlbum类的纯洁性。

在大型企业级系统中,这种类常常称作边界类

  1文件和常用对话框
  2
  3vs自带了一个标准菜单,可以在标准菜单的基础上进行更改,也可以自定义
  4菜单。
  5
  6定义相册管理类AlbumManager,是逻辑更加清晰。用户界面中通过这个类同相册进行交互。
  7这样可以保持Photograph 和 PhotoAlbum类的纯洁性。
  8
  9在大型企业级系统中,这种类常常称作边界类
 10
 11using System.Drawing;
 12using System.IO;
 13
 14namespace Manning.MyPhotoAlbum
 15{
 16    public class AlbumManager
 17    {
 18        static private  string  _defaultPath;
 19        static public  string DefaultPath
 20        {
 21            get
 22            {
 23                return _defaultPath;
 24            }

 25            set
 26            {
 27                _defaultPath=value;
 28            }

 29        }

 30        
 31        static AlbumManager()
 32        {
 33            _defaultPath=Environement.GetFolderPath(Environemnt.SpecialFolder.Person)+@"\Albums";
 34        }

 35        
 36        private int _pos=-1;
 37        private string _name=String.Empty;
 38        private PhotoAlbum  _album;
 39        
 40        public AlbumManager()
 41        {
 42            _album=new PhotoAlbum();
 43        }

 44        
 45        public albumManager(string name):this()
 46        {
 47            _name=name;
 48            throw  new  NotImplementedException();
 49        }

 50        
 51        public PhotoAlbum Album
 52        {
 53            get
 54            {
 55                return _album;
 56            }

 57        }

 58        
 59        public string FullName
 60        {
 61            get
 62            {
 63                return _name;
 64            }

 65            private set
 66            {
 67                _name=value;
 68            }

 69        }

 70        
 71        public string  ShortName
 72        {
 73            get
 74            {
 75            if(String.IsNullOrEmpty(FullName))
 76                return null;
 77            else
 78            return Path.GetFileNameWithoutExtension(FullName);
 79                }

 80        }

 81        
 82        public Photograph Current
 83        {
 84            get
 85            {
 86                if(Index<0 || Index>=Album.Count)
 87                {
 88                    return null;
 89                }

 90                return Album[_pos];
 91            }

 92        }

 93        
 94        public Bitmap CurrentImage
 95        {
 96            get
 97            {
 98                if(Current==null)
 99                {
100                    return null;
101                }

102                return Current.Image;
103            }

104        }

105        
106        public int Index
107        {
108            get
109            {
110                int count=Album.Count;
111                if(_pos>=count)
112                    _pos=count-1;
113                
114                return _pos;
115            }

116            set
117            {
118                if(value<0 || value>=Album.Count)
119                    throw  new IndexOutOfRangeException("The given index is out of bounds");
120                _pos=value;
121            }

122        }

123        
124        
125        
126        static public  bool albumExists(string name)
127        {
128             //Todo :implement  albumExists method
129            
130            return false;
131        }

132        
133        public void Save()
134        {
135            //Todo: Implement Save method
136            
137            throw  new NotImplementedException();
138        }

139        public void Save(string name, bool overwrite)
140        {
141            //Todo:Implement Save(name) method
142            
143            throw new NotImplementedException();
144        }

145        
146        public bool MoveNext()
147        {
148            if(Index>=album.Count)
149                return false;
150            
151            Index++;
152            
153            return true;
154        }

155        
156        public bool MovePrev()
157        {
158            if(Index<=0)
159                return false;
160            
161            Index--;
162            return true;
163        }

164    }

165}

166        
posted on 2007-12-29 17:32  蓝蓝的天2016  阅读(240)  评论(0)    收藏  举报