记得在某个论坛上看了谋篇大侠的文章,他说自己写的代码在稀烂,也要学会精心维护,总有一天你写的代码会给你带来很大收益的,我加一句哈,总有一天我写的代码会越来越健壮的。
Ext.ns('El.Base');
El.Base.RowGridEdit = Ext.extend(N21.Base.GridEdit, {
dataRecordMeta:Ext.data.Record.create([
{name:"recId",type:"int"}
,{name:"itemId",type:"string"}
,{name:"inputQty",type:"double"}
,{name:"inputUnit",type:"double"}
,{name:"pickListNum",type:"string"}
,{name:"pickListTableRecId",type:"int"}
,{name:"frmBatchId",type:"string"}
,{name:"toBatchId",type:"string"}
,{name:"refId",type:"string"}
,{name:"exFactoryNo",type:"string"}
,{name:"frmProjId",type:"string"}
,{name:"frmSKU",type:"string"}
,{name:"toProjId",type:"string"}
,{name:"toSKU",type:"string"}
,{name:"barcodeUniqueId",type:"string"}
,{name:"frmWarehouse",type:"string"}
,{name:"frmLocation",type:"string"}
,{name:"toWarehouse",type:"string"}
,{name:"toLocation",type:"string"}
,{name:"inputWeight",type:"double"}
,{name:"levelQty",type:"double"}
,{name:"remarks",type:"string"}
,{name:"containerType",type:"string"}
,{name:"containerQty",type:"int"}
,{name:"mouldId",type:"string"}
,{name:"mouldRefNum",type:"string"}
,{name:"mouldVersion",type:"string"} //int or nvarchar?
// ,{name:"domainId",type:"string"}
,{name:"dataareaId",type:"string"}
])
,columns: new Ext.util.MixedCollection()
,clicksToEdit:2 //單機兩下進入編輯狀態
,recordPk:["recId"] //記錄主鍵PK
,initComponent:function() {
// this.columns.add("RecId", {header:"Selected",width:40,dataIndex:"selected",editor:new Ext.FormPanel.ComboBox({id:'statusCmb',hiddenName:'',store:yy,displayField:'value',valueField:'code',editable:false,mode:'local',triggerAction:'all'})});// 设置下拉框
this.columns.add("RefId",{header:"單號",width:100,dataIndex:'refId',allowBlank: false,hidden:false,sortable:true,align:"center",
editor:new Ext.form.NumberField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("ExFactoryNo",{header:"出廠單號",width:100,dataIndex:'exFactoryNo',hidden:false,sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("ItemId",{header:"物料編號",width:100,dataIndex:'itemId',hidden:false,sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("InputQty",{header:"總數量",width:100,dataIndex:'inputQty',hidden:false,sortable:true,align:"center",
editor:new Ext.form.NumberField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("InputUnit",{header:"單位",width:100,dataIndex:'inputUnit',hidden:false,sortable:true,align:"center",
editor:new Ext.form.NumberField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("InputWeight",{header:"總重量",width:100,dataIndex:'inputWeight',sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("LevelQty",{header:"對準書",width:150,dataIndex:'levelQty',sortable:true,align:"center",
editor:new Ext.form.NumberField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("ContainerType",{header:"箱類型",width:100,dataIndex:'containerType',sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("ContainerQty",{header:"箱數量",width:100,dataIndex:'containerQty',sortable:true,align:"center",
editor:new Ext.form.NumberField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("MouldId",{header:"洋行模號",width:100,dataIndex:'mouldId',sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("MouldRefNum",{header:"模廠模號",width:100,dataIndex:'mouldRefNum',sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("MouldVersion",{header:"模版本",width:100,dataIndex:'mouldVersion',sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("FrmWarehouse",{header:"由倉庫",width:100,dataIndex:'frmWarehouse', sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("FrmLocation",{header:"由位置",width:100,dataIndex:'frmLocation', sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("ToWarehouse",{header:"至倉庫",width:100,dataIndex:'toWarehouse',sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("ToLocation",{header:"至位置",width:150,dataIndex:'toLocation',sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("FrmProjId",{header:"由項目",width:100,dataIndex:'frmProjId',hidden:false,sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("FrmSKU",{header:"由SKU",width:100,dataIndex:'frmSKU',sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("FrmBatchId",{header:"由批號",width:100,dataIndex:'frmBatchId',hidden:false,sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("ToProjId",{header:"至項目",width:100,dataIndex:'toProjId', hidden:false,sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("ToSKU",{header:"至SKU",width:100,dataIndex:'toSKU',hidden:false,sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("ToBatchId",{header:"至批號",width:100,dataIndex:'toBatchId',hidden:false,sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
this.columns.add("PickListNum",{header:"領料預算表",width:100,dataIndex:'pickListNum',hidden:false,sortable:true,align:"center"});
this.columns.add("Remarks",{header:"備註",width:100,dataIndex:'remarks',sortable:true,align:"center",
editor:new Ext.form.TextField({selectOnFocus:true,allowBlank: false,cls:"x-form-text-in-grid"}) });
// this.columns.add("CreateTime",{header:"CreateTime",width:150,dataIndex:'created_time',xtype:'datecolumn',sortable:true,align:"center",format:'Y-m-d H:i:s'}); //日期格式 format and dataIndex
var sm=new Ext.grid.CheckboxSelectionModel({ singleSelect:false /*,checkOnly:true*/ })//設置可全選
Ext.apply(this, {
store: new Ext.data.Store({
id:"storeMP_item_mas_h"
,reader:new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'id',
root: 'records',
messageProperty: 'message'
}, this.dataRecordMeta)
,fields:this.dataRecordMeta
,url:"BarCode/showEL_PickListLine.action"
,method:'GET'
,remoteSort :false
,pruneModifiedRecords:true
,params:this.getSelectedRowPK()
//,firstFocusFieldName:"MO_ID"
})
,columns:[
new Ext.grid.RowNumberer(),sm,
this.columns.get("RefId"),this.columns.get("ExFactoryNo"),this.columns.get("ItemId"),this.columns.get("InputQty"),this.columns.get("InputUnit"),this.columns.get("InputWeight")
,this.columns.get("LevelQty"),this.columns.get("ContainerType"),this.columns.get("ContainerQty"),this.columns.get("MouldId"),this.columns.get("MouldRefNum"),this.columns.get("MouldVersion"),this.columns.get("FrmWarehouse")
,this.columns.get("FrmLocation"),this.columns.get("ToWarehouse"),this.columns.get("ToLocation"),this.columns.get("FrmProjId"),this.columns.get("FrmSKU"),this.columns.get("FrmBatchId")
,this.columns.get("ToProjId"),this.columns.get("ToSKU"),this.columns.get("ToBatchId"),this.columns.get("PickListNum"),this.columns.get("Remarks")
]
,selModel:sm
,reloadRecord:function(){
this.executeQuery();
}
/*
,bbar : new Array(
{id:"tlb_btn_rec_qry",xtype: "button",cls:"x-btn-icon", icon:"/_static/icon/g_rec_src.png", tooltip:"Filter <Ctrl+F>",handler: this.enter_query,scope :this }
,{id:"tlb_btn_rec_cmt",xtype: "button",cls:"x-btn-icon", icon:"/_static/icon/g_rec_commit.png", tooltip:"Save changes <Ctrl+S>",handler: this.commitForm,scope :this }
,{id:"tlb_btn_rec_new",xtype: "button",cls:"x-btn-icon", icon:"/_static/icon/g_rec_new.png", tooltip:"Create new <Ctrl+N>",handler: this.createNewRecord,scope :this }
,'-'
,{id:"tlb_btn_rec_del",xtype: "button",cls:"x-btn-icon", icon:"/_static/icon/g_rec_del.png", tooltip:"Delete <Ctrl+D>",handler: this.deleteRecord,scope :this }
,'-'
,{id:"tlb_btn_rec_mp_plan",xtype: "button",cls:"x-btn-icon", icon:"/_static/icon/print.png", tooltip:"Master Plan ",handler: this.export_data,scope :this }
,{id:"tlb_btn_rec_mp_publish",xtype: "button",cls:"x-btn-icon", icon:"/_static/icon/print.png", tooltip:"Print",handler: this.export_data,scope :this }
)
,queryFields: [
{xtype:'textfield',name:'query_pk',id:'IM_ModelNumber1',width:120,fieldLabel:'Model Number',allowBlank:false}
,{xtype:'IMStatusCombo',name:'query_status',id:'IM_Status1',fieldLabel:'Status',allowBlank:false}
]
,dataComponentName:"ItemMasterListGrid1"
,frame:true
,queryArraySize:-1
*/
});
El.Base.RowGridEdit.superclass.initComponent.apply(this, arguments);
}
,getSelectedRowPK: function(){
var selRecords=this.getSelectionModel().getSelections();
var itemMasterPks=this.recordPk;//獲得紀錄的主鍵
var modelNumber="";
var delParams=new Object();
if(itemMasterPks.length==1){
var singPk=itemMasterPks[0];
for(var i=0;i<selRecords.length;i++){
modelNumber+=selRecords[i].data[singPk]+",";
}
modelNumber=modelNumber.substring(0,modelNumber.length-1);
delParams[singPk]=modelNumber;
}
return delParams;
}
,deleteRecord: function() {
var selCount=this.getSelectionModel().getCount();//獲得選擇的紀錄數
if (selCount==0) {
Ext.Msg.show({
title:'溫馨提示'
,msg: '請選擇要刪除的信息.'
,buttons: Ext.Msg.OK
,fn: this.executeDelete
,scope:this
,icon: Ext.MessageBox.WARNING
});
} else {
Ext.Msg.show({
title:'溫馨提示'
,msg: '確定刪除該記錄嗎?'
,buttons: Ext.Msg.YESNO
,fn: this.executeDelete
,scope:this
,icon: Ext.MessageBox.QUESTION
});
}
}
,executeDelete: function(btn) {
if (btn=='yes') {
this.stopEditing( );
Ext.MessageBox.wait("正在刪除中 ...");
Ext.Ajax.request({
url:"BarCode/deleteByRecId.action"
,success:this.afterExecuteDeleteSuccess
,failure:this.afterExecuteDeleteFailure
,timeout:10000
,scope:this
,params:this.getSelectedRowPK()
});
}
}
,afterExecuteDeleteSuccess: function(response,options) {
Ext.MessageBox.hide();
var resp = Ext.decode(response.responseText);
if (resp.success) {
var selRecords=this.getSelectionModel().getSelections();
this.getStore().remove(selRecords);
Ext.Msg.show({title:'溫馨提示',msg:'刪除成功 !',buttons:Ext.Msg.OK,fn:Ext.emptyFn,scope:this,icon:'control-successful-icon'});
}else {
if (resp.message) {
Ext.Msg.show({title:'Error',msg:this.urldecode(resp.message),buttons:Ext.Msg.OK,fn:Ext.emptyFn,scope:this,icon:'control-failed-icon'});
} else {
Ext.Msg.show({title:'Error',msg:'操作失敗,請與系統管理員聯繫.',buttons:Ext.Msg.OK,fn:Ext.emptyFn,scope:this,icon:'control-failed-icon'});
}
}
}
,onRender:function(){
El.Base.RowGridEdit.superclass.onRender.apply(this, arguments);
}
,updateColumnFn:function(){
//Ext.Msg.alert('提示信息','暫未提供處理更新欄位Action');
location.href = 'setvdoing.jsp';
}
/*
,afterCellEdit:function(e){
//console.log("測試函數!====編輯領料單行");
this.stopEditing(); //停止編輯
this.serverMessages = new Array();
var x = this.store.getModifiedRecords(); //获取修改后的记录数 (返回一個對象object)
//console.log("編輯記錄數--:"+x.length);
if (x.length>0){
//Ext.MessageBox.wait("Saving your data pleate wait...");
Ext.MessageBox.alert("舒婷","你修改了記錄");
}
for (var i=0;i<x.length;i++){
var lo = x[i];
var ld = new Object();
//如何獲取修改了的內容--
Ext.Ajax.request({
params:this.getSelectedRowPK()
,method:"POST"
,callback:this.afterCellEditEvent
,scope: this
,timeout:10000
,url:"BarCode/updateByRecId.action"
});
}
}
*/
,beforeCellEdit:Ext.emptyFn
});
Ext.reg("rowGridEdit",El.Base.RowGridEdit);
var row_grid_edit=new El.Base.RowGridEdit({title:'領料單行',id:'rowgridedit',height:200});
//row_grid_edit.executeQuery(); //經歷了千辛萬苦 終於自動顯示在頁面中了 嗚嗚嗚嗚嗚嗚嗚
领料单行 后台
package com.barcode.Web;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.barcode.Model.EL_PickListLine;
import com.barcode.Model.EL_PickListTable;
import com.barcode.Service.EL_PickListLineService;
import com.barcode.Service.EL_PickListTableService;
@Controller
public class EL_PickListLineController {
private EL_PickListTableService el_PickListTableService;
@Autowired
public void setEL_PickListTableService(EL_PickListTableService el_PickListTableService){
this.el_PickListTableService=el_PickListTableService;
}
private EL_PickListLineService el_PickListLineService;
@Autowired
public void setEl_PickListLineService(
EL_PickListLineService el_PickListLineService) {
this.el_PickListLineService = el_PickListLineService;
}
//@RequestMapping(value="BarCode/selectEL_PLL.action")
public List<EL_PickListLine> getAllInfo(int a){
return this.el_PickListLineService.getAllInfo(a);
}
@RequestMapping(value="BarCode/selectByRecId.action")
public void selectByRecId(){
EL_PickListLine elp=this.el_PickListLineService.selectByRecId(2);
// elp.printInfo();
System.out.println("獲取RecId為2滴信息"+elp.getBarcodeUniqueId());
}
/* 函數deleteByRecId
* 刪除所選的一條或多條記錄
* ?--枚舉類型的對象轉換 string數組--轉換成int類型的變量
* */
@SuppressWarnings("unchecked")
@RequestMapping(value="BarCode/deleteByRecId.action")
public @ResponseBody Map<String,Object>deleteByRecId(HttpServletRequest request){
Enumeration enu=request.getParameterNames();
while(enu.hasMoreElements()){
String rn=(String)enu.nextElement();
System.out.println("paramName["+rn+"]="+request.getParameter(rn));
String[] spk= (request.getParameter(rn).split(","));
for(int i=0;i<spk.length;i++){
int ipk=Integer.parseInt(spk[i]);
EL_PickListLine elp=this.el_PickListLineService.returnInfo(ipk);
this.el_PickListLineService.deleteInfo(elp);
}
}
Map<String,Object>map=new HashMap<String,Object>();
map.put("success",true);
map.put("message","成功刪除記錄!");
return map;
}
/* 函数 updateInfo
* 作用 将前台修改数据与后台数据绑定
* return
* */
@SuppressWarnings("unchecked")
@RequestMapping(value="BarCode/updateByRecId.action")
public @ResponseBody Map<String,Object>updateInfo(HttpServletRequest request){
Enumeration enu=request.getParameterNames();
Map<String,Object>map=new HashMap<String,Object>();
EL_PickListLine elp = null;
while(enu.hasMoreElements()){
String params=enu.nextElement().toString();
System.out.println("params:["+ params +"]"+request.getParameter(params));
if(params.equals("recId")){
String recId=request.getParameter(params);
int RecId =Integer.parseInt(recId);
elp=this.el_PickListLineService.returnInfo(RecId);//根据RecId找到对应的实体类
elp.setMouldVersion(request.getParameter("mouldVersion"));
elp.setLevelQty(Double.parseDouble(request.getParameter("levelQty")));
elp.setRemarks(request.getParameter("remarks"));
elp.setInputQty(Double.parseDouble(request.getParameter("inputQty")));
elp.setContainerType(request.getParameter("containerType"));
//elp.setPickListNum(request.getParameter("pickListNum")); 領料預算表是不能被修改的
elp.setContainerQty(Integer.parseInt(request.getParameter("containerQty")));
elp.setFrmProjId(request.getParameter("frmProjId"));
elp.setMouldId(request.getParameter("mouldId"));
elp.setToLocation(request.getParameter("toLocation"));
elp.setInputWeight(Double.parseDouble(request.getParameter("inputWeight")));
elp.setItemId(request.getParameter("itemId"));
elp.setRefId(request.getParameter("refId"));
elp.setExFactoryNo(request.getParameter("exFactoryNo"));
elp.setToProjId(request.getParameter("toProjId"));
elp.setFrmBatchId(request.getParameter("frmBatchId"));
elp.setMouldRefNum(request.getParameter("mouldRefNum"));
elp.setFrmWarehouse(request.getParameter("frmWarehouse"));
elp.setFrmSKU(request.getParameter("frmSKU"));
elp.setFrmLocation(request.getParameter("frmLocation"));
elp.setToSKU(request.getParameter("toSKU"));
elp.setToWarehouse(request.getParameter("toWarehouse"));
elp.setToBatchId(request.getParameter("toBatchId"));
elp.setInputUnit(Double.parseDouble(request.getParameter("inputUnit")));
}
}
this.el_PickListLineService.updateInfo(elp);//保存所修改的数据
if(enu.hasMoreElements()){
map.put("success",true);
map.put("message","成功保存修改记录!");
return map;
}else{
map.put("success", false);
map.put("message","修改失败,请重新操作");
return map;
}
}
/* 函數 insertInfo
* 接受條碼槍輸入的條碼,並將其解析,插入數據庫中
* 領料單行條碼-- !@1201@140@00MA228989@01MA228989@04MA228989@05MA228989@08401-01A0518-220@09752451@102000.000@11PPL10/010204!";
* 領料單頭條碼-- !@1200@1409@06SG@071A@11PPL01/010204!
* */
@SuppressWarnings("unchecked")
@RequestMapping(value="BarCode/insertEL_PLL.action")
public @ResponseBody Map<String,Object> insertInfo(HttpServletRequest request){
Enumeration enu=request.getParameterNames();
Map<String,Object>map=new HashMap<String,Object>();
while(enu.hasMoreElements()){
String rn=(String)enu.nextElement();
System.out.println("paramName["+rn+"]="+request.getParameter(rn));
String barcode=rn;
System.out.println("tes------------------------:"+barcode);
String fieldcode=null;
String fieldvalue= null;
String code[]=barcode.split("@");
@SuppressWarnings("unused")
boolean tag =false;
EL_PickListLine elp=new EL_PickListLine();
EL_PickListTable elpt=new EL_PickListTable();
//存儲處理后的條碼字符信息
List list = new ArrayList();
List listbody = new ArrayList();
System.out.println("test:-----------------------www-"+code.length);
System.out.println("test:-----------------------www-"+code[0]);
if(code.length==1){ //判斷條碼是否為空值,為空則提示重新輸入
map.put("success",false);
map.put("message","條碼錯誤!請重新掃描條碼!");
}else{
String s =code[1].substring(2);//提取單頭or單行標示
Integer a=(Integer.parseInt(s));//將其轉換為int類型用於判斷條碼類型
for(int i=2;i<code.length;i++){
if(i<code.length-1){
fieldvalue =code[i].substring(2);
}else{
fieldvalue=code[i].substring(2,code[i].length()-1);
}
fieldcode =code[i].substring(0,2);
//將條碼中的信息添加到list中存儲
list.add(fieldcode);
listbody.add(fieldvalue);
}
// if(tag=true){
// //提取条码中的表编号与数据库中的相比较看是否存在
// //如果存在同一用戶,多個相同的表號碼 设置tag标示为true
// // 前台判断tag是否为true,进而选择是否插入数据库
// }else{
if(a==01){
elp.setBarcodeUniqueId((String)listbody.get(1));
elp.setFrmProjId((String)listbody.get(2));
elp.setFrmSKU((String)listbody.get(3));
elp.setToProjId((String)listbody.get(4));
elp.setItemId((String)listbody.get(5));
elp.setPickListTableRecId(2); //外鍵不能為空,--手動設置外鍵5
elp.setInputUnit((Double.parseDouble((String)listbody.get(6))));//String類型的數據轉換成Double類型的數據時出錯!
System.out.println("----------------------------"+listbody.get(6));
elp.setInputQty((Double.parseDouble((String)listbody.get(7))));
elp.setPickListNum((String)listbody.get(8));
System.out.println("從條碼中解析信息以完成!");
this.el_PickListLineService.insertInfo(elp);
map.put("success",true);
map.put("message","成功添加記錄--單行!");
System.out.println("成功將條碼中的信息插入數據庫中!");
}else if(a==00){
System.out.println("======================================test a :"+a);
elpt.setBarcodeUniqueId((String)listbody.get(0));
elpt.setToWarehouse((String)listbody.get(1));
elpt.setToLocation((String)listbody.get(2));
elpt.setPickListNum((String)listbody.get(3));
this.el_PickListTableService.insertInfo(elpt);
map.put("success",true);
map.put("message","成功添加記錄----單頭!");
}else{
System.out.println("條碼錯誤!");
map.put("success",false);
map.put("message","條碼錯誤!請重新掃描條碼!");
}
}
}
return map;
}
// }
}