///<reference path="/Scripts/ExtPB_Net.js" />
///<reference path="/Scripts/MyExtPB.js" />
///<reference path="/Scripts/ExtPB_Dll_Pb_Http.js" />
///<reference path="/Scripts/MyExtPb_Input.js" />

function W_ZXFX_CG() {

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var st_title = new StaticText(requestor);
    var sle_nf = new SingleLineEdit(requestor);
    var sle_formatname = new SingleLineEdit(requestor);
    var rb_cmhx = new RadioButton(requestor);
    var cbx_gys = new CheckBox(requestor);
    var rb_cmzx = new RadioButton(requestor);
    var rb_ys = new RadioButton(requestor);
    var rb_kh = new RadioButton(requestor);
    var cbx_lb = new CheckBox(requestor);
    var cbx_bm = new CheckBox(requestor);
    var cb_8 = new CommandButton(requestor);
    var cb_7 = new CommandButton(requestor);
    var cb_6 = new CommandButton(requestor);
    var cb_5 = new CommandButton(requestor);
    var cb_4 = new CommandButton(requestor);
    var cb_3 = new CommandButton(requestor);
    var sle_fs = new SingleLineEdit(requestor);
    var sle_ml = new SingleLineEdit(requestor);
    var sle_jj = new SingleLineEdit(requestor);
    var sle_lb = new SingleLineEdit(requestor);
    var sle_kh = new SingleLineEdit(requestor);
    var sle_gys = new SingleLineEdit(requestor);
    var cb_2 = new CommandButton(requestor);
    var sle_pp = new SingleLineEdit(requestor);
    var cb_1 = new CommandButton(requestor);
    var sle_bm = new SingleLineEdit(requestor);
    var dp_2 = new DatePicker(requestor);
    var dp_1 = new DatePicker(requestor);
    var ddlb_sex = new DropDownListBox(requestor);
    var dw_list = new DataWindow(requestor);
    var mle_1 = new MultiLineEdit(requestor);
    var dw_temp = new DataWindow(requestor);
    var dw_format_hz = new DataWindow(requestor);
    var dw_1 = new DataWindow(requestor);
    var dw_format_mx = new DataWindow(requestor);
    var dw_mx = new DataWindow(requestor);
    var dw_hssl = new DataWindow(requestor);
    var dw_format = new DataWindow(requestor);
    var dw_zxsl_cg = new DataWindow(requestor);
    var tb_1 = new ToolStrip(requestor);
    var ContextMenuStrip1 = new ContextMenu(requestor);

    if (typeof (this.bind) == "function") var baseBind = this.bind;
    this.bind = function (win) {
        self.Instance = win;
        if (typeof (baseBind) == "function") baseBind(win);

        if (requestor == null) requestor = new PBWindow();
        requestor.Attach(win);
        if (st_title == null) st_title = new StaticText(requestor);
        st_title.Attach(win.Control("st_title"));
        if (sle_nf == null) sle_nf = new SingleLineEdit(requestor);
        sle_nf.Attach(win.Control("sle_nf"));
        if (sle_formatname == null) sle_formatname = new SingleLineEdit(requestor);
        sle_formatname.Attach(win.Control("sle_formatname"));
        if (rb_cmhx == null) rb_cmhx = new RadioButton(requestor);
        rb_cmhx.Attach(win.Control("rb_cmhx"));
        if (cbx_gys == null) cbx_gys = new CheckBox(requestor);
        cbx_gys.Attach(win.Control("cbx_gys"));
        if (rb_cmzx == null) rb_cmzx = new RadioButton(requestor);
        rb_cmzx.Attach(win.Control("rb_cmzx"));
        if (rb_ys == null) rb_ys = new RadioButton(requestor);
        rb_ys.Attach(win.Control("rb_ys"));
        if (rb_kh == null) rb_kh = new RadioButton(requestor);
        rb_kh.Attach(win.Control("rb_kh"));
        if (cbx_lb == null) cbx_lb = new CheckBox(requestor);
        cbx_lb.Attach(win.Control("cbx_lb"));
        if (cbx_bm == null) cbx_bm = new CheckBox(requestor);
        cbx_bm.Attach(win.Control("cbx_bm"));
        if (cb_8 == null) cb_8 = new CommandButton(requestor);
        cb_8.Attach(win.Control("cb_8"));
        if (cb_7 == null) cb_7 = new CommandButton(requestor);
        cb_7.Attach(win.Control("cb_7"));
        if (cb_6 == null) cb_6 = new CommandButton(requestor);
        cb_6.Attach(win.Control("cb_6"));
        if (cb_5 == null) cb_5 = new CommandButton(requestor);
        cb_5.Attach(win.Control("cb_5"));
        if (cb_4 == null) cb_4 = new CommandButton(requestor);
        cb_4.Attach(win.Control("cb_4"));
        if (cb_3 == null) cb_3 = new CommandButton(requestor);
        cb_3.Attach(win.Control("cb_3"));
        if (sle_fs == null) sle_fs = new SingleLineEdit(requestor);
        sle_fs.Attach(win.Control("sle_fs"));
        if (sle_ml == null) sle_ml = new SingleLineEdit(requestor);
        sle_ml.Attach(win.Control("sle_ml"));
        if (sle_jj == null) sle_jj = new SingleLineEdit(requestor);
        sle_jj.Attach(win.Control("sle_jj"));
        if (sle_lb == null) sle_lb = new SingleLineEdit(requestor);
        sle_lb.Attach(win.Control("sle_lb"));
        if (sle_kh == null) sle_kh = new SingleLineEdit(requestor);
        sle_kh.Attach(win.Control("sle_kh"));
        if (sle_gys == null) sle_gys = new SingleLineEdit(requestor);
        sle_gys.Attach(win.Control("sle_gys"));
        if (cb_2 == null) cb_2 = new CommandButton(requestor);
        cb_2.Attach(win.Control("cb_2"));
        if (sle_pp == null) sle_pp = new SingleLineEdit(requestor);
        sle_pp.Attach(win.Control("sle_pp"));
        if (cb_1 == null) cb_1 = new CommandButton(requestor);
        cb_1.Attach(win.Control("cb_1"));
        if (sle_bm == null) sle_bm = new SingleLineEdit(requestor);
        sle_bm.Attach(win.Control("sle_bm"));
        if (dp_2 == null) dp_2 = new DatePicker(requestor);
        dp_2.Attach(win.Control("dp_2"));
        if (dp_1 == null) dp_1 = new DatePicker(requestor);
        dp_1.Attach(win.Control("dp_1"));
        if (ddlb_sex == null) ddlb_sex = new DropDownListBox(requestor);
        ddlb_sex.Attach(win.Control("ddlb_sex"));
        if (dw_list == null) dw_list = new DataWindow(requestor);
        dw_list.Attach(win.Control("dw_list"));
        if (mle_1 == null) mle_1 = new MultiLineEdit(requestor);
        mle_1.Attach(win.Control("mle_1"));
        if (dw_temp == null) dw_temp = new DataWindow(requestor);
        dw_temp.Attach(win.Control("dw_temp"));
        if (dw_format_hz == null) dw_format_hz = new DataWindow(requestor);
        dw_format_hz.Attach(win.Control("dw_format_hz"));
        if (dw_1 == null) dw_1 = new DataWindow(requestor);
        dw_1.Attach(win.Control("dw_1"));
        if (dw_format_mx == null) dw_format_mx = new DataWindow(requestor);
        dw_format_mx.Attach(win.Control("dw_format_mx"));
        if (dw_mx == null) dw_mx = new DataWindow(requestor);
        dw_mx.Attach(win.Control("dw_mx"));
        if (dw_hssl == null) dw_hssl = new DataWindow(requestor);
        dw_hssl.Attach(win.Control("dw_hssl"));
        if (dw_format == null) dw_format = new DataWindow(requestor);
        dw_format.Attach(win.Control("dw_format"));
        if (dw_zxsl_cg == null) dw_zxsl_cg = new DataWindow(requestor);
        dw_zxsl_cg.Attach(win.Control("dw_zxsl_cg"));
        if (tb_1 == null) tb_1 = new ToolStrip(requestor);
        tb_1.Attach(win.Control("tb_1"));
        if (ContextMenuStrip1 == null) ContextMenuStrip1 = new ContextMenu(requestor);
        ContextMenuStrip1.Attach(win.Control("ContextMenuStrip1"));

        if (typeof (self.PostOpen) == "function")
            win.AttachEvent("window", "PostOpen", self.PostOpen);

        if (typeof (self.CheckedNF) == "function")
            win.AttachEvent("cb_checknf", "Clicked", self.CheckedNF);

        if (typeof (self.CbxEnable) == "function")
            win.AttachEvent("rb_cmhx", "Clicked", self.CbxEnable);

        if (typeof (self.CbxEnable) == "function")
            win.AttachEvent("rb_cmzx", "Clicked", self.CbxEnable);

        if (typeof (self.CbxEnable) == "function")
            win.AttachEvent("rb_ys", "Clicked", self.CbxEnable);

        if (typeof (self.CbxEnable) == "function")
            win.AttachEvent("rb_kh", "Clicked", self.CbxEnable);

        if (typeof (self.Changetzfs) == "function")
            win.AttachEvent("cb_8", "Clicked", self.Changetzfs);

        if (typeof (self.Changeml) == "function")
            win.AttachEvent("cb_7", "Clicked", self.Changeml);

        if (typeof (self.Changejj) == "function")
            win.AttachEvent("cb_6", "Clicked", self.Changejj);

        if (typeof (self.Changelb) == "function")
            win.AttachEvent("cb_5", "Clicked", self.Changelb);

        if (typeof (self.Changekh) == "function")
            win.AttachEvent("cb_4", "Clicked", self.Changekh);

        if (typeof (self.Changegys) == "function")
            win.AttachEvent("cb_3", "Clicked", self.Changegys);

        if (typeof (self.Changepinpai) == "function")
            win.AttachEvent("cb_2", "Clicked", self.Changepinpai);

        if (typeof (self.Changebmbh) == "function")
            win.AttachEvent("cb_1", "Clicked", self.Changebmbh);

        if (typeof (self.DoubleClicked) == "function")
            win.AttachEvent("dw_list", "DoubleClicked", self.DoubleClicked);

        if (typeof (self.RowFocusChanged) == "function")
            win.AttachEvent("dw_list", "RowFocusChanged", self.RowFocusChanged);

        if (typeof (self.TongJi) == "function")
            win.AttachEvent("btn_Query", "Clicked", self.TongJi);

        if (typeof (self.ReportOp) == "function")
            win.AttachEvent("列格式保存ToolStripMenuItem", "Clicked", self.ReportOp);

        if (typeof (self.ReportClare) == "function")
            win.AttachEvent("清空当前窗口所有格式ToolStripMenuItem", "Clicked", self.ReportClare);

    }

    if (typeof (this.unbind) == "function") var baseUnBind = this.unbind;
    this.unbind = function () {
        self.Instance = null;
        if (typeof (this.Release) == "function") this.Release();
        if (typeof (baseUnBind) == "function") baseUnBind();

        st_title.Detach(); st_title = null;
        sle_nf.Detach(); sle_nf = null;
        sle_formatname.Detach(); sle_formatname = null;
        rb_cmhx.Detach(); rb_cmhx = null;
        cbx_gys.Detach(); cbx_gys = null;
        rb_cmzx.Detach(); rb_cmzx = null;
        rb_ys.Detach(); rb_ys = null;
        rb_kh.Detach(); rb_kh = null;
        cbx_lb.Detach(); cbx_lb = null;
        cbx_bm.Detach(); cbx_bm = null;
        cb_8.Detach(); cb_8 = null;
        cb_7.Detach(); cb_7 = null;
        cb_6.Detach(); cb_6 = null;
        cb_5.Detach(); cb_5 = null;
        cb_4.Detach(); cb_4 = null;
        cb_3.Detach(); cb_3 = null;
        sle_fs.Detach(); sle_fs = null;
        sle_ml.Detach(); sle_ml = null;
        sle_jj.Detach(); sle_jj = null;
        sle_lb.Detach(); sle_lb = null;
        sle_kh.Detach(); sle_kh = null;
        sle_gys.Detach(); sle_gys = null;
        cb_2.Detach(); cb_2 = null;
        sle_pp.Detach(); sle_pp = null;
        cb_1.Detach(); cb_1 = null;
        sle_bm.Detach(); sle_bm = null;
        dp_2.Detach(); dp_2 = null;
        dp_1.Detach(); dp_1 = null;
        ddlb_sex.Detach(); ddlb_sex = null;
        dw_list.Detach(); dw_list = null;
        mle_1.Detach(); mle_1 = null;
        dw_temp.Detach(); dw_temp = null;
        dw_format_hz.Detach(); dw_format_hz = null;
        dw_1.Detach(); dw_1 = null;
        dw_format_mx.Detach(); dw_format_mx = null;
        dw_mx.Detach(); dw_mx = null;
        dw_hssl.Detach(); dw_hssl = null;
        dw_format.Detach(); dw_format = null;
        dw_zxsl_cg.Detach(); dw_zxsl_cg = null;
        tb_1.Detach(); tb_1 = null;
        ContextMenuStrip1.Detach(); ContextMenuStrip1 = null;
        requestor.Detach(); requestor = null;

        setTimeout(CollectGarbage, 100);
    }

    //以上代码由设计器自动生成,请不要手工修改
    //ExtPB.Net JavaScript End  设计器查找标志,请不要删除或修改
    //#region 变量定义
    var curW_OPEN_BMDA = new OpenWindowQueryBase();

    var curW_OPEN_BMDA_NEW = new OpenWindowQueryNewBase();
    var curW_OPEN_BMDA_URL = "OpenWindowQueryNewBase";


    var curW_OPEN_SIMPLE_CHOSE = new OpenWindowSimpleChoseBase();
    var ColorRow = 1;
    var curOtherWidht = 1080;
    var curOtherHeight = 760;

    var curOpenWindowDoubleRowsChooseBase = new OpenWindowDoubleRowsChooseBase();
    var gRowCount = 0;
    webReq = new WebRequestor();
    webReq.SetWebServiceUrl("/Service/ServiceForDwSyndax.ashx");
    webReq_Print = new WebRequestor();
    webReq_Print.SetWebServiceUrl("/Service/Ajax_XT.ashx");
    var curYhmc = "";
    var ywflag = "";
    var realSql = "";
    var realSql1 = ""
    var curYhbh = "";
    var curW_Base_Report_Open_Mx = new W_Base_Report_Open_Mx();
    var curBbmc = "rb_kh";
    var ChildDWCheckValue = "";
    var curCdbh = "";
    var curUserId = "";
    var curJgtx = "";
    var ExistGYS = "";
    //报表名称
    var curBBMCNew = "";
    var curBBPZH = "";
    var curOptype = "0" //0 ：保存  1：修改 
    var cur_Open_Window = null;
    var ChildDWCheckValue = "";
//    var dw_format_hz = null; //格式汇总窗口
//    var dw_format_mx = null; //格式明细窗口
    var Exel_FH_Flag = "1";
    var curW_Base_Report_Open_Mx_Ex = new W_Base_Report_Open_Mx_Ex();
    var curUserId = "";
    var curcbx_gs = 0;
    var xsmrgs = 0;
    var curPzh = "";
    var syntax = "";
    var evealStr = "";
    var lastSortName = "";
    var isFirstSave = "";
    var jgtxlist = "";
    var curW_KC_PIC = new W_KC_PIC();
    var curSelDays = "";
    var dw_format_hz = new DataWindow(requestor);
    var dw_format_mx = new DataWindow(requestor);
    var curW_NFCheck = new W_NFCheck();
    var sle_nf = new SingleLineEdit(requestor);
    //#endregion

 
    //#region Function 呼出数据窗口的函数群 

    this.Changebmbh = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_ZXFX_CG, "bmbh", "bmmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_bmda_fl_tree&listDw=dw_pub_list_bmda&treeRootLabel=部门分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple&curQxlx=cgcx"), curW_OPEN_BMDA_NEW, null);
    }

    this.Changepinpai = function (x, y, row, dwoName) {
        dwoName == "ppbm";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_ZXFX_CG, "ppbm", "ppmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_sp_sppp_by_yhbh&selectStyle=multiple&flag=ywcx"), curW_OPEN_SIMPLE_CHOSE, null);
    }

    this.Changegys = function (x, y, row, dwoName) {
        dwoName == "gysbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_ZXFX_CG, "gysbh", "gysmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_gysda_fl_tree&listDw=dw_pub_list_gysda&treeRootLabel=供应商分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple"), curW_OPEN_BMDA_NEW, null);
    }

    this.Changekh = function (x, y, row, dwoName) {
        dwoName == "spkh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_ZXFX_CG, "spkh", "ksmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_sp_lbda_tree&listDw=dw_da_sp_spda_1&treeRootLabel=商品分类&treeData=lbbh&treeLabel=lbmc&treeParentData=flbbh&treeLeave=islast&selectStyle=multiple&curQxlx=all"), curW_OPEN_BMDA_NEW, null);
    }

    this.Changelb = function (x, y, row, dwoName) {
        dwoName == "lbbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_ZXFX_CG, "lbbh", "lbmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_sp_lbda_tree&listDw=dw_da_sp_lbda_list&treeRootLabel=商品分类&treeData=lbbh&treeLabel=lbmc&treeParentData=flbbh&treeLeave=islast&selectStyle=multiple"), curW_OPEN_BMDA_NEW, null);
    }

    this.Changejj = function (x, y, row, dwoName) {
        dwoName == "jjbm";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_ZXFX_CG, "jjbm", "jjmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_da_sp_jjda_list&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }


    this.Changeml = function (x, y, row, dwoName) {
        dwoName == "mlbh";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_ZXFX_CG, "mlbh", "mlmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_da_sp_mlda_list&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }

    this.Changetzfs = function (x, y, row, dwoName) {
        dwoName == "csbh";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_ZXFX_CG, "csbh", "csmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        //dw_pub_list_qj_csb_ddfs
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_da_qj_csb_cgfs_list&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }

    //选中后赋值

    this.SetSleValue = function (difBh, val) {
        if ("''" == val)
            val = "";

        if ("bmbh" == difBh)
            sle_bm.SetText(val);
        else if ("gysbh" == difBh)
            sle_gys.SetText(val);
        else if ("lbbh" == difBh)
            sle_lb.SetText(val);
        else if ("ppbm" == difBh)
            sle_pp.SetText(val);
        else if ("jjbm" == difBh)
            sle_jj.SetText(val);
        else if ("spkh" == difBh)
            sle_kh.SetText(val);
        else if ("csbh" == difBh)
            sle_fs.SetText(val);
        else if ("mlbh" == difBh)
            sle_ml.SetText(val);
    }
    //#region this.Query
    this.Query = function () {

        requestor.ShowLoading("正在查询中......请勿关闭程序。");
        var dynamicShowStr = "";
        var dynamicShowStr1 = "";
        var dynamicShowStr2 = "";
        var dynamicShowString = "";
        var dynamicShowString1 = "";
        var dynamicShowStr3 = "";
        var dynamicShowStr4 = "";
        var curSql = ""
        var curRows = "";
        var curCols = "";
        var curValues = "";
        var curColTypes = "";
        var sy = "";
        var finishSql = "";
        ChildDWCheckValue = "";
        dw_temp.Reset();
        if (cbx_bm.GetChecked()) {
            dynamicShowStr += " a.bmbh as bmbh ,c.bmmc as bmmc,";
            dynamicShowString += " ,a.bmbh,c.bmmc";
            dynamicShowStr1 += " t1.bmbh as bmbh ,t3.bmmc as bmmc,";
            dynamicShowString1 += " ,t1.bmbh,t3.bmmc";
            dynamicShowStr2 += " bmbh ,bmmc,";
            dynamicShowStr3 += " cg_ddb.bmbh ,cg_ddb.bmmc,";
            dynamicShowStr4 += " and cg_ddb.bmbh=cg_rkb.bmbh "
            ChildDWCheckValue += "cbx_bm,"
        }
        if (cbx_lb.GetChecked()) {
            dynamicShowStr += "b.hplb hplb,d.lbmc lbmc,";
            dynamicShowString += ",b.hplb,d.lbmc";
            dynamicShowStr1 += "t2.hplb,t4.lbmc,";
            dynamicShowString1 += ",t2.hplb,t4.lbmc";
            dynamicShowStr2 += "hplb,lbmc,";
            dynamicShowStr3 += "cg_ddb.hplb,cg_ddb.lbmc,";
            dynamicShowStr4 += " and cg_ddb.hplb=cg_rkb.hplb "
            ChildDWCheckValue += "cbx_lb,"
        }
        if (cbx_gys.GetChecked()) {
            dynamicShowStr += "a.gysbh gysbh ,e.gysmc gysmc,";
            dynamicShowString += ",a.gysbh,e.gysmc";
            dynamicShowStr1 += "t1.gysbh gysbh ,t5.gysmc gysmc,";
            dynamicShowString1 += ",t1.gysbh,t5.gysmc";
            dynamicShowStr2 += "gysbh ,gysmc,";
            dynamicShowStr3 += "cg_ddb.gysbh ,cg_ddb.gysmc,";
            dynamicShowStr4 += " and cg_ddb.gysbh=cg_rkb.gysbh "
            ChildDWCheckValue += "cbx_gys,"
        }

        self.GetSqlWhere()
        //#region 款式
        if (rb_kh.GetChecked()) {
            curBbmc = rb_kh.GetName();

            var finishSql_dd = "(select a.bmbh,c.bmmc,a.gysbh,e.gysmc,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.bxbh,SUM(a.sl) ddbzjsl, avg(a.lsj) lsj,sum(a.sl*a.lsj) lsjze,avg(a.jj) jj,sum(a.sl*a.jj) jjze from (SELECT * FROM dbo.yw_cg_cgddtz_ls   UNION ALL   SELECT * FROM dbo.yw_cg_cgddtz) a " +
                            " left join  da_sp_spda b on a.spkh=b.spkh " +
                            "left join  da_bmda c  on a.bmbh= c.bmbh  " +
                            "left join  da_sp_lbda d on d.lbbh=b.hplb " +
                            "left join  da_gysda e on e.gysbh=a.gysbh " +
                            "left join  (select * from da_qj_csb where  csfl='CG_CGFS') f on a.cgfs=f.csbh  where a.djlx='1' " +
                            realSql + " group by  a.bmbh,c.bmmc,a.gysbh,e.gysmc,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.bxbh) as cg_ddb left join "
            var finishSql_rk = "(select t1.bmbh,t3.bmmc,t1.gysbh,t5.gysmc,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.bxbh,SUM((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)) rkbzjsl, avg(t1.lsj) lsj,sum((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)*t1.lsj) lsjze,avg(t1.jj) jj,sum((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)*t1.jj) jjze from (SELECT * FROM dbo.yw_cg_cgrkdtz   UNION ALL   SELECT * FROM dbo.yw_cg_cgrkdtz_ls) t1 " +
                            " left join  da_sp_spda t2 on t1.spkh=t2.spkh " +
                            "left join  da_bmda t3  on t1.bmbh= t3.bmbh  " +
                            "left join  da_sp_lbda t4 on t4.lbbh=t2.hplb " +
                            "left join  da_gysda t5 on t5.gysbh=t1.gysbh " +
                            "left join  (select * from da_qj_csb where  csfl='CG_CGFS') t6 on t1.cgfs=t6.csbh  where 1=1 " + realSql1 +
                            " group by  t1.bmbh,t3.bmmc,t1.gysbh,t5.gysmc,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.bxbh) as cg_rkb  on cg_ddb.spkh=cg_rkb.spkh  and cg_ddb.bmbh=cg_rkb.bmbh  and cg_ddb.gysbh=cg_rkb.gysbh  and cg_ddb.hplb=cg_rkb.hplb  AND cg_ddb.yslsh=cg_rkb.yslsh and  cg_ddb.cmbh=cg_rkb.cmbh and cg_ddb.bxbh=cg_rkb.bxbh"
            var sendsql = "select " + dynamicShowStr3 + " cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw,sum(isnull(ddbzjsl,0))ddbzjsl,sum(isnull(rkbzjsl,0))rkbzjsl,sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0)) sqsl, sum(isnull(rkbzjsl,0))/CASE WHEN sum(ISNULL(ddbzjsl, 0))=0 THEN  1 ELSE sum(ISNULL(ddbzjsl, 0)) end dhbl from  " + finishSql_dd + finishSql_rk +
                    " where 1=1 " +
                    " group by " + dynamicShowStr3 + "cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw"


            //requestor.ClipBoardNao(sendsql)
            sendsql = sendsql.replace(/\+/g, "%2B");
            sendsql = sendsql.replace(/\&/g, "%26");
            sendsql = sendsql.replace(/\%/g, "%25");
            self.DrawDataWindow(sendsql);

            DWSort(dw_format, dw_list);
            //#endregion
            //self.SetValue(C_CheckValue, curBbmc, curCdbh, curYhbh);


        }
        //#endregion

        //#region 颜色
        if (rb_ys.GetChecked()) {
            curBbmc = rb_ys.GetName();
            var finishSql_dd = "(select a.bmbh,c.bmmc,a.gysbh,e.gysmc,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.ysbh,g.ysmc,a.bxbh,SUM(a.sl) ddbzjsl, avg(a.lsj) lsj,sum(a.sl*a.lsj) lsjze,avg(a.jj) jj,sum(a.sl*a.jj) jjze from (SELECT * FROM dbo.yw_cg_cgddtz_ls   UNION ALL   SELECT * FROM dbo.yw_cg_cgddtz) a " +
                            " left join  da_sp_spda b on a.spkh=b.spkh " +
                            "left join  da_bmda c  on a.bmbh= c.bmbh  " +
                            "left join  da_sp_lbda d on d.lbbh=b.hplb " +
                            "left join  da_gysda e on e.gysbh=a.gysbh " +
                                "left join da_sp_ysda g on  a.yslsh=g.yslsh " +
                            "left join  (select * from da_qj_csb where  csfl='CG_CGFS') f on a.cgfs=f.csbh  where a.djlx='1'  " +
                            realSql + " group by   a.bmbh,c.bmmc,a.gysbh,e.gysmc,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.ysbh,g.ysmc,a.bxbh) as cg_ddb left join "
            var finishSql_rk = "(select t1.bmbh,t3.bmmc,t1.gysbh,t5.gysmc,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.ysbh,t7.ysmc,t1.bxbh,SUM((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)) rkbzjsl, avg(t1.lsj) lsj,sum((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)*t1.lsj) lsjze,avg(t1.jj) jj,sum((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)*t1.jj) jjze from (SELECT * FROM dbo.yw_cg_cgrkdtz   UNION ALL   SELECT * FROM dbo.yw_cg_cgrkdtz_ls) t1 " +
                            " left join  da_sp_spda t2 on t1.spkh=t2.spkh " +
                            "left join  da_bmda t3  on t1.bmbh= t3.bmbh  " +
                            "left join  da_sp_lbda t4 on t4.lbbh=t2.hplb " +
                            "left join  da_gysda t5 on t5.gysbh=t1.gysbh " +
                            "left join da_sp_ysda t7 on t1.yslsh=t7.yslsh " +
                            "left join  (select * from da_qj_csb where  csfl='CG_CGFS') t6 on t1.cgfs=t6.csbh  where 1=1 " + realSql1 +
                            " group by t1.bmbh,t3.bmmc,t1.gysbh,t5.gysmc,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.ysbh,t7.ysmc,t1.bxbh) as cg_rkb on  cg_ddb.spkh=cg_rkb.spkh  and cg_ddb.bmbh=cg_rkb.bmbh  and cg_ddb.gysbh=cg_rkb.gysbh  and cg_ddb.hplb=cg_rkb.hplb  AND cg_ddb.yslsh=cg_rkb.yslsh and  cg_ddb.cmbh=cg_rkb.cmbh and cg_ddb.bxbh=cg_rkb.bxbh"
            var sendsql = "select " + dynamicShowStr3 + " cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw,cg_ddb.ysbh,cg_ddb.ysmc,sum(isnull(ddbzjsl,0))ddbzjsl,sum(isnull(rkbzjsl,0))rkbzjsl,sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0)) sqsl, sum(isnull(rkbzjsl,0))/CASE WHEN sum(ISNULL(ddbzjsl, 0))=0 THEN  1 ELSE sum(ISNULL(ddbzjsl, 0)) end dhbl from  " + finishSql_dd + finishSql_rk +
                    " where 1=1 " +
                    " group by " + dynamicShowStr3 + "cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw,cg_ddb.ysbh,cg_ddb.ysmc"

            requestor.ClipBoard(sendsql)
            sendsql = sendsql.replace(/\+/g, "%2B");
            sendsql = sendsql.replace(/\&/g, "%26");
            sendsql = sendsql.replace(/\%/g, "%25");
            self.DrawDataWindow(sendsql);
            DWSort(dw_format, dw_list);
            //#endregion
            // self.SetValue(C_CheckValue, curBbmc, curCdbh, curYhbh);
        }
        //#endregion

        //#region 尺码纵向
        if (rb_cmzx.GetChecked()) {
            curBbmc = rb_cmzx.GetName();
            if (dynamicShowStr3.length > 0) {
                dynamicShowStr3 = "," + dynamicShowStr3.substring(0, dynamicShowStr3.length - 1)
            }
            var finishSql_dd = "(select  a.bmbh,c.bmmc,a.gysbh,e.gysmc,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.ysbh,g.ysmc,a.bxbh," +
                            "SUM(a.sl) ddbzjsl, avg(a.lsj) lsj,sum(a.sl*a.lsj) lsjze,avg(a.jj) jj,sum(a.sl*a.jj) jjze," +
                            "b.jypp,k.ppmc,b.spml,j.mlmc,b.spnf,b.spjj,h.jjmc,b.spsx,b.spsx1,b.spsx2 " +
                            "from yw_cg_cgddtz a " +
                            " left join  da_sp_spda b on a.spkh=b.spkh " +
                            "left join  da_bmda c  on a.bmbh= c.bmbh  " +
                            "left join  da_sp_lbda d on d.lbbh=b.hplb " +
                            "left join  da_gysda e on e.gysbh=a.gysbh " +
                            "left join da_sp_ysda g on  a.yslsh=g.yslsh " +
                            "left join da_sp_jjda h on b.spjj=h.jjbm " +
                            "left join da_sp_mlda j on j.mlbh=b.spml " +
                            " left join da_sp_ppda k on k.ppbm=b.jypp " +
                            "left join  (select * from da_qj_csb where  csfl='CG_CGFS') f on a.cgfs=f.csbh  where a.djlx='1' " +
                            realSql + " group by   a.bmbh,c.bmmc,a.gysbh,e.gysmc,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.ysbh,g.ysmc,a.bxbh,b.jypp,k.ppmc,b.spml,j.mlmc,b.spnf,b.spjj,h.jjmc,b.spsx,b.spsx1,b.spsx2) as cg_ddb left join ";
            var finishSql_rk = "(select t1.bmbh,t3.bmmc,t1.gysbh,t5.gysmc,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.ysbh,t7.ysmc,t1.bxbh," +
                            "SUM((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)) rkbzjsl, avg(t1.lsj) lsj,sum((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)*t1.lsj) lsjze,avg(t1.jj) jj,sum((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)*t1.jj) jjze," +
                            "t2.jypp,t10.ppmc,t2.spml,t9.mlmc,t2.spnf,t2.spjj,t8.jjmc,t2.spsx,t2.spsx1,t2.spsx2 " +
                            "from yw_cg_cgrkdtz t1 " +
                            " left join  da_sp_spda t2 on t1.spkh=t2.spkh " +
                            "left join  da_bmda t3  on t1.bmbh= t3.bmbh  " +
                            "left join  da_sp_lbda t4 on t4.lbbh=t2.hplb " +
                            "left join  da_gysda t5 on t5.gysbh=t1.gysbh " +
                            "left join da_sp_ysda t7 on t1.yslsh=t7.yslsh " +
                            "left join da_sp_jjda t8 on t2.spjj=t8.jjbm " +
                            "left join da_sp_mlda t9 on t9.mlbh=t2.spml " +
                            " left join da_sp_ppda t10 on t10.ppbm=t2.jypp " +
                            "left join  (select * from da_qj_csb where  csfl='CG_CGFS') t6 on t1.cgfs=t6.csbh  where 1=1 " + realSql1 +
                            " group by  t1.bmbh,t3.bmmc,t1.gysbh,t5.gysmc,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.ysbh,t7.ysmc,t1.bxbh,t2.jypp,t10.ppmc,t2.spml,t9.mlmc,t2.spnf,t2.spjj,t8.jjmc,t2.spsx,t2.spsx1,t2.spsx2) as cg_rkb on cg_ddb.spkh=cg_rkb.spkh  and cg_ddb.bmbh=cg_rkb.bmbh  and cg_ddb.gysbh=cg_rkb.gysbh  and cg_ddb.hplb=cg_rkb.hplb  AND cg_ddb.yslsh=cg_rkb.yslsh and  cg_ddb.cmbh=cg_rkb.cmbh and cg_ddb.bxbh=cg_rkb.bxbh "
            var sendsql = " select 'cg_ddb.hplb' hplb,'cg_ddb.lbmc' lbmc,cg_ddb.spkh spkh,cg_ddb.ksmc ksmc ,cg_ddb.jldw jldw ,cg_ddb.ysbh ysbh,cg_ddb.ysmc ysmc,'cg_ddb.bmbh' bmbh,'cg_ddb.bmmc' bmmc," +
                    " 'cg_ddb.gysbh' gysbh,'cg_ddb.gysmc' gysmc," +
                    "sum(isnull(ddbzjsl,0))ddzjsl,  sum(isnull(rkbzjsl,0))rkzjsl,sum(isnull(ddbzjsl,0)-isnull(rkbzjsl,0)) sqsl, " +
                    "avg(cg_ddb.jj) ddjj,avg(cg_ddb.lsj) ddlsj,sum(cg_ddb.lsjze) ddlsjze,sum(cg_ddb.jjze)  ddjjze, " +
                    "avg(cg_rkb.jj) rkjj,avg(cg_rkb.lsj) rklsj,sum(cg_rkb.lsjze) rklsjze,sum(cg_rkb.jjze)  rkjjze, " +
                    "sum(isnull(cg_ddb.jjze,0)-isnull(cg_rkb.jjze,0))/(case when  sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0))=0  then 1 else sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0)) end) sqjj, " +
                    "avg(cg_ddb.lsj) sqlsj, " +
                    "sum(isnull(cg_ddb.lsjze,0)-isnull(cg_rkb.lsjze,0)) sqlsjze,sum(isnull(cg_ddb.jjze,0)-isnull(cg_rkb.jjze,0)) sqjjze, " +
                    "cg_ddb.cmzbh,cg_ddb.cmbh, " +
                    "cg_ddb.jypp,cg_ddb.ppmc,cg_ddb.spml,cg_ddb.mlmc,cg_ddb.spnf,cg_ddb.spjj,cg_ddb.jjmc,cg_ddb.spsx,cg_ddb.spsx1,cg_ddb.spsx2  " +
                    "  from    " + finishSql_dd + finishSql_rk +
                    " where 1=1 " +
                    " group by  cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw,cg_ddb.ysbh,cg_ddb.ysmc,cg_ddb.cmzbh,cg_ddb.cmbh,cg_ddb.jypp,cg_ddb.ppmc,cg_ddb.spml,cg_ddb.mlmc,cg_ddb.spnf,cg_ddb.spjj,cg_ddb.jjmc,cg_ddb.spsx,cg_ddb.spsx1,cg_ddb.spsx2" + dynamicShowStr3

            if (cbx_lb.GetChecked()) {
                sendsql = sendsql.replace("'cg_ddb.hplb'", "cg_ddb.hplb");
                sendsql = sendsql.replace("'cg_ddb.lbmc'", "cg_ddb.lbmc");
            }
            if (cbx_gys.GetChecked()) {
                sendsql = sendsql.replace("'cg_ddb.gysbh'", "cg_ddb.gysbh");
                sendsql = sendsql.replace("'cg_ddb.gysmc'", "cg_ddb.gysmc");
            }
            if (cbx_bm.GetChecked()) {
                sendsql = sendsql.replace("'cg_ddb.bmbh'", "cg_ddb.bmbh");
                sendsql = sendsql.replace("'cg_ddb.bmmc'", "cg_ddb.bmmc");
            }
          //  requestor.ClipBoardNao(sendsql)
            sendsql = sendsql.replace(/\+/g, "%2B");
            sendsql = sendsql.replace(/\&/g, "%26");
            sendsql = sendsql.replace(/\%/g, "%25");
            dw_zxsl_cg.Retrieve(sendsql);
            webReq.Invoke("CG_ZXFX_CMZX", "ls_syntax=" + sendsql + "&flag=CMZX");
            if (webReq.StatusCode() == 200) {
                dw_zxsl_cg.Retrieve()
                dw_list.SetFullState(dw_zxsl_cg.GetFullState());
                self.Controlhl();
                DWSort(dw_format, dw_list);
                dw_list.SetSort("spkh,ksmc,ysbh,ysmc,sort");
                dw_list.Sort();
            }
            else {
                requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);
            }

        }
        //#endregion

        //#region 尺码横向
        if (rb_cmhx.GetChecked()) {
            curBbmc = rb_cmhx.GetName();
            if (dynamicShowStr3.length > 0) {
                dynamicShowStr3 = "," + dynamicShowStr3.substring(0, dynamicShowStr3.length - 1)
            }
            var finishSql_dd = "(select  a.bmbh,c.bmmc,a.gysbh,e.gysmc,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.ysbh,g.ysmc,a.bxbh," +
                            "SUM(a.sl) ddbzjsl, avg(a.lsj) lsj,sum(a.sl*a.lsj) lsjze,avg(a.jj) jj,sum(a.sl*a.jj) jjze," +
                            "b.jypp,k.ppmc,b.spml,j.mlmc,b.spnf,b.spjj,h.jjmc,b.spsx,b.spsx1,b.spsx2 " +
                            "from (SELECT * FROM dbo.yw_cg_cgddtz_ls   UNION ALL   SELECT * FROM dbo.yw_cg_cgddtz) a " +
                            " left join  da_sp_spda b on a.spkh=b.spkh " +
                            "left join  da_bmda c  on a.bmbh= c.bmbh  " +
                            "left join  da_sp_lbda d on d.lbbh=b.hplb " +
                            "left join  da_gysda e on e.gysbh=a.gysbh " +
                            "left join da_sp_ysda g on  a.yslsh=g.yslsh " +
                            "left join da_sp_jjda h on b.spjj=h.jjbm " +
                            "left join da_sp_mlda j on j.mlbh=b.spml " +
                            " left join da_sp_ppda k on k.ppbm=b.jypp " +
                            "left join  (select * from da_qj_csb where  csfl='CG_CGFS') f on a.cgfs=f.csbh  where a.djlx='1' " +
                            realSql + " group by   a.bmbh,c.bmmc,a.gysbh,e.gysmc,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.ysbh,g.ysmc,a.bxbh,b.jypp,k.ppmc,b.spml,j.mlmc,b.spnf,b.spjj,h.jjmc,b.spsx,b.spsx1,b.spsx2) as cg_ddb left join ";
            var finishSql_rk = "(select t1.bmbh,t3.bmmc,t1.gysbh,t5.gysmc,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.ysbh,t7.ysmc,t1.bxbh," +
                            "SUM((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)) rkbzjsl, avg(t1.lsj) lsj,sum((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)*t1.lsj) lsjze,avg(t1.jj) jj,sum((CASE WHEN djlx='1' THEN t1.sl ELSE -t1.sl END)*t1.jj) jjze," +
                            "t2.jypp,t10.ppmc,t2.spml,t9.mlmc,t2.spnf,t2.spjj,t8.jjmc,t2.spsx,t2.spsx1,t2.spsx2 " +
                            "from (SELECT * FROM dbo.yw_cg_cgrkdtz   UNION ALL   SELECT * FROM dbo.yw_cg_cgrkdtz_ls) t1 " +
                            " left join  da_sp_spda t2 on t1.spkh=t2.spkh " +
                            "left join  da_bmda t3  on t1.bmbh= t3.bmbh  " +
                            "left join  da_sp_lbda t4 on t4.lbbh=t2.hplb " +
                            "left join  da_gysda t5 on t5.gysbh=t1.gysbh " +
                            "left join da_sp_ysda t7 on t1.yslsh=t7.yslsh " +
                            "left join da_sp_jjda t8 on t2.spjj=t8.jjbm " +
                            "left join da_sp_mlda t9 on t9.mlbh=t2.spml " +
                            " left join da_sp_ppda t10 on t10.ppbm=t2.jypp " +
                            "left join  (select * from da_qj_csb where  csfl='CG_CGFS') t6 on t1.cgfs=t6.csbh  where 1=1 " + realSql1 +
                            " group by  t1.bmbh,t3.bmmc,t1.gysbh,t5.gysmc,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.ysbh,t7.ysmc,t1.bxbh,t2.jypp,t10.ppmc,t2.spml,t9.mlmc,t2.spnf,t2.spjj,t8.jjmc,t2.spsx,t2.spsx1,t2.spsx2) as cg_rkb on cg_ddb.spkh=cg_rkb.spkh  and cg_ddb.bmbh=cg_rkb.bmbh  and cg_ddb.gysbh=cg_rkb.gysbh  and cg_ddb.hplb=cg_rkb.hplb  AND cg_ddb.yslsh=cg_rkb.yslsh and  cg_ddb.cmbh=cg_rkb.cmbh and cg_ddb.bxbh=cg_rkb.bxbh "
            var sendsql = " select 'cg_ddb.hplb' hplb,'cg_ddb.lbmc' lbmc,cg_ddb.spkh spkh,cg_ddb.ksmc ksmc ,cg_ddb.jldw jldw ,cg_ddb.ysbh ysbh,cg_ddb.ysmc ysmc,'cg_ddb.bmbh' bmbh,'cg_ddb.bmmc' bmmc," +
                    " 'cg_ddb.gysbh' gysbh,'cg_ddb.gysmc' gysmc," +
                    "sum(isnull(ddbzjsl,0))ddzjsl,  sum(isnull(rkbzjsl,0))rkzjsl,sum(isnull(ddbzjsl,0)-isnull(rkbzjsl,0)) sqsl, " +
                    "avg(cg_ddb.jj) ddjj,avg(cg_ddb.lsj) ddlsj,sum(cg_ddb.lsjze) ddlsjze,sum(cg_ddb.jjze)  ddjjze, " +
                    "avg(cg_rkb.jj) rkjj,avg(cg_rkb.lsj) rklsj,sum(cg_rkb.lsjze) rklsjze,sum(cg_rkb.jjze)  rkjjze, " +
                    "sum(isnull(cg_ddb.jjze,0)-isnull(cg_rkb.jjze,0))/(case when  sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0))=0  then 1 else sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0)) end) sqjj, " +
                    "avg(cg_ddb.lsj) sqlsj, " +
                    "sum(isnull(cg_ddb.lsjze,0)-isnull(cg_rkb.lsjze,0)) sqlsjze,sum(isnull(cg_ddb.jjze,0)-isnull(cg_rkb.jjze,0)) sqjjze, " +
                    "cg_ddb.cmzbh,cg_ddb.cmbh, " +
                    "cg_ddb.jypp,cg_ddb.ppmc,cg_ddb.spml,cg_ddb.mlmc,cg_ddb.spnf,cg_ddb.spjj,cg_ddb.jjmc,cg_ddb.spsx,cg_ddb.spsx1,cg_ddb.spsx2  " +
                    "  from    " + finishSql_dd + finishSql_rk +
                    " where 1=1 " +
                    " group by  cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw,cg_ddb.ysbh,cg_ddb.ysmc,cg_ddb.cmzbh,cg_ddb.cmbh,cg_ddb.jypp,cg_ddb.ppmc,cg_ddb.spml,cg_ddb.mlmc,cg_ddb.spnf,cg_ddb.spjj,cg_ddb.jjmc,cg_ddb.spsx,cg_ddb.spsx1,cg_ddb.spsx2" + dynamicShowStr3
            if (cbx_lb.GetChecked()) {
                sendsql = sendsql.replace("'cg_ddb.hplb'", "cg_ddb.hplb");
                sendsql = sendsql.replace("'cg_ddb.lbmc'", "cg_ddb.lbmc");
            }
            if (cbx_gys.GetChecked()) {
                sendsql = sendsql.replace("'cg_ddb.gysbh'", "cg_ddb.gysbh");
                sendsql = sendsql.replace("'cg_ddb.gysmc'", "cg_ddb.gysmc");
            }
            if (cbx_bm.GetChecked()) {
                sendsql = sendsql.replace("'cg_ddb.bmbh'", "cg_ddb.bmbh");
                sendsql = sendsql.replace("'cg_ddb.bmmc'", "cg_ddb.bmmc");
            }

            sendsql = sendsql.replace(/\+/g, "%2B");
            sendsql = sendsql.replace(/\&/g, "%26");
            sendsql = sendsql.replace(/\%/g, "%25");

            webReq.Invoke("CG_ZXFX_CMZX", "ls_syntax=" + sendsql + "&flag=CMHX");
            if (webReq.StatusCode() == 200) {
                dw_hssl.Retrieve()
                dw_list.SetFullState(dw_hssl.GetFullState());
                self.Controlhl();
                DWSort(dw_format, dw_list);
            }
            else {
                requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);
            }

            //#endregion
            // self.SetValue(C_CheckValue, curBbmc, curCdbh, curYhbh);
        }
        // mle_1.SetText(sendsql);
        //#endregion

        requestor.CloseLoading();

    }
    //#endregion

    //#region 表头颜色
    this.RowFocusChanged = function () {
        if (rb_cmhx.GetChecked() || rb_cmzx.GetChecked()) {
            for (var i = 1; i < 36; i++) {
                var str = "";
                if (ColorRow == "1") {
                    str = "cm" + i;
                }
                else {
                    str = "cm" + i + "0" + (parseInt(ColorRow) - 1);
                }
                dw_list.Modify(str + "_t.color='33554432'" + str + "_t.Font.Weight='400'");

            }
            var row = dw_list.GetRow();
            if (row < 1) {
                return;
            }
            var cmzbh = dw_list.GetItemString(row, "cmzbh");
            var spkh = dw_list.GetItemString(row, "spkh");
            dw_1.Retrieve(cmzbh, spkh);

            var modifyColor = dw_1.GetItemString(1, "colorchange").split("#")[0].toString();


            for (var i = 1; i < 36; i++) {

                var str = "";
                if (modifyColor == "1") {
                    str = "cm" + i;
                }
                else {
                    str = "cm" + i + "0" + (parseInt(modifyColor) - 1);
                }
                dw_list.Modify(str + "_t.color='16711680'" + str + "_t.Font.Weight='700'");
                //dw_list.Modify(str+".color")
            }
            ColorRow = modifyColor;
        }
    }


    //#region 处理引号的问题
    this.GetQuotes = function (curValue) {
        var temp1 = curValue.split(",")
        var ret_Value = "";
        for (var i = 0; i < temp1.length; i++) {
            if (ret_Value.length > 0) {
                ret_Value += "'" + temp1[i] + "',";
            }
            else {
                ret_Value = "'" + temp1[i] + "',"
            }
        }
        return ret_Value.substr(0, ret_Value.length - 1);
    }
    //#endregion



    //#region Function DealWords
    this.DealWords = function (words) {

        var temChar = words.toString().charAt(0);
        if (!(temChar == "'"))
            words = "'" + words + "'";
        return words;
    }
    //#endregion
    
    //#region PostOpen
    this.PostOpen = function () {
    
        webReq.Invoke("GetXbDa", "flag=TJ");
        if (webReq.StatusCode() == 200) {
            ddlb_sex.Reset()

            var xbmc = webReq.ResponseText();
           // alert(xbmc);
            if (xbmc.length > 0) {
                for (var i = 0; i < xbmc.split(",").length; i++) {
                    ddlb_sex.AddItem(xbmc.split(",")[i])
                }
            }
            //   alert(webReq_common.ResponseText())
        }


        sle_bm.SetEnabled(false);
        sle_gys.SetEnabled(false);
        //    for(var i = 1;i<= dw_list.)
        if (dw_format_hz == null) dw_format_hz = new DataWindow(requestor);
        dw_format_hz.Attach(requestor.Control("dw_format_hz"));

        if (dw_format_mx == null) dw_format_mx = new DataWindow(requestor);
        dw_format_mx.Attach(requestor.Control("dw_format_mx"));



        if (typeof (self.SelectGS) == "function")
            requestor.AttachEvent("cb_Select", "Clicked", self.SelectGS);

        if (typeof (self.SaveGS) == "function")
            requestor.AttachEvent("cb_Save", "Clicked", self.SaveGS);

        if (typeof (self.Print) == "function")
            requestor.AttachEvent("btn_Print", "Clicked", self.Print);

        if (typeof (self.ReportOp) == "function")
            requestor.AttachEvent("列格式保存ToolStripMenuItem", "Clicked", self.ReportOp);

        if (typeof (self.ReportClare) == "function")
            requestor.AttachEvent("清空当前窗口所有格式ToolStripMenuItem", "Clicked", self.ReportClare);

        if (typeof (self.picpreview) == "function")
            requestor.AttachEvent("浏览图片ToolStripMenuItem", "Clicked", self.picpreview);

        //        if (typeof (self.DoubleClicked) == "function")
        //            requestor.AttachEvent("dw_List", "DoubleClicked", self.DoubleClicked);

        if (typeof (self.RightKey) == "function")
            requestor.AttachEvent("xxxxxxaToolStripMenuItem", "Clicked", self.RightKey);

        if (typeof (self.Exit) == "function")
            requestor.AttachEvent("btn_Exit", "Clicked", self.Exit);


        dw_temp.SetVisible(false)
        //    dw_format_hz = window.external.Control("dw_format_hz");
        //    dw_format_mx = window.external.Control("dw_format");
        Exel_FH_Flag = GetGlobalParm("Excel_FH_Flag", "Excel_FH_Flag", "qybz");
        if (Exel_FH_Flag.length < 1) {
            Exel_FH_Flag = "1";
        }
        ywflag = requestor.GetParm("ywflag");
        curCdbh = requestor.GetParm("curCdbh");
        curYhbh = requestor.GetParm("curYhbh");
        curUserId = requestor.GetParm("curYhbh");
        curYhmc = requestor.GetParm("curYhmc");
        var myDate = new Date();
        var nian = myDate.getFullYear().toString();
        var yue = myDate.getMonth();
        var ri = "01";
        var objDate = new Date(nian, yue, ri);
        // dp_1.SetValue(objDate.getVarDate())
        dp_1.SetValue(UtcDateFormatToString(new Date().getVarDate()))
        dp_2.SetValue(UtcDateFormatToString(new Date().getVarDate()))
        var v_CheckBoxState = GetCheckBoxValue(dw_format, curYhbh, curCdbh, curBbmc)
        if (v_CheckBoxState.length > 1) {
            window.eval(v_CheckBoxState);
        }

        curJgtx = requestor.GetParm("jgtxlist");
        ExistGYS = ExistJG(curJgtx, "gysbh");
        // 供应商
        if (ExistGYS == "N") {
            cbx_gys.SetEnabled(false);
            cbx_gys.SetChecked(false);
            cb_3.SetEnabled(false);

        }
        else {
            cbx_gys.SetEnabled(true);
            cb_3.SetEnabled(true);
        }
        curPzh = requestor.GetParm("pzh");
        curBbmc = requestor.GetParm("bbmc");
        curBbfl = requestor.GetParm("bbfl");
        var context = curPzh + "#" + curBbmc + "#" + curBbfl;
        self.SetBBMC(context, "1");
        if (curOptype == "1" && curBBMCNew.length > 0) {
            sle_formatname.SetText(curBBMCNew);
            self.ClearAndTJ(true);
        } else {
            sle_formatname.SetText("");
            curBBPZH = "";
        }

        //#region 查询天数的

        curSelDays = GetXiTongCanShu(curUserId, curCdbh, "bzxx");

        //#endregion 



    }
    //#endregion

    //#region checkBox关闭还是打开状态
    this.CbxEnable = function (bchecked, obj) {
        var tempbbmc = obj.Name;
        cbx_bm.SetChecked(false);
        cbx_lb.SetChecked(false);
        cbx_gys.SetChecked(false);
        if (tempbbmc.length > 1) {
            var v_CheckBoxState = GetCheckBoxValue(dw_format, curYhbh, curCdbh, tempbbmc)
            if (v_CheckBoxState.length > 1) {
                window.eval(v_CheckBoxState);
            }
        }
    }

    //#endregion

    //#region 显示屏蔽列
    this.Controlhl = function () {
        var curCol = requestor.GetParm("curCol");
        if (!cbx_bm.GetChecked()) {

            dw_list.Modify("bmbh.visible='0' bmmc.visible='0'")
        }

        if (!cbx_gys.GetChecked()) {

            dw_list.Modify("gysbh.visible='0' gysmc.visible='0'")
        }

        if (!cbx_lb.GetChecked()) {

            dw_list.Modify("hplb.visible='0' lbmc.visible='0'")
        }
        if (rb_cmzx.GetChecked()) {

            for (var i = 1; i <= parseInt(curCol); i++) {
                dw_list.Modify("cm" + i + ".visible='1'");
                dw_list.Modify("cm" + i + ".width = '150'");
                dw_list.SetFormat("cm" + i, '######')
            }
        }
        else if (rb_cmhx.GetChecked()) {
            for (var i = 1; i <= parseInt(curCol); i++) {

                dw_list.Modify("cm" + i + ".visible='1'");
                dw_list.Modify("cm" + i + ".width = '150'");
                dw_list.SetFormat("cm" + i, '######')

                dw_list.Modify("k" + i + ".visible='1'");
                dw_list.Modify("k" + i + ".width = '150'");
                dw_list.SetFormat("k" + i, '######')

                dw_list.Modify("j" + i + ".visible='1'");
                dw_list.Modify("j" + i + ".width = '150'");
                dw_list.SetFormat("j" + i, '######')
            }
        }
    }
    //#endregion

    //#region Function DrawDataWindow
    this.DrawDataWindow = function (parameter) {
        syntax = "";
        webReq.Invoke("GetSnataxAndDataFromSql", "sql=" + parameter + "&flag=Grid");
        if (webReq.StatusCode() == 200) {
            syntax = webReq.ResponseText();
            dw_temp.SetFullState(syntax);
            dw_list.SetFullState(dw_temp.GetFullState());
            dw_list.SetRowSelection(0);
            gRowCount = dw_list.RowCount();
            var colCount = dw_list.Describe("DataWindow.Column.Count");
            self.SetItemName(colCount);
        } else {
            alert("error!");
        }
        //    dw_list.Modify(" create text(band=header alignment='2' text='序号' border='0' color='33554432' x='0' y='0' height='76' width='183' html.valueishtml='0'  name=xh_t visible='1'  font.face='Tahoma' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912' background.transparency='0' background.gradient.color='8421504' background.gradient.transparency='0' background.gradient.angle='0' background.brushmode='0' background.gradient.repetition.mode='0' background.gradient.repetition.count='0' background.gradient.repetition.length='100' background.gradient.focus='0' background.gradient.scale='100' background.gradient.spread='100' tooltip.backcolor='134217752' tooltip.delay.initial='0' tooltip.delay.visible='32000' tooltip.enabled='0' tooltip.hasclosebutton='0' tooltip.icon='0' tooltip.isbubble='0' tooltip.maxwidth='0' tooltip.textcolor='134217751' tooltip.transparency='0' transparency='0' )")
        //    dw_list.Modify("create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='0' y='0' height='76' width='183' format='[GENERAL]' html.valueishtml='0' name=xh  visible='1'  font.face='Arial' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='1073741824')");
        dw_list.Modify(" create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='0' y='8' height='72' width='169' format='[GENERAL]' html.valueishtml='0' name=xh  visible='1'  font.face='Arial' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912')");
        dw_list.Modify(" create  text(band=header    alignment='2' text='序号' border='0' color='33554432' x='0' y='8' height='56' width='169' html.valueishtml='0'  name=xh_t visible='1'  font.face='Tahoma' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912' background.transparency='0' background.gradient.color='8421504' background.gradient.transparency='0' background.gradient.angle='0' background.brushmode='0' background.gradient.repetition.mode='0' background.gradient.repetition.count='0' background.gradient.repetition.length='100' background.gradient.focus='0' background.gradient.scale='100' background.gradient.spread='100' tooltip.backcolor='134217752' tooltip.delay.initial='0' tooltip.delay.visible='32000' tooltip.enabled='0' tooltip.hasclosebutton='0' tooltip.icon='0' tooltip.isbubble='0' tooltip.maxwidth='0' tooltip.textcolor='134217751' tooltip.transparency='0' transparency='0' )");
        dw_list.Modify("xh_t.y='" + dw_list.Describe("sl_t.y") + "'");
    }
    //#endregion 

    //#region 设置标题名称
    this.SetItemName = function (colCount) {

        var ls_columntitle = "";
        for (var li_loop1 = 1; li_loop1 <= colCount; li_loop1++) {
            var ls_columnname = dw_list.Describe('#' + String(li_loop1) + '.name');
            switch (ls_columnname) {
                case "bmbh":
                    ls_columntitle = "部门编号"
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;

                case "bmmc":
                    ls_columntitle = "部门名称";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "ysbh":
                    ls_columntitle = "颜色编号";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "ysmc":
                    ls_columntitle = "颜色名称";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "spkh":
                    ls_columntitle = "商品款式";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "ksmc":
                    ls_columntitle = "款式名称";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "jldw":
                    ls_columntitle = "单位";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "rq":
                    ls_columntitle = "日期";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 300 + "'");
                    break;
                case "pzh":
                    ls_columntitle = "凭证号";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 500 + "'");
                    break;
                case "cgfs":
                    ls_columntitle = "采购方式";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "rq":
                    ls_columntitle = "调整日期";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "lbbh":
                    ls_columntitle = "类别编号";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "hplb":
                    ls_columntitle = "类别编号";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "lbmc":
                    ls_columntitle = "类别名称";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "gysbh":
                    ls_columntitle = "供应商编号";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "cgy":
                    ls_columntitle = "采购人";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "bzxx":
                    ls_columntitle = "备注";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "gysmc":
                    ls_columntitle = "供应商名称";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "zjsl":
                    ls_columntitle = "数量";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".edit.name='#####' " + ls_columnname + ".editmask.mask='#####' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "jjze":
                    ls_columntitle = "进价总额";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "lsjze":
                    ls_columntitle = "零售总额";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "jj":
                    ls_columntitle = "进价";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "lsj":
                    ls_columntitle = "零售价";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "ddbzjsl":
                    ls_columntitle = "订货数量";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='#####' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "rkbzjsl":
                    ls_columntitle = "到货数量";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='#####' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "sqsl":
                    ls_columntitle = "尚缺数量";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='######' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "dhbl":
                    ls_columntitle = "到货比率";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00%' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;

            }
        }
        self.SetSummary();
    }
    //#endregion

    //#region 设置标题名称 SetItemNameForDw_mx
    this.SetItemNameForDw_mx = function (colCount) {

        var ls_columntitle = "";
        for (var li_loop1 = 1; li_loop1 <= colCount; li_loop1++) {
            var ls_columnname = dw_mx.Describe('#' + String(li_loop1) + '.name');
            switch (ls_columnname) {
                case "pzh":
                    ls_columntitle = "凭证号"
                    dw_mx.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_mx.Modify(ls_columnname + ".width = '" + 600 + "'");
                    dw_mx.Modify(ls_columnname + ".alignment = '2'");
        
                    break;
                case "kdrq":
                    ls_columntitle = "到货日期"
                    dw_mx.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_mx.Modify(ls_columnname + ".width = '" + 400 + "'");
                    dw_mx.Modify(ls_columnname + ".alignment = '2'");
                    dw_mx.Modify(ls_columnname + ".format='yyyy-mm-dd' ")
                    break;

                case "rkbzjsl":
                    ls_columntitle = "入库数量";
                    dw_mx.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_mx.Modify(ls_columnname + ".width = '" + 400 + "'");
                    dw_mx.Modify(ls_columnname + ".format='######' ")
                    break;
                 

            }
        }
        self.SetSummaryForDw_mx();
    }
    //#endregion

    //#region  this.SetSummary
    this.SetSummary = function () {
        //ddbzjsl 订货数量 rkbzjsl 到货数量 sqsl 尚缺数量
        var ls_bqkcx = "";
        var ls_lswidth = "";
        var ls_syntax = '';
        var ls_bqkcwidth = "";
        var ls_bqrkwidth = "";
        var ls_spmcx = "";
        var ls_spmcwidth = ""
        ls_spmcx = dw_list.Describe("ksmc.x");
        ls_spmcwidth = dw_list.Describe("ksmc.width")
        ls_slx = dw_list.Describe("ddbzjsl.x");
        ls_slwidth = dw_list.Describe("ddbzjsl.width")
        ls_lszjex = dw_list.Describe("rkbzjsl.x");
        ls_lszjewidth = dw_list.Describe("rkbzjsl.width")
        ls_jjzex = dw_list.Describe("sqsl.x");
        ls_jjzewidth = dw_list.Describe("sqsl.width")
        ls_syntax = dw_list.Modify("DataWindow.summary.Height=90");
        //ls_syntax = ls_syntax + "create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='0' y='8' height='72' width='215' format='[GENERAL]' html.valueishtml='0' name=xh  visible='1'  font.face='Arial' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='1073741824')";
        ls_syntax = ls_syntax + "create compute(band=summary alignment='1' expression='sum(rkbzjsl  for all)' border='0' color='128' x='" + ls_lszjex + "' y='8' height='52' width='" + ls_lszjewidth + "' name=rkbzjsl_sum  visible='1' font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='536870912' format='#####')"
        ls_syntax = ls_syntax + "create compute(band=summary alignment='1' expression='sum(sqsl  for all)' border='0' color='128' x='" + ls_jjzex + "' y='8' height='52' width='" + ls_jjzewidth + "' name=sqsl_sum  visible='1' font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='536870912'  format='#####')"
        ls_syntax = ls_syntax + "create compute(band=summary alignment='1' expression='sum(ddbzjsl  for all)' border='0' color='128' x='" + ls_slx + "' y='8' height='52' width='" + ls_slwidth + "' name=ddbzjsl_sum  visible='1' font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='536870912'  format='#####')"
        ls_syntax = ls_syntax + "create text(band=summary alignment='1'  text='合计:' border='0' color='128' x='" + ls_spmcx + "'  y='0' height='60' width='" + ls_spmcwidth + "' html.valueishtml='0'   name=t_1 visible='1'  font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='1073741824')"
        //ls_syntax = ls_syntax + "create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='0' y='8' height='72' width='215' format='[GENERAL]' html.valueishtml='0' name=xh  visible='1'  font.face='Arial' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='1073741824')";
        dw_list.Modify(ls_syntax);
    }
    //#endregion

    //#region  this.SetSummaryForDw_mx
    this.SetSummaryForDw_mx = function () {
        //ddbzjsl 订货数量 rkbzjsl 到货数量 sqsl 尚缺数量
        var ls_rkslX = "";
        var ls_rkslWidth = "";

        ls_rkslX = dw_mx.Describe("rkbzjsl.x");
        ls_rkslWidth = dw_mx.Describe("rkbzjsl.width");

      var ls_kdrqX = "";
      var ls_kdrqWidth = "";

      ls_kdrqX = dw_mx.Describe("kdrq.x");
      ls_kdrqWidth = dw_mx.Describe("kdrq.width");




        ls_syntax = dw_mx.Modify("DataWindow.summary.Height=90");
        ls_syntax = ls_syntax + "create compute(band=summary alignment='1' expression='sum(rkbzjsl  for all)' border='0' color='128' x='" + ls_rkslX + "' y='8' height='52' width='" + ls_rkslWidth + "' name=rkbzjsl_sum  visible='1' font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='536870912' format='#####')"
        ls_syntax = ls_syntax + "create text(band=summary alignment='2'  text='合计:' border='0' color='128' x='" + ls_kdrqX + "'  y='0' height='60' width='" + ls_kdrqWidth + "' html.valueishtml='0'   name=t_1 visible='1'  font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='1073741824')"
        //ls_syntax = ls_syntax + "create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='0' y='8' height='72' width='215' format='[GENERAL]' html.valueishtml='0' name=xh  visible='1'  font.face='Arial' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='1073741824')";
        dw_mx.Modify(ls_syntax);
    }
    //#endregion

    //#region exit
    this.Exit = function () {
        setTimeout("window.close()", 100);
    }
    //#endregion

    //#region 打印处理
    this.Print = function () {
        var curHeadString_rq = "";
        var curHeadString = "";
        var curFootString = "";
        var rq1 = UtcDateFormatToString(dp_1.GetValue())
        var rq2 = UtcDateFormatToString(dp_2.GetValue())
        if (rq1 == rq2) {
            curHeadString_rq = "日期：" + rq1
        } else {
            curHeadString_rq = "日期：" + rq1 + "到" + rq2 + "之间"
        }
        //#region 条件显示
        var bmmc = sle_bm.GetText();
        var curHeadStringBM = Report_Print(bmmc, "BM");

        var gysmc = sle_gys.GetText();
        var curHeadStringGYS = Report_Print(gysmc, "GYS");

        var ppmc = sle_pp.GetText();
        var curFootStringPP = Report_Print(ppmc, "PP");

        var khmc = sle_kh.GetText();
        var curFootStringKH = Report_Print(khmc, "KH");

        var fsmc = sle_fs.GetText();
        var curFootStringFS = Report_Print(fsmc, "CGFS");

        var lbmc = sle_lb.GetText();
        var curFootStringLB = Report_Print(lbmc, "LB");

        var jjmc = sle_jj.GetText();
        var curFootStringJJ = Report_Print(jjmc, "JJ");

        var mlmc = sle_ml.GetText();
        var curFootStringML = Report_Print(mlmc, "ML");

        //#endregion

        var curTitleName = "执行分析【采购订单】"
        curFootString = "制单人：" + curYhmc + "&&&【" + GetErpProductTypeName() + "】" + UtcDateTimeFormatToString(new Date().getVarDate()) +
                "&&&" + curFootStringPP + "," + curFootStringKH + "," + curFootStringFS + "," + curFootStringLB +
                "," + curFootStringJJ + "," + curFootStringML
        curHeadString = curHeadString_rq + "&&&" + curHeadStringBM + "&&&" + curHeadStringGYS;
        A8erp_Report.NaoErpReportPrint(dw_list, curTitleName, curHeadString, curFootString);
    }
    //#endregion

    //#region 设置报表名称和凭证号

    this.SetBBMC = function (context, optype) {
        if (context.length > 0) {
            curBBPZH = context.split("#")[0];
            curBBMCNew = context.split("#")[1];
            isFirstSave = context.split("#")[2];
            if (optype == "1") {
                curBbmc = context.split("#")[2];
                self.SetBbfl(curBbmc);
            }
        }
        curOptype = optype;
    }
    //#endregion

    //#region 报表格式选择
    this.SelectGS = function () {
        self.SelectBBFL();
        cur_Open_Window = new W_Base_BB_List();
        cur_Open_Window.SetParentWindow(self);
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.KuCun.TongJiFenXi.Base.W_Base_BB_List" + "&opFlag=PF" + "&FunID=" + curCdbh + "&bbfl=" + curBbmc + "&dataObject=dw_pub_all_report_format_hz"), cur_Open_Window, null);

        if (curOptype == "1" && curBBMCNew.length > 0) {
            sle_formatname.SetText(curBBMCNew);
            self.ClearAndTJ(true);
        } else {
            sle_formatname.SetText("");
            curBBPZH = "";
        }
        //刷新
    }
    //#region 格式保存#报表格式清空
    this.ReportClare = function () {
        var tempPzh = "";
        if (dw_format_hz.RowCount() > 0) {
            tempPzh = dw_format_hz.GetItemString(1, "pzh");
        }
        //    if (tempPzh.length <= 0 || sle_formatname.GetText().length <= 0) {
        //        requestor.MessageBox("提示", "请先选择报表格式", ICON.StopSign);
        //        return;
        //    }
        dw_format_mx.Reset();
        dw_format_hz.Reset();
        sle_formatname.SetText("");
        self.TongJi();
    }
    //#endregion
    this.ClearAndTJ = function (isTj) {
        dw_format_hz.RetrieveEx("pzh='" + curBBPZH + "'");
        dw_format_mx.RetrieveEx("pzh='" + curBBPZH + "'");
        dw_format_mx.SetFilter("mrgxtj='1'");
        dw_format_mx.Filter();
        xsmrgs = dw_format_mx.RowCount();
        cbx_bm.SetChecked(false);
        cbx_lb.SetChecked(false);
        cbx_gys.SetChecked(false);
        //界面控制
        var evealStr = "";
        for (var i = 1; i <= dw_format_mx.RowCount(); i++) {
            evealStr += dw_format_mx.GetItemString(i, "col") + ".SetChecked(true);";
        }
        eval(evealStr);

        dw_format_mx.SetFilter("");
        dw_format_mx.Filter();
        dw_format_mx.SetFilter("mrgxtj='0'");
        dw_format_mx.Filter();
        if (isTj == true) {
            // self.TongJi();
            if (dw_format_mx.RowCount() <= 0) {
                sle_formatname.SetText("");
            }
        }
    }
    //#endregion

    //#region 横向/纵向

    this.SetBbfl = function (bbfl) {
        if (bbfl == "rb_kh") {
            rb_kh.SetChecked(true);
        }
        else if (bbfl == "rb_ys") {
            rb_ys.SetChecked(true);
        }
        else if (bbfl == "rb_cmzx") {
            rb_cmzx.SetChecked(true);
        }
        else if (bbfl == "rb_cmhx") {
            rb_cmhx.SetChecked(true);
        }
    }
    //#endregion

    //#region 保存
    this.SaveGS = function () {
        self.SelectBBFL();

        //curBBMCNew = "";
        if (curBbmc.length > 0) {
            cur_Open_Window = new W_Base_SaveOP();
            cur_Open_Window.SetParentWindow(self, curCdbh);
            requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.KuCun.TongJiFenXi.Base.W_Base_SaveOP" + "&opFlag=CG" + "&Bbfl=" + curBbmc + "&dataObject=dw_kctjfx_top"), cur_Open_Window, null);
        }
        if (curBBMCNew.length <= 0 || curOptype != 0) {
            return;
        }
        sle_formatname.SetText(curBBMCNew);
        self.ReportSave();
    }
    //#endregion

    //#region 获取报表分类
    this.SelectBBFL = function () {

        if (rb_kh.GetChecked()) {
            curBbmc = "rb_kh";
        }
        if (rb_cmzx.GetChecked()) {
            curBbmc = "rb_cmzx";
        }
        if (rb_cmhx.GetChecked()) {
            curBbmc = "rb_cmhx";
        }
        if (rb_ys.GetChecked()) {
            curBbmc = "rb_ys";
        }
    }
    //#endregion 

    //#region 提交
    this.ReportSave = function () {
        self.PropertCheckStatus();
        var msg = ReportSaveEx(dw_list, dw_format_hz, dw_format_mx, curYhbh, curCdbh, curBbmc, curBBPZH, curYhbh, curBBMCNew, ChildDWCheckValue, jgtxlist, isFirstSave);
        if (msg == "OK") {
            requestor.MessageBox("提示", "保存成功", ICON.Information);
            dw_format_mx.ResetUpdate();
            dw_format_mx.SetFilter("mrgxtj='1'");
            curCol = requestor.GetParm("curCol");
            dw_format_mx.Filter();
            xsmrgs = dw_format_mx.RowCount();
            dw_format_mx.SetFilter("");
            dw_format_mx.Filter();
            dw_format_mx.SetFilter("mrgxtj='0'");
            dw_format_mx.Filter();
            self.TongJi();
            return;
        }
        else {
            requestor.MessageBox("提示", msg, ICON.StopSign);
        }
    }
    //#endregion

    //#region 获取被选中复选框
    this.PropertCheckStatus = function () {
        ChildDWCheckValue = "";
        //日期
        if (cbx_gys.GetChecked()) {
            ChildDWCheckValue += "cbx_gys,"
        }
        //批发部门
        if (cbx_bm.GetChecked()) {
            ChildDWCheckValue += "cbx_bm,"
        }
        //类别
        if (cbx_lb.GetChecked()) {
            ChildDWCheckValue += "cbx_lb,"
        }

    }
    //#endregion

    //#region 定义title高度
    this.A8erp_Report_Header_Row_Height = function (curDw_List) {
        curDw_List.Modify("datawindow.header.height='76'");
    }
    //#endregion

    //#region 定义Detail高度
    this.A8erp_Report_Detail_Row_Height = function (curDw_List) {
        curDw_List.Modify("datawindow.detail.height='76'");
    }
    //#endregion

    //#region 定义单据样式

    this.A8erp_Report_Style = function (curDw_List) {//67108864    15780518
        curDw_List.Modify("datawindow.detail.color='67108864' datawindow.detail.gradient.color='16777215' datawindow.detail.brushmode='1' ")
    }
    //#endregion

    //#region FormatSave
    this.FormatSave = function () {
        dw_format_mx.SetRedraw(false);

        //        if (curcbx_gs != xsmrgs) {
        //            dw_list.Modify("cm1.Format='###' cm2.Format='###' cm3.Format='###' cm4.Format='###' cm5.Format='###' cm6.Format='###' cm7.Format='###' cm8.Format='###' cm9.Format='###' cm10.Format='###' cm11.Format='###' cm12.Format='###' cm13.Format='###' cm14.Format='###' cm15.Format='###' cm16.Format='###' cm17.Format='###' cm18.Format='###' cm19.Format='###' cm20.Format='###' cm21.Format='###' cm22.Format='###' cm23.Format='###' cm24.Format='###' cm25.Format='###' cm26.Format='###' cm27.Format='###' cm28.Format='###' cm29.Format='###' cm30.Format='###' cm31.Format='###' cm32.Format='###' cm33.Format='###' cm34.Format='###' cm35.Format='###'");
        //            if (Exel_FH_Flag == "1") {
        //                dw_list.Modify("DataWindow.Sparse='spkh\tksmc\tjldw\tysbh\tysmc\tbxbh\tbxmc'");
        //            }
        //            return
        //        }
        dw_format_mx.SetSort("col_x A");
        dw_format_mx.Sort();
        for (var i = 1; i <= dw_format_mx.RowCount(); i++) {
            var curCol = dw_format_mx.GetItemString(i, "col");

            var curVisible = dw_format_mx.GetItemString(i, "visible");
            dw_list.Modify(curCol + ".visible='0'");
            dw_list.Modify(curCol + ".visible='" + curVisible + "'");

            var curWidth = dw_format_mx.GetItemNumber(i, "width");
            dw_list.Modify(curCol + ".width='" + curWidth + "'");

            var curColHz = dw_format_mx.GetItemString(i, "col_hz");
            dw_list.Modify(curCol + "_t.Text='" + curColHz + "'");

            var curfont_face = dw_format_mx.GetItemString(i, "font_face");
            dw_list.Modify(curCol + ".Font.Face='" + curfont_face + "'");

            var curfont_height = dw_format_mx.GetItemString(i, "font_height");
            dw_list.Modify(curCol + ".Font.Height='" + curfont_height + "'");

            var curfont_weight = dw_format_mx.GetItemString(i, "font_weight");
            dw_list.Modify(curCol + ".Font.Weight='" + curfont_weight + "'");

            var curfont_italic = dw_format_mx.GetItemString(i, "font_italic");
            dw_list.Modify(curCol + ".Font.Italic='" + curfont_italic + "'");

            var curfont_underline = dw_format_mx.GetItemString(i, "font_underline");
            dw_list.Modify(curCol + ".Font.Underline='" + curfont_underline + "'");

            var curCol_border = dw_format_mx.GetItemString(i, "col_border");
            dw_list.Modify(curCol + ".Border='" + curCol_border + "'");

            var ls_color = dw_format_mx.GetItemString(i, "color");
            dw_list.Modify(curCol + ".Color='" + curCol_border + "'");

            var ls_format = dw_format_mx.GetItemString(i, "format");
            dw_list.Modify(curCol + ".Format='" + ls_format + "'");

            var ls_alignment = dw_format_mx.GetItemString(i, "alignment");
            dw_list.Modify(curCol + ".Alignment='" + ls_alignment + "'");

            var ls_alignment = dw_format_mx.GetItemString(i, "tabsequence");
            dw_list.Modify(curCol + ".TabSequence='" + ls_alignment + "'");

            var li_bg_mode = dw_format_mx.GetItemString(i, "bg_mode");
            dw_list.Modify(curCol + ".Background.Mode='" + li_bg_mode + "'");

            var ls_bg_color = dw_format_mx.GetItemString(i, "bg_color");
            dw_list.Modify(curCol + ".Background.Color='" + ls_bg_color + "'");
        }
        dw_format_mx.SetRedraw(true);
        //#endregion
    }

    //#endregion

    //#region 格式保存#报表列格式操作
    this.ReportOp = function () {
        if (curBBPZH.length <= 0 || sle_formatname.GetText().length <= 0) {
            requestor.MessageBox("提示", "请先选择报表格式", ICON.StopSign);
            return;
        }
        curW_Base_Report_Open_Mx_Ex.SetDataWindow(self, curUserId, curCdbh, curBbmc, curBBPZH, "curParent.ClearAndTJ(true);");
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.Base.W_Base_Report_Open_Mx_Ex"), curW_Base_Report_Open_Mx_Ex, null);
        dw_format_hz.RetrieveEx("pzh='" + curBBPZH + "'");
        dw_format_mx.RetrieveEx("pzh='" + curBBPZH + "'");
    }
    //#endregion

    //#region 执行查询
    this.TongJi = function () {
        //        dw_format_hz.RetrieveEx("pzh='" + curBBPZH + "'");
        //        dw_format_mx.RetrieveEx("pzh='" + curBBPZH + "'");
      
        dw_list.SetRedraw(false);
        curcbx_gs = 0;
        //self.GetTableYM();
        if (rb_kh.GetChecked()) {
            self.Query(); //规格
            // dw_list.Modify("cm1.Format='###' cm2.Format='###' cm3.Format='###' cm4.Format='###' cm5.Format='###' cm6.Format='###' cm7.Format='###' cm8.Format='###' cm9.Format='###' cm10.Format='###' cm11.Format='###' cm12.Format='###' cm13.Format='###' cm14.Format='###' cm15.Format='###' cm16.Format='###' cm17.Format='###' cm18.Format='###' cm19.Format='###' cm20.Format='###' cm21.Format='###' cm22.Format='###' cm23.Format='###' cm24.Format='###' cm25.Format='###' cm26.Format='###' cm27.Format='###' cm28.Format='###' cm29.Format='###' cm30.Format='###' cm31.Format='###' cm32.Format='###' cm33.Format='###' cm34.Format='###' cm35.Format='###'");
            if (Exel_FH_Flag == "1") {
                dw_list.Modify("DataWindow.Sparse='spkh\tksmc\tjldw\tysbh\tysmc\tbxbh\tbxmc'");
            }
            self.FormatSave();
            dw_list.SetSort("spkh,ksmc,v.ysbh,v.ysmc,v.bxbh,v.bxmc");
            dw_list.Sort();
            //给Title加颜色。。
            A8erp_Report.ReportDataWindowHeaderColor(dw_list);
           // self.A8erp_Report_Style(dw_list);
            self.A8erp_Report_Header_Row_Height(dw_list, false);
            self.A8erp_Report_Detail_Row_Height(dw_list);
            //JS样式。
        }
        if (rb_ys.GetChecked()) {
            self.Query(); // 款式
            if (Exel_FH_Flag == "1") {
                dw_list.Modify("DataWindow.Sparse='spkh\tksmc\tjldw\tysbh\tysmc\tbxbh\tbxmc'");
            }
            self.FormatSave();
            dw_list.SetSort("spkh,ksmc,v.ysbh,v.ysmc,v.bxbh,v.bxmc");
            dw_list.Sort();
            A8erp_Report.ReportDataWindowHeaderColor(dw_list);
           // self.A8erp_Report_Style(dw_list);
            self.A8erp_Report_Header_Row_Height(dw_list, false);
            self.A8erp_Report_Detail_Row_Height(dw_list);
        }
        if (rb_cmzx.GetChecked()) {
            self.Query(); // 款式
            if (Exel_FH_Flag == "1") {
                dw_list.Modify("DataWindow.Sparse='spkh\tksmc\tjldw\tysbh\tysmc\tbxbh\tbxmc'");
            }
            self.FormatSave();
           // dw_list.SetSort("spkh,ksmc,v.ysbh,v.ysmc,v.bxbh,v.bxmc,t_type");
            dw_list.Sort();
            A8erp_Report.ReportDataWindowHeaderColor(dw_list);
         //   self.A8erp_Report_Style(dw_list);
            self.A8erp_Report_Detail_Row_Height(dw_list);
        }
        if (rb_cmhx.GetChecked()) {
            self.Query(); // 款式
            if (Exel_FH_Flag == "1") {
                dw_list.Modify("DataWindow.Sparse='spkh\tksmc\tjldw\tysbh\tysmc\tbxbh\tbxmc'");
            }
            self.FormatSave();
            dw_list.SetSort("spkh,ksmc,v.ysbh,v.ysmc,v.bxbh,v.bxmc");
            dw_list.Sort();
            A8erp_Report.ReportDataWindowHeaderColor(dw_list);
          //  self.A8erp_Report_Style(dw_list);
            self.A8erp_Report_Detail_Row_Height(dw_list);
        }

        dw_list.SetRedraw(true); 
        //   dw_mx.Modify("datawindow.detail.color='16777215\tif(currentrow()=getrow(), 12639424,536870912 )' ");

        dw_list.Modify("datawindow.detail.color='16777215\tif(currentrow()=getrow(), 12639424,536870912 )' ");
      //  //requestor.ClipBoardNao(dw_list.Describe("datawindow.syntax"))

    }
    //#endregion

    //#region SetValue
    this.SetValue = function (str1, str2, str3, str4) {

        ChildDWCheckValue = str1;
        curBbmc = str2;
        curCdbh = str3;
        curUserId = str4;
    }
    //#endregion

    //#region 双击标题排序
    this.DoubleClicked = function (x, y, row, dwcName) {
        if (dwcName.indexOf("_t") > -1) {
            var curColName = dwcName.split("_")[0];
            if (curColName == lastSortName) {
                dw_list.SetSort(curColName + " A");
                lastSortName = "";
                dw_list.Sort();
            } else {
                dw_list.SetSort(curColName + " D");
                lastSortName = dwcName.split("_")[0];
                dw_list.Sort();
            }
        }
    }
    //#endregion


    //#region 图片预览
    this.picpreview = function () {
        var cloumCount = 0;
        var cloumName = "";
        cloumCount = parseInt(dw_list.Describe("datawindow.column.count"));
        for (var i = 1; i <= cloumCount; i++) {
            cloumName += dw_list.Describe("#" + String(i) + ".name")
        }
        if (cloumName.indexOf("spkh") > -1) {
            var curRow = dw_list.GetRow();
            //图片的跳转
            if (curRow > 0) {
                var curspkh = dw_list.GetItemString(curRow, "spkh")
                var picuploadflag = 0;
                curW_KC_PIC.SetDataWindow(dw_list, curspkh, self, picuploadflag, "");
                requestor.Open("/Service/LoadWindow.ashx?WinName= A8ERP.KuCun.TongJiFenXi.W_KC_PIC&curSpkh=" + curspkh, curW_KC_PIC);
            }
        } else {
            requestor.MessageBox("提示", "请选择款号条件统计后再预览图片!", ICON.Information);
        }


    }
    //#endregion

    //#region 右键保存
    this.RightKey = function () {
        if (sle_formatname.GetText().toString().length > 0) {
            self.ReportSave();
        }
        else {
            requestor.MessageBox("提示", "请选择格式后再保存!", ICON.Information);
        }
    }
    //#endregion

    //#region 取输出行、小计列字段
    this.CheckedNF = function () {
        curW_NFCheck.SetDataWindow(self)
        requestor.Open("/Service/LoadWindow.ashx?WinName=A8ERP.KuCun.TongJiFenXi.W_NFCheck", curW_NFCheck, null);
    }
    //#endregion

    //#region this.EvalJs

    this.EvalJs = function (jsScript) {
        eval(jsScript);
    }
    //#endregion

    this.CheckedNF = function () {
        curW_NFCheck.SetDataWindow(self)
        requestor.Open("/Service/LoadWindow.ashx?WinName=A8ERP.KuCun.TongJiFenXi.W_NFCheck", curW_NFCheck, null);
    }


    this.ClickedDhrq = function (b) {
        if (b) {
          
        } else { 
        
        }
    }

    //#region Function GetSqlWhere
    this.GetSqlWhere = function () {
        realSql = "";
        realSql1 = ""
        //var curYhbh = requestor.GetParm("curYhbh")
        var beginDate = UtcDateFormatToString(dp_1.GetValue());
        var endDate = UtcDateFormatToString(dp_2.GetValue());
        //var curPzh = sle_pzh.GetText();
        var curKh = sle_kh.GetText();
        var curBm = sle_bm.GetText();
        var curPp = sle_pp.GetText();
        var curGys = sle_gys.GetText();
        var curLb = sle_lb.GetText();
        var curJj = sle_jj.GetText();
        var curFs = sle_fs.GetText();
        var curMl = sle_ml.GetText();
        var curSex = ddlb_sex.GetText();

        var curNF = sle_nf.GetText();


        if (curSelDays != "-1") {
            var tempBeginDate = compareDate(curSelDays, beginDate);

            realSql += " and (CONVERT(date,a.kdrq) between '" + tempBeginDate + "' and '" + endDate + "')";
            realSql1 += " and (CONVERT(date,t1.kdrq) between '" + tempBeginDate + "' and '" + endDate + "')";
        }
        else {
            realSql += " and (CONVERT(date,a.kdrq) between '" + beginDate + "' and '" + endDate + "')";
            realSql1 += " and (CONVERT(date,t1.kdrq) between '" + beginDate + "' and '" + endDate + "')";
        }


 
        if (curKh.length > 0) {
            var is_quotes = curKh.substring(0, 1);
            if (is_quotes == "%") {
                realSql += " and a.spkh like('" + curKh + "%')";
                realSql1 += " and t1.spkh like('" + curKh + "%')";
            }
            else {
                var curflag = curKh.substr(curKh.length - 1, 1);

                if (curflag == "," || curflag == "，") {
                    curKh = curKh.substring(0, curKh.length - 1);
                    var tempspkh = self.GetQuotes(curKh);
                    realSql += " and a.spkh in(" + tempspkh + ")";
                    realSql1 += " and t1.spkh in(" + tempspkh + ")";
                }
                else {
                    if (is_quotes == "'") {
                        realSql += " and a.spkh in(" + curKh + ")";
                        realSql1 += " and t1.spkh in(" + curKh + ")";
                    }
                    else {
                        realSql += " and a.spkh like('" + curKh + "%')";
                        realSql1 += " and t1.spkh like('" + curKh + "%')";
                    }
                }
            }
        }

        if (curBm.length > 0) {
            var is_quotes = curBm.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and a.bmbh  in(" + curBm + ")";
                realSql1 += " and t1.bmbh  in(" + curBm + ")";
            }
            else {
                var tempspkh = self.GetQuotes(curBm);
                realSql += " and a.bmbh in(" + tempspkh + ")";
                realSql += " and t1.bmbh in(" + tempspkh + ")";
            }
        } else {
            realSql += "and a.bmbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and cgcx = '1')"
            realSql1 += "and t1.bmbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and cgcx = '1')"
        }

        if (curPp.length > 0) {
            var is_quotes = curPp.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and jypp in(" + curPp + ")";
                realSql1 += " and jypp in(" + curPp + ")";
            } else {
                var tempspkh = self.GetQuotes(curPp);
                realSql += " and jypp in(" + tempspkh + ")";
                realSql1 += " and jypp in(" + tempspkh + ")";
            }
        } else {
            realSql += "and  jypp in(select ppbh from da_qx_ppda  where yhbh='" + curYhbh + "' and bz1='1')"
            realSql1 += "and  jypp in(select ppbh from da_qx_ppda  where yhbh='" + curYhbh + "' and bz1='1')"
        }

        if (curGys.length > 0) {
            var is_quotes = curGys.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and a.gysbh in(" + curGys + ")";
                realSql1 += " and t1.gysbh in(" + curGys + ")";
            }
            else {
                var tempspkh = self.GetQuotes(curGys);
                realSql += " and a.gysbh in(" + tempspkh + ")";
                realSql1 += " and t1.gysbh in(" + tempspkh + ")";
            }
        } else {
            realSql += "and a.gysbh in( select gysbh from da_qx_gysda where yhbh='" + curYhbh + "' and bz3='1')"
            realSql1 += "and t1.gysbh in( select gysbh from da_qx_gysda where yhbh='" + curYhbh + "' and bz3='1')"
        }

        if (curLb.length > 0) {
            var is_quotes = curLb.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and b.hplb in(" + curLb + ")";
                realSql1 += " and t2.hplb in(" + curLb + ")";
            }
            else {
                var tempspkh = self.GetQuotes(curLb);
                realSql += " and b.hplb in(" + tempspkh + ")";
                realSql1 += " and t2.hplb in(" + tempspkh + ")";
            }
        }

        if (curJj.length > 0) {
            var is_quotes = curJj.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and b.spjj in(" + curJj + ")";
                realSql1 += " and t2.spjj in(" + curJj + ")";
            } else {
                var tempspkh = self.GetQuotes(curJj);
                realSql += " and b.spjj in(" + tempspkh + ")";
                realSql1 += " and t2.spjj in(" + tempspkh + ")";
            }
        }

        if (curFs.length > 0) {
            var is_quotes = curFs.substring(0, 1);
            if (is_quotes == "'") {
                //realSql += " and a.cgfs in(" + curFs + ")";
                realSql1 += " and t1.cgfs in(" + curFs + ")";
            } else {
                var tempspkh = self.GetQuotes(curFs);
                //realSql += " and a.cgfs in(" + tempspkh + ")";
                realSql1 += " and t1.cgfs in(" + tempspkh + ")";
            }
        }

        if (curMl.length > 0) {
            var is_quotes = curMl.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and b.spml in(" + curMl + ")";
                realSql1 += " and t2.spml in(" + curMl + ")";
            } else {
                var tempspkh = self.GetQuotes(curMl);
                realSql += " and b.spml in(" + tempspkh + ")";
                realSql1 += " and t2.spml in(" + tempspkh + ")";
            }
        }
        if (curSex.length > 0) {
//            if (curSex == "女") { realSql += " and  b.spxb='" + 0 + "'"; realSql1 += " and  t2.spxb='" + 0 + "'" }
//            else if (curSex == "男") { realSql += " and  b.spxb='" + 1 + "'"; realSql1 += " and  t2.spxb='" + 1 + "'"; }
//            else if (curSex == "中性") { realSql += " and  b.spxb='" + 2 + "'"; realSql1 += "  and  t2.spxb='" + 2 + "'"; }
            realSql  += " and  b.spxb='" + curSex + "'";
            realSql1 += "  and  t2.spxb='" + curSex + "'"; 
        }
        if (curNF.length > 0) {
            realSql += " and  b.spnf in (" + curNF + ")";
            realSql1 += " and  t2.spnf in (" + curNF + ")";

        }
        //    if (curspbh.length > 0) {

        //        curspbh = self.DealWords(curspbh);

        //        if (flag == true) {
        //            realSql += " and  dbo.F_GET_spkh_have_spbh(b.spkh," + curspbh + ") = 'Y'"
        //            realSql1 += " and  dbo.F_GET_spkh_have_spbh(t2.spkh," + curspbh + ") = 'Y'"
        //        }
        //        else {
        //            realSql += " and  dbo.F_GET_spkh_have_spbh(b.spkh," + curspbh + ") = 'Y'"
        //            realSql1 += " and  dbo.F_GET_spkh_have_spbh(t2.spkh," + curspbh + ") = 'Y'"
        //        }

        //    }
        // return realSql;
    }
    //#endregion
    this.DoubleClicked = function (x, y, row, docName) {

        var curBmbh = "";

        var curSpkh = "";
        var curYsbh = "";

        var curGysbh = "";
        //#region 款式
        if (rb_kh.GetChecked()) {

            curSpkh = dw_list.GetItemString(row, "spkh");

            if (cbx_bm.GetChecked()) {
                curBmbh = dw_list.GetItemString(row, "bmbh");
            }
            if (cbx_gys.GetChecked()) {
                curGysbh = dw_list.GetItemString(row, "gysbh");
            }


            var beginDate = UtcDateFormatToString(dp_1.GetValue());
            var endDate = UtcDateFormatToString(dp_2.GetValue());
            //var curPzh = sle_pzh.GetText();
            var curKh = sle_kh.GetText();
            var curBm = sle_bm.GetText();
            var curPp = sle_pp.GetText();
            var curGys = sle_gys.GetText();
            var curLb = sle_lb.GetText();
            var curJj = sle_jj.GetText();
            var curFs = sle_fs.GetText();
            var curMl = sle_ml.GetText();
            var curSex = ddlb_sex.GetText();

            var curNF = sle_nf.GetText();



            var curSql = " SELECT RKB.pzh pzh,RKB.KDRQ KDRQ,SUM(RKB.RKSL) RKBZJSL ";
            curSql += "    FROM ";
            curSql += " ( ";
            curSql += " SELECT bmbh,gysbh,spkh,spbh, SUM(ISNULL(sl, 0))   ddsl ";
            curSql += " FROM   yw_cg_cgddtz    ";
            curSql += " WHERE     CONVERT(DATE, kdrq) BETWEEN '" + beginDate + "'  AND     '" + endDate + "'  ";
            curSql += " GROUP BY bmbh,gysbh,spbh,spkh) DDB  ";
            curSql += " 	LEFT JOIN ( SELECT pzh,CONVERT(DATE, kdrq) kdrq, bmbh,gysbh,spkh,spbh, SUM(CASE WHEN  djlx ='1' THEN ISNULL(sl, 0) ELSE ISNULL(-sl, 0) end) rksl ";
            curSql += " 				FROM   yw_cg_cgrkdtz rdk   ";
            curSql += " 				WHERE    CONVERT(DATE, kdrq) BETWEEN '" + beginDate + "'  AND     '" + endDate + "'  ";
            curSql += " 				GROUP BY pzh,CONVERT(DATE, kdrq),bmbh,gysbh,spbh,spkh	 ";
            curSql += " 			  ) RKB  ";
            curSql += " ON DDB.bmbh=rkb.bmbh AND DDB.gysbh=RKB.gysbh AND ddb.spbh=RKB.spbh AND ddb.spkh=RKB.spkh  ";
            curSql += " where ddb.spkh = '" + curSpkh + "' ";
         


   

            //部门
            if (curBmbh.length < 1) {
                if (curBm.length < 1) {
                    curSql += " AND ddb.bmbh IN ( SELECT bmbh FROM   da_qx_bmqxsz  WHERE  yhbh = '" + curYhbh + "' AND cgcx = '1' )";
                } else {
                    curSql += " AND ddb.bmbh IN (" + curBm + ")";
                }
            } else {
                curSql += " AND ddb.bmbh ='" + curBmbh + "'";

            }

            //供应商
            if (curGysbh.length < 1) {
                if (curGys.length < 1) {
                    curSql += "  AND ddb.gysbh IN ( SELECT gysbh FROM da_qx_gysda WHERE yhbh = '" + curYhbh + "'  and bz3='1')";
                } else {
                    curSql += "  AND ddb.gysbh IN (" + curGys + ")";
                }
            } else {
                curSql += " AND ddb.gysbh ='" + curGysbh + "'";

            }



            curSql += " GROUP BY kdrq,pzh ";
            curSql += " HAVING RKB.kdrq IS NOT NULL ";
            curSql += " ORDER BY kdrq DESC";


            //requestor.ClipBoardNao(curSql)

            webReq.Invoke("GetSnataxAndDataFromSql", "sql=" + curSql + "&flag=Grid");
            if (webReq.StatusCode() == 200) {
                syntax = webReq.ResponseText();
                dw_temp.SetFullState(syntax);
                dw_mx.SetFullState(dw_temp.GetFullState());
                dw_mx.SetRowSelection(0);
                gRowCount = dw_mx.RowCount();
                var colCount = dw_mx.Describe("DataWindow.Column.Count");
                self.SetItemNameForDw_mx(colCount);
            } else {
                alert("error!");
            }




            dw_mx.Modify(" create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='0' y='8' height='72' width='169' format='[GENERAL]' html.valueishtml='0' name=xh  visible='1'  font.face='Arial' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912')");
            dw_mx.Modify(" create  text(band=header    alignment='2' text='序号' border='0' color='33554432' x='0' y='8' height='56' width='169' html.valueishtml='0'  name=xh_t visible='1'  font.face='Tahoma' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912' background.transparency='0' background.gradient.color='8421504' background.gradient.transparency='0' background.gradient.angle='0' background.brushmode='0' background.gradient.repetition.mode='0' background.gradient.repetition.count='0' background.gradient.repetition.length='100' background.gradient.focus='0' background.gradient.scale='100' background.gradient.spread='100' tooltip.backcolor='134217752' tooltip.delay.initial='0' tooltip.delay.visible='32000' tooltip.enabled='0' tooltip.hasclosebutton='0' tooltip.icon='0' tooltip.isbubble='0' tooltip.maxwidth='0' tooltip.textcolor='134217751' tooltip.transparency='0' transparency='0' )");
            dw_mx.Modify("datawindow.detail.color='16777215\tif(currentrow()=getrow(), 12639424,536870912 )' ");
            A8erp_Report.ReportDataWindowHeaderColor(dw_mx);

            self.A8erp_Report_Header_Row_Height(dw_mx, false);
        }
        //#endregion

        //#region 颜色
        if (rb_ys.GetChecked()) {

            curSpkh = dw_list.GetItemString(row, "spkh");
            curYsbh = dw_list.GetItemString(row, "ysbh");
            if (cbx_bm.GetChecked()) {
                curBmbh = dw_list.GetItemString(row, "bmbh");
            }
            if (cbx_gys.GetChecked()) {
                curGysbh = dw_list.GetItemString(row, "gysbh");
            }


            var beginDate = UtcDateFormatToString(dp_1.GetValue());
            var endDate = UtcDateFormatToString(dp_2.GetValue());
            //var curPzh = sle_pzh.GetText();
            var curKh = sle_kh.GetText();
            var curBm = sle_bm.GetText();
            var curPp = sle_pp.GetText();
            var curGys = sle_gys.GetText();
            var curLb = sle_lb.GetText();
            var curJj = sle_jj.GetText();
            var curFs = sle_fs.GetText();
            var curMl = sle_ml.GetText();
            var curSex = ddlb_sex.GetText();

            var curNF = sle_nf.GetText();



            var curSql = " SELECT RKB.PZH PZH,RKB.KDRQ KDRQ,SUM(RKB.RKSL) RKBZJSL ";
            curSql += "    FROM ";
            curSql += " ( ";
            curSql += " SELECT bmbh,gysbh,spkh,spbh,ysbh, SUM(ISNULL(sl, 0))   ddsl ";
            curSql += " FROM   yw_cg_cgddtz    ";
            curSql += " WHERE     CONVERT(DATE, kdrq) BETWEEN '" + beginDate + "'  AND     '" + endDate + "'  ";
            curSql += " GROUP BY bmbh,gysbh,spbh,ysbh,spkh) DDB  ";
            curSql += " 	LEFT JOIN ( SELECT pzh,CONVERT(DATE, kdrq) kdrq, bmbh,gysbh,spkh,spbh,ysbh, SUM(CASE WHEN  djlx ='1' THEN ISNULL(sl, 0) ELSE ISNULL(-sl, 0) end) rksl ";
            curSql += " 				FROM   yw_cg_cgrkdtz rdk   ";
            curSql += " 				WHERE    CONVERT(DATE, kdrq) BETWEEN '" + beginDate + "'  AND     '" + endDate + "'  ";
            curSql += " 				GROUP BY CONVERT(DATE, kdrq),bmbh,gysbh,spbh,spkh,ysbh,pzh	 ";
            curSql += " 			  ) RKB  ";
            curSql += " ON DDB.bmbh=rkb.bmbh AND DDB.gysbh=RKB.gysbh AND ddb.spbh=RKB.spbh AND ddb.spkh=RKB.spkh  ";
            curSql += " where ddb.spkh = '" + curSpkh + "' ";
            curSql += " AND ddb.ysbh = '" + curYsbh + "' ";




            //部门
            if (curBmbh.length < 1) {
                if (curBm.length < 1) {
                    curSql += " AND ddb.bmbh IN ( SELECT bmbh FROM   da_qx_bmqxsz  WHERE  yhbh = '" + curYhbh + "' AND cgcx = '1' )";
                } else {
                    curSql += " AND ddb.bmbh IN (" + curBm + ")";
                }
            } else {
                curSql += " AND ddb.bmbh ='" + curBmbh + "'";

            }

            //供应商
            if (curGysbh.length < 1) {
                if (curGys.length < 1) {
                    curSql += "  AND ddb.gysbh IN ( SELECT gysbh FROM da_qx_gysda WHERE yhbh = '" + curYhbh + "'  and bz3='1')";
                } else {
                    curSql += "  AND ddb.gysbh IN (" + curGys + ")";
                }
            } else {
                curSql += " AND ddb.gysbh ='" + curGysbh + "'";

            }



            curSql += " GROUP BY kdrq ,PZH";
            curSql += " HAVING RKB.kdrq IS NOT NULL ";
            curSql += " ORDER BY kdrq DESC";


            //requestor.ClipBoardNao(curSql)

            webReq.Invoke("GetSnataxAndDataFromSql", "sql=" + curSql + "&flag=Grid");
            if (webReq.StatusCode() == 200) {
                syntax = webReq.ResponseText();
                dw_temp.SetFullState(syntax);
                dw_mx.SetFullState(dw_temp.GetFullState());
                dw_mx.SetRowSelection(0);
                gRowCount = dw_mx.RowCount();
                var colCount = dw_mx.Describe("DataWindow.Column.Count");
                self.SetItemNameForDw_mx(colCount);
            } else {
                alert("error!");
            }




            dw_mx.Modify(" create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='0' y='8' height='72' width='169' format='[GENERAL]' html.valueishtml='0' name=xh  visible='1'  font.face='Arial' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912')");
            dw_mx.Modify(" create  text(band=header    alignment='2' text='序号' border='0' color='33554432' x='0' y='8' height='56' width='169' html.valueishtml='0'  name=xh_t visible='1'  font.face='Tahoma' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912' background.transparency='0' background.gradient.color='8421504' background.gradient.transparency='0' background.gradient.angle='0' background.brushmode='0' background.gradient.repetition.mode='0' background.gradient.repetition.count='0' background.gradient.repetition.length='100' background.gradient.focus='0' background.gradient.scale='100' background.gradient.spread='100' tooltip.backcolor='134217752' tooltip.delay.initial='0' tooltip.delay.visible='32000' tooltip.enabled='0' tooltip.hasclosebutton='0' tooltip.icon='0' tooltip.isbubble='0' tooltip.maxwidth='0' tooltip.textcolor='134217751' tooltip.transparency='0' transparency='0' )");
            dw_mx.Modify("datawindow.detail.color='16777215\tif(currentrow()=getrow(), 12639424,536870912 )' ");
            A8erp_Report.ReportDataWindowHeaderColor(dw_mx);

            self.A8erp_Report_Header_Row_Height(dw_mx, false);
        }
        //#endregion

        //#region 尺码纵向
        if (rb_cmzx.GetChecked()) {

            curSpkh = dw_list.GetItemString(row, "spkh");
            curYsbh = dw_list.GetItemString(row, "ysbh");
            if (cbx_bm.GetChecked()) {
                curBmbh = dw_list.GetItemString(row, "bmbh");
            }
            if (cbx_gys.GetChecked()) {
                curGysbh = dw_list.GetItemString(row, "gysbh");
            }


            var beginDate = UtcDateFormatToString(dp_1.GetValue());
            var endDate = UtcDateFormatToString(dp_2.GetValue());
            //var curPzh = sle_pzh.GetText();
            var curKh = sle_kh.GetText();
            var curBm = sle_bm.GetText();
            var curPp = sle_pp.GetText();
            var curGys = sle_gys.GetText();
            var curLb = sle_lb.GetText();
            var curJj = sle_jj.GetText();
            var curFs = sle_fs.GetText();
            var curMl = sle_ml.GetText();
            var curSex = ddlb_sex.GetText();

            var curNF = sle_nf.GetText();



            var curSql = " SELECT RKB.PZH PZH,RKB.KDRQ KDRQ,SUM(RKB.RKSL) RKBZJSL ";
            curSql += "    FROM ";
            curSql += " ( ";
            curSql += " SELECT bmbh,gysbh,spkh,spbh,ysbh, SUM(ISNULL(sl, 0))   ddsl ";
            curSql += " FROM   yw_cg_cgddtz    ";
            curSql += " WHERE     CONVERT(DATE, kdrq) BETWEEN '" + beginDate + "'  AND     '" + endDate + "'  ";
            curSql += " GROUP BY bmbh,gysbh,spbh,ysbh,spkh) DDB  ";
            curSql += " 	LEFT JOIN ( SELECT pzh,CONVERT(DATE, kdrq) kdrq, bmbh,gysbh,spkh,spbh,ysbh, SUM(CASE WHEN  djlx ='1' THEN ISNULL(sl, 0) ELSE ISNULL(-sl, 0) end) rksl ";
            curSql += " 				FROM   yw_cg_cgrkdtz rdk   ";
            curSql += " 				WHERE    CONVERT(DATE, kdrq) BETWEEN '" + beginDate + "'  AND     '" + endDate + "'  ";
            curSql += " 				GROUP BY CONVERT(DATE, kdrq),bmbh,gysbh,spbh,spkh,ysbh,pzh	 ";
            curSql += " 			  ) RKB  ";
            curSql += " ON DDB.bmbh=rkb.bmbh AND DDB.gysbh=RKB.gysbh AND ddb.spbh=RKB.spbh AND ddb.spkh=RKB.spkh  ";
            curSql += " where ddb.spkh = '" + curSpkh + "' ";
            curSql += " AND ddb.ysbh = '" + curYsbh + "' ";




            //部门
            if (curBmbh.length < 1) {
                if (curBm.length < 1) {
                    curSql += " AND ddb.bmbh IN ( SELECT bmbh FROM   da_qx_bmqxsz  WHERE  yhbh = '" + curYhbh + "' AND cgcx = '1' )";
                } else {
                    curSql += " AND ddb.bmbh IN (" + curBm + ")";
                }
            } else {
                curSql += " AND ddb.bmbh ='" + curBmbh + "'";

            }

            //供应商
            if (curGysbh.length < 1) {
                if (curGys.length < 1) {
                    curSql += "  AND ddb.gysbh IN ( SELECT gysbh FROM da_qx_gysda WHERE yhbh = '" + curYhbh + "'  and bz3='1')";
                } else {
                    curSql += "  AND ddb.gysbh IN (" + curGys + ")";
                }
            } else {
                curSql += " AND ddb.gysbh ='" + curGysbh + "'";

            }



            curSql += " GROUP BY kdrq ,PZH";
            curSql += " HAVING RKB.kdrq IS NOT NULL ";
            curSql += " ORDER BY kdrq DESC";


            //requestor.ClipBoardNao(curSql)

            webReq.Invoke("GetSnataxAndDataFromSql", "sql=" + curSql + "&flag=Grid");
            if (webReq.StatusCode() == 200) {
                syntax = webReq.ResponseText();
                dw_temp.SetFullState(syntax);
                dw_mx.SetFullState(dw_temp.GetFullState());
                dw_mx.SetRowSelection(0);
                gRowCount = dw_mx.RowCount();
                var colCount = dw_mx.Describe("DataWindow.Column.Count");
                self.SetItemNameForDw_mx(colCount);
            } else {
                alert("error!");
            }




            dw_mx.Modify(" create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='0' y='8' height='72' width='169' format='[GENERAL]' html.valueishtml='0' name=xh  visible='1'  font.face='Arial' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912')");
            dw_mx.Modify(" create  text(band=header    alignment='2' text='序号' border='0' color='33554432' x='0' y='8' height='56' width='169' html.valueishtml='0'  name=xh_t visible='1'  font.face='Tahoma' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912' background.transparency='0' background.gradient.color='8421504' background.gradient.transparency='0' background.gradient.angle='0' background.brushmode='0' background.gradient.repetition.mode='0' background.gradient.repetition.count='0' background.gradient.repetition.length='100' background.gradient.focus='0' background.gradient.scale='100' background.gradient.spread='100' tooltip.backcolor='134217752' tooltip.delay.initial='0' tooltip.delay.visible='32000' tooltip.enabled='0' tooltip.hasclosebutton='0' tooltip.icon='0' tooltip.isbubble='0' tooltip.maxwidth='0' tooltip.textcolor='134217751' tooltip.transparency='0' transparency='0' )");
            dw_mx.Modify("datawindow.detail.color='16777215\tif(currentrow()=getrow(), 12639424,536870912 )' ");
            A8erp_Report.ReportDataWindowHeaderColor(dw_mx);

            self.A8erp_Report_Header_Row_Height(dw_mx, false);
        }
        //#endregion

        //#region 尺码横向
        if (rb_cmhx.GetChecked()) {

            curSpkh = dw_list.GetItemString(row, "spkh");
            curYsbh = dw_list.GetItemString(row, "ysbh");
            if (cbx_bm.GetChecked()) {
                curBmbh = dw_list.GetItemString(row, "bmbh");
            }
            if (cbx_gys.GetChecked()) {
                curGysbh = dw_list.GetItemString(row, "gysbh");
            }


            var beginDate = UtcDateFormatToString(dp_1.GetValue());
            var endDate = UtcDateFormatToString(dp_2.GetValue());
            //var curPzh = sle_pzh.GetText();
            var curKh = sle_kh.GetText();
            var curBm = sle_bm.GetText();
            var curPp = sle_pp.GetText();
            var curGys = sle_gys.GetText();
            var curLb = sle_lb.GetText();
            var curJj = sle_jj.GetText();
            var curFs = sle_fs.GetText();
            var curMl = sle_ml.GetText();
            var curSex = ddlb_sex.GetText();

            var curNF = sle_nf.GetText();



            var curSql = " SELECT RKB.PZH PZH,RKB.KDRQ KDRQ,SUM(RKB.RKSL) RKBZJSL ";
            curSql += "    FROM ";
            curSql += " ( ";
            curSql += " SELECT bmbh,gysbh,spkh,spbh,ysbh, SUM(ISNULL(sl, 0))   ddsl ";
            curSql += " FROM   yw_cg_cgddtz    ";
            curSql += " WHERE     CONVERT(DATE, kdrq) BETWEEN '" + beginDate + "'  AND     '" + endDate + "'  ";
            curSql += " GROUP BY bmbh,gysbh,spbh,ysbh,spkh) DDB  ";
            curSql += " 	LEFT JOIN ( SELECT pzh,CONVERT(DATE, kdrq) kdrq, bmbh,gysbh,spkh,spbh,ysbh, SUM(CASE WHEN  djlx ='1' THEN ISNULL(sl, 0) ELSE ISNULL(-sl, 0) end) rksl ";
            curSql += " 				FROM   yw_cg_cgrkdtz rdk   ";
            curSql += " 				WHERE    CONVERT(DATE, kdrq) BETWEEN '" + beginDate + "'  AND     '" + endDate + "'  ";
            curSql += " 				GROUP BY CONVERT(DATE, kdrq),bmbh,gysbh,spbh,spkh,ysbh,pzh	 ";
            curSql += " 			  ) RKB  ";
            curSql += " ON DDB.bmbh=rkb.bmbh AND DDB.gysbh=RKB.gysbh AND ddb.spbh=RKB.spbh AND ddb.spkh=RKB.spkh  ";
            curSql += " where ddb.spkh = '" + curSpkh + "' ";
            curSql += " AND ddb.ysbh = '" + curYsbh + "' ";




            //部门
            if (curBmbh.length < 1) {
                if (curBm.length < 1) {
                    curSql += " AND ddb.bmbh IN ( SELECT bmbh FROM   da_qx_bmqxsz  WHERE  yhbh = '" + curYhbh + "' AND cgcx = '1' )";
                } else {
                    curSql += " AND ddb.bmbh IN (" + curBm + ")";
                }
            } else {
                curSql += " AND ddb.bmbh ='" + curBmbh + "'";

            }

            //供应商
            if (curGysbh.length < 1) {
                if (curGys.length < 1) {
                    curSql += "  AND ddb.gysbh IN ( SELECT gysbh FROM da_qx_gysda WHERE yhbh = '" + curYhbh + "'  and bz3='1')";
                } else {
                    curSql += "  AND ddb.gysbh IN (" + curGys + ")";
                }
            } else {
                curSql += " AND ddb.gysbh ='" + curGysbh + "'";

            }



            curSql += " GROUP BY kdrq ,PZH";
            curSql += " HAVING RKB.kdrq IS NOT NULL ";
            curSql += " ORDER BY kdrq DESC";


            //requestor.ClipBoardNao(curSql)

            webReq.Invoke("GetSnataxAndDataFromSql", "sql=" + curSql + "&flag=Grid");
            if (webReq.StatusCode() == 200) {
                syntax = webReq.ResponseText();
                dw_temp.SetFullState(syntax);
                dw_mx.SetFullState(dw_temp.GetFullState());
                dw_mx.SetRowSelection(0);
                gRowCount = dw_mx.RowCount();
                var colCount = dw_mx.Describe("DataWindow.Column.Count");
                self.SetItemNameForDw_mx(colCount);
            } else {
                alert("error!");
            }




            dw_mx.Modify(" create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='0' y='8' height='72' width='169' format='[GENERAL]' html.valueishtml='0' name=xh  visible='1'  font.face='Arial' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912')");
            dw_mx.Modify(" create  text(band=header    alignment='2' text='序号' border='0' color='33554432' x='0' y='8' height='56' width='169' html.valueishtml='0'  name=xh_t visible='1'  font.face='Tahoma' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912' background.transparency='0' background.gradient.color='8421504' background.gradient.transparency='0' background.gradient.angle='0' background.brushmode='0' background.gradient.repetition.mode='0' background.gradient.repetition.count='0' background.gradient.repetition.length='100' background.gradient.focus='0' background.gradient.scale='100' background.gradient.spread='100' tooltip.backcolor='134217752' tooltip.delay.initial='0' tooltip.delay.visible='32000' tooltip.enabled='0' tooltip.hasclosebutton='0' tooltip.icon='0' tooltip.isbubble='0' tooltip.maxwidth='0' tooltip.textcolor='134217751' tooltip.transparency='0' transparency='0' )");
            dw_mx.Modify("datawindow.detail.color='16777215\tif(currentrow()=getrow(), 12639424,536870912 )' ");
            A8erp_Report.ReportDataWindowHeaderColor(dw_mx);

            self.A8erp_Report_Header_Row_Height(dw_mx, false);
        }
        //#endregion
    } 
 
}