Exemplo n.º 1
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="theData">保存的数据</param>
        public ActionResult SaveData(Pro_GetMaterial theData)
        {
            if (theData.Id.IsNullOrEmpty())
            {
                theData.Id = Guid.NewGuid().ToSequentialGuid();

                _pro_GetMaterialBusiness.AddData(theData);
            }
            else
            {
                _pro_GetMaterialBusiness.UpdateData(theData);
            }

            return(Success());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 工程领料单领料
        /// </summary>
        /// <param name="theData"></param>
        public void ProMaterial(StockOutModel theData, string Picker, string ProCode, string ProName)
        {
            Pro_GetMaterialBusiness         _getMeterialBus = new Pro_GetMaterialBusiness();
            Pro_MaterialRequisitionBusiness _mrb            = new Pro_MaterialRequisitionBusiness();
            //检查是否领料
            var query = _mrb.GetIQueryable().Where(p => p.PMR_No == theData.ApplyNo).SingleOrDefault();

            if (query.Status == 2)
            {
                throw new Exception("已领料");
            }
            //if (query.Status == 0)
            //{
            //    throw new Exception("未审批");
            //}
            if (query.Status == 3)
            {
                throw new Exception("已作废");
            }

            Sto_StockOut stockOut = theData.ToJson().ToObject <Sto_StockOut>();

            this.BeginTransaction();
            this._stockOutItemBus.BeginTransaction();
            _getMeterialBus.BeginTransaction();
            this.Insert(stockOut);
            foreach (Sto_StockOutItem item in theData.StockOutItems)
            {
                this._stockOutItemBus.Insert(item);
                Pro_GetMaterial getMaterial = new Pro_GetMaterial()
                {
                    Id       = Guid.NewGuid().ToSequentialGuid(),
                    PMR_No   = theData.ApplyNo,
                    GetDate  = DateTime.Now,
                    GuiGe    = item.GuiGe,
                    MatName  = item.MatName,
                    MatNo    = item.MatNo,
                    Context  = stockOut.Context,
                    ProCode  = ProCode,
                    ProName  = ProName,
                    UnitNo   = item.UnitNo,
                    Quantity = item.Quantity,
                    Picker   = Picker
                };
                _getMeterialBus.Insert(getMaterial);
            }
            if (this.EndTransaction())
            {
                if (!this._stockOutItemBus.EndTransaction())
                {
                    this.Delete(stockOut.Id);
                    throw new Exception("出库失败");
                }
                else
                {
                    //出库成功,更改领料单状态
                    _getMeterialBus.EndTransaction();
                    _mrb.UpdateWhere(p => p.PMR_No == theData.ApplyNo, item => item.Status = 2);
                    _mrb.UpdateWhere(p => p.PMR_No == theData.ApplyNo, item => item.Picker = Picker);
                }
            }
            else
            {
                throw new Exception("出库失败");
            }
        }