/// <summary>
        /// 保存实体数据(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键</param>
        /// <returns></returns>
        public void SaveEntity(string keyValue, Mes_RequistHeadEntity entity, List <Mes_RequistDetailEntity> mes_RequistDetailList)
        {
            var db = this.BaseRepository().BeginTrans();

            try
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    var mes_RequistHeadEntityTmp = GetMes_RequistHeadEntity(keyValue);
                    entity.Modify(keyValue);
                    db.Update(entity);
                    db.Delete <Mes_RequistDetailEntity>(t => t.R_RequistNo == mes_RequistHeadEntityTmp.R_RequistNo);
                    foreach (Mes_RequistDetailEntity item in mes_RequistDetailList)
                    {
                        item.Create();
                        item.R_RequistNo = mes_RequistHeadEntityTmp.R_RequistNo;
                        db.Insert(item);
                    }
                }
                else
                {
                    var dp = new DynamicParameters(new { });
                    dp.Add("@BillType", "调拨单");
                    dp.Add("@Doucno", "", DbType.String, ParameterDirection.Output);
                    db.ExecuteByProc("sp_GetDoucno", dp);
                    var billNo = dp.Get <string>("@Doucno");//存储过程返回单号
                    entity.R_RequistNo = billNo;
                    entity.Create();
                    db.Insert(entity);
                    foreach (Mes_RequistDetailEntity item in mes_RequistDetailList)
                    {
                        item.Create();
                        item.R_RequistNo = entity.R_RequistNo;
                    }
                    db.Insert(mes_RequistDetailList);
                }
                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Example #2
0
 /// <summary>
 /// 保存实体数据(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键</param>
 /// <returns></returns>
 public void SaveEntity(string keyValue, Mes_RequistHeadEntity entity, List <Mes_RequistDetailEntity> mes_RequistDetailList)
 {
     try
     {
         requistBillService.SaveEntity(keyValue, entity, mes_RequistDetailList);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }