EctomereAction.java
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:8k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. //Created by MyEclipse Struts
  2. // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl
  3. package com.oa.module.pub.ectomere;
  4. import java.text.DateFormat;
  5. import java.text.SimpleDateFormat;
  6. import java.util.Calendar;
  7. import java.lang.reflect.InvocationTargetException;
  8. import java.util.Date;
  9. import java.util.List;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. import javax.servlet.http.HttpSession;
  13. import org.hibernate.Session;
  14. import org.hibernate.SessionFactory;
  15. import org.apache.commons.beanutils.BeanUtils;
  16. import org.apache.struts.action.ActionForm;
  17. import org.apache.struts.action.ActionForward;
  18. import org.apache.struts.action.ActionMapping;
  19. import org.apache.struts.actions.DispatchAction;
  20. import com.oa.module.office.user.Tuser;
  21. /** 
  22.  * MyEclipse Struts
  23.  * Creation date: 01-17-2008
  24.  * 
  25.  * // 欢迎${sessionScope.adminuserbean.loginname}登录! 
  26.  
  27.   //String uno = (String)((Tuser) request.getSession().getAttribute("?????")).getUno();
  28.  * 
  29.  * XDoclet definition:
  30.  * @struts.action path="/ectomere" name="ectomereForm" input="/Jsp_file/ectomere/exteriorlist.jsp" parameter="task" scope="request" validate="true"
  31.  */
  32. public class EctomereAction extends DispatchAction {
  33. // --------------------------------------------------------- Instance Variables
  34. private EctomereDAO ectomeredao;
  35. // --------------------------------------------------------- Methods
  36. /** 
  37.  * Method execute
  38.  * @param mapping
  39.  * @param form
  40.  * @param request
  41.  * @param response
  42.  * @return ActionForward
  43.  * @throws InvocationTargetException 
  44.  */
  45. //查询
  46. public ActionForward query(
  47. ActionMapping mapping,
  48. ActionForm form,
  49. HttpServletRequest request,
  50. HttpServletResponse response){
  51. EctomereForm ectomereForm = (EctomereForm) form;
  52. System.out.println(ectomeredao);
  53. int currentPage=1;
  54. try {
  55. currentPage=Integer.parseInt(request.getParameter("currentPage"));
  56. } catch (Exception e) {
  57. currentPage=1;
  58. }
  59. int count=5;
  60. Ectomere ect=new Ectomere();
  61. //拷贝查询参数
  62. try {
  63. BeanUtils.copyProperties(ect,ectomereForm);
  64. } catch (IllegalAccessException e) {
  65. e.printStackTrace();
  66. }catch (InvocationTargetException e) {
  67. e.printStackTrace();
  68. }
  69. List paramlist = null;
  70. List userlist=null;
  71. userlist=ectomeredao.getUser();
  72. paramlist = ectomeredao.getParam();
  73. XPage ectpage = ectomeredao.getEctomerelist(currentPage,count,ect);
  74. request.setAttribute("userlist",userlist);
  75. request.setAttribute("paramlist",paramlist);
  76. request.setAttribute("ectpage",ectpage);
  77. return mapping.findForward("list");
  78. }
  79. //添加
  80. public ActionForward add(
  81. ActionMapping mapping,
  82. ActionForm form,
  83. HttpServletRequest request,
  84. HttpServletResponse response){
  85. EctomereForm ectomereForm = (EctomereForm) form;
  86. //从Session作用域获得本用户ID
  87. HttpSession session = request.getSession();
  88. Tuser user =  (Tuser) session.getAttribute("user");
  89. String userid=user.getUno();
  90. System.out.println(userid);
  91. request.setAttribute("uno",userid);
  92. //获取系统时间
  93. Date date=new Date();
  94. System.out.println(date);
  95. Calendar cd=Calendar.getInstance();
  96. DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm");
  97. String eaddtime=df.format(cd.getTime());
  98. System.out.println(eaddtime);
  99. request.setAttribute("eaddtime",eaddtime);
  100. List paramlist = null;
  101. paramlist = ectomeredao.getParam();
  102. request.setAttribute("paramlist",paramlist);
  103. ectomereForm.setTask("save");
  104. return mapping.getInputForward();
  105. }
  106. //添加保存------------------------------
  107. public ActionForward save(
  108. ActionMapping mapping,
  109. ActionForm form,
  110. HttpServletRequest request,
  111. HttpServletResponse response){
  112. EctomereForm ectomereForm = (EctomereForm) form;
  113. //从Session作用域获得本用户ID
  114. HttpSession session = request.getSession();
  115. Tuser user =  (Tuser) session.getAttribute("user");
  116. String userid=user.getUno();
  117. System.out.println(userid);
  118. Texterior info=new Texterior();
  119. try {
  120. BeanUtils.copyProperties(info, ectomereForm);
  121. } catch (IllegalAccessException e) {
  122. e.printStackTrace();
  123. } catch (InvocationTargetException e) {
  124. e.printStackTrace();
  125. }
  126. boolean flag = ectomeredao.create(info);
  127. if (flag) {
  128. request.setAttribute("msg", "添加外联信息成功");
  129. return mapping.findForward("query");
  130. }else {
  131. request.setAttribute("msg", "添加外联信息失败");
  132. return mapping.getInputForward();
  133. }
  134. }
  135. //编辑
  136. public ActionForward init(
  137. ActionMapping mapping,
  138. ActionForm form,
  139. HttpServletRequest request,
  140. HttpServletResponse response){
  141. EctomereForm ectomereForm = (EctomereForm) form;
  142. //从Session作用域获得本用户ID
  143. HttpSession session = request.getSession();
  144. Tuser user =  (Tuser) session.getAttribute("user");
  145. String userid=user.getUno();
  146. System.out.println(userid);
  147. //判断录入人是否是本人或超级管理员
  148. String uno=request.getParameter("uno");
  149. System.out.println(uno);
  150. //管理员
  151. if(userid.equals("1")||userid.equals(uno)){
  152. //获取系统时间
  153. Date date=new Date();
  154. System.out.println(date);
  155. Calendar cd=Calendar.getInstance();
  156. DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm");
  157. String eaddtime=df.format(cd.getTime());
  158. System.out.println(eaddtime);
  159. request.setAttribute("eaddtime",eaddtime);
  160. request.setAttribute("uno",userid);
  161. Texterior info=ectomeredao.getTexteriorById(new Long(ectomereForm.getEid()));
  162. try {
  163. BeanUtils.copyProperties(ectomereForm,info);
  164. } catch (IllegalAccessException e) {
  165. e.printStackTrace();
  166. } catch (InvocationTargetException e) {
  167. e.printStackTrace();
  168. }
  169. List paramlist = null;
  170. paramlist = ectomeredao.getParam();
  171. request.setAttribute("paramlist",paramlist);
  172. ectomereForm.setTask("edit");
  173. return mapping.getInputForward();
  174. }else{
  175. request.setAttribute("msg","无权限修改");
  176. return mapping.findForward("query");
  177. }
  178. }
  179. //编辑保存
  180. public ActionForward edit(
  181. ActionMapping mapping,
  182. ActionForm form,
  183. HttpServletRequest request,
  184. HttpServletResponse response){
  185. EctomereForm ectomereForm = (EctomereForm) form;
  186. Texterior info=new Texterior();
  187. try {
  188. BeanUtils.copyProperties(info, ectomereForm);
  189. } catch (IllegalAccessException e) {
  190. e.printStackTrace();
  191. } catch (InvocationTargetException e) {
  192. e.printStackTrace();
  193. }
  194. boolean flag=ectomeredao.update(info);
  195. if(flag){
  196. request.setAttribute("msg","修改成功");
  197. return mapping.findForward("query");
  198. }else{
  199. request.setAttribute("msg","修改失败");
  200. return mapping.getInputForward();
  201. }
  202. }
  203. //删除
  204. public ActionForward del(
  205. ActionMapping mapping,
  206. ActionForm form,
  207. HttpServletRequest request,
  208. HttpServletResponse response){
  209. EctomereForm ectomereForm = (EctomereForm) form;
  210. //从Session作用域获得本用户ID
  211. HttpSession session = request.getSession();
  212. Tuser user =  (Tuser) session.getAttribute("user");
  213. String userid=user.getUno();
  214. System.out.println(userid);
  215. String uno=request.getParameter("uno");
  216. System.out.println(uno);
  217. //判断录入人是否是本人或超级管理员
  218. System.out.println(ectomereForm.getUno());
  219. if(userid.equals("1")||userid.equals(uno)){
  220. long eid = ectomereForm.getEid();
  221. System.out.println(eid);
  222. boolean flag =ectomeredao.del(eid);
  223. if (flag) {
  224. request.setAttribute("msg", "删除外联信息成功");
  225. return mapping.findForward("query");
  226. } else {
  227. request.setAttribute("msg", "删除外联信息失败");
  228. return mapping.findForward("query");
  229. }
  230. }else{
  231. request.setAttribute("msg","无权限删除");
  232. return mapping.findForward("query");
  233. }
  234. }
  235. public EctomereDAO getEctomeredao() {
  236. return ectomeredao;
  237. }
  238. public void setEctomeredao(EctomereDAO ectomeredao) {
  239. this.ectomeredao = ectomeredao;
  240. }
  241. }