Ejemplo n.º 1
0
        public override IModel CreateModel(SqlDataReader dr)
        {
            StockMove stockmove = new StockMove();

            int indexStockMoveId = dr.GetOrdinal("StockMoveId");
            stockmove.StockMoveId = Convert.ToInt32(dr[indexStockMoveId]);

            int indexStockMoveApplyId = dr.GetOrdinal("StockMoveApplyId");
            stockmove.StockMoveApplyId = Convert.ToInt32(dr[indexStockMoveApplyId]);

            int indexMover = dr.GetOrdinal("Mover");
            if (dr["Mover"] != DBNull.Value)
            {
                stockmove.Mover = Convert.ToInt32(dr[indexMover]);
            }

            int indexMoveTime = dr.GetOrdinal("MoveTime");
            if (dr["MoveTime"] != DBNull.Value)
            {
                stockmove.MoveTime = Convert.ToDateTime(dr[indexMoveTime]);
            }

            int indexMoveStatus = dr.GetOrdinal("MoveStatus");
            if (dr["MoveStatus"] != DBNull.Value)
            {
                stockmove.MoveStatus = (Common.StatusEnum)Convert.ToInt32(dr[indexMoveStatus]);
            }

            int indexMoveMemo = dr.GetOrdinal("MoveMemo");
            if (dr["MoveMemo"] != DBNull.Value)
            {
                stockmove.MoveMemo = Convert.ToString(dr[indexMoveMemo]);
            }

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

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

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

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

            return stockmove;
        }
Ejemplo n.º 2
0
        public ResultModel StockMoveCreateHandle(UserModel user, int stockMoveApplyId, string memo)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    Model.StockMove stockMove = new StockMove()
                    {
                        StockMoveApplyId = stockMoveApplyId,
                        Mover = user.EmpId,
                        MoveTime = DateTime.Now,
                        MoveMemo = memo,
                    };

                    DAL.StockMoveDAL stockMoveDAL = new StockMoveDAL();
                    result = stockmoveDAL.Insert(user, stockMove);
                    if (result.ResultStatus != 0)
                        return result;

                    int stockMoveId = (int)result.ReturnValue;

                    DAL.StockMoveApplyDetailDAL stockMoveApplyDetailDAL = new StockMoveApplyDetailDAL();
                    result = stockMoveApplyDetailDAL.Load(user, stockMoveApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockMoveApplyDetail> details = result.ReturnValue as List<Model.StockMoveApplyDetail>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    DAL.StockMoveDetailDAL stockMoveDetailDAL = new StockMoveDetailDAL();
                    foreach (Model.StockMoveApplyDetail stockMoveApplyDetail in details)
                    {
                        result = stockMoveDetailDAL.Insert(user, new StockMoveDetail()
                        {
                            StockMoveId = stockMoveId,
                            MoveDetailStatus = StatusEnum.已生效,
                            StockId = stockMoveApplyDetail.StockId,
                            PaperNo = stockMoveApplyDetail.PaperNo,
                            DeliverPlaceId = stockMoveApplyDetail.DeliverPlaceId
                        });

                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }