079eafc131ce7526dd8cf8c49193076f663c937f.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. package xin.glue.ui.B;
  2. import java.util.List;
  3. import java.util.Map;
  4. import javax.servlet.http.HttpServletRequest;
  5. import jxl.Cell;
  6. import jxl.CellType;
  7. import jxl.Sheet;
  8. import jxl.Workbook;
  9. import jxl.write.Label;
  10. import jxl.write.WritableSheet;
  11. import jxl.write.WritableWorkbook;
  12. import jxl.write.WriteException;
  13. import jxl.write.biff.RowsExceededException;
  14. import xin.glue.ui.common.blob.PosExcelEngine;
  15. /**
  16. *
  17. * @Description 板加质保书生成
  18. * @author 梅贵平{meiguiping}
  19. * @date 2010-1-19 下午07:02:27
  20. * @JDK Version jdk1.4.2
  21. */
  22. public class BjCertBookBuilder extends PosExcelEngine
  23. {
  24. private int TotalCols = 44;//原始38更改为44
  25. // private int TheCols = 43;//原始37改为43
  26. private String pageCoilNo = null;
  27. protected void setData(Workbook rwb, WritableWorkbook wb) throws RowsExceededException, WriteException {
  28. Sheet rs = rwb.getSheet(0);
  29. setData(wb, rs);
  30. }
  31. private void setData(WritableWorkbook wb, Sheet rs) throws WriteException, RowsExceededException {
  32. this.addRows = 0;
  33. if (pageCount > 0)
  34. wb.importSheet("sheet" + (pageCount + 1), pageCount, rs);
  35. WritableSheet sheet = wb.getSheet(pageCount++);
  36. sheet.removeRow(12);
  37. sheet.removeRow(8);
  38. setHeader(rs, sheet);
  39. setSize(rs, sheet);
  40. setSample(rs, sheet);
  41. if (dataList.size() > 3) {
  42. if (((List)dataList.get(1)).size() > 0 || ((List)dataList.get(3)).size() > 0)
  43. setData(wb, rs);
  44. }
  45. }
  46. private void setHeader(Sheet rs, WritableSheet sheet) throws WriteException, RowsExceededException {
  47. if (dataList == null || dataList.size() < 1) return;
  48. List list = (List)dataList.get(0);
  49. if (list.size() > 0) {
  50. Map row = (Map)list.get(0);
  51. Cell cell;
  52. Label label;
  53. String fieldName;
  54. for (int curCol = 2; curCol < TotalCols; curCol++) {
  55. for (int curRow = 1; curRow < 4; curRow++) {
  56. cell = rs.getCell(curCol, curRow);
  57. if (cell.getType() == CellType.EMPTY) continue;
  58. fieldName = cell.getContents().trim();
  59. if (fieldName.startsWith("[") && fieldName.endsWith("]")) {
  60. fieldName = fieldName.substring(1, fieldName.length() - 1);
  61. if (row.get(fieldName) != null) {
  62. label = (Label)sheet.getWritableCell(curCol, curRow);
  63. label.setString(row.get(fieldName).toString());
  64. }
  65. else//当结果中没有该元素时,将该格子的值置为空
  66. {
  67. label = (Label)sheet.getWritableCell(curCol, curRow);
  68. label.setString("");
  69. }
  70. }
  71. }
  72. }
  73. // 订货单位、收货单位、订单号、产品名称、标准、发行指示编号
  74. // 车号、数量合计、重量合计、证明书编号、签发日期、发货日期
  75. }
  76. }
  77. protected void addBlankRow(WritableSheet sheet, int curRow, Sheet rs, int refRow, int rows) throws WriteException {
  78. if (autoBlank) {
  79. while (rows < pageSize) {
  80. curRow = insertRow(sheet, curRow, rs, refRow);
  81. setValue(sheet, curRow, 0, String.valueOf(++rows)); // NO.
  82. }
  83. }
  84. }
  85. private void setSize(Sheet rs, WritableSheet sheet) throws WriteException, RowsExceededException {
  86. if (dataList == null || dataList.size() < 2) return;//因为Size的查询存储在第二个list中
  87. List list = (List)dataList.get(1);
  88. Cell cell;
  89. int count = 0, curRow = 7;
  90. String coilNo = null;
  91. for (int i = 0; i < list.size(); ) {
  92. Map row = (Map)list.get(i);
  93. if (!row.get("COIL_PAKG_NO").toString().equals(coilNo)) {
  94. if (count > pageSize) break;//行数不允许超过最大容量
  95. coilNo = row.get("COIL_PAKG_NO").toString();
  96. pageCoilNo = coilNo;
  97. curRow = insertRow(sheet, curRow, rs, 8);//-------------------------增加一行-----------------------
  98. //合并单元格
  99. sheet.mergeCells(3, curRow, 6, curRow);//炉号
  100. sheet.mergeCells(7, curRow, 9, curRow); // 牌号
  101. sheet.mergeCells(10, curRow, 10, curRow); // 厚度
  102. sheet.mergeCells(11, curRow, 12, curRow); // 宽度
  103. sheet.mergeCells(13, curRow, 14, curRow); // 长度
  104. sheet.mergeCells(15, curRow, 15, curRow); // 长度
  105. sheet.mergeCells(16, curRow, 16, curRow); // 重量
  106. sheet.mergeCells(43, curRow, 44, curRow); // 车号
  107. //注意,非填值,仅仅是增加了序号(1、2、3、4、5、6、7、8.....)
  108. setValue(sheet, curRow, 0, String.valueOf(++count)); // NO.
  109. }
  110. list.remove(i);
  111. //填值(牌号、炉号、厚度、宽度、长度等)
  112. for (int curCol = 1; curCol < TotalCols; curCol++) {
  113. cell = rs.getCell(curCol, 8);
  114. if (cell.getType() != CellType.EMPTY)//????????????????????????????
  115. setValue(sheet, curRow, curCol, row.get(cell.getContents().trim()));
  116. }
  117. // CHARGE_NO、SMP_NO、COIL_THK、COIL_WTK、COIL_LEN、COIL_WGT、TP
  118. setChem(rs, sheet, coilNo, curRow);
  119. }// for end
  120. //多余的行以空行补齐
  121. addBlankRow(sheet, curRow, rs, 8, count);
  122. for (int i = count, j = 1; i < pageSize; i++, j++) {
  123. sheet.mergeCells(3, curRow+j, 6, curRow+j);//炉号
  124. sheet.mergeCells(7, curRow + j, 9, curRow + j); // 牌号
  125. sheet.mergeCells(10, curRow + j, 10, curRow + j); // 厚度
  126. sheet.mergeCells(11, curRow + j, 12, curRow + j); // 宽度
  127. sheet.mergeCells(13, curRow + j, 14, curRow + j); // 长度
  128. sheet.mergeCells(15, curRow + j, 16, curRow + j); // 重量
  129. sheet.mergeCells(43, curRow + j, 44, curRow + j); // 车号
  130. }
  131. }
  132. //成分
  133. private void setChem(Sheet rs, WritableSheet sheet, String coilNo, int curRow) throws WriteException, RowsExceededException {
  134. if (dataList == null || dataList.size() < 3) return;
  135. List list = (List)dataList.get(2);
  136. Cell cell;
  137. Label label;
  138. int curCol;
  139. boolean canExit = false;
  140. for (int i = 0; i < list.size(); ) {
  141. Map row = (Map)list.get(i);
  142. if (row.get("COIL_PAKG_NO").equals(coilNo)) {
  143. canExit = true;
  144. String chemName = row.get("CHEM_CD").toString();
  145. for (curCol = 18; curCol < TotalCols; curCol++) {//元素存储从18位开始
  146. cell = sheet.getCell(curCol, 5);//第5行
  147. if (cell.getContents().equals(chemName)) break;
  148. if (cell.getType() == CellType.EMPTY) {
  149. cell = rs.getCell(curCol, 5);
  150. //
  151. label = new Label(curCol, 5, chemName, cell.getCellFormat());
  152. sheet.addCell(label);//将定义好的单元格添加到生成的工作表中
  153. break;
  154. }
  155. }
  156. if (curCol < TotalCols) {
  157. label = (Label)sheet.getWritableCell(curCol, curRow);
  158. label.setString(row.get("CHEM_VAL").toString());
  159. }
  160. list.remove(i);
  161. } else {
  162. if (canExit) break;
  163. i++;
  164. }
  165. }
  166. }
  167. // 性能
  168. private void setSample(Sheet rs, WritableSheet sheet) throws WriteException, RowsExceededException {
  169. if (dataList == null || dataList.size() < 4) return;
  170. List list = (List)dataList.get(3);
  171. String coilNo = null, samplePos = null, qltyCD, qltyName;
  172. int curRow = 10 + this.addRows, fixedRow = 9 + this.addRows, curCol = 0;
  173. int count = 0;
  174. Cell cell;
  175. Label label;
  176. boolean canExit = false, rowChange = false;
  177. for (int i = 0; i < list.size(); ) {
  178. Map row = (Map)list.get(i);
  179. if (!row.get("COIL_PAKG_NO").equals(coilNo)) {
  180. if (row.get("COIL_PAKG_NO").equals(pageCoilNo))
  181. canExit = true;
  182. if (canExit && count > pageSize) break;
  183. coilNo = row.get("COIL_PAKG_NO").toString();
  184. curRow = insertRow(sheet, curRow, rs, 12);
  185. setValue(sheet, curRow, 0, String.valueOf(++count)); // NO.
  186. cell = rs.getCell(1, 12); // COIL NO. -> Sample NO.
  187. setValue(sheet, curRow, 1, row.get(cell.getContents().trim()));
  188. rowChange = true;
  189. }
  190. list.remove(i);
  191. if (rowChange || !row.get("SMP_NO").equals(samplePos)) {
  192. rowChange = false;
  193. samplePos = row.get("SMP_NO").toString();
  194. cell = rs.getCell(2, 12); // Sampling Position
  195. setValue(sheet, curRow, 2, row.get(cell.getContents().trim()));
  196. cell = rs.getCell(TotalCols, 12); // 交货状态
  197. setValue(sheet, curRow, TotalCols, row.get(cell.getContents().trim()));
  198. }
  199. qltyCD = row.get("QLTY_CD").toString();
  200. qltyName = row.get("QLTY_CD_CFNM").toString();
  201. if ((qltyCD.equals("YS") || qltyCD.equals("TE") ||
  202. qltyCD.equals("EL") || qltyCD.equals("RA") || qltyCD.equals("YR"))) {
  203. //试样位置、位置方向、温度
  204. for (curCol = 3; curCol < 6; curCol++) {
  205. if(curCol == 3&&qltyCD.equals("TE")) //取抗拉强度的方向做为试验方向
  206. {
  207. cell = rs.getCell(curCol, 12);
  208. String fangXiang = row.get(cell.getContents().trim()).toString();
  209. // if("H".equals(fangXiang))//横向
  210. // {
  211. // fangXiang = "T";
  212. // }
  213. // else if("Z".equals(fangXiang))//纵向
  214. // {
  215. // fangXiang = "L";
  216. // }
  217. setValue(sheet, curRow, curCol, fangXiang);
  218. }
  219. }
  220. //屈服、抗拉、等拉力实验
  221. for (curCol = 6; curCol < 11; curCol++) {
  222. cell = rs.getCell(curCol, 12);
  223. if (qltyCD.equals(cell.getContents().trim())) {
  224. setValue(sheet, curRow, curCol, row.get("QLTY_VAL_WK"));
  225. break;
  226. }
  227. }
  228. if(qltyCD.equals("YS") )
  229. {
  230. cell = sheet.getCell(6, fixedRow+1);
  231. String ss = cell.getContents().toString();
  232. if("ReL".equals(ss))
  233. {
  234. Label ll = (Label)sheet.getWritableCell(6, fixedRow+1);
  235. ll.setString(qltyName.replaceAll("\\[矩形\\]", "").replaceAll("\\[圆形\\]", "").replaceAll("屈服强度", "") );
  236. }
  237. }
  238. else if(qltyCD.equals("EL"))
  239. {
  240. cell = sheet.getCell(8, fixedRow+1);
  241. String ss = cell.getContents().toString();
  242. if("A".equals(ss))
  243. {
  244. Label ll = (Label)sheet.getWritableCell(8, fixedRow+1);
  245. ll.setString(qltyName.replaceAll("\\[矩形\\]", "").replaceAll("\\[圆形\\]", "").replaceAll("伸长率", "") );
  246. }
  247. }
  248. }
  249. else if(qltyName.equals("非金属夹杂物A"))
  250. {
  251. cell = rs.getCell(38 , 12);
  252. setValue(sheet, curRow, 38, row.get("QLTY_VAL_WK"));
  253. }
  254. else if(qltyName.equals("非金属夹杂物B"))
  255. {
  256. cell = rs.getCell(39 , 12);
  257. setValue(sheet, curRow, 39, row.get("QLTY_VAL_WK"));
  258. }
  259. else if(qltyName.equals("非金属夹杂物C"))
  260. {
  261. cell = rs.getCell(40 , 12);
  262. setValue(sheet, curRow, 40, row.get("QLTY_VAL_WK"));
  263. }
  264. else if(qltyName.equals("非金属夹杂物D"))
  265. {
  266. cell = rs.getCell(41 , 12);
  267. setValue(sheet, curRow, 41, row.get("QLTY_VAL_WK"));
  268. }
  269. else if(qltyName.indexOf("夏比冲击剪切面积") != -1 )
  270. {
  271. int xiabiCol = 19;
  272. cell = rs.getCell(xiabiCol, 12);
  273. setValue(sheet, curRow, xiabiCol, row.get(cell.getContents().trim()));
  274. cell = rs.getCell(xiabiCol+3, 12); // AVE
  275. setValue(sheet, curRow, xiabiCol+3, row.get("QLTY_VAL_WK"));
  276. setQlty(rs, sheet, coilNo, qltyCD, curRow);
  277. }
  278. else if(qltyName.equals("晶粒度"))
  279. {
  280. cell = rs.getCell(23 , 12);
  281. setValue(sheet, curRow, 23, row.get("QLTY_VAL_WK"));
  282. }
  283. else if(qltyName.equals("带状组织"))
  284. {
  285. cell = rs.getCell(24 , 12);
  286. setValue(sheet, curRow, 24, row.get("QLTY_VAL_WK"));
  287. }
  288. else if (qltyCD.equals("IM")) {
  289. if("S".equals(row.get("MS_QLTY_DIR")) ||"H".equals(row.get("MS_QLTY_DIR"))||"Z".equals(row.get("MS_QLTY_DIR")))//普通冲击
  290. {
  291. String str;
  292. // for (curCol = 15; curCol < 18; curCol++) {
  293. for (curCol = 12; curCol < 15; curCol++) {
  294. cell = rs.getCell(curCol, 12);
  295. if(row.get(cell.getContents().trim()) != null)
  296. {
  297. str = row.get(cell.getContents().trim()).toString();
  298. }
  299. else
  300. {
  301. str = "";
  302. }
  303. if("H".equals(row.get(cell.getContents().trim())))
  304. {
  305. str = "T";
  306. }
  307. else if("Z".equals(row.get(cell.getContents().trim())))
  308. {
  309. str = "L";
  310. }
  311. setValue(sheet, curRow, curCol, str);
  312. }
  313. cell = rs.getCell(18, 12); // AVE(平均值),列为18列
  314. setValue(sheet, curRow, 18, row.get("QLTY_VAL_WK"));
  315. setQlty(rs, sheet, coilNo, qltyCD, curRow);
  316. }
  317. if("L".equals(row.get("MS_QLTY_DIR"))||"X".equals(row.get("MS_QLTY_DIR")))//时效冲击
  318. {
  319. String str = "";
  320. //时冲的位置、尺寸、温度
  321. for (curCol = 31; curCol < 34; curCol++) {
  322. cell = rs.getCell(curCol, 12);
  323. // str = row.get(cell.getContents().trim())== null ? "":row.get(cell.getContents().trim()).toString();
  324. if(row.get(cell.getContents().trim()) != null)
  325. {
  326. str = row.get(cell.getContents().trim()).toString();
  327. }
  328. else
  329. {
  330. str = "";
  331. }
  332. if("X".equals(row.get(cell.getContents().trim())))
  333. {
  334. str = "L";
  335. }
  336. else if("L".equals(row.get(cell.getContents().trim())))
  337. {
  338. str = "T";
  339. }
  340. setValue(sheet, curRow, curCol, str );
  341. }
  342. cell = rs.getCell(37, 12); // AVE
  343. setValue(sheet, curRow, 37, row.get("QLTY_VAL_WK"));
  344. setQlty(rs, sheet, coilNo, qltyCD, curRow);
  345. //生成时效冲击的名称
  346. label = new Label(34, fixedRow, qltyName, cell.getCellFormat());
  347. label.setString(qltyName);
  348. sheet.addCell(label);
  349. }
  350. }else if (qltyCD.equals("HD")) {
  351. cell = rs.getCell(27, 12);//位置方向
  352. setValue(sheet, curRow, 27, row.get(cell.getContents().trim()));
  353. cell = rs.getCell(30, 12); // AVE
  354. setValue(sheet, curRow, 30, row.get("QLTY_VAL_WK"));
  355. setQlty(rs, sheet, coilNo, qltyCD, curRow);
  356. //生成硬度的名称
  357. label = new Label(27, fixedRow, qltyName, cell.getCellFormat());
  358. label.setString(qltyName);
  359. sheet.addCell(label);
  360. } else if (qltyCD.equals("CB")) {
  361. int colCB = 25;
  362. cell = rs.getCell(colCB, 12); // CB
  363. setValue(sheet, curRow, colCB, row.get("QLTY_VAL_WK"));
  364. setQlty(rs, sheet, coilNo, qltyCD, curRow);
  365. }
  366. //对于其它的检验项目
  367. else {
  368. // qltyName = (String)row.get("QLTY_CD_CFNM");
  369. for (curCol = 42; curCol < TotalCols; curCol++) {
  370. cell = sheet.getCell(curCol, fixedRow);
  371. if (cell.getContents().equals(qltyName)) break;
  372. if (cell.getType() == CellType.EMPTY) {
  373. cell = rs.getCell(curCol, 10);
  374. label = new Label(curCol, fixedRow, qltyName, cell.getCellFormat());
  375. sheet.addCell(label);
  376. break;
  377. }
  378. }
  379. if (curCol < TotalCols)
  380. setValue(sheet, curRow, curCol, row.get("QLTY_VAL_WK"));
  381. }
  382. }
  383. addBlankRow(sheet, curRow, rs, 12, count);
  384. //制表人
  385. list = (List)dataList.get(0);
  386. if (list.size() > 0) {
  387. Map row = (Map)list.get(0);
  388. //注意,不能用rs.getRows(),rs代表的是原始模板
  389. label = new Label(10, sheet.getRows()-1, row.get("USERID").toString());
  390. sheet.addCell(label);
  391. }
  392. //备注
  393. list = (List)dataList.get(0);
  394. if (list.size() > 0) {
  395. Map row = (Map)list.get(0);
  396. //注意,不能用rs.getRows(),rs代表的是原始模板
  397. // Label la = new Label(0,29 , "");
  398. label = new Label(2, 29, row.get("CRET_NO_RMK")==null?"": row.get("CRET_NO_RMK").toString() , PosCertificate.getCommStyle() );
  399. sheet.addCell(label);
  400. }
  401. }
  402. private void setQlty(Sheet rs, WritableSheet sheet, String coilNo, String qltyCD, int curRow) {
  403. if (dataList == null || dataList.size() < 5) return;
  404. List list = (List)dataList.get(4);
  405. String qltySeq;
  406. Cell cell;
  407. int curCol = 0;
  408. boolean canExit = false;
  409. for (int i = 0;i < list.size();i++) {
  410. Map row = (Map)list.get(i);
  411. if (row.get("COIL_PAKG_NO").equals(coilNo)) {
  412. if (row.get("QLTY_CD").equals(qltyCD)) {
  413. qltySeq = (String)row.get("QLTY_SEQ");
  414. // String qltyName = row.get("QLTY_CD_CFNM").toString();
  415. if("IM".equals(qltyCD) && row.get("MS_QLTY_DIR") == null)
  416. {
  417. // for (curCol = 18; curCol < 21; curCol++) {
  418. // cell = rs.getCell(curCol, 12);
  419. // if (cell.getContents().trim().equals(qltySeq)) {
  420. // setValue(sheet, curRow, curCol, row.get("QLTY_VAL_WK"));
  421. // row.put("QLTY_CD", "isUsed");
  422. // break;
  423. // }
  424. // }
  425. }
  426. else if ("IM".equals(qltyCD)) {
  427. if("S".equals(row.get("MS_QLTY_DIR")) ||"H".equals(row.get("MS_QLTY_DIR"))||"Z".equals(row.get("MS_QLTY_DIR")))//普通冲击
  428. {
  429. for (curCol = 15; curCol < 18; curCol++) {
  430. cell = rs.getCell(curCol, 12);
  431. if (cell.getContents().trim().equals(qltySeq)) {
  432. setValue(sheet, curRow, curCol, row.get("QLTY_VAL_WK"));
  433. row.put("QLTY_CD", "isUsed");
  434. break;
  435. }
  436. }
  437. }
  438. if("L".equals(row.get("MS_QLTY_DIR"))||"X".equals(row.get("MS_QLTY_DIR")))//时效冲击
  439. {
  440. for (curCol = 34; curCol < 37; curCol++) {
  441. cell = rs.getCell(curCol, 12);
  442. if (cell.getContents().trim().equals(qltySeq)) {
  443. setValue(sheet, curRow, curCol, row.get("QLTY_VAL_WK"));
  444. row.put("QLTY_CD", "isUsed");
  445. break;
  446. }
  447. }
  448. }
  449. } else if ("HD".equals(qltyCD)) {
  450. for (curCol = 27; curCol < 30; curCol++) {
  451. cell = rs.getCell(curCol, 12);
  452. if (cell.getContents().trim().equals(qltySeq)) {
  453. setValue(sheet, curRow, curCol, row.get("QLTY_VAL_WK"));
  454. row.put("QLTY_CD", "isUsed");
  455. break;
  456. }
  457. }
  458. }
  459. }
  460. }
  461. }
  462. }
  463. }