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

            try
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    var mes_BackSupplyHeadEntityTmp = GetMes_BackSupplyHeadEntity(keyValue);
                    entity.Modify(keyValue);
                    db.Update(entity);
                    db.Delete <Mes_BackSupplyDetailEntity>(t => t.B_BackSupplyNo == mes_BackSupplyHeadEntityTmp.B_BackSupplyNo);
                    foreach (Mes_BackSupplyDetailEntity item in mes_BackSupplyDetailList)
                    {
                        item.Create();
                        item.B_BackSupplyNo = mes_BackSupplyHeadEntityTmp.B_BackSupplyNo;
                        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.B_BackSupplyNo = billNo;
                    entity.Create();
                    db.Insert(entity);
                    foreach (Mes_BackSupplyDetailEntity item in mes_BackSupplyDetailList)
                    {
                        item.Create();
                        item.B_BackSupplyNo = entity.B_BackSupplyNo;
                        db.Insert(item);
                    }
                }
                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_BackSupplyHeadEntity entity, List <Mes_BackSupplyDetailEntity> mes_BackSupplyDetailList)
        {
            var db = this.BaseRepository().BeginTrans();

            try
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    var mes_BackSupplyHeadEntityTmp = GetMes_BackSupplyHeadEntity(keyValue);
                    entity.Modify(keyValue);
                    db.Update(entity);
                    db.Delete <Mes_BackSupplyDetailEntity>(t => t.B_BackSupplyNo == mes_BackSupplyHeadEntityTmp.B_BackSupplyNo);
                    foreach (Mes_BackSupplyDetailEntity item in mes_BackSupplyDetailList)
                    {
                        item.Create();
                        item.B_BackSupplyNo = mes_BackSupplyHeadEntityTmp.B_BackSupplyNo;
                        db.Insert(item);
                    }
                }
                else
                {
                    entity.Create();
                    db.Insert(entity);
                    foreach (Mes_BackSupplyDetailEntity item in mes_BackSupplyDetailList)
                    {
                        item.Create();
                        item.B_BackSupplyNo = entity.B_BackSupplyNo;
                        db.Insert(item);
                    }
                }
                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }