public AscmLocationMaterialLink(AscmLocationMaterialLink locationMaterialLink,
            string materialDocNumber, string materialDescription,
            string locationDocNumber, string warehouseId)
        {
            this.pk = locationMaterialLink.pk;
            this.organizationId = locationMaterialLink.organizationId;
            this.createUser = locationMaterialLink.createUser;
            this.createTime = locationMaterialLink.createUser;
            this.modifyUser = locationMaterialLink.modifyUser;
            this.modifyTime = locationMaterialLink.modifyTime;

            this.materialDocNumber = materialDocNumber;
            this.materialDescription = materialDescription;
            this.locationDocNumber = locationDocNumber;
            this.warehouseId = warehouseId;
        }
Beispiel #2
0
        public AscmLocationMaterialLink(AscmLocationMaterialLink locationMaterialLink,
                                        string materialDocNumber, string materialDescription,
                                        string locationDocNumber, string warehouseId)
        {
            this.pk             = locationMaterialLink.pk;
            this.organizationId = locationMaterialLink.organizationId;
            this.createUser     = locationMaterialLink.createUser;
            this.createTime     = locationMaterialLink.createUser;
            this.modifyUser     = locationMaterialLink.modifyUser;
            this.modifyTime     = locationMaterialLink.modifyTime;

            this.materialDocNumber   = materialDocNumber;
            this.materialDescription = materialDescription;
            this.locationDocNumber   = locationDocNumber;
            this.warehouseId         = warehouseId;
        }
        /// <summary>存操作:保存货位转移信息,并返回其ID</summary>
        public void UpdateWmsLocationTransfer(AscmWmsLocationTransfer ascmWmsLocationTransfer)
        {
            try
            {
                if (ascmWmsLocationTransfer == null)
                    throw new Exception("获取货位转移信息失败");

                string sql = "from AscmLocationMaterialLink "
                           + "where warelocationId in(" + ascmWmsLocationTransfer.fromWarelocationId + "," + ascmWmsLocationTransfer.toWarelocationId + ") "
                           + "and materialId=" + ascmWmsLocationTransfer.materialId;

                IList<AscmLocationMaterialLink> ilist = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmLocationMaterialLink>(sql);
                if (ilist == null || ilist.Count == 0)
                    throw new Exception("获取货位失败");
                AscmLocationMaterialLink fromLocationMaterialLink = ilist.First(P => P.pk.warelocationId == ascmWmsLocationTransfer.fromWarelocationId);
                if (fromLocationMaterialLink == null)
                    throw new Exception("获取来源货位失败");
                DateTime dtServerTime = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentDate("AscmLocationMaterialLink");
                List<AscmLocationMaterialLink> listLocationMaterialLinkSaveOrUpdate = new List<AscmLocationMaterialLink>();

                fromLocationMaterialLink.quantity -= ascmWmsLocationTransfer.quantity;
                fromLocationMaterialLink.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                fromLocationMaterialLink.modifyUser = ascmWmsLocationTransfer.modifyUser;
                listLocationMaterialLinkSaveOrUpdate.Add(fromLocationMaterialLink);

                AscmLocationMaterialLink toLocationMaterialLink = null;
                toLocationMaterialLink = ilist.First(P => P.pk.warelocationId == ascmWmsLocationTransfer.toWarelocationId);
                //如果货位之前没存放此物料,则新增
                if (toLocationMaterialLink == null)
                {
                    toLocationMaterialLink = new AscmLocationMaterialLink();
                    int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmWmsLocationTransfer");
                    //toLocationMaterialLink.id = ++maxId;
                    toLocationMaterialLink.createTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                    toLocationMaterialLink.createUser = ascmWmsLocationTransfer.modifyUser;
                    //toLocationMaterialLink.warelocationId = ascmWmsLocationTransfer.toWarelocationId;
                    //toLocationMaterialLink.materialId = ascmWmsLocationTransfer.materialId;
                    toLocationMaterialLink.pk = new AscmLocationMaterialLinkPK { warelocationId = ascmWmsLocationTransfer.toWarelocationId, materialId = ascmWmsLocationTransfer.materialId };
                }
                toLocationMaterialLink.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                toLocationMaterialLink.modifyUser = ascmWmsLocationTransfer.modifyUser;
                toLocationMaterialLink.quantity += ascmWmsLocationTransfer.quantity;
                listLocationMaterialLinkSaveOrUpdate.Add(toLocationMaterialLink);

                using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
                {
                    try
                    {
                        YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmWmsLocationTransfer);

                        YnDaoHelper.GetInstance().nHibernateHelper.SaveOrUpdateList(listLocationMaterialLinkSaveOrUpdate);

                        tx.Commit();//正确执行提交
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();//回滚
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                YnBaseClass2.Helper.LogHelper.GetLog().Error("增加失败(Update AscmWmsLocationTransfer)", ex);
                throw ex;
            }
        }