public void Update(AscmLocationMaterialLink locationMaterialLink)
 {
     try
     {
         using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
         {
             try
             {
                 YnDaoHelper.GetInstance().nHibernateHelper.Update <AscmLocationMaterialLink>(locationMaterialLink);
                 tx.Commit();//正确执行提交
             }
             catch (Exception ex)
             {
                 tx.Rollback();//回滚
                 YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmLocationMaterialLink)", ex);
                 throw ex;
             }
         }
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Save AscmLocationMaterialLink)", ex);
         throw ex;
     }
 }
 public void Delete(AscmLocationMaterialLink locationMaterialLink)
 {
     try
     {
         YnDaoHelper.GetInstance().nHibernateHelper.Delete <AscmLocationMaterialLink>(locationMaterialLink);
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmLocationMaterialLink)", ex);
         throw ex;
     }
 }
 public void Delete(AscmLocationMaterialLinkPK pk)
 {
     try
     {
         AscmLocationMaterialLink locationMaterialLink = Get(pk);
         Delete(locationMaterialLink);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public List <AscmLocationMaterialLink> GetList(string sortName, string sortOrder, int?buildingId, string queryWord)
        {
            List <AscmLocationMaterialLink> list = null;

            try
            {
                StringBuilder strSQL = new StringBuilder();
                strSQL.Append(" SELECT a.Id, c.DocNumber as MaterialDocNumber, a.Quantity, b.DocNumber as LocationDocNumber ");
                strSQL.Append(" FROM ASCM_LOCATION_MATERIAL_LINK a  ");
                strSQL.Append(" LEFT JOIN ASCM_WARELOCATION b ON a.warelocationid = b.id ");
                strSQL.Append(" LEFT JOIN ASCM_MATERIAL_ITEM c ON a.materialid=c.id  ");
                strSQL.Append(" WHERE b.BUILDINGID IS NOT NULL ");

                if (buildingId.HasValue)
                {
                    strSQL.Append(" AND  b.BUILDINGID = " + buildingId.Value);
                }
                if (!string.IsNullOrEmpty(queryWord))
                {
                    queryWord = queryWord.ToUpper();
                    strSQL.Append(" AND  c.DocNumber LIKE '%" + queryWord + "%'");
                }
                strSQL.Append(" ORDER BY a.id ");

                ISession      session = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession();
                OracleCommand command = (OracleCommand)session.Connection.CreateCommand();
                command.CommandText = strSQL.ToString();
                OracleDataAdapter da = new OracleDataAdapter(command);
                DataSet           ds = new DataSet();
                da.Fill(ds);
                DataTable dt = ds.Tables[0];

                if (dt != null && dt.Rows != null && dt.Rows.Count > 0)
                {
                    list = new List <AscmLocationMaterialLink>();
                    foreach (DataRow dr in dt.Rows)
                    {
                        AscmLocationMaterialLink entity = new AscmLocationMaterialLink();
                        entity.materialDocNumber = dr["materialDocNumber"].ToString();
                        entity.quantity          = Convert.ToDecimal(dr["quantity"]);
                        entity.locationDocNumber = dr["locationDocNumber"].ToString();
                        list.Add(entity);
                    }
                }
            }
            catch (Exception ex)
            {
                YnBaseClass2.Helper.LogHelper.GetLog().Error("查询失败(Find AscmLocationMaterialLink)", ex);
                throw ex;
            }

            return(list);
        }
        public AscmLocationMaterialLink Get(AscmLocationMaterialLinkPK pk)
        {
            AscmLocationMaterialLink locationMaterialLink = null;

            try
            {
                locationMaterialLink = YnDaoHelper.GetInstance().nHibernateHelper.Get <AscmLocationMaterialLink>(pk);
            }
            catch (Exception ex)
            {
                YnBaseClass2.Helper.LogHelper.GetLog().Error("查询失败(Get AscmLocationMaterialLink)", ex);
                throw ex;
            }
            return(locationMaterialLink);
        }
        /// <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;
            }
        }