public void Delete(AscmEmployeeCar ascmEmployeeCar) { try { ////删除与用户的关联 //string sql = "from YnUserRoleLink where ids.roleId=" + ascmEmployeeCar.id; //IList<YnUserRoleLink> ilistUserRoleLink = YnDaoHelper.GetInstance().nHibernateHelper.Find<YnUserRoleLink>(sql); //if (ilistUserRoleLink != null && ilistUserRoleLink.Count > 0) //{ // List<YnUserRoleLink> list = YnBaseClass2.Helper.ConvertHelper.ConvertIListToList<YnUserRoleLink>(ilistUserRoleLink); // YnDaoHelper.GetInstance().nHibernateHelper.DeleteList(list); //} ////删除与模块的关联 //sql = "from YnWebModuleRoleLink where ascmEmployeeCar.id=" + ascmEmployeeCar.id; //IList<YnWebModuleRoleLink> ilistModuleRoleLink = YnDaoHelper.GetInstance().nHibernateHelper.Find<YnWebModuleRoleLink>(sql); //if (ilistModuleRoleLink != null && ilistModuleRoleLink.Count > 0) //{ // List<YnWebModuleRoleLink> list = YnBaseClass2.Helper.ConvertHelper.ConvertIListToList<YnWebModuleRoleLink>(ilistModuleRoleLink); // YnDaoHelper.GetInstance().nHibernateHelper.DeleteList(list); //} YnDaoHelper.GetInstance().nHibernateHelper.Delete<AscmEmployeeCar>(ascmEmployeeCar); } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmEmployeeCar)", ex); throw ex; } }
public ContentResult EmployeeCarSave(AscmEmployeeCar ascmEmployeeCar_Model, int? id) { JsonObjectResult jsonObjectResult = new JsonObjectResult(); try { AscmEmployeeCar ascmEmployeeCar = null; if (id.HasValue) { ascmEmployeeCar = AscmEmployeeCarService.GetInstance().Get(id.Value); } else { ascmEmployeeCar = new AscmEmployeeCar(); } if (ascmEmployeeCar == null) throw new Exception("保存员工车辆基本信息失败!"); if (ascmEmployeeCar_Model.plateNumber == null || ascmEmployeeCar_Model.plateNumber.Trim() == "") throw new Exception("员工车辆车牌号不能为空!"); if (ascmEmployeeCar_Model.rfid.Length != 10) { throw new Exception("rfid编号可能有错误【" + ascmEmployeeCar_Model.rfid.Trim() + "】,请检查,请输入后4位或后6位!"); } //if (ascmEmployeeCar_Model.employeeId==0) // throw new Exception("必须选择输入员工!"); ascmEmployeeCar.plateNumber = ascmEmployeeCar_Model.plateNumber.Trim(); ascmEmployeeCar.spec = ascmEmployeeCar_Model.spec; ascmEmployeeCar.color = ascmEmployeeCar_Model.color; ascmEmployeeCar.seatCount = ascmEmployeeCar_Model.seatCount; ascmEmployeeCar.rfid = ascmEmployeeCar_Model.rfid.Trim(); ascmEmployeeCar.memo = ascmEmployeeCar_Model.memo; //ascmEmployeeCar.employeeId = ascmEmployeeCar_Model.employeeId; ascmEmployeeCar.employeeDocNumber = ascmEmployeeCar_Model.employeeDocNumber; if (!string.IsNullOrEmpty(ascmEmployeeCar.employeeDocNumber)) ascmEmployeeCar.employeeDocNumber = ascmEmployeeCar.employeeDocNumber.Trim(); ascmEmployeeCar.employeeName = ascmEmployeeCar_Model.employeeName; if (!string.IsNullOrEmpty(ascmEmployeeCar.employeeName)) ascmEmployeeCar.employeeName = ascmEmployeeCar.employeeName.Trim(); ascmEmployeeCar.employeeSex = ascmEmployeeCar_Model.employeeSex; if (!string.IsNullOrEmpty(ascmEmployeeCar.employeeSex)) ascmEmployeeCar.employeeSex = ascmEmployeeCar.employeeSex.Trim(); ascmEmployeeCar.employeeIdNumber = ascmEmployeeCar_Model.employeeIdNumber; if (!string.IsNullOrEmpty(ascmEmployeeCar.employeeIdNumber)) ascmEmployeeCar.employeeIdNumber = ascmEmployeeCar.employeeIdNumber.Trim(); ascmEmployeeCar.employeeOfficeTel = ascmEmployeeCar_Model.employeeOfficeTel; ascmEmployeeCar.employeeMobileTel = ascmEmployeeCar_Model.employeeMobileTel; ascmEmployeeCar.exemption = ascmEmployeeCar_Model.exemption; ascmEmployeeCar.employeeLevel = ascmEmployeeCar_Model.employeeLevel; AscmRfid ascmRfid_Old = null; AscmRfid ascmRfid_New_Update = null; AscmRfid ascmRfid_New_Save = null; bool _new = true; if (!id.HasValue) { object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmEmployeeCar where plateNumber='" + ascmEmployeeCar_Model.plateNumber.Trim() + "'"); if (object1 == null) throw new Exception("查询异常!"); int iCount = 0; if (int.TryParse(object1.ToString(), out iCount) && iCount > 0) throw new Exception("已经存在此员工车辆车牌号【" + ascmEmployeeCar_Model.plateNumber.Trim() + "】!"); if (!string.IsNullOrEmpty(ascmEmployeeCar_Model.rfid)) { object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmEmployeeCar where rfid='" + ascmEmployeeCar_Model.rfid.Trim() + "'"); if (object1 == null) throw new Exception("查询异常!"); //int iCount = 0; if (int.TryParse(object1.ToString(), out iCount) && iCount > 0) throw new Exception("已经分配此车辆RFID【" + ascmEmployeeCar_Model.rfid.Trim() + "】!"); } int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmEmployeeCar"); ascmEmployeeCar.id = maxId+1; //AscmEmployeeCarService.GetInstance().Save(ascmEmployeeCar); } else { _new = false; if (ascmEmployeeCar.rfid!=null) ascmRfid_Old = AscmRfidService.GetInstance().Get(ascmEmployeeCar.rfid.Trim()); object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmEmployeeCar where plateNumber='" + ascmEmployeeCar_Model.plateNumber.Trim() + "' and id<>" + id.Value + ""); if (object1 == null) throw new Exception("查询异常!"); int iCount = 0; if (int.TryParse(object1.ToString(), out iCount) && iCount > 0) throw new Exception("已经存在此员工车辆车牌号【" + ascmEmployeeCar_Model.plateNumber.Trim() + "】!"); if (!string.IsNullOrEmpty(ascmEmployeeCar_Model.rfid)) { object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmEmployeeCar where rfid='" + ascmEmployeeCar_Model.rfid.Trim() + "' and id<>" + id.Value + ""); if (object1 == null) throw new Exception("查询异常!"); //int iCount = 0; if (int.TryParse(object1.ToString(), out iCount) && iCount > 0) throw new Exception("已经分配此车辆RFID【" + ascmEmployeeCar_Model.rfid.Trim() + "】!"); } //AscmEmployeeCarService.GetInstance().Update(ascmEmployeeCar); } ascmRfid_New_Update = AscmRfidService.GetInstance().Get(ascmEmployeeCar.rfid.Trim()); if (ascmRfid_Old != null && ascmRfid_New_Update != null) { if (ascmRfid_Old.id == ascmRfid_New_Update.id) { ascmRfid_Old = null; } } if (ascmRfid_Old != null) { ascmRfid_Old.bindType = AscmRfid.BindTypeDefine.employeeCar; ascmRfid_Old.bindId = ""; ascmRfid_Old.status = AscmRfid.StatusDefine.none; //ascmRfid_Old.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss"); } if (ascmRfid_New_Update != null) { ascmRfid_New_Update.bindType = AscmRfid.BindTypeDefine.employeeCar; ascmRfid_New_Update.bindId = ascmEmployeeCar.id.ToString(); ascmRfid_New_Update.status = AscmRfid.StatusDefine.inUse; //ascmRfid_New_Update.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss"); } else { ascmRfid_New_Save = new AscmRfid(); ascmRfid_New_Save.id = ascmEmployeeCar.rfid; ascmRfid_New_Save.createUser = ""; //ascmRfid_New_Save.createTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss"); //ascmRfid_New_Save.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss"); ascmRfid_New_Save.bindType = AscmRfid.BindTypeDefine.employeeCar; ascmRfid_New_Save.bindId = ascmEmployeeCar.id.ToString(); ascmRfid_New_Save.status = AscmRfid.StatusDefine.inUse; } /* if (string.IsNullOrEmpty(ascmEmployeeCar_Model.rfid)) { ascmEmployeeCar.rfid = ""; //取消绑定 if (ascmRfid_Old != null) { ascmRfid_Old.bindId = ""; ascmRfid_Old.status = ""; } } else { //增加绑定 ascmRfid_New = AscmRfidService.GetInstance().Get(ascmEmployeeCar_Model.rfid.Trim()); if (ascmRfid_New == null) throw new Exception("RFID标签号码不存在!"); if (ascmRfid_New.bindType != AscmRfid.BindTypeDefine.employeeCar) throw new Exception("请选择[" + AscmRfid.BindTypeDefine.DisplayText(ascmRfid_New.bindType) + "]类型的RFID标签!"); if (ascmRfid_Old != null) { //存在原绑定 if (ascmRfid_Old.id == ascmRfid_New.id) { //没有改变绑定 ascmRfid_Old = null; } else { //新绑定 ascmRfid_Old.bindId = ""; ascmRfid_Old.status = ""; if (!string.IsNullOrEmpty(ascmRfid_New.status) && ascmRfid_New.status != AscmRfid.StatusDefine.cancel) throw new Exception("RFID标签【" + ascmRfid_New.id + "】已经处于[" + AscmRfid.StatusDefine.DisplayText(ascmRfid_New.status) + "]状态,不能重复绑定!"); if (!string.IsNullOrEmpty(ascmRfid_New.bindId)) throw new Exception("RFID标签【" + ascmRfid_New.id + "】已经绑定[" + ascmRfid_New.bindId + "],不能重复绑定!"); ascmRfid_New.bindId = ascmEmployeeCar.id.ToString(); ascmRfid_New.status = ""; ascmEmployeeCar.rfid = ascmRfid_New.id; } } else { ascmRfid_New.bindId = ascmEmployeeCar.id.ToString(); ascmRfid_New.status = ""; ascmEmployeeCar.rfid = ascmRfid_New.id; } } */ AscmEmployeeCarService.GetInstance().Save(_new, ascmEmployeeCar, ascmRfid_Old, ascmRfid_New_Update, ascmRfid_New_Save); /* using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction()) { try { if (!id.HasValue) { YnDaoHelper.GetInstance().nHibernateHelper.Save(ascmEmployeeCar); } else { YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmEmployeeCar); } if (ascmRfid_Old!=null) YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmRfid_Old); if (ascmRfid_New != null) YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmRfid_New); tx.Commit();//正确执行提交 } catch (Exception ex) { tx.Rollback();//回滚 throw ex; } }*/ jsonObjectResult.result = true; jsonObjectResult.message = ""; jsonObjectResult.id = ascmEmployeeCar.id.ToString(); jsonObjectResult.entity = ascmEmployeeCar; } catch (Exception ex) { jsonObjectResult.message = ex.Message; } string sReturn = JsonConvert.SerializeObject(jsonObjectResult); return Content(sReturn); }
public void Save(bool _new, AscmEmployeeCar ascmEmployeeCar, AscmRfid ascmRfid_Old, AscmRfid ascmRfid_New_Update, AscmRfid ascmRfid_New_Save) { try { DateTime dtServerTime = MideaAscm.Dal.YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentDate("AscmEmployeeCar"); ascmEmployeeCar.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss"); if (ascmRfid_Old != null) ascmRfid_Old.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss"); if (ascmRfid_New_Update != null) ascmRfid_New_Update.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss"); if (ascmRfid_New_Save != null) ascmRfid_New_Save.modifyTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss"); using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction()) { try { if (_new) { ascmEmployeeCar.createTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss"); YnDaoHelper.GetInstance().nHibernateHelper.Save(ascmEmployeeCar); } else { YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmEmployeeCar); } if (ascmRfid_Old != null) YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmRfid_Old); if (ascmRfid_New_Update != null) YnDaoHelper.GetInstance().nHibernateHelper.Update(ascmRfid_New_Update); if (ascmRfid_New_Save != null) { ascmRfid_New_Save.createTime = dtServerTime.ToString("yyyy-MM-dd HH:mm:ss"); YnDaoHelper.GetInstance().nHibernateHelper.Save(ascmRfid_New_Save); } tx.Commit();//正确执行提交 } catch (Exception ex) { tx.Rollback();//回滚 throw ex; } } } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("保存失败(Save AscmEmployeeCar)", ex); throw ex; } }
public void Update(AscmEmployeeCar ascmEmployeeCar) { int count = YnDaoHelper.GetInstance().nHibernateHelper.GetCount("select count(*) from AscmEmployeeCar where id<>" + ascmEmployeeCar.id + " and plateNumber='" + ascmEmployeeCar.plateNumber + "'"); if (count == 0) { using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction()) { try { YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmEmployeeCar>(ascmEmployeeCar); tx.Commit();//正确执行提交 } catch (Exception ex) { tx.Rollback();//回滚 YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmEmployeeCar)", ex); throw ex; } } } else { throw new Exception("已经存在车辆牌号\"" + ascmEmployeeCar.plateNumber + "\"!"); } }
public void Save(AscmEmployeeCar ascmEmployeeCar) { try { int count = YnDaoHelper.GetInstance().nHibernateHelper.GetCount("select count(*) from AscmEmployeeCar where plateNumber='" + ascmEmployeeCar.plateNumber + "'"); if (count == 0) { int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmEmployeeCar"); using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction()) { try { maxId++; ascmEmployeeCar.id = maxId; YnDaoHelper.GetInstance().nHibernateHelper.Save(ascmEmployeeCar); tx.Commit();//正确执行提交 } catch (Exception ex) { tx.Rollback();//回滚 throw ex; } } } else { throw new Exception("已经存在车辆牌号\"" + ascmEmployeeCar.plateNumber + "\"!"); } } catch (Exception ex) { YnBaseClass2.Helper.LogHelper.GetLog().Error("保存失败(Save AscmEmployeeCar)", ex); throw ex; } }