ACCESS面向接口开发的二个架构(三)

政工逻辑层

一、IBusinessFacade:定义业务逻辑接口

IBusinessBase.cs

ACCESS 1ACCESS 2IBusinessBase
 1ACCESS 3namespace IBusinessFacade
 2ACCESS 4ACCESS 5ACCESS 6{
 3ACCESS 7    public interface IBusinessBase
 4ACCESS 8ACCESS 9    ACCESS 10{
 5ACCESS 11        void Init(string type);
 6ACCESS 12        DataSet Get();
 7ACCESS 13        DataSet Get(int id);
 8ACCESS 14        void Add(DataSet ds);
 9ACCESS 15        void Add(string[] temp);
10ACCESS 16        void Delete(int id);
11ACCESS 17        void Update(DataSet ds);
12ACCESS 18    }
13ACCESS 19}

 

ILog.cs

1ACCESS 20namespace IBusinessFacade
2ACCESS 21ACCESS 22ACCESS 23{
3ACCESS 24    public interface ILog : IBusinessBase
4ACCESS 25ACCESS 26    ACCESS 27{
5ACCESS 28        
6ACCESS 29    }
7ACCESS 30}

 

2、BusinessLogic:业务实现层

1、BaseBuiness.cs

ACCESS 31ACCESS 32IBusinessBase
  1ACCESS 33namespace BusinessLogic
  2ACCESS 34ACCESS 35ACCESS 36{
  3ACCESS 37    public class BaseBusiness : IBusinessBase
  4ACCESS 38ACCESS 39    ACCESS 40{
  5ACCESS 41        public string BusinessType = string.Empty;
  6ACCESS 42
  7ACCESS 43        private Assembly assembly;
  8ACCESS 44        private Object obj;
  9ACCESS 45        private const string FAILED_LOAD_ASSEMBLY = “Can’t load assembly.”;
 10ACCESS 46        private const string FAILED_CREATE_CLASS = “Can’t create class”;
 11ACCESS 47        private const string FAILED_ACCESS_STR = “Failed access DAL. return null value.please checked BusinessType or make sure DataAccess assembly in your application folder.”;
 12ACCESS 48
 13ACCESS 49        public BaseBusiness()
 14ACCESS 50ACCESS 51        ACCESS 52{
 15ACCESS 53            assembly = null;
 16ACCESS 54            obj = null;
 17ACCESS 55        }
 18ACCESS 56
 19ACCESS 57        public BaseBusiness(string businessType)
 20ACCESS 58ACCESS 59        ACCESS 60{
 21ACCESS 61            Init(businessType);
 22ACCESS 62        }
 23ACCESS 63
 24ACCESS 64ACCESS 65        IBusinessBase Members#region IBusinessBase Members
 25ACCESS 66
 26ACCESS 67        public void Init(string businessType)
 27ACCESS 68ACCESS 69        ACCESS 70{
 28ACCESS 71            if (string.IsNullOrEmpty(businessType))
 29ACCESS 72ACCESS 73            ACCESS 74{
 30ACCESS 75                throw new Exception(“BusinessType should not be empty!”);
 31ACCESS 76            }
 32ACCESS 77            BusinessType = businessType;
 33ACCESS 78            assembly = Assembly.Load(“DataAccess”);
 34ACCESS 79            if (assembly == null)
 35ACCESS 80ACCESS 81            ACCESS 82{
 36ACCESS 83                throw new Exception(FAILED_LOAD_ASSEMBLY);
 37ACCESS 84            }
 38ACCESS 85            BusinessType = string.Format(“DataAccess.{0}DA”,businessType);
 39ACCESS 86            obj = assembly.CreateInstance(BusinessType);
 40ACCESS 87            if (obj == null)
 41ACCESS 88ACCESS 89            ACCESS 90{
 42ACCESS 91                throw new Exception(FAILED_CREATE_CLASS);
 43ACCESS 92            }
 44ACCESS 93        }
 45ACCESS 94
 46ACCESS 95        public DataSet Get()
 47ACCESS 96ACCESS 97        ACCESS 98{
ACCESS, 48ACCESS 99ACCESS 100            MethodInfo getMethod = assembly.GetType(BusinessType).GetMethod(“Get”,new Type[]ACCESS 101{});
 49ACCESS 102            Object ret = getMethod.Invoke(obj,null);
 50ACCESS 103            if (ret == null)
 51ACCESS 104ACCESS 105            ACCESS 106{
 52ACCESS 107                throw new Exception(FAILED_ACCESS_STR);
 53ACCESS 108            }
 54ACCESS 109            DataSet ds = (DataSet)ret;
 55ACCESS 110            return ds;
 56ACCESS 111        }
 57ACCESS 112
 58ACCESS 113        public System.Data.DataSet Get(int id)
 59ACCESS 114ACCESS 115        ACCESS 116{
 60ACCESS 117ACCESS 118            MethodInfo getMethod = assembly.GetType(BusinessType).GetMethod(“Get”,new Type[]ACCESS 119{typeof(int)});
 61ACCESS 120ACCESS 121            Object ret = getMethod.Invoke(obj, new object[]ACCESS 122{id});
 62ACCESS 123            if (ret == null)
 63ACCESS 124ACCESS 125            ACCESS 126{
 64ACCESS 127                throw new Exception(FAILED_ACCESS_STR);
 65ACCESS 128            }
 66ACCESS 129            DataSet ds = (DataSet)ret;
 67ACCESS 130            return ds;
 68ACCESS 131        }
 69ACCESS 132
 70ACCESS 133        public void Add(DataSet ds)
 71ACCESS 134ACCESS 135        ACCESS 136{
 72ACCESS 137            MethodInfo getMethod = assembly.GetType(BusinessType).GetMethod(“Add”);
 73ACCESS 138ACCESS 139            Object ret = getMethod.Invoke(obj, new object[]ACCESS 140{ds});
 74ACCESS 141            if (ret == null)
 75ACCESS 142ACCESS 143            ACCESS 144{
 76ACCESS 145                throw new Exception(FAILED_ACCESS_STR);
 77ACCESS 146            }
 78ACCESS 147            int result = (int)ret;
 79ACCESS 148            if (result == 0)
 80ACCESS 149ACCESS 150            ACCESS 151{
 81ACCESS 152                throw new Exception(“no record has effected”);
 82ACCESS 153            }
 83ACCESS 154        }
 84ACCESS 155
 85ACCESS 156        public void Delete(int id)
 86ACCESS 157ACCESS 158        ACCESS 159{
 87ACCESS 160            MethodInfo getMethod = assembly.GetType(BusinessType).GetMethod(“Delete”);
 88ACCESS 161ACCESS 162            Object ret = getMethod.Invoke(obj, new object[] ACCESS 163{ id });
 89ACCESS 164            if (ret == null)
 90ACCESS 165ACCESS 166            ACCESS 167{
 91ACCESS 168                throw new Exception(FAILED_ACCESS_STR);
 92ACCESS 169            }
 93ACCESS 170        }
 94ACCESS 171
 95ACCESS 172        public void Update(DataSet ds)
 96ACCESS 173ACCESS 174        ACCESS 175{
 97ACCESS 176            MethodInfo getMethod = assembly.GetType(BusinessType).GetMethod(“Update”);
 98ACCESS 177ACCESS 178            Object ret = getMethod.Invoke(obj, new object[] ACCESS 179{ ds });
 99ACCESS 180            if (ret == null)
100ACCESS 181ACCESS 182            ACCESS 183{
101ACCESS 184                throw new Exception(FAILED_ACCESS_STR);
102ACCESS 185            }
103ACCESS 186        }
104ACCESS 187
105ACCESS 188        #endregion
106ACCESS 189    }
107ACCESS 190}

 

2、LogBusiness.cs

1ACCESS 191namespace BusinessLogic
2ACCESS 192ACCESS 193ACCESS 194{
3ACCESS 195    public class LogBusiness :BaseBusiness, ILog
4ACCESS 196ACCESS 197    ACCESS 198{
5ACCESS 199       
6ACCESS 200    }
7ACCESS 201}

 

ILog和LogBusiness类都以空的,是用来现在方式扩充使用。

相关文章