关闭

VS.2005 子窗体提交数据刷新父窗体 GRIDVIEW 父窗体

标签: stringexceptionnullserveraspassembly
1372人阅读 评论(0) 收藏 举报
分类:

父窗题ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddChance.aspx.cs" Inherits="BaseOperation_AddChance"%>
<%@ Register Assembly="Microsoft.Web.UI.WebControls" Namespace="Microsoft.Web.UI.WebControls"
    TagPrefix="iewc" %>
<%@ Register Assembly="WebPager" Namespace="Hooyee.WebControls" TagPrefix="cc1" %>
<%@ Register Assembly="ZoneSoft.Web.UI" Namespace="ZoneSoft.Web.UI" TagPrefix="ZoneSoft" %>

<html>
<head runat="server">
    <title>添加渠道信息</title>
    <link href="../css/CRM.css" type="text/css" rel="stylesheet" />
    <script language="javascript" src="../css/Calendar.js"></script>
     <script language="javascript">

    function viewCustomer_onclick()
    {
        if ((document.all["listCompany"].value != '') && (document.all["listCompany"].value != '0'))
        {
            window.open('AddCustomer.aspx?id=' + document.all["listCompany"].value ,'','height=550,width=700,top=100,left=100,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=yes');
        }
    }

    function viewContact_onclick()
    {
        if ((document.all["listContact"].value != '') && (document.all["listContact"].value != '0'))
        {
            window.open('AddContact.aspx?id=' + document.all["listContact"].value ,'','height=500,width=700,top=100,left=100,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=yes');
        }
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    <iewc:Toolbar ID="topToolBar" runat="server" DefaultStyle="background-repeat:repeat;border:0;background-image:url(../images/menu/silver.gif);"
                                            Height="28px" OnButtonClick="Toolbar_ButtonClick" Style="border-right: #466094 1px solid;
                                            border-top: #466094 1px solid; font-size: 12px; border-left: #466094 1px solid;
                                            width: 100%; border-bottom: #466094 1px; font-family: 宋体">
            <iewc:ToolbarButton ID="chanceInfo" DefaultStyle="background-image:url(../images/menu/silver.gif);"
                                                HoverStyle="background-image:url(../images/menu/2k3OlBarOver.gif);border:solid 1px #000080;"
                                                ImageUrl="../Images/ico/ico_18_service.gif" SelectedStyle="background-image:url(../images/menu/2k3OlBarDown.gif);"
                                                Text="渠道信息" />
            <iewc:ToolbarSeparator />
            <iewc:ToolbarButton ID="chanceListInfo" DefaultStyle="background-image:url(../images/menu/silver.gif);"
                                                HoverStyle="background-image:url(../images/menu/2k3OlBarOver.gif);border:solid 1px #000080;"
                                                ImageUrl="../Images/ico/ico_16_changestatus.gif" SelectedStyle="background-image:url(../images/menu/2k3OlBarDown.gif);"
                                                Text="渠道明细" />
            <iewc:ToolbarSeparator />
            <iewc:ToolbarLabel DefaultStyle="background-image:url(../images/menu/silver.gif);width:100%;" />
        </iewc:Toolbar>
        <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
     
            <asp:View ID="vChanceListInfo" runat="server">
                <table style="width: auto; height: 100%">
                    <tr>
                        <td colspan="3" style="font-weight: bold; font-size: 20px; color: white; font-family: 楷体_GB2312;
                            height: 27px; background-color: #63769b">
                            渠道明细</td>
                    </tr>
                    <tr>
                        <td colspan="3" style="height: 277px">
                            <table style="left: 10px; width: 100%; height: 100%">
                                <tr>
                                    <td style="width: 928px; height: 24px">
                                        <iewc:Toolbar ID="Toolbar2" runat="server" DefaultStyle="background-repeat:repeat;border:0;background-image:url(../images/menu/silver.gif);"
                                            Height="28px" OnButtonClick="Toolbar_ButtonClick" Style="border-right: #466094 1px solid;
                                            border-top: #466094 1px solid; font-size: 12px; border-left: #466094 1px solid;
                                            width: 100%; border-bottom: #466094 1px; font-family: 宋体">
                                            <iewc:ToolbarButton ID="newChanceList" DefaultStyle="background-image:url(../images/menu/silver.gif);"
                                                HoverStyle="background-image:url(../images/menu/2k3OlBarOver.gif);border:solid 1px #000080;"
                                                ImageUrl="../Images/ico/18_addResources.gif" SelectedStyle="background-image:url(../images/menu/2k3OlBarDown.gif);"
                                                Text="新建渠道明细" />
                                            <iewc:ToolbarSeparator />
                                        <iewc:ToolbarButton Text="导出到Excel" ImageUrl="../Images/ico/16_excel.gif" DefaultStyle="background-image:url(../images/menu/silver.gif);"
        ID="ChanceExcel" HoverStyle="background-image:url(../images/menu/2k3OlBarOver.gif);border:solid 1px #000080;"
        SelectedStyle="background-image:url(../images/menu/2k3OlBarDown.gif);"></iewc:ToolbarButton>
       <iewc:ToolbarSeparator></iewc:ToolbarSeparator>
                                            <iewc:ToolbarLabel DefaultStyle="background-image:url(../images/menu/silver.gif);width:100%;" />
                                        </iewc:Toolbar>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center" style="border-right: #ff9966 1px solid; border-top: #ff9966 1px solid;
                                        border-left: #ff9966 1px solid; width: 928px; border-bottom: #ff9966 1px solid;
                                        height: 371px" valign="top">
                                        <asp:GridView ID="GridView1" runat="server" AllowPaging="false" AutoGenerateColumns="False"
                                            CellPadding="4" CssClass="Grid" DataKeyNames="CHANCEDETAILID" EnableTheming="False"
                                            ForeColor="#333333" GridLines="None" OnRowCreated="GridView1_RowCreated" OnRowDeleting="GridView1_RowDeleting"
                                            PageSize="15" Style="word-break: keep-all" Width="100%">
                                            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                            <Columns>
                                                <asp:HyperLinkField DataNavigateUrlFields="PRODUCTID" DataNavigateUrlFormatString="AddProduct.aspx?id={0}"
                                                    DataTextField="PRODUCTNAME" HeaderText="产品名称" ItemStyle-HorizontalAlign=Center>
                                                    <%--<ItemStyle Wrap="False" />--%>
                                                    <HeaderStyle Wrap="False" />
                                                </asp:HyperLinkField>
                                                <asp:BoundField DataField="AMOUNT" HeaderText="数量" ItemStyle-HorizontalAlign=Center>
                                                    <HeaderStyle Wrap="False" />
                                                </asp:BoundField>
                                                <asp:BoundField DataField="AGIO" HeaderText="折扣" ItemStyle-HorizontalAlign=Center>
                                                    <%--<ItemStyle Wrap="False" />--%>
                                                    <HeaderStyle Wrap="False" />
                                                </asp:BoundField>
                                                <asp:BoundField DataField="MONEYSUM" HeaderText="总金额" DataFormatString="{0:N}" HtmlEncode="False" ItemStyle-HorizontalAlign=Center>
                                                    <%--<ItemStyle Wrap="False" />--%>
                                                    <HeaderStyle Wrap="False" />
                                                </asp:BoundField>
                                                <asp:CommandField CausesValidation="False" HeaderText="删除" InsertVisible="False" ItemStyle-HorizontalAlign=Center
                                                    ShowCancelButton="False" ShowDeleteButton="True" />
                                            </Columns>
                                            <RowStyle BackColor="#EFF3FB" />
                                            <EditRowStyle BackColor="#2461BF" />
                                            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                                            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                                            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                            <AlternatingRowStyle BackColor="White" />
                                            <PagerSettings Visible="False" />
                                            <EmptyDataTemplate>
                                                <font color="Navy">暂时无数据内容。</font>
                                            </EmptyDataTemplate>
                                        </asp:GridView>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </asp:View>
       
        </asp:MultiView>
    </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;
using System.Text;
using System.Data.SqlClient;
using Microsoft.Web.UI.WebControls;

public partial class BaseOperation_AddChance : System.Web.UI.Page
{
    private static string strSqlQuery;//存储查询串,带格式的,可配置参
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((Request.QueryString["id"] != null)
            && (!string.IsNullOrEmpty(Request.QueryString["id"].Trim())))
        {
            this.sTitle.Text = this.Title = "查看/修改渠道信息";
        }

        if (!IsPostBack)
        {
            if (JS.isCookiesAvailabile())
            {
                if ((null == Request.QueryString["type"])
                    || (string.IsNullOrEmpty(Request.QueryString["type"].Trim())))
                {
                    JS.Alert("缺少类型字段。");
                    return;
                }

            

                if ((Request.QueryString["id"] != null)
                    && (!string.IsNullOrEmpty(Request.QueryString["id"].Trim()))
                    && initChanceInfo(Request.QueryString["id"].Trim()))
                {
                    this.GridView1.PageIndex = 0;
                    initChanceListInfoList();

                  
                }
             
            }
        }
    }

    #region 工具条事件(新建、打印)
    protected void Toolbar_ButtonClick(object sender, EventArgs e)
    {
        if (sender is Microsoft.Web.UI.WebControls.ToolbarButton)
        {
            ToolbarButton button = (ToolbarButton)sender;

            switch (button.ID)
            {
                case "newChanceList"://新建渠道明细
                    {
                        JS.OpenNewWindow("ChanceList.aspx?backindex=1&type=1&Chanceid=" + Request.QueryString["id"].Trim(), "", 300, 220, 400, 270);
                        break;
                    }
                case "printList"://打印查询结果
                    {
                        break;
                    }
                case "chanceInfo"://渠道信息
                    {
                        if (this.MultiView1.ActiveViewIndex != 0)
                        {
                            this.MultiView1.ActiveViewIndex = 0;
                        }
                        break;
                    }
                case "chanceListInfo"://渠道明细
                    {
                        if (this.MultiView1.ActiveViewIndex != 1)
                        {
                            this.MultiView1.ActiveViewIndex = 1;
                        }
                        break;
                    }
                case "ChanceExcel"://导出渠道列表
                    {
                        if (this.GridView1.Rows.Count == 0)
                        {
                            return;
                        }

                        DataTable ToExcelDataTable = DbHelperSQL.gettable(string.Format(strSqlQuery, "", "").Replace("TOP", ""));//导出Excel的DataTable

                        string[] listname = { "产品名称", "数量", "折扣", "总金额" };
                        string[] cols = { "PRODUCTNAME", "AMOUNT", "AGIO","MONEYSUM" };
                        ToExcel.tableToExcel(ToExcelDataTable, listname, cols);


                        break;
                    }
                default:
                    {
                        return;
                    }
             }
        }
    }
    #endregion 工具条事件(新建、打印)
    #region 初始化表格行事件
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int index = e.Row.RowIndex;
            if (index >= 0)
            {
                string cid = this.GridView1.DataKeys[index][0].ToString();


                string s1 = "window.open('ChanceList.aspx?Chanceid={0}&id={1}&backindex=1','','height=470,width=700,top=100,left=250,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=yes')";

                e.Row.Attributes.Add("ondblclick", string.Format(s1, Request.QueryString["id"].Trim(), cid));
                e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Add("onclick", "return confirm('确定要永久删除该条记录吗?');");
            }
        }
    }
    #endregion 初始化表格行事件

    #region 表格记录的删除事件
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        if ((!JS.isCookiesAvailabile()))
        {
            return;
        }

        //this.GridView1.Rows[e.RowIndex].ToString()
        try
        {
            if (DbHelperSQL.ExecuteSql("DELETE FROM CHANCELIST WHERE CHANCEDETAILID = " + this.GridView1.DataKeys[e.RowIndex].Value) > 0)
            {
                this.initChanceListInfoList();
            }
            else
            {
                JS.Alert("删除记录失败,请稍候再试。");
            }
        }
        catch (Exception ex)
        {
            JS.Alert("删除记录失败,详细信息:" + ex.Message.Replace("/r/n", "").Replace("'", ""));
        }
    }
    #endregion 表格记录的删除事件

    #region 初始化渠道明细页面内容


    protected void initChanceListInfoList()
    {
        
        StringBuilder strSql = new StringBuilder("SELECT CHANCELIST.CHANCEDETAILID, CHANCELIST.AMOUNT, CHANCELIST.AGIO, CHANCELIST.MONEYSUM, PRODUCTS.PRODUCTNAME, CHANCELIST.PRODUCTID FROM PRODUCTS INNER JOIN CHANCELIST ON PRODUCTS.PRODUCTID = CHANCELIST.PRODUCTID WHERE CHANCELIST.CHANCEID =").Append(Request.QueryString["id"].Trim()).Append(" AND CHANCELIST.BCHANCE=").Append(Request.QueryString["type"].Trim());

        String strLevel = Request.Cookies["askCRM"]["LEVELID"];
        string strUid = Request.Cookies["askCRM"]["USERID"];

        if (string.IsNullOrEmpty(strLevel)
            || string.IsNullOrEmpty(strUid))
        {
            return;
        }

        strUid = Tools.Decrypt(strUid, Tools.myKey);
        strLevel = Tools.Decrypt(strLevel, Tools.myKey);

        switch (Convert.ToInt32(strLevel))
        {
            case 0://超级用户
                break;
            default://其他用户
                strSql.Append(" AND CHANCELIST.OPERATOR = '").Append(strUid).Append("'");
                break;
        }

        try
        {
            strSqlQuery = strSql.ToString();
            this.GridView1.DataSource = DbHelperSQL.gettable(strSql.ToString());
            this.GridView1.DataBind();
        }
        catch (Exception ex)
        {
            JS.Alert("初始化数据失败。详细信息:" + ex.Message.Replace("/r/n", "").Replace("'", ""));
            return;
        }
    }
    #endregion 初始化渠道明细页面内容
}

 

刷新夫窗体用的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);
            }

          }

 }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:400858次
    • 积分:7439
    • 等级:
    • 排名:第2921名
    • 原创:334篇
    • 转载:23篇
    • 译文:1篇
    • 评论:52条
    文章分类
    最新评论