Ejemplo n.º 1
0
        /// <summary>
        /// 新增益损信息
        /// </summary>
        /// <param name="recordId">记录Id</param>
        /// <param name="targetType">目标类型</param>
        /// <param name="category">分类</param>
        /// <param name="quantity">数量</param>
        /// <param name="remark">备注</param>
        /// <param name="creator">创建人</param>
        public void Add(string recordId, string targetType, string category, decimal quantity, string remark, string creator)
        {
            using (DbConnection conn = DbHelper.CreateConnection())
            {
                DbTransaction trans = null;
                try
                {
                    conn.Open();
                    trans = conn.BeginTransaction();
                    if (trans == null)
                    {
                        throw new ArgumentNullException("DbTransaction");
                    }
                    if (targetType == ProfitLossTargetType.Purchase)
                    {
                        Purchase purchase = this.purchaseService.Select(trans, recordId);
                        purchase.AddProfitLoss(category, quantity);
                        if (purchase.Inventory < 0)
                        {
                            throw new EasySoftException(BusinessResource.Purchase_LowStocks);
                        }
                        this.purchaseService.Update(trans, purchase);
                    }
                    else if (targetType == ProfitLossTargetType.Sale)
                    {
                        // 销售
                        throw new NotSupportedException();
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    ProfitLoss entity = new ProfitLoss();
                    entity.Create(recordId, targetType, category, quantity, remark, creator);
                    this.profitLossRepository.Insert(trans, entity);

                    trans.Commit();
                }
                catch
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    throw;
                }
            }
        }