时间:2021-07-01 10:21:17 帮助过:3人阅读
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.Append("@{\"");
jsonBuilder.Append("MyData");
jsonBuilder.Append("\":[");
int k = bh.Split(',').Length + 1;
for (int i = 0; i < bh.Split(',').Length; i++)
{
tem += "update KH_PFX set DF = '"+EncriptLib.EncriptLib.EncodeCode(Convert.ToDouble(df.Split(',')[i].ToString().Trim()))+"',";
tem += "BZ = '"+bz.Split(',')[i].ToString().Trim()+"',PFRXM = '"+Session["XM"].ToString()+"',";
tem += "PFRBH = '"+Session["YHBH"].ToString()+"',PFRQ = to_date('"+DateTime.Now.ToShortDateString()+"','yyyy-MM-dd')";
tem += " where BH = '"+bh.Split(',')[i].ToString().Trim()+"'";
tem += "卐"; //此处用此特殊的符号来分隔sql语句
jsonBuilder.Append("{\"bh\":" + "\"" + bh.Split(',')[i].ToString().Trim() + "\"" + ",");
jsonBuilder.Append("\"lx\":" + "\"" + lx.Split(',')[i].ToString().Trim() + "\"" + ",");
jsonBuilder.Append("\"df\":" + "\"" + df.Split(',')[i].ToString().Trim() + "\"" + ",");
jsonBuilder.Append("\"bz\":" + "\"" + bz.Split(',')[i].ToString().Trim() + "\"" + "},");
}
if(tem != "")
{
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]");
jsonBuilder.Append("}");
Page.ClientScript.RegisterClientScriptBlock(GetType(), "cg", "<Script>window.close();opener.GetZXDF('zxdf" + Request.QueryString["bh"].ToString() + "','" + parent_df.Text.Trim() + "','" + jsonBuilder.ToString() + "',\"" + tem + "\");</Script>");
}
"@"符号可以防止在jsonBuilder.ToString()后,转义字符“\”的消失。
调用父窗体的GetZXDF()方法,将json数据传递给父窗体。
下面给出子窗体加载时,绑定json数据的代码
代码如下:
$(function() {
//加载时获取json,然后绑定打分结果
var obj = opener.GetJson($("#txt_YCBH").val());
if($.trim(obj) != ""){
obj = "(" + obj + ")";
obj = eval(obj);
var data = obj.MyData;
$.each(data, function(i, n) {
if(n.lx == "1"){
//直接打分类的绑定
$("#lx" + n.bh).siblings("input").eq(0).val(n.df);
$("#lx" + n.bh).siblings("input").eq(1).val(n.df);
$("#lx" + n.bh).parent().parent().next().children().children("textarea").val(n.bz);
}
if(n.lx == "2"){
//选项打分类的绑定
$("#lx" + n.bh).siblings("input:text").eq(1).val(n.df);
$("#lx" + n.bh).siblings("input:checkbox").each(function(){
if($.trim($(this).val()) == $.trim(n.df)){
$(this).attr("checked",true);
}
});
$("#lx" + n.bh).parent().parent().parent().next().children().children("textarea").val(n.bz);
}
});
opener.GetJson()方法是父窗体上用来向子窗体传递json数据的方法,代码如下:
代码如下:
//通过编号获取对应评分项的子项打分结果的json字符串
function GetJson(p_bh)
{
//$("#zxdf" + p_bh).siblings("input").eq(1).val()中保存的就是子窗体传递给父窗体的json数据
return $("#zxdf" + p_bh).siblings("input").eq(1).val();
}