public void Delete(AscmPallet ascmPallet) { try { YnDaoHelper.GetInstance().nHibernateHelper.Delete<AscmPallet>(ascmPallet); } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmPallet)", ex); throw ex; } }
public void Update(AscmPallet ascmPallet) { try { using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction()) { try { YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmPallet>(ascmPallet); tx.Commit();//正确执行提交 } catch (Exception ex) { tx.Rollback();//回滚 YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmPallet)", ex); throw ex; } } } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Save AscmPallet)", ex); throw ex; } }
public ContentResult PalletSave(AscmPallet ascmPallet_Model, string id) { JsonObjectResult jsonObjectResult = new JsonObjectResult(); try { string userName = string.Empty; if (User.Identity.IsAuthenticated) { userName = User.Identity.Name; } if (id != null && id.Trim() != "") { AscmPallet ascmPallet = AscmPalletService.GetInstance().Get(id); if (ascmPallet == null) throw new Exception("保存托盘失败!"); if (!string.IsNullOrEmpty(ascmPallet_Model.description)) ascmPallet.description = ascmPallet_Model.description.Trim(); ascmPallet.modifyUser = userName; ascmPallet.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); AscmPalletService.GetInstance().Update(ascmPallet); jsonObjectResult.id = ascmPallet.sn; jsonObjectResult.entity = ascmPallet; } else { if (ascmPallet_Model.startSn == null || ascmPallet_Model.startSn.Trim() == "") throw new Exception("开始编号不能为空"); if (ascmPallet_Model.endSn == null || ascmPallet_Model.endSn.Trim() == "") throw new Exception("结束编号不能为空"); if (ascmPallet_Model.startSn.Trim().Length != ascmPallet_Model.endSn.Trim().Length) throw new Exception("开始编号和结束编号长度不一致"); long startSn = 0, endSn = 0; long.TryParse(ascmPallet_Model.startSn, out startSn); long.TryParse(ascmPallet_Model.endSn, out endSn); if (startSn == 0 || endSn == 0 || startSn > endSn) throw new Exception("托盘编号输入错误"); if (endSn - startSn + 1 > 500) throw new Exception("单次添加不能超过500"); object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmRfid where id between '" + ascmPallet_Model.startSn.Trim() + "' and '" + ascmPallet_Model.endSn.Trim() + "'"); if (object1 == null) throw new Exception("查询异常!"); int count = 0; if (int.TryParse(object1.ToString(), out count) && count > 0) throw new Exception("已存在编号"); List<AscmPallet> listAscmPallet = new List<AscmPallet>(); List<AscmRfid> listAscmRfid = new List<AscmRfid>(); for (; startSn <= endSn; startSn++) { AscmPallet ascmPallet = new AscmPallet(); string sn = string.Format("{0:" + YnBaseClass2.Helper.StringHelper.Repeat('0', ascmPallet_Model.startSn.Trim().Length) + "}", startSn); ascmPallet.sn = sn; ascmPallet.rfid = sn; ascmPallet.supplierId = ascmPallet_Model.supplierId; if (!string.IsNullOrEmpty(ascmPallet_Model.description)) ascmPallet.description = ascmPallet_Model.description.Trim(); ascmPallet.status = ascmPallet_Model.status; ascmPallet.createUser = userName; ascmPallet.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); ascmPallet.modifyUser = userName; ascmPallet.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); listAscmPallet.Add(ascmPallet); AscmRfid ascmRfid = new AscmRfid(); ascmRfid.id = sn; ascmRfid.createUser = userName; ascmRfid.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); ascmRfid.modifyUser = userName; ascmRfid.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); ascmRfid.bindType = AscmRfid.BindTypeDefine.pallet; ascmRfid.bindId = sn; ascmRfid.status = AscmRfid.StatusDefine.inUse; listAscmRfid.Add(ascmRfid); } using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction()) { try { if (listAscmPallet.Count > 0) YnDaoHelper.GetInstance().nHibernateHelper.SaveList(listAscmPallet); if (listAscmRfid.Count > 0) YnDaoHelper.GetInstance().nHibernateHelper.SaveOrUpdateList(listAscmRfid); tx.Commit();//正确执行提交 } catch (Exception ex) { tx.Rollback();//回滚 throw ex; } } } jsonObjectResult.result = true; jsonObjectResult.message = ""; } catch (Exception ex) { jsonObjectResult.message = ex.Message; } string sReturn = JsonConvert.SerializeObject(jsonObjectResult); return Content(sReturn); }