DAL - 保存多张表的资料


DAL - 保存多张表的资料-开发框架文库

DAL - 保存多张表的资料

客户产品资料

DAL - 保存多张表的资料

DAL - 保存多张表的资料

DAL层Update方法保存多张表资料

图片

 

DAL层代码

 

C# 全选
        /// <summary>
        /// 保存多张表资料
        /// </summary>
        /// <param name="input">提交的数据模型</param>
        /// <returns></returns>
        public bool Update(ProductUpdateModel input)
        {
            try
            {
                _Database.BeginTransaction();

                //新增客户产品,自动生成产品序号
                if (input.MasterDataUpdate.listAdded.Count > 0)
                {
                    input.MasterDataUpdate.listAdded.First().ProductCode = 
                        DocNoHelper.GetDataSN(_Database, "CP", true, 8, "", _Loginer.Account);//生成客户产品编码
                }

                //提交主表:纸盒资料
                base.Update(input.MasterDataUpdate, _Database, false);

                //获取当前盒式编码,作为外键值
                var ProductCode = input.MasterDataUpdate.VisibleList.First().ProductCode;

                #region 提交明细表:产品物料

                SetCommonValue<dt_CustomerProductMaterials>(input.ProductMaterialsList);

                if (input.ProductMaterialsList != null)
                {
                    foreach (var v in input.ProductMaterialsList)
                    {
                        //新增记录,设置默认值
                        if (v.isid.IsEmpty()) v.isid = IdHelper.GetId();
                        if (v.ProductCode.IsEmpty()) v.ProductCode = ProductCode;
                    }

                    //删除旧数据
                    _Database.Remove<dt_CustomerProductMaterials>(w => w.ProductCode == ProductCode);

                    //保存数据
                    _Database.Add(input.ProductMaterialsList);
                }

                #endregion

                #region 提交明细表:产品工艺

                SetCommonValue<dt_CustomerProductCraft>(input.ProductCraftList);

                if (input.ProductCraftList != null)
                {
                    foreach (var v in input.ProductCraftList)
                    {
                        //新增记录,设置默认值
                        if (v.isid.IsEmpty()) v.isid = IdHelper.GetId();
                        if (v.ProductCode.IsEmpty()) v.ProductCode = ProductCode;
                    }

                    //删除旧数据
                    _Database.Remove<dt_CustomerProductCraft>(w => w.ProductCode == ProductCode);

                    //保存数据
                    _Database.Add(input.ProductCraftList);
                }

                #endregion

                #region 提交明细表:打包要求

                SetCommonValue<dt_CustomerProductPacking>(input.ProductPackingList);

                if (input.ProductPackingList != null)
                {
                    foreach (var v in input.ProductPackingList)
                    {
                        //新增记录,设置默认值
                        if (v.isid.IsEmpty()) v.isid = IdHelper.GetId();
                        if (v.ProductCode.IsEmpty()) v.ProductCode = ProductCode;
                    }

                    //删除旧数据
                    _Database.Remove<dt_CustomerProductPacking>(w => w.ProductCode == ProductCode);

                    //保存数据
                    _Database.Add(input.ProductPackingList);
                }

                #endregion

                #region 提交明细表:产品工序

                SetCommonValue<dt_CustomerProductProcess>(input.ProductProcessList);

                if (input.ProductProcessList != null)
                {
                    foreach (var v in input.ProductProcessList)
                    {
                        //新增记录,设置默认值
                        if (v.isid.IsEmpty()) v.isid = IdHelper.GetId();
                        if (v.ProductCode.IsEmpty()) v.ProductCode = ProductCode;
                    }

                    //删除旧数据
                    _Database.Remove<dt_CustomerProductProcess>(w => w.ProductCode == ProductCode);

                    //保存数据
                    _Database.Add(input.ProductProcessList);
                }

                #endregion

                #region 提交明细表:唛头文件

                if (input.ProductLogoFilesList != null)
                {
                    foreach (var v in input.ProductLogoFilesList)
                    {
                        //新增记录,设置默认值
                        if (v.FileID.IsEmpty())
                        {
                            v.FileID = IdHelper.GetId();
                            v.DocID = ProductCode;
                            v.DocType = "Carton";
                        }
                    }

                    //删除旧数据
                    _Database.Remove<tb_AttachFile>(w => w.DocType == "Carton" && w.DocID == ProductCode);

                    //保存数据
                    _Database.Add(input.ProductLogoFilesList);
                }

                #endregion

                _Database.CommitTransaction();

                return true;
            }
            catch (System.Exception)
            {
                _Database.RollbackTransaction();
                throw;
            }
        }

 

ProductUpdateModel 组合模型

C# 全选
/// <summary>
/// 客户产品资料-保存数据模型
/// </summary>
public class ProductUpdateModel
{
    //主表数据
    public MasterDataUpdate<dt_CustomerProduct> MasterDataUpdate { get; set; }

    /// <summary>
    /// 明细表数据
    /// </summary>
    public List<dt_CustomerProductMaterials> ProductMaterialsList { get; set; }
    public List<dt_CustomerProductCraft> ProductCraftList { get; set; }
    public List<dt_CustomerProductPacking> ProductPackingList { get; set; }
    public List<dt_CustomerProductProcess> ProductProcessList { get; set; }
    public List<tb_AttachFile> ProductLogoFilesList { get; set; }
    
    /// <summary>
    /// 对应销售单明细
    /// </summary>
    public List<tb_SOs> ProductSubInfoList { get; set; }
}

 

 

版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
C/S框架网
评论列表

发表评论

评论内容
昵称:
关联文章

DAL - 保存资料
C/S开发框架教程:使用基础资料(数据字典)DAL层更新主从(或)数据
DAL数据访问层提交单个数据
单上实现增删改查,除了生成BLL,DAL和ORM,还需要处理什么?
CSFrameworkV6旗舰版 - 保存数据字典基础资料自动生成流水号、序号
修改用户资料保存后密码丢失问题
FastReport.NET报表打印图片
C/S Winform开发框架 - 单基础资料窗体实现主从资料管理
DAL - 单数据字典数据访问层C#代码
DAL - 主从业务单据数据访问层C#代码
代码生成器 CodeGenerator - 生成DAL
ERP系统 - 语言资料管理与维护
ORM_TableAttribute类详解:资料特性定义
SQLServer2008:阻止保存要求重新创建更改问题设置方法
CSFramework.CodeGeneratorV6.0-生成DAL
开发技巧:删除资料保存日志并检查数据是否能删除
sp_sys_GetTableFieldNames 获取资料字段备注信息
CSFrameworkV6旗舰版 - 单基础资料窗体完整C#源码
开发示例:数据字典窗体提供数据更新
LINQ 删除数据、检查数据引用