Exemplo n.º 1
0
 public ResModel UpdatePartsBuy(PartsBuyDto partsBuyDto, UserDto operationUser)
 {
     using (var db = new ModelContext())
     {
         var partsBuy = db.PartsBuy.FirstOrDefault(i => i.Id == partsBuyDto.Id);
         if (partsBuy == null)
         {
             return(new ResModel()
             {
                 Msg = "更新采购入库失败,未找到该采购入库", Success = false
             });
         }
         partsBuy.SupplierId    = partsBuyDto.SupplierId;
         partsBuy.WarehouseId   = partsBuyDto.WarehouseId;
         partsBuy.ApplyUser     = operationUser.Name;
         partsBuy.OperationTime = DateTime.Now;
         partsBuy.TotalMoney    = partsBuyDto.TotalMoney;
         partsBuy.ReadyToPay    = partsBuyDto.TotalMoney;
         partsBuy.Description   = partsBuyDto.Description;
         var partsIns = partsBuyDto.PartsIns.Select(i => new PartsIn()
         {
             Id                = Guid.NewGuid(),
             PartsBuyId        = partsBuy.Id,
             PartsDictionaryId = i.PartsDictionaryId,
             SupplierPrice     = i.SupplierPrice,
             Count             = i.Count,
         });
         using (var scope = new TransactionScope())
         {
             try
             {
                 db.PartsIn.RemoveRange(partsBuy.PartsIns);
                 db.SaveChanges();
                 db.PartsIn.AddRange(partsIns);
                 db.SaveChanges();
                 scope.Complete();
             }
             catch (Exception e)
             {
                 return(new ResModel()
                 {
                     Msg = "更新失败", Success = false
                 });
             }
             return(new ResModel()
             {
                 Msg = "更新成功", Success = true
             });
         }
     }
 }
Exemplo n.º 2
0
        public ActionResult Update(PartsBuyDto partsBuyDto)
        {
            var currentUser = Session["LogUser"] as UserDto;

            return(Json(_partsBuyService.UpdatePartsBuy(partsBuyDto, currentUser)));
        }
Exemplo n.º 3
0
        public ResModel AddPartsBuy(PartsBuyDto partsBuyDto, UserDto operationUser)
        {
            using (var db = new ModelContext())
            {
                var billNo            = "";
                var lastPartsBuyIndex = 0;
                var dateFormat        = "";
                var index             = 0;
                var indexStr          = "";
                var partsBuyBill      = db.BillNoSetting.FirstOrDefault(i => i.Name == BillTypeName.采购入库.ToString());
                if (partsBuyBill.DailyReset)
                {
                    var lastPartsBuy = db.PartsBuy.Where(i => i.CreateTime.Value.Day == DateTime.Now.Day).OrderByDescending(i => i.CreateTime).FirstOrDefault();
                    lastPartsBuyIndex = lastPartsBuy?.BillNoIndex ?? 0;
                }
                else
                {
                    var lastPartsBuy = db.PartsBuy.OrderByDescending(i => i.CreateTime).FirstOrDefault();
                    lastPartsBuyIndex = lastPartsBuy?.BillNoIndex ?? 0;
                }
                index    = lastPartsBuyIndex + 1;
                indexStr = index.ToString();
                switch (partsBuyBill.SerNoLength)
                {
                case BillSerNoLength.两位:
                    indexStr = indexStr.PadLeft(2, '0');
                    break;

                case BillSerNoLength.位:
                    indexStr = indexStr.PadLeft(3, '0');
                    break;

                case BillSerNoLength.四位:
                    indexStr = indexStr.PadLeft(4, '0');
                    break;

                case BillSerNoLength.五位:
                    indexStr = indexStr.PadLeft(5, '0');
                    break;

                case BillSerNoLength.六位:
                    indexStr = indexStr.PadLeft(6, '0');
                    break;
                }
                switch (partsBuyBill.DateFormat)
                {
                case BillDateFormat.简洁年月日:
                    dateFormat = DateTime.Now.ToString("yyMMdd");
                    break;

                case BillDateFormat.完整年月日:
                    dateFormat = DateTime.Now.ToString("yyyyMMdd");
                    break;

                case BillDateFormat.无:
                    dateFormat = "";
                    break;
                }
                billNo = partsBuyBill.Prefix + dateFormat + indexStr;

                var partsBuy = new PartsBuy()
                {
                    Id            = Guid.NewGuid(),
                    SupplierId    = partsBuyDto.SupplierId,
                    BillNo        = billNo,
                    BillNoIndex   = index,
                    State         = PartsBuyState.未审核,
                    ApplyUser     = operationUser.Name,
                    OperationTime = DateTime.Now,
                    TotalMoney    = partsBuyDto.TotalMoney,
                    ReadyToPay    = partsBuyDto.TotalMoney,
                    WarehouseId   = partsBuyDto.WarehouseId,
                    Description   = partsBuyDto.Description,
                    CreateTime    = DateTime.Now,
                };
                var partsIns = partsBuyDto.PartsIns.Select(i => new PartsIn()
                {
                    Id                = Guid.NewGuid(),
                    PartsBuyId        = partsBuy.Id,
                    PartsDictionaryId = i.PartsDictionaryId,
                    SupplierPrice     = i.SupplierPrice,
                    Count             = i.Count,
                });
                using (var scope = new TransactionScope())
                {
                    try
                    {
                        db.PartsBuy.Add(partsBuy);
                        db.PartsIn.AddRange(partsIns);
                        db.SaveChanges();
                        scope.Complete();;
                    }
                    catch (Exception e)
                    {
                        return(new ResModel()
                        {
                            Msg = "添加采购入库失败", Success = false
                        });
                    }
                    return(new ResModel()
                    {
                        Msg = "添加采购入库成功", Success = true
                    });
                }
            }
        }
Exemplo n.º 4
0
 public ResModel UpdatePartsBuy(PartsBuyDto partsBuyDto, UserDto operationUser)
 {
     return(_partsBuyRepository.UpdatePartsBuy(partsBuyDto, operationUser));
 }