Beispiel #1
0
        public override IModel CreateModel(SqlDataReader dr)
        {
            FinBusInvAllot finbusinvallot = new FinBusInvAllot();

            int indexAllotId = dr.GetOrdinal("AllotId");
            finbusinvallot.AllotId = Convert.ToInt32(dr[indexAllotId]);

            int indexAllotBala = dr.GetOrdinal("AllotBala");
            if (dr["AllotBala"] != DBNull.Value)
            {
                finbusinvallot.AllotBala = Convert.ToDecimal(dr[indexAllotBala]);
            }

            int indexCurrencyId = dr.GetOrdinal("CurrencyId");
            if (dr["CurrencyId"] != DBNull.Value)
            {
                finbusinvallot.CurrencyId = Convert.ToInt32(dr[indexCurrencyId]);
            }

            int indexAlloter = dr.GetOrdinal("Alloter");
            if (dr["Alloter"] != DBNull.Value)
            {
                finbusinvallot.Alloter = Convert.ToInt32(dr[indexAlloter]);
            }

            int indexAllotDate = dr.GetOrdinal("AllotDate");
            if (dr["AllotDate"] != DBNull.Value)
            {
                finbusinvallot.AllotDate = Convert.ToDateTime(dr[indexAllotDate]);
            }

            int indexAllotStatus = dr.GetOrdinal("AllotStatus");
            if (dr["AllotStatus"] != DBNull.Value)
            {
                finbusinvallot.AllotStatus = (Common.StatusEnum)Convert.ToInt32(dr[indexAllotStatus]);
            }

            int indexCreatorId = dr.GetOrdinal("CreatorId");
            if (dr["CreatorId"] != DBNull.Value)
            {
                finbusinvallot.CreatorId = Convert.ToInt32(dr[indexCreatorId]);
            }

            int indexCreateTime = dr.GetOrdinal("CreateTime");
            if (dr["CreateTime"] != DBNull.Value)
            {
                finbusinvallot.CreateTime = Convert.ToDateTime(dr[indexCreateTime]);
            }

            int indexLastModifyId = dr.GetOrdinal("LastModifyId");
            if (dr["LastModifyId"] != DBNull.Value)
            {
                finbusinvallot.LastModifyId = Convert.ToInt32(dr[indexLastModifyId]);
            }

            int indexLastModifyTime = dr.GetOrdinal("LastModifyTime");
            if (dr["LastModifyTime"] != DBNull.Value)
            {
                finbusinvallot.LastModifyTime = Convert.ToDateTime(dr[indexLastModifyTime]);
            }

            return finbusinvallot;
        }
Beispiel #2
0
        public ResultModel CreateAllot(UserModel user, int currencyId, List<Model.FinBusInvAllotDetail> details)
        {
            ResultModel result = new ResultModel();
            DAL.FinBusInvAllotDetailDAL finBusInvAllotDetailDAL = new FinBusInvAllotDetailDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    decimal sumAllotAmount = 0;
                    if (details != null && details.Any())
                    {
                        foreach (Model.FinBusInvAllotDetail detail in details)
                        {
                            sumAllotAmount += detail.AllotBala;
                        }
                    }

                    if (sumAllotAmount == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "分配金额不能为0";
                        return result;
                    }

                    Model.FinBusInvAllot finBusInvAllot = new FinBusInvAllot()
                    {
                        AllotBala = sumAllotAmount,
                        CurrencyId = currencyId,
                        Alloter = user.EmpId,
                        AllotDate = DateTime.Now
                    };

                    result = finbusinvallotDAL.Insert(user, finBusInvAllot);
                    if (result.ResultStatus != 0)
                        return result;

                    int allotId = (int)result.ReturnValue;

                    foreach (Model.FinBusInvAllotDetail detail in details)
                    {
                        detail.AllotId = allotId;
                        result = finBusInvAllotDetailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (this.Log.IsInfoEnabled)
                    this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }