public void Delete(AscmDriver ascmDriver) { try { YnDaoHelper.GetInstance().nHibernateHelper.Delete<AscmDriver>(ascmDriver); } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmDriver)", ex); throw ex; } }
public void Update(AscmDriver ascmDriver) { try { using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction()) { try { YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmDriver>(ascmDriver); tx.Commit();//正确执行提交 } catch (Exception ex) { tx.Rollback();//回滚 YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmDriver)", ex); throw ex; } } } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Save AscmDriver)", ex); throw ex; } }
public ContentResult DriverSave(AscmDriver ascmDriver_Model, int? id) { JsonObjectResult jsonObjectResult = new JsonObjectResult(); try { string userName = string.Empty; if (User.Identity.IsAuthenticated) { userName = User.Identity.Name; } if (ascmDriver_Model.rfid == null || ascmDriver_Model.rfid == "") throw new Exception("必须输入RFID编号"); string rfid = ascmDriver_Model.rfid.Trim(); AscmSupplier ascmSupplier = null; AscmDriver ascmDriver = null; AscmRfid ascmRfid = null; AscmRfid ascmRfidOld = null; if (id.HasValue) { ascmDriver = AscmDriverService.GetInstance().Get(id.Value); if (ascmDriver == null) throw new Exception("保存司机失败!"); ascmDriver.modifyUser = userName; ascmDriver.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); ascmSupplier = AscmSupplierService.GetInstance().Get(ascmDriver.supplierId); if (ascmDriver.rfid != rfid) { object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmRfid where id='" + rfid + "'"); if (object1 == null) throw new Exception("查询异常!"); int count = 0; if (int.TryParse(object1.ToString(), out count) && count > 0) throw new Exception("已存在编号【" + rfid + "】"); ascmRfidOld = AscmRfidService.GetInstance().Get(ascmDriver.sn); if (ascmRfidOld != null) { object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmDriverDelivery where driverSn='" + ascmRfidOld.id + "'"); if (object1 == null) throw new Exception("查询异常!"); count = 0; if (int.TryParse(object1.ToString(), out count) && count > 0) throw new Exception("不能修改已绑定物料的司机编号"); } ascmRfid = new AscmRfid(); ascmRfid.id = rfid; 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.driver; ascmRfid.bindId = rfid; ascmRfid.status = AscmRfid.StatusDefine.inUse; } } else { object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmRfid where id='" + rfid + "'"); if (object1 == null) throw new Exception("查询异常!"); int count = 0; if (int.TryParse(object1.ToString(), out count) && count > 0) throw new Exception("已存在编号"); ascmSupplier = AscmSupplierService.GetInstance().Get(ascmDriver_Model.supplierId); if (ascmSupplier == null) throw new Exception("供应商不存在"); ascmDriver = new AscmDriver(); int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmDriver"); ascmDriver.id = ++maxId; ascmDriver.supplierId = ascmDriver_Model.supplierId; ascmDriver.status = ascmDriver_Model.status; ascmDriver.createUser = userName; ascmDriver.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); ascmDriver.modifyUser = userName; ascmDriver.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); ascmRfid = new AscmRfid(); ascmRfid.id = rfid; 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.driver; ascmRfid.bindId = rfid; ascmRfid.status = AscmRfid.StatusDefine.inUse; } if (!string.IsNullOrEmpty(ascmDriver_Model.name)) { ascmDriver.name = ascmDriver_Model.name.Trim(); object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject( "select count(*) from AscmDriver where supplierId=" + ascmDriver.supplierId + " and name='" + ascmDriver.name + "' and id<>" + ascmDriver.id); if (object1 == null) throw new Exception("查询异常!"); int count = 0; if (int.TryParse(object1.ToString(), out count) && count > 0) throw new Exception("供应商【" + ascmSupplier.name + "】中已存在司机【" + ascmDriver.name + "】"); } ascmDriver.sn = rfid; ascmDriver.rfid = rfid; ascmDriver.sex = ascmDriver_Model.sex; if (!string.IsNullOrEmpty(ascmDriver_Model.idNumber)) ascmDriver.idNumber = ascmDriver_Model.idNumber.Trim(); if (!string.IsNullOrEmpty(ascmDriver_Model.mobileTel)) ascmDriver.mobileTel = ascmDriver_Model.mobileTel.Trim(); if (!string.IsNullOrEmpty(ascmDriver_Model.plateNumber)) ascmDriver.plateNumber = ascmDriver_Model.plateNumber.Trim(); ascmDriver.load = ascmDriver_Model.load; if (!string.IsNullOrEmpty(ascmDriver_Model.description)) ascmDriver.description = ascmDriver_Model.description.Trim(); ascmDriver.type = ascmDriver_Model.type; using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction()) { try { if (ascmDriver != null) YnDaoHelper.GetInstance().nHibernateHelper.SaveOrUpdate(ascmDriver); if (ascmRfid != null) YnDaoHelper.GetInstance().nHibernateHelper.SaveOrUpdate(ascmRfid); if (ascmRfidOld != null) YnDaoHelper.GetInstance().nHibernateHelper.Delete(ascmRfidOld); tx.Commit();//正确执行提交 jsonObjectResult.result = true; jsonObjectResult.id = ascmDriver.id.ToString(); jsonObjectResult.entity = ascmDriver; jsonObjectResult.message = ""; } catch (Exception ex) { tx.Rollback();//回滚 throw ex; } } } catch (Exception ex) { jsonObjectResult.message = ex.Message; } string sReturn = JsonConvert.SerializeObject(jsonObjectResult); return Content(sReturn); }