关于业务单据主从表导入数据,销售订单(SO)的数据导入到销售退货单(SR)
作者:C/S框架网  发布日期:2014-12-29 15:03:04
  关于业务单据主从表导入数据,销售订单(SO)的数据导入到销售退货单(SR)


假设我们将销售订单(SO)的数据导入到销售退货单(SR), 我们在设计时退货单要关联是那张销售单的的退货,所以退货单有个关联号码(RefSONO), 原则上两张单据的数据结构相差不大.

理解简单些, 就是数据源的DataSet A, A里面包含主从表两张表,1是主表,里面一条记录,2是明细表,里面多条记录. 我们将A的数据复制到DataSet B, 先复制主表的记录,然后打循环复制明细表的记录, 将关联的字段 一 一对应起来赋值就行了.


例子:



C# Code:


/// <summary>
/// 从销售订单导入数据到销售退货
/// </summary>
/// <param name="ds">销售订单数据(主从表)</param>
public void ImportFromSO(DataSet ds)
{
   //取销售订单数据的主从表
   DataTable SOM = ds.Tables[tb_SO.__TableName];
   DataTable SOD = ds.Tables[tb_SOs.__TableName];
   
   //取销售退货数据的主从表
   DataTable SRM = _CurrentBusiness.Tables[tb_SR.__TableName];
   DataTable SRD = _CurrentBusiness.Tables[tb_SRs.__TableName];
   
   DateTime dt = CommonData.ServerTime;//服务器时间
   
   //复制主表资料 SO->SR
   SRM.Rows[0][tb_SR.FID] = "*自动生成*";
   SRM.Rows[0][tb_SR.FDate] = new DateTime(dt.Year, dt.Month, dt.Day);
   SRM.Rows[0][tb_SR.CustomerCode] = SOM.Rows[0][tb_SO.CustomerCode];
   SRM.Rows[0][tb_SR.CustomerName] = SOM.Rows[0][tb_SO.CustomerName];
   SRM.Rows[0][tb_SR.RefSONO] = SOM.Rows[0][tb_SO.FID];//关联号码
   SRM.Rows[0][tb_SR.FlagCreate] = "Y";
   
   //复制明细表资料 SOs->SRs
   foreach (DataRow R in SOD.Rows)
   {
      //仅处理勾选的数据
      if (ConvertEx.ToString(R["FlagCheck"]) != "Y") continue;
      
      DataRow D = SRD.Rows.Add();
      D[tb_SRs.Amount] = R[tb_SOs.Amount];
      D[tb_SRs.BulkQty] = R[tb_SOs.BulkQty];
      D[tb_SRs.ComminnionAmt] = R[tb_SOs.ComminnionAmt];
      D[tb_SRs.Commission] = R[tb_SOs.Commission];
      D[tb_SRs.CommissionAmount] = R[tb_SOs.CommissionAmount];
      D[tb_SRs.LanguageCode] = R[tb_SOs.LanguageCode];
      D[tb_SRs.Packing] = R[tb_SOs.Packing];
      D[tb_SRs.Piceces] = R[tb_SOs.Piceces];
      D[tb_SRs.Price] = R[tb_SOs.Price];
      D[tb_SRs.Quantity] = R[tb_SOs.Quantity];
      D[tb_SRs.Queue] = R[tb_SOs.Queue];
      D[tb_SRs.StockCode] = R[tb_SOs.StockCode];
      D[tb_SRs.StockName] = R[tb_SOs.StockName];
      D[tb_SRs.UnitCode] = R[tb_SOs.UnitCode];
      D[tb_SRs.CreatedBy] = Loginer.CurrentUser.Account;
      D[tb_SRs.CreationDate] = dt;
      D[tb_SRs.LastUpdateDate] = dt;
      D[tb_SRs.LastUpdatedBy] = Loginer.CurrentUser.Account;
   }
}

//来源:C/S框架网(www.csframework.com) QQ:1980854898


上一篇 下一篇