<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<%
/**
floodseason=1:前汛期
floodseason=2:主汛期
floodseason=3:后汛期
*/
String cPath = request.getContextPath();
String floodseason = request.getParameter("floodseason");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>典型入库洪水过程</title>
<%@ include file="/includes/header.jsp"%>
<script type="text/javascript" src="<%=cPath%>/extjs/RowEditor.js"></script>
<link rel="stylesheet" type="text/css" href="<%=cPath%>/styles/RowEditor.css" />
<script>
var num = null;
var nmId = "";
var strForGrid = "";
//window.clipboardData.setData("Text",strForGrid);
var form = null;
var grid = null;
var uploadform = null;
var hiddenfield1 = null;
Ext.onReady(function(){
Ext.QuickTips.init();
hiddenfield1 = new Ext.form.Hidden({
name: 'uploadfilepath',
allowBlank: false
});
var User = Ext.data.Record.create([
{name: 'tm', type: 'string'},
{name: 'flow', type: 'double'}
]);
var editor = new Ext.ux.grid.RowEditor({
saveText : "保存",
cancelText: "关闭"
});
editor.on({
scope: this,
afteredit: function(roweditor, changes, record, rowIndex) {
if(state == 'add'){
Ext.Ajax.request({
url : '${ctx}/baseinfo.do?method=saveFlood_Data&flow='+record.get('flow')+'&tm='+record.get('tm')+'&doAction=insert&floodseason=<%=floodseason%>&name_id='+nmId,
success: function() {
ds.baseParams = {
name_id : nmId
};
ds.load({params:{start:0,limit:30}});
grid.getStore().reload();
changeChart();
parent.window.Ext.example.msg('消息提示','添加成功');
}
});
}else{
Ext.Ajax.request({
url : '${ctx}/baseinfo.do?method=saveFlood_Data&rec_no='+record.get('rec_no')+'&flow='+record.get('flow')+'&tm='+record.get('tm')+'&doAction=update&floodseason=<%=floodseason%>&name_id='+nmId,
success: function() {
ds.baseParams = {
name_id : nmId
};
ds.load({params:{start:0,limit:30}});
grid.getStore().reload();
changeChart();
parent.window.Ext.example.msg('消息提示','修改成功');
}
});
}
},
canceledit: function(roweditor, changes, record, rowIndex) {
if(state == 'add'){
grid.store.remove(ds.getAt(0)) ;
grid.getView().refresh();
}
editor.stopEditing();
}
});
var store1 = new Ext.data.JsonStore({
url: '${ctx}/baseinfo.do?method=getFlood_Typical_NumList&floodseason=<%=floodseason%>',
root:'root',
fields: ['name_id','name']
});
store1.on('load', function(){
ds.baseParams = {
name_id : nmId
};
ds.load({params:{start:0,limit:30}});
grid.getStore().reload();
});
store1.load();
var comboBox1 = new Ext.form.ComboBox({
id:'selId',
name:'selId',
store:store1,
fieldLabel:'典型洪水编号',
emptyText:"请选择..",
mode:'local',
typeAhead: true,
triggerAction: 'all',
valueField:'name_id',
displayField:'name',
selectOnFocus:true,
border:true,
frame:true,
editable:true,
allowBlank: false,
hiddenName:'name_id',
listeners:{
select:function(combo,record,index){
num = index;
nmId = combo.getValue();
changeChart();
ds.baseParams = {
name_id : nmId
};
ds.load({params:{start:0,limit:30}});
grid.getStore().reload();
}
}
});
//上传文件表单
uploadform = new Ext.form.FormPanel({
fileUpload : true,
border:false,
height:22,
items:[{
id : 'file',
autoScroll : false,
xtype : 'textfield',
fieldLabel:'导入TXT文件',
name : 'file',
hideLabel : true,
autoCreate : {
tag : "input",
type : "file",
size : "20",
autocomplete : "off",
onChange : "chkFileExtname(this.value);"
}
},
hiddenfield1
]
});
//表单
form = new Ext.form.FormPanel({
region:'north',
frame:true,
height:80,
border:false,
buttonAlign:'center',
items:[
comboBox1
],
buttons: [{
text: '添加典型',
handler: function() {
if (!form.getForm().isValid()) {
return;
}
form.getForm().submit({
url : '${ctx}/baseinfo.do?method=saveFlood_Typical_Num&floodseason=<%=floodseason%>',
success : function(form, action){
if (action.result.success) {
parent.window.Ext.Msg.alert('系统提示', action.result.showMsg, function() {
comboBox1.setValue('');
store1.reload();
nmId = '';
changeChart();
//nmId = form.getForm().findField("selId").getValue();
});
}
},
failure : function(form, action) {
parent.window.Ext.Msg.alert('系统提示', "添加失败");
}
});
}
},{
text: '删除典型',
handler: function() {
if (!form.getForm().isValid()) {
return;
}
parent.window.Ext.Msg.confirm('系统提示','您确定要删除吗?',function(btn){
if(btn == 'yes'){
form.getForm().submit({
url : '${ctx}/baseinfo.do?method=delFlood_Typical_Num&floodseason=<%=floodseason%>',
success : function(form, action){
if (action.result.success) {
parent.window.Ext.Msg.alert('系统提示', action.result.showMsg, function() {
//store1.remove(store1.getAt(num));
comboBox1.setValue('');
store1.reload();
nmId = '';
changeChart();
});
}
},
failure : function(form, action) {
parent.window.Ext.Msg.alert('系统提示', "删除失败");
}
});
}
});
}
}]
});
var cm = new Ext.grid.ColumnModel([
{
name: 'rec_no',
hidden : true
},
{
header : '时间',
dataIndex: 'tm',
editor : new Ext.form.TextField({
name: 'tm',
editable:false,
allowBlank: false
//decimalPrecision:3
})
},
{
header : '流量(m<sup>3</sup>/s)',
dataIndex: 'flow',
editor : new Ext.form.NumberField({
name: 'flow',
editable:false,
allowBlank: false
//decimalPrecision:3
})
}
]);
ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'${ctx}/baseinfo.do?method=getData_Flood_List&floodseason=<%=floodseason%>'}),
baseParams : {
name_id : nmId
},
reader: new Ext.data.JsonReader({
totalProperty: 'totalProperty',
root: 'root',
successProperty :'success'
}, [
{name: 'rec_no',mapping:'rec_no',type:'string',hidden:true},
{name: 'tm',mapping:'tm',type:'string'},
{name: 'flow',mapping:'flow',type:'double'}
])
});
//数据表
grid = new Ext.grid.GridPanel({
plugins: [editor],
title:'数据列表',
region:'center',
border:false,
loadMask: {msg:'正在载入数据,请稍候...'},
//sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
ds: ds,
cm: cm,
tbar: new Ext.Toolbar([
'-',
{
text:'添加',
icon: '${ctx}/images/add.gif',
handler: function() {
if(nmId != ''){
editor.stopEditing();
var newUser = new User({});
grid.store.insert(0, newUser);
grid.getView().refresh();
grid.getSelectionModel().selectRow(0);
editor.startEditing(0);
state = 'add';
}else{
parent.window.Ext.Msg.alert('系统提示', "请您先选择典型洪水编号!");
}
}
},
'-',
{
text:'粘贴',
icon: '${ctx}/images/excel.png',
tooltip:'从Excel中粘贴数据',
handler:function(){
if(nmId != ''){
//粘贴板数据
var opData = window.clipboardData.getData("text");
if(opData != null && opData != ''){
pasteData(opData);
if(strForGrid != ''){
Ext.Ajax.request({
url: '${ctx}/baseinfo.do?method=pasteFlood_Data&floodseason=<%=floodseason%>&name_id='+nmId+'&strForGrid='+strForGrid,
success: function(response, options) {
var responseArray = Ext.util.JSON.decode(response.responseText);
if(responseArray.success==true){
ds.baseParams = {
name_id : nmId
};
ds.load({params:{start:0,limit:30}});
grid.getStore().reload();
changeChart();
parent.window.Ext.example.msg('消息提示',responseArray.showMsg);
}else{
parent.window.Ext.Msg.alert('错误提示',responseArray.showMsg);
}
},
failure: function() {
parent.window.Ext.Msg.alert('系统提示', "系统错误,粘帖失败!");
}
});
}
}else{
parent.window.Ext.Msg.alert('系统提示','请您先复制数据!');
return;
}
}else{
parent.window.Ext.Msg.alert('系统提示', "请您先选择典型洪水编号!");
}
}
},
'-',
{
text:'删除',
icon: '${ctx}/images/delete.gif',
tooltip:'先选中被删除记录行,再删除数据',
//disabled: true,
handler:function(){
if(grid.getSelectionModel().getCount()>0){
parent.window.Ext.Msg.confirm('系统提示','您确定要删除吗?',function(btn){
if(btn == 'yes'){
editor.stopEditing();
var cellcount = grid.getSelectionModel().getCount()
var s = grid.getSelectionModel().getSelections();
rec_no = "";
for(var i = 0, r; r = s[i]; i++){
ds.remove(r);
if(i==0){
rec_no += "'"+r.get('rec_no')+"'";
}else{
rec_no += ",'"+r.get('rec_no')+"'";
}
}
if(rec_no != ''){
Ext.Ajax.request({
url: '${ctx}/baseinfo.do?method=delFlood_Data&floodseason=<%=floodseason%>&rec_no='+rec_no ,
success: function(response, options) {
var responseArray = Ext.util.JSON.decode(response.responseText);
if(responseArray.success==true){
ds.baseParams = {
name_id : nmId
};
ds.load({params:{start:0,limit:30}});
grid.getStore().reload();
changeChart();
parent.window.Ext.example.msg('消息提示','删除成功');
}else{
parent.window.Ext.Msg.alert('错误提示',responseArray.showMsg);
}
},
failure: function() {
parent.window.Ext.Msg.alert('系统提示', "系统错误,删除失败!");
}
});
}
}
});
}else{
parent.window.Ext.Msg.alert('系统提示','请您先选中一条记录再进行删除操作!');
return;
}
}
},
'-'
]),
bbar: new Ext.PagingToolbar({
pageSize: 30,
store: ds,
displayInfo: true,
displayMsg: '{0}-{1} / 共{2}条',
emptyMsg: "没有记录"
}),
viewConfig:{
forceFit:true
},
listeners : {
'render' : function() {
var tbar = new Ext.Toolbar({
items : ['-',uploadform,{
text:'导入',
icon: '${ctx}/images/edit.gif',
tooltip:'导入TXT文本文件',
handler:function(){
if(nmId == ''){
parent.window.Ext.Msg.alert('系统提示','请您先选择典型洪水编号!');
return;
}
//针对IE8的安全限制的特殊处理
Ext.getDom('file').select();
uploadform.getForm().findField("uploadfilepath").setValue(document.selection.createRange().text);
var filePath = uploadform.getForm().findField("uploadfilepath").getValue();
if (filePath=='') {
parent.window.Ext.Msg.alert('系统提示','请您选择要导入的TXT文件!');
return;
}
var sExp = filePath.substring(filePath.lastIndexOf('.'),filePath.length);
if(sExp.toUpperCase()!='.TXT'){
parent.window.Ext.Msg.alert('系统提示','只可以导入TXT文件!');
return;
}
uploadform.getForm().submit({
url : "${ctx}/baseinfo.do?method=importData&name_id="+nmId+"&floodseason=<%=floodseason%>",
method : "POST",
success : function(form, action) {
var responseArray = action.result;
if(responseArray.success==true){
ds.baseParams = {
name_id : nmId
};
ds.load({params:{start:0,limit:30}});
grid.getStore().reload();
changeChart();
parent.window.Ext.Msg.alert('提示',responseArray.showMsg);
}else{
parent.window.Ext.Msg.alert('错误提示',responseArray.showMsg);
}
},
failure : function(form, action) {
parent.window.Ext.Msg.alert('系统提示', "系统错误,导入失败!");
}
});
}
}]
});
tbar.render(grid.tbar);
}
}
});
var myurl = My_encode("${ctx}/baseinfo.do?method=getData_Flood_List&floodseason=<%=floodseason%>&name_id="+nmId+"&rnd="+Math.random());
var panel1 = new Ext.Panel({
region:'center',
border:false,
html:'<iframe src="${ctx}/pages/baseinfo/flex/flexlinkchar.html?url='+myurl+'&rndnum='+Math.random()+'" name="iframe_leftxx" id="iframe_leftxx" frameborder="0" scrolling="no" width="100%" height="100%"></iframe>',
title:'过程线图表'
});
var viewport = new Ext.Viewport({
layout:"border",
items:[
panel1,{
region:"west",
width:400,
split:true,
layout:"fit",
border:false,
collapsed: false,
collapseMode:"mini",
items:[{
layout:"border",
border:false,
items:[grid,form]
}]
}]
});
});
function doQuery_pro(pselId){
ds.baseParams = {
name_id : pselId
};
ds.load({params:{start:0,limit:30}});
grid.getStore().reload();
}
function pasteData(opData){
var opLineBreak = new RegExp("//r//n", "g");
var opTab = new RegExp("//t", "g");
var opRows = opData.split(opLineBreak);
for (var i = 0; i < opRows.length; i ++){
var opCells = opRows[i].split(opTab);
if(strForGrid == ''){
strForGrid += opCells;
}else{
strForGrid += "_" + opCells;
}
}
}
function chkFileExtname(pFilepath){
hiddenfield1.setValue(pFilepath);
pFilepath = pFilepath.toUpperCase();
var sExp = pFilepath.substring(pFilepath.lastIndexOf('.'),pFilepath.length);
if(sExp!='.TXT'){
parent.window.Ext.Msg.alert('系统提示','只可以导入TXT文件!');
hiddenfield1.setValue('');
}
}
function changeChart(){
var url = My_encode("${ctx}/baseinfo.do?method=getData_Flood_List&floodseason=<%=floodseason%>&name_id="+nmId+"&rnd="+Math.random());
document.getElementById("iframe_leftxx").src = "${ctx}/pages/baseinfo/flex/flexlinkchar.html?url="+url+"&rndnum="+Math.random();
}
function My_encode(url){
return encodeURIComponent(url);
}
//粘帖数据
function pasteData1(opData){
var opLineBreak = new RegExp("//r//n", "g");
var opTab = new RegExp("//t", "g");
var opRows = opData.split(opLineBreak);
for (var i = 0; i < opRows.length; i ++){
var opCells = opRows[i].split(opTab);
if(isNaN(opCells[0]) || isNaN(opCells[1]) || isNaN(opCells[2]) || isNaN(opCells[3]) || isNaN(opCells[4])){
strForGrid = "";
Ext.example.msg('消息提示','粘帖的数据非数值');
break;
}
if(strForGrid == ''){
strForGrid += opCells;
}else{
strForGrid += "_" + opCells;
}
}
}
function usFormat(v){
v = String(v);
if(v=='0'){
v = "";
}
return v;
}
function fsFormat(v){
v = String(v);
var ps = v.split('.');
var whole = ps[0] ? ps[0] : '0';
var sub = ps[1] ? '.'+ ps[1] : '';
v = whole + sub;
return v;
}
</script>
</head>
<body>
</body>
</html>