protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        if (this.ddlCoalKind.SelectedValue == "")
        {
            MessageBox.Show(this, "请选择煤种!");
            return;
        }
        if (this.txtDate.Value.Trim() == "")
        {
            MessageBox.Show(this, "生效日期不能为空!");
            return;
        }
        if (Convert.ToDateTime(this.txtDate.Value) < DateTime.Now)
        {
            MessageBox.Show(this, "生效日期不能小于当前日期!");
            return;
        }
        List<string> listRoom = new List<string>();
        List<TDTK.IndustryPlatform.CoalTraffic.Model.TT_TaxItemDetail> listModel = new List<TDTK.IndustryPlatform.CoalTraffic.Model.TT_TaxItemDetail>();
        if (this.ddlRoom.SelectedValue == "")
        {
            foreach (ListItem li in this.ddlRoom.Items)
            {
                if (li.Value != "")
                    listRoom.Add(li.Value);
            }
        }
        else
        {

            listRoom.Add(this.ddlRoom.SelectedValue);
        }
        string strIsAll = "";
        if (listRoom.Count > 1)
            strIsAll = "1";
        else
            strIsAll = "0";
        lock (this)
        {
            decimal dTaxGroup = DbHelperSQL.GetMaxID("TaxGroup", "TT_TaxItemDetail");
            foreach (GridViewRow gr in this.gdvList.Rows)
            {
                GridView gdvDetail = (GridView)gr.Cells[1].FindControl("gdvDetail");
                foreach (GridViewRow r in gdvDetail.Rows)
                {
                    TDTK.IndustryPlatform.CoalTraffic.Model.TT_TaxItemDetail model = new TDTK.IndustryPlatform.CoalTraffic.Model.TT_TaxItemDetail();
                    string strAmount = ((TextBox)r.Cells[1].FindControl("txtAmount")).Text.Trim().Replace(" ","");
                    if (strAmount == "")
                        strAmount = "0";
                    model.Amount = Convert.ToDecimal(strAmount);
                    model.CoalKindCode = this.ddlCoalKind.SelectedValue;
                    model.EffectTime = Convert.ToDateTime(this.txtDate.Value.Trim());
                    model.Operator = CookieManager.GetCookieValue("UserName");
                    model.OperateTime = DateTime.Now;
                    model.TaxItemCode = gdvDetail.DataKeys[r.RowIndex].Value.ToString();
                    model.TaxGroup = dTaxGroup;
                    model.IsAll = strIsAll;
                    listModel.Add(model);
                }
            }
            if (bll.Add(listModel, listRoom))
            {
                #region 数据同步
                //StringBuilder strSql = new StringBuilder("");
                //foreach (string strRoomCode in listRoom)
                //{
                //    //如果同一天设置了多次规费,删除这一天的设置和分配,重新添加并且重新分配
                //    strSql.Append("Delete TT_TaxItemDetail where RoomCode='" + strRoomCode + "' and CoalKindCode='" + listModel[0].CoalKindCode + "' and EffectTime='" + listModel[0].EffectTime + "';");

                //    strSql.Append("Delete TT_TaxAssignDetail where ItemDetailId in (select ItemDetailId from TT_TaxItemDetail where RoomCode='" + strRoomCode + "' and CoalKindCode='" + listModel[0].CoalKindCode + "' and EffectTime='" + listModel[0].EffectTime + "');");

                //    foreach (TDTK.IndustryPlatform.CoalTraffic.Model.TT_TaxItemDetail model in listModel)
                //    {
                //        model.RoomCode = strRoomCode;
                //        strSql.Append("insert into TT_TaxItemDetail(");
                //        strSql.Append("CoalKindCode,RoomCode,TaxItemCode,Amount,EffectTime,Operator,OperateTime,TaxGroup,IsAssigned,IsAll)");
                //        strSql.Append(" values (");
                //        strSql.Append("'" + model.CoalKindCode + "','" + model.RoomCode + "','" + model.TaxItemCode + "','" + model.Amount + "','" + model.EffectTime + "','" + model.Operator + "','" + model.OperateTime + "','" + dTaxGroup + "','0','" + model.IsAll + "');");
                //    }
                //    dTaxGroup++;
                //}

                //string strMq = mq.AllStation + mq.Prefix + "TT_TaxItemDetail" + mq.Prefix + mq.AddFlg + mq.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + mq.Prefix + strSql.ToString();
                //mq.AddMsmq(strMq.ToString());禁用了消息队列
                #endregion

                loadData();
                this.ddlCoalKind.SelectedValue = "";
                this.ddlRoom.SelectedValue = "";
                this.txtDate.Value = "";
                MessageBox.Show(this, "规费设置成功!");

                #region 打印明细单
                string strRoom = "";
                if (this.ddlRoom.SelectedValue == "")
                {
                    foreach (ListItem li in this.ddlRoom.Items)
                    {
                        if (li.Value != "")
                            strRoom += "'" + li.Value + "',";
                    }
                }
                else
                {
                    strRoom = "'" + ddlRoom.SelectedValue + "'";
                }
                if (strRoom != "")
                    strRoom = strRoom.TrimEnd(',');

                string userName = GetUserName();
                string title = GetXianName();
                title += "规费标准设置";
                string strWhere = " 1=1 ";
                strWhere += " and a.RoomCode in(" + strRoom + ") and a.CoalKindCode='" + ddlCoalKind.SelectedValue + "' and EffectTime='"+this.txtDate.Value+"'";
                strWhere = Server.UrlEncode(strWhere);

                #endregion
                ScriptManager.RegisterStartupScript(this, Page.GetType(), "", "LoadUrl(\"" + strWhere + "\",'" + userName + "','" + title + "','" + strTaxObject + "');", true);
                //ClientScript.RegisterStartupScript(Page.GetType(), "", "this.top.currForm.close();", true);
            }

            else
                MessageBox.Show(this, "规费设置失败!");
        }
    }
    protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        if (this.ddlCoalKind.SelectedValue == "")
        {
            MessageBox.Show(this.UpdatePanel1,this, "请选择煤种!");
            return;
        }
        if (this.ddlEffectTime.SelectedValue == "")
        {
            MessageBox.Show(this.UpdatePanel1,this, "您的选择没有要修改的规费设置!");
            return;
        }

        List<string> listRoom = new List<string>();
        List<TDTK.IndustryPlatform.CoalTraffic.Model.TT_TaxItemDetail> listModel = new List<TDTK.IndustryPlatform.CoalTraffic.Model.TT_TaxItemDetail>();
        if (this.ddlRoom.SelectedValue == "")
        {
            foreach (ListItem li in this.ddlRoom.Items)
            {
                if (li.Value != "")
                    listRoom.Add(li.Value);
            }
        }
        else
            listRoom.Add(this.ddlRoom.SelectedValue);
        string strIsAll = "";
        if (listRoom.Count > 1)
            strIsAll = "1";
        else
            strIsAll = "0";
        lock (this)
        {
            decimal dTaxGroup = DbHelperSQL.GetMaxID("TaxGroup", "TT_TaxItemDetail");

            foreach (GridViewRow gr in this.gdvList.Rows)
            {
                GridView gdvDetail = (GridView)gr.Cells[1].FindControl("gdvDetail");
                foreach (GridViewRow r in gdvDetail.Rows)
                {
                    TDTK.IndustryPlatform.CoalTraffic.Model.TT_TaxItemDetail model = new TDTK.IndustryPlatform.CoalTraffic.Model.TT_TaxItemDetail();
                    string strAmount = ((TextBox)r.Cells[1].FindControl("txtAmount")).Text.Trim().Replace(" ","");
                    if (strAmount == "")
                        strAmount = "0";
                    model.Amount = Convert.ToDecimal(strAmount);
                    model.CoalKindCode = this.ddlCoalKind.SelectedValue;
                    model.EffectTime = Convert.ToDateTime(this.ddlEffectTime.SelectedValue);
                    model.Operator = CookieManager.GetCookieValue("UserName");
                    model.OperateTime = DateTime.Now;
                    model.TaxItemCode = gdvDetail.DataKeys[r.RowIndex].Value.ToString();
                    model.TaxGroup = dTaxGroup;
                    model.IsAll = strIsAll;
                    listModel.Add(model);
                }
            }
            if (bll.Add(listModel, listRoom))
            {
                #region 数据同步
                StringBuilder strSql = new StringBuilder("");
                foreach (string strRoomCode in listRoom)
                {
                    //如果同一天设置了多次规费,删除这一天的设置和分配,重新添加并且重新分配
                    strSql.Append("Delete TT_TaxItemDetail where RoomCode='" + strRoomCode + "' and CoalKindCode='" + listModel[0].CoalKindCode + "' and EffectTime='" + listModel[0].EffectTime + "';");

                    strSql.Append("Delete TT_TaxAssignDetail where ItemDetailId in (select ItemDetailId from TT_TaxItemDetail where RoomCode='" + strRoomCode + "' and CoalKindCode='" + listModel[0].CoalKindCode + "' and EffectTime='" + listModel[0].EffectTime + "');");

                    foreach (TDTK.IndustryPlatform.CoalTraffic.Model.TT_TaxItemDetail model in listModel)
                    {
                        model.RoomCode = strRoomCode;
                        strSql.Append("insert into TT_TaxItemDetail(");
                        strSql.Append("CoalKindCode,RoomCode,TaxItemCode,Amount,EffectTime,Operator,OperateTime,TaxGroup,IsAssigned,IsAll)");
                        strSql.Append(" values (");
                        strSql.Append("'" + model.CoalKindCode + "','" + model.RoomCode + "','" + model.TaxItemCode + "','" + model.Amount + "','" + model.EffectTime + "','" + model.Operator + "','"+model.OperateTime+"','" + model.TaxGroup + "','0','" + model.IsAll + "');");
                    }
                }
                string strMq = mq.AllStation + mq.Prefix + "TT_TaxItemDetail" + mq.Prefix + mq.EditFlg + mq.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + mq.Prefix + strSql.ToString();
                mq.AddMsmq(strMq.ToString());
                #endregion

                ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "this.top.currForm.close();", true);
            }
            else
                MessageBox.Show(this.UpdatePanel1, this, "规费设置失败!");
        }
    }