Пример #1
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="theData">保存的数据</param>
        public ActionResult SaveData(Pro_Project theData)
        {
            if (theData.Id.IsNullOrEmpty())
            {
                theData.Id         = Guid.NewGuid().ToSequentialGuid();
                theData.CreateDate = DateTime.Now;
                theData.Status     = "0";
                _pro_ProjectBusiness.AddData(theData);
            }
            else
            {
                _pro_ProjectBusiness.UpdateData(theData);
            }

            return(Success());
        }
Пример #2
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();
                }
            }
        }