Guest User

Untitled

a guest
May 20th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.79 KB | None | 0 0
  1. <div id="div2" class="hide">
  2. <label for="nonCICAccountName">Account Name:</label> &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="nonCICAccountName" id="nonCICAccountName" /> <br />
  3. <label for="country">Country:</label> &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="country" id="country" /> <br />
  4. <label for="countryNumber">Country Number:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  5. <input type="text" name="countryNumber" id="countryNumber" /> <br />
  6. <label for="locationName">Location Name:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  7. <input type="text" name="locationName" id="locationName" /> <br />
  8. <label for="locationNumber">Location Number:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  9. <input type="text" name="locationNumber" id="locationNumber" /> <br />
  10. <label for="departmentName">Department Name:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  11. <input type="text" name="departmentName" id="departmentName" /> <br />
  12. <label for="departmentNumber">Department Number:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  13. <input type="text" name="departmentNumber" id="departmentNumber" /> <br />
  14. <label for="division">Division:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  15. <input type="text" name="division" id="division" /> <br />
  16. <label for="major">Major:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  17. <input type="text" name="major" id="major" /> <br />
  18. <label for="minor">Minor:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  19. <input type="text" name="minor" id="minor" /> <br />
  20. <label for="subminor">Subminor:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  21. <input type="text" name="subminor" id="subminor" /> <br />
  22. <label for="leru">Leru:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  23. <input type="text" name="leru" id="leru" /> <br />
  24. <label for="task">Task:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  25. <input type="text" name="task" id="task" /> <br />
  26. <label for="approvingManager">Approving Manager:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  27. <input type="text" name="approvingManager" id="approvingManager" /> <br />
  28. <label for="financialApprover">Financial Approver:</label>&nbsp;&nbsp;&nbsp;&nbsp;
  29. <input type="text" name="financialApprover" id="financialApprover" /> <br />
  30.  
  31. <br /> <input type="button" value="Create NonCIC Account" onclick="createNonCICAccount();">
  32. <input type="button" value="Search Account" onclick="searchNonCICAccount();">
  33. </div>
  34.  
  35. function createNonCICAccount()
  36. {
  37.  
  38. var accountName = document.getElementById("nonCICAccountName").value;
  39. var country = document.getElementById("country").value;
  40. var countryNumber = document.getElementById("countryNumber").value;
  41. var locationName = document.getElementById("locationName").value;
  42. var locationNumber = document.getElementById("locationNumber").value;
  43.  
  44. var departmentName = document.getElementById("departmentName").value;
  45. var departmentNumber = document.getElementById("departmentNumber").value;
  46. var division = document.getElementById("division").value;
  47.  
  48.  
  49.  
  50. var major = document.getElementById("major").value;
  51. var minor = document.getElementById("minor").value;
  52. var subminor = document.getElementById("subminor").value;
  53. var leru = document.getElementById("leru").value;
  54. var task = document.getElementById("task").value;
  55. var approvingManager = document.getElementById("approvingManager").value;
  56. var financialApprover = document.getElementById("financialApprover").value;
  57.  
  58.  
  59. $.ajax({
  60. type: "POST",
  61. url: "NonCICAccountController",
  62. data: {"action":"createNonCICAccount",
  63. "nonCICAccountName":accountName,"country":country,"countryNumber":countryNumber,"locationName":locationName,"locationNumber":locationNumber,"departmentName":departmentName,"departmentmentNumber":departmentNumber,"division":division,"major":major,"minor":minor,
  64. "subminor":subminor,"leru":leru,"task":task,"approvingManager":approvingManager,"financialApprover":financialApprover},
  65. success: function(data,jqXHR){
  66. $("#accMessageDiv").html(data);
  67. reset();
  68. },
  69. error: function(data,jqXHR){
  70. $("#accMessageDiv").html(data);
  71. },
  72. beforeSend: function() {
  73. // setting a timeout
  74.  
  75. },
  76. complete: function()
  77. {
  78.  
  79. }
  80. });
  81.  
  82. }
  83.  
  84. package com.coetool.servlet.model;
  85.  
  86. public class NonCICAccount {
  87.  
  88. private int accountId;
  89.  
  90. private String accountName;
  91.  
  92. private String country;
  93. private int countryNumber;
  94. private String locationName;
  95. private String locationNumber;
  96. private String departmentName;
  97. private String departmentNumber;
  98. private String division;
  99. private int major;
  100. private int minor;
  101. private int subminor;
  102. private String leru;
  103. private int task;
  104. private String approvingManager;
  105. private String financialApprover;
  106.  
  107. public NonCICAccount() {}
  108.  
  109.  
  110.  
  111. public NonCICAccount(int accountId, String accountName, String country,int countryNumber,String locationName,String locationNumber,String departmentName,String departmentNumber,String division,int major, int minor,
  112. int subminor,String leru,int task,String approvingManager,String financialApprover)
  113. {
  114. this.accountId=accountId;
  115. this.accountName=accountName;
  116. this.country = country;
  117. this.countryNumber = countryNumber;
  118. this.locationName = locationName;
  119. this.locationNumber = locationNumber;
  120. this.departmentName = departmentName;
  121. this.departmentNumber = departmentNumber;
  122. this.division = division;
  123. this.major = major;
  124. this.minor = minor;
  125. this.subminor = subminor;
  126. this.leru = leru;
  127. this.task = task;
  128. this.approvingManager = approvingManager;
  129. this.financialApprover = financialApprover;
  130. }
  131.  
  132. public int getAccountId() {
  133. return accountId;
  134. }
  135.  
  136.  
  137.  
  138. public void setAccountId(int accountId) {
  139. this.accountId = accountId;
  140. }
  141.  
  142. public String getAccountName() {
  143. return accountName;
  144. }
  145.  
  146.  
  147.  
  148. public void setAccountName(String accountName) {
  149. this.accountName = accountName;
  150. }
  151.  
  152.  
  153.  
  154. public String getCountry() {
  155. return country;
  156. }
  157.  
  158.  
  159.  
  160. public void setCountry(String country) {
  161. this.country = country;
  162. }
  163.  
  164.  
  165.  
  166. public int getCountryNumber() {
  167. return countryNumber;
  168. }
  169.  
  170.  
  171.  
  172. public void setCountryNumber(int countryNumber) {
  173. this.countryNumber = countryNumber;
  174. }
  175.  
  176.  
  177.  
  178. public String getLocationName() {
  179. return locationName;
  180. }
  181.  
  182.  
  183.  
  184. public void setLocationName(String locationName) {
  185. this.locationName = locationName;
  186. }
  187.  
  188.  
  189.  
  190. public String getLocationNumber() {
  191. return locationNumber;
  192. }
  193.  
  194.  
  195.  
  196. public void setLocationNumber(String locationNumber) {
  197. this.locationNumber = locationNumber;
  198. }
  199.  
  200.  
  201.  
  202. public String getDepartmentName() {
  203. return departmentName;
  204. }
  205.  
  206.  
  207.  
  208. public void setDepartmentName(String departmentName) {
  209. this.departmentName = departmentName;
  210. }
  211.  
  212.  
  213.  
  214. public String getDepartmentNumber() {
  215. return departmentNumber;
  216. }
  217.  
  218.  
  219.  
  220. public void setDepartmentNumber(String departmentNumber) {
  221. this.departmentNumber = departmentNumber;
  222. }
  223.  
  224.  
  225.  
  226. public String getDivision() {
  227. return division;
  228. }
  229.  
  230.  
  231.  
  232. public void setDivision(String division) {
  233. this.division = division;
  234. }
  235.  
  236.  
  237.  
  238. public int getMajor() {
  239. return major;
  240. }
  241.  
  242.  
  243.  
  244. public void setMajor(int major) {
  245. this.major = major;
  246. }
  247.  
  248.  
  249.  
  250. public int getMinor() {
  251. return minor;
  252. }
  253.  
  254.  
  255.  
  256. public void setMinor(int minor) {
  257. this.minor = minor;
  258. }
  259.  
  260.  
  261.  
  262. public int getSubminor() {
  263. return subminor;
  264. }
  265.  
  266.  
  267.  
  268. public void setSubminor(int subminor) {
  269. this.subminor = subminor;
  270. }
  271.  
  272.  
  273.  
  274. public String getLeru() {
  275. return leru;
  276. }
  277.  
  278.  
  279.  
  280. public void setLeru(String leru) {
  281. this.leru = leru;
  282. }
  283.  
  284.  
  285.  
  286. public int getTask() {
  287. return task;
  288. }
  289.  
  290.  
  291.  
  292. public void setTask(int task) {
  293. this.task = task;
  294. }
  295.  
  296.  
  297.  
  298. public String getApprovingManager() {
  299. return approvingManager;
  300. }
  301.  
  302.  
  303.  
  304. public void setApprovingManager(String approvingManager) {
  305. this.approvingManager = approvingManager;
  306. }
  307.  
  308.  
  309.  
  310. public String getFinancialApprover() {
  311. return financialApprover;
  312. }
  313.  
  314.  
  315.  
  316. public void setFinancialApprover(String financialApprover) {
  317. this.financialApprover = financialApprover;
  318. }
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330. }
  331.  
  332. protected void createNonCICAccount(HttpServletRequest request,HttpServletResponse response) throws IOException
  333. {
  334. String error;
  335.  
  336. NonCICAccount account = new NonCICAccount();
  337.  
  338. account = fillAttributes(account, request);
  339. PrintWriter out = response.getWriter();
  340. HttpSession session = request.getSession();
  341. NonCICAccountDAO accountDAO = new NonCICAccountDAOImpl();
  342. NonCICAccount accountToBeFetched = null;
  343.  
  344. int result=0;
  345. try {
  346. if(account.getAccountName() != null && account.getDepartmentName() != null && account.getDepartmentNumber() !=null)
  347. {
  348. accountToBeFetched = accountDAO.getNonCICAccountDetailsWithAccountNameAndDepartmentNumber(account);
  349. if(accountToBeFetched== null)
  350. result = accountDAO.createNonCICAccount(account);
  351.  
  352. }
  353. } catch (SQLException e) {
  354. // TODO Auto-generated catch block
  355. e.printStackTrace();
  356. }
  357.  
  358. if (account.getAccountName() == null || account.getDepartmentName() == null || account.getDepartmentNumber() == null ) {
  359. error = "Please provide the Account Name, Department Name and Department Number.";
  360.  
  361.  
  362. out.write("<p style='color:red;'>"+error+"</p>");
  363. }
  364. else if(accountToBeFetched != null && (account.getAccountName() != null || account.getDepartmentName() != null || account.getDepartmentNumber() != null ))
  365. {
  366. error = "Account already exist with given Account Name, Department Name and Department Number.";
  367. out.write("<p style='color:red;'>"+error+"</p>");
  368. }
  369. else {
  370. String msg = "Account :"+account.getAccountName() + " successfully added. ";
  371. out.write("<p style='color:blue;'>"+msg+"</p>");
  372. /*session.setAttribute("message", msg);
  373. session.removeAttribute("error");
  374. response.sendRedirect("index.jsp");*/
  375. }
  376.  
  377. }
  378.  
  379. private NonCICAccount fillAttributes(NonCICAccount account,HttpServletRequest request)
  380. {
  381.  
  382. account.setAccountName(checkNull(request.getParameter("nonCICAccountName")));
  383. account.setCountry(checkNull(request.getParameter("country")));
  384. account.setCountryNumber(Integer.parseInt(request.getParameter("countryNumber")));
  385. account.setLocationName(checkNull(request.getParameter("locationName")));
  386. account.setLocationNumber(checkNull(request.getParameter("locationNumber")));
  387. account.setDepartmentName(checkNull(request.getParameter("departmentName")));
  388. account.setDepartmentNumber(checkNull(request.getParameter("departmentNumber")));
  389. account.setDivision(checkNull(request.getParameter("division")));
  390. account.setMajor(Integer.parseInt(request.getParameter("major")));
  391. account.setMinor(Integer.parseInt(request.getParameter("minor")));
  392. account.setSubminor(Integer.parseInt(request.getParameter("subminor")));
  393. account.setLeru(checkNull(request.getParameter("leru")));
  394. account.setTask(Integer.parseInt(request.getParameter("task")));
  395. account.setApprovingManager(checkNull(request.getParameter("approvingManager")));
  396. account.setFinancialApprover(checkNull(request.getParameter("financialApprover")));
  397.  
  398. return account;
  399. }
  400.  
  401. public int createNonCICAccount(NonCICAccount account) throws SQLException {
  402. int result = 0;
  403. try {
  404.  
  405. // dbConnection.prepareStatement(SQL_INSERT,Statement.RETURN_GENERATED_KEYS);
  406. pStmt = dbConnection.prepareStatement(SQL_INSERT);
  407.  
  408. pStmt.setString(1, account.getAccountName());
  409. pStmt.setString(2, account.getCountry());
  410. pStmt.setInt(3, account.getCountryNumber());
  411. pStmt.setString(4, account.getLocationName());
  412. pStmt.setString(5, account.getLocationNumber());
  413. pStmt.setString(6, account.getDepartmentName());
  414. pStmt.setString(7, account.getDepartmentNumber());
  415. pStmt.setString(8, account.getDivision());
  416. pStmt.setInt(9, account.getMajor());
  417. pStmt.setInt(10, account.getMinor());
  418. pStmt.setInt(11, account.getSubminor());
  419. pStmt.setString(12, account.getLeru());
  420. pStmt.setInt(13, account.getTask());
  421. pStmt.setString(14, account.getApprovingManager());
  422. pStmt.setString(15, account.getFinancialApprover());
  423.  
  424. result = pStmt.executeUpdate();
  425.  
  426. /*
  427. * rs = pstmt.getGeneratedKeys(); if(rs != null && rs.next()){
  428. * System.out.println("Generated Emp Id: "+rs.getInt(1)); }
  429. */
  430. } catch (Exception e) {
  431. System.err.println(e.getMessage());
  432. throw new SQLException(e);
  433. } finally {
  434. try {
  435.  
  436. if (pStmt != null)
  437. pStmt.close();
  438.  
  439. } catch (Exception ex) {
  440. }
  441. }
  442. return result;
  443. }
Add Comment
Please, Sign In to add comment