예제 #1
0
        ///// <summary>
        ///// 添加数据
        ///// </summary>
        ///// <param name="newData">数据</param>
        //public void AddData(Pro_MaterialRequisition newData)
        //{
        //    Insert(newData);
        //}

        /// <summary>
        /// 修改申请单数据
        /// </summary>
        ///
        public string UpdateData(MaterialRequisitionModel theData, List <string> itemList)
        {
            Pro_MaterialRequisitionItemBusiness mrItemBus = new Pro_MaterialRequisitionItemBusiness();

            try
            {
                mrItemBus.BeginTransaction();
                if (itemList != null && itemList.Count > 0)
                {
                    mrItemBus.Delete(itemList);
                }
                theData.MReqItemList.ForEach(item =>
                {
                    mrItemBus.UpdateWhere(x => x.Id == item.Id, x =>
                    {
                        x.Quantity = item.Quantity;
                    });
                });
            }
            catch
            {
                return("修改数据失败");
            }
            if (mrItemBus.EndTransaction())
            {
                return("");
            }
            else
            {
                return("修改数据失败");
            }
        }
예제 #2
0
        /// <summary>
        /// 获取指定的单条数据
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        public MaterialRequisitionModel GetTheData(string id)
        {
            Pro_MaterialRequisition  mrData = GetEntity(id);
            MaterialRequisitionModel mrd    = new MaterialRequisitionModel()
            {
                Id         = mrData.Id,
                CreateDate = mrData.CreateDate,
                Creator    = mrData.Creator,
                Picker     = mrData.Picker,
                PMR_No     = mrData.PMR_No,
                ProCode    = mrData.ProCode,
                ProName    = mrData.ProName,
                Status     = mrData.Status
            };
            Pro_MaterialRequisitionItemBusiness mrb = new Pro_MaterialRequisitionItemBusiness();

            mrd.MReqItemList = mrb.GetDataList(id);
            return(mrd);
        }
예제 #3
0
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="newData">数据</param>
        public void AddData(MaterielParam theData)
        {
            Pro_ProjectBusiness                 pb          = new Pro_ProjectBusiness();
            Pro_MaterialRequisitionBusiness     mReqBus     = new Pro_MaterialRequisitionBusiness();
            Pro_MaterialRequisitionItemBusiness mReqItemBus = new Pro_MaterialRequisitionItemBusiness();

            //检查项目是否存在
            var projects = pb.GetDataList("ProCode", theData.ProCode, new Pagination()
            {
                PageIndex = 1, PageRows = int.MaxValue
            });
            Pro_Project pro = projects.Find(p => p.ProCode == theData.ProCode);

            if (pro == null)
            {
                throw new Exception($"项目编号为:{theData.ProCode}的项目不存在");
            }

            //直接创建领料单
            this.BeginTransaction();
            mReqBus.BeginTransaction();
            mReqItemBus.BeginTransaction();
            string    sql = $"SELECT 'PMR-' + convert(varchar(10),getdate(),112) + RIGHT(1000001+ISNULL(RIGHT(MAX(rtrim(PMR_No)),4),0),4) FROM Pro_MaterialRequisition WITH(XLOCK) WHERE ProCode = '{theData.ProCode}'";
            DataTable dt  = mReqBus.GetDataTableWithSql(sql);

            if (dt == null || dt.Rows.Count == 0)
            {
                throw new Exception("创建申请单失败");
            }
            //创建领料单
            Pro_MaterialRequisition pro_matReq = new Pro_MaterialRequisition()
            {
                Id         = Guid.NewGuid().ToSequentialGuid(),
                PMR_No     = $"{dt.Rows[0][0]}",
                ProCode    = pro.ProCode,
                ProName    = pro.ProName,
                CreateDate = DateTime.Now,
                Creator    = theData.Creator,
                Picker     = ""
            };

            mReqBus.Insert(pro_matReq);
            theData.MaterielList.ForEach(item =>
            {
                //工程物料
                Pro_ProjectMateriel materiel = new Pro_ProjectMateriel()
                {
                    Id           = Guid.NewGuid().ToSequentialGuid(),
                    ProCode      = item.ProCode,
                    GuiGe        = item.GuiGe,
                    MatNo        = item.MatNo,
                    MatName      = item.MatName,
                    ProName      = pro.ProName,
                    UnitNo       = item.UnitNo,
                    PlanQuantity = item.Quantity
                };
                this.Insert(materiel);
                //申请单物料
                Pro_MaterialRequisitionItem mReqItem = new Pro_MaterialRequisitionItem()
                {
                    Id       = Guid.NewGuid().ToSequentialGuid(),
                    MR_Id    = pro_matReq.Id,
                    ProCode  = item.ProCode,
                    GuiGe    = item.GuiGe,
                    MatNo    = item.MatNo,
                    MatName  = item.MatName,
                    UnitNo   = item.UnitNo,
                    Quantity = item.Quantity.Value
                };
                mReqItemBus.Insert(mReqItem);
            });
            //submit
            if (this.EndTransaction())
            {
                if (mReqBus.EndTransaction())
                {
                    mReqItemBus.EndTransaction();
                }
            }
        }