/// <summary> /// 添加客户的地址 /// </summary> /// <param name="cstmrAddr"></param> /// <returns></returns> public ActionResult Add(CustomerAddr cstmrAddr) { CustomerAddr retVal = null; ISession s = null; ITransaction trans = null; try { s = HibernateOper.GetCurrentSession(); trans = s.BeginTransaction(); //查找客户ID if (cstmrAddr.AddrCode != null && !cstmrAddr.AddrCode.Equals("")) { cstmrAddr.Addr = PojoUtil.GetAddrForCode(s, cstmrAddr.AddrCode); LocationUtil.Location loc = LocationUtil.GetLocation(cstmrAddr.Addr + cstmrAddr.Location); if (loc != null) { cstmrAddr.Lat = loc.lat; cstmrAddr.Lng = loc.lng; } } string openId = cstmrAddr.Cstmr.OpenId; cstmrAddr.Cstmr = PojoUtil.GetCust(s, openId); if (cstmrAddr.Cstmr == null) { if (openId == null || openId.Equals("")) { //客户不存在 throw new Exceptions.CstmrIsNotExistsException(); } Customer cstmr = new Customer(); cstmr.OpenId = openId; s.Save(cstmr); cstmrAddr.Cstmr = cstmr; } s.Save(cstmrAddr); trans.Commit(); retVal = cstmrAddr; } catch (Exception e) { if (trans != null) { trans.Rollback(); } throw e; } return(Json(retVal)); }
private IList <Mod> GetMods(Guid modPId) { IList <Mod> retVal = new List <Mod>(); ISession s = null; ITransaction tran = null; try { s = HibernateOper.GetCurrentSession(); tran = s.BeginTransaction(); ICriterion criterion = null; ICriteria criteria = s.CreateCriteria(typeof(EmpMod)); criterion = Restrictions.Eq("Del", false); criteria.Add(criterion); criterion = Restrictions.Eq("RoleFlag", EmpModFunc.RoleFlagValStr(EmpModFunc.RoleFlagVal.Emp)); criteria.Add(criterion); criterion = Restrictions.Eq("RoleId", MySelf.Id); criteria.Add(criterion); ICriteria modCriteria = criteria.CreateCriteria("Mod", "m"); criterion = Restrictions.Eq("Del", false); modCriteria.Add(criterion); criterion = Restrictions.Eq("PId", modPId); modCriteria.Add(criterion); modCriteria.AddOrder(Order.Asc("Index")); IList <EmpMod> empMods = criteria.List <EmpMod>(); if (empMods != null) { foreach (EmpMod empMod in empMods) { retVal.Add(empMod.Mod); } empMods.Clear(); } tran.Commit(); } catch (Exception e) { if (tran != null) { tran.Rollback(); } } return(retVal); }
/// <summary> /// 客户的地址 /// </summary> /// <returns></returns> public ActionResult Get(Customer cstmr) { IList <CustomerAddr> retVal = null; ISession s = null; ITransaction trans = null; try { s = HibernateOper.GetCurrentSession(); trans = s.BeginTransaction(); //查找客户ID string openId = cstmr.OpenId; cstmr = PojoUtil.GetCust(s, openId); if (cstmr == null) { //客户不存在 throw new Exceptions.CstmrIsNotExistsException(); } else { //查找客户的所有地址 ICriteria criteria = s.CreateCriteria(typeof(CustomerAddr)); criteria.Add(Restrictions.Eq("Cstmr", cstmr)); retVal = criteria.List <CustomerAddr>(); } trans.Commit(); } catch (Exception e) { if (trans != null) { trans.Rollback(); } throw e; } return(Json(retVal)); }
//查找地址码 public ActionResult Add(WorkAndWorkTypeDetails wawtd) { bool retVal = false; Work work = wawtd.Work; //主工单 WorkSub workSub = wawtd.WorkSub; //子工单 if (workSub == null) { workSub = new WorkSub(); } IList <WorkTypeDetail> workTypeDetails = wawtd.WorkTypeDetails; //子工单维修类型 IList <WorkPic> workPics = wawtd.WorkPics; //子工单图片 ISession s = null; ITransaction trans = null; try { s = HibernateOper.GetCurrentSession(); trans = s.BeginTransaction(); //如果主工单的ID不存在则新建主工单,有可能是在原来的主工单基础上追加的子工单就会把主工单的ID传过来 if (work.Id == Guid.Empty) { //生成工单编号 work.Code = DateTime.Now.ToString("yyyyMMddHHmmssfffff"); //查找客户ID string openId = work.Cstmr.OpenId; work.Cstmr = PojoUtil.GetCust(s, openId); if (work.Cstmr == null) { Customer cstmr = new Customer(); cstmr.OpenId = openId; s.Save(cstmr); work.Cstmr = cstmr; } //保存工单 s.Save(work); } else { //根据工单ID找到工单 work = s.Get <Work>(work.Id); if (work == null) { //工单不存在 throw new Exceptions.WorkIsNotFoundException(); } } //保存子工单 //如果子工单的下单员工存在 if (workSub.OrderEmp != null) { //如果子工单的下单员ID存在 if (workSub.OrderEmp.Id != Guid.Empty) { workSub.OrderEmp = s.Get <Employee>(workSub.OrderEmp.Id); } //如果子工单的下单员工号存在 if (workSub.OrderEmp.Code != null && !workSub.OrderEmp.Code.ToString().Equals("")) { workSub.OrderEmp = PojoUtil.GetEmployee(s, workSub.OrderEmp.Code); } if (workSub.OrderEmp == null) { //该下单员不存在 throw new Exceptions.EmployeeIsNotFoundException(); } } workSub.Work = work; //根据工单地址自动分配任务到分店 workSub.Dept = PojoUtil.GetMinDistDept(s, work); s.Save(workSub); //保存维修类型 if (workTypeDetails != null) { foreach (WorkTypeDetail wtd in workTypeDetails) { wtd.WorkSub = workSub; s.Save(wtd); } } else { //维修类型明细不存在 throw new Exceptions.WorkTypeDetailIsNotFoundException(); } //保存图片 if (workPics != null) { foreach (WorkPic wp in workPics) { wp.WorkSub = workSub; s.Save(wp); } } trans.Commit(); retVal = true; } catch (Exception e) { if (trans != null) { trans.Rollback(); } throw e; } return(Json(retVal)); }
public ActionResult ImportData(string cls) { //string table = "Department"; IList <ImportResult> retVal = new List <ImportResult>(); string path = Server.MapPath("/") + @"Files\Temp\"; ////文件上传,一次上传1M的数据,防止出现大文件无法上传 HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { //保存上传的文件 File file = SaveHttpPostFile(files[i], path); if (file.Size == 0) { continue; } Type type = Type.GetType("EasyJob.Pojo.Pojo." + cls + ",EasyJob.Pojo"); ImportExcel ie = new ImportExcel(file.RealPath, type); IList <object> vals = ie.List(type); //数据存储 ISession s = null; ITransaction trans = null; try { s = HibernateOper.GetCurrentSession(); trans = s.BeginTransaction(); foreach (object val in vals) { if (val is TbBase && val is IExists) { ImportResult ir = new ImportResult(); TbBase tbVal = (TbBase)val; try { bool isExists = false;//是否存在 IExists valExists = (IExists)tbVal; isExists = valExists.IsExists(s); if (tbVal.ImportType.Equals("添加")) { if (isExists) { throw new Exception("Val is exists"); } s.Save(tbVal); } else if (tbVal.ImportType.Equals("修改")) { if (!isExists) { throw new Exception("Val is not exists"); } //s.Update(tbVal); s.Merge(tbVal); } ir.Success = true; } catch (Exception e) { ir.Success = false; ir.Msg = e.Message; } finally { retVal.Add(ir); } } } trans.Commit(); } catch (Exception e) { if (trans != null) { trans.Rollback(); } throw e; } } return(Json(retVal)); }