双击dhtmlgrid行,父窗口弹出层,并将该行的数据传递到弹出层的页面。
其他导入grid之类的文件略,此处导入
<script type="text/javascript" src="js/window.js"></script>
<script type="text/javascript" src="js/jquery-1.6.1.js"></script>
<script src="js/jquery.blockUI.js" type="text/javascript"></script>
js文件
function onRowDblClicked(){
var str = mygrid.getSelectedRowId(); // 取得rowid
var flag='0';
parent.window.openMyWin(window,"诊间叫号设置",595,230,"aa/show_clc_callnumset.htm?str="+str+"&flag="+flag);//?deptcode="+deptcode+"&text_mac="+text_ma
}
function openMyWin(win,title,width,height,url)
{
mywin = win;
openWin(title,width,height,url);
}
function adjustDisp(){//高度自适应,取相应的数据
var avalibleHeight = $(window).height()-250;
if(avalibleHeight>260){
pageSize = Math.floor((avalibleHeight-27)/26);
$("#grid_newApply").css("height",avalibleHeight);
}
}
function doClose(){
//关闭弹层 $.unblockUI()
$.unblockUI();
}
后台action代码:
@RequestMapping("/show_clc_callnumset")
public String show_clc_callnumset(HttpServletRequest request,ModelMap model,HttpServletResponse response)throws Exception{
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String sql = null;
String flag=request.getParameter("flag"); //flag 0时修改,1时新增
String view = null;
List<Map> list = null;
if("0".equals(flag)){ //修改
String str=request.getParameter("str");
System.out.println(str);
DBOperator db = new DBOperator();
try {
String localip = request.getParameter("localip");
sql = "select * from CLC_CALLNUMSET where hosnum=? and nodecode=? and localip=?";
list = db.find(sql, new Object[] { str.split(",")[0],str.split(",")[1],str.split(",")[2]});
request.setAttribute("localip", list.get(0).get("localip").toString());
request.setAttribute("localmac", list.get(0).get("localmac").toString());
request.setAttribute("deptcode", list.get(0).get("deptcode").toString());
request.setAttribute("deptname", list.get(0).get("deptname").toString());
request.setAttribute("clc_roomnum", list.get(0).get("clc_roomnum").toString());
request.setAttribute("localname", list.get(0).get("localname").toString());
request.setAttribute("isclcscreenpc", list.get(0).get("isclcscreenpc").toString());
} catch (RuntimeException e) {
e.printStackTrace();
db.rollback();
} finally {
db.freeCon();
}
}
request.setAttribute("flag", flag);
return "updatezhenjian";
}
@RequestMapping(value = "/getcountzhenjian", method = RequestMethod.POST)
public void getCount(HttpServletRequest request,HttpServletResponse response,String status) throws IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
List<Map> list = null;
DBOperator db = null;
PrintWriter pw = response.getWriter();
int count = 0;
String localip= request.getParameter("ip");
String deptname = request.getParameter("combodept");
try {
db = new DBOperator();
String sql="select count(*) as count from CLC_CALLNUMSET";
if(deptname!=null &&!"".equals(deptname)){
sql+=" where deptname='"+deptname+"'";
System.out.println(deptname);
}
if(localip!=null &&!"".equals(localip)){
sql+=" and localip='"+localip+"'";
}
list = db.find(sql);
db.commit();
count=Integer.valueOf(String.valueOf(list.get(0).get("count")));
pw.print(count);
}catch(Exception e){
e.printStackTrace();
pw.print("fail");
}finally{
db.freeCon();
}
pw.flush();
pw.close();
}
@RequestMapping(value = "/loadtzhenjian", method = RequestMethod.POST)
public void loadGrid(HttpServletRequest request,HttpServletResponse response,String status) throws IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
int Pagesize = Integer.parseInt(request.getParameter("size"));
int index = Integer.parseInt(request.getParameter("index"));
String deptname = request.getParameter("combodept");
System.out.println(deptname);
String localip = request.getParameter("ip");
String pagingSql1 = "select OHYEAH.* from (select OHNO.*,rownum no from ("; // 用于分页// 段1
String pagingSql2 = ") OHNO where rownum <= ?) OHYEAH where no > ?"; // 用于分页段2
String sql = "select hosnum,nodecode,deptname,deptcode,localip,localmac,clc_roomnum,localname,isclcscreenpc from CLC_CALLNUMSET ";
if(deptname!=null &&!"".equals(deptname)){
// deptname=new String(insheetno.getBytes("iso-8859-1"), "utf-8");
sql+=" where deptname='"+deptname+"'";
}
if(localip!=null &&!"".equals(localip)){
// intype=new String(intype.getBytes("iso-8859-1"), "utf-8");
sql+=" and localip='"+localip+"'";
}
DBOperator db = null;
try {
db = new DBOperator();
List list = db.find(pagingSql1+sql+pagingSql2,new Object[]{Pagesize*index+Pagesize,Pagesize*index});
response.setContentType("text/html;charset=utf-8"); //前台拼凑用text/html
// response.setContentType("text/xml;charset=utf-8"); //用vm模版的话用text/xml
PrintWriter pw = null;
pw = response.getWriter();
//String vmpagckage = "com/cpinfo/learn/template/";
//String vmname = "hello.vm";
//String vm = VelocityUtils.generateGridVm(vmpagckage, vmname,"MW_hello", list);
JSONArray json = JSONArray.fromObject(list);
System.out.println(json.toString());
pw.print(json.toString());
// pw.print(vm);
pw.flush();
pw.close();
db.commit();
}catch(Exception e){
e.printStackTrace();
}finally{
db.freeCon();
}
}
@RequestMapping("/updatezhenjian")
public void updatezhenjian(HttpServletRequest request,ModelMap model,HttpServletResponse response)throws Exception{
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String hosnum="1005";
String nodecode="1005";
String localip = request.getParameter("text_ip");
System.out.println(localip);
String localmac = request.getParameter("text_mac");
String deptname = request.getParameter("deptname");
String clc_roomnum = request.getParameter("deptno");
String localname = request.getParameter("pcname");
String isclcscreenpc = request.getParameter("radion_pc");
String deptcode = request.getParameter("deptcode");
String view = null;
List<Map> list = null;
DBOperator db = new DBOperator();
try {
String sql="update CLC_CALLNUMSET set localmac=?,deptname=?,clc_roomnum=?,localname=?,isclcscreenpc=?,deptcode=? where hosnum=? and nodecode=? and localip=?";
db.excute(sql, new Object[] {localmac,deptname,clc_roomnum,localname,isclcscreenpc,deptcode,hosnum,nodecode,localip});
db.commit();
} catch (RuntimeException e) {
e.printStackTrace();
db.rollback();
} finally {
db.freeCon();
}
}
<script>
var combo_deptname;
var text_ip;
var text_mac;
var deptname;
var deptno;
var pcname;
var radion_pc;
$(document).ready(function(){
//alert("${hosname}") ;
combo_deptname = new dhtmlXCombo("combo_zone1", "alfa1", 132);
combo_deptname.enableFilteringMode(true);
combo1();
if("${flag}"=="0"){
$("#pcIp").val("${localip}"); // 将接收(值栈)的localip取出赋给id为pcIp的文本框
$("#pcIp").attr("style","background-color: #EAEAEA");
$("#pcIp").attr("readonly",true);
$("#pcMac").val("${localmac}");
combo_deptname.setComboValue("${deptcode}");
combo_deptname.setComboText("${deptname}");
// $("#deptname").val("${deptcode}");
$("#deptno").val("${clc_roomnum}");
$("#pcname").val("${localname}");
$("#deptname").val(combo_deptname.getComboText());
$("#deptcode").val(combo_deptname.getActualValue());
// $("#radio_pc").val("${isclcscreenpc}");
// alert("${isclcscreenpc}");
if("${isclcscreenpc}"=="Y"){
$("#radio_pc1").attr('checked',true);
}else{
$("#radio_pc2").attr('checked',true);
}
$("#li1").text("修改");
}
});
function doClose(){
parent.doClose();
}
function combo1(){
$.ajax({
type:"post",
url: "sick3/sbzl.htm",
cache: false,
error:function(){
//alert("没有该病人记录!");
},
success: function(data){
if(data=="fail"){
alert("错误");
}else{
var json = eval("{" + data + "}");
//alert(json);
for(var i=0;i<json.length;i++){
combo_deptname.addOption(json[i].deptcode,json[i].deptname);
}
}
}
});
}
function dozlUpdate(){
text_ip=$('#pcIp').val();
alert(text_ip);
text_mac=$('#pcMac').val();
deptname=combo_deptname.getComboText();
deptno=$('#deptno').val();
pcname=$('#pcname').val();
deptcode=combo_deptname.getActualValue();
// alert(deptcode);
radion_pc=$("input[name='radio_pc']:checked").val();
// var _value = $("input[@type=radio][name=item][checked]").val();
alert(text_ip);
if(text_ip==''||text_ip==null){
text_ip='';
}
if(text_mac==''||text_mac==null){
text_mac='';
}
if(deptname==''||deptname==null){
deptname='';
}
if(deptno==''||deptno==null){
deptno='';
}
if(pcname==''||pcname==null){
pcname='';
}
if(radion_pc==''||radion_pc==null){
radion_pc='';
}
if(deptcode==''||deptcode==null){
deptcode='';
}
$.ajax({
async:false,
cache:false,
type:"post",
url:"aa/updatezhenjian.htm",
data:"text_ip="+text_ip+"&text_mac="+text_mac+"&deptname="+deptname+"&deptno="+deptno+"&pcname="+pcname+"&radion_pc="+radion_pc+"&deptcode="+deptcode,
error:function(){
alert("服务器内部错误!");
},
success:function(data){
if(data=='fail'){
alert("获取数据失败!");
}else{
//alert(data);
// createPagination_no(data);
}
}
});
}
</script>