/// <summary>取操作:保存货位转移信息,并返回其ID</summary>
        public int AddWmsLocationTransfer(AscmWmsLocationTransfer ascmWmsLocationTransfer)
        {
            int id = -1;
            try
            {
                if (ascmWmsLocationTransfer == null)
                    throw new Exception("获取货位转移信息失败");

                string sql = "from AscmLocationMaterialLink where pk.warelocationId=" + ascmWmsLocationTransfer.fromWarelocationId + " and pk.materialId=" + ascmWmsLocationTransfer.materialId;
                IList<AscmLocationMaterialLink> ilist = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmLocationMaterialLink>(sql);
                if (ilist == null || ilist.Count == 0)
                    throw new Exception("获取来源货位失败");

                int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmWmsLocationTransfer");
                id = ++maxId;
                ascmWmsLocationTransfer.id = id;

                //DateTime dtServerTime = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentDate("AscmLocationMaterialLink");

                //AscmLocationMaterialLink ascmLocationMaterialLink = ilist.First();
                //ascmLocationMaterialLink.modifyUser = ascmWmsLocationTransfer.modifyUser;
                //ascmLocationMaterialLink.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss");
                //ascmLocationMaterialLink.quantity -= ascmWmsLocationTransfer.quantity;

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

                        //YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmLocationMaterialLink);

                        tx.Commit();//正确执行提交
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();//回滚
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                YnBaseClass2.Helper.LogHelper.GetLog().Error("增加失败(Add AscmWmsLocationTransfer)", ex);
                throw ex;
            }
            return id;
        }
 public void Delete(AscmWmsLocationTransfer ascmWmsLocationTransfer)
 {
     try
     {
         YnDaoHelper.GetInstance().nHibernateHelper.Delete<AscmWmsLocationTransfer>(ascmWmsLocationTransfer);
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmWmsLocationTransfer)", ex);
         throw ex;
     }
 }
        /// <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;
            }
        }
 public void Update(AscmWmsLocationTransfer ascmWmsLocationTransfer)
 {
     try
     {
         using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
         {
             try
             {
                 YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmWmsLocationTransfer>(ascmWmsLocationTransfer);
                 tx.Commit();//正确执行提交
             }
             catch (Exception ex)
             {
                 tx.Rollback();//回滚
                 YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmWmsLocationTransfer)", ex);
                 throw ex;
             }
         }
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Save AscmWmsLocationTransfer)", ex);
         throw ex;
     }
 }