08年,我的软件框架.
08年,公司没什么项目做,本人主要从事软件框架编写。个人认为,做管理软件不需要什么高深的算法和技术,做的都是些Copy->Paste的工作,在程序保证质量的情况下,代码写得优雅一点就可以了!在上次写的<程序员,回头是岸>的文章中,看了很多回复,反思了一下,希望我的情绪不会影响到大家对程序的执着!就如一些兄弟回复一样,我五年的工作经历到现在一事无成,是我个人问题。确实,我从没有去怪任何一个人,我只怪我的环境,同时希望和我一样环境的程序员能或多或少有些感悟和定位。虽然通过五年的辛苦中,没有什么成绩,自认为自己的生活和技术还是有了很大的跨度。生活中我确实是一个小角色,不是什么老板,一直被老板直接领导,这种情况或将继续;也没有下级,只有一个团队,一帮在一起混的程序员兄弟,各自做着不一样的工作!先前做了一些实施工作,由于ERP不好实施也不好签单,后来转入后台做架构设计了。还好老板有政府背景,公司在运作上基本不缺钱,所以,一直给了我一个学习的环境,没项目做思维上有些空洞、精神上有些空虚!感觉程序员跟着Microsoft很累,技术更新太快了,前两年还在用.net 2.0,后面又有了.net 3.5,不过.net3.5的wcf和Linq还是特别强大,现在Microsoft准备推出.Net 4.0。学了很久的SOA也不知所云,最后利用WCF实现了分布式应用程序,实现了服务对外的发布,然后写了一些基础组件。最近没事做,花了一些时间整理了c/s和b/s框架,很多地方设计得还不是很成熟,希望大家给点意见和建议。
1、代码自动生成工具(DataEntity)
很多业务实体生成工具一般都是通过数据库反向工程生成代码。DataEntity主要是根据功能需求,设计出数据字段和关系,然后根据字段生成相应的代码。通过工具可以生成Oracle、SQLServer数据库、生成数据库描述(数据字典)、生成业务实体(Entitiy)、生成数据层(DAL)、生成服务层(Service)、生成表示层(UI)、生成VS.NET 2008解决方案。
2、C/S控制台
控制台应用程序通过模块维护和权限维护动态添加。
3、B/S控制台
控制台应用程序通过模块维护和权限维护动态添加,展示B/S主从表的数据浏览和编辑操作。
4、N层结构
1)、业务实体层
///<summary>
///产品结存初始化
///</summary>
[DataContract()]
public partial class TBProductInit :GR.Common.Entity
{
#region 私有变量
private Guid _PK01;
private string _Code;
private DateTime? _ActDate;
private int _EmployeeID;
private int _WarehouseID;
private string _Remark;
private SystemMgr.Entities.TBEmployee _Employee = new SystemMgr.Entities.TBEmployee();
private SystemMgr.Entities.TBWarehouse _Warehouse = new SystemMgr.Entities.TBWarehouse();
private GR.Common.EntitySet<WarehouseMgr.Entities.TBProductInitItem> _TBProductInitItem = new GR.Common.EntitySet<WarehouseMgr.Entities.TBProductInitItem>();
#endregion
#region 实体属性
///<summary>
///-
///</summary>
[DataMember()]
[System.ComponentModel.Browsable(false)]
public Guid PK01
{
get{return _PK01;}
set{this._PK01 = value;}
}
///<summary>
///单据编号
///</summary>
[DataMember()]
public string Code
{
get{return _Code;}
set{this._Code = value;}
}
///<summary>
///记帐日期
///</summary>
[DataMember()]
public DateTime? ActDate
{
get{return _ActDate;}
set{this._ActDate = value;}
}
///<summary>
///公司员工信息登记
///</summary>
[DataMember()]
[System.ComponentModel.Browsable(false)]
public int EmployeeID
{
get{return _EmployeeID;}
set{this._EmployeeID = value;}
}
///<summary>
///对各片区的分库房进行管理。
///</summary>
[DataMember()]
[System.ComponentModel.Browsable(false)]
public int WarehouseID
{
get{return _WarehouseID;}
set{this._WarehouseID = value;}
}
///<summary>
///备注
///</summary>
[DataMember()]
public string Remark
{
get{return _Remark;}
set{this._Remark = value;}
}
///<summary>
///公司员工信息登记
///</summary>
[DataMember()]
[System.ComponentModel.Browsable(false)]
public SystemMgr.Entities.TBEmployee Employee
{
get{return _Employee;}
set{this._Employee = value;}
}
///<summary>
///对各片区的分库房进行管理。
///</summary>
[DataMember()]
[System.ComponentModel.Browsable(false)]
public SystemMgr.Entities.TBWarehouse Warehouse
{
get{return _Warehouse;}
set{this._Warehouse = value;}
}
///<summary>
///产品结存初始化明细
///</summary>
[DataMember()]
[System.ComponentModel.Browsable(false)]
public GR.Common.EntitySet<WarehouseMgr.Entities.TBProductInitItem> TBProductInitItem
{
get{return _TBProductInitItem;}
set{this._TBProductInitItem = value;}
}
#endregion
#region Overrides
public override bool Equals(object obj)
{
if(obj == null)
return false;
if(!obj.GetType().IsAssignableFrom(this.GetType()))
return false;
if(!(obj as TBProductInit).PK01.Equals(_PK01))
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
#endregion
}
2)、数据层
#region TBProductInit -- DataProvider
public virtual int TBProductInitInsertOrUpdate(TBProductInit entity, DbTransaction tran)
{
//TODO:初始化行标识列
int iEffectedRow = 0;
string tableName = "TBProductInit";
string[] Cols = new string[] {"PK01","Code","ActDate","EmployeeID","WarehouseID","Remark"};
object[] values = new object[] {entity.PK01,entity.Code,entity.ActDate,entity.EmployeeID,entity.WarehouseID,entity.Remark};
string where = string.Empty;
try{
switch(entity.RowAction){
case ActionType.Insert:
iEffectedRow = Gateway.Default.Insert(tableName, Cols, values,tran);
//TODO:自动增量识列
return iEffectedRow;
case ActionType.Update:
where = BuildEqualWhereStr(new string[] {"PK01"});
iEffectedRow = Gateway.Default.Update(tableName, Cols, values, where, new object[] {entity.PK01},tran);
return iEffectedRow;
case ActionType.Delete:
where = BuildEqualWhereStr(new string[] {"PK01" });
iEffectedRow = Gateway.Default.Delete(tableName, where, new object[] {entity.PK01},tran);
return iEffectedRow;
}
}
catch (Exception ex){
throw ex;
}
return 0;
}
public TBProductInit GetTBProductInit(Guid PK01)
{
string queryString = "PK01=" + Gateway.Default.Db.DbProvider.BuildColumn("PK01") ;
object[] values = new object[] { PK01 };
try
{
return TBProductInits(queryString, values).SingleOrDefault();
}
catch (Exception ex) { throw ex; };
}
public virtual List<TBProductInit> TBProductInits()
{
return TBProductInits(string.Empty);
}
public virtual List<TBProductInit> TBProductInits(string query)
{
return TBProductInits(query,null);
}
public virtual List<TBProductInit> TBProductInits(string query,object[] paramValues)
{
List<TBProductInit> values = new List<TBProductInit>();
string tableName = "TBProductInit";
using (IDataReader dr = Gateway.Default.Select(tableName,query, paramValues))
{
while (dr.Read())
values.Add(PopulateTBProductInit(dr) as TBProductInit);
}
AssignEntitySetForTBProductInit(values);
return values;
}
public virtual List<TBProductInit> TBProductInits(int PageIndex,int PageSize,string queryString)
{
List<TBProductInit> values = new List<TBProductInit>();
string tableName = "TBProductInit";
string orderBy = "Code";
using (IDataReader dr = Gateway.Default.Select(tableName, PageIndex, PageSize,queryString,orderBy,true))
{
while (dr.Read())
values.Add(PopulateTBProductInit(dr) as TBProductInit);
}
AssignEntitySetForTBProductInit(values);
return values;
}
protected object PopulateTBProductInit(IDataReader dr)
{
TBProductInit entity = new TBProductInit();
if (!Convert.IsDBNull(dr["PK01"]))entity.PK01 = new Guid(dr["PK01"].ToString());//主键---
if (!Convert.IsDBNull(dr["Code"]))entity.Code = Convert.ToString(dr["Code"]);//单据编号
if (!Convert.IsDBNull(dr["ActDate"]))entity.ActDate = Convert.ToDateTime(dr["ActDate"]);//记帐日期
if (!Convert.IsDBNull(dr["EmployeeID"]))entity.EmployeeID = Convert.ToInt32(dr["EmployeeID"]);//库管员--公司员工信息登记
if (!Convert.IsDBNull(dr["WarehouseID"]))entity.WarehouseID = Convert.ToInt32(dr["WarehouseID"]);//库房信息--对各片区的分库房进行管理。
if (!Convert.IsDBNull(dr["Remark"]))entity.Remark = Convert.ToString(dr["Remark"]);//备注
return entity;
}
protected void AssignEntitySetForTBProductInit(List<TBProductInit> values)
{
List<object> employeeList = new List<object>();
List<object> warehouseList = new List<object>();
var q0 = (from p in values select p.EmployeeID).Distinct().ToArray();
foreach (var v in q0.ToList())
employeeList.Add(v);
var q1 = (from p in values select p.WarehouseID).Distinct().ToArray();
foreach (var v in q1.ToList())
warehouseList.Add(v);
List<SystemMgr.Entities.TBEmployee> _Employee = (new SystemMgr.DAL.SqlDataProvider()).TBEmployees(BuildInStatementToOrStatement("ID", employeeList.ToArray()), employeeList.ToArray());
List<SystemMgr.Entities.TBWarehouse> _Warehouse = (new SystemMgr.DAL.SqlDataProvider()).TBWarehouses(BuildInStatementToOrStatement("ID", warehouseList.ToArray()), warehouseList.ToArray());
foreach (TBProductInit entity in values)
{
List<TBProductInitItem> _TBProductInitItem = TBProductInitItems(BuildInStatementToOrStatement("PK02", new object[] { entity.PK01 }), new object[] { entity.PK01 });
entity.Employee = _Employee.SingleOrDefault(p => p.ID == entity.EmployeeID);
entity.Warehouse = _Warehouse.SingleOrDefault(p => p.ID == entity.WarehouseID);
entity.TBProductInitItem.Assign(_TBProductInitItem.Where(p => p.PK02 == entity.PK01),true);
}
}
public virtual int TBProductInitsRowCount(string queryString)
{
string tableName = "TBProductInit";
string whereStr = string.IsNullOrEmpty(queryString) ? string.Empty : " WHERE " + queryString;
string cmdText = string.Format("SELECT COUNT(*) FROM {0} {1}",tableName,whereStr);
return Gateway.Default.SelectScalar<int>(cmdText);
}
public virtual int TBProductInitsPos(TBProductInit entity,string queryString)
{
string tableName = "TBProductInit";
string orderField = "Code";
string whereStr = string.IsNullOrEmpty(queryString) ? string.Empty : " AND " + queryString;
string cmdText = string.Format("SELECT COUNT(*) FROM {0} WHERE {1}>={2} {3}", tableName, Gateway.Default.Db.DbProvider.BuildColumn(orderField), Gateway.Default.Db.DbProvider.BuildParamColumn(orderField),whereStr);
return Gateway.Default.SelectScalar<int>(cmdText,new object[]{entity.Code});
}
#endregion
3)、业务逻辑层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Linq.Dynamic;
using GR.Data;
using GR.Common;
using WarehouseMgr.Entities;
using WarehouseMgr.DAL;
using WarehouseMgr.Contract;
namespace WarehouseMgr.Services
{
public partial class TBProductInits : GR.Common.Services.ServiceBase, ITBProductInit
{
SqlDataProvider db = null;
public TBProductInits()
{
db = new SqlDataProvider();
}
public override object InitializeLifetimeService()
{
return null;
}
public void Create(TBProductInit entity)
{
try
{
entity.SetAttached();
Save(entity);
}
catch (Exception ex) { throw ex; };
}
public void Update(TBProductInit entity)
{
try
{
entity.SetModified();
Save(entity);
}
catch (Exception ex) { throw ex; };
}
public void Delete(TBProductInit entity)
{
try
{
entity.SetDetach();
Save(entity);
}
catch (Exception ex) { throw ex; };
}
public List<TBProductInit> GetEntities()
{
try
{
return db.TBProductInits().ToList();
}
catch (Exception ex) { throw ex; };
}
public List<TBProductInit> GetEntitiesByPageIndex(int PageIndex, int PageSize, string queryString)
{
try
{
return db.TBProductInits(PageIndex,PageSize,queryString);
}
catch (Exception ex) { throw ex; };
}
public int GetEntityPos(TBProductInit entity, string queryString)
{
try
{
return db.TBProductInitsPos(entity,queryString);
}
catch (Exception ex) { throw ex; };
}
public int GetEntityCount(string queryString)
{
try
{
return db.TBProductInitsRowCount(queryString);
}
catch (Exception ex) { throw ex; };
}
public List<TBProductInit> Find(string queryString)
{
try
{
Expression<Func<TBProductInit, bool>> expr = DynamicExpression.ParseLambda<TBProductInit, bool>(queryString);
List<TBProductInit> values = GetEntities().Where(expr.Compile()).ToList();
return values.ToList();
}
catch (Exception ex) { throw ex; };
}
private void Save(TBProductInit entity)
{
System.Data.Common.DbTransaction tran = GR.Data.Gateway.Default.DbHelper.BeginTransaction();
try
{
switch (entity.RowAction)
{
case ActionType.Insert:
case ActionType.Update:
db.TBProductInitInsertOrUpdate(entity, tran);
foreach (TBProductInitItem item in entity.TBProductInitItem.GetChangedList())
{
db.TBProductInitItemInsertOrUpdate(item, tran);
}
break;
case ActionType.Delete:
foreach (TBProductInitItem item in entity.TBProductInitItem.GetList())
{
item.SetDetach();
db.TBProductInitItemInsertOrUpdate(item, tran);
}
db.TBProductInitInsertOrUpdate(entity, tran);
break;
}
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
throw ex;
}
finally
{
tran.Dispose();
}
}
public void Dispose()
{
}
}
}
4)、服务调用层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using GR.Common;
using GR.Common.MVP;
using GR.SystemFrameworks;
using WarehouseMgr.Entities;
using WarehouseMgr.Contract;
namespace WarehouseMgr.Domain
{
public partial class EM_TBProductInits : IEntityModal<TBProductInit>
{
static ITBProductInit service = ServiceFactory.Default.GetServices<ITBProductInit>("WarehouseMgr", "TBProductInits");
public void Create(TBProductInit entity)
{
try
{
service.Create(entity);
}
catch (FaultException ex) { throw new Exception(ex.Message); };
}
public void Update(TBProductInit entity)
{
try
{
service.Update(entity);
}
catch (FaultException ex) { throw new Exception(ex.Message); };
}
public void Delete(TBProductInit entity)
{
try
{
service.Delete(entity);
}
catch (FaultException ex) { throw new Exception(ex.Message); };
}
public List<TBProductInit> GetEntities()
{
List<TBProductInit> values = new List<TBProductInit>();
try
{
values = service.GetEntities();
}
catch (FaultException ex) { throw new Exception(ex.Message); };
return values;
}
public List<TBProductInit> GetEntities(int PageIndex, int PageSize, string query)
{
List<TBProductInit> values = new List<TBProductInit>();
try
{
values = service.GetEntitiesByPageIndex(PageIndex, PageSize, query);
}
catch (FaultException ex) { throw new Exception(ex.Message); };
return values;
}
public List<TBProductInit> Find(string queryString)
{
List<TBProductInit> values = new List<TBProductInit>();
try
{
values = service.Find(queryString);
}
catch (FaultException ex) { throw new Exception(ex.Message); };
return values;
}
public int GetEntityCount(string queryString)
{
return service.GetEntityCount(queryString);
}
public int GetEntityPos(TBProductInit entity,string queryString)
{
return service.GetEntityPos(entity,queryString);
}
}
}

浙公网安备 33010602011771号