如何减少基于DataSet框架的代码输入量(一)

       前一段时间看了一阵子的ORM,感觉有单表的都还简单,最头痛的就是如何控制多表关联那些没必要的SQL语句,可能自己还没什么仔细看的缘故吧。
      目前拥有的框架是基于DataSet的,支持多表关联,已经可以彻底的摆脱Insert/Update/Delete语句了,后来又增加了UpdateObject 和 DeleteObject 来减少基于DataSet而能导致的Sql语句执行的次数烦多的缘故。现在为了减少程序员编码的痛苦,同时,又能得到编译时类型控制,往Data层增加Entity,一般是贫血Object,纯粹拥有属性,没有方法的。
        原来是一个DataSet 囊括了构建DataTable的功能。现在增加BaseEntity ,BaseDataTable类。BaseEntity 有一个属性RowIndex ,用来保存对应的行号,如果是新增RowIndex=-1 否则对应行号。BaseDataTable 有3个虚方法:1。获取实体类 public virtual BaseEntity GetEntity(int rowIndex)  2。创建一个实体类 public virtual BaseEntity CreateEntity() 3。 把实体值转入DataRow中 public virtual bool SetEntity(BaseEntity entity)  
       这样,我们就可以使用代码生成器来构建我们需要的对象。
       比如
             OrdersDataSet 需要拥有 OrdersTable ItemsTable DeliveriesTable  OrdersEntity ItemsEntity DeliveriesEntity
             OrdersDataSet 只需要拥有3个Public 的 OrdersTable ItemsTable DeliveriesTable
             OrdersTable 需要Override那三个方法,然后 使用OrdersEntity
             ItemsTable以此类推.....
      
        1.获取实体以及修改保存
                   OrdersEntity entity=ordersDataSet.OrdersTable.GetEntity(0) as OrdersEntity ;
                   Console.WirteLine("Order ID is"+entity.OrderID);
                   entity.Quantity=20;
                  ordersDataSet.OrdersTable.SetEntity(entity);
        2.新增一个实体,并设置值以及保存入表格
                   OrdersEntity newEntity=ordersDataSet.OrdersTable.CreateEntity() as OrdersEntity;
                   newEntity.OrderID="xxxxx";
                   ordersDataSet.OrdersTable.SetEntity(newEntity);
        当然了,如上的代码,如果移植到.Net2.0就可以充分的利用泛型,但是还有几个网站在1.1下, 不敢一下子更换。.........
        通过这种封装,我们可以减少原本基于DataRow的赋值和获取值的麻烦,而且类型也是编译时安全的。
当然了,我知道这不可能时ORM  :)因为我是使用硬编码,只是通过代码生成器可以减少编写这么多麻烦的重复的代码。事实也证明了这种方式的开发的快速性,不过,不够OO,因为是基于Table的。相对来说,对于大企业的大系统不适合,中小企业还可以吧,个人觉得:)
         呵呵,虽然自己的框架不是优秀的,但是,用的习惯了,觉得还是很快的,虽然没有拥有那么多令人骄傲的特色,没有那么OO,但是也足够我自己用了~_~ ! 自己是多么的不求上进,但是依然要写很多Select语句来获取复杂的查询数据。

 sample code 如下:

None.gif using  System;
None.gif
using  FishSky.Data.Base;
None.gif
None.gif
namespace  FishSky.Data.Chateau
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**////<summary>
InBlock.gif    
/// SendOutEntity实体类
ExpandedSubBlockEnd.gif    
///</summary>

InBlock.gif    public class SendOutEntity : BaseEntity
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
构造函数#region 构造函数
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 构造函数
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public SendOutEntity()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
出库单#region 出库单
InBlock.gif
InBlock.gif        
private String mSendOutNo;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 出库单
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public String SendOutNo
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn mSendOutNo; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ mSendOutNo = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
发票号#region 发票号
InBlock.gif
InBlock.gif        
private String mInvoiceNo;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 发票号
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public String InvoiceNo
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn mInvoiceNo; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ mInvoiceNo = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
总计#region 总计
InBlock.gif
InBlock.gif        
private Decimal mAmount;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 总计
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public Decimal Amount
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn mAmount; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ mAmount = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
操作员#region 操作员
InBlock.gif
InBlock.gif        
private String mUserName;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 操作员
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public String UserName
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn mUserName; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ mUserName = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
操作员中文名#region 操作员中文名
InBlock.gif
InBlock.gif        
private String mChineseName;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 操作员中文名
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public String ChineseName
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn mChineseName; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ mChineseName = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
客户代码#region 客户代码
InBlock.gif
InBlock.gif        
private String mCustomerCode;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 客户代码
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public String CustomerCode
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn mCustomerCode; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ mCustomerCode = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
客户中文名#region 客户中文名
InBlock.gif
InBlock.gif        
private String mCustomerName;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 客户中文名
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public String CustomerName
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn mCustomerName; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ mCustomerName = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
备注#region 备注
InBlock.gif
InBlock.gif        
private String mRemark;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 备注
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public String Remark
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn mRemark; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ mRemark = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
货款付讫#region 货款付讫
InBlock.gif
InBlock.gif        
private String mIsPaid;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 货款付讫
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public String IsPaid
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn mIsPaid; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ mIsPaid = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
出售日期#region 出售日期
InBlock.gif
InBlock.gif        
private DateTime mSendOutDate;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        // 出售日期
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**////</summary>
InBlock.gif        public DateTime SendOutDate
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn mSendOutDate; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ mSendOutDate = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

 

 

None.gif using  System;
None.gif
using  System.Data;
None.gif
using  FishSky.Data.Base;
None.gif
None.gif
namespace  FishSky.Data.Chateau
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public class SendOutDataTable : BaseDataTable
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
表格常量#region 表格常量
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 定义对象数据集表名:SendOut
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String TBL_SendOut = "SendOut";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///出库单
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String SendOutNo_SendOut = "SendOutNo";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///发票号
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String InvoiceNo_SendOut = "InvoiceNo";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///总计
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String Amount_SendOut = "Amount";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///操作员
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String UserName_SendOut = "UserName";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///操作员中文名
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String ChineseName_SendOut = "ChineseName";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///客户代码
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String CustomerCode_SendOut = "CustomerCode";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///客户中文名
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String CustomerName_SendOut = "CustomerName";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///备注
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String Remark_SendOut = "Remark";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///货款付讫
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String IsPaid_SendOut = "IsPaid";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///出售日期
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public const String SendOutDate_SendOut = "SendOutDate";
InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion
 
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
构造函数#region 构造函数
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        
/// 构造函数
ExpandedSubBlockEnd.gif        
///</summary>

InBlock.gif        public SendOutDataTable()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.TableName = TBL_SendOut;
InBlock.gif            DataColumnCollection columns 
= this.Columns;
InBlock.gif            DataColumn column;
InBlock.gif            column 
= new DataColumn(SendOutNo_SendOut, typeof (String));
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isPrimaryKeyColumn, 
true);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isSecondaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isValidColumn, 
true);
InBlock.gif            column.MaxLength 
= 50;
InBlock.gif            column.DefaultValue 
= " ";
InBlock.gif            columns.Add(column);
InBlock.gif
InBlock.gif            column 
= new DataColumn(InvoiceNo_SendOut, typeof (String));
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isPrimaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isSecondaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isValidColumn, 
true);
InBlock.gif            column.MaxLength 
= 50;
InBlock.gif            column.DefaultValue 
= " ";
InBlock.gif            columns.Add(column);
InBlock.gif
InBlock.gif            column 
= new DataColumn(Amount_SendOut, typeof (Decimal));
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isPrimaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isSecondaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isValidColumn, 
true);
InBlock.gif            column.DefaultValue 
= 0;
InBlock.gif            columns.Add(column);
InBlock.gif
InBlock.gif            column 
= new DataColumn(UserName_SendOut, typeof (String));
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isPrimaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isSecondaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isValidColumn, 
true);
InBlock.gif            column.MaxLength 
= 20;
InBlock.gif            column.DefaultValue 
= " ";
InBlock.gif            columns.Add(column);
InBlock.gif
InBlock.gif            column 
= new DataColumn(ChineseName_SendOut, typeof (String));
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isPrimaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isSecondaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isValidColumn, 
true);
InBlock.gif            column.MaxLength 
= 50;
InBlock.gif            column.DefaultValue 
= " ";
InBlock.gif            columns.Add(column);
InBlock.gif
InBlock.gif            column 
= new DataColumn(CustomerCode_SendOut, typeof (String));
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isPrimaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isSecondaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isValidColumn, 
true);
InBlock.gif            column.MaxLength 
= 20;
InBlock.gif            column.DefaultValue 
= " ";
InBlock.gif            columns.Add(column);
InBlock.gif
InBlock.gif            column 
= new DataColumn(CustomerName_SendOut, typeof (String));
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isPrimaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isSecondaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isValidColumn, 
true);
InBlock.gif            column.MaxLength 
= 50;
InBlock.gif            column.DefaultValue 
= " ";
InBlock.gif            columns.Add(column);
InBlock.gif
InBlock.gif            column 
= new DataColumn(Remark_SendOut, typeof (String));
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isPrimaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isSecondaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isValidColumn, 
true);
InBlock.gif            column.MaxLength 
= 100;
InBlock.gif            column.DefaultValue 
= " ";
InBlock.gif            columns.Add(column);
InBlock.gif
InBlock.gif            column 
= new DataColumn(IsPaid_SendOut, typeof (String));
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isPrimaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isSecondaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isValidColumn, 
true);
InBlock.gif            column.MaxLength 
= 1;
InBlock.gif            column.DefaultValue 
= " ";
InBlock.gif            columns.Add(column);
InBlock.gif
InBlock.gif            column 
= new DataColumn(SendOutDate_SendOut, typeof (DateTime));
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isPrimaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isSecondaryKeyColumn, 
false);
InBlock.gif            column.ExtendedProperties.Add(BaseConst.isValidColumn, 
true);
InBlock.gif            column.DefaultValue 
= DateTime.Now;
InBlock.gif            columns.Add(column);
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
创建实体#region 创建实体
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        
/// 创建实体
InBlock.gif        
///</summary>
ExpandedSubBlockEnd.gif        
///<returns>实体</returns>

InBlock.gif        public override BaseEntity CreateEntity()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return new SendOutEntity();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
获取指定行号的实体#region 获取指定行号的实体
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        
/// 获取指定行号的实体
InBlock.gif        
///</summary>
InBlock.gif        
/// <param name="rowIndex">行号</param>
ExpandedSubBlockEnd.gif        
/// <returns>实体</returns>

InBlock.gif        public override BaseEntity GetEntity(int rowIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (rowIndex >= 0 && rowIndex <= this.Rows.Count)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                SendOutEntity entity 
= new SendOutEntity();
InBlock.gif                entity.RowIndex 
= rowIndex;
InBlock.gif                DataRow dr 
= this.Rows[rowIndex];
InBlock.gif                entity.SendOutNo 
= dr[SendOutNo_SendOut].ToString();
InBlock.gif                entity.InvoiceNo 
= dr[InvoiceNo_SendOut].ToString();
InBlock.gif                entity.Amount 
= Convert.ToDecimal(dr[Amount_SendOut]);
InBlock.gif                entity.UserName 
= dr[UserName_SendOut].ToString();
InBlock.gif                entity.ChineseName 
= dr[ChineseName_SendOut].ToString();
InBlock.gif                entity.CustomerCode 
= dr[CustomerCode_SendOut].ToString();
InBlock.gif                entity.CustomerName 
= dr[CustomerName_SendOut].ToString();
InBlock.gif                entity.Remark 
= dr[Remark_SendOut].ToString();
InBlock.gif                entity.IsPaid 
= dr[IsPaid_SendOut].ToString();
InBlock.gif                entity.SendOutDate 
= Convert.ToDateTime(dr[SendOutDate_SendOut]);
InBlock.gif                
return entity;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw new ApplicationException("提示:您输入的行号有误!");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
设置实体值到DataTable#region 设置实体值到DataTable
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////<summary>
InBlock.gif        
/// 设置实体值到DataTable
InBlock.gif        
///</summary>
InBlock.gif        
///<param name="baseEntity">实体</param>
ExpandedSubBlockEnd.gif        
///<returns>是否设置成功</returns>

InBlock.gif        public override bool SetEntity(BaseEntity baseEntity)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int rowIndex = baseEntity.RowIndex;
InBlock.gif            SendOutEntity entity 
= baseEntity as SendOutEntity;
InBlock.gif            
if (entity == null)
InBlock.gif                
return false;
InBlock.gif            DataRow dr;
InBlock.gif            
if (rowIndex == -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                dr 
= this.NewRow();
InBlock.gif
InBlock.gif                dr[SendOutNo_SendOut] 
= entity.SendOutNo;
InBlock.gif                dr[InvoiceNo_SendOut] 
= entity.InvoiceNo;
InBlock.gif                dr[Amount_SendOut] 
= entity.Amount;
InBlock.gif                dr[UserName_SendOut] 
= entity.UserName;
InBlock.gif                dr[ChineseName_SendOut] 
= entity.ChineseName;
InBlock.gif                dr[CustomerCode_SendOut] 
= entity.CustomerCode;
InBlock.gif                dr[CustomerName_SendOut] 
= entity.CustomerName;
InBlock.gif                dr[Remark_SendOut] 
= entity.Remark;
InBlock.gif                dr[IsPaid_SendOut] 
= entity.IsPaid;
InBlock.gif                dr[SendOutDate_SendOut] 
= entity.SendOutDate;
InBlock.gif
InBlock.gif                
this.Rows.Add(dr);
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (rowIndex >= 0 && rowIndex < this.Rows.Count)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        dr 
= this.Rows[rowIndex];
InBlock.gif                        
//只要是Key的值都不可以更改
InBlock.gif
                        dr[InvoiceNo_SendOut] = entity.InvoiceNo;
InBlock.gif                        dr[Amount_SendOut] 
= entity.Amount;
InBlock.gif                        dr[UserName_SendOut] 
= entity.UserName;
InBlock.gif                        dr[ChineseName_SendOut] 
= entity.ChineseName;
InBlock.gif                        dr[CustomerCode_SendOut] 
= entity.CustomerCode;
InBlock.gif                        dr[CustomerName_SendOut] 
= entity.CustomerName;
InBlock.gif                        dr[Remark_SendOut] 
= entity.Remark;
InBlock.gif                        dr[IsPaid_SendOut] 
= entity.IsPaid;
InBlock.gif                        dr[SendOutDate_SendOut] 
= entity.SendOutDate;
InBlock.gif                        
return true;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
return false;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return false;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

 

None.gif using  System;
None.gif
using  System.Runtime.Serialization;
None.gif
using  FishSky.Data.Base;
None.gif
None.gif
namespace  FishSky.Data.Chateau
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    [Serializable]
InBlock.gif    
public class SendOutDataSet : BaseDataSet
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
表格常量及数据表#region 表格常量及数据表
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 定义对象数据集表:SendOutDataTable
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public SendOutDataTable SendOutTable = new SendOutDataTable();
InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
构造函数#region 构造函数
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 构造函数
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public SendOutDataSet() : base()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
序列化的构造函数#region 序列化的构造函数
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 序列化的构造函数
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public SendOutDataSet(SerializationInfo info, StreamingContext context) : base(info, context)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
建立数据集的表格#region 建立数据集的表格
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 建立数据集的表格
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        protected override void BuildDataTables()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Tables.Add(SendOutTable);
InBlock.gif            
//设置新增自动生成key字段
InBlock.gif
            this.KeyTypeID = "SendOutNo";
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}


  

转载于:https://www.cnblogs.com/wildfish/archive/2005/12/29/307743.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值