刷新夫窗体用的JS

/// </summary>
public class JS
{
    public JS()
    {

    }

    /// <summary>
    /// 刷新父窗口

    /// </summary>
    public static void refreshParent(string strIndex)
    {
        
        HttpContext.Current.Response.Write("<script language=javascript>var str=window.opener.location.href; var ch=str.indexOf(\"?\"); if(ch>=0){var i=str.indexOf(\"?index\");if(i<0){i=str.indexOf(\"&index\")} if (i>=0){i=i+1;var strTmp = str.substr(i);var itemp = strTmp.indexOf(\"&\");if(itemp>0){strTmp=strTmp.substr(itemp);}str=str.replace(strTmp, \"\");}else{str+=\"&\";}}else{str+=\"?\";}str += \"index=" + strIndex + "\"; opener.document.location=str;</script>");
    }

    #region 验证COOKIE信息是否可用
    /// <summary>
    /// 判断程序所使用的相关信息是否有效

    /// </summary>
    /// <returns></returns>
    public static bool isCookiesAvailabile()
    {
        if ((null == HttpContext.Current.Request.Cookies["askCRM"])
            || (null == HttpContext.Current.Request.Cookies["askCRM"]["USERID"])
            || (null == HttpContext.Current.Request.Cookies["askCRM"]["DEPARTMENTID"])
            || (null == HttpContext.Current.Request.Cookies["askCRM"]["LEVELID"])
            || (null == HttpContext.Current.Request.Cookies["askCRM"]["ANALYSEPOWER"]))
        {
            Alert("权限验证失败(信息失效),请重新登录。");
            return false;
        }
        return true;
    }
    #endregion 验证COOKIE信息是否可用

    #region 从COOKIE读取当前用户的相当配置信息

    #region 得到当前用户的登录名
    /// <summary>
    /// 得到当前用户的登录名
    /// </summary>
    /// <returns>当前用户的登录名</returns>
    public static String getUserID()
    {
        if (isCookiesAvailabile())
        {
            string strUid = HttpContext.Current.Request.Cookies["askCRM"]["USERID"];

            if (string.IsNullOrEmpty(strUid))
            {
                JS.Alert("验证权限失败,请重新登录。");
                return null;
            }

            return Tools.Decrypt(strUid, Tools.myKey);
        }
        else
        {
            return null;
        }
    }
    #endregion 得到当前用户的登录名

    #region 得到当前用户的权限分配类型ID
    /// <summary>
    /// 得到当前用户的权限分配类型ID
    /// </summary>
    /// <returns>当前用户的权限分配类型ID</returns>
    public static String getUserLevel()
    {
        if (isCookiesAvailabile())
        {
            string strLevel = HttpContext.Current.Request.Cookies["askCRM"]["LEVELID"];

            if (string.IsNullOrEmpty(strLevel))
            {
                JS.Alert("验证权限失败,请重新登录。");
                return null;
            }

            return Tools.Decrypt(strLevel, Tools.myKey);
        }
        else
        {
            return null;
        }
    }
    #endregion 得到当前用户的权限分配类型ID

    #region 得到当前用户所在部门的
    /// <summary>
    /// 得到当前用户所在部门的ID
    /// </summary>
    /// <returns>部门ID</returns>
    public static String getUserDepartMent()
    {
        if (isCookiesAvailabile())
        {
            string strDepartmentID = HttpContext.Current.Request.Cookies["askCRM"]["DEPARTMENTID"];

            if (string.IsNullOrEmpty(strDepartmentID))
            {
                JS.Alert("验证权限失败,请重新登录。");
                return null;
            }

            return Tools.Decrypt(strDepartmentID, Tools.myKey);
        }
        else
        {
            return null;
        }
    }
    #endregion 得到当前用户所在部门的

    #region 获取当前用户分析时是否可以用全局数据
    /// <summary>
    /// 获取当前用户分析时是否可以用全局数据
    /// </summary>
    /// <returns>是否可以使用全局数据</returns>
    public static bool getUserPurview()
    {
        if (isCookiesAvailabile())
        {
            bool bRestrict;//是否准许分析所有数据

            if (!Boolean.TryParse(Tools.Decrypt(HttpContext.Current.Request.Cookies["askCRM"]["ANALYSEPOWER"], Tools.myKey), out bRestrict))
            {
                JS.Alert("验证权限失败,请重新登录。");
                return false;
            }

            return bRestrict;
        }
        else
        {
            return false;
        }
    }
    #endregion 获取当前用户分析时是否可以用全局数据
    #endregion 从COOKIE读取当前用户的相当配置信息

}

子窗体
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChanceList.aspx.cs" Inherits="BaseOperation_ChanceList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>添加明细</title>
<link href="../css/CRM.css" type="text/css" rel="stylesheet" />
<script language="javascript" type="text/javascript">
<!--

function IMG1_onclick() {
window.opener=null;
window.close();
}

// -->
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table cellpadding="0" cellspacing="0" width="100%">
            <tbody>
                <%--<table style="width: 823px; height: 284px">--%>
                <tr>
                    <td colspan="3" style="font-weight: bold; font-size: 20px; color: white; font-family: 楷体_GB2312;
                        height: 27px; background-color: #63769b">
                        <asp:Label ID="sTitle" Width="100%" runat="server" Text="添加明细"></asp:Label>
                        </td>
                </tr>
                <tr>
                    <td style="width: 149px; height: 26px">
                    </td>
                    <td style="width: 129px; height: 26px">
                    </td>
                    <td style="width: 385px; height: 26px">
                    </td>
                </tr>
                <tr>
                    <td style="width: 149px; height: 20px">
                    </td>
                    <td style="width: 129px; height: 20px">
                        产品类别:</td>
                    <td style="width: 385px; height: 20px"><asp:DropDownList ID="listProductType" runat="server" Width="160px" DataTextField="PRODUCTTYPENAME" DataValueField="PRODUCTTYPEID" AutoPostBack="True" OnSelectedIndexChanged="listProductType_SelectedIndexChanged">
                    </asp:DropDownList></td>
                </tr>
                <tr>
                    <td style="width: 149px; height: 30px">
                    </td>
                    <td style="width: 129px; color: #000000; height: 30px">
                        <font color="red">产品名称:</font></td>
                    <td style="width: 385px; height: 30px">
                        <asp:DropDownList ID="listProductName" runat="server" Width="160px" DataTextField="PRODUCTNAME" DataValueField="PRODUCTID">
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td style="width: 149px; height: 30px;">
                    </td>
                    <td style="width: 129px; height: 30px;">
                        数量:</td>
                    <td style="width: 385px; height: 30px;">
                        <asp:TextBox ID="txtBoxNumber" runat="server" Height="20px" Width="155px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 149px; height: 25px">
                    </td>
                    <td style="width: 129px; height: 25px">
                        总金额(元):</td>
                    <td style="width: 385px; height: 25px">
                        <asp:TextBox ID="txtBoxMoneysum" runat="server" Height="20px" Width="155px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 149px; height: 40px">
                    </td>
                    <td style="width: 129px; height: 40px;">
                        折扣:</td>
                    <td style="width: 385px; height: 40px;">
                        <asp:TextBox ID="txtBoxAgio" runat="server" Height="20px" Width="155px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 149px; height: 40px">
                    </td>
                    <td style="width: 129px; height: 40px" align="right">
                        <asp:ImageButton ID="imgBtnOK" runat="server" ImageUrl="~/Images/button/button01.gif"
                            OnClick="imgBtnOK_Click" /></td>
                    <td align="left" style="width: 385px; height: 40px">
                        &nbsp; &nbsp; &nbsp;&nbsp;
                        <img id="IMG1" src="../Images/button/btClose.gif" language="javascript" onclick="return IMG1_onclick()" /></td>
                </tr>
            </tbody>
        </table>
    </div>
    </form>
</body>
</html>

    子窗体。CS
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 调用当前页面有两个参数需要传递:
/// [Chanceid],标识(ID),必须传递。

/// [id],明细标识(ID),只在查看修改明细时必须传递。

/// </summary>
public partial class BaseOperation_ChanceList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (JS.isCookiesAvailabile())
            {
                //添加明细,必须要有ID
                if ((null == Request.QueryString["Chanceid"])
                    || (string.IsNullOrEmpty(Request.QueryString["Chanceid"].Trim())))
                {
                    return;
                }

                initProductTypeList();
                this.initProductList(this.listProductType.SelectedValue);

                if ((Request.QueryString["id"] != null)
                    && (!string.IsNullOrEmpty(Request.QueryString["id"].Trim())))
                {
                    initChanceList(Request.QueryString["id"].Trim());
                    this.sTitle.Text = this.Title = "查看/修改明细信息";
                }
            }
        }
    }

    protected void imgBtnOK_Click(object sender, ImageClickEventArgs e)
    {
        if (!JS.isCookiesAvailabile())
        {
            return;
        }

        if ((string.IsNullOrEmpty(Request.Cookies["askCRM"]["USERID"].Trim())))
        {
            JS.Alert("信息失效,请重新登录。");
            return;
        }
        if (string.IsNullOrEmpty(this.listProductName.Text.Trim()))
        {
            JS.Alert("请选择产品名称");
            return;
        }

        int iTmp;
        if ((!string.IsNullOrEmpty(this.txtBoxNumber.Text.Trim()))
            && (!Int32.TryParse(this.txtBoxNumber.Text.Trim(), out iTmp)))
        {
            JS.Alert("数量必须为数字,请重新输入。");
            return;
        }

        double dbTmp;
        if ((!string.IsNullOrEmpty(this.txtBoxMoneysum.Text.Trim())) &&
            (!Double.TryParse(this.txtBoxMoneysum.Text.Trim(), out dbTmp)))
        {
            JS.Alert("总金额必须为数字,请重新输入。");
            return;
        }

        if ((Request.QueryString["id"] != null)
            && (!string.IsNullOrEmpty(Request.QueryString["id"].Trim())))
        {
            modifyChanceListInfo(Request.QueryString["id"].Trim());
        }
        else
        {
            newChanceListInfo(Tools.Decrypt(Request.Cookies["askCRM"]["USERID"].Trim(), Tools.myKey));
        }

        //Response.Write("<script>opener.document.location=opener.document.location;</script>");
        if ((Request.QueryString["backindex"] != null) && (Request.QueryString["backindex"].Trim() != ""))
        {
            JS.refreshParent(Request.QueryString["backindex"].Trim());
        }
    }

    #region 清除所有界面文本内容

    private void clearAllText()
    {
        this.txtBoxAgio.Text = "";
        this.txtBoxMoneysum.Text = "";
        this.txtBoxNumber.Text = "";
        if (this.listProductType.Items.Count > 0)
        {
            this.listProductType.SelectedIndex = 0;
            this.initProductList(this.listProductType.SelectedValue);
        }
    }
    #endregion

    #region 初始化下拉框内容
    /// <summary>
    /// 初始化产品类型下拉框
    /// </summary>
    ///
    private void initProductTypeList()
    {
        if ((null == DbHelperSQL.dtMemoryData)
            || (!DbHelperSQL.dtMemoryData.Columns[0].Caption.Equals("PRODUCTTYPEID")))
        {
            try
            {
                DbHelperSQL.dtMemoryData = DbHelperSQL.gettable("SELECT PRODUCTTYPEID, PRODUCTTYPENAME FROM DICT_PRODUCTTYPE WHERE PRODUCTTYPEID>0;");
            }
            catch (Exception ex)
            {
                JS.Alert("初始化产品类别信息失败。详细信息:" + ex.Message.Replace("\r\n", "").Replace("'", ""));
            }
        }

        this.listProductType.DataSource = DbHelperSQL.dtMemoryData;
        this.listProductType.DataBind();
    }

    /// <summary>
    /// 初始化产品列表

    /// </summary>
    private void initProductList(string strProductTypeId)
    {
        if (string.IsNullOrEmpty(strProductTypeId))
        {
            return;
        }

        DataTable tmpData = null;
        try
        {
            tmpData = DbHelperSQL.gettable("SELECT PRODUCTID, PRODUCTNAME FROM PRODUCTS WHERE PRODUCTTYPEID=" + strProductTypeId);
        }
        catch (Exception ex)
        {
            JS.Alert("初始化产品类别信息失败。详细信息:" + ex.Message.Replace("\r\n", "").Replace("'", ""));
        }

        this.listProductName.DataSource = tmpData;
        this.listProductName.DataBind();
    }
    #endregion 初始化下拉框内容

    private void initChanceList(string strCid)
    {
        if (!DbHelperSQL.IsSafe(strCid))
        {
            JS.Alert(string.Format("参数{{0}}包含不合法字符。", strCid.Replace("\r\n", "\n").Replace("'", "")));
            return;
        }

        string strSql = "SELECT CHANCELIST.PRODUCTID, CHANCELIST.AMOUNT, CHANCELIST.AGIO, CHANCELIST.MONEYSUM, PRODUCTS.PRODUCTTYPEID FROM CHANCELIST LEFT OUTER JOIN PRODUCTS ON CHANCELIST.PRODUCTID = PRODUCTS.PRODUCTID WHERE CHANCEDETAILID={0}";

        try
        {
            using (DataTable dt = DbHelperSQL.gettable(string.Format(strSql, strCid)))
            {
                if ((dt != null) && (dt.Rows.Count > 0))
                {
                    this.txtBoxAgio.Text = dt.Rows[0]["AGIO"].ToString();
                    this.txtBoxMoneysum.Text = dt.Rows[0]["MONEYSUM"].ToString();
                    this.txtBoxNumber.Text = dt.Rows[0]["AMOUNT"].ToString();
                    //this.listProductType.SelectedValue = dt.Rows[0]["PRODUCTTYPEID"].ToString();
                    //this.listProductName.SelectedValue = dt.Rows[0]["PRODUCTID"].ToString();
                    initProductList(this.listProductType.SelectedValue = dt.Rows[0]["PRODUCTTYPEID"].ToString());
                }
                else
                {
                    JS.Alert(string.Format("未能读取到明细{{0}}的相关信息。", strCid));
                   
                }
            }
        }
        catch (Exception ex)
        {
            JS.Alert("初始化数据失败。详细信息:" + ex.Message.Replace("\r\n", "").Replace("'", ""));
        }
    }

    #region 添加新的明细
    private void newChanceListInfo(string strUid)
    {
        if ((null == Request.QueryString["type"])
            || ("" == Request.QueryString["type"].Trim()))
        {
            JS.Alert("缺少类型字段。");
            return;
        }

        string strSql = "INSERT INTO CHANCELIST (CHANCEID, PRODUCTID, AMOUNT, AGIO, MONEYSUM, OPERATOR, BCHANCE) VALUES ('{0}',{1},'{2}','{3}','{4}','{5}','{6}')";

        try
        {
            int count = DbHelperSQL.ExecuteSql(string.Format(strSql
                , Request.QueryString["Chanceid"].Trim()
                , string.IsNullOrEmpty(this.listProductName.Text.Trim()) ? "0" : this.listProductName.SelectedValue
                , this.txtBoxNumber.Text.Trim()
                , this.txtBoxAgio.Text.Trim()
                , this.txtBoxMoneysum.Text.Trim()
                , strUid
                , Request.QueryString["type"].Trim()));

            if (count > 0)
            {
                JS.Alert("明细信息保存成功。");
                clearAllText();
            }
            else
            {
                JS.Alert("明细信息保存失败。请稍候再试。");
            }
        }
        catch (Exception ex)
        {
            JS.Alert("添加新明细信息失败。详细信息:" + ex.Message.Replace("\r\n", "").Replace("'", ""));
            return;
        }
    }
    #endregion 添加新的明细

    #region 修改已存在明细的信息
    private void modifyChanceListInfo(string strCid)
    {
        string strSql = "UPDATE CHANCELIST SET PRODUCTID='{0}', AMOUNT='{1}', AGIO='{2}', MONEYSUM='{3}' WHERE CHANCEDETAILID={4}";

        try
        {
            int count = DbHelperSQL.ExecuteSql(string.Format(strSql
                , string.IsNullOrEmpty(this.listProductName.Text.Trim()) ? "0" : this.listProductName.SelectedValue
                , this.txtBoxNumber.Text.Trim()
                , this.txtBoxAgio.Text.Trim()
                , this.txtBoxMoneysum.Text.Trim()
                , strCid));

            if (count > 0)
            {
                JS.Alert("明细信息保存成功。");
            }
            else
            {
                JS.Alert("明细信息保存失败。请稍候再试。");
            }
        }
        catch (Exception ex)
        {
            JS.Alert("修改明细信息失败。详细信息:" + ex.Message.Replace("\r\n", "").Replace("'", ""));
            return;
        }
    }
    #endregion 修改已存在明细的信息
    protected void listProductType_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.initProductList(this.listProductType.SelectedValue);
    }
}
帮定用的数据库连接对象

 /// <summary>
 /// Copyright (C) 2004-2008 
 /// 数据访问基础类(基于SQLServer)
 /// 用户可以修改满足自己项目的需要。
 /// </summary>
 public abstract class DbHelperSQL
 {
  //数据库连接字符串(web.config来配置)
  //<add key="ConnectionString" value="server=127.0.0.1;database=DATABASE;uid=sa;pwd=" />  
  public static string connectionString = Tools.Decrypt(ConfigurationSettings.AppSettings["ConnectionString"], Tools.myKey);
        public static DataTable dtMemoryData = null;

  public DbHelperSQL()
  {   
  }

  #region  执行简单SQL语句

  

        public static DataTable gettable(string sql)
        {

            try
            {
                SqlConnection connection = new SqlConnection(connectionString);

                connection.Open();
                SqlDataAdapter sa = new SqlDataAdapter(sql, connection);

                DataSet ds = new DataSet();
                sa.SelectCommand.CommandTimeout = 600;
                sa.Fill(ds);

                connection.Close();

                return ds.Tables[0]; }
            catch (System.Data.SqlClient.SqlException E)
            {
             
                throw new Exception(E.Message);
            }

          }

 }